use of com.zimbra.cs.account.Identity 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.cs.account.Identity in project zm-mailbox by Zimbra.
the class CalendarMailSender method getTargetedIdentity.
// Returns the Identity of the account that matches the attendee address in the invite.
// Default identity is returned if no attendee matches any identity.
private static Identity getTargetedIdentity(Account acct, Invite invite) throws ServiceException {
ZAttendee addressedAtt = invite.getMatchingAttendee(acct);
if (addressedAtt != null && addressedAtt.getAddress() != null) {
String addr = addressedAtt.getAddress();
List<Identity> idens = Provisioning.getInstance().getAllIdentities(acct);
for (Identity iden : idens) {
String idenAddr = iden.getAttr(Provisioning.A_zimbraPrefFromAddress);
if (addr.equalsIgnoreCase(idenAddr)) {
return iden;
}
}
}
return acct.getDefaultIdentity();
}
use of com.zimbra.cs.account.Identity in project zm-mailbox by Zimbra.
the class Invite method getMatchingAttendee.
/**
* Find the (first) Attendee in our list that matches the passed-in account. If multiple attendees
* match this account (because an account can have multiple addresses), the address that matches
* the given identity (persona) id is returned. Account's default identity is used if identityId
* is null or invalid.
*
* @param acct
* @param identityId
* @return The first matching attendee
* @throws ServiceException
*/
public ZAttendee getMatchingAttendee(Account acct, String identityId) throws ServiceException {
Identity identity;
if (identityId != null) {
identity = acct.getIdentityById(identityId);
if (identity == null) {
ZimbraLog.calendar.warn("No such identity " + identityId + " for account " + acct.getName());
identity = acct.getDefaultIdentity();
}
} else {
identity = acct.getDefaultIdentity();
}
String identityEmail = identity.getAttr(Provisioning.A_zimbraPrefFromAddress);
ZAttendee acctMatch = null;
List<ZAttendee> attendees = getAttendees();
AccountAddressMatcher acctMatcher = new AccountAddressMatcher(acct);
for (ZAttendee at : attendees) {
String thisAtEmail = at.getAddress();
// Does this attendee match our identity?
if (identityEmail != null && identityEmail.equalsIgnoreCase(thisAtEmail))
return at;
if (acctMatch == null && acctMatcher.matches(thisAtEmail)) {
acctMatch = at;
// If we didn't have identity email for some reason, we have our best match.
if (identityEmail == null)
return at;
}
}
return acctMatch;
}
use of com.zimbra.cs.account.Identity in project zm-mailbox by Zimbra.
the class MailSignature method preModify.
/**
* check to make sure zimbraPrefMailSignature is shorter than the limit
*/
@Override
public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry) throws ServiceException {
SingleValueMod mod = singleValueMod(attrName, value);
if (mod.unsetting())
return;
if (entry != null && !((entry instanceof Account) || (entry instanceof Identity) || (entry instanceof Signature))) {
return;
}
long maxLen = -1;
String maxInContext = context.getData(DataKey.MAX_SIGNATURE_LEN);
if (maxInContext != null) {
try {
maxLen = Integer.parseInt(maxInContext);
} catch (NumberFormatException e) {
ZimbraLog.account.warn("encountered invalid " + DataKey.MAX_SIGNATURE_LEN.name() + ": " + maxInContext);
}
}
if (maxLen == -1) {
String maxInAttrsToModify = (String) attrsToModify.get(Provisioning.A_zimbraMailSignatureMaxLength);
if (maxInAttrsToModify != null) {
try {
maxLen = Integer.parseInt(maxInAttrsToModify);
} catch (NumberFormatException e) {
ZimbraLog.account.warn("encountered invalid " + Provisioning.A_zimbraMailSignatureMaxLength + ": " + maxInAttrsToModify);
}
}
}
if (maxLen == -1) {
if (entry == null) {
return;
}
Account account;
if (entry instanceof Account) {
account = (Account) entry;
} else if (entry instanceof Identity) {
account = ((Identity) entry).getAccount();
} else if (entry instanceof Signature) {
account = ((Signature) entry).getAccount();
} else {
return;
}
maxLen = account.getMailSignatureMaxLength();
}
// 0 means unlimited
if (maxLen != 0 && ((String) value).length() > maxLen) {
throw ServiceException.INVALID_REQUEST(Provisioning.A_zimbraPrefMailSignature + " is longer than the limited value " + maxLen, null);
}
}
use of com.zimbra.cs.account.Identity in project zm-mailbox by Zimbra.
the class SoapProvisioning method createIdentity.
@Override
public Identity createIdentity(Account account, String identityName, Map<String, Object> attrs) throws ServiceException {
com.zimbra.soap.account.type.Identity id = new com.zimbra.soap.account.type.Identity(identityName, null);
id.setAttrs(attrs);
CreateIdentityRequest request = new CreateIdentityRequest(id);
CreateIdentityResponse response = invokeJaxbOnTargetAccount(request, account.getId());
return new SoapIdentity(account, response.getIdentity(), this);
}
Aggregations