class Draftextends Mail
Represents a draft email message with attachments and Bcc support. Differences from Mail: - Never multipart, body is always text/plain UTF-8 - Attachments are just headers containing name, type, encoding, and path to file - Bcc is a header
  • Field Details

    • attachments

      private final List<Attachment> attachments
      Files attached to the draft.
    • bcc

      private String[] bcc
      Blind copies, addresses only, enclosed by angle brackets.
    • size

      private long size
      Size of the draft's contents, in bytes.
    • HDR_ATTACH

      private static final String HDR_ATTACH
      Header marking an attachment in a sent message.
      See Also:
    • HDR_BCC

      public static final String HDR_BCC
      Header line carrying the blind-copy recipients of a draft, which a draft otherwise has no way to express in the body.
      See Also:
  • Constructor Details

    • Draft

      public Draft(String uidl)
      Start an empty draft with no attachments.
      Parameters:
      uidl - unique ID for this draft
  • Method Details

    • setBody

      public void setBody(Buffer rb)
      Overridden to process attachment and Bcc headers.
      Overrides:
      setBody in class Mail
      Parameters:
      rb - buffer containing body data
    • getSize

      public long getSize()
      Includes size of attachments.
      Overrides:
      getSize in class Mail
      Returns:
      body plus attachment size in bytes
    • setSize

      public void setSize(long size)
      Does nothing: a draft computes its own size from the body and its attachments, so there is no server-reported size to record.
      Overrides:
      setSize in class Mail
      Parameters:
      size - the message size
    • hasAttachment

      public boolean hasAttachment()
      Is any file attached to this draft?
      Overrides:
      hasAttachment in class Mail
      Returns:
      whether attachment is present
    • getBcc

      public String[] getBcc()
      The blind-copy recipients found in the draft's Bcc header, with no header meaning none were entered.
      Returns:
      may be null
    • getAttachments

      public List<Attachment> getAttachments()
      The live attachment list, so callers can add or drop entries directly.
      Returns:
      non-null, not a copy
    • addAttachment

      public int addAttachment(Attachment a)
      Adds an attachment if not already present.
      Parameters:
      a - the attachment to add
      Returns:
      the index of the attachment
    • removeAttachment

      public void removeAttachment(int index)
      Removes an attachment by index and deletes its data file.
      Parameters:
      index - the 0-based position in the attachment list; out of range is ignored
    • clearAttachments

      public void clearAttachments()
      Removes all attachments and deletes their data files.
    • encodeAttachments

      public StringBuilder encodeAttachments()
      Encodes all attachments as header lines for storage.
      Returns:
      the encoded attachment headers