Search in sources :

Example 1 with MailingList

use of edu.stanford.muse.AddressBookManager.MailingList in project epadd by ePADD.

the class EmailDocument method setOwners.

/*
    This method combines the contacts corresponding to the passed email addresses and set the resultant contact as owner.
     */
public static void setOwners(Archive archive, Set<String> emailAddresses) {
    AddressBook ab = archive.getAddressBook();
    // get contacts for these email addresses.
    Set<Contact> ofInterest = emailAddresses.stream().map(emailAddress -> ab.lookupByEmail(emailAddress)).collect(Collectors.toSet());
    if (ofInterest.size() == 1) {
        // if single element in the set ofInterest then simply set it as owner and recompute summary
        Contact newowner = ofInterest.iterator().next();
        ab.setContactForSelf(newowner);
        ab.fillL1_SummaryObject(archive.getAllDocs());
    } else {
        // if multiple elements in the set ofInterest then
        // combine them to create a new contact.
        Contact newone = new Contact();
        // MailingList ml=null;
        ofInterest.forEach(contact -> {
            newone.merge(contact);
        // if(ml==null && ab.mailingListMap.containsKey(contact))
        // ml = ab.mailingListMap.get(contact);
        });
        // set it as ML if any of the contact is ML.-- NOT DONE
        // add contact to contactListForIds
        ab.contactListForIds.add(newone);
        // remove all these contacts (obtained from the input email addresses)
        ab.removeContacts(ofInterest);
        // set the newly create contact as owner.
        ab.setContactForSelf(newone);
    // recompute L1 summary,not needed now. Just make sure that the caller is invoking it after completion of this method.
    // just to avoid unnecessary duplication of this call.
    // ab.fillL1_SummaryObject(archive.getAllDocs());
    }
}
Also used : Address(javax.mail.Address) CalendarUtil(edu.stanford.muse.email.CalendarUtil) java.util(java.util) AddressBook(edu.stanford.muse.AddressBookManager.AddressBook) Blob(edu.stanford.muse.datacache.Blob) MailingList(edu.stanford.muse.AddressBookManager.MailingList) Util(edu.stanford.muse.util.Util) JSPHelper(edu.stanford.muse.webapp.JSPHelper) EmailFetcherThread(edu.stanford.muse.email.EmailFetcherThread) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) InternetAddress(javax.mail.internet.InternetAddress) JSONException(org.json.JSONException) Contact(edu.stanford.muse.AddressBookManager.Contact) Logger(org.apache.logging.log4j.Logger) JSONObject(org.json.JSONObject) GeneralSecurityException(java.security.GeneralSecurityException) java.io(java.io) EmailUtils(edu.stanford.muse.util.EmailUtils) LogManager(org.apache.logging.log4j.LogManager) LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) AddressBook(edu.stanford.muse.AddressBookManager.AddressBook) Contact(edu.stanford.muse.AddressBookManager.Contact)

Aggregations

LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)1 AddressBook (edu.stanford.muse.AddressBookManager.AddressBook)1 Contact (edu.stanford.muse.AddressBookManager.Contact)1 MailingList (edu.stanford.muse.AddressBookManager.MailingList)1 Blob (edu.stanford.muse.datacache.Blob)1 CalendarUtil (edu.stanford.muse.email.CalendarUtil)1 EmailFetcherThread (edu.stanford.muse.email.EmailFetcherThread)1 EmailUtils (edu.stanford.muse.util.EmailUtils)1 Util (edu.stanford.muse.util.Util)1 JSPHelper (edu.stanford.muse.webapp.JSPHelper)1 java.io (java.io)1 GeneralSecurityException (java.security.GeneralSecurityException)1 java.util (java.util)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Address (javax.mail.Address)1 InternetAddress (javax.mail.internet.InternetAddress)1 StringUtils (org.apache.commons.lang3.StringUtils)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1