Ejemplo n.º 1
0
 /** construct recipient addresses from user entities */
 private Address[] resolveAddresses(List<User> users, AddressResolver addressResolver) {
   int userCount = users.size();
   List<Address> addresses = new ArrayList<Address>();
   for (int i = 0; i < userCount; i++) {
     if (!StringUtils.isEmpty(users.get(i).getBusinessEmail())) {
       addresses.add(addressResolver.resolveAddress(users.get(i)));
     }
   }
   return addresses.toArray(new Address[addresses.size()]);
 }
Ejemplo n.º 2
0
  /**
   * Fills the <code>from</code> attribute of the given email. The sender addresses are an optional
   * element in the mail template. If absent, each mail server supplies the current user's email
   * address.
   *
   * @see {@link InternetAddress#getLocalAddress(Session)}
   */
  protected void fillFrom(Message email, Execution execution, JCRSessionWrapper session)
      throws MessagingException {
    try {
      AddressTemplate fromTemplate = getTemplate().getFrom();
      // "from" attribute is optional
      if (fromTemplate == null) return;

      // resolve and parse addresses
      String addresses = fromTemplate.getAddresses();
      if (addresses != null) {
        addresses = evaluateExpression(execution, addresses, session);
        // non-strict parsing applies to a list of mail addresses entered by a human
        email.addFrom(InternetAddress.parse(addresses, false));
      }

      EnvironmentImpl environment = EnvironmentImpl.getCurrent();
      IdentitySession identitySession = environment.get(IdentitySession.class);
      AddressResolver addressResolver = environment.get(AddressResolver.class);

      // resolve and tokenize users
      String userList = fromTemplate.getUsers();
      if (userList != null) {
        String[] userIds = tokenizeActors(userList, execution, session);
        List<User> users = identitySession.findUsersById(userIds);
        email.addFrom(resolveAddresses(users, addressResolver));
      }

      // resolve and tokenize groups
      String groupList = fromTemplate.getGroups();
      if (groupList != null) {
        for (String groupId : tokenizeActors(groupList, execution, session)) {
          Group group = identitySession.findGroupById(groupId);
          email.addFrom(addressResolver.resolveAddresses(group));
        }
      }
    } catch (ScriptException e) {
      logger.error(e.getMessage(), e);
    } catch (RepositoryException e) {
      logger.error(e.getMessage(), e);
    }
  }
Ejemplo n.º 3
0
  private void fillRecipients(
      AddressTemplate addressTemplate,
      Message email,
      Message.RecipientType recipientType,
      Execution execution,
      JCRSessionWrapper session)
      throws MessagingException, RepositoryException, ScriptException {
    // resolve and parse addresses
    String addresses = addressTemplate.getAddresses();
    if (addresses != null) {
      addresses = evaluateExpression(execution, addresses, session);
      // non-strict parsing applies to a list of mail addresses entered by a human
      email.addRecipients(recipientType, InternetAddress.parse(addresses, false));
    }

    EnvironmentImpl environment = EnvironmentImpl.getCurrent();
    IdentitySession identitySession = environment.get(IdentitySession.class);
    AddressResolver addressResolver = environment.get(AddressResolver.class);

    // resolve and tokenize users
    String userList = addressTemplate.getUsers();
    if (userList != null) {
      String[] userIds = tokenizeActors(userList, execution, session);
      List<User> users = identitySession.findUsersById(userIds);
      email.addRecipients(recipientType, resolveAddresses(users, addressResolver));
    }

    // resolve and tokenize groups
    String groupList = addressTemplate.getGroups();
    if (groupList != null) {
      for (String groupId : tokenizeActors(groupList, execution, session)) {
        Group group = identitySession.findGroupById(groupId);
        email.addRecipients(recipientType, addressResolver.resolveAddresses(group));
      }
    }
  }