Search in sources :

Example 11 with Group

use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.

the class SoapProvisioning method getAllGroups.

@Override
public List<Group> getAllGroups(Domain domain) throws ServiceException {
    ArrayList<Group> result = new ArrayList<Group>();
    GetAllDistributionListsResponse resp = invokeJaxb(new GetAllDistributionListsRequest(getSelector(domain)));
    for (DistributionListInfo dl : resp.getDls()) {
        result.add(makeGroup(dl));
    }
    return result;
}
Also used : Group(com.zimbra.cs.account.Group) DistributionListInfo(com.zimbra.soap.admin.type.DistributionListInfo) ArrayList(java.util.ArrayList)

Example 12 with Group

use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.

the class MilterHandler method SMFIC_BodyEOB.

private void SMFIC_BodyEOB() throws IOException {
    ZimbraLog.milter.debug("SMFIC_BodyEOB");
    Set<String> listAddrs = Sets.newHashSetWithExpectedSize(lists.size());
    Set<String> replyToAddrs = Sets.newHashSetWithExpectedSize(lists.size());
    for (Group group : lists) {
        if (group == null) {
            ZimbraLog.milter.warn("null group in group list!?!");
            continue;
        }
        if (visibleAddresses.contains(group.getMail().toLowerCase())) {
            listAddrs.add(group.getMail());
            if (group.isPrefReplyToEnabled()) {
                String addr = group.getPrefReplyToAddress();
                if (Strings.isNullOrEmpty(addr)) {
                    // fallback to the default email address
                    addr = group.getMail();
                }
                String disp = group.getPrefReplyToDisplay();
                if (Strings.isNullOrEmpty(disp)) {
                    // fallback to the default display name
                    disp = group.getDisplayName();
                }
                replyToAddrs.add(new InternetAddress(disp, addr).toString());
            }
        }
    }
    if (!listAddrs.isEmpty()) {
        SMFIR_ChgHeader(1, "X-Zimbra-DL", Joiner.on(", ").join(listAddrs));
    }
    if (!replyToAddrs.isEmpty()) {
        SMFIR_ChgHeader(1, "Reply-To", Joiner.on(", ").join(replyToAddrs));
    }
    connection.send(new MilterPacket(SMFIR_ACCEPT));
}
Also used : Group(com.zimbra.cs.account.Group) InternetAddress(com.zimbra.common.mime.InternetAddress)

Example 13 with Group

use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.

the class MilterHandler method SMFIC_Rcpt.

private void SMFIC_Rcpt() throws ServiceException {
    ZimbraLog.milter.debug("SMFIC_Rcpt");
    String sender = context.get(Context.SENDER);
    if (sender == null) {
        ZimbraLog.milter.warn("Empty sender");
    }
    String rcpt = context.get(Context.RECIPIENT);
    if (rcpt == null) {
        ZimbraLog.milter.warn("Empty recipient");
    }
    if (sender == null || rcpt == null) {
        connection.send(new MilterPacket(SMFIR_TEMPFAIL));
        return;
    }
    if (prov.isDistributionList(rcpt)) {
        Group group = prov.getGroupBasic(Key.DistributionListBy.name, rcpt);
        if (group != null) {
            if (!accessMgr.canDo(sender, group, User.R_sendToDistList, false)) {
                ZimbraLog.milter.debug("Sender is not allowed to email this distribution list: %s", rcpt);
                SMFIR_ReplyCode("571", "571 Sender is not allowed to email this distribution list: " + rcpt);
                return;
            }
            lists.add(group);
            ZimbraLog.milter.debug("group %s has been added into the list.", group);
        } else {
            ZimbraLog.milter.debug("rcpt %s is a list but not a group?", rcpt);
        }
    } else {
        ZimbraLog.milter.debug("%s is not a distribution list.", rcpt);
    }
    connection.send(new MilterPacket(SMFIR_CONTINUE));
}
Also used : Group(com.zimbra.cs.account.Group)

Example 14 with Group

use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.

the class GetAllDistributionLists method doDomain.

private void doDomain(ZimbraSoapContext zsc, Element e, Domain d, AdminAccessControl aac) throws ServiceException {
    List dls = Provisioning.getInstance().getAllGroups(d);
    for (Iterator it = dls.iterator(); it.hasNext(); ) {
        Group dl = (Group) it.next();
        boolean hasRightToList = true;
        if (dl.isDynamic()) {
            // TODO: fix me
            hasRightToList = true;
        } else {
            hasRightToList = aac.hasRightsToList(dl, Admin.R_listDistributionList, null);
        }
        if (hasRightToList) {
            GetDistributionList.encodeDistributionList(e, dl, true, false, null, aac.getAttrRightChecker(dl));
        }
    }
}
Also used : Group(com.zimbra.cs.account.Group) Iterator(java.util.Iterator) DistributionList(com.zimbra.cs.account.DistributionList) List(java.util.List)

Example 15 with Group

use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.

the class SmtpRecipientValidator method validate.

@Override
public Iterable<String> validate(String recipient) {
    try {
        Provisioning prov = Provisioning.getInstance();
        Account account = prov.get(AccountBy.name, recipient);
        if (account != null) {
            return Arrays.asList(account.getName());
        } else {
            Group group = prov.getGroup(Key.DistributionListBy.name, recipient);
            if (group != null) {
                String[] members;
                if (group instanceof DynamicGroup) {
                    members = ((DynamicGroup) group).getAllMembers(true);
                } else {
                    members = group.getAllMembers();
                }
                return Arrays.asList(members);
            }
        }
    } catch (ServiceException e) {
        log.error("Unable to validate recipient %s", recipient, e);
    }
    return Collections.emptyList();
}
Also used : Account(com.zimbra.cs.account.Account) DynamicGroup(com.zimbra.cs.account.DynamicGroup) Group(com.zimbra.cs.account.Group) DynamicGroup(com.zimbra.cs.account.DynamicGroup) ServiceException(com.zimbra.common.service.ServiceException) Provisioning(com.zimbra.cs.account.Provisioning)

Aggregations

Group (com.zimbra.cs.account.Group)110 Account (com.zimbra.cs.account.Account)53 Test (org.junit.Test)42 DynamicGroup (com.zimbra.cs.account.DynamicGroup)27 ServiceException (com.zimbra.common.service.ServiceException)23 SoapTransport (com.zimbra.common.soap.SoapTransport)23 Provisioning (com.zimbra.cs.account.Provisioning)23 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)21 Domain (com.zimbra.cs.account.Domain)17 GuestAccount (com.zimbra.cs.account.GuestAccount)17 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)17 Element (com.zimbra.common.soap.Element)16 AccountServiceException (com.zimbra.cs.account.AccountServiceException)15 NamedEntry (com.zimbra.cs.account.NamedEntry)14 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)12 DistributionListActionRequest (com.zimbra.soap.account.message.DistributionListActionRequest)12 DistributionListAction (com.zimbra.soap.account.type.DistributionListAction)12 DistributionListActionResponse (com.zimbra.soap.account.message.DistributionListActionResponse)11 DistributionList (com.zimbra.cs.account.DistributionList)9 Entry (com.zimbra.cs.account.Entry)9