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.21  2007/04/10 05:08:46  rjongbloed
00029  * Fixed issue with use of static C string variables in DLL environment,
00030  *   must use functional interface for correct initialisation.
00031  *
00032  * Revision 1.20  2005/11/30 12:47:37  csoutheren
00033  * Removed tabs, reformatted some code, and changed tags for Doxygen
00034  *
00035  * Revision 1.19  2004/04/21 00:29:55  csoutheren
00036  * Added SASL authentication to PPOP3Client and PSMTPClient
00037  * Thanks to Federico Pinna and Reitek S.p.A.
00038  *
00039  * Revision 1.18  2002/11/06 22:47:24  robertj
00040  * Fixed header comment (copyright etc)
00041  *
00042  * Revision 1.17  2002/09/16 01:08:59  robertj
00043  * Added #define so can select if #pragma interface/implementation is used on
00044  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00045  *
00046  * Revision 1.16  2000/11/10 01:08:11  robertj
00047  * Added content transfer encoding and automatic base64 translation.
00048  *
00049  * Revision 1.15  2000/11/09 06:01:58  robertj
00050  * Added MIME version and content disposition to RFC822 class.
00051  *
00052  * Revision 1.14  2000/11/09 05:50:23  robertj
00053  * Added RFC822 aware channel class for doing internet mail.
00054  *
00055  * Revision 1.13  2000/06/21 01:01:21  robertj
00056  * AIX port, thanks Wolfgang Platzer (wolfgang.platzer@infonova.at).
00057  *
00058  * Revision 1.12  2000/06/19 11:33:53  robertj
00059  * Fixed incorrect comment documentation
00060  *
00061  * Revision 1.11  1999/03/09 08:01:46  robertj
00062  * Changed comments for doc++ support (more to come).
00063  *
00064  * Revision 1.10  1999/02/16 08:07:10  robertj
00065  * MSVC 6.0 compatibility changes.
00066  *
00067  * Revision 1.9  1998/11/30 02:50:51  robertj
00068  * New directory structure
00069  *
00070  * Revision 1.8  1998/09/23 06:19:36  robertj
00071  * Added open source copyright license.
00072  *
00073  * Revision 1.7  1996/12/21 01:24:15  robertj
00074  * Added missing open message to pop server.
00075  *
00076  * Revision 1.6  1996/09/16 12:57:45  robertj
00077  * Removed redundant functions.
00078  *
00079  * Revision 1.5  1996/09/14 13:17:59  robertj
00080  * Renamed file and changed to be a protocol off new indirect channel to separate
00081  *   the protocol from the low level byte transport channel.
00082  *
00083  * Revision 1.4  1996/07/27 04:14:49  robertj
00084  * Redesign and reimplement of mail sockets.
00085  *
00086  * Revision 1.3  1996/06/28 13:16:32  robertj
00087  * Changed SMTP incoming message handler so can tell when started, processing or ended message.
00088  *
00089  * Revision 1.2  1996/03/16 04:38:24  robertj
00090  * Added ParseReponse() for splitting reponse line into code and info.
00091  *
00092  * Revision 1.1  1996/01/23 13:04:20  robertj
00093  * Initial revision
00094  *
00095  * Revision 1.3  1995/06/17 11:12:15  robertj
00096  * Documentation update.
00097  *
00098  * Revision 1.2  1995/06/17 00:39:53  robertj
00099  * More implementation.
00100  *
00101  * Revision 1.1  1995/06/04 13:17:16  robertj
00102  * Initial revision
00103  *
00104  */
00105 
00106 #ifndef _PMAILPROTOCOL
00107 #define _PMAILPROTOCOL
00108 
00109 #ifdef P_USE_PRAGMA
00110 #pragma interface
00111 #endif
00112 
00113 #include <ptclib/inetprot.h>
00114 #include <ptclib/mime.h>
00115 
00116 class PSocket;
00117 
00118 
00120 // PSMTP
00121 
00147 class PSMTP : public PInternetProtocol
00148 {
00149   PCLASSINFO(PSMTP, PInternetProtocol)
00150 
00151   public:
00152   // New functions for class.
00153     enum Commands {
00154       HELO, EHLO, QUIT, HELP, NOOP,
00155       TURN, RSET, VRFY, EXPN, RCPT,
00156       MAIL, SEND, SAML, SOML, DATA,
00157       AUTH, NumCommands
00158     };
00159 
00160   protected:
00161     PSMTP();
00162     // Create a new SMTP protocol channel.
00163 };
00164 
00165 
00182 class PSMTPClient : public PSMTP
00183 {
00184   PCLASSINFO(PSMTPClient, PSMTP)
00185 
00186   public:
00193     PSMTPClient();
00194 
00198     ~PSMTPClient();
00199 
00200 
00201   // Overrides from class PChannel.
00207     virtual BOOL Close();
00208 
00209 
00210   // New functions for class.
00218     BOOL LogIn(
00219       const PString & username,   
00220       const PString & password    
00221     );
00222 
00231     BOOL BeginMessage(
00232       const PString & from,        
00233       const PString & to,          
00234       BOOL eightBitMIME = FALSE    
00235     );
00236     BOOL BeginMessage(
00237       const PString & from,        
00238       const PStringList & toList,  
00239       BOOL eightBitMIME = FALSE    
00240     );
00241 
00247     BOOL EndMessage();
00248 
00249 
00250   protected:
00251     BOOL OnOpen();
00252 
00253     BOOL    haveHello;
00254     BOOL    extendedHello;
00255     BOOL    eightBitMIME;
00256     PString fromAddress;
00257     PStringList toNames;
00258     BOOL    sendingData;
00259 
00260   private:
00261     BOOL _BeginMessage();
00262 };
00263 
00264 
00290 class PSMTPServer : public PSMTP
00291 {
00292   PCLASSINFO(PSMTPServer, PSMTP)
00293 
00294   public:
00301     PSMTPServer();
00302 
00303 
00304   // New functions for class.
00312     BOOL ProcessCommand();
00313 
00314     void ServerReset();
00315     // Reset the state of the SMTP server socket.
00316 
00317     enum ForwardResult {
00318       LocalDomain,    
00319       WillForward,    
00320       CannotForward   
00321     };
00322     // Result of forward check
00323 
00330     virtual ForwardResult ForwardDomain(
00331       PCaselessString & userDomain,       
00332       PCaselessString & forwardDomainList 
00333     );
00334 
00335     enum LookUpResult {
00336       ValidUser,      
00337       AmbiguousUser,  
00338       UnknownUser,    
00339       LookUpError     
00340     };
00341     // Result of user name look up
00342 
00350     virtual LookUpResult LookUpName(
00351       const PCaselessString & name,    
00352       PString & expandedName           
00353     );
00354 
00364     virtual BOOL HandleMessage(
00365       PCharArray & buffer,  
00366       BOOL starting,        
00367       BOOL completed        
00368 
00369     );
00370 
00371 
00372   protected:
00373     BOOL OnOpen();
00374 
00375     virtual void OnHELO(
00376       const PCaselessString & remoteHost  
00377     );
00378     // Start connection.
00379 
00380     virtual void OnEHLO(
00381       const PCaselessString & remoteHost  
00382     );
00383     // Start extended SMTP connection.
00384 
00385     virtual void OnQUIT();
00386     // close connection and die.
00387 
00388     virtual void OnHELP();
00389     // get help.
00390 
00391     virtual void OnNOOP();
00392     // do nothing
00393     
00394     virtual void OnTURN();
00395     // switch places
00396     
00397     virtual void OnRSET();
00398     // Reset state.
00399 
00400     virtual void OnVRFY(
00401       const PCaselessString & name    
00402     );
00403     // Verify address.
00404 
00405     virtual void OnEXPN(
00406       const PCaselessString & name    
00407     );
00408     // Expand alias.
00409 
00410     virtual void OnRCPT(
00411       const PCaselessString & recipient   
00412     );
00413     // Designate recipient
00414 
00415     virtual void OnMAIL(
00416       const PCaselessString & sender  
00417     );
00418     // Designate sender
00419     
00420     virtual void OnSEND(
00421       const PCaselessString & sender  
00422     );
00423     // send message to screen
00424 
00425     virtual void OnSAML(
00426       const PCaselessString & sender  
00427     );
00428     // send AND mail
00429     
00430     virtual void OnSOML(
00431       const PCaselessString & sender  
00432     );
00433     // send OR mail
00434 
00435     virtual void OnDATA();
00436     // Message text.
00437 
00444     virtual BOOL OnUnknown(
00445       const PCaselessString & command  
00446     );
00447 
00448     virtual void OnSendMail(
00449       const PCaselessString & sender  
00450     );
00451     // Common code for OnMAIL(), OnSEND(), OnSOML() and OnSAML() funtions.
00452 
00464     virtual BOOL OnTextData(PCharArray & buffer, BOOL & completed);
00465 
00477     virtual BOOL OnMIMEData(PCharArray & buffer, BOOL & completed);
00478 
00479 
00480   // Member variables
00481     BOOL        extendedHello;
00482     BOOL        eightBitMIME;
00483     PString     fromAddress;
00484     PString     fromPath;
00485     PStringList toNames;
00486     PStringList toDomains;
00487     PINDEX      messageBufferSize;
00488     enum { WasMAIL, WasSEND, WasSAML, WasSOML } sendCommand;
00489     StuffState  endMIMEDetectState;
00490 };
00491 
00492 
00494 // PPOP3
00495 
00533 class PPOP3 : public PInternetProtocol
00534 {
00535   PCLASSINFO(PPOP3, PInternetProtocol)
00536 
00537   public:
00538     enum Commands {
00539       USER, PASS, QUIT, RSET, NOOP, STATcmd,
00540       LIST, RETR, DELE, APOP, TOP,  UIDL,
00541       AUTH, NumCommands
00542     };
00543 
00544 
00545   protected:
00546     PPOP3();
00547 
00559     virtual PINDEX ParseResponse(
00560       const PString & line 
00561     );
00562 
00563   // Member variables
00564     static PString okResponse;
00565     static PString errResponse;
00566 };
00567 
00568 
00596 class PPOP3Client : public PPOP3
00597 {
00598   PCLASSINFO(PPOP3Client, PPOP3)
00599 
00600   public:
00607     PPOP3Client();
00608 
00612     ~PPOP3Client();
00613 
00614 
00615   // Overrides from class PChannel.
00621     virtual BOOL Close();
00622 
00623 
00624   // New functions for class.
00625     enum LoginOptions
00626     {
00627       AllowUserPass = 1,      
00628 
00629       UseSASL = 2,            
00630 
00631       AllowClearTextSASL = 4  
00632     };
00633 
00639     BOOL LogIn(
00640       const PString & username,       
00641       const PString & password,       
00642       int options = AllowUserPass     
00643     );
00644 
00650     int GetMessageCount();
00651 
00658     PUnsignedArray GetMessageSizes();
00659 
00669     PStringArray GetMessageHeaders();
00670 
00671 
00672     /* Begin the retrieval of an entire message. The application may then use
00673        the <A>PApplicationSocket::ReadLine()</A> function with the
00674        <CODE>unstuffLine</CODE> parameter set to TRUE. Repeated calls until
00675        its return valus is FALSE will read the message headers and body.
00676 
00677        @return
00678        Array of strings continaing message headers.
00679      */
00680     BOOL BeginMessage(
00681       PINDEX messageNumber
00685     );
00686 
00692     BOOL DeleteMessage(
00693       PINDEX messageNumber
00694         /* Number of message to retrieve. This is an integer from 1 to the
00695            maximum number of messages available.
00696          */
00697     );
00698 
00699 
00700   protected:
00701     BOOL OnOpen();
00702 
00703   // Member variables
00704     BOOL loggedIn;
00705     PString apopBanner;
00706 };
00707 
00708 
00721 class PPOP3Server : public PPOP3
00722 {
00723   PCLASSINFO(PPOP3Server, PPOP3)
00724 
00725   public:
00732     PPOP3Server();
00733 
00734 
00735   // New functions for class.
00743     BOOL ProcessCommand();
00744 
00754     virtual BOOL HandleOpenMailbox(
00755       const PString & username,  
00756       const PString & password   
00757     );
00758 
00766     virtual void HandleSendMessage(
00767       PINDEX messageNumber, 
00768       const PString & id,   
00769       PINDEX lines          
00770     );
00771     
00779     virtual void HandleDeleteMessage(
00780       PINDEX messageNumber, 
00781       const PString & id    
00782     );
00783     
00784 
00785   protected:
00786     BOOL OnOpen();
00787 
00788     virtual void OnUSER(
00789       const PString & name  
00790     );
00791     // Specify user name (mailbox).
00792 
00793     virtual void OnPASS(
00794       const PString & passwd  
00795     );
00796     // Specify password and log user in.
00797 
00798     virtual void OnQUIT();
00799     // End connection, saving all changes (delete messages).
00800 
00801     virtual void OnRSET();
00802     // Reset connection (undelete messages).
00803 
00804     virtual void OnNOOP();
00805     // Do nothing.
00806 
00807     virtual void OnSTAT();
00808     // Get number of messages in mailbox.
00809 
00813     virtual void OnLIST(
00814       PINDEX msg  
00815     );
00816 
00817     virtual void OnRETR(
00818       PINDEX msg  
00819     );
00820     // Retrieve a message from mailbox.
00821 
00822     virtual void OnDELE(
00823       PINDEX msg  
00824     );
00825     // Delete a message from mailbox.
00826 
00827     virtual void OnTOP(
00828       PINDEX msg,  
00829       PINDEX count 
00830     );
00831     // Get the message header and top <CODE>count</CODE> lines of message.
00832 
00836     virtual void OnUIDL(
00837       PINDEX msg  
00838     );
00839 
00846     virtual BOOL OnUnknown(
00847       const PCaselessString & command  
00848     );
00849 
00850 
00851   // Member variables
00852     PString        username;
00853     PUnsignedArray messageSizes;
00854     PStringArray   messageIDs;
00855     PBYTEArray     messageDeletions;
00856 };
00857 
00858 
00884 class PRFC822Channel : public PIndirectChannel
00885 {
00886     PCLASSINFO(PRFC822Channel, PIndirectChannel);
00887   public:
00888     enum Direction {
00889       Sending,
00890       Receiving
00891     };
00894     PRFC822Channel(
00895       Direction direction 
00896     );
00897 
00900     ~PRFC822Channel();
00901 
00902 
00903   // Overrides from class PChannel.
00908     BOOL Close();
00909 
00918     virtual BOOL Write(
00919       const void * buf, 
00920       PINDEX len        
00921     );
00922 
00923 
00928     void NewMessage(
00929       Direction direction  
00930     );
00931 
00941     PString MultipartMessage();
00942 
00952     BOOL MultipartMessage(
00953       const PString & boundary
00954     );
00955 
00966     void NextPart(
00967       const PString & boundary
00968     );
00969 
00970 
00974     void SetFromAddress(
00975       const PString & fromAddress  
00976     );
00977 
00981     void SetToAddress(
00982       const PString & toAddress 
00983     );
00984 
00988     void SetCC(
00989       const PString & ccAddress 
00990     );
00991 
00995     void SetBCC(
00996       const PString & bccAddress 
00997     );
00998 
01002     void SetSubject(
01003       const PString & subject  
01004     );
01005 
01013     void SetContentType(
01014       const PString & contentType   
01015     );
01016 
01024     void SetContentAttachment(
01025       const PFilePath & filename   
01026     );
01027 
01037     void SetTransferEncoding(
01038       const PString & encoding,   
01039       BOOL autoTranslate = TRUE   
01040     );
01041 
01042 
01046     void SetHeaderField(
01047       const PString & name,   
01048       const PString & value   
01049     );
01050 
01051     // Common MIME header tags
01052     static const PString & MimeVersionTag();
01053     static const PString & FromTag();
01054     static const PString & ToTag();
01055     static const PString & CCTag();
01056     static const PString & BCCTag();
01057     static const PString & SubjectTag();
01058     static const PString & DateTag();
01059     static const PString & ReturnPathTag();
01060     static const PString & ReceivedTag();
01061     static const PString & MessageIDTag();
01062     static const PString & MailerTag();
01063     static const PString & ContentTypeTag();
01064     static const PString & ContentDispositionTag();
01065     static const PString & ContentTransferEncodingTag();
01066 
01071     BOOL SendWithSMTP(
01072       const PString & hostname
01073     );
01074 
01079     BOOL SendWithSMTP(
01080       PSMTPClient * smtp
01081     );
01082 
01083 
01084   protected:
01085     BOOL OnOpen();
01086 
01087     BOOL        writeHeaders;
01088     PMIMEInfo   headers;
01089     BOOL        writePartHeaders;
01090     PMIMEInfo   partHeaders;
01091     PStringList boundaries;
01092     PBase64   * base64;
01093 };
01094 
01095 
01096 #endif  // _PMAILPROTOCOL
01097 
01098 
01099 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:25:02 2008 for PTLib by  doxygen 1.5.1