public Email parse(final Map<String, String> keyVals) {
    if (_parsed) {
      return _email;
    }

    _email = new Email();

    if (null == keyVals) {
      return _email;
    }

    keyVals.putAll(parseScript(keyVals));

    Iterator<String> i = keyVals.keySet().iterator();
    while (i.hasNext()) {
      String key = i.next();
      String token = "@" + key + "@";
      String val = keyVals.get(key);
      val = Matcher.quoteReplacement(val);

      _addressee = _addressee.replaceAll(token, val);
      _subject = _subject.replaceAll(token, val);
      _template = _template.replaceAll(token, val);
    }

    _email.setSubject(_subject);

    _email.setTo(_addressee.split(","));
    _email.setBody(_template);

    _parsed = true;

    return _email;
  }
Exemple #2
0
  /**
   * Deliveres notification to the user that an email has been dropped. Typically due to size
   * restriction
   *
   * @param account
   * @param messageNumber
   * @param message
   * @throws Exception
   */
  public void saveMessageDroppedNotification(
      Account account, int messageNumber, Message message, int reportedSize) throws Exception {
    MessageParser parser = new MessageParser();

    Email email = new Email();
    email.setSubject(
        "Your email"); // ReceiverUtilsTools.subSubject(parser.parseMsgSubject(message),
                       // subjectSize));
    email.setFrom(parser.parseMsgAddress(message, "FROM", false));
    email.setTo(ReceiverUtilsTools.subAddress(parser.parseMsgAddress(message, "TO", true)));
    email.setCc(ReceiverUtilsTools.subAddress(parser.parseMsgAddress(message, "CC", true)));
    email.setBcc(ReceiverUtilsTools.subAddress(parser.parseMsgAddress(message, "BCC", true)));
    email.setMaildate(ReceiverUtilsTools.dateToStr(message.getSentDate()));
    email.setStatus("0");
    email.setUserId(account.getUser_id());
    email.setMessage_type("EMAIL");

    Body body = new Body();

    String droppedMessage =
        getEmailDroppedMessage(account, getMessageDate(message), reportedSize, email.getFrom());

    body.setData(droppedMessage.getBytes());
    email.setBodySize(droppedMessage.length());

    int saveStatus = DALDominator.newSaveMail(account, email, body);

    if (log.isDebugEnabled())
      log.debug(
          String.format(
              "[%s] msgNum=%d, saving completed for dropped message with status %s",
              account.getName(), messageNumber, saveStatus));
  }
Exemple #3
0
 public final Email buildEmail() {
   final Email email = new Email();
   email.setAttachments(getAttachments());
   email.setContent(getContent());
   email.setSubject(subject);
   email.setTo(getTo());
   return email;
 }
  private void saveToCache(MimeMessage[] messages) {

    for (int i = 0; i < messages.length; i++) {

      Email email = new Email();
      try {

        email.setMessageID(messages[i].getMessageID());

        HashSet<String> from = new HashSet<String>();
        if (messages[i].getFrom() != null) {
          from = getEmailAdress(messages[i].getFrom());
        }
        email.setFrom(from);

        HashSet<Email> replies = new HashSet<Email>();

        if (messages[i].getHeader("In-Reply-To") != null) {
          String inReplyTo = extractReplyID(messages[i].getHeader("In-Reply-To")[0]);

          email.setInReplyTo(inReplyTo);
          replies.add(emailData.get(inReplyTo));
        }

        if (messages[i].getHeader("References") != null) {
          HashSet<Email> referenceList = getEmailAdress(messages[i].getHeader("References")[0]);
          email.setReferences(referenceList);
          replies.addAll(referenceList);
        }

        email.setReplies(replies);

        if (messages[i].getAllRecipients() != null) {
          email.setAllRecipients(getEmailAdress(messages[i].getAllRecipients()));
        }

        email.setSubject(messages[i].getSubject());

        // email.put("content", getText(messages[i]));

        email.setSentDate(messages[i].getSentDate());

        emailData.put(email.getMessageID(), email);

        // recursiveProcessReplies(email);
        emailCount++;

      } catch (MessagingException e) {
        emailLevelErrors++;
        // System.out.println("MessagingException on saveToDB: getContents: " + e.getMessage());
      }
    }
  }
Exemple #5
0
  public void notifyAccountLock(Account account, String context) {
    PartnerCode partnerCode = account.getPartnerCode();
    String lockedOutMessageBody =
        SysConfigManager.instance()
            .getValue("lockedOutMessageBody", LOCKED_OUT_MESSAGE_BODY, partnerCode);
    String lockedOutMessageSubject =
        SysConfigManager.instance()
            .getValue("lockedOutMessageSubject", LOCKED_OUT_MESSAGE_SUBJECT, partnerCode);
    String lockedOutMessageFrom =
        SysConfigManager.instance()
            .getValue("lockedOutMessageFrom", LOCKED_OUT_MESSAGE_FROM, partnerCode);
    String lockedOutMessageAlias =
        SysConfigManager.instance()
            .getValue("lockedOutMessageAlias", LOCKED_OUT_MESSAGE_ALIAS, partnerCode);

    try {
      Email email = new Email();
      email.setSubject(lockedOutMessageSubject);

      email.setStatus("0");
      email.setUserId(account.getUser_id());
      email.setMessage_type("EMAIL");

      email.setFrom(lockedOutMessageFrom);
      email.setFrom_alias(lockedOutMessageAlias);
      email.setTo(account.getLoginName());
      email.setBodySize(lockedOutMessageBody.length());

      DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      email.setMaildate(dateFormat.format(new Date(System.currentTimeMillis()))); // ugh!

      email.setOriginal_account(account.getLoginName());

      // create the pojgo
      EmailPojo emailPojo = new EmailPojo();
      emailPojo.setEmail(email);

      Body body = new Body();
      body.setData(lockedOutMessageBody.getBytes());

      // note, the email will be encoded to prevent sql-injection. since this email is destined
      // directly for the
      // device, we need to reverse the encoding after the call to newSaveEmail
      new EmailRecievedService().newSaveEmail(account, email, body);

      // Added by Dan so we stop checking accounts that have incorrect passwords
      account.setStatus("0");

    } catch (Throwable t) {
      log.warn(String.format("failed to save locked out message for %s", context), t);
    }
  }
  /**
   * Get the template for an email message. The message is suitable for inserting values using
   * <code>java.text.MessageFormat</code>.
   *
   * @param emailFile full name for the email template, for example
   *     "/dspace/config/emails/register".
   * @return the email object, with the content and subject filled out from the template
   * @throws IOException if the template couldn't be found, or there was some other error reading
   *     the template
   */
  public static Email getEmail(String emailFile) throws IOException {
    String charset = null;
    String subject = "";
    StringBuffer contentBuffer = new StringBuffer();

    // Read in template
    BufferedReader reader = null;
    try {
      reader = new BufferedReader(new FileReader(emailFile));

      boolean more = true;

      while (more) {
        String line = reader.readLine();

        if (line == null) {
          more = false;
        } else if (line.toLowerCase().startsWith("subject:")) {
          // Extract the first subject line - everything to the right
          // of the colon, trimmed of whitespace
          subject = line.substring(8).trim();

          // 20110611 by Pudding Chen
          Date date = new Date();
          SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
          String time = df.format(date);
          subject = subject + " (" + time + ")";
        } else if (line.toLowerCase().startsWith("charset:")) {
          // Extract the character set from the email
          charset = line.substring(8).trim();
        } else if (!line.startsWith("#")) {
          // Add non-comment lines to the content
          contentBuffer.append(line);
          contentBuffer.append("\n");
        }
      }
    } finally {
      if (reader != null) {
        reader.close();
      }
    }
    // Create an email
    Email email = new Email();
    email.setSubject(subject);
    email.setContent(contentBuffer.toString());

    if (charset != null) email.setCharset(charset);

    return email;
  }