use of javax.mail.Address in project zm-mailbox by Zimbra.
the class ForwardCalendarItem method makeFwdMsg.
private static Pair<MimeMessage, MimeMessage> makeFwdMsg(Account senderAcct, Invite inv, MimeMessage mmInv, ZVCalendar cal, MimeMessage mmFwdWrapper, MimeBodyPart plainDesc, MimeBodyPart htmlDesc, boolean useFwdText) throws ServiceException, MessagingException, IOException {
// Set SENT-BY to sender's email address. Required by Outlook.
// Also, set ATTENDEEs to the forwardees. For consistency with Outlook.
setSentByAndAttendees(cal, AccountUtil.getFriendlyEmailAddress(senderAcct).getAddress(), mmFwdWrapper.getAllRecipients());
// From: and Sender: headers
Address from = null;
Address sender = null;
sender = AccountUtil.getFriendlyEmailAddress(senderAcct);
ZOrganizer org = inv.getOrganizer();
if (org != null) {
if (org.hasCn())
from = new JavaMailInternetAddress(org.getAddress(), org.getCn(), MimeConstants.P_CHARSET_UTF8);
else
from = new JavaMailInternetAddress(org.getAddress());
} else {
from = sender;
}
MimeMessage mm;
if (useFwdText) {
String plainDescStr = null;
String htmlDescStr = null;
if (plainDesc != null)
plainDescStr = (String) plainDesc.getContent();
if (htmlDesc != null)
htmlDescStr = (String) htmlDesc.getContent();
setDescProps(cal, plainDescStr, htmlDescStr);
mm = createMergedMessage(senderAcct, from, sender, mmInv, inv, cal, plainDesc, htmlDesc);
} else {
mm = CalendarMailSender.createCalendarMessage(senderAcct, from, sender, null, mmInv, inv, cal, false);
}
// Copy recipient headers from forward wrapper msg.
RecipientType[] rcptTypes = { RecipientType.TO, RecipientType.CC, RecipientType.BCC };
for (RecipientType rcptType : rcptTypes) {
Address[] rcpts = mmFwdWrapper.getRecipients(rcptType);
mm.setRecipients(rcptType, rcpts);
}
mm.setSubject(mmFwdWrapper.getSubject());
mm.saveChanges();
// Create a Forward Notification message if the invitation is originally from ZCS user.
MimeMessage notifyMimeMsg = null;
if (org != null) {
String orgAddress = org.getAddress();
Account orgAccount = Provisioning.getInstance().getAccountByName(orgAddress);
if (orgAccount != null && !orgAccount.getId().equals(senderAcct.getId())) {
notifyMimeMsg = CalendarMailSender.createForwardNotifyMessage(senderAcct, orgAccount, orgAddress, mmFwdWrapper.getAllRecipients(), inv);
}
}
return new Pair<MimeMessage, MimeMessage>(mm, notifyMimeMsg);
}
use of javax.mail.Address in project zm-mailbox by Zimbra.
the class CalendarMailSender method createCalendarInviteDeniedMessage.
private static MimeMessage createCalendarInviteDeniedMessage(Account fromAccount, Account senderAccount, boolean onBehalfOf, boolean allowPrivateAccess, Address toAddr, Invite inv, MsgKey bodyTextKey) throws ServiceException {
Locale locale = !onBehalfOf ? fromAccount.getLocale() : senderAccount.getLocale();
Identity fromIdentity = getTargetedIdentity(fromAccount, inv);
StringBuilder replyText = new StringBuilder();
String sigText = getSignatureText(fromAccount, fromIdentity, Provisioning.A_zimbraPrefCalendarAutoDenySignatureId);
if (sigText == null || sigText.length() < 1)
sigText = L10nUtil.getMessage(bodyTextKey, locale);
if (sigText != null && sigText.length() > 0)
replyText.append(sigText).append("\r\n");
attachInviteSummary(replyText, inv, null, locale);
String subject = L10nUtil.getMessage(MsgKey.calendarReplySubjectDecline, locale) + ": " + inv.getName();
String uid = inv.getUid();
ParsedDateTime exceptDt = null;
if (inv.hasRecurId())
exceptDt = inv.getRecurId().getDt();
Invite replyInv = replyToInvite(fromAccount, senderAccount, onBehalfOf, allowPrivateAccess, inv, VERB_DECLINE, subject, exceptDt);
ZVCalendar iCal = replyInv.newToICalendar(true);
Address fromAddr = fromIdentity.getFriendlyEmailAddress();
Address senderAddr = null;
if (onBehalfOf)
senderAddr = AccountUtil.getFriendlyEmailAddress(senderAccount);
List<Address> toAddrs = new ArrayList<Address>(1);
toAddrs.add(toAddr);
return createCalendarMessage(senderAccount, fromAddr, senderAddr, toAddrs, subject, replyText.toString(), null, uid, iCal);
}
use of javax.mail.Address in project zm-mailbox by Zimbra.
the class CalendarMailSender method createDefaultReply.
private static MimeMessage createDefaultReply(Account fromAccount, String fromIdentityId, Account authAccount, String authIdentityId, boolean asAdmin, boolean onBehalfOf, CalendarItem calItem, Invite inv, MimeMessage mmInv, String replySubject, Verb verb, boolean partialAccept, String additionalMsgBody, ZVCalendar iCal, boolean addSignature) throws ServiceException {
Identity fromIdentity = null;
if (fromIdentityId != null) {
fromIdentity = fromAccount.getIdentityById(fromIdentityId);
if (fromIdentity == null) {
ZimbraLog.calendar.warn("No such identity " + fromIdentityId + " for account " + fromAccount.getName());
fromIdentity = getTargetedIdentity(fromAccount, inv);
}
} else {
fromIdentity = getTargetedIdentity(fromAccount, inv);
}
Identity authIdentity = null;
if (authIdentityId != null) {
authIdentity = authAccount.getIdentityById(authIdentityId);
if (authIdentity == null) {
ZimbraLog.calendar.warn("No such identity " + authIdentityId + " for account " + authAccount.getName());
if (authAccount.equals(fromAccount))
authIdentity = fromIdentity;
else
authIdentity = getTargetedIdentity(authAccount, inv);
}
} else {
if (authAccount.equals(fromAccount))
authIdentity = fromIdentity;
else
authIdentity = getTargetedIdentity(authAccount, inv);
}
Locale lc;
InternetAddress organizerAddress;
if (inv.hasOrganizer()) {
ZOrganizer org = inv.getOrganizer();
// organizer or sent-by
organizerAddress = org.getReplyAddress();
Account organizer = Provisioning.getInstance().get(AccountBy.name, organizerAddress.getAddress());
lc = organizer != null ? organizer.getLocale() : authAccount.getLocale();
} else {
organizerAddress = null;
lc = authAccount.getLocale();
}
String fromDisplayName = fromIdentity.getAttr(Provisioning.A_zimbraPrefFromDisplay);
if (fromDisplayName == null) {
fromDisplayName = fromAccount.getAttr(Provisioning.A_displayName, fromAccount.getName());
}
StringBuilder replyText = new StringBuilder();
boolean isResourceAccount = fromAccount instanceof CalendarResource;
MsgKey statusMsgKey;
if (VERB_ACCEPT.equals(verb)) {
if (isResourceAccount) {
if (partialAccept)
statusMsgKey = MsgKey.calendarResourceDefaultReplyPartiallyAccept;
else
statusMsgKey = MsgKey.calendarResourceDefaultReplyAccept;
} else {
statusMsgKey = MsgKey.calendarDefaultReplyAccept;
}
} else if (VERB_DECLINE.equals(verb)) {
if (isResourceAccount) {
if (partialAccept)
statusMsgKey = MsgKey.calendarResourceDefaultReplyPartiallyDecline;
else
statusMsgKey = MsgKey.calendarResourceDefaultReplyDecline;
} else {
statusMsgKey = MsgKey.calendarDefaultReplyDecline;
}
} else if (VERB_TENTATIVE.equals(verb)) {
if (isResourceAccount)
statusMsgKey = MsgKey.calendarResourceDefaultReplyTentativelyAccept;
else
statusMsgKey = MsgKey.calendarDefaultReplyTentativelyAccept;
} else {
statusMsgKey = MsgKey.calendarDefaultReplyOther;
}
String statusMsg;
if (!statusMsgKey.equals(MsgKey.calendarDefaultReplyOther))
statusMsg = L10nUtil.getMessage(statusMsgKey, lc, fromDisplayName);
else
statusMsg = L10nUtil.getMessage(statusMsgKey, lc, fromDisplayName, verb.toString());
replyText.append(statusMsg).append("\r\n\r\n");
if (additionalMsgBody != null) {
replyText.append(additionalMsgBody).append("\r\n");
}
// signature can come above or below original invite text
boolean sigAboveOriginal = true;
String sigText = null;
if (addSignature) {
String sigStyle = fromAccount.getAttr(Provisioning.A_zimbraPrefMailSignatureStyle, "outlook");
sigAboveOriginal = sigStyle.equalsIgnoreCase("outlook");
String sigKey;
if (VERB_DECLINE.equals(verb))
sigKey = Provisioning.A_zimbraPrefCalendarAutoDeclineSignatureId;
else
sigKey = Provisioning.A_zimbraPrefCalendarAutoAcceptSignatureId;
sigText = getSignatureText(fromAccount, fromIdentity, sigKey);
if (sigAboveOriginal && sigText != null && sigText.length() > 0) {
replyText.append(sigText).append("\r\n");
}
}
boolean allowPrivateAccess = calItem != null ? calItem.allowPrivateAccess(authAccount, asAdmin) : true;
if (inv.isPublic() || allowPrivateAccess) {
attachInviteSummary(replyText, inv, mmInv, lc);
}
if (addSignature && !sigAboveOriginal && sigText != null && sigText.length() > 0) {
replyText.append("\r\n-------------------------\r\n\r\n");
replyText.append(sigText).append("\r\n");
}
List<Address> toList = new ArrayList<Address>(1);
if (organizerAddress != null)
toList.add(organizerAddress);
Address senderAddr = null;
if (onBehalfOf)
senderAddr = authIdentity.getFriendlyEmailAddress();
return createCalendarMessage(authAccount, fromIdentity.getFriendlyEmailAddress(), senderAddr, toList, replySubject, replyText.toString(), null, inv.getUid(), iCal);
}
use of javax.mail.Address in project zm-mailbox by Zimbra.
the class CalendarMailSender method sendInviteDeniedMessage.
public static void sendInviteDeniedMessage(final OperationContext octxt, Account fromAccount, Account senderAccount, boolean onBehalfOf, boolean allowPrivateAccess, final Mailbox mbox, final ItemId origMsgId, String toEmail, Invite inv) throws ServiceException {
Address toAddr;
try {
toAddr = new JavaMailInternetAddress(toEmail);
} catch (AddressException e) {
throw ServiceException.FAILURE("Bad address: " + toEmail, e);
}
MsgKey bodyTextKey;
if (fromAccount instanceof CalendarResource)
bodyTextKey = MsgKey.calendarResourceDefaultReplyPermissionDenied;
else
bodyTextKey = MsgKey.calendarUserReplyPermissionDenied;
final MimeMessage mm = createCalendarInviteDeniedMessage(fromAccount, senderAccount, onBehalfOf, allowPrivateAccess, toAddr, inv, bodyTextKey);
// Send in a separate thread to avoid nested transaction error when saving a copy to Sent folder.
Runnable r = new Runnable() {
@Override
public void run() {
try {
MailSender mailSender = getCalendarMailSender(mbox).setSendPartial(true);
mailSender.sendMimeMessage(octxt, mbox, true, mm, null, origMsgId, MailSender.MSGTYPE_REPLY, null, false);
} catch (ServiceException e) {
ZimbraLog.calendar.warn("Ignoring error while sending permission-denied auto reply", e);
} catch (OutOfMemoryError e) {
Zimbra.halt("OutOfMemoryError while sending permission-denied auto reply", e);
}
}
};
Thread senderThread = new Thread(r, "CalendarPermDeniedReplySender");
senderThread.setDaemon(true);
senderThread.start();
}
use of javax.mail.Address in project zm-mailbox by Zimbra.
the class CalendarMailSender method createCancelMessage.
public static MimeMessage createCancelMessage(Account fromAccount, Account senderAccount, boolean asAdmin, boolean onBehalfOf, List<Address> toAddrs, CalendarItem calItem, Invite inv, String text, ZVCalendar iCal) throws ServiceException {
Locale locale = !onBehalfOf ? fromAccount.getLocale() : senderAccount.getLocale();
Invite defaultInv = calItem.getDefaultInviteOrNull();
boolean hidePrivate = !calItem.isPublic() && !calItem.allowPrivateAccess(senderAccount, asAdmin);
String invSubject;
if (hidePrivate)
invSubject = L10nUtil.getMessage(MsgKey.calendarSubjectWithheld, locale);
else
invSubject = inv != null ? inv.getName() : "";
String sbj = getCancelSubject(invSubject, locale);
StringBuilder sb = new StringBuilder(text);
sb.append("\r\n\r\n");
if (!inv.equals(defaultInv) && inv.getStartTime() != null && inv.getRecurId() != null) {
sb.append(L10nUtil.getMessage(MsgKey.calendarCancelAppointmentInstanceWhich, locale));
sb.append(" ");
ParsedDateTime start = inv.getStartTime();
TimeZone tz = start.getTimeZone();
Date startDate = new Date(start.getUtcTime());
sb.append(CalendarMailSender.formatDateTime(startDate, tz, locale));
sb.append("\r\n\r\n");
}
if (!hidePrivate) {
MimeMessage mmInv = inv.getMimeMessage();
if (mmInv == null && defaultInv != null)
mmInv = defaultInv.getMimeMessage();
if (mmInv != null)
attachInviteSummary(sb, inv, mmInv, locale);
}
Address from = AccountUtil.getFriendlyEmailAddress(fromAccount);
Address sender = null;
if (onBehalfOf)
sender = AccountUtil.getFriendlyEmailAddress(senderAccount);
return createCalendarMessage(senderAccount, from, sender, toAddrs, sbj, sb.toString(), null, defaultInv != null ? defaultInv.getUid() : "unknown", iCal);
}
Aggregations