use of javax.mail.Address in project zm-mailbox by Zimbra.
the class CalendarRequest method notifyCalendarItem.
// Notify attendees following an update to the series of a recurring appointment. Only the
// added attendees are notified if notifyAllAttendees is false. If it is true all attendees
// for each invite are notified. (Some invites may have more attendees than others.)
protected static void notifyCalendarItem(ZimbraSoapContext zsc, OperationContext octxt, Account acct, Mailbox mbox, CalendarItem calItem, boolean notifyAllAttendees, List<ZAttendee> addedAttendees, boolean ignorePastExceptions, MailSendQueue sendQueue) throws ServiceException {
boolean onBehalfOf = isOnBehalfOfRequest(zsc);
Account authAcct = getAuthenticatedAccount(zsc);
boolean hidePrivate = !calItem.isPublic() && !calItem.allowPrivateAccess(authAcct, zsc.isUsingAdminPrivileges());
Address from = AccountUtil.getFriendlyEmailAddress(acct);
Address sender = null;
if (onBehalfOf)
sender = AccountUtil.getFriendlyEmailAddress(authAcct);
List<Address> addedRcpts = CalendarMailSender.toListFromAttendees(addedAttendees);
long now = octxt != null ? octxt.getTimestamp() : System.currentTimeMillis();
mbox.lock.lock();
try {
// Refresh the cal item so we see the latest blob, whose path may have been changed
// earlier in the current request.
calItem = mbox.getCalendarItemById(octxt, calItem.getId());
Invite[] invites = calItem.getInvites();
// Get exception instances. These will be included in the series update email.
List<Invite> exceptions = new ArrayList<Invite>();
for (Invite inv : invites) {
if (inv.hasRecurId()) {
exceptions.add(inv);
}
}
// Send the update invites.
boolean didExceptions = false;
for (Invite inv : invites) {
if (ignorePastExceptions && inv.hasRecurId() && !inviteIsAfterTime(inv, now)) {
continue;
}
// Make the new iCalendar part to send.
ZVCalendar cal = inv.newToICalendar(!hidePrivate);
// For series invite, append the exception instances.
if (inv.isRecurrence() && !didExceptions) {
// Find the VEVENT/VTODO for the series.
ZComponent seriesComp = null;
for (Iterator<ZComponent> compIter = cal.getComponentIterator(); compIter.hasNext(); ) {
ZComponent comp = compIter.next();
ICalTok compName = comp.getTok();
if (ICalTok.VEVENT.equals(compName) || ICalTok.VTODO.equals(compName)) {
if (comp.getProperty(ICalTok.RRULE) != null) {
seriesComp = comp;
break;
}
}
}
for (Invite except : exceptions) {
if (except.isCancel() && seriesComp != null) {
// Cancels are added as EXDATEs in the series VEVENT/VTODO.
RecurId rid = except.getRecurId();
if (rid != null && rid.getDt() != null) {
ZProperty exdate = rid.getDt().toProperty(ICalTok.EXDATE, false);
seriesComp.addProperty(exdate);
}
} else {
// Exception instances are added as additional VEVENTs/VTODOs.
ZComponent exceptComp = except.newToVComponent(false, !hidePrivate);
cal.addComponent(exceptComp);
}
}
didExceptions = true;
}
// Compose email using the existing MimeMessage as template and send it.
MimeMessage mmInv = calItem.getSubpartMessage(inv.getMailItemId());
List<Address> rcpts;
if (notifyAllAttendees) {
rcpts = CalendarMailSender.toListFromAttendees(inv.getAttendees());
} else {
rcpts = addedRcpts;
}
if (rcpts != null && !rcpts.isEmpty()) {
MimeMessage mmModify = CalendarMailSender.createCalendarMessage(authAcct, from, sender, rcpts, mmInv, inv, cal, true);
CalSendData csd = new CalSendData();
csd.mMm = mmModify;
csd.mOrigId = new ItemId(mbox, inv.getMailItemId());
MailSendQueueEntry entry = new MailSendQueueEntry(octxt, mbox, csd, null);
sendQueue.add(entry);
}
}
} finally {
mbox.lock.release();
}
}
use of javax.mail.Address in project zm-mailbox by Zimbra.
the class CalendarRequest method notifyRemovedAttendees.
protected static void notifyRemovedAttendees(ZimbraSoapContext zsc, OperationContext octxt, Account acct, Mailbox mbox, CalendarItem calItem, Invite invToCancel, List<ZAttendee> removedAttendees, MailSendQueue sendQueue) throws ServiceException {
boolean onBehalfOf = isOnBehalfOfRequest(zsc);
Account authAcct = getAuthenticatedAccount(zsc);
Locale locale = !onBehalfOf ? acct.getLocale() : authAcct.getLocale();
CalSendData dat = new CalSendData();
dat.mOrigId = new ItemId(mbox, invToCancel.getMailItemId());
dat.mReplyType = MailSender.MSGTYPE_REPLY;
String text = L10nUtil.getMessage(MsgKey.calendarCancelRemovedFromAttendeeList, locale);
if (ZimbraLog.calendar.isDebugEnabled()) {
StringBuilder sb = new StringBuilder("Sending cancellation message for \"");
sb.append(invToCancel.getName()).append("\" to ");
sb.append(getAttendeesAddressList(removedAttendees));
ZimbraLog.calendar.debug(sb.toString());
}
List<Address> rcpts = CalendarMailSender.toListFromAttendees(removedAttendees);
try {
dat.mInvite = CalendarUtils.buildCancelInviteCalendar(acct, authAcct, zsc.isUsingAdminPrivileges(), onBehalfOf, calItem, invToCancel, text, removedAttendees);
ZVCalendar cal = dat.mInvite.newToICalendar(true);
dat.mMm = CalendarMailSender.createCancelMessage(acct, authAcct, zsc.isUsingAdminPrivileges(), onBehalfOf, rcpts, calItem, invToCancel, text, cal);
// If we are sending this cancellation to other people, then we MUST be the organizer!
if (!dat.mInvite.isOrganizer() && rcpts != null && !rcpts.isEmpty())
throw MailServiceException.MUST_BE_ORGANIZER("updateRemovedInvitees");
sendCalendarCancelMessage(zsc, octxt, calItem.getFolderId(), acct, mbox, dat, false, sendQueue);
} catch (ServiceException ex) {
String to = getAttendeesAddressList(removedAttendees);
ZimbraLog.calendar.debug("Could not inform attendees (" + to + ") that they were removed from meeting " + invToCancel.toString() + " b/c of exception: " + ex.toString());
}
}
use of javax.mail.Address in project logging-log4j2 by apache.
the class SmtpAppenderTest method testMessageFactorySetFrom.
@Test
public void testMessageFactorySetFrom() throws MessagingException {
final MimeMessageBuilder builder = new MimeMessageBuilder(null);
final String address = "testing@example.com";
assertNull(builder.build().getFrom());
builder.setFrom(null);
Address[] array = null;
final Address addr = InternetAddress.getLocalAddress(null);
if (addr != null) {
array = new Address[] { addr };
}
assertArrayEquals(array, builder.build().getFrom());
builder.setFrom(address);
assertArrayEquals(new Address[] { new InternetAddress(address) }, builder.build().getFrom());
}
use of javax.mail.Address in project opennms by OpenNMS.
the class JavaMailAckReaderIT method workingWithSimpleTextMessages.
/**
* tests the ability to create acknowledgments from an email for plain text. This test
* creates a message from scratch rather than reading from an inbox.
*/
@Test
public void workingWithSimpleTextMessages() {
Properties props = new Properties();
Message msg = new MimeMessage(Session.getDefaultInstance(props));
try {
Address[] addrs = new Address[1];
addrs[0] = new InternetAddress("david@opennms.org");
msg.addFrom(addrs);
msg.addRecipient(javax.mail.internet.MimeMessage.RecipientType.TO, addrs[0]);
msg.setSubject("Re: Notice #1234 JavaMailReaderImplTest Test Message");
msg.setText("ACK");
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
List<Message> msgs = new ArrayList<Message>(1);
msgs.add(msg);
List<OnmsAcknowledgment> acks = m_processor.createAcks(msgs);
Assert.assertEquals(1, acks.size());
Assert.assertEquals(AckType.NOTIFICATION, acks.get(0).getAckType());
Assert.assertEquals("david@opennms.org", acks.get(0).getAckUser());
Assert.assertEquals(AckAction.ACKNOWLEDGE, acks.get(0).getAckAction());
Assert.assertEquals(new Integer(1234), acks.get(0).getRefId());
}
use of javax.mail.Address in project opennms by OpenNMS.
the class JavaMailAckReaderIT method workingWithMultiPartMessages.
/**
* tests the ability to create acknowledgments from an email for a multi-part text. This test
* creates a message from scratch rather than reading from an inbox. This message creation
* may not actually represent what comes from a mail server.
*/
@Test
public void workingWithMultiPartMessages() throws JavaMailerException, MessagingException {
List<Message> msgs = new ArrayList<>();
Properties props = new Properties();
Message msg = new MimeMessage(Session.getDefaultInstance(props));
Address[] addrs = new Address[1];
addrs[0] = new InternetAddress("david@opennms.org");
msg.addFrom(addrs);
msg.addRecipient(RecipientType.TO, new InternetAddress("david@opennms.org"));
msg.setSubject("Re: Notice #1234 JavaMailReaderImplTest Test Message");
Multipart mpContent = new MimeMultipart();
BodyPart textBp = new MimeBodyPart();
BodyPart htmlBp = new MimeBodyPart();
textBp.setText("ack");
htmlBp.setContent("<html>\n" + " <head>\n" + " <title>\n" + " Acknowledge\n" + " </title>\n" + " </head>\n" + " <body>\n" + " <h1>\n" + " ack\n" + " </h1>\n" + " </body>\n" + "</html>", "text/html");
mpContent.addBodyPart(textBp);
mpContent.addBodyPart(htmlBp);
msg.setContent(mpContent);
msgs.add(msg);
List<OnmsAcknowledgment> acks = m_processor.createAcks(msgs);
Assert.assertEquals(1, acks.size());
Assert.assertEquals(AckType.NOTIFICATION, acks.get(0).getAckType());
Assert.assertEquals("david@opennms.org", acks.get(0).getAckUser());
Assert.assertEquals(AckAction.ACKNOWLEDGE, acks.get(0).getAckAction());
Assert.assertEquals(new Integer(1234), acks.get(0).getRefId());
}
Aggregations