use of com.zimbra.cs.account.DistributionList in project zm-mailbox by Zimbra.
the class LdapProvisioning method getDistributionListIds.
private Set<String> getDistributionListIds(Account acct, boolean directOnly) throws ServiceException {
Set<String> dls = new HashSet<String>();
List<DistributionList> lists = getDistributionLists(acct, directOnly, null);
for (DistributionList dl : lists) {
dls.add(dl.getId());
}
dls = Collections.unmodifiableSet(dls);
return dls;
}
use of com.zimbra.cs.account.DistributionList in project zm-mailbox by Zimbra.
the class LdapProvisioning method renameAddressesInAllDistributionLists.
protected void renameAddressesInAllDistributionLists(Map<String, String> changedPairs) {
String[] oldAddrs = changedPairs.keySet().toArray(new String[0]);
String[] newAddrs = changedPairs.values().toArray(new String[0]);
List<DistributionList> lists = null;
Map<String, String[]> attrs = null;
try {
lists = getAllDistributionListsForAddresses(oldAddrs, false);
} catch (ServiceException se) {
ZimbraLog.account.warn("unable to rename addr " + oldAddrs.toString() + " in all DLs ", se);
return;
}
for (DistributionList list : lists) {
// removeMember/addMember might have to update an entry's zimbraMemberId twice
if (attrs == null) {
attrs = new HashMap<String, String[]>();
attrs.put("-" + Provisioning.A_zimbraMailForwardingAddress, oldAddrs);
attrs.put("+" + Provisioning.A_zimbraMailForwardingAddress, newAddrs);
}
try {
modifyAttrs(list, attrs);
// list.removeMember(oldName)
// list.addMember(newName);
} catch (ServiceException se) {
// log warning an continue
ZimbraLog.account.warn("unable to rename " + oldAddrs.toString() + " to " + newAddrs.toString() + " in DL " + list.getName(), se);
}
}
}
use of com.zimbra.cs.account.DistributionList in project zm-mailbox by Zimbra.
the class LdapProvisioning method getAllAddressesOfEntry.
//
// returns the primary address and all aliases of the named account or DL
//
private AddrsOfEntry getAllAddressesOfEntry(String name) {
String primary = null;
String[] aliases = null;
AddrsOfEntry addrs = new AddrsOfEntry();
try {
// bug 56621. Do not count implicit aliases (aliases resolved by alias domain)
// when dealing with distribution list members.
Account acct = getAccountByName(name, false, false);
if (acct != null) {
addrs.setIsAccount(true);
primary = acct.getName();
aliases = acct.getMailAlias();
} else {
DistributionList dl = get(Key.DistributionListBy.name, name);
if (dl != null) {
primary = dl.getName();
aliases = dl.getAliases();
}
}
} catch (ServiceException se) {
// swallow any exception and go on
}
if (primary != null)
addrs.setPrimary(primary);
if (aliases != null)
addrs.addAll(aliases);
return addrs;
}
use of com.zimbra.cs.account.DistributionList in project zm-mailbox by Zimbra.
the class LdapProvisioning method getHABGroupMemberDetails.
/**
* get members of static group and member details
* @param group
* @return
*/
public List<HABGroupMember> getHABGroupMemberDetails(Group group) {
final List<HABGroupMember> members = Lists.newArrayList();
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.REPLICA, LdapUsage.GET_GROUP_MEMBER);
String[] memberEmails = null;
DistributionList dl = get(DistributionListBy.id, group.getId());
memberEmails = dl.getMultiAttr(Provisioning.A_zimbraMailForwardingAddress);
String[] memberAttrMap = getConfig().getMultiAttr(Provisioning.A_zimbraHABMemberLdapAttrMap);
Map<String, String> habMemberAttrMap = Arrays.stream(memberAttrMap).collect(Collectors.toMap(e -> e.split("=")[0], e -> e.split("=")[1]));
for (String memberEmail : memberEmails) {
Account memberAcc = null;
try {
memberAcc = get(AccountBy.name, memberEmail);
} catch (ServiceException e) {
ZimbraLog.account.debug("not a direct member of hab group %s", memberEmail, e);
}
if (memberAcc != null) {
HABGroupMember habMember = new HABGroupMember(memberEmail);
for (String key : habMemberAttrMap.keySet()) {
if (Provisioning.A_zimbraMailAlias.equals(habMemberAttrMap.get(key))) {
String[] aliases = memberAcc.getAliases();
for (String alias : aliases) {
habMember.addAttr(new NamedValue(key, alias));
}
} else {
String val = memberAcc.getAttr(habMemberAttrMap.get(key));
if (StringUtils.isNotEmpty(val)) {
habMember.addAttr(new NamedValue(key, val));
}
}
}
int seniorityIndex = memberAcc.getHABSeniorityIndex();
if (seniorityIndex == -1) {
seniorityIndex = 0;
}
habMember.setSeniorityIndex(seniorityIndex);
members.add(habMember);
}
}
Collections.sort(members, new SortBySeniorityIndexThenName());
} catch (ServiceException e) {
ZimbraLog.account.debug("unable to get hab group members", e);
} finally {
LdapClient.closeContext(zlc);
}
return members;
}
use of com.zimbra.cs.account.DistributionList in project zm-mailbox by Zimbra.
the class LdapProvisioning method createDistributionList.
private DistributionList createDistributionList(String listAddress, Map<String, Object> listAttrs, Account creator) throws ServiceException {
boolean isHabGroup = false;
SpecialAttrs specialAttrs = mDIT.handleSpecialAttrs(listAttrs);
String baseDn = specialAttrs.getLdapBaseDn();
listAddress = listAddress.toLowerCase().trim();
String[] parts = listAddress.split("@");
if (parts.length != 2)
throw ServiceException.INVALID_REQUEST("must be valid list address: " + listAddress, null);
String localPart = parts[0];
String domain = parts[1];
domain = IDNUtil.toAsciiDomainName(domain);
listAddress = localPart + "@" + domain;
validEmailAddress(listAddress);
CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
callbackContext.setCreatingEntryName(listAddress);
AttributeManager.getInstance().preModify(listAttrs, null, callbackContext, true);
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_DISTRIBUTIONLIST);
Domain d = getDomainByAsciiName(domain, zlc);
if (d == null)
throw AccountServiceException.NO_SUCH_DOMAIN(domain);
if (!d.isLocal()) {
throw ServiceException.INVALID_REQUEST("domain type must be local", null);
}
ZMutableEntry entry = LdapClient.createMutableEntry();
isHabGroup = populateEntryForHABGroup(entry, listAttrs, localPart, d, zlc);
entry.mapToAttrs(listAttrs);
Set<String> ocs = LdapObjectClass.getDistributionListObjectClasses(this, isHabGroup);
entry.addAttr(A_objectClass, ocs);
String zimbraIdStr = LdapUtil.generateUUID();
entry.setAttr(A_zimbraId, zimbraIdStr);
entry.setAttr(A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date()));
entry.setAttr(A_mail, listAddress);
// unlike accounts (which have a zimbraMailDeliveryAddress for the primary,
// and zimbraMailAliases only for aliases), DLs use zibraMailAlias for both.
// Postfix uses these two attributes to route mail, and zimbraMailDeliveryAddress
// indicates that something has a physical mailbox, which DLs don't.
entry.setAttr(A_zimbraMailAlias, listAddress);
// by default a distribution list is always created enabled
if (!entry.hasAttribute(Provisioning.A_zimbraMailStatus)) {
entry.setAttr(A_zimbraMailStatus, MAIL_STATUS_ENABLED);
}
String displayName = entry.getAttrString(Provisioning.A_displayName);
if (displayName != null && !isHabGroup) {
entry.setAttr(A_cn, displayName);
}
entry.setAttr(A_uid, localPart);
setGroupHomeServer(entry, creator);
if (!isHabGroup) {
entry.setDN(mDIT.distributionListDNCreate(baseDn, entry.getAttributes(), localPart, domain));
}
zlc.createEntry(entry);
DistributionList dlist = getDLBasic(DistributionListBy.id, zimbraIdStr, zlc);
if (dlist != null) {
AttributeManager.getInstance().postModify(listAttrs, dlist, callbackContext);
removeExternalAddrsFromAllDynamicGroups(dlist.getAllAddrsSet(), zlc);
allDLs.addGroup(dlist);
} else {
throw ServiceException.FAILURE("unable to get distribution list after creating LDAP entry: " + listAddress, null);
}
return dlist;
} catch (LdapEntryAlreadyExistException nabe) {
throw AccountServiceException.DISTRIBUTION_LIST_EXISTS(listAddress);
} catch (LdapException e) {
throw e;
} catch (AccountServiceException e) {
throw e;
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to create distribution list: " + listAddress, e);
} finally {
LdapClient.closeContext(zlc);
}
}
Aggregations