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

class PersistentMailCacheextends 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.
  • Field Details

    • DIR_IMPORT

      public static final String DIR_IMPORT
      Directory beside the cache holding imported .eml files, debug only.
      See Also:
    • DIR_ATTACHMENTS

      public static final String 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 directory
      host - IMAP host, part of the directory name
      port - IMAP port, part of the directory name
      user - mail account name, part of the directory name
      pass - not used; the cache is keyed on account name alone
      folder - on-disk maildir name, one of the DIRS values, e.g. DIR_FOLDER; only DIR_DRAFTS gets an attachment directory
      Throws:
      IOException - if the cache directory cannot be created
  • Method Details

    • getMails

      public Collection<Mail> getMails()
      Fetch all mails from disk.
      Returns:
      a new collection
    • getMail

      public boolean getMail(Mail mail, boolean headerOnly)
      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 uidl
      headerOnly - 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

      public boolean saveMail(Mail mail)
      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

      public void deleteMail(Mail mail)
      Delete both the full-message and the header-only file for this mail.
      Parameters:
      mail - the mail to remove
    • deleteMail

      public void deleteMail(String uidl)
      Delete both the full-message and the header-only file for this uidl.
      Parameters:
      uidl - the unique ID of the mail to remove
    • getHeaderFile

      public File getHeaderFile(String uidl)
      The gzipped header-only file for this uidl. The file need not exist yet.
      Parameters:
      uidl - the unique ID of the mail
      Returns:
      the header-only file for this UIDL
    • getFullFile

      public File getFullFile(String uidl)
      The gzipped full-message file for this uidl. The file need not exist yet.
      Parameters:
      uidl - the unique ID of the mail
      Returns:
      the full message file for this UIDL
    • 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.
      Parameters:
      uidl - the unique ID of the mail
      Returns:
      a new buffer over the full message file
    • getAttachmentDir

      public File getAttachmentDir()
      Where draft attachments are stored, which only the drafts cache creates.
      Returns:
      non-null only for Drafts