use of com.zimbra.common.mime.shim.JavaMailInternetAddress in project zm-mailbox by Zimbra.
the class IDNUtil method toAsciiWithPersonalPart.
private static String toAsciiWithPersonalPart(String name) {
String asciiName = name;
// extract out the domain, convert it to ACE, and put it back
Matcher m = S_DOMAIN.matcher(name);
if (m.matches() && m.groupCount() == 4) {
// if matches(), then groupCount() must be 4 according to our regex, just to be safe
String domain = m.group(3);
String asciiDomain = toAsciiDomainName(domain);
// put everything back
asciiName = m.group(1) + m.group(2) + asciiDomain + m.group(4);
}
try {
InternetAddress ia = new JavaMailInternetAddress(asciiName);
String personal = ia.getPersonal();
if (personal != null)
ia = new JavaMailInternetAddress(ia.getAddress(), personal, MimeConstants.P_CHARSET_UTF8);
/*
* note, if personal part contains non-ascii chars, it will be
* converted (by InternetAddress.toString()) to RFC 2047 encoded address.
* The resulting string contains only US-ASCII characters, and
* hence is mail-safe.
*
* e.g. a personal part: \u4e2d\u6587
* will be converted to =?utf-8?B?5Lit5paH?=
* and stored in LDAP in the encoded form
*/
return ia.toString();
} catch (UnsupportedEncodingException e) {
ZimbraLog.account.info("cannot convert to ascii, returning original addr: [" + name + "]", e);
} catch (AddressException e) {
ZimbraLog.account.info("cannot convert to ascii, returning original addr: [" + name + "]", e);
}
return name;
}
use of com.zimbra.common.mime.shim.JavaMailInternetAddress in project zm-mailbox by Zimbra.
the class Identity method getFriendlyEmailAddress.
public InternetAddress getFriendlyEmailAddress() {
String personalPart = getAttr(Provisioning.A_zimbraPrefFromDisplay);
if (personalPart == null || personalPart.trim().equals(""))
personalPart = null;
String address = getAttr(Provisioning.A_zimbraPrefFromAddress);
try {
return new JavaMailInternetAddress(address, personalPart, MimeConstants.P_CHARSET_UTF8);
} catch (UnsupportedEncodingException e) {
}
// UTF-8 should *always* be supported (i.e. this is actually unreachable)
try {
// fall back to using the system's default charset (also pretty much guaranteed not to be "unsupported")
return new JavaMailInternetAddress(address, personalPart);
} catch (UnsupportedEncodingException e) {
}
// if we ever reached this point (which we won't), just return an address with no personal part
InternetAddress ia = new JavaMailInternetAddress();
ia.setAddress(address);
return ia;
}
use of com.zimbra.common.mime.shim.JavaMailInternetAddress in project zm-mailbox by Zimbra.
the class AttributeInfo method validEmailAddress.
public static void validEmailAddress(String addr, boolean personal) throws ServiceException {
if (addr.indexOf('@') == -1)
throw AccountServiceException.INVALID_ATTR_VALUE("address '" + addr + "' does not include domain", null);
try {
InternetAddress ia = new JavaMailInternetAddress(addr, true);
// is this even needed?
ia.validate();
if (!personal && ia.getPersonal() != null && !ia.getPersonal().equals(""))
throw AccountServiceException.INVALID_ATTR_VALUE("invalid email address: " + addr, null);
} catch (AddressException e) {
throw AccountServiceException.INVALID_ATTR_VALUE("invalid email address: " + addr, e);
}
}
use of com.zimbra.common.mime.shim.JavaMailInternetAddress in project zm-mailbox by Zimbra.
the class AutoProvision method sendNotifMessage.
protected void sendNotifMessage(Account acct, String password) throws ServiceException {
String subject = fillTemplate(acct, domain.getAutoProvNotificationSubject());
String body = fillTemplate(acct, domain.getAutoProvNotificationBody());
String from = domain.getAutoProvNotificationFromAddress();
if (from == null) {
// TODO: should we use a seperate boolean control?
return;
}
String toAddr = acct.getName();
try {
SMTPMessage out = AccountUtil.getSmtpMessageObj(acct);
InternetAddress addr = null;
try {
addr = new JavaMailInternetAddress(from);
} catch (AddressException e) {
// log and try the next one
ZimbraLog.autoprov.warn("invalid address in " + Provisioning.A_zimbraAutoProvNotificationFromAddress, e);
}
Address fromAddr = addr;
Address replyToAddr = addr;
// From
out.setFrom(fromAddr);
// Reply-To
out.setReplyTo(new Address[] { replyToAddr });
// To
out.setRecipient(javax.mail.Message.RecipientType.TO, new JavaMailInternetAddress(toAddr));
// Date
out.setSentDate(new Date());
// Subject
Locale locale = acct.getLocale();
out.setSubject(subject);
// NOTIFY=NEVER
out.setNotifyOptions(SMTPMessage.NOTIFY_NEVER);
// body
MimeMultipart mmp = new ZMimeMultipart("alternative");
// TEXT part (add me first!)
String text = body;
MimeBodyPart textPart = new ZMimeBodyPart();
textPart.setText(text, MimeConstants.P_CHARSET_UTF8);
mmp.addBodyPart(textPart);
// HTML part
StringBuilder html = new StringBuilder();
html.append("<h4>\n");
html.append("<p>" + body + "</p>\n");
html.append("</h4>\n");
html.append("\n");
MimeBodyPart htmlPart = new ZMimeBodyPart();
htmlPart.setDataHandler(new DataHandler(new HtmlPartDataSource(html.toString())));
mmp.addBodyPart(htmlPart);
out.setContent(mmp);
// send it
Transport.send(out);
// log
Address[] rcpts = out.getRecipients(javax.mail.Message.RecipientType.TO);
StringBuilder rcptAddr = new StringBuilder();
for (Address a : rcpts) rcptAddr.append(a.toString());
ZimbraLog.autoprov.info("auto provision notification sent rcpt='" + rcptAddr + "' Message-ID=" + out.getMessageID());
} catch (MessagingException e) {
ZimbraLog.autoprov.warn("send auto provision notification failed rcpt='" + toAddr + "'", e);
}
}
use of com.zimbra.common.mime.shim.JavaMailInternetAddress in project zm-mailbox by Zimbra.
the class CalendarMailSender method createOrganizerChangeMessage.
public static MimeMessage createOrganizerChangeMessage(Account fromAccount, Account authAccount, boolean asAdmin, CalendarItem calItem, Invite inv, List<Address> rcpts) throws ServiceException {
ZOrganizer organizer = inv.getOrganizer();
assert (organizer != null);
boolean onBehalfOf = organizer.hasSentBy();
String senderAddr = onBehalfOf ? organizer.getSentBy() : organizer.getAddress();
Locale locale = fromAccount.getLocale();
boolean hidePrivate = !calItem.isPublic() && !calItem.allowPrivateAccess(authAccount, asAdmin);
String subject;
if (hidePrivate) {
subject = L10nUtil.getMessage(MsgKey.calendarSubjectWithheld, locale);
} else {
subject = inv.getName();
}
StringBuilder sb = new StringBuilder("Organizer has been changed to " + fromAccount.getName());
sb.append("\r\n\r\n");
if (!hidePrivate) {
MimeMessage mmInv = inv.getMimeMessage();
if (mmInv != null) {
attachInviteSummary(sb, inv, mmInv, locale);
}
}
ZVCalendar iCal = inv.newToICalendar(true);
Address from = AccountUtil.getFriendlyEmailAddress(fromAccount);
Address sender = null;
if (onBehalfOf) {
try {
sender = new JavaMailInternetAddress(senderAddr);
} catch (AddressException e) {
throw MailServiceException.ADDRESS_PARSE_ERROR(e);
}
}
return createCalendarMessage(authAccount, from, sender, rcpts, subject, sb.toString(), null, inv.getUid(), iCal);
}
Aggregations