<commit_before>/***********************************************************************
 * Copyright (c) 2000-2006 The Apache Software Foundation.             *
 * All rights reserved.                                                *
 * ------------------------------------------------------------------- *
 * Licensed under the Apache License, Version 2.0 (the "License"); you *
 * may not use this file except in compliance with the License. You    *
 * may obtain a copy of the License at:                                *
 *                                                                     *
 *     http://www.apache.org/licenses/LICENSE-2.0                      *
 *                                                                     *
 * Unless required by applicable law or agreed to in writing, software *
 * distributed under the License is distributed on an "AS IS" BASIS,   *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
 * implied.  See the License for the specific language governing       *
 * permissions and limitations under the License.                      *
 ***********************************************************************/


package org.apache.james.test.mock.james;

import org.apache.james.services.MailRepository;
import org.apache.mailet.Mail;

import javax.mail.MessagingException;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Collection;

public class MockMailRepository implements MailRepository {
    
    private HashMap messages = new HashMap();

    public void store(Mail mc) throws MessagingException {
        this.messages.put(mc.getName(),mc);
    }

    public Iterator list() throws MessagingException {
        return messages.keySet().iterator();  // trivial implementation
    }

    public Mail retrieve(String key) throws MessagingException {
        return (Mail) messages.get(key);  // trivial implementation
    }

    public void remove(Mail mail) throws MessagingException {
        messages.remove(mail.getName());
    }

    public void remove(Collection mails) throws MessagingException {
        for (Iterator i = mails.iterator(); i.hasNext(); ) {
            Mail m = (Mail) i.next();
            messages.remove(m.getName());
        }
    }

    public void remove(String key) throws MessagingException {
        messages.remove(key);
    }

    public boolean lock(String key) throws MessagingException {
        return false;  // trivial implementation
    }

    public boolean unlock(String key) throws MessagingException {
        return false;  // trivial implementation
    }
}
<commit_msg>Some James component rely on the mail cloning made by repositories. 1) Repositories are persistent (changing a mail after the store call should not change the stored instance) 2) Multiple calls to retrieve provides different instances: changes to one of the retrieved message must not change the original stored mail or other retrieved copies.<commit_after>/***********************************************************************
 * Copyright (c) 2000-2006 The Apache Software Foundation.             *
 * All rights reserved.                                                *
 * ------------------------------------------------------------------- *
 * Licensed under the Apache License, Version 2.0 (the "License"); you *
 * may not use this file except in compliance with the License. You    *
 * may obtain a copy of the License at:                                *
 *                                                                     *
 *     http://www.apache.org/licenses/LICENSE-2.0                      *
 *                                                                     *
 * Unless required by applicable law or agreed to in writing, software *
 * distributed under the License is distributed on an "AS IS" BASIS,   *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
 * implied.  See the License for the specific language governing       *
 * permissions and limitations under the License.                      *
 ***********************************************************************/


package org.apache.james.test.mock.james;

import org.apache.james.core.MailImpl;
import org.apache.james.services.MailRepository;
import org.apache.mailet.Mail;

import javax.mail.MessagingException;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Collection;

public class MockMailRepository implements MailRepository {
    
    private HashMap messages = new HashMap();

    public void store(Mail mc) throws MessagingException {
        this.messages.put(mc.getName(),new MailImpl(mc,mc.getName()));
    }

    public Iterator list() throws MessagingException {
        return messages.keySet().iterator();  // trivial implementation
    }

    public Mail retrieve(String key) throws MessagingException {
        return new MailImpl((Mail) messages.get(key),key);  // trivial implementation
    }

    public void remove(Mail mail) throws MessagingException {
        messages.remove(mail.getName());
    }

    public void remove(Collection mails) throws MessagingException {
        for (Iterator i = mails.iterator(); i.hasNext(); ) {
            Mail m = (Mail) i.next();
            messages.remove(m.getName());
        }
    }

    public void remove(String key) throws MessagingException {
        messages.remove(key);
    }

    public boolean lock(String key) throws MessagingException {
        return false;  // trivial implementation
    }

    public boolean unlock(String key) throws MessagingException {
        return false;  // trivial implementation
    }
}

{'fraction_non_alphanumeric': 0.14418925919530307, 'fraction_numerical': 0.0044897254360214125, 'mean_word_length': 2.0010362694300516, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7150675', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1216, 'n_words': 437}