i2p.susi.webmail

## Class PersistentMailCache

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

-     class PersistentMailCache
      extends Object

  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. TODO cached server caps and config.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `DIR_ATTACHMENTS`
    `static String` | `DIR_IMPORT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PersistentMailCache(I2PAppContext ctx, String host, int port, String user, String pass, String folder)` Use the params to generate a unique directory name.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `deleteMail(Mail mail)` Delete data from disk.
    `void` | `deleteMail(String uidl)` Delete data from disk.
    `File` | `getAttachmentDir()`
    `GzipFileBuffer` | `getFullBuffer(String uidl)` For reading or writing a new full mail (NOT headers only).
    `File` | `getFullFile(String uidl)`
    `File` | `getHeaderFile(String uidl)`
    `boolean` | `getMail(Mail mail, boolean headerOnly)` Fetch any needed data from disk.
    `Collection<Mail>` | `getMails()` Fetch all mails from disk.
    `boolean` | `saveMail(Mail mail)` Save data to disk.

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

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

- - ### Field Detail

    - #### DIR_ATTACHMENTS

          public static final String DIR_ATTACHMENTS

      See Also:
        Constant Field Values

    - #### DIR_IMPORT

          public static final String DIR_IMPORT

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### 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:
        `pass` - ignored
        `folder` - e.g. DIR_FOLDER
      Throws:
        `IOException`

  - ### Method Detail

    - #### deleteMail

          public void deleteMail(Mail mail)

      Delete data from disk.

    - #### deleteMail

          public void deleteMail(String uidl)

      Delete data from disk.

    - #### getAttachmentDir

          public File getAttachmentDir()

      Returns:
        non-null only for Drafts

    - #### getFullBuffer

          public GzipFileBuffer getFullBuffer(String uidl)

      For reading or writing a new full mail (NOT headers only). For writing, caller MUST call writeComplete() on rv. Does not necessarily exist.

    - #### getFullFile

          public File getFullFile(String uidl)

    - #### getHeaderFile

          public File getHeaderFile(String uidl)

    - #### getMail

          public boolean getMail(Mail mail,
                                 boolean headerOnly)

      Fetch any needed data from disk.
      Returns:
        success

    - #### getMails

          public Collection<Mail> getMails()

      Fetch all mails from disk.
      Returns:
        a new collection

    - #### saveMail

          public boolean saveMail(Mail mail)

      Save data to disk.
      Returns:
        success