Java 类javax.mail.internet.MailDateFormat 实例源码

项目:community-edition-old    文件:SimpleMessageAttributes.java   
void setAttributesFor(MimeMessage msg) throws MessagingException {
    try {
        internalDate = msg.getSentDate();
    } catch (MessagingException me) {
        internalDate = new Date();
    }
    if (null == internalDate) {
        internalDate = new Date();
    }

    /*  
     * mrogers
     * Internal Date Format must conform to RFC 3501
     */
    internalDateString = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss Z", Locale.ENGLISH).format(internalDate);
    interalDateEnvelopeString = new MailDateFormat().format(internalDate);
    parseMimePart(msg);
    envelope = null;
    bodyStructure = null;
}
项目:CryptMeme    文件:Email.java   
/**
 * Removes all headers that are not on the whitelist, and initializes some
 * basic header fields.<br/>
 * Called by {@link #saveChanges()}, see JavaMail JavaDoc.
 * @throws MessagingException
 */
@Override
public void updateHeaders() throws MessagingException {
    super.updateHeaders();
    scrubHeaders();
    removeRecipientNames();

    // Depending on includeSendTime, set the send time or remove the send time field
    if (includeSendTime) {
        if (getSentDate() == null) {
            // Set the "Date" field in UTC time, using the English locale.
            MailDateFormat formatter = new MailDateFormat();
            formatter.setTimeZone(TimeZone.getTimeZone("GMT"));   // always use UTC for outgoing mail
            setHeader("Date", formatter.format(new Date()));
        }
    }
    else
        removeHeader("Date");
}
项目:trading4j    文件:MailSenderIT.java   
private void assertCorrectDate(final String mailDate, final Instant minimalRaw, final Instant maximalRaw)
        throws ParseException {
    final Instant actual = new MailDateFormat().parse(mailDate).toInstant();

    final Instant minimal = minimalRaw.atOffset(UTC).withNano(0).minusNanos(1).toInstant();
    final Instant maximal = minimalRaw.atOffset(UTC).withNano(1).plusSeconds(1).toInstant();
    assertThat(actual.isAfter(minimal))
            .overridingErrorMessage("The date of the mail should be after %s but was %s.", minimal, actual)
            .isTrue();
    assertThat(actual.isBefore(maximal))
            .overridingErrorMessage("The date of the mail should be before %s but was %s.", maximal, actual)
            .isTrue();
}
项目:trading4j    文件:MailSenderIT.java   
private void assertCorrectDate(final String mailDate, final Instant minimalRaw, final Instant maximalRaw)
        throws ParseException {
    final Instant actual = new MailDateFormat().parse(mailDate).toInstant();

    final Instant minimal = minimalRaw.atOffset(UTC).withNano(0).minusNanos(1).toInstant();
    final Instant maximal = minimalRaw.atOffset(UTC).withNano(1).plusSeconds(1).toInstant();
    assertThat(actual.isAfter(minimal))
            .overridingErrorMessage("The date of the mail should be after %s but was %s.", minimal, actual)
            .isTrue();
    assertThat(actual.isBefore(maximal))
            .overridingErrorMessage("The date of the mail should be before %s but was %s.", maximal, actual)
            .isTrue();
}
项目:CryptMeme    文件:EmailMetadata.java   
/**
 * Returns the date and time the email was submitted by the user, or <code>null</code>
 * if the value cannot be parsed.
 */
public Date getCreateTime() {
    String dateStr = getProperty(PROPERTY_CREATE_TIME);
    Date createTime;
    try {
        createTime = new MailDateFormat().parse(dateStr);
    } catch (ParseException e) {
        log.error("Can't parse create time.", e);
        createTime = null;
    }
    return createTime;
}
项目:CryptMeme    文件:EmailMetadata.java   
public void setCreateTime(Date createTime) {
    setProperty(PROPERTY_CREATE_TIME, new MailDateFormat().format(createTime));
}
项目:ImapNote2    文件:UpdateThread.java   
public void WriteMailToNew(OneNote note, String usesticky, String noteBody) throws MessagingException, IOException {
  String body = null;

  // Here we add the new note to the "new" folder
  //Log.d(TAG,"Add new note");
  Properties props = new Properties();
  Session session = Session.getDefaultInstance(props, null);
  MimeMessage message = new MimeMessage(session);
  if (usesticky.equals("true")) {
    body = "BEGIN:STICKYNOTE\nCOLOR:" + this.color + "\nTEXT:" + noteBody +
           "\nPOSITION:0 0 0 0\nEND:STICKYNOTE";
    message.setText(body);
    message.setHeader("Content-Transfer-Encoding", "8bit");
    message.setHeader("Content-Type","text/x-stickynote; charset=\"utf-8\"");
  } else {
    message.setHeader("X-Uniform-Type-Identifier","com.apple.mail-note");
    UUID uuid = UUID.randomUUID();
    message.setHeader("X-Universally-Unique-Identifier", uuid.toString());
    body = noteBody;
    body = body.replaceFirst("<p dir=ltr>", "<div>");
    body = body.replaceFirst("<p dir=\"ltr\">", "<div>");
    body = body.replaceAll("<p dir=ltr>", "<div><br></div><div>");
    body = body.replaceAll("<p dir=\"ltr\">", "<div><br></div><div>");
    body = body.replaceAll("</p>", "</div>");
    body = body.replaceAll("<br>\n", "</div><div>");
    message.setText(body, "utf-8", "html");
    message.setFlag(Flags.Flag.SEEN,true);
  }
  message.setSubject(note.GetTitle());
  MailDateFormat mailDateFormat = new MailDateFormat();
  // Remove (CET) or (GMT+1) part as asked in github issue #13
  String headerDate = (mailDateFormat.format(new Date())).replaceAll("\\(.*$", "");
  message.addHeader("Date", headerDate);
  //déterminer l'uid temporaire
  String uid = Integer.toString(Math.abs(Integer.parseInt(note.GetUid())));
  File directory = new File ((ImapNotes2.getAppContext()).getFilesDir() + "/" +
          Listactivity.imapNotes2Account.GetAccountname() + "/new");
  //message.setFrom(new InternetAddress("ImapNotes2", Listactivity.imapNotes2Account.GetAccountname()));
  message.setFrom(Listactivity.imapNotes2Account.GetAccountname());
  File outfile = new File (directory, uid);
  OutputStream str = new FileOutputStream(outfile);
  message.writeTo(str);

}