Example usage for javax.mail.internet InternetAddress getAddress

List of usage examples for javax.mail.internet InternetAddress getAddress

Introduction

In this page you can find the example usage for javax.mail.internet InternetAddress getAddress.

Prototype

public String getAddress() 

Source Link

Document

Get the email address.

Usage

From source file:mitm.common.mail.EmailAddressUtils.java

/**
 * See: getDomain(email)/*w w w. j  a  va2 s  .co  m*/
 */
public static String getDomain(InternetAddress email) {
    if (email == null) {
        return null;
    }

    return getDomain(email.getAddress());
}

From source file:mitm.common.mail.EmailAddressUtils.java

/**
 * See getLocalPart(String email)//from  w w w  . ja  va2 s  .  c  o  m
 */
public static String getLocalPart(InternetAddress email) {
    if (email == null) {
        return null;
    }

    return getLocalPart(email.getAddress());
}

From source file:mitm.common.mail.EmailAddressUtils.java

/**
 * Returns true if email is equal to INVALID_EMAIL (invalid@invalid.tld)
 *//*from w  w w. j a  va2  s  .  c om*/
public static boolean isInvalidDummyAddress(InternetAddress email) {
    if (email == null) {
        return false;
    }

    return INVALID_EMAIL.equals(email.getAddress());
}

From source file:org.elasticsearch.river.email.EmailToJson.java

static String[] convertAddress(Address[] input) {

    String[] addrs1 = new String[input.length];
    for (int i = 0; i < input.length; i++) {
        InternetAddress t = (InternetAddress) input[i];
        if (t != null) {
            addrs1[i] = t.getAddress();
        }/*  w  w w . j a  va  2  s  . c  o  m*/
    }
    return addrs1;
}

From source file:org.silverpeas.core.importexport.control.PublicationImportExport.java

/**
 * Mthodes permettant de rcuprer un objet publication dont les mta-donnes sont gnres 
 * partir des informations du fichier destin  tre attach  celle ci. Utilisation de l'api POI
 * dans le cas des fichiers MSoffice.//w ww  .  ja v a 2 s . c  o  m
 * @param file - fichier destin  tre attach  la publication d'o l'on extrait les
 * informations qui iront renseigner les mta-donnes de la publication  creer
 * @param settings the import export settings
 * @return renvoie un objet PublicationDetail
 */
public static PublicationDetail convertFileInfoToPublicationDetail(File file, ImportSettings settings) {
    String fileName = file.getName();
    String nomPub = settings.getPublicationName(fileName);
    String description = "";
    String motsClefs = "";
    String content = "";
    Date creationDate = new Date();
    Date lastModificationDate = null;

    if (!settings.mustCreateOnePublicationForAllFiles()) {
        if (FileUtil.isMail(file.getName())) {
            try {
                MailExtractor extractor = Extractor.getExtractor(file);
                Mail mail = extractor.getMail();

                creationDate = mail.getDate();

                // define StringTemplate attributes
                Map<String, String> attributes = new HashMap<>();
                attributes.put("subject", mail.getSubject());
                InternetAddress address = mail.getFrom();
                if (StringUtil.isDefined(address.getPersonal())) {
                    attributes.put("fromPersonal", address.getPersonal());
                    description += address.getPersonal() + " - ";
                }
                attributes.put("fromAddress", address.getAddress());

                // generate title of publication
                StringTemplate titleST = new StringTemplate(
                        multilang.getString("importExport.import.mail.title"));
                titleST.setAttributes(attributes);
                nomPub = titleST.toString();

                // generate description of publication
                StringTemplate descriptionST = new StringTemplate(
                        multilang.getString("importExport.import.mail.description"));
                descriptionST.setAttributes(attributes);
                description = descriptionST.toString();
            } catch (Exception e) {
                SilverTrace.error("importExport", "PublicationImportExport.convertFileInfoToPublicationDetail",
                        "importExport.EX_CANT_EXTRACT_MAIL_DATA", e);
            }
        } else {
            // it's a classical file (not an email)
            MetaData metaData = null;
            if (settings.isPoiUsed()) {
                // extract title, subject and keywords
                metaData = MetadataExtractor.get().extractMetadata(file.getAbsolutePath());
                if (StringUtil.isDefined(metaData.getTitle())) {
                    nomPub = metaData.getTitle();
                }
                if (StringUtil.isDefined(metaData.getSubject())) {
                    description = metaData.getSubject();
                }
                if (metaData.getKeywords() != null && metaData.getKeywords().length > 0) {
                    motsClefs = StringUtils.join(metaData.getKeywords(), ';');
                }
            }

            if (settings.useFileDates()) {
                // extract creation and last modification dates
                if (metaData == null) {
                    metaData = MetadataExtractor.get().extractMetadata(file.getAbsolutePath());
                }
                if (metaData.getCreationDate() != null) {
                    creationDate = metaData.getCreationDate();
                }
                if (metaData.getLastSaveDateTime() != null) {
                    lastModificationDate = metaData.getLastSaveDateTime();
                }
            }
        }
    } else {
        nomPub = settings.getPublicationForAllFiles().getName();
        description = settings.getPublicationForAllFiles().getDescription();
        motsClefs = settings.getPublicationForAllFiles().getKeywords();
        content = settings.getPublicationForAllFiles().getContentPagePath();
    }
    PublicationDetail publication = new PublicationDetail("unknown", nomPub, description, creationDate,
            new Date(), null, settings.getUser().getId(), "1", null, motsClefs, content);
    publication.setTargetValidatorId(settings.getTargetValidatorIds());
    publication.setLanguage(settings.getContentLanguage());
    if (lastModificationDate != null) {
        publication.setUpdateDate(lastModificationDate);
        publication.setUpdateDateMustBeSet(true);
    }
    return publication;
}

From source file:org.elasticsearch.river.email.EmailToJson.java

public static String getFrom(MimeMessage msg) throws MessagingException, UnsupportedEncodingException {
    String from = "";
    Address[] froms = msg.getFrom();/*from   w ww.  j  a v  a2  s  . c om*/
    if (froms.length < 1)
        throw new MessagingException("?!");

    InternetAddress address = (InternetAddress) froms[0];
    String person = address.getPersonal();
    if (person != null) {
        person = MimeUtility.decodeText(person) + " ";
    } else {
        person = "";
    }
    from = person + "<" + address.getAddress() + ">";

    return from;
}

From source file:com.aurel.track.util.emailHandling.MailReader.java

/**
 * Retrieves the senders e-mail address from this message.
 *
 * @param message/*  ww w. ja  v a  2s .  c om*/
 *            the message to be processed
 * @return the senders e-mail address
 */
public static String getSenderEmailAddress(Message message) {
    String from = null;
    try {
        if (message.getFrom() != null && message.getFrom().length > 0) {
            InternetAddress fromAddress = (InternetAddress) message.getFrom()[0];
            if (null != fromAddress) {
                from = fromAddress.getAddress();
            }
        } else {
            LOGGER.warn("No from sender address in message!");
        }
    } catch (Exception e) {
        // can't do much here
        LOGGER.warn("Can't get sender email address", e);
    }
    return from;
}

From source file:com.zimbra.cs.imap.ImapMessage.java

private static void address(PrintStream ps, InternetAddress addr) {
    String address = addr.getAddress().trim(), route = null;

    // handle obsolete route-addr
    int colon;/*  ww  w  . ja  v  a2  s. com*/
    if (address.startsWith("@") && (colon = address.indexOf(':')) != -1) {
        route = address.substring(0, colon);
        address = address.substring(colon + 1);
    }

    String[] parts = address.split("@", 2);
    ps.write('(');
    nstring2047(ps, addr.getPersonal());
    ps.write(' ');
    nstring(ps, route);
    ps.write(' ');
    nstring(ps, parts[0]);
    ps.write(' ');
    nstring(ps, parts.length > 1 ? parts[1] : null);
    ps.write(')');
}

From source file:immf.SendMailBridge.java

private static List<InternetAddress> getBccRecipients(List<String> allRecipients, List<InternetAddress> to,
        List<InternetAddress> cc) throws AddressException {
    List<String> addrList = new ArrayList<String>();
    List<String> toccAddrList = new ArrayList<String>();
    for (String addr : allRecipients) {
        addrList.add(addr);// w ww .  ja  va2  s .com
    }
    for (InternetAddress ia : to) {
        toccAddrList.add(ia.getAddress());
    }
    for (InternetAddress ia : cc) {
        toccAddrList.add(ia.getAddress());
    }
    addrList.removeAll(toccAddrList);
    List<InternetAddress> r = new ArrayList<InternetAddress>();
    for (String addr : addrList) {
        r.add(new InternetAddress(addr));
    }
    return r;
}

From source file:com.aurel.track.util.emailHandling.MailReader.java

/**
 * Retrieves the sender as a TPersonBean with first and last name
 *
 * @param message/* w w w .  ja v  a 2 s  . co  m*/
 *            the message to be processed
 * @return the sender
 */
public static TPersonBean getSender(Message message) {
    String from = null;
    TPersonBean sender = null;
    String firstName = "";
    String lastName = "";
    try {
        if (message.getFrom() != null && message.getFrom().length > 0) {
            InternetAddress fromAddress = (InternetAddress) message.getFrom()[0];
            if (null != fromAddress) {
                from = fromAddress.getAddress();
                String name = fromAddress.getPersonal();
                if (name != null && !"".equals(name)) {
                    String nameparts[] = name.split("\\s+");
                    for (int i = 0; i < nameparts.length - 1; ++i) {
                        firstName = firstName + " " + nameparts[i];
                    }
                    firstName = firstName.trim();
                    lastName = nameparts[nameparts.length - 1];
                }
                sender = new TPersonBean();
                sender.setEmail(from);
                sender.setFirstName(firstName);
                sender.setLastName(lastName);
            }
        } else {
            LOGGER.warn("No from sender address in message!");
        }
    } catch (Exception e) {
        // can't do much here
        LOGGER.warn("Can't get sender email address", e);
    }
    return sender;
}