java.lang.Object
i2p.susi.webmail.PersistentMailCache
Manages persistent on-disk email cache with custom compressed format. This is a custom format with subdirectories, gzipped files, and the encoded UIDL in the file name. We store either the headers or the full message. No, it is not Maildir format but we could add Maildir-style status suffixes (e.g. ":2.SR") later. Exporting to a Maildir format would be just ungzipping each file to a flat directory. This class should only be accessed from MailCache.
Field Summary
FieldsConstructor Summary
ConstructorsConstructorDescriptionPersistentMailCache(I2PAppContext ctx, String host, int port, String user, String pass, String folder) Use the params to generate a unique directory name.Method Summary
All MethodsModifier and TypeMethodDescriptionvoiddeleteMail(Mail mail) Delete both the full-message and the header-only file for this mail.voiddeleteMail(String uidl) Delete both the full-message and the header-only file for this uidl.Where draft attachments are stored, which only the drafts cache creates.getFullBuffer(String uidl) For reading or writing a new full mail (NOT headers only).getFullFile(String uidl) The gzipped full-message file for this uidl.getHeaderFile(String uidl) The gzipped header-only file for this uidl.booleanFetch any needed data from disk, filling in the header, or the body if that is what was asked for and only a header file is on disk.getMails()Fetch all mails from disk.booleanWrite the mail to disk as a full message when it has a body, otherwise as a header-only file.
Field Details
DIR_IMPORT
Directory beside the cache holding imported .eml files, debug only.- See Also:
DIR_ATTACHMENTS
Directory holding draft attachment files, created only by the drafts cache.- See Also:
Constructor Details
PersistentMailCache
public PersistentMailCache(I2PAppContext ctx, String host, int port, String user, String pass, String folder) throws IOException Use the params to generate a unique directory name. Does NOT load the mails in. Caller MUST call getMails().- Parameters:
ctx- supplies the log manager and the base directoryhost- IMAP host, part of the directory nameport- IMAP port, part of the directory nameuser- mail account name, part of the directory namepass- not used; the cache is keyed on account name alonefolder- on-disk maildir name, one of theDIRSvalues, e.g.DIR_FOLDER; only DIR_DRAFTS gets an attachment directory- Throws:
IOException- if the cache directory cannot be created
Method Details
getMails
getMail
Fetch any needed data from disk, filling in the header, or the body if that is what was asked for and only a header file is on disk.- Parameters:
mail- the mail to populate, matched on its uidlheaderOnly- true to load just the header, false to load the body too- Returns:
- true if the mail was populated; false if no file exists for the uidl or it could not be read
saveMail
Write the mail to disk as a full message when it has a body, otherwise as a header-only file. An existing file is left alone.- Parameters:
mail- the mail to save- Returns:
- true if the file is on disk, either just written or already present; false if the mail carries neither body nor header, or the write failed
deleteMail
Delete both the full-message and the header-only file for this mail.- Parameters:
mail- the mail to remove
deleteMail
Delete both the full-message and the header-only file for this uidl.- Parameters:
uidl- the unique ID of the mail to remove
getHeaderFile
getFullFile
getFullBuffer
For reading or writing a new full mail (NOT headers only). For writing, caller MUST call writeComplete() on rv. Does not necessarily exist.- Parameters:
uidl- the unique ID of the mail- Returns:
- a new buffer over the full message file
getAttachmentDir
Where draft attachments are stored, which only the drafts cache creates.- Returns:
- non-null only for Drafts