java.lang.Object
i2p.susi.webmail.Mail
Direct Known Subclasses:
Draft

class Mailextends Object
Data structure representing a single email message for folder display and sorting.
  • Field Details

    • unknown

      private static final String unknown
      Default unknown date string.
      See Also:
    • P1

      private static final String P1
      Regex for email address without angle brackets.
      See Also:
    • P2

      private static final String P2
      Regex for email address with angle brackets.
      See Also:
    • PATTERN1

      private static final Pattern PATTERN1
      Compiled pattern for bare email addresses.
    • PATTERN2

      private static final Pattern PATTERN2
      Compiled pattern for bracketed email addresses.
    • HEADER_MATCH

      static final byte[] HEADER_MATCH
      Also used by MailPart See MailPart for why we don't do \r\n\r\n.
    • size

      private long size
      Message size in bytes.
    • sender

      public String sender
      As received, trimmed only, not HTML escaped.
    • reply

      public String reply
      Address only, enclosed by <>.
    • subject

      public String subject
      As received, trimmed only, not HTML escaped. Default "".
    • dateString

      public String dateString
      Raw date string from the Date header.
    • formattedDate

      public String formattedDate
      Formatted date string in UTC.
    • localFormattedDate

      public String localFormattedDate
      Formatted date string in local time zone.
    • shortSender

      public String shortSender
      Sender name or address truncated with …
    • shortSubject

      public String shortSubject
      Subject truncated with …. Default "".
    • quotedDate

      public String quotedDate
      Quoted date in local time zone, longer format.
    • dateOnly

      public String dateOnly
      Long date-only format for mail list tooltips.
    • uidl

      public final String uidl
      Unique ID assigned by the POP3 server.
    • date

      public Date date
      The parsed message date.
    • body

      private Buffer body
      Raw body buffer.
    • part

      private MailPart part
      Parsed mail part tree.
    • to

      String[] to
      May be null. Non-empty if non-null. Not HTML escaped.
    • cc

      String[] cc
      Addresses only, enclosed by <>.
    • isNew

      private boolean isNew
      Whether this message is unread.
    • isSpam

      private boolean isSpam
      Whether this message is flagged as spam.
    • headersParsed

      private boolean headersParsed
      Whether headers have been parsed.
    • contentType

      public String contentType
      Content-Type header value.
    • messageID

      public String messageID
      Message-ID as received, not HTML escaped.
    • error

      public String error
      Error message from parsing, or empty.
    • markForDeletion

      public boolean markForDeletion
      Whether this message is flagged for deletion.
    • _log

      private final Log _log
      Logger.
    • dateFormatter

      private static final ThreadLocal<DateFormat> dateFormatter
      Formatter for short UTC date display.
    • dateOnlyFormatter

      private static final ThreadLocal<DateFormat> dateOnlyFormatter
      Formatter for long date-only tooltips.
    • localDateFormatter

      private static final ThreadLocal<DateFormat> localDateFormatter
      Formatter for short local time zone display.
    • longLocalDateFormatter

      private static final ThreadLocal<DateFormat> longLocalDateFormatter
      Formatter for medium local time zone display.
  • Constructor Details

    • Mail

      public Mail(String uidl)
      Create an empty message placeholder for one UIDL.
      Parameters:
      uidl - unique ID for this mail
  • Method Details

    • getHeader

      public Buffer getHeader()
      This may or may not contain the body also.
      Returns:
      if null, nothing has been loaded yet for this UIDL
    • setHeader

      public void setHeader(Buffer rb)
      Record the header bytes fetched from the server.
      Parameters:
      rb - buffer containing header data
    • setHeader

      private String[] setHeader(Buffer rb, InputStream in, boolean closeIn)
      Parse and store the message headers.
      Parameters:
      rb - the fetched header buffer, null to do nothing
      in - stream to read the header lines from
      closeIn - whether to mark the buffer read-complete when done
      Returns:
      all headers, to pass to MailPart, or null on error
    • hasHeader

      public boolean hasHeader()
      Whether the header has been fetched for this UIDL.
      Returns:
      if false, nothing has been loaded yet for this UIDL
    • getBody

      public Buffer getBody()
      This contains the header also.
      Returns:
      may be null
    • deleteTempBodyFile

      static void deleteTempBodyFile(Buffer rb)
      Delete the backing file of a body buffer if it is a susimail-new-* temp file. The disk cache files (GzipFileBuffer) are never deleted here.
      Parameters:
      rb - the buffer whose backing file should be removed when it is a susimail-new-* temp file; any other buffer, and every disk cache file, is left alone
    • setBody

      public void setBody(Buffer rb)
      Record the body bytes fetched from the server.
      Parameters:
      rb - buffer containing body data
    • hasBody

      public boolean hasBody()
      Whether the body has been loaded.
      Returns:
      true if body is loaded
    • getPart

      public MailPart getPart()
      The parsed message part.
      Returns:
      the parsed MailPart, or null
    • hasPart

      public boolean hasPart()
      Whether the body has been parsed into a MailPart.
      Returns:
      true if the body has been parsed into a MailPart
    • getSize

      public long getSize()
      The size the server reported for this message.
      Returns:
      0 if unknown
    • setSize

      public void setSize(long size)
      Record the size the server reported.
      Parameters:
      size - the message size
    • isSpam

      public boolean isSpam()
      Whether this message is identified as spam.
      Returns:
      true if identified as spam
    • isNew

      public boolean isNew()
      Whether this message is new (unread).
      Returns:
      true if mail is new (unread)
    • setNew

      public void setNew(boolean isNew)
      Mark this message read or unread.
      Parameters:
      isNew - the new/unread flag
    • hasAttachment

      public boolean hasAttachment()
      Whether the content type suggests an attachment.
      Returns:
      true if the content type suggests an attachment
    • getAttachmentType

      public String getAttachmentType()
      Get the attachment type.
      Returns:
      the attachment type string
    • validateAddress

      public static boolean validateAddress(String address)
      Check an address for the shape a mail server will accept.
      Parameters:
      address - E-mail address to be validated
      Returns:
      Is the e-mail address valid?
    • getAddress

      public static String getAddress(String address)
      Pull the first e-mail address out of a header line.
      Parameters:
      address - the header text to scan
      Returns:
      the address enclosed in angle brackets, or null
    • getRecipientsFromList

      public static boolean getRecipientsFromList(ArrayList<String> recipients, String text, boolean ok)
      A little misnamed. Adds all addresses from the comma-separated line in text to the recipients list.
      Parameters:
      recipients - collects the addresses parsed from text
      text - the comma-separated address line to split and parse
      ok - will be returned
      Returns:
      true if ALL e-mail addresses are valid AND the in parameter was true
    • getRecipientsFromList

      public static boolean getRecipientsFromList(ArrayList<String> recipients, String[] ccs, boolean ok)
      A little misnamed. Adds all addresses from the elements in text to the recipients list.
      Parameters:
      recipients - collects the addresses parsed from text
      ccs - the Cc addresses
      ok - will be returned
      Returns:
      true if ALL e-mail addresses are valid AND the in parameter was true
    • appendRecipients

      public static void appendRecipients(StringBuilder buf, ArrayList<String> recipients, String prefix)
      Adds all items from the list to the builder, separated by tabs. This is for SMTP/POP.
      Parameters:
      buf - receives the formatted addresses
      recipients - the addresses to write out, each followed by a comma except the last
      prefix - prepended to the addresses
    • appendRecipients

      public static void appendRecipients(PrintWriter out, String[] recipients, String prefix)
      Adds all items from the array to the builder, separated by commas This is for display of a forwarded email.
      Parameters:
      out - the writer the folded recipient lines are printed to, one println() per 75-character line
      recipients - the addresses to write out, separated by commas and folded at 75 characters
      prefix - prepended to the addresses, includes trailing ": "
    • setDate

      private void setDate(long dateLong)
      Sets the date from a long value.
      Parameters:
      dateLong - milliseconds since the epoch, never negative
    • parseHeaders

      private String[] parseHeaders(InputStream in)
      Parse the header lines of a message.
      Parameters:
      in - stream to read the header lines from
      Returns:
      all headers, to pass to MailPart, or null on error