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  * $Revision: 20385 $
00028  * $Author: rjongbloed $
00029  * $Date: 2008-06-04 10:40:38 +0000 (Wed, 04 Jun 2008) $
00030  */
00031 
00032 #ifndef _PMAILPROTOCOL
00033 #define _PMAILPROTOCOL
00034 
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038 
00039 #include <ptclib/inetprot.h>
00040 #include <ptclib/mime.h>
00041 
00042 class PSocket;
00043 
00044 
00046 // PSMTP
00047 
00073 class PSMTP : public PInternetProtocol
00074 {
00075   PCLASSINFO(PSMTP, PInternetProtocol)
00076 
00077   public:
00078   // New functions for class.
00079     enum Commands {
00080       HELO, EHLO, QUIT, HELP, NOOP,
00081       TURN, RSET, VRFY, EXPN, RCPT,
00082       MAIL, SEND, SAML, SOML, DATA,
00083       AUTH, NumCommands
00084     };
00085 
00086   protected:
00087     PSMTP();
00088     // Create a new SMTP protocol channel.
00089 };
00090 
00091 
00108 class PSMTPClient : public PSMTP
00109 {
00110   PCLASSINFO(PSMTPClient, PSMTP)
00111 
00112   public:
00119     PSMTPClient();
00120 
00124     ~PSMTPClient();
00125 
00126 
00127   // Overrides from class PChannel.
00133     virtual PBoolean Close();
00134 
00135 
00136   // New functions for class.
00144     PBoolean LogIn(
00145       const PString & username,   
00146       const PString & password    
00147     );
00148 
00157     PBoolean BeginMessage(
00158       const PString & from,        
00159       const PString & to,          
00160       PBoolean eightBitMIME = PFalse    
00161     );
00162     PBoolean BeginMessage(
00163       const PString & from,        
00164       const PStringList & toList,  
00165       PBoolean eightBitMIME = PFalse    
00166     );
00167 
00173     PBoolean EndMessage();
00174 
00175 
00176   protected:
00177     PBoolean OnOpen();
00178 
00179     PBoolean    haveHello;
00180     PBoolean    extendedHello;
00181     PBoolean    eightBitMIME;
00182     PString fromAddress;
00183     PStringList toNames;
00184     PBoolean    sendingData;
00185 
00186   private:
00187     PBoolean _BeginMessage();
00188 };
00189 
00190 
00216 class PSMTPServer : public PSMTP
00217 {
00218   PCLASSINFO(PSMTPServer, PSMTP)
00219 
00220   public:
00227     PSMTPServer();
00228 
00229 
00230   // New functions for class.
00238     PBoolean ProcessCommand();
00239 
00240     void ServerReset();
00241     // Reset the state of the SMTP server socket.
00242 
00243     enum ForwardResult {
00244       LocalDomain,    
00245       WillForward,    
00246       CannotForward   
00247     };
00248     // Result of forward check
00249 
00256     virtual ForwardResult ForwardDomain(
00257       PCaselessString & userDomain,       
00258       PCaselessString & forwardDomainList 
00259     );
00260 
00261     enum LookUpResult {
00262       ValidUser,      
00263       AmbiguousUser,  
00264       UnknownUser,    
00265       LookUpError     
00266     };
00267     // Result of user name look up
00268 
00276     virtual LookUpResult LookUpName(
00277       const PCaselessString & name,    
00278       PString & expandedName           
00279     );
00280 
00290     virtual PBoolean HandleMessage(
00291       PCharArray & buffer,  
00292       PBoolean starting,        
00293       PBoolean completed        
00294 
00295     );
00296 
00297 
00298   protected:
00299     PBoolean OnOpen();
00300 
00301     virtual void OnHELO(
00302       const PCaselessString & remoteHost  
00303     );
00304     // Start connection.
00305 
00306     virtual void OnEHLO(
00307       const PCaselessString & remoteHost  
00308     );
00309     // Start extended SMTP connection.
00310 
00311     virtual void OnQUIT();
00312     // close connection and die.
00313 
00314     virtual void OnHELP();
00315     // get help.
00316 
00317     virtual void OnNOOP();
00318     // do nothing
00319     
00320     virtual void OnTURN();
00321     // switch places
00322     
00323     virtual void OnRSET();
00324     // Reset state.
00325 
00326     virtual void OnVRFY(
00327       const PCaselessString & name    
00328     );
00329     // Verify address.
00330 
00331     virtual void OnEXPN(
00332       const PCaselessString & name    
00333     );
00334     // Expand alias.
00335 
00336     virtual void OnRCPT(
00337       const PCaselessString & recipient   
00338     );
00339     // Designate recipient
00340 
00341     virtual void OnMAIL(
00342       const PCaselessString & sender  
00343     );
00344     // Designate sender
00345     
00346     virtual void OnSEND(
00347       const PCaselessString & sender  
00348     );
00349     // send message to screen
00350 
00351     virtual void OnSAML(
00352       const PCaselessString & sender  
00353     );
00354     // send AND mail
00355     
00356     virtual void OnSOML(
00357       const PCaselessString & sender  
00358     );
00359     // send OR mail
00360 
00361     virtual void OnDATA();
00362     // Message text.
00363 
00370     virtual PBoolean OnUnknown(
00371       const PCaselessString & command  
00372     );
00373 
00374     virtual void OnSendMail(
00375       const PCaselessString & sender  
00376     );
00377     // Common code for OnMAIL(), OnSEND(), OnSOML() and OnSAML() funtions.
00378 
00390     virtual PBoolean OnTextData(PCharArray & buffer, PBoolean & completed);
00391 
00403     virtual PBoolean OnMIMEData(PCharArray & buffer, PBoolean & completed);
00404 
00405 
00406   // Member variables
00407     PBoolean        extendedHello;
00408     PBoolean        eightBitMIME;
00409     PString     fromAddress;
00410     PString     fromPath;
00411     PStringList toNames;
00412     PStringList toDomains;
00413     PINDEX      messageBufferSize;
00414     enum { WasMAIL, WasSEND, WasSAML, WasSOML } sendCommand;
00415     StuffState  endMIMEDetectState;
00416 };
00417 
00418 
00420 // PPOP3
00421 
00459 class PPOP3 : public PInternetProtocol
00460 {
00461   PCLASSINFO(PPOP3, PInternetProtocol)
00462 
00463   public:
00464     enum Commands {
00465       USER, PASS, QUIT, RSET, NOOP, STATcmd,
00466       LIST, RETR, DELE, APOP, TOP,  UIDL,
00467       AUTH, NumCommands
00468     };
00469 
00470 
00471   protected:
00472     PPOP3();
00473 
00485     virtual PINDEX ParseResponse(
00486       const PString & line 
00487     );
00488 
00489   // Member variables
00490     static PString okResponse;
00491     static PString errResponse;
00492 };
00493 
00494 
00522 class PPOP3Client : public PPOP3
00523 {
00524   PCLASSINFO(PPOP3Client, PPOP3)
00525 
00526   public:
00533     PPOP3Client();
00534 
00538     ~PPOP3Client();
00539 
00540 
00541   // Overrides from class PChannel.
00547     virtual PBoolean Close();
00548 
00549 
00550   // New functions for class.
00551     enum LoginOptions
00552     {
00553       AllowUserPass = 1,      
00554 
00555       UseSASL = 2,            
00556 
00557       AllowClearTextSASL = 4  
00558     };
00559 
00565     PBoolean LogIn(
00566       const PString & username,       
00567       const PString & password,       
00568       int options = AllowUserPass     
00569     );
00570 
00576     int GetMessageCount();
00577 
00584     PUnsignedArray GetMessageSizes();
00585 
00595     PStringArray GetMessageHeaders();
00596 
00597 
00598     /* Begin the retrieval of an entire message. The application may then use
00599        the <A>PApplicationSocket::ReadLine()</A> function with the
00600        <CODE>unstuffLine</CODE> parameter set to PTrue. Repeated calls until
00601        its return valus is PFalse will read the message headers and body.
00602 
00603        @return
00604        Array of strings continaing message headers.
00605      */
00606     PBoolean BeginMessage(
00607       PINDEX messageNumber
00611     );
00612 
00618     PBoolean DeleteMessage(
00619       PINDEX messageNumber
00620         /* Number of message to retrieve. This is an integer from 1 to the
00621            maximum number of messages available.
00622          */
00623     );
00624 
00625 
00626   protected:
00627     PBoolean OnOpen();
00628 
00629   // Member variables
00630     PBoolean loggedIn;
00631     PString apopBanner;
00632 };
00633 
00634 
00647 class PPOP3Server : public PPOP3
00648 {
00649   PCLASSINFO(PPOP3Server, PPOP3)
00650 
00651   public:
00658     PPOP3Server();
00659 
00660 
00661   // New functions for class.
00669     PBoolean ProcessCommand();
00670 
00680     virtual PBoolean HandleOpenMailbox(
00681       const PString & username,  
00682       const PString & password   
00683     );
00684 
00692     virtual void HandleSendMessage(
00693       PINDEX messageNumber, 
00694       const PString & id,   
00695       PINDEX lines          
00696     );
00697     
00705     virtual void HandleDeleteMessage(
00706       PINDEX messageNumber, 
00707       const PString & id    
00708     );
00709     
00710 
00711   protected:
00712     PBoolean OnOpen();
00713 
00714     virtual void OnUSER(
00715       const PString & name  
00716     );
00717     // Specify user name (mailbox).
00718 
00719     virtual void OnPASS(
00720       const PString & passwd  
00721     );
00722     // Specify password and log user in.
00723 
00724     virtual void OnQUIT();
00725     // End connection, saving all changes (delete messages).
00726 
00727     virtual void OnRSET();
00728     // Reset connection (undelete messages).
00729 
00730     virtual void OnNOOP();
00731     // Do nothing.
00732 
00733     virtual void OnSTAT();
00734     // Get number of messages in mailbox.
00735 
00739     virtual void OnLIST(
00740       PINDEX msg  
00741     );
00742 
00743     virtual void OnRETR(
00744       PINDEX msg  
00745     );
00746     // Retrieve a message from mailbox.
00747 
00748     virtual void OnDELE(
00749       PINDEX msg  
00750     );
00751     // Delete a message from mailbox.
00752 
00753     virtual void OnTOP(
00754       PINDEX msg,  
00755       PINDEX count 
00756     );
00757     // Get the message header and top <CODE>count</CODE> lines of message.
00758 
00762     virtual void OnUIDL(
00763       PINDEX msg  
00764     );
00765 
00772     virtual PBoolean OnUnknown(
00773       const PCaselessString & command  
00774     );
00775 
00776 
00777   // Member variables
00778     PString        username;
00779     PUnsignedArray messageSizes;
00780     PStringArray   messageIDs;
00781     PBYTEArray     messageDeletions;
00782 };
00783 
00784 
00810 class PRFC822Channel : public PIndirectChannel
00811 {
00812     PCLASSINFO(PRFC822Channel, PIndirectChannel);
00813   public:
00814     enum Direction {
00815       Sending,
00816       Receiving
00817     };
00820     PRFC822Channel(
00821       Direction direction 
00822     );
00823 
00826     ~PRFC822Channel();
00827 
00828 
00829   // Overrides from class PChannel.
00834     PBoolean Close();
00835 
00844     virtual PBoolean Write(
00845       const void * buf, 
00846       PINDEX len        
00847     );
00848 
00849 
00854     void NewMessage(
00855       Direction direction  
00856     );
00857 
00867     PString MultipartMessage();
00868 
00878     PBoolean MultipartMessage(
00879       const PString & boundary
00880     );
00881 
00892     void NextPart(
00893       const PString & boundary
00894     );
00895 
00896 
00900     void SetFromAddress(
00901       const PString & fromAddress  
00902     );
00903 
00907     void SetToAddress(
00908       const PString & toAddress 
00909     );
00910 
00914     void SetCC(
00915       const PString & ccAddress 
00916     );
00917 
00921     void SetBCC(
00922       const PString & bccAddress 
00923     );
00924 
00928     void SetSubject(
00929       const PString & subject  
00930     );
00931 
00939     void SetContentType(
00940       const PString & contentType   
00941     );
00942 
00950     void SetContentAttachment(
00951       const PFilePath & filename   
00952     );
00953 
00963     void SetTransferEncoding(
00964       const PString & encoding,   
00965       PBoolean autoTranslate = PTrue   
00966     );
00967 
00968 
00972     void SetHeaderField(
00973       const PString & name,   
00974       const PString & value   
00975     );
00976 
00977     // Common MIME header tags
00978     static const PString & MimeVersionTag();
00979     static const PString & FromTag();
00980     static const PString & ToTag();
00981     static const PString & CCTag();
00982     static const PString & BCCTag();
00983     static const PString & SubjectTag();
00984     static const PString & DateTag();
00985     static const PString & ReturnPathTag();
00986     static const PString & ReceivedTag();
00987     static const PString & MessageIDTag();
00988     static const PString & MailerTag();
00989     static const PString & ContentTypeTag();
00990     static const PString & ContentDispositionTag();
00991     static const PString & ContentTransferEncodingTag();
00992 
00997     PBoolean SendWithSMTP(
00998       const PString & hostname
00999     );
01000 
01005     PBoolean SendWithSMTP(
01006       PSMTPClient * smtp
01007     );
01008 
01009 
01010   protected:
01011     PBoolean OnOpen();
01012 
01013     PBoolean        writeHeaders;
01014     PMIMEInfo   headers;
01015     PBoolean        writePartHeaders;
01016     PMIMEInfo   partHeaders;
01017     PStringList boundaries;
01018     PBase64   * base64;
01019 };
01020 
01021 
01022 #endif  // _PMAILPROTOCOL
01023 
01024 
01025 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Sep 15 01:21:35 2008 for PTLib by  doxygen 1.5.1