Search in sources :

Example 21 with Contact

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

the class NameExpansion method getMatches.

/* Given the string s in emailDocument ed, returns a matches object with candidates matching s */
public static Matches getMatches(String s, Archive archive, EmailDocument ed, int maxResults) {
    Matches matches = new Matches(s, maxResults);
    AddressBook ab = archive.addressBook;
    List<Contact> contactsExceptSelf = ed.getParticipatingContactsExceptOwn(archive.addressBook);
    List<Contact> contacts = new ArrayList(contactsExceptSelf);
    contacts.add(ab.getContactForSelf());
    // check if s matches any contacts on this message
    outer: for (Contact c : contacts) {
        if (c.getNames() == null)
            continue;
        for (String name : c.getNames()) {
            StringMatchType matchType = Matches.match(s, name);
            if (matchType != null) {
                float score = 1.0F;
                if (matches.addMatch(name, score, matchType, "Name of a contact on this message", true))
                    return matches;
                continue outer;
            }
        }
    }
    // check if s matches anywhere else in this message
    if (matchAgainstEmailContent(archive, ed, matches, "Mentioned elsewhere in this message", 1.0F)) {
        return matches;
    }
    synchronized (archive) {
        if (ed.threadID == 0L) {
            archive.assignThreadIds();
        }
    }
    // check if s matches anywhere else in this thread
    List<EmailDocument> messagesInThread = (List) archive.docsWithThreadId(ed.threadID);
    for (EmailDocument messageInThread : messagesInThread) {
        if (matchAgainstEmailContent(archive, messageInThread, matches, "Mentioned in this thread", 0.9F)) {
            return matches;
        }
    }
    // check if s matches any other email with any of these correspondents
    for (Contact c : contactsExceptSelf) {
        if (c.getEmails() != null) {
            String correspondentsSearchStr = String.join(";", c.getEmails());
            // As filterForCorrespondents function do not use queryparams therefore it is fine to instantiate SearchResult
            // object with queryParams as null. After refactoring, filter methods take SearchObject as input and modify it
            // according to the filter.
            SearchResult inputSet = new SearchResult(archive, null);
            SearchResult outputSet = SearchResult.filterForCorrespondents(inputSet, correspondentsSearchStr, true, true, true, true);
            Set<Document> messagesWithSameCorrespondents = outputSet.getDocumentSet();
            for (Document messageWithSameCorrespondents : messagesWithSameCorrespondents) {
                EmailDocument edoc = (EmailDocument) messageWithSameCorrespondents;
                if (matchAgainstEmailContent(archive, edoc, matches, "Mentioned in other messages with these correspondents", 0.8F)) {
                    return matches;
                }
            }
        }
    }
    // search for s anywhere in the archive
    Multimap<String, String> params = LinkedHashMultimap.create();
    params.put("termSubject", "on");
    params.put("termBody", "on");
    String term = s;
    if (s.contains(" ") && (!s.startsWith("\"") || !s.endsWith("\""))) {
        term = "\"" + s + "\"";
    }
    // To search for terms, create a searchResult object and invoke appropriate filter method on it.
    SearchResult inputSet = new SearchResult(archive, params);
    SearchResult outputSet = SearchResult.searchForTerm(inputSet, term);
    Set<Document> docsWithTerm = outputSet.getDocumentSet();
    for (Document docWithTerm : docsWithTerm) {
        EmailDocument edoc = (EmailDocument) docWithTerm;
        if (matchAgainstEmailContent(archive, edoc, matches, "Mentioned elsewhere in this archive", 0.7F))
            return matches;
    }
    return matches;
}
Also used : EmailDocument(edu.stanford.muse.index.EmailDocument) SearchResult(edu.stanford.muse.index.SearchResult) Document(edu.stanford.muse.index.Document) EmailDocument(edu.stanford.muse.index.EmailDocument) Contact(edu.stanford.muse.AddressBookManager.Contact) AddressBook(edu.stanford.muse.AddressBookManager.AddressBook)

Example 22 with Contact

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

the class SearchResult method filterForMailingListState.

/**
 * returns only the docs matching per params[mailingListState].
 * If this value is either, no filtering is done.
 * if set to yes, only docs with at least one address matching a mailing list are returned.
 */
private static SearchResult filterForMailingListState(SearchResult inputSet) {
    String mailingListState = JSPHelper.getParam(inputSet.queryParams, "mailingListState");
    AddressBook ab = inputSet.archive.addressBook;
    if ("either".equals(mailingListState) || Util.nullOrEmpty(mailingListState))
        return inputSet;
    // keep on removing those documents from allDocs which do not satisfy the filter conditions.
    inputSet.matchedDocs = inputSet.matchedDocs.entrySet().stream().filter(k -> {
        EmailDocument ed = (EmailDocument) k.getKey();
        Collection<Contact> contactsInMessage = EmailUtils.getContactsForMessage(ab, ed);
        // is any of these addresses a ML?
        boolean atLeastOneML = false;
        for (Contact c : contactsInMessage) {
            boolean isMailingList = (c.mailingListState & MailingList.SUPER_DEFINITE) != 0 || (c.mailingListState & MailingList.USER_ASSIGNED) != 0;
            if (isMailingList && "no".equals(mailingListState))
                // continue outer; // we don't want mailing lists, but found one associated with this message. therefore this message fails search.
                return false;
            if (isMailingList)
                // mark this message as having at least one ML
                atLeastOneML = true;
        }
        if (!atLeastOneML && "yes".equals(mailingListState))
            // continue outer; // no ML, but search criteria need ML, so ignore this ed
            return false;
        // result.add(ed);
        return true;
    }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    return inputSet;
}
Also used : AddressBook(edu.stanford.muse.AddressBookManager.AddressBook) Contact(edu.stanford.muse.AddressBookManager.Contact)

Example 23 with Contact

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

the class SearchResult method filterForContactId.

/**
 * returns only the docs matching the given contact id. used by facets, correspondents table, etc
 */
private static SearchResult filterForContactId(SearchResult inputSet, String cid) {
    AddressBook ab = inputSet.archive.addressBook;
    int contactId = -1;
    try {
        contactId = Integer.parseInt(cid);
    } catch (NumberFormatException nfe) {
        Util.print_exception("Bad contactId in filterForContactId", nfe, log);
    }
    if (contactId >= 0) {
        Contact c = ab.getContact(contactId);
        // now get the set of documents from addressbook summary object because we have already calculated that.
        Set<EmailDocument> docs = ab.getDocsFromSummary(c);
        inputSet.matchedDocs.keySet().retainAll(docs);
        // add this information to body highlight object under "contact" key
        inputSet.commonHLInfo.addContact(contactId);
    }
    /* //highlighting info addition
        try {
            int ci = Integer.parseInt(cid);
            //add this information to body highlight object under "contact" key
            inputSet.commonHLInfo.addContact(ci);
        } catch (Exception e) {
            JSPHelper.log.warn(cid + " is not a contact id");
        }
        return filterForCorrespondents(inputSet, correspondentName, true, true, true, true); // for contact id, all the 4 fields - to/from/cc/bcc are enabled*/
    return inputSet;
}
Also used : AddressBook(edu.stanford.muse.AddressBookManager.AddressBook) Contact(edu.stanford.muse.AddressBookManager.Contact)

Example 24 with Contact

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

the class EmailDocument method getParticipatingContactsExceptOwn.

/* get all participating addrs in this email message,
	 * including to, cc, bcc, etc.
	 * exclude oneself. the sole exception is the special case
	 * when own addrs contains both the sender and all receivers.
	 * ownaddrs can be null or empty.
	 */
public List<Contact> getParticipatingContactsExceptOwn(AddressBook addressBook) {
    List<Contact> result = new ArrayList<>();
    Contact self = addressBook.getContactForSelf();
    // getParticipatingAddrsExcept(addressBook.getOwnAddrs());
    List<String> rawEmailAddrs = getAllAddrs();
    for (String s : rawEmailAddrs) {
        Contact c = addressBook.lookupByEmail(s);
        if (c != null && c != self)
            result.add(c);
    }
    return result;
}
Also used : Contact(edu.stanford.muse.AddressBookManager.Contact)

Example 25 with Contact

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

the class EmailDocument method isThirdPartyName.

public boolean isThirdPartyName(AddressBook ab, String s) {
    if (ab == null || s == null)
        return true;
    // get all the involved addresses
    List<String> addrs = this.getAllAddrs();
    // assemble tokens within the names for each address, e.g. "Sudheendra" and "Hangal" are 2 tokens for the addr hangal@cs.stanford.edu
    Set<String> nameTokens = new LinkedHashSet<>();
    for (String addr : addrs) {
        Contact c = ab.lookupByEmail(addr);
        if (c == null || c.getNames() == null)
            continue;
        for (String name : c.getNames()) for (String token : Util.tokenize(name)) nameTokens.add(token.toLowerCase());
    }
    return !nameTokens.contains(s.toLowerCase());
}
Also used : Contact(edu.stanford.muse.AddressBookManager.Contact)

Aggregations

Contact (edu.stanford.muse.AddressBookManager.Contact)27 AddressBook (edu.stanford.muse.AddressBookManager.AddressBook)10 InternetAddress (javax.mail.internet.InternetAddress)7 Address (javax.mail.Address)6 JSONObject (org.json.JSONObject)5 Blob (edu.stanford.muse.datacache.Blob)4 Pair (edu.stanford.muse.util.Pair)4 Util (edu.stanford.muse.util.Util)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 JSONArray (org.json.JSONArray)4 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)3 Multimap (com.google.common.collect.Multimap)3 EmailUtils (edu.stanford.muse.util.EmailUtils)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 MailingList (edu.stanford.muse.AddressBookManager.MailingList)2 AnnotationManager (edu.stanford.muse.AnnotationManager.AnnotationManager)2 Config (edu.stanford.muse.Config)2 BlobStore (edu.stanford.muse.datacache.BlobStore)2