00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
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
00121
00147 class PSMTP : public PInternetProtocol
00148 {
00149 PCLASSINFO(PSMTP, PInternetProtocol)
00150
00151 public:
00152
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
00163 };
00164
00165
00182 class PSMTPClient : public PSMTP
00183 {
00184 PCLASSINFO(PSMTPClient, PSMTP)
00185
00186 public:
00193 PSMTPClient();
00194
00198 ~PSMTPClient();
00199
00200
00201
00207 virtual BOOL Close();
00208
00209
00210
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
00312 BOOL ProcessCommand();
00313
00314 void ServerReset();
00315
00316
00317 enum ForwardResult {
00318 LocalDomain,
00319 WillForward,
00320 CannotForward
00321 };
00322
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
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
00379
00380 virtual void OnEHLO(
00381 const PCaselessString & remoteHost
00382 );
00383
00384
00385 virtual void OnQUIT();
00386
00387
00388 virtual void OnHELP();
00389
00390
00391 virtual void OnNOOP();
00392
00393
00394 virtual void OnTURN();
00395
00396
00397 virtual void OnRSET();
00398
00399
00400 virtual void OnVRFY(
00401 const PCaselessString & name
00402 );
00403
00404
00405 virtual void OnEXPN(
00406 const PCaselessString & name
00407 );
00408
00409
00410 virtual void OnRCPT(
00411 const PCaselessString & recipient
00412 );
00413
00414
00415 virtual void OnMAIL(
00416 const PCaselessString & sender
00417 );
00418
00419
00420 virtual void OnSEND(
00421 const PCaselessString & sender
00422 );
00423
00424
00425 virtual void OnSAML(
00426 const PCaselessString & sender
00427 );
00428
00429
00430 virtual void OnSOML(
00431 const PCaselessString & sender
00432 );
00433
00434
00435 virtual void OnDATA();
00436
00437
00444 virtual BOOL OnUnknown(
00445 const PCaselessString & command
00446 );
00447
00448 virtual void OnSendMail(
00449 const PCaselessString & sender
00450 );
00451
00452
00464 virtual BOOL OnTextData(PCharArray & buffer, BOOL & completed);
00465
00477 virtual BOOL OnMIMEData(PCharArray & buffer, BOOL & completed);
00478
00479
00480
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
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
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
00621 virtual BOOL Close();
00622
00623
00624
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
00673
00674
00675
00676
00677
00678
00679
00680 BOOL BeginMessage(
00681 PINDEX messageNumber
00685 );
00686
00692 BOOL DeleteMessage(
00693 PINDEX messageNumber
00694
00695
00696
00697 );
00698
00699
00700 protected:
00701 BOOL OnOpen();
00702
00703
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
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
00792
00793 virtual void OnPASS(
00794 const PString & passwd
00795 );
00796
00797
00798 virtual void OnQUIT();
00799
00800
00801 virtual void OnRSET();
00802
00803
00804 virtual void OnNOOP();
00805
00806
00807 virtual void OnSTAT();
00808
00809
00813 virtual void OnLIST(
00814 PINDEX msg
00815 );
00816
00817 virtual void OnRETR(
00818 PINDEX msg
00819 );
00820
00821
00822 virtual void OnDELE(
00823 PINDEX msg
00824 );
00825
00826
00827 virtual void OnTOP(
00828 PINDEX msg,
00829 PINDEX count
00830 );
00831
00832
00836 virtual void OnUIDL(
00837 PINDEX msg
00838 );
00839
00846 virtual BOOL OnUnknown(
00847 const PCaselessString & command
00848 );
00849
00850
00851
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
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
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