use of javax.mail.internet.AddressException in project iaf by ibissource.
the class IbisExceptionTest method testRecursiveExceptionMessageSearchUseToStringShort.
@Test
public void testRecursiveExceptionMessageSearchUseToStringShort() {
String rootMessage = "rootmsg";
Exception rootException = new AddressException(rootMessage);
String message2 = rootException.toString();
Exception exception2 = new IbisException(message2, rootException);
String result = exception2.getMessage();
assertEquals("(AddressException) " + rootMessage, result);
}
use of javax.mail.internet.AddressException in project iaf by ibissource.
the class MailFileSystemUtils method getValidAddress.
public static String getValidAddress(String type, String address) {
try {
if (StringUtils.isEmpty(address)) {
return null;
}
InternetAddress[] addresses = InternetAddress.parseHeader(address, true);
if (addresses.length == 0) {
return null;
}
StringBuffer result = new StringBuffer();
for (InternetAddress iaddress : addresses) {
String personal = iaddress.getPersonal();
if (personal != null) {
iaddress.setPersonal(iaddress.getPersonal().trim());
}
if (result.length() != 0) {
result.append(", ");
}
result.append(iaddress.toUnicodeString());
}
return result.toString();
} catch (AddressException | UnsupportedEncodingException e) {
log.warn("type [" + type + "] address [" + address + "] is invalid: " + e.getMessage());
return null;
}
}
use of javax.mail.internet.AddressException in project zm-mailbox by Zimbra.
the class ZEmailAddress method parseAddresses.
/**
* @param type type of addresses to create in the returned list.
* @see com.zimbra.client.ZEmailAddress EMAIL_TYPE_TO, etc.
* @return list of ZEMailAddress obejcts.
* @throws ServiceException
*/
public static List<ZEmailAddress> parseAddresses(String line, String type) throws ServiceException {
try {
line = line.replace(";", ",");
InternetAddress[] inetAddrs = JavaMailInternetAddress.parseHeader(line, false);
List<ZEmailAddress> result = new ArrayList<ZEmailAddress>(inetAddrs.length);
for (InternetAddress ia : inetAddrs) {
result.add(new ZEmailAddress(ia.getAddress().replaceAll("\"", ""), null, ia.getPersonal(), type));
}
return result;
} catch (AddressException e) {
throw ServiceException.INVALID_REQUEST("Couldn't parse address", e);
}
}
use of javax.mail.internet.AddressException in project zm-mailbox by Zimbra.
the class ScheduleOutbox method handleEventRequest.
private void handleEventRequest(DavContext ctxt, ZCalendar.ZVCalendar cal, ZComponent req, DelegationInfo delegationInfo, String rcpt, Element resp) throws ServiceException, DavException {
if (!DavResource.isSchedulingEnabled()) {
resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
resp.addElement(DavElements.E_REQUEST_STATUS).setText("5.3;No scheduling for the user");
return;
}
ArrayList<Address> recipients = new java.util.ArrayList<Address>();
InternetAddress from, sender, to;
Account target = null;
try {
sender = new JavaMailInternetAddress(delegationInfo.getOriginatorEmail());
Provisioning prov = Provisioning.getInstance();
if (ctxt.getActingAsDelegateFor() != null) {
target = prov.getAccountByName(ctxt.getActingAsDelegateFor());
}
if (target != null) {
from = AccountUtil.getFriendlyEmailAddress(target);
} else {
if (delegationInfo.getOwnerEmail() != null) {
from = new JavaMailInternetAddress(delegationInfo.getOwnerEmail());
} else {
target = getMailbox(ctxt).getAccount();
if (AccountUtil.addressMatchesAccount(target, delegationInfo.getOriginatorEmail())) {
// Make sure we don't use two different aliases for From and Sender.
// This is a concern with Apple iCal, which picks a random alias as originator.
from = sender;
} else {
from = AccountUtil.getFriendlyEmailAddress(target);
}
}
}
if (sender.getAddress() != null && sender.getAddress().equalsIgnoreCase(from.getAddress())) {
sender = null;
}
to = new JavaMailInternetAddress(CalDavUtils.stripMailto(rcpt));
recipients.add(to);
} catch (AddressException e) {
resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
resp.addElement(DavElements.E_REQUEST_STATUS).setText("3.7;" + rcpt);
return;
}
String status = req.getPropVal(ICalTok.STATUS, "");
String method = cal.getPropVal(ICalTok.METHOD, "REQUEST");
String subject = "";
if (method.equals("REQUEST")) {
ZProperty organizerProp = req.getProperty(ICalTok.ORGANIZER);
if (organizerProp != null) {
String organizerStr = this.getAddressFromPrincipalURL(new ZOrganizer(organizerProp).getAddress());
if (!AccountUtil.addressMatchesAccount(getMailbox(ctxt).getAccount(), organizerStr)) {
ZimbraLog.dav.debug("scheduling appointment on behalf of %s", organizerStr);
}
}
} else if (method.equals("REPLY")) {
ZProperty attendeeProp = req.getProperty(ICalTok.ATTENDEE);
if (attendeeProp == null)
throw new DavException("missing property ATTENDEE", HttpServletResponse.SC_BAD_REQUEST);
ZAttendee attendee = new ZAttendee(attendeeProp);
String partStat = attendee.getPartStat();
if (partStat.equals(IcalXmlStrMap.PARTSTAT_ACCEPTED)) {
subject = "Accept: ";
} else if (partStat.equals(IcalXmlStrMap.PARTSTAT_TENTATIVE)) {
subject = "Tentative: ";
} else if (partStat.equals(IcalXmlStrMap.PARTSTAT_DECLINED)) {
subject = "Decline: ";
}
}
if (status.equals("CANCELLED"))
subject = "Cancelled: ";
subject += req.getPropVal(ICalTok.SUMMARY, "");
String uid = req.getPropVal(ICalTok.UID, null);
if (uid == null) {
resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
resp.addElement(DavElements.E_REQUEST_STATUS).setText("3.1;UID");
return;
}
try {
List<Invite> components = Invite.createFromCalendar(ctxt.getAuthAccount(), null, cal, false);
FriendlyCalendaringDescription friendlyDesc = new FriendlyCalendaringDescription(components, ctxt.getAuthAccount());
String desc = friendlyDesc.getAsPlainText();
String descHtml = req.getDescriptionHtml();
if ((descHtml == null) || (descHtml.length() == 0))
descHtml = friendlyDesc.getAsHtml();
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(ctxt.getAuthAccount());
MimeMessage mm = CalendarMailSender.createCalendarMessage(target, from, sender, recipients, subject, desc, descHtml, uid, cal);
mbox.getMailSender().setSendPartial(true).sendMimeMessage(ctxt.getOperationContext(), mbox, true, mm, null, null, null, null, false);
} catch (ServiceException e) {
resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
resp.addElement(DavElements.E_REQUEST_STATUS).setText("5.1");
return;
}
resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
resp.addElement(DavElements.E_REQUEST_STATUS).setText("2.0;Success");
}
use of javax.mail.internet.AddressException in project zm-mailbox by Zimbra.
the class Notification method notifyIfNecessary.
/**
* If the recipient's account is set up for email notification, sends a notification
* message to the user's notification address.
*/
private void notifyIfNecessary(Account account, Message msg, String rcpt) throws MessagingException, ServiceException {
// Does user have new mail notification turned on
boolean notify = account.getBooleanAttr(Provisioning.A_zimbraPrefNewMailNotificationEnabled, false);
if (!notify) {
return;
}
// Validate notification address
String destination = account.getAttr(Provisioning.A_zimbraPrefNewMailNotificationAddress);
if (destination == null) {
nfailed("destination not set", null, rcpt, msg, null);
return;
}
try {
new JavaMailInternetAddress(destination);
} catch (AddressException ae) {
nfailed("invalid destination", destination, rcpt, msg, ae);
return;
}
// filter rules, we assume it's not interesting.
if (msg.inSpam()) {
nfailed("in spam", destination, rcpt, msg);
return;
}
try {
if (msg.inTrash()) {
nfailed("in trash", destination, rcpt, msg);
return;
}
} catch (ServiceException e) {
nfailed("call to Message.inTrash() failed", destination, rcpt, msg, e);
return;
}
// If precedence is bulk or junk
MimeMessage mm = msg.getMimeMessage();
String[] precedence = mm.getHeader("Precedence");
if (hasPrecedence(precedence, "bulk")) {
nfailed("precedence bulk", destination, rcpt, msg);
return;
}
if (hasPrecedence(precedence, "junk")) {
nfailed("precedence junk", destination, rcpt, msg);
return;
}
// Check for mail loop
String[] autoSubmittedHeaders = mm.getHeader("Auto-Submitted");
if (autoSubmittedHeaders != null) {
for (int i = 0; i < autoSubmittedHeaders.length; i++) {
String headerValue = autoSubmittedHeaders[i].toLowerCase();
if (headerValue.indexOf("notification") != -1) {
nfailed("detected a mail loop", destination, rcpt, msg);
return;
}
}
}
// Send the message
try {
Domain domain = Provisioning.getInstance().getDomain(account);
Session smtpSession = JMSession.getSmtpSession(domain);
// Assemble message components
MimeMessage out = assembleNotificationMessage(account, msg, rcpt, destination, smtpSession);
if (out == null) {
return;
}
String envFrom = "<>";
try {
if (!Provisioning.getInstance().getConfig().getBooleanAttr(Provisioning.A_zimbraAutoSubmittedNullReturnPath, true)) {
envFrom = account.getName();
}
} catch (ServiceException se) {
ZimbraLog.mailbox.warn("error encoutered looking up return path configuration, using null return path instead", se);
}
smtpSession.getProperties().setProperty("mail.smtp.from", envFrom);
Transport.send(out);
MailSender.logMessage(out, out.getAllRecipients(), envFrom, smtpSession.getProperties().getProperty("mail.smtp.host"), String.valueOf(msg.getId()), null, null, "notify");
} catch (MessagingException me) {
nfailed("send failed", destination, rcpt, msg, me);
}
}
Aggregations