i2p.susi.webmail

## Class MailCache

- java.lang.Object
- - i2p.susi.webmail.MailCache

-     class MailCache
      extends Object

  Caches email data for each folder with POP3 mailbox integration. Only DIR_FOLDER has a non-null POP3MailBox.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `MailCache.FetchMode` Enumeration of email fetching strategies.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MailCache(I2PAppContext ctx, POP3MailBox mailbox, String folderName, String host, int port, String user, String pass)` Does NOT load the mails in.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `delete(Collection<String> uidls)` Mark mail for deletion locally.
    `void` | `delete(String uidl)` Mark mail for deletion locally.
    `File` | `getAttachmentDir()`
    `Folder<String>` | `getFolder()`
    `String` | `getFolderName()`
    `Buffer` | `getFullWriteBuffer(String uidl)` For writing a new full mail (NOT headers only) Caller must close.
    `boolean` | `getMail(MailCache.FetchMode mode)` Fetch any needed data from pop3 server.
    `Mail` | `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.
    `String` | `getTranslatedName()`
    `String[]` | `getUIDLs()` The ones known locally, which will include any known on the server, if connected.
    `boolean` | `isLoaded()` Has loadFromDisk completed?
    `boolean` | `isLoading()` Is loadFromDisk in progress?
    `boolean` | `loadFromDisk(NewMailListener nml)` Threaded.
    `boolean` | `moveTo(String uidl, MailCache toMC)` Move a mail to another MailCache, neither may be DIR_DRAFTS
    `void` | `writeComplete(String uidl, Buffer buffer, boolean success)` For writing a new full mail

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### 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 call loadFromDisk().
      Parameters:
        `mailbox` - non-null for DIR_FOLDER; null otherwise
      Throws:
        `IOException`

  - ### Method Detail

    - #### delete

          public void delete(Collection<String> uidls)

      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.

    - #### delete

          public void delete(String uidl)

      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.

    - #### getAttachmentDir

          public File getAttachmentDir()

      Returns:
        non-null only for Drafts

    - #### getFolder

          public Folder<String> getFolder()

      Returns:
        non-null

    - #### getFolderName

          public String getFolderName()

      Returns:
        as passed in

    - #### getFullWriteBuffer

          public Buffer getFullWriteBuffer(String uidl)

      For writing a new full mail (NOT headers only) Caller must close.

    - #### getMail

          public boolean getMail(MailCache.FetchMode mode)

      Fetch any needed data from pop3 server. Mail objects are inserted into the requests. After this, call getUIDLs() 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

    - #### getMail

          public Mail 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. Blocking for a long time unless mode is CACHE_ONLY or HEADER_CACHE_ONLY.
      Parameters:
        `uidl` - message id to get
        `mode` - CACHE_ONLY or HEADER_CACHE_ONLY to not pull from pop server
      Returns:
        An e-mail or null

    - #### getTranslatedName

          public String getTranslatedName()

      Returns:
        translation of name passed in

    - #### getUIDLs

          public String[] 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

    - #### isLoaded

          public boolean isLoaded()

      Has loadFromDisk completed?

    - #### isLoading

          public boolean isLoading()

      Is loadFromDisk in progress?

    - #### loadFromDisk

          public boolean loadFromDisk(NewMailListener nml)

      Threaded. Returns immediately. This will not access the mailbox. Mailbox need not be ready.
      Returns:
        success false if in progress already and nml will NOT be called back, true if nml will be called back

    - #### moveTo

          public boolean moveTo(String uidl,
                                MailCache toMC)

      Move a mail to another MailCache, neither may be DIR_DRAFTS
      Returns:
        success

    - #### writeComplete

          public void writeComplete(String uidl,
                                    Buffer buffer,
                                    boolean success)

      For writing a new full mail
      Parameters:
        `buffer` - as received from getFullBuffer