java.lang.Object
i2p.susi.webmail.MailCache
Caches email data for each folder with POP3 mailbox integration. Only DIR_FOLDER has a non-null POP3MailBox.
Nested Class Summary
Modifier and TypeClassDescriptionstatic enumEnumeration of email fetching strategies.private classLoads new mail in a background thread.private static classOutgoing to POP3.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final I2PAppContextThe app context.private final booleanTrue if this cache holds the drafts.private booleanTrue once the folder was loaded.private NewMailListenerListener of the load currently running.private final LogLogger for the mail cache.private final ObjectSerializes draft/sent full-mail writes.private final PersistentMailCacheThe on disk copy of the cache.private static final intIncludes header, headers are generally 1KB to 1.5 KB, and bodies will compress well.The folder holding the messages.private final StringThe name of the folder.private final POP3MailBoxThe mailbox the messages come from.The cached messages, by id.Constructor Summary
ConstructorsConstructorDescriptionMailCache(I2PAppContext ctx, POP3MailBox mailbox, String folderName, String host, int port, String user, String pass) Does NOT load the mails in.Method Summary
Modifier and TypeMethodDescriptionprivate static StringLooks up a localized string in the message bundle.private voidBlocking.voidMark mail for deletion locally.voiddelete(Collection<String> uidls) Mark mail for deletion locally.Where attachments for a newly composed draft are written.The sortable view of the UIDLs held in this cache.The folder key this cache was created under.getFullWriteBuffer(String uidl) For writing a new full mail (NOT headers only) Caller must close.booleangetMail(MailCache.FetchMode mode) Fetch any needed data from pop3 server.getMail(String uidl, MailCache.FetchMode mode) Fetch any needed data from pop3 server, unless mode is CACHE_ONLY or HEADER_CACHE_ONLY, or this isn't the Inbox.The folder name after message-bundle translation, "Inbox" for the inbox folder.String[]getUIDLs()The ones known locally, which will include any known on the server, if connected.The monitor callers must hold across a full-mail write.booleanisLoaded()Has loadFromDisk completed?booleanIs loadFromDisk in progress?booleanThreaded.private voidMoved a mail from another MailCache.booleanMove a mail to another MailCache, neither may be DIR_DRAFTS.private static StringLooks up the localized plural form for n items.voidwriteComplete(String uidl, Buffer buffer, boolean success) For writing a new full mail.
Field Details
mailbox
The mailbox the messages come from.mails
disk
The on disk copy of the cache._context
The app context.folder
folderName
The name of the folder._writeLock
Serializes draft/sent full-mail writes. @since 0.9.71+._loadInProgress
Listener of the load currently running._isLoaded
private boolean _isLoadedTrue once the folder was loaded._isDrafts
private final boolean _isDraftsTrue if this cache holds the drafts._log
Logger for the mail cache.FETCH_ALL_SIZE
private static final int FETCH_ALL_SIZEIncludes header, headers are generally 1KB to 1.5 KB, and bodies will compress well.- See Also:
Constructor Details
MailCache
MailCache(I2PAppContext ctx, POP3MailBox mailbox, String folderName, String host, int port, String user, String pass) throws IOException Does NOT load the mails in. Caller MUST callloadFromDisk(NewMailListener).- Parameters:
ctx- the application context supplying the logger and the disk cachemailbox- non-null for DIR_FOLDER; null otherwisefolderName- the folder this cache holds, one of the WebMail.DIR_ nameshost- POP3 host, passed through to the disk cache for reconnectsport- POP3 port, passed through to the disk cache for reconnectsuser- POP3 account name, passed through to the disk cachepass- POP3 password, passed through to the disk cache- Throws:
IOException- if the persistent cache directory cannot be created
Method Details
getFolderName
getTranslatedName
The folder name after message-bundle translation, "Inbox" for the inbox folder.- Returns:
- translation of name passed in
getFolder
getFullWriteBuffer
For writing a new full mail (NOT headers only) Caller must close. Caller must hold the write lock (seegetWriteLock()) for the whole write.- Parameters:
uidl- the UIDL identifying the mail being written- Returns:
- the full write buffer
getWriteLock
The monitor callers must hold across a full-mail write.- Returns:
- the write lock serializing draft and sent folder writes
writeComplete
getAttachmentDir
Where attachments for a newly composed draft are written.- Returns:
- non-null only for Drafts
moveTo
Move a mail to another MailCache, neither may be DIR_DRAFTS.- Parameters:
uidl- the UIDL of the mail to movetoMC- the cache receiving the mail- Returns:
- true if the mail was moved, false if either cache holds drafts or the mail has no body or its file is missing
movedTo
Moved a mail from another MailCache.- Parameters:
mail- the mail moved into this cache, its body is re-read from disk
isLoading
public boolean isLoading()Is loadFromDisk in progress?- Returns:
- true if loadFromDisk() is running
isLoaded
public boolean isLoaded()Has loadFromDisk completed?- Returns:
- true if loadFromDisk() has completed
loadFromDisk
Threaded. Returns immediately. This will not access the mailbox. Mailbox need not be ready.- Parameters:
nml- notified when the background load completes; not called if a load is already in progress or already finished- Returns:
- success false if in progress already and nml will NOT be called back, true if nml will be called back
blockingLoadFromDisk
private void blockingLoadFromDisk()Blocking. Only call once! This will not access the mailbox. Mailbox need not be ready.getUIDLs
The ones known locally, which will include any known on the server, if connected. Will not include any marked for deletion. This will not access the mailbox. Mailbox need not be ready. loadFromDisk() must have been called first.- Returns:
- non-null
getMail
Fetch any needed data from pop3 server, unless mode is CACHE_ONLY or HEADER_CACHE_ONLY, or this isn't the Inbox. Blocking for a long time unless mode is CACHE_ONLY or HEADER_CACHE_ONLY.- Parameters:
uidl- message id to getmode- CACHE_ONLY or HEADER_CACHE_ONLY to not pull from pop server- Returns:
- An e-mail or null
getMail
Fetch any needed data from pop3 server. Mail objects are inserted into the requests. After this, callgetUIDLs()to get all known mail UIDLs. MUST already be connected, otherwise returns false. Call only on inbox! Blocking.- Parameters:
mode- HEADER or ALL only- Returns:
- true if any were fetched
delete
Mark mail for deletion locally. Send delete requests to POP3 then quit and reconnect. No success/failure indication is returned. Does not delete from folder.- Parameters:
uidl- the UIDL of the mail to delete
delete
Mark mail for deletion locally. Send delete requests to POP3 then quit and reconnect. No success/failure indication is returned. Does not delete from folder.- Parameters:
uidls- the UIDLs of the mails to delete
_t
ngettext