use of com.zimbra.cs.mailbox.MailSender in project zm-mailbox by Zimbra.
the class FilterUtil method reply.
public static void reply(OperationContext octxt, Mailbox mailbox, ParsedMessage parsedMessage, String bodyTemplate) throws MessagingException, ServiceException {
MimeMessage mimeMessage = parsedMessage.getMimeMessage();
if (isMailLoop(mailbox, mimeMessage, new String[] { HEADER_FORWARDED })) {
String error = String.format("Detected a mail loop for message %s.", Mime.getMessageID(mimeMessage));
throw ServiceException.FAILURE(error, null);
}
if (isDeliveryStatusNotification(mimeMessage)) {
ZimbraLog.filter.debug("Not auto-replying to a DSN message");
return;
}
Account account = mailbox.getAccount();
MimeMessage replyMsg = new Mime.FixedMimeMessage(JMSession.getSmtpSession(account));
// add the forwarded header account names to detect the mail loop between accounts
for (String headerFwdAccountName : Mime.getHeaders(mimeMessage, HEADER_FORWARDED)) {
replyMsg.addHeader(HEADER_FORWARDED, headerFwdAccountName);
}
replyMsg.addHeader(HEADER_FORWARDED, account.getName());
String to = mimeMessage.getHeader("Reply-To", null);
if (StringUtil.isNullOrEmpty(to))
to = Mime.getSender(mimeMessage);
if (StringUtil.isNullOrEmpty(to))
throw new MessagingException("Can't locate the address to reply to");
replyMsg.setRecipient(javax.mail.Message.RecipientType.TO, new JavaMailInternetAddress(to));
String subject = mimeMessage.getSubject();
if (subject == null) {
subject = "";
}
String replySubjectPrefix = L10nUtil.getMessage(L10nUtil.MsgKey.replySubjectPrefix, account.getLocale());
if (!subject.toLowerCase().startsWith(replySubjectPrefix.toLowerCase())) {
subject = replySubjectPrefix + " " + subject;
}
replyMsg.setSubject(subject, getCharset(account, subject));
//getVarsMap() result is now being passed to replaceVariables(), so following call is redundant
//Map<String, String> vars = getVarsMap(mailbox, parsedMessage, mimeMessage);
replyMsg.setText(bodyTemplate, getCharset(account, bodyTemplate));
String origMsgId = mimeMessage.getMessageID();
if (!StringUtil.isNullOrEmpty(origMsgId))
replyMsg.setHeader("In-Reply-To", origMsgId);
replyMsg.setSentDate(new Date());
replyMsg.saveChanges();
MailSender mailSender = mailbox.getMailSender();
mailSender.setReplyType(MailSender.MSGTYPE_REPLY);
mailSender.setDsnNotifyOptions(MailSender.DsnNotifyOption.NEVER);
mailSender.sendMimeMessage(octxt, mailbox, replyMsg);
}
use of com.zimbra.cs.mailbox.MailSender in project zm-mailbox by Zimbra.
the class BounceMsg method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account acct = getRequestedAccount(zsc);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
Element msgElem = request.getElement(MailConstants.E_MSG);
ItemId iid = new ItemId(msgElem.getAttribute(MailConstants.A_ID), zsc);
MailSender msender = mbox.getMailSender().setSaveToSent(false).setRedirectMode(true).setSkipHeaderUpdate(true);
Upload upload = null;
try {
InputStream is;
if (iid.belongsTo(mbox)) {
is = mbox.getMessageById(octxt, iid.getId()).getContentStream();
} else if (iid.isLocal()) {
Mailbox mboxSrc = MailboxManager.getInstance().getMailboxByAccountId(iid.getAccountId());
is = mboxSrc.getMessageById(octxt, iid.getId()).getContentStream();
} else {
upload = UserServlet.getRemoteResourceAsUpload(zsc.getAuthToken(), iid, Maps.<String, String>newHashMap());
is = upload.getInputStream();
}
ZMimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSmtpSession(acct), is);
addResentHeaders(msgElem, mm, zsc, octxt, acct, msender);
msender.sendMimeMessage(octxt, mbox, mm);
} catch (MessagingException me) {
throw ServiceException.FAILURE("error generating new message", me);
} catch (IOException ioe) {
throw ServiceException.FAILURE("error fetching remote message", ioe);
} finally {
// always want to delete the upload; msender.setUploads() deletes only on success
if (upload != null) {
FileUploadServlet.deleteUpload(upload);
}
}
Element response = zsc.createElement(MailConstants.BOUNCE_MSG_RESPONSE);
return response;
}
use of com.zimbra.cs.mailbox.MailSender in project zm-mailbox by Zimbra.
the class CounterCalendarItem method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account acct = getRequestedAccount(zsc);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
Invite oldInv = null;
// proxy handling
String idStr = request.getAttribute(MailConstants.A_ID, null);
if (idStr != null) {
ItemId iid = new ItemId(idStr, zsc);
if (!iid.belongsTo(acct))
return proxyRequest(request, context, iid.getAccountId());
CalendarItem calItem = mbox.getCalendarItemById(octxt, iid.getId());
if (calItem == null) {
throw MailServiceException.NO_SUCH_CALITEM(iid.toString(), "Could not find calendar item");
}
// Conflict detection. Do it only if requested by client. (for backward compat)
int modSeq = (int) request.getAttributeLong(MailConstants.A_MODIFIED_SEQUENCE, 0);
int revision = (int) request.getAttributeLong(MailConstants.A_REVISION, 0);
if (modSeq != 0 && revision != 0 && (modSeq < calItem.getModifiedSequence() || revision < calItem.getSavedSequence()))
throw MailServiceException.INVITE_OUT_OF_DATE(iid.toString());
int compNum = (int) request.getAttributeLong(MailConstants.A_CAL_COMP, 0);
if (compNum != 0) {
oldInv = calItem.getInvite(iid.getSubpartId(), compNum);
if (oldInv == null)
throw MailServiceException.INVITE_OUT_OF_DATE(iid.toString());
}
}
Element msgElem = request.getElement(MailConstants.E_MSG);
InviteParser parser = new InviteParser(oldInv);
CalSendData dat = handleMsgElement(zsc, octxt, msgElem, acct, mbox, parser);
MailSender mailSender = mbox.getMailSender();
mailSender.sendMimeMessage(octxt, mbox, dat.mMm);
Element response = getResponseElement(zsc);
return response;
}
use of com.zimbra.cs.mailbox.MailSender in project zm-mailbox by Zimbra.
the class DeclineCounterCalendarItem method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account acct = getRequestedAccount(zsc);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
Element msgElem = request.getElement(MailConstants.E_MSG);
InviteParser parser = new InviteParser();
CalSendData dat = handleMsgElement(zsc, octxt, msgElem, acct, mbox, parser);
MailSender mailSender = mbox.getMailSender();
mailSender.sendMimeMessage(octxt, mbox, dat.mMm);
Element response = getResponseElement(zsc);
return response;
}
use of com.zimbra.cs.mailbox.MailSender in project zm-mailbox by Zimbra.
the class SendVerificationCode method sendVerificationCode.
static void sendVerificationCode(String emailAddr, String code, Mailbox mbox) throws MessagingException, ServiceException {
MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSmtpSession(mbox.getAccount()));
mm.setRecipient(javax.mail.Message.RecipientType.TO, new JavaMailInternetAddress(emailAddr));
mm.setText(L10nUtil.getMessage(L10nUtil.MsgKey.deviceSendVerificationCodeText, mbox.getAccount().getLocale(), code), MimeConstants.P_CHARSET_UTF8);
mm.saveChanges();
MailSender mailSender = mbox.getMailSender();
mailSender.setSaveToSent(false);
mailSender.sendMimeMessage(null, mbox, mm);
}
Aggregations