List of usage examples for javax.mail.internet InternetAddress getPersonal
public String getPersonal()
From source file:org.beangle.notification.notifiers.mail.MimeUtils.java
public static final List<InternetAddress> parseAddress(String address, String encoding) { if (StringUtils.isEmpty(address)) return Collections.emptyList(); try {/*from w ww .j a v a 2 s . co m*/ InternetAddress[] parsed = InternetAddress.parse(address); List<InternetAddress> returned = CollectUtils.newArrayList(); for (InternetAddress raw : parsed) { returned.add((encoding != null ? new InternetAddress(raw.getAddress(), raw.getPersonal(), encoding) : raw)); } return returned; } catch (Exception ex) { throw new RuntimeException("Failed to parse embedded personal name to correct encoding", ex); } }
From source file:com.flexive.shared.FxMailUtils.java
private static InternetAddress[] encodePersonal(InternetAddress[] addresses) throws UnsupportedEncodingException { if (addresses == null) { return null; }/* ww w . j a va 2s . c o m*/ for (InternetAddress address : addresses) { if (address.getPersonal() != null) { address.setPersonal(address.getPersonal(), "UTF-8"); } } return addresses; }
From source file:com.flexive.shared.FxMailUtils.java
private static InternetAddress createAddress(String from) throws AddressException, UnsupportedEncodingException { final InternetAddress address = new InternetAddress(from); if (address.getPersonal() != null) { // encode name which is more likely to use non-ASCII characters address.setPersonal(address.getPersonal(), "UTF-8"); }/*ww w . j a va 2 s. com*/ return address; }
From source file:com.silverpeas.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 userDetail - contient les informations sur l'utilisateur du moteur d'importExport * @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 isPOIUsed * @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 (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<String, String>(); 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.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.extractMetadata(file.getAbsolutePath()); } if (metaData.getCreationDate() != null) { creationDate = metaData.getCreationDate(); } if (metaData.getLastSaveDateTime() != null) { lastModificationDate = metaData.getLastSaveDateTime(); } } } PublicationDetail publication = new PublicationDetail("unknown", nomPub, description, creationDate, new Date(), null, settings.getUser().getId(), "5", null, motsClefs, content); if (lastModificationDate != null) { publication.setUpdateDate(lastModificationDate); publication.setUpdateDateMustBeSet(true); } return publication; }
From source file:com.liferay.petra.mail.InternetAddressUtil.java
public static String toString(Address address) { InternetAddress internetAddress = (InternetAddress) address; if (internetAddress != null) { StringBundler sb = new StringBundler(5); String personal = internetAddress.getPersonal(); String emailAddress = internetAddress.getAddress(); if (Validator.isNotNull(personal)) { sb.append(personal);//from w w w .j av a2 s .c om sb.append(StringPool.SPACE); sb.append(StringPool.LESS_THAN); sb.append(emailAddress); sb.append(StringPool.GREATER_THAN); } else { sb.append(emailAddress); } return sb.toString(); } return StringPool.BLANK; }
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 w w . j a va 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:com.glaf.mail.util.MailUtils.java
public static String getMailAddress(Address aaddress[]) { String mailAddress = ""; if (aaddress != null) { try {/*from ww w . j a v a 2 s . c om*/ StringBuffer addrBuffer = new StringBuffer(); for (int j = 0; j < aaddress.length; j++) { InternetAddress internetaddress = (InternetAddress) aaddress[j]; if (internetaddress.getPersonal() == null || internetaddress.getPersonal().length() == 0) { addrBuffer.append(internetaddress.getAddress()).append(" < ") .append(internetaddress.getAddress()).append(" > "); } else { addrBuffer.append(internetaddress.getPersonal()).append(" < ") .append(internetaddress.getAddress()).append(" > "); } } String addr = addrBuffer.toString(); if (addr.startsWith("=?GBK?Q?=") || addr.startsWith("=?GB2312?Q?=")) { addr = convertString(addr); } mailAddress = addr; } catch (Exception ex) { } } return mailAddress; }
From source file:Main.java
public static String getAddressString(Address[] addresses) { if (addresses == null || addresses.length <= 0) { return ""; }/*from w w w . ja v a2 s . co m*/ HashSet<String> foundAddress = new HashSet<String>(); StringBuffer sb = new StringBuffer(); InternetAddress addr = null; int length = addresses.length; for (int i = 0; i < length; i++) { addr = (InternetAddress) addresses[i]; if (foundAddress.contains(addr.getAddress())) { continue; } foundAddress.add(addr.getAddress()); if (addr.getPersonal() != null) { String personaladdr = getOneString(getTokens(addr.getPersonal(), "\r\n"), ""); sb.append(personaladdr).append(" <").append(addr.getAddress()).append(">, "); } else { sb.append(addr.getAddress()).append(", "); } } String addressStr = sb.toString(); return addressStr.substring(0, addressStr.length() - 2); }
From source file:de.bht.fpa.mail.s000000.common.mail.imapsync.MessageConverter.java
private static void convertSender(javax.mail.Message javaMailMessage, MessageBuilder messageBuilder) throws MessagingException { Address[] from = javaMailMessage.getFrom(); if (from == null || from.length <= 0) { return;/*from ww w . j a v a 2 s .c om*/ } Address firstFrom = from[0]; if (!(firstFrom instanceof InternetAddress)) { return; } InternetAddress internetAddress = (InternetAddress) firstFrom; messageBuilder.sender( newSenderBuilder().email(internetAddress.getAddress()).personal(internetAddress.getPersonal())); }
From source file:de.bht.fpa.mail.s000000.common.mail.imapsync.MessageConverter.java
private static void addRecipients(MessageBuilder messageBuilder, RecipientType recipientType, Address[] recipients) {/*from w w w . ja v a 2s . co m*/ if (recipients == null) { return; } for (Address address : recipients) { if (!(address instanceof InternetAddress)) { continue; } InternetAddress internetAddress = (InternetAddress) address; // @formatter:off messageBuilder.recipient(newRecipientBuilder().email(internetAddress.getAddress()) .personal(internetAddress.getPersonal()).type(recipientType)); // @formatter:on } }