PWLib
1.10.10
|
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.20 2005/11/30 12:47:37 csoutheren 00029 * Removed tabs, reformatted some code, and changed tags for Doxygen 00030 * 00031 * Revision 1.19 2004/04/21 00:29:55 csoutheren 00032 * Added SASL authentication to PPOP3Client and PSMTPClient 00033 * Thanks to Federico Pinna and Reitek S.p.A. 00034 * 00035 * Revision 1.18 2002/11/06 22:47:24 robertj 00036 * Fixed header comment (copyright etc) 00037 * 00038 * Revision 1.17 2002/09/16 01:08:59 robertj 00039 * Added #define so can select if #pragma interface/implementation is used on 00040 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00041 * 00042 * Revision 1.16 2000/11/10 01:08:11 robertj 00043 * Added content transfer encoding and automatic base64 translation. 00044 * 00045 * Revision 1.15 2000/11/09 06:01:58 robertj 00046 * Added MIME version and content disposition to RFC822 class. 00047 * 00048 * Revision 1.14 2000/11/09 05:50:23 robertj 00049 * Added RFC822 aware channel class for doing internet mail. 00050 * 00051 * Revision 1.13 2000/06/21 01:01:21 robertj 00052 * AIX port, thanks Wolfgang Platzer (wolfgang.platzer@infonova.at). 00053 * 00054 * Revision 1.12 2000/06/19 11:33:53 robertj 00055 * Fixed incorrect comment documentation 00056 * 00057 * Revision 1.11 1999/03/09 08:01:46 robertj 00058 * Changed comments for doc++ support (more to come). 00059 * 00060 * Revision 1.10 1999/02/16 08:07:10 robertj 00061 * MSVC 6.0 compatibility changes. 00062 * 00063 * Revision 1.9 1998/11/30 02:50:51 robertj 00064 * New directory structure 00065 * 00066 * Revision 1.8 1998/09/23 06:19:36 robertj 00067 * Added open source copyright license. 00068 * 00069 * Revision 1.7 1996/12/21 01:24:15 robertj 00070 * Added missing open message to pop server. 00071 * 00072 * Revision 1.6 1996/09/16 12:57:45 robertj 00073 * Removed redundant functions. 00074 * 00075 * Revision 1.5 1996/09/14 13:17:59 robertj 00076 * Renamed file and changed to be a protocol off new indirect channel to separate 00077 * the protocol from the low level byte transport channel. 00078 * 00079 * Revision 1.4 1996/07/27 04:14:49 robertj 00080 * Redesign and reimplement of mail sockets. 00081 * 00082 * Revision 1.3 1996/06/28 13:16:32 robertj 00083 * Changed SMTP incoming message handler so can tell when started, processing or ended message. 00084 * 00085 * Revision 1.2 1996/03/16 04:38:24 robertj 00086 * Added ParseReponse() for splitting reponse line into code and info. 00087 * 00088 * Revision 1.1 1996/01/23 13:04:20 robertj 00089 * Initial revision 00090 * 00091 * Revision 1.3 1995/06/17 11:12:15 robertj 00092 * Documentation update. 00093 * 00094 * Revision 1.2 1995/06/17 00:39:53 robertj 00095 * More implementation. 00096 * 00097 * Revision 1.1 1995/06/04 13:17:16 robertj 00098 * Initial revision 00099 * 00100 */ 00101 00102 #ifndef _PMAILPROTOCOL 00103 #define _PMAILPROTOCOL 00104 00105 #ifdef P_USE_PRAGMA 00106 #pragma interface 00107 #endif 00108 00109 #include <ptclib/inetprot.h> 00110 #include <ptclib/mime.h> 00111 00112 class PSocket; 00113 00114 00116 // PSMTP 00117 00143 class PSMTP : public PInternetProtocol 00144 { 00145 PCLASSINFO(PSMTP, PInternetProtocol) 00146 00147 public: 00148 // New functions for class. 00149 enum Commands { 00150 HELO, EHLO, QUIT, HELP, NOOP, 00151 TURN, RSET, VRFY, EXPN, RCPT, 00152 MAIL, SEND, SAML, SOML, DATA, 00153 AUTH, NumCommands 00154 }; 00155 00156 protected: 00157 PSMTP(); 00158 // Create a new SMTP protocol channel. 00159 }; 00160 00161 00178 class PSMTPClient : public PSMTP 00179 { 00180 PCLASSINFO(PSMTPClient, PSMTP) 00181 00182 public: 00189 PSMTPClient(); 00190 00194 ~PSMTPClient(); 00195 00196 00197 // Overrides from class PChannel. 00203 virtual BOOL Close(); 00204 00205 00206 // New functions for class. 00214 BOOL LogIn( 00215 const PString & username, 00216 const PString & password 00217 ); 00218 00227 BOOL BeginMessage( 00228 const PString & from, 00229 const PString & to, 00230 BOOL eightBitMIME = FALSE 00231 ); 00232 BOOL BeginMessage( 00233 const PString & from, 00234 const PStringList & toList, 00235 BOOL eightBitMIME = FALSE 00236 ); 00237 00243 BOOL EndMessage(); 00244 00245 00246 protected: 00247 BOOL OnOpen(); 00248 00249 BOOL haveHello; 00250 BOOL extendedHello; 00251 BOOL eightBitMIME; 00252 PString fromAddress; 00253 PStringList toNames; 00254 BOOL sendingData; 00255 00256 private: 00257 BOOL _BeginMessage(); 00258 }; 00259 00260 00286 class PSMTPServer : public PSMTP 00287 { 00288 PCLASSINFO(PSMTPServer, PSMTP) 00289 00290 public: 00297 PSMTPServer(); 00298 00299 00300 // New functions for class. 00308 BOOL ProcessCommand(); 00309 00310 void ServerReset(); 00311 // Reset the state of the SMTP server socket. 00312 00313 enum ForwardResult { 00314 LocalDomain, 00315 WillForward, 00316 CannotForward 00317 }; 00318 // Result of forward check 00319 00326 virtual ForwardResult ForwardDomain( 00327 PCaselessString & userDomain, 00328 PCaselessString & forwardDomainList 00329 ); 00330 00331 enum LookUpResult { 00332 ValidUser, 00333 AmbiguousUser, 00334 UnknownUser, 00335 LookUpError 00336 }; 00337 // Result of user name look up 00338 00346 virtual LookUpResult LookUpName( 00347 const PCaselessString & name, 00348 PString & expandedName 00349 ); 00350 00360 virtual BOOL HandleMessage( 00361 PCharArray & buffer, 00362 BOOL starting, 00363 BOOL completed 00364 00365 ); 00366 00367 00368 protected: 00369 BOOL OnOpen(); 00370 00371 virtual void OnHELO( 00372 const PCaselessString & remoteHost 00373 ); 00374 // Start connection. 00375 00376 virtual void OnEHLO( 00377 const PCaselessString & remoteHost 00378 ); 00379 // Start extended SMTP connection. 00380 00381 virtual void OnQUIT(); 00382 // close connection and die. 00383 00384 virtual void OnHELP(); 00385 // get help. 00386 00387 virtual void OnNOOP(); 00388 // do nothing 00389 00390 virtual void OnTURN(); 00391 // switch places 00392 00393 virtual void OnRSET(); 00394 // Reset state. 00395 00396 virtual void OnVRFY( 00397 const PCaselessString & name 00398 ); 00399 // Verify address. 00400 00401 virtual void OnEXPN( 00402 const PCaselessString & name 00403 ); 00404 // Expand alias. 00405 00406 virtual void OnRCPT( 00407 const PCaselessString & recipient 00408 ); 00409 // Designate recipient 00410 00411 virtual void OnMAIL( 00412 const PCaselessString & sender 00413 ); 00414 // Designate sender 00415 00416 virtual void OnSEND( 00417 const PCaselessString & sender 00418 ); 00419 // send message to screen 00420 00421 virtual void OnSAML( 00422 const PCaselessString & sender 00423 ); 00424 // send AND mail 00425 00426 virtual void OnSOML( 00427 const PCaselessString & sender 00428 ); 00429 // send OR mail 00430 00431 virtual void OnDATA(); 00432 // Message text. 00433 00440 virtual BOOL OnUnknown( 00441 const PCaselessString & command 00442 ); 00443 00444 virtual void OnSendMail( 00445 const PCaselessString & sender 00446 ); 00447 // Common code for OnMAIL(), OnSEND(), OnSOML() and OnSAML() funtions. 00448 00460 virtual BOOL OnTextData(PCharArray & buffer, BOOL & completed); 00461 00473 virtual BOOL OnMIMEData(PCharArray & buffer, BOOL & completed); 00474 00475 00476 // Member variables 00477 BOOL extendedHello; 00478 BOOL eightBitMIME; 00479 PString fromAddress; 00480 PString fromPath; 00481 PStringList toNames; 00482 PStringList toDomains; 00483 PINDEX messageBufferSize; 00484 enum { WasMAIL, WasSEND, WasSAML, WasSOML } sendCommand; 00485 StuffState endMIMEDetectState; 00486 }; 00487 00488 00490 // PPOP3 00491 00529 class PPOP3 : public PInternetProtocol 00530 { 00531 PCLASSINFO(PPOP3, PInternetProtocol) 00532 00533 public: 00534 enum Commands { 00535 USER, PASS, QUIT, RSET, NOOP, STATcmd, 00536 LIST, RETR, DELE, APOP, TOP, UIDL, 00537 AUTH, NumCommands 00538 }; 00539 00540 00541 protected: 00542 PPOP3(); 00543 00555 virtual PINDEX ParseResponse( 00556 const PString & line 00557 ); 00558 00559 // Member variables 00560 static PString okResponse; 00561 static PString errResponse; 00562 }; 00563 00564 00592 class PPOP3Client : public PPOP3 00593 { 00594 PCLASSINFO(PPOP3Client, PPOP3) 00595 00596 public: 00603 PPOP3Client(); 00604 00608 ~PPOP3Client(); 00609 00610 00611 // Overrides from class PChannel. 00617 virtual BOOL Close(); 00618 00619 00620 // New functions for class. 00621 enum LoginOptions 00622 { 00623 AllowUserPass = 1, 00624 00625 UseSASL = 2, 00626 00627 AllowClearTextSASL = 4 00628 }; 00629 00635 BOOL LogIn( 00636 const PString & username, 00637 const PString & password, 00638 int options = AllowUserPass 00639 ); 00640 00646 int GetMessageCount(); 00647 00654 PUnsignedArray GetMessageSizes(); 00655 00665 PStringArray GetMessageHeaders(); 00666 00667 00668 /* Begin the retrieval of an entire message. The application may then use 00669 the <A>PApplicationSocket::ReadLine()</A> function with the 00670 <CODE>unstuffLine</CODE> parameter set to TRUE. Repeated calls until 00671 its return valus is FALSE will read the message headers and body. 00672 00673 @return 00674 Array of strings continaing message headers. 00675 */ 00676 BOOL BeginMessage( 00677 PINDEX messageNumber 00681 ); 00682 00688 BOOL DeleteMessage( 00689 PINDEX messageNumber 00690 /* Number of message to retrieve. This is an integer from 1 to the 00691 maximum number of messages available. 00692 */ 00693 ); 00694 00695 00696 protected: 00697 BOOL OnOpen(); 00698 00699 // Member variables 00700 BOOL loggedIn; 00701 PString apopBanner; 00702 }; 00703 00704 00717 class PPOP3Server : public PPOP3 00718 { 00719 PCLASSINFO(PPOP3Server, PPOP3) 00720 00721 public: 00728 PPOP3Server(); 00729 00730 00731 // New functions for class. 00739 BOOL ProcessCommand(); 00740 00750 virtual BOOL HandleOpenMailbox( 00751 const PString & username, 00752 const PString & password 00753 ); 00754 00762 virtual void HandleSendMessage( 00763 PINDEX messageNumber, 00764 const PString & id, 00765 PINDEX lines 00766 ); 00767 00775 virtual void HandleDeleteMessage( 00776 PINDEX messageNumber, 00777 const PString & id 00778 ); 00779 00780 00781 protected: 00782 BOOL OnOpen(); 00783 00784 virtual void OnUSER( 00785 const PString & name 00786 ); 00787 // Specify user name (mailbox). 00788 00789 virtual void OnPASS( 00790 const PString & passwd 00791 ); 00792 // Specify password and log user in. 00793 00794 virtual void OnQUIT(); 00795 // End connection, saving all changes (delete messages). 00796 00797 virtual void OnRSET(); 00798 // Reset connection (undelete messages). 00799 00800 virtual void OnNOOP(); 00801 // Do nothing. 00802 00803 virtual void OnSTAT(); 00804 // Get number of messages in mailbox. 00805 00809 virtual void OnLIST( 00810 PINDEX msg 00811 ); 00812 00813 virtual void OnRETR( 00814 PINDEX msg 00815 ); 00816 // Retrieve a message from mailbox. 00817 00818 virtual void OnDELE( 00819 PINDEX msg 00820 ); 00821 // Delete a message from mailbox. 00822 00823 virtual void OnTOP( 00824 PINDEX msg, 00825 PINDEX count 00826 ); 00827 // Get the message header and top <CODE>count</CODE> lines of message. 00828 00832 virtual void OnUIDL( 00833 PINDEX msg 00834 ); 00835 00842 virtual BOOL OnUnknown( 00843 const PCaselessString & command 00844 ); 00845 00846 00847 // Member variables 00848 PString username; 00849 PUnsignedArray messageSizes; 00850 PStringArray messageIDs; 00851 PBYTEArray messageDeletions; 00852 }; 00853 00854 00880 class PRFC822Channel : public PIndirectChannel 00881 { 00882 PCLASSINFO(PRFC822Channel, PIndirectChannel); 00883 public: 00884 enum Direction { 00885 Sending, 00886 Receiving 00887 }; 00890 PRFC822Channel( 00891 Direction direction 00892 ); 00893 00896 ~PRFC822Channel(); 00897 00898 00899 // Overrides from class PChannel. 00904 BOOL Close(); 00905 00914 virtual BOOL Write( 00915 const void * buf, 00916 PINDEX len 00917 ); 00918 00919 00924 void NewMessage( 00925 Direction direction 00926 ); 00927 00937 PString MultipartMessage(); 00938 00948 BOOL MultipartMessage( 00949 const PString & boundary 00950 ); 00951 00962 void NextPart( 00963 const PString & boundary 00964 ); 00965 00966 00970 void SetFromAddress( 00971 const PString & fromAddress 00972 ); 00973 00977 void SetToAddress( 00978 const PString & toAddress 00979 ); 00980 00984 void SetCC( 00985 const PString & ccAddress 00986 ); 00987 00991 void SetBCC( 00992 const PString & bccAddress 00993 ); 00994 00998 void SetSubject( 00999 const PString & subject 01000 ); 01001 01009 void SetContentType( 01010 const PString & contentType 01011 ); 01012 01020 void SetContentAttachment( 01021 const PFilePath & filename 01022 ); 01023 01033 void SetTransferEncoding( 01034 const PString & encoding, 01035 BOOL autoTranslate = TRUE 01036 ); 01037 01038 01042 void SetHeaderField( 01043 const PString & name, 01044 const PString & value 01045 ); 01046 01047 // Common MIME header tags 01048 static const char MimeVersionTag[]; 01049 static const char FromTag[]; 01050 static const char ToTag[]; 01051 static const char CCTag[]; 01052 static const char BCCTag[]; 01053 static const char SubjectTag[]; 01054 static const char DateTag[]; 01055 static const char ReturnPathTag[]; 01056 static const char ReceivedTag[]; 01057 static const char MessageIDTag[]; 01058 static const char MailerTag[]; 01059 static const char ContentTypeTag[]; 01060 static const char ContentDispositionTag[]; 01061 static const char ContentTransferEncodingTag[]; 01062 01067 BOOL SendWithSMTP( 01068 const PString & hostname 01069 ); 01070 01075 BOOL SendWithSMTP( 01076 PSMTPClient * smtp 01077 ); 01078 01079 01080 protected: 01081 BOOL OnOpen(); 01082 01083 BOOL writeHeaders; 01084 PMIMEInfo headers; 01085 BOOL writePartHeaders; 01086 PMIMEInfo partHeaders; 01087 PStringList boundaries; 01088 PBase64 * base64; 01089 }; 01090 01091 01092 #endif // _PMAILPROTOCOL 01093 01094 01095 // End Of File ///////////////////////////////////////////////////////////////