⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inetmail.h

📁 开源代码的pwlib的1.10.0版本,使用openh323的1.18.0版本毕备
💻 H
📖 第 1 页 / 共 3 页
字号:
       is used when the socket is acting as a server.

       @return
       TRUE if more processing may be done, FALSE if the QUIT command was
       received or the <A>OnUnknown()</A> function returns FALSE.
     */
    BOOL ProcessCommand();

    /** Log the specified user into the mail system and return sizes of each
       message in mail box.

       The user override of this function is expected to populate the protected
       member fields <CODE>messageSizes</CODE> and <CODE>messageIDs</CODE>.

       @return
       TRUE if user and password were valid.
     */
    virtual BOOL HandleOpenMailbox(
      const PString & username,  ///< User name for mail box
      const PString & password   ///< Password for user name
    );

    /** Handle the sending of the specified message to the remote client. The
       data written to the socket will automatically have the '.' character
       stuffing enabled.

       @return
       TRUE if successfully sent message.
     */
    virtual void HandleSendMessage(
      PINDEX messageNumber, ///< Number of message to send.
      const PString & id,   ///< Unique id of message to send.
      PINDEX lines          ///< Nuumber of lines in body of message to send.
    );
    
    /** Handle the deleting of the specified message from the mail box. This is
       called when the OnQUIT command is called for each message that was
       deleted using the DELE command.

       @return
       TRUE if successfully sent message.
     */
    virtual void HandleDeleteMessage(
      PINDEX messageNumber, ///< Number of message to send.
      const PString & id    ///< Unique id of message to send.
    );
    

  protected:
    BOOL OnOpen();

    virtual void OnUSER(
      const PString & name  ///< Name of user.
    );
    // Specify user name (mailbox).

    virtual void OnPASS(
      const PString & passwd  ///< Password for account.
    );
    // Specify password and log user in.

    virtual void OnQUIT();
    // End connection, saving all changes (delete messages).

    virtual void OnRSET();
    // Reset connection (undelete messages).

    virtual void OnNOOP();
    // Do nothing.

    virtual void OnSTAT();
    // Get number of messages in mailbox.

    /** Get the size of a message in mailbox. If <CODE>msg</CODE> is 0 then get
       sizes of all messages in mailbox.
     */
    virtual void OnLIST(
      PINDEX msg  ///< Number of message.
    );

    virtual void OnRETR(
      PINDEX msg  ///< Number of message.
    );
    // Retrieve a message from mailbox.

    virtual void OnDELE(
      PINDEX msg  ///< Number of message.
    );
    // Delete a message from mailbox.

    virtual void OnTOP(
      PINDEX msg,  ///< Number of message.
      PINDEX count ///< Count of messages
    );
    // Get the message header and top <CODE>count</CODE> lines of message.

    /** Get unique ID for message in mailbox. If <CODE>msg</CODE> is 0 then get
       all IDs for all messages in mailbox.
     */
    virtual void OnUIDL(
      PINDEX msg  ///< Number of message.
    );

    /** Handle an unknown command.

       @return
       TRUE if more processing may be done, FALSE if the
       <A>ProcessCommand()</A> function is to return FALSE.
     */
    virtual BOOL OnUnknown(
      const PCaselessString & command  ///< Complete command line received.
    );


  // Member variables
    PString        username;
    PUnsignedArray messageSizes;
    PStringArray   messageIDs;
    PBYTEArray     messageDeletions;
};


/**A channel for sending/receiving RFC822 compliant mail messages.
   This encpsulates all that is required to send an RFC822 compliant message
   via another channel. It automatically adds/strips header information from
   the stream so the Read() and Write() functions only deal with the message
   body.
   For example to send a message using the SMTP classes:
      <PRE><CODE>
      PSMTPClient mail("mailserver");
      if (mail.IsOpen()) {
        PRFC822Channel message;
        message.SetFromAddress("Me@here.com.au");
        message.SetToAddress("Fred@somwhere.com");
        if (message.Open(mail)) {
          if (mail.BeginMessage("Me@here.com.au", "Fred@somwhere.com")) {
            if (!message.Write(myMessageBody))
              PError << "Mail write failed." << endl;
            if (!message.EndMessage())
              PError << "Mail send failed." << endl;
          }
        }
      }
      else
         PError << "Mail conection failed." << endl;
      </PRE></CODE>
  */
class PRFC822Channel : public PIndirectChannel
{
    PCLASSINFO(PRFC822Channel, PIndirectChannel);
  public:
    enum Direction {
      Sending,
      Receiving
    };
    /**Construct a RFC822 aware channel.
      */
    PRFC822Channel(
      Direction direction ////< Indicates are sending or receiving a message
    );

    /**Close the channel before destruction.
      */
    ~PRFC822Channel();


  // Overrides from class PChannel.
    /**Close the channel.
       This assures that all mime fields etc are closed off before closing
       the underliying channel.
      */
    BOOL Close();

    /** Low level write to the channel.

       This override assures that the header is written before the body that
       will be output via this function.

       @return
       TRUE if at least len bytes were written to the channel.
     */
    virtual BOOL Write(
      const void * buf, ///< Pointer to a block of memory to write.
      PINDEX len        ///< Number of bytes to write.
    );


    /**Begin a new message.
       This may be used if the object is to encode 2 or more messages
       sequentially. It resets the internal state of the object.
      */
    void NewMessage(
      Direction direction  ///< Indicates are sending or receiving a message
    );

    /**Enter multipart MIME message mode.
       This indicates that the message, or individual part within a message as
       MIME is nestable, is a multipart message. This form returns the
       boundary indicator string generated internally which must then be used
       in all subsequent NextPart() calls.

       Note this must be called before any writes are done to the message or
       part.
      */
    PString MultipartMessage();

    /**Enter multipart MIME message mode.
       This indicates that the message, or individual part within a message as
       MIME is nestable, is a multipart message. In this form the user
       supplies a boundary indicator string which must then be used in all
       subsequent NextPart() calls.

       Note this must be called before any writes are done to the message or
       part.
      */
    BOOL MultipartMessage(
      const PString & boundary
    );

    /**Indicate that a new multipart message part is to begin.
       This will close off the previous part, and any nested multipart
       messages contained therein, and allow a new part to begin.

       The user may adjust the parts content type and other header fields
       after this call and before the first write of the parts body. The
       default Content-Type is "text/plain".

       Note that all header fields are cleared from the previous part.
      */
    void NextPart(
      const PString & boundary
    );


    /**Set the sender address.
       This must be called before any writes are done to the channel.
      */
    void SetFromAddress(
      const PString & fromAddress  ///< Senders e-mail address
    );

    /**Set the recipient address(es).
       This must be called before any writes are done to the channel.
      */
    void SetToAddress(
      const PString & toAddress ///< Recipients e-mail address (comma separated)
    );

    /**Set the Carbon Copy address(es).
       This must be called before any writes are done to the channel.
      */
    void SetCC(
      const PString & ccAddress ///< Recipients e-mail address (comma separated)
    );

    /**Set the Blind Carbon Copy address(es).
       This must be called before any writes are done to the channel.
      */
    void SetBCC(
      const PString & bccAddress ///< Recipients e-mail address (comma separated)
    );

    /**Set the message subject.
       This must be called before any writes are done to the channel.
      */
    void SetSubject(
      const PString & subject  ///< Subject string
    );

    /**Set the content type.
       This must be called before any writes are done to the channel. It may
       be set again immediately after any call to NextPart() when multipart
       mime is being used.

       The default Content-Type is "text/plain".
      */
    void SetContentType(
      const PString & contentType   ///< Content type in form major/minor
    );

    /**Set the content disposition for attachments.
       This must be called before any writes are done to the channel. It may
       be set again immediately after any call to NextPart() when multipart
       mime is being used.

       Note that this will alter the Content-Type field to 
      */
    void SetContentAttachment(
      const PFilePath & filename   ///< Attachment filename
    );

    /**Set the content transfer encoding.
       This must be called before any writes are done to the channel. It may
       be set again immediately after any call to NextPart() when multipart
       mime is being used.

       If the encoding is "base64" (case insensitive) and , all writes will be
       treated as binary and translated into base64 encoding before output to
       the underlying channel.
      */
    void SetTransferEncoding(
      const PString & encoding,   ///< Encoding type
      BOOL autoTranslate = TRUE   ///< Automatically convert to encoding type
    );


    /**Set the and arbitrary header field.
       This must be called before any writes are done to the channel.
      */
    void SetHeaderField(
      const PString & name,   ///< MIME fields tag
      const PString & value   ///< MIME fields contents
    );

    // Common MIME header tags
    static const char MimeVersionTag[];
    static const char FromTag[];
    static const char ToTag[];
    static const char CCTag[];
    static const char BCCTag[];
    static const char SubjectTag[];
    static const char DateTag[];
    static const char ReturnPathTag[];
    static const char ReceivedTag[];
    static const char MessageIDTag[];
    static const char MailerTag[];
    static const char ContentTypeTag[];
    static const char ContentDispositionTag[];
    static const char ContentTransferEncodingTag[];

    /**Send this message using an SMTP socket.
       This will create a PSMTPClient and connect to the specified host then
       send the message to the remote SMTP server.
      */
    BOOL SendWithSMTP(
      const PString & hostname
    );

    /**Send this message using an SMTP socket.
       This assumes PSMTPClient is open the sends the message to the remote
       SMTP server.
      */
    BOOL SendWithSMTP(
      PSMTPClient * smtp
    );


  protected:
    BOOL OnOpen();

    BOOL        writeHeaders;
    PMIMEInfo   headers;
    BOOL        writePartHeaders;
    PMIMEInfo   partHeaders;
    PStringList boundaries;
    PBase64   * base64;
};


#endif  // _PMAILPROTOCOL


// End Of File ///////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -