Search in sources :

Example 1 with MsgKey

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;
}
Also used : MsgKey(com.zimbra.common.util.L10nUtil.MsgKey)

Example 2 with MsgKey

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;
}
Also used : Locale(java.util.Locale) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) MessagingException(javax.mail.MessagingException) MsgKey(com.zimbra.common.util.L10nUtil.MsgKey) AddressException(javax.mail.internet.AddressException) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Date(java.util.Date)

Example 3 with MsgKey

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);
}
Also used : Locale(java.util.Locale) Account(com.zimbra.cs.account.Account) InternetAddress(javax.mail.internet.InternetAddress) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) ArrayList(java.util.ArrayList) MsgKey(com.zimbra.common.util.L10nUtil.MsgKey) Identity(com.zimbra.cs.account.Identity) CalendarResource(com.zimbra.cs.account.CalendarResource)

Example 4 with MsgKey

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();
}
Also used : Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) AddressException(javax.mail.internet.AddressException) MsgKey(com.zimbra.common.util.L10nUtil.MsgKey) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) MailSender(com.zimbra.cs.mailbox.MailSender) CalendarResource(com.zimbra.cs.account.CalendarResource)

Aggregations

MsgKey (com.zimbra.common.util.L10nUtil.MsgKey)4 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)3 CalendarResource (com.zimbra.cs.account.CalendarResource)2 Locale (java.util.Locale)2 Address (javax.mail.Address)2 AddressException (javax.mail.internet.AddressException)2 InternetAddress (javax.mail.internet.InternetAddress)2 MimeMessage (javax.mail.internet.MimeMessage)2 ServiceException (com.zimbra.common.service.ServiceException)1 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)1 Account (com.zimbra.cs.account.Account)1 Identity (com.zimbra.cs.account.Identity)1 MailSender (com.zimbra.cs.mailbox.MailSender)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 MessagingException (javax.mail.MessagingException)1 MimeMultipart (javax.mail.internet.MimeMultipart)1