use of com.zimbra.cs.account.Identity in project zm-mailbox by Zimbra.
the class MailSender method sendMimeMessage.
/**
* Sets member variables and sends the message.
*/
public ItemId sendMimeMessage(OperationContext octxt, Mailbox mbox, MimeMessage mm, List<Upload> uploads, ItemId origMsgId, String replyType, String identityId, boolean replyToSender, MimeProcessor mimeProc) throws ServiceException {
Account authuser = octxt == null ? null : octxt.getAuthenticatedUser();
if (authuser == null) {
authuser = mbox.getAccount();
}
Identity identity = null;
if (identityId != null) {
identity = Provisioning.getInstance().get(authuser, Key.IdentityBy.id, identityId);
}
return sendMimeMessage(octxt, mbox, null, mm, uploads, origMsgId, replyType, identity, replyToSender, mimeProc);
}
use of com.zimbra.cs.account.Identity in project zm-mailbox by Zimbra.
the class CalendarMailSender method sendResourceAutoReply.
public static void sendResourceAutoReply(final OperationContext octxt, final Mailbox mbox, final boolean saveToSent, Verb verb, boolean partialAccept, String additionalMsgBody, CalendarItem calItem, Invite inv, Invite[] replies, MimeMessage mmInv) throws ServiceException {
Identity iden = getTargetedIdentity(mbox.getAccount(), inv);
final MimeMessage mm = createResourceAutoReply(octxt, iden.getId(), iden.getId(), mbox, verb, partialAccept, additionalMsgBody, calItem, inv, replies, mmInv, true);
final String replyType = MailSender.MSGTYPE_REPLY;
final int invId = inv.getMailItemId();
// 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, saveToSent, mm, null, new ItemId(mbox, invId), replyType, null, false);
} catch (ServiceException e) {
ZimbraLog.calendar.warn("Ignoring error while sending auto accept/decline reply", e);
} catch (OutOfMemoryError e) {
Zimbra.halt("OutOfMemoryError while sending calendar resource auto accept/decline reply", e);
}
}
};
Thread senderThread = new Thread(r, "CalendarAutoAcceptDeclineReplySender");
senderThread.setDaemon(true);
senderThread.start();
}
use of com.zimbra.cs.account.Identity in project zm-mailbox by Zimbra.
the class CalendarMailSender method replyToInvite.
/**
* RFC2446 4.2.2:
*
* BEGIN:VCALENDAR PRODID:-//ACME/DesktopCalendar//EN METHOD:REPLY
* VERSION:2.0 BEGIN:VEVENT ATTENDEE;PARTSTAT=ACCEPTED:Mailto:B@example.com
* ORGANIZER:MAILTO:A@example.com
* UID:calsrv.example.com-873970198738777@example.com SEQUENCE:0
* REQUEST-STATUS:2.0;Success DTSTAMP:19970612T190000Z END:VEVENT
* END:VCALENDAR
*
* @param acct replying account
* @param identityId use this identity/persona in the reply
* @param authAcct authenticated account acting on behalf of acct
* @param oldInv
* @param verb
* @param replySubject
* @return
* @throws ServiceException
*/
public static Invite replyToInvite(Account acct, String identityId, Account authAcct, boolean onBehalfOf, boolean allowPrivateAccess, Invite oldInv, Verb verb, String replySubject, ParsedDateTime exceptDt) throws ServiceException {
Invite reply = new Invite(oldInv.getItemType(), ICalTok.REPLY.toString(), new TimeZoneMap(Util.getAccountTimeZone(onBehalfOf ? authAcct : acct)), oldInv.isOrganizer());
// suppress X-ZIMBRA-LOCAL-ONLY property
reply.setLocalOnly(false);
reply.getTimeZoneMap().add(oldInv.getTimeZoneMap());
reply.setIsAllDayEvent(oldInv.isAllDayEvent());
Identity identity = null;
if (identityId != null) {
identity = acct.getIdentityById(identityId);
if (identity == null) {
ZimbraLog.calendar.warn("No such identity " + identityId + " for account " + acct.getName());
identity = getTargetedIdentity(acct, oldInv);
}
} else {
identity = getTargetedIdentity(acct, oldInv);
}
String identityAddr = identity.getAttr(Provisioning.A_zimbraPrefFromAddress);
String identityCn = identity.getAttr(Provisioning.A_zimbraPrefFromDisplay);
// ATTENDEE -- send back this attendee with the proper status
ZAttendee meReply = null;
ZAttendee me = oldInv.getMatchingAttendee(acct, identityId);
if (me != null) {
String atAddr = me.getAddress();
// Use identity's address/cn if possible, overriding the case/name used by the organizer.
if (identityAddr.equalsIgnoreCase(atAddr)) {
meReply = new ZAttendee(identityAddr);
if (identityCn != null)
meReply.setCn(identityCn);
} else {
meReply = new ZAttendee(atAddr);
if (me.hasCn())
meReply.setCn(me.getCn());
}
meReply.setPartStat(verb.getXmlPartStat());
if (me.hasRole())
meReply.setRole(me.getRole());
if (me.hasCUType())
meReply.setCUType(me.getCUType());
} else {
meReply = new ZAttendee(identityAddr);
meReply.setPartStat(verb.getXmlPartStat());
if (identityCn != null)
meReply.setCn(identityCn);
}
if (onBehalfOf)
meReply.setSentBy(authAcct.getName());
reply.addAttendee(meReply);
boolean hidePrivate = !oldInv.isPublic() && !allowPrivateAccess;
reply.setClassProp(oldInv.getClassProp());
// DTSTART, DTEND, LOCATION (outlook seems to require these,
// even though it shouldn't)
reply.setDtStart(oldInv.getStartTime());
reply.setDtEnd(oldInv.getEffectiveEndTime());
if (!hidePrivate)
reply.setLocation(oldInv.getLocation());
else
reply.setLocation("");
// ORGANIZER
if (oldInv.hasOrganizer())
reply.setOrganizer(oldInv.getOrganizer());
// UID
reply.setUid(oldInv.getUid());
// RECURRENCE-ID (if necessary)
if (exceptDt != null) {
reply.setRecurId(new RecurId(exceptDt, RecurId.RANGE_NONE));
} else if (oldInv.hasRecurId()) {
reply.setRecurId(oldInv.getRecurId());
} else if (oldInv.isRecurrence()) {
// RRULE (BES seems to require it even though it shouldn't)
// Must use a cloned object!
reply.setRecurrence((IRecurrence) oldInv.getRecurrence().clone());
}
// SEQUENCE
reply.setSeqNo(oldInv.getSeqNo());
// DTSTAMP
// we should pick "now" -- but the dtstamp MUST be >= the one sent by
// the organizer,
// so we'll use theirs if it is after "now"...
Date now = new Date();
Date dtStampDate = new Date(oldInv.getDTStamp());
if (now.after(dtStampDate)) {
dtStampDate = now;
}
reply.setDtStamp(dtStampDate.getTime());
// SUMMARY
reply.setName(replySubject);
return reply;
}
use of com.zimbra.cs.account.Identity in project zm-mailbox by Zimbra.
the class GetIdentities method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account account = getRequestedAccount(zsc);
if (!canAccessAccount(zsc, account)) {
throw ServiceException.PERM_DENIED("can not access account");
}
Element response = zsc.createElement(AccountConstants.GET_IDENTITIES_RESPONSE);
Provisioning prov = Provisioning.getInstance();
for (Identity ident : prov.getAllIdentities(account)) {
ToXML.encodeIdentity(response, ident);
}
return response;
}
use of com.zimbra.cs.account.Identity in project zm-mailbox by Zimbra.
the class ModifyIdentity method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account account = getRequestedAccount(zsc);
Identity identity = null;
if (!canModifyOptions(zsc, account))
throw ServiceException.PERM_DENIED("can not modify options");
Provisioning prov = Provisioning.getInstance();
Element eIdentity = request.getElement(AccountConstants.E_IDENTITY);
Map<String, Object> attrs = AccountService.getAttrs(eIdentity, AccountConstants.A_NAME);
// remove anything that doesn't start with zimbraPref. ldap will also do additional checks
for (Iterator<String> it = attrs.keySet().iterator(); it.hasNext(); ) if (// if this changes, make sure we don't let them ever change objectclass
!it.next().toLowerCase().startsWith("zimbrapref"))
it.remove();
String key, id = eIdentity.getAttribute(AccountConstants.A_ID, null);
if (id != null) {
identity = prov.get(account, Key.IdentityBy.id, key = id);
} else {
identity = prov.get(account, Key.IdentityBy.name, key = eIdentity.getAttribute(AccountConstants.A_NAME));
}
if (identity == null) {
String[] childIds = account.getChildAccount();
for (String childId : childIds) {
Account childAccount = prov.get(AccountBy.id, childId, zsc.getAuthToken());
if (childAccount != null) {
Identity childIdentity;
if (id != null) {
childIdentity = prov.get(childAccount, Key.IdentityBy.id, key = id);
} else {
childIdentity = prov.get(childAccount, Key.IdentityBy.name, key = eIdentity.getAttribute(AccountConstants.A_NAME));
}
if (childIdentity != null) {
identity = childIdentity;
account = childAccount;
break;
}
}
}
}
if (identity == null)
throw AccountServiceException.NO_SUCH_IDENTITY(key);
prov.modifyIdentity(account, identity.getName(), attrs);
Element response = zsc.createElement(AccountConstants.MODIFY_IDENTITY_RESPONSE);
return response;
}
Aggregations