Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

inetmail.h

Go to the documentation of this file.
00001 /*
00002  * inetmail.h
00003  *
00004  * Internet Mail channel classes
00005  * Simple Mail Transport Protocol & Post Office Protocol v3
00006  *
00007  * Portable Windows Library
00008  *
00009  * Copyright (c) 1993-2002 Equivalence Pty. Ltd.
00010  *
00011  * The contents of this file are subject to the Mozilla Public License
00012  * Version 1.0 (the "License"); you may not use this file except in
00013  * compliance with the License. You may obtain a copy of the License at
00014  * http://www.mozilla.org/MPL/
00015  *
00016  * Software distributed under the License is distributed on an "AS IS"
00017  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00018  * the License for the specific language governing rights and limitations
00019  * under the License.
00020  *
00021  * The Original Code is Portable Windows Library.
00022  *
00023  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00024  *
00025  * Contributor(s): Federico Pinna and Reitek S.p.A.
00026  *
00027  * $Log: inetmail.h,v $
00028  * Revision 1.19  2004/04/21 00:29:55  csoutheren
00029  * Added SASL authentication to PPOP3Client and PSMTPClient
00030  * Thanks to Federico Pinna and Reitek S.p.A.
00031  *
00032  * Revision 1.18  2002/11/06 22:47:24  robertj
00033  * Fixed header comment (copyright etc)
00034  *
00035  * Revision 1.17  2002/09/16 01:08:59  robertj
00036  * Added #define so can select if #pragma interface/implementation is used on
00037  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00038  *
00039  * Revision 1.16  2000/11/10 01:08:11  robertj
00040  * Added content transfer encoding and automatic base64 translation.
00041  *
00042  * Revision 1.15  2000/11/09 06:01:58  robertj
00043  * Added MIME version and content disposition to RFC822 class.
00044  *
00045  * Revision 1.14  2000/11/09 05:50:23  robertj
00046  * Added RFC822 aware channel class for doing internet mail.
00047  *
00048  * Revision 1.13  2000/06/21 01:01:21  robertj
00049  * AIX port, thanks Wolfgang Platzer (wolfgang.platzer@infonova.at).
00050  *
00051  * Revision 1.12  2000/06/19 11:33:53  robertj
00052  * Fixed incorrect comment documentation
00053  *
00054  * Revision 1.11  1999/03/09 08:01:46  robertj
00055  * Changed comments for doc++ support (more to come).
00056  *
00057  * Revision 1.10  1999/02/16 08:07:10  robertj
00058  * MSVC 6.0 compatibility changes.
00059  *
00060  * Revision 1.9  1998/11/30 02:50:51  robertj
00061  * New directory structure
00062  *
00063  * Revision 1.8  1998/09/23 06:19:36  robertj
00064  * Added open source copyright license.
00065  *
00066  * Revision 1.7  1996/12/21 01:24:15  robertj
00067  * Added missing open message to pop server.
00068  *
00069  * Revision 1.6  1996/09/16 12:57:45  robertj
00070  * Removed redundant functions.
00071  *
00072  * Revision 1.5  1996/09/14 13:17:59  robertj
00073  * Renamed file and changed to be a protocol off new indirect channel to separate
00074  *   the protocol from the low level byte transport channel.
00075  *
00076  * Revision 1.4  1996/07/27 04:14:49  robertj
00077  * Redesign and reimplement of mail sockets.
00078  *
00079  * Revision 1.3  1996/06/28 13:16:32  robertj
00080  * Changed SMTP incoming message handler so can tell when started, processing or ended message.
00081  *
00082  * Revision 1.2  1996/03/16 04:38:24  robertj
00083  * Added ParseReponse() for splitting reponse line into code and info.
00084  *
00085  * Revision 1.1  1996/01/23 13:04:20  robertj
00086  * Initial revision
00087  *
00088  * Revision 1.3  1995/06/17 11:12:15  robertj
00089  * Documentation update.
00090  *
00091  * Revision 1.2  1995/06/17 00:39:53  robertj
00092  * More implementation.
00093  *
00094  * Revision 1.1  1995/06/04 13:17:16  robertj
00095  * Initial revision
00096  *
00097  */
00098 
00099 #ifndef _PMAILPROTOCOL
00100 #define _PMAILPROTOCOL
00101 
00102 #ifdef P_USE_PRAGMA
00103 #pragma interface
00104 #endif
00105 
00106 #include <ptclib/inetprot.h>
00107 #include <ptclib/mime.h>
00108 
00109 class PSocket;
00110 
00111 
00113 // PSMTP
00114 
00140 class PSMTP : public PInternetProtocol
00141 {
00142   PCLASSINFO(PSMTP, PInternetProtocol)
00143 
00144   public:
00145   // New functions for class.
00146     enum Commands {
00147       HELO, EHLO, QUIT, HELP, NOOP,
00148       TURN, RSET, VRFY, EXPN, RCPT,
00149       MAIL, SEND, SAML, SOML, DATA,
00150       AUTH, NumCommands
00151     };
00152 
00153   protected:
00154     PSMTP();
00155     // Create a new SMTP protocol channel.
00156 };
00157 
00158 
00175 class PSMTPClient : public PSMTP
00176 {
00177   PCLASSINFO(PSMTPClient, PSMTP)
00178 
00179   public:
00186     PSMTPClient();
00187 
00191     ~PSMTPClient();
00192 
00193 
00194   // Overrides from class PChannel.
00200     virtual BOOL Close();
00201 
00202 
00203   // New functions for class.
00211     BOOL LogIn(
00212       const PString & username,   // User name on remote system.
00213       const PString & password    // Password for user name.
00214     );
00215 
00224     BOOL BeginMessage(
00225       const PString & from,        // User name of sender.
00226       const PString & to,          // User name of recipient.
00227       BOOL eightBitMIME = FALSE    // Mesage will be 8 bit MIME.
00228     );
00229     BOOL BeginMessage(
00230       const PString & from,        // User name of sender.
00231       const PStringList & toList,  // List of user names of recipients.
00232       BOOL eightBitMIME = FALSE    // Mesage will be 8 bit MIME.
00233     );
00234 
00240     BOOL EndMessage();
00241 
00242 
00243   protected:
00244     BOOL OnOpen();
00245 
00246     BOOL    haveHello;
00247     BOOL    extendedHello;
00248     BOOL    eightBitMIME;
00249     PString fromAddress;
00250     PStringList toNames;
00251     BOOL    sendingData;
00252 
00253   private:
00254     BOOL _BeginMessage();
00255 };
00256 
00257 
00283 class PSMTPServer : public PSMTP
00284 {
00285   PCLASSINFO(PSMTPServer, PSMTP)
00286 
00287   public:
00294     PSMTPServer();
00295 
00296 
00297   // New functions for class.
00305     BOOL ProcessCommand();
00306 
00307     void ServerReset();
00308     // Reset the state of the SMTP server socket.
00309 
00310     enum ForwardResult {
00311       LocalDomain,    // User may be on local machine, do LookUpName().
00312       WillForward,    // User may be forwarded to another SMTP host.
00313       CannotForward   // User cannot be forwarded.
00314     };
00315     // Result of forward check
00316 
00323     virtual ForwardResult ForwardDomain(
00324       PCaselessString & userDomain,       // Domain for user
00325       PCaselessString & forwardDomainList // Domains forwarding to
00326     );
00327 
00328     enum LookUpResult {
00329       ValidUser,      // User name was valid and unique.
00330       AmbiguousUser,  // User name was valid but ambiguous.
00331       UnknownUser,    // User name was invalid.
00332       LookUpError     // Some other error occurred in look up.
00333     };
00334     // Result of user name look up
00335 
00343     virtual LookUpResult LookUpName(
00344       const PCaselessString & name,    // Name to look up.
00345       PString & expandedName           // Expanded form of name (if found).
00346     );
00347 
00357     virtual BOOL HandleMessage(
00358       PCharArray & buffer,  // Buffer containing message data received.
00359       BOOL starting,        // This is the first call for the message.
00360       BOOL completed        // This is the last call for the message.
00361       // Indication that the entire message has been received.
00362     );
00363 
00364 
00365   protected:
00366     BOOL OnOpen();
00367 
00368     virtual void OnHELO(
00369       const PCaselessString & remoteHost  // Name of remote host.
00370     );
00371     // Start connection.
00372 
00373     virtual void OnEHLO(
00374       const PCaselessString & remoteHost  // Name of remote host.
00375     );
00376     // Start extended SMTP connection.
00377 
00378     virtual void OnQUIT();
00379     // close connection and die.
00380 
00381     virtual void OnHELP();
00382     // get help.
00383 
00384     virtual void OnNOOP();
00385     // do nothing
00386     
00387     virtual void OnTURN();
00388     // switch places
00389     
00390     virtual void OnRSET();
00391     // Reset state.
00392 
00393     virtual void OnVRFY(
00394       const PCaselessString & name    // Name to verify.
00395     );
00396     // Verify address.
00397 
00398     virtual void OnEXPN(
00399       const PCaselessString & name    // Name to expand.
00400     );
00401     // Expand alias.
00402 
00403     virtual void OnRCPT(
00404       const PCaselessString & recipient   // Name of recipient.
00405     );
00406     // Designate recipient
00407 
00408     virtual void OnMAIL(
00409       const PCaselessString & sender  // Name of sender.
00410     );
00411     // Designate sender
00412     
00413     virtual void OnSEND(
00414       const PCaselessString & sender  // Name of sender.
00415     );
00416     // send message to screen
00417 
00418     virtual void OnSAML(
00419       const PCaselessString & sender  // Name of sender.
00420     );
00421     // send AND mail
00422     
00423     virtual void OnSOML(
00424       const PCaselessString & sender  // Name of sender.
00425     );
00426     // send OR mail
00427 
00428     virtual void OnDATA();
00429     // Message text.
00430 
00437     virtual BOOL OnUnknown(
00438       const PCaselessString & command  // Complete command line received.
00439     );
00440 
00441     virtual void OnSendMail(
00442       const PCaselessString & sender  // Name of sender.
00443     );
00444     // Common code for OnMAIL(), OnSEND(), OnSOML() and OnSAML() funtions.
00445 
00457     virtual BOOL OnTextData(PCharArray & buffer, BOOL & completed);
00458 
00470     virtual BOOL OnMIMEData(PCharArray & buffer, BOOL & completed);
00471 
00472 
00473   // Member variables
00474     BOOL        extendedHello;
00475     BOOL        eightBitMIME;
00476     PString     fromAddress;
00477     PString     fromPath;
00478     PStringList toNames;
00479     PStringList toDomains;
00480     PINDEX      messageBufferSize;
00481     enum { WasMAIL, WasSEND, WasSAML, WasSOML } sendCommand;
00482     StuffState  endMIMEDetectState;
00483 };
00484 
00485 
00487 // PPOP3
00488 
00526 class PPOP3 : public PInternetProtocol
00527 {
00528   PCLASSINFO(PPOP3, PInternetProtocol)
00529 
00530   public:
00531     enum Commands {
00532       USER, PASS, QUIT, RSET, NOOP, STATcmd,
00533       LIST, RETR, DELE, APOP, TOP,  UIDL,
00534       AUTH, NumCommands
00535     };
00536 
00537 
00538   protected:
00539     PPOP3();
00540 
00552     virtual PINDEX ParseResponse(
00553       const PString & line // Input response line to be parsed
00554     );
00555 
00556   // Member variables
00557     static PString okResponse;
00558     static PString errResponse;
00559 };
00560 
00561 
00589 class PPOP3Client : public PPOP3
00590 {
00591   PCLASSINFO(PPOP3Client, PPOP3)
00592 
00593   public:
00600     PPOP3Client();
00601 
00605     ~PPOP3Client();
00606 
00607 
00608   // Overrides from class PChannel.
00614     virtual BOOL Close();
00615 
00616 
00617   // New functions for class.
00618     enum LoginOptions
00619     {
00620       AllowUserPass = 1,      // Allow the use of the plain old USER/PASS if APOP
00621                               // or SASL are not available
00622       UseSASL = 2,            // Use SASL if the AUTH command is supported by
00623                               // the server
00624       AllowClearTextSASL = 4  // Allow LOGIN and PLAIN mechanisms to be used
00625     };
00626 
00632     BOOL LogIn(
00633       const PString & username,       // User name on remote system.
00634       const PString & password,       // Password for user name.
00635       int options = AllowUserPass     // See LoginOptions above
00636     );
00637 
00643     int GetMessageCount();
00644 
00651     PUnsignedArray GetMessageSizes();
00652 
00662     PStringArray GetMessageHeaders();
00663 
00664 
00665     /* Begin the retrieval of an entire message. The application may then use
00666        the <A>PApplicationSocket::ReadLine()</A> function with the
00667        <CODE>unstuffLine</CODE> parameter set to TRUE. Repeated calls until
00668        its return valus is FALSE will read the message headers and body.
00669 
00670        @return
00671        Array of strings continaing message headers.
00672      */
00673     BOOL BeginMessage(
00674       PINDEX messageNumber
00678     );
00679 
00685     BOOL DeleteMessage(
00686       PINDEX messageNumber
00687         /* Number of message to retrieve. This is an integer from 1 to the
00688            maximum number of messages available.
00689          */
00690     );
00691 
00692 
00693   protected:
00694     BOOL OnOpen();
00695 
00696   // Member variables
00697     BOOL loggedIn;
00698     PString apopBanner;
00699 };
00700 
00701 
00714 class PPOP3Server : public PPOP3
00715 {
00716   PCLASSINFO(PPOP3Server, PPOP3)
00717 
00718   public:
00725     PPOP3Server();
00726 
00727 
00728   // New functions for class.
00736     BOOL ProcessCommand();
00737 
00747     virtual BOOL HandleOpenMailbox(
00748       const PString & username,  // User name for mail box
00749       const PString & password   // Password for user name
00750     );
00751 
00759     virtual void HandleSendMessage(
00760       PINDEX messageNumber, // Number of message to send.
00761       const PString & id,   // Unique id of message to send.
00762       PINDEX lines          // Nuumber of lines in body of message to send.
00763     );
00764     
00772     virtual void HandleDeleteMessage(
00773       PINDEX messageNumber, // Number of message to send.
00774       const PString & id    // Unique id of message to send.
00775     );
00776     
00777 
00778   protected:
00779     BOOL OnOpen();
00780 
00781     virtual void OnUSER(
00782       const PString & name  // Name of user.
00783     );
00784     // Specify user name (mailbox).
00785 
00786     virtual void OnPASS(
00787       const PString & passwd  // Password for account.
00788     );
00789     // Specify password and log user in.
00790 
00791     virtual void OnQUIT();
00792     // End connection, saving all changes (delete messages).
00793 
00794     virtual void OnRSET();
00795     // Reset connection (undelete messages).
00796 
00797     virtual void OnNOOP();
00798     // Do nothing.
00799 
00800     virtual void OnSTAT();
00801     // Get number of messages in mailbox.
00802 
00806     virtual void OnLIST(
00807       PINDEX msg  // Number of message.
00808     );
00809 
00810     virtual void OnRETR(
00811       PINDEX msg  // Number of message.
00812     );
00813     // Retrieve a message from mailbox.
00814 
00815     virtual void OnDELE(
00816       PINDEX msg  // Number of message.
00817     );
00818     // Delete a message from mailbox.
00819 
00820     virtual void OnTOP(
00821       PINDEX msg,  // Number of message.
00822       PINDEX count // Count of messages
00823     );
00824     // Get the message header and top <CODE>count</CODE> lines of message.
00825 
00829     virtual void OnUIDL(
00830       PINDEX msg  // Number of message.
00831     );
00832 
00839     virtual BOOL OnUnknown(
00840       const PCaselessString & command  // Complete command line received.
00841     );
00842 
00843 
00844   // Member variables
00845     PString        username;
00846     PUnsignedArray messageSizes;
00847     PStringArray   messageIDs;
00848     PBYTEArray     messageDeletions;
00849 };
00850 
00851 
00877 class PRFC822Channel : public PIndirectChannel
00878 {
00879     PCLASSINFO(PRFC822Channel, PIndirectChannel);
00880   public:
00881     enum Direction {
00882       Sending,
00883       Receiving
00884     };
00887     PRFC822Channel(
00888       Direction direction 
00889     );
00890 
00893     ~PRFC822Channel();
00894 
00895 
00896   // Overrides from class PChannel.
00901     BOOL Close();
00902 
00911     virtual BOOL Write(
00912       const void * buf, // Pointer to a block of memory to write.
00913       PINDEX len        // Number of bytes to write.
00914     );
00915 
00916 
00921     void NewMessage(
00922       Direction direction  
00923     );
00924 
00934     PString MultipartMessage();
00935 
00945     BOOL MultipartMessage(
00946       const PString & boundary
00947     );
00948 
00959     void NextPart(
00960       const PString & boundary
00961     );
00962 
00963 
00967     void SetFromAddress(
00968       const PString & fromAddress  
00969     );
00970 
00974     void SetToAddress(
00975       const PString & toAddress 
00976     );
00977 
00981     void SetCC(
00982       const PString & ccAddress 
00983     );
00984 
00988     void SetBCC(
00989       const PString & bccAddress 
00990     );
00991 
00995     void SetSubject(
00996       const PString & subject  
00997     );
00998 
01006     void SetContentType(
01007       const PString & contentType   
01008     );
01009 
01017     void SetContentAttachment(
01018       const PFilePath & filename   
01019     );
01020 
01030     void SetTransferEncoding(
01031       const PString & encoding,   
01032       BOOL autoTranslate = TRUE   
01033     );
01034 
01035 
01039     void SetHeaderField(
01040       const PString & name,   
01041       const PString & value   
01042     );
01043 
01044     // Common MIME header tags
01045     static const char MimeVersionTag[];
01046     static const char FromTag[];
01047     static const char ToTag[];
01048     static const char CCTag[];
01049     static const char BCCTag[];
01050     static const char SubjectTag[];
01051     static const char DateTag[];
01052     static const char ReturnPathTag[];
01053     static const char ReceivedTag[];
01054     static const char MessageIDTag[];
01055     static const char MailerTag[];
01056     static const char ContentTypeTag[];
01057     static const char ContentDispositionTag[];
01058     static const char ContentTransferEncodingTag[];
01059 
01064     BOOL SendWithSMTP(
01065       const PString & hostname
01066     );
01067 
01072     BOOL SendWithSMTP(
01073       PSMTPClient * smtp
01074     );
01075 
01076 
01077   protected:
01078     BOOL OnOpen();
01079 
01080     BOOL        writeHeaders;
01081     PMIMEInfo   headers;
01082     BOOL        writePartHeaders;
01083     PMIMEInfo   partHeaders;
01084     PStringList boundaries;
01085     PBase64   * base64;
01086 };
01087 
01088 
01089 #endif  // _PMAILPROTOCOL
01090 
01091 
01092 // End Of File ///////////////////////////////////////////////////////////////

Generated on Tue Mar 15 10:44:52 2005 for PWLib by  doxygen 1.4.0