use of com.zimbra.common.util.L10nUtil.MsgKey in project zm-mailbox by Zimbra.
the class CalendarMailSender method getReplySubject.
public static String getReplySubject(Verb verb, String subject, Locale lc) {
MsgKey key = sVerbMsgKeys.get(verb);
String prefix = L10nUtil.getMessage(key, lc);
return prefix + ": " + subject;
}
use of com.zimbra.common.util.L10nUtil.MsgKey in project zm-mailbox by Zimbra.
the class SendShareNotification method generateShareNotification.
protected MimeMessage generateShareNotification(Account authAccount, Account ownerAccount, ShareInfoData sid, String notes, Action action, Collection<String> internlaRecipients, String externalRecipient) throws ServiceException, MessagingException {
Locale locale = authAccount.getLocale();
String charset = authAccount.getAttr(Provisioning.A_zimbraPrefMailDefaultCharset, MimeConstants.P_CHARSET_UTF8);
MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSmtpSession(authAccount));
MsgKey subjectKey;
if (action == null) {
subjectKey = MsgKey.shareNotifSubject;
} else {
switch(action) {
case edit:
subjectKey = MsgKey.shareModifySubject;
break;
case revoke:
subjectKey = MsgKey.shareRevokeSubject;
break;
case expire:
subjectKey = MsgKey.shareExpireSubject;
break;
default:
subjectKey = MsgKey.shareNotifSubject;
}
}
String subject = L10nUtil.getMessage(subjectKey, locale);
String ownerAcctDisplayName = ownerAccount.getDisplayName();
if (ownerAcctDisplayName == null) {
ownerAcctDisplayName = ownerAccount.getName();
}
subject += L10nUtil.getMessage(MsgKey.sharedBySubject, locale, sid.getName(), ownerAcctDisplayName);
mm.setSubject(subject, CharsetUtil.checkCharset(subject, charset));
mm.setSentDate(new Date());
// from the owner
mm.setFrom(AccountUtil.getFriendlyEmailAddress(ownerAccount));
// sent by auth account
mm.setSender(AccountUtil.getFriendlyEmailAddress(authAccount));
// to the grantee
if (internlaRecipients != null) {
assert (externalRecipient == null);
for (String recipient : internlaRecipients) {
try {
mm.addRecipient(javax.mail.Message.RecipientType.TO, new JavaMailInternetAddress(recipient));
} catch (AddressException e) {
sLog.warn("Ignoring error while sending share notification to " + recipient, e);
}
}
} else if (externalRecipient != null) {
mm.setRecipient(javax.mail.Message.RecipientType.TO, new JavaMailInternetAddress(externalRecipient));
} else {
String recipient = sid.getGranteeName();
mm.setRecipient(javax.mail.Message.RecipientType.TO, new JavaMailInternetAddress(recipient));
}
MimeMultipart mmp = ShareInfo.NotificationSender.genNotifBody(sid, notes, locale, action, externalRecipient);
mm.setContent(mmp);
mm.saveChanges();
if (sLog.isDebugEnabled()) {
// log4j.logger.com.zimbra.cs.service.mail=DEBUG
try {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
mm.writeTo(buf);
String mmDump = new String(buf.toByteArray());
sLog.debug("********\n" + mmDump);
} catch (MessagingException e) {
sLog.debug("failed log debug share notification message", e);
} catch (IOException e) {
sLog.debug("failed log debug share notification message", e);
}
}
return mm;
}
use of com.zimbra.common.util.L10nUtil.MsgKey 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 com.zimbra.common.util.L10nUtil.MsgKey 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();
}
Aggregations