Example usage for javax.mail.internet InternetAddress toUnicodeString

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

Introduction

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

Prototype

public String toUnicodeString() 

Source Link

Document

Returns a properly formatted address (RFC 822 syntax) of Unicode characters.

Usage

From source file:immf.Util.java

public static String getHeaderInfo(ImodeMail imm, boolean isHtml, boolean subjectEmojiReplace, Config conf) {
    StringBuilder buf = new StringBuilder();
    StringBuilder header = new StringBuilder();

    header.append(" From:    ").append(imm.getFromAddr().toUnicodeString()).append("\r\n");

    String label = " To:";
    if (imm.getRecvType() == ImodeMail.RECV_TYPE_TO && imm.getFolderId() != ImodeNetClient.FolderIdSent) {
        header.append(label + "      ").append(imm.getMyMailAddr()).append("\r\n");
        label = "    ";
    }/* w  ww .  jav a 2  s  . c  o m*/
    for (InternetAddress addr : imm.getToAddrList()) {
        header.append(label + "      ").append(addr.toUnicodeString()).append("\r\n");
        label = "    ";
    }
    String prefix = " Cc:";
    if (imm.getRecvType() == ImodeMail.RECV_TYPE_CC && imm.getFolderId() != ImodeNetClient.FolderIdSent) {
        header.append(prefix + "      ").append(imm.getMyMailAddr()).append("\r\n");
        label = "    ";
    }
    for (InternetAddress addr : imm.getCcAddrList()) {
        header.append(prefix + "      ").append(addr.toUnicodeString()).append("\r\n");
        prefix = "    ";
    }
    prefix = " Bcc:";
    if (imm.getRecvType() == ImodeMail.RECV_TYPE_BCC && imm.getFolderId() != ImodeNetClient.FolderIdSent) {
        header.append(" Bcc:     ").append(imm.getMyMailAddr()).append("\r\n");
    }

    SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd (EEE) HH:mm:ss");
    header.append(" Date:    ").append(df.format(imm.getTimeDate())).append("\r\n");
    String subject = imm.getSubject();
    if (subjectEmojiReplace) {
        subject = EmojiUtil.replaceToLabel(subject);
    }
    header.append(" Subject: ").append(subject).append("\r\n");

    for (String s : imm.getOtherInfoList()) {
        header.append(" :").append(s).append("\r\n");
    }

    if (isHtml) {
        String fontfamily = conf.getMailFontFamily();
        if (fontfamily != null) {
            buf.append("<pre style=\"white-space:pre-wrap;word-wrap:break-word;font-family:\'" + fontfamily
                    + "\';\">");
        } else {
            buf.append("<pre style=\"white-space:pre-wrap;word-wrap:break-word;\">");
        }
    }
    buf.append("----").append("\r\n");
    if (isHtml) {
        buf.append(Util.easyEscapeHtml(header.toString()));
    } else {
        buf.append(header.toString());
    }
    buf.append("----").append("\r\n");
    if (isHtml) {
        buf.append("</pre>");
    }
    buf.append("\r\n");
    return buf.toString();
}

From source file:com.cubusmail.mail.util.MessageUtils.java

/**
 * @param emailAddress/*from  ww w.ja v  a2  s .  c om*/
 * @param displayName
 * @return
 */
public static String toInternetAddress(String emailAddress, String displayName) {

    InternetAddress address;
    try {
        if (!StringUtils.isEmpty(displayName)) {
            address = new InternetAddress(emailAddress, displayName);
            return address.toUnicodeString();
        } else {
            return emailAddress;
        }
    } catch (UnsupportedEncodingException e) {
        return null;
    }
}

From source file:immf.ImodeMail.java

public String toLoggingString() {
    StrBuilder buf = new StrBuilder();
    buf.appendln("FolderID     " + this.folderId);
    buf.appendln("MailID       " + this.mailId);
    buf.appendln("Subject      " + this.subject);
    buf.appendln("Time         " + this.mailId);
    buf.appendln("Decome       " + this.decomeFlg);
    buf.appendln("RecvType     " + this.recvType);
    buf.appendln("MyAddr       " + this.myAddr);
    buf.appendln("From         " + this.fromAddr.toUnicodeString());
    for (InternetAddress to : this.toAddrList) {
        buf.appendln("To           " + to.toUnicodeString());
    }/*from   w w  w . j a v  a  2  s .c o  m*/
    for (InternetAddress cc : this.ccAddrList) {
        buf.appendln("Cc           " + cc.toUnicodeString());
    }
    for (AttachedFile f : this.attachFileList) {
        buf.appendln("AttachFile ---- " + f.getFilename());
        buf.appendln("  ID            " + f.getId());
        buf.appendln("  ContentType   " + f.getContentType());
        buf.appendln("  Size          " + f.getData().length);
    }
    for (AttachedFile f : this.attachFileList) {
        buf.appendln("InlineFile ---- " + f.getFilename());
        buf.appendln("  ID            " + f.getId());
        buf.appendln("  ContentType   " + f.getContentType());
        buf.appendln("  Size          " + f.getData().length);
    }
    buf.appendln("Body -----");
    buf.appendln(this.body);
    buf.appendln("----------");
    return buf.toString();
}

From source file:org.jasig.portlet.emailpreview.dao.javamail.JavamailAccountDaoImpl.java

private String getFormattedAddresses(Address[] addresses) {
    List<String> recipientsList = new ArrayList<String>();
    String receiver = null;/*www.java  2s . c om*/
    if (addresses != null && addresses.length != 0) {
        for (Address adress : addresses) {
            if (INTERNET_ADDRESS_TYPE.equals(adress.getType())) {
                InternetAddress inet = (InternetAddress) adress;
                receiver = inet.toUnicodeString();
            } else {
                receiver = adress.toString();
            }
            recipientsList.add(receiver);
        }
    }
    return StringUtils.join(recipientsList, "; ").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
}

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

public static String getReceiveAddress(MimeMessage msg, Message.RecipientType type) throws MessagingException {
    StringBuilder receiveAddress = new StringBuilder();
    Address[] addresss = null;//from w w w.j a v a 2  s  . co  m
    if (type == null) {
        addresss = msg.getAllRecipients();
    } else {
        addresss = msg.getRecipients(type);
    }

    if (addresss == null || addresss.length < 1)
        return "";
    // throw new MessagingException("!");
    for (Address address : addresss) {
        InternetAddress internetAddress = (InternetAddress) address;
        receiveAddress.append(internetAddress.toUnicodeString()).append(",");
    }

    receiveAddress.deleteCharAt(receiveAddress.length() - 1); //??

    return receiveAddress.toString();
}