java.lang.Object
i2p.susi.webmail.Mail
- Direct Known Subclasses:
Draft
Data structure representing a single email message for folder display and sorting.
Field Summary
Modifier and TypeFieldDescriptionprivate final LogLogger.private BufferRaw body buffer.(package private) String[]Addresses only, enclosed by<>.Content-Type header value.The parsed message date.private static final ThreadLocal<DateFormat> Formatter for short UTC date display.Long date-only format for mail list tooltips.private static final ThreadLocal<DateFormat> Formatter for long date-only tooltips.Raw date string from the Date header.Error message from parsing, or empty.Formatted date string in UTC.private BufferRaw header buffer.(package private) static final byte[]Also used byMailPartSee MailPart for why we don't do \r\n\r\n.private booleanWhether headers have been parsed.private booleanWhether this message is unread.private booleanWhether this message is flagged as spam.private static final ThreadLocal<DateFormat> Formatter for short local time zone display.Formatted date string in local time zone.private static final ThreadLocal<DateFormat> Formatter for medium local time zone display.booleanWhether this message is flagged for deletion.Message-ID as received, not HTML escaped.private static final StringRegex for email address without angle brackets.private static final StringRegex for email address with angle brackets.private MailPartParsed mail part tree.private static final PatternCompiled pattern for bare email addresses.private static final PatternCompiled pattern for bracketed email addresses.Quoted date in local time zone, longer format.Address only, enclosed by<>.As received, trimmed only, not HTML escaped.Sender name or address truncated with …Subject truncated with ….private longMessage size in bytes.As received, trimmed only, not HTML escaped.(package private) String[]May be null.final StringUnique ID assigned by the POP3 server.private static final StringDefault unknown date string.Constructor Summary
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendRecipients(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.static voidappendRecipients(StringBuilder buf, ArrayList<String> recipients, String prefix) Adds all items from the list to the builder, separated by tabs.(package private) static voidDelete the backing file of a body buffer if it is a susimail-new-* temp file.static StringgetAddress(String address) Pull the first e-mail address out of a header line.Get the attachment type.getBody()This contains the header also.This may or may not contain the body also.getPart()The parsed message part.static booleangetRecipientsFromList(ArrayList<String> recipients, String[] ccs, boolean ok) A little misnamed.static booleangetRecipientsFromList(ArrayList<String> recipients, String text, boolean ok) A little misnamed.longgetSize()The size the server reported for this message.booleanWhether the content type suggests an attachment.booleanhasBody()Whether the body has been loaded.booleanWhether the header has been fetched for this UIDL.booleanhasPart()Whether the body has been parsed into a MailPart.booleanisNew()Whether this message is new (unread).booleanisSpam()Whether this message is identified as spam.private String[]Parse the header lines of a message.voidRecord the body bytes fetched from the server.private voidsetDate(long dateLong) Sets the date from a long value.voidRecord the header bytes fetched from the server.private String[]setHeader(Buffer rb, InputStream in, boolean closeIn) Parse and store the message headers.voidsetNew(boolean isNew) Mark this message read or unread.voidsetSize(long size) Record the size the server reported.static booleanvalidateAddress(String address) Check an address for the shape a mail server will accept.
Field Details
unknown
P1
Regex for email address without angle brackets.- See Also:
P2
Regex for email address with angle brackets.- See Also:
PATTERN1
Compiled pattern for bare email addresses.PATTERN2
Compiled pattern for bracketed email addresses.HEADER_MATCH
static final byte[] HEADER_MATCHAlso used byMailPartSee MailPart for why we don't do \r\n\r\n.size
private long sizeMessage size in bytes.sender
As received, trimmed only, not HTML escaped.reply
Address only, enclosed by<>.subject
As received, trimmed only, not HTML escaped. Default "".dateString
Raw date string from the Date header.formattedDate
Formatted date string in UTC.localFormattedDate
Formatted date string in local time zone.shortSender
Sender name or address truncated with …shortSubject
Subject truncated with …. Default "".quotedDate
Quoted date in local time zone, longer format.dateOnly
Long date-only format for mail list tooltips.uidl
Unique ID assigned by the POP3 server.date
The parsed message date.header
Raw header buffer.body
Raw body buffer.part
Parsed mail part tree.to
String[] toMay be null. Non-empty if non-null. Not HTML escaped.cc
String[] ccAddresses only, enclosed by<>.isNew
private boolean isNewWhether this message is unread.isSpam
private boolean isSpamWhether this message is flagged as spam.headersParsed
private boolean headersParsedWhether headers have been parsed.contentType
Content-Type header value.messageID
Message-ID as received, not HTML escaped.error
Error message from parsing, or empty.markForDeletion
public boolean markForDeletionWhether this message is flagged for deletion._log
Logger.dateFormatter
Formatter for short UTC date display.dateOnlyFormatter
Formatter for long date-only tooltips.localDateFormatter
Formatter for short local time zone display.longLocalDateFormatter
Formatter for medium local time zone display.
Constructor Details
Mail
Create an empty message placeholder for one UIDL.- Parameters:
uidl- unique ID for this mail
Method Details
getHeader
This may or may not contain the body also.- Returns:
- if null, nothing has been loaded yet for this UIDL
setHeader
Record the header bytes fetched from the server.- Parameters:
rb- buffer containing header data
setHeader
Parse and store the message headers.- Parameters:
rb- the fetched header buffer, null to do nothingin- stream to read the header lines fromcloseIn- 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
deleteTempBodyFile
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
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
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
validateAddress
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
getRecipientsFromList
A little misnamed. Adds all addresses from the comma-separated line in text to the recipients list.- Parameters:
recipients- collects the addresses parsed from texttext- the comma-separated address line to split and parseok- will be returned- Returns:
- true if ALL e-mail addresses are valid AND the in parameter was true
getRecipientsFromList
A little misnamed. Adds all addresses from the elements in text to the recipients list.- Parameters:
recipients- collects the addresses parsed from textccs- the Cc addressesok- will be returned- Returns:
- true if ALL e-mail addresses are valid AND the in parameter was true
appendRecipients
Adds all items from the list to the builder, separated by tabs. This is for SMTP/POP.- Parameters:
buf- receives the formatted addressesrecipients- the addresses to write out, each followed by a comma except the lastprefix- prepended to the addresses
appendRecipients
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 linerecipients- the addresses to write out, separated by commas and folded at 75 charactersprefix- 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
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