PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
inetmail.h
Go to the documentation of this file.
1 /*
2  * inetmail.h
3  *
4  * Internet Mail channel classes
5  * Simple Mail Transport Protocol & Post Office Protocol v3
6  *
7  * Portable Windows Library
8  *
9  * Copyright (c) 1993-2002 Equivalence Pty. Ltd.
10  *
11  * The contents of this file are subject to the Mozilla Public License
12  * Version 1.0 (the "License"); you may not use this file except in
13  * compliance with the License. You may obtain a copy of the License at
14  * http://www.mozilla.org/MPL/
15  *
16  * Software distributed under the License is distributed on an "AS IS"
17  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18  * the License for the specific language governing rights and limitations
19  * under the License.
20  *
21  * The Original Code is Portable Windows Library.
22  *
23  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24  *
25  * Contributor(s): Federico Pinna and Reitek S.p.A.
26  */
27 
28 #ifndef PTLIB_INETMAIL_H
29 #define PTLIB_INETMAIL_H
30 
31 #ifdef P_USE_PRAGMA
32 #pragma interface
33 #endif
34 
35 #include <ptclib/inetprot.h>
36 #include <ptclib/mime.h>
37 
38 class PSocket;
39 
40 
42 // PSMTP
43 
69 class PSMTP : public PInternetProtocol
70 {
72 
73  public:
74  // New functions for class.
75  enum Commands {
80  };
81 
83  struct Parameters
84  {
86  : m_port(0)
87  , m_eightBitMIME(false)
88  {
89  }
90 
92  WORD m_port;
103  };
104 
107  static bool SendMail(
108  const Parameters & params,
109  PString & error
110  );
111 
112  protected:
113  PSMTP();
114  // Create a new SMTP protocol channel.
115 };
116 
117 
134 class PSMTPClient : public PSMTP
135 {
137 
138  public:
145  PSMTPClient();
146 
150  ~PSMTPClient();
151 
152 
153  // Overrides from class PChannel.
159  virtual PBoolean Close();
160 
161 
162  // New functions for class.
170  bool LogIn(
171  const PString & username,
172  const PString & password
173  );
174 
183  bool BeginMessage(
184  const PString & from,
185  const PString & to,
186  PBoolean eightBitMIME = false
187  );
188  bool BeginMessage(
189  const PString & from,
190  const PStringList & toList,
191  bool eightBitMIME = false
192  );
193 
200 
201 
202  protected:
203  PBoolean OnOpen();
204 
210 
211  private:
212  bool InternalHello();
213  bool InternalExtendedHello();
214  PString InternalLocalHostName();
215  bool InternalBeginMessage(bool useEightBitMIME);
216 };
217 
218 
244 class PSMTPServer : public PSMTP
245 {
247 
248  public:
255  PSMTPServer();
256 
257 
258  // New functions for class.
267 
268  void ServerReset();
269  // Reset the state of the SMTP server socket.
270 
275  };
276  // Result of forward check
277 
285  PCaselessString & userDomain,
286  PCaselessString & forwardDomainList
287  );
288 
294  };
295  // Result of user name look up
296 
304  virtual LookUpResult LookUpName(
305  const PCaselessString & name,
306  PString & expandedName
307  );
308 
318  virtual PBoolean HandleMessage(
319  PCharArray & buffer,
320  PBoolean starting,
321  PBoolean completed
322  );
324 
325 
326  protected:
327  PBoolean OnOpen();
328 
329  virtual void OnHELO(
330  const PCaselessString & remoteHost
331  );
332  // Start connection.
333 
334  virtual void OnEHLO(
335  const PCaselessString & remoteHost
336  );
337  // Start extended SMTP connection.
338 
339  virtual void OnQUIT();
340  // close connection and die.
341 
342  virtual void OnHELP();
343  // get help.
344 
345  virtual void OnNOOP();
346  // do nothing
347 
348  virtual void OnTURN();
349  // switch places
350 
351  virtual void OnRSET();
352  // Reset state.
353 
354  virtual void OnVRFY(
355  const PCaselessString & name
356  );
357  // Verify address.
358 
359  virtual void OnEXPN(
360  const PCaselessString & name
361  );
362  // Expand alias.
363 
364  virtual void OnRCPT(
365  const PCaselessString & recipient
366  );
367  // Designate recipient
368 
369  virtual void OnMAIL(
370  const PCaselessString & sender
371  );
372  // Designate sender
373 
374  virtual void OnSEND(
375  const PCaselessString & sender
376  );
377  // send message to screen
378 
379  virtual void OnSAML(
380  const PCaselessString & sender
381  );
382  // send AND mail
383 
384  virtual void OnSOML(
385  const PCaselessString & sender
386  );
387  // send OR mail
388 
389  virtual void OnDATA();
390  // Message text.
391 
398  virtual PBoolean OnUnknown(
399  const PCaselessString & command
400  );
401 
402  virtual void OnSendMail(
403  const PCaselessString & sender
404  );
405  // Common code for OnMAIL(), OnSEND(), OnSOML() and OnSAML() funtions.
406 
418  virtual PBoolean OnTextData(PCharArray & buffer, PBoolean & completed);
419 
431  virtual PBoolean OnMIMEData(PCharArray & buffer, PBoolean & completed);
432 
433 
434  // Member variables
444 };
445 
446 
448 // PPOP3
449 
487 class PPOP3 : public PInternetProtocol
488 {
490 
491  public:
492  enum Commands {
496  };
497 
498 
499  protected:
500  PPOP3();
501 
513  virtual PINDEX ParseResponse(
514  const PString & line
515  );
516 
517  // Member variables
518  static const PString & okResponse();
519  static const PString & errResponse();
520 };
521 
522 
550 class PPOP3Client : public PPOP3
551 {
553 
554  public:
561  PPOP3Client();
562 
566  ~PPOP3Client();
567 
568 
569  // Overrides from class PChannel.
575  virtual PBoolean Close();
576 
577 
578  // New functions for class.
580  {
582  UseSASL = 2,
584  AllowClearTextSASL = 4
586  };
587 
593  PBoolean LogIn(
594  const PString & username,
595  const PString & password,
596  int options = AllowUserPass
597  );
598 
604  int GetMessageCount();
605 
613 
624 
625 
626  /* Begin the retrieval of an entire message. The application may then use
627  the <A>PApplicationSocket::ReadLine()</A> function with the
628  <CODE>unstuffLine</CODE> parameter set to true. Repeated calls until
629  its return valus is false will read the message headers and body.
630 
631  @return
632  Array of strings continaing message headers.
633  */
635  PINDEX messageNumber
639  );
640 
647  PINDEX messageNumber
648  /* Number of message to retrieve. This is an integer from 1 to the
649  maximum number of messages available.
650  */
651  );
652 
653 
654  protected:
655  PBoolean OnOpen();
656 
657  // Member variables
660 };
661 
662 
675 class PPOP3Server : public PPOP3
676 {
678 
679  public:
686  PPOP3Server();
687 
688 
689  // New functions for class.
698 
708  virtual PBoolean HandleOpenMailbox(
709  const PString & username,
710  const PString & password
711  );
712 
720  virtual void HandleSendMessage(
721  PINDEX messageNumber,
722  const PString & id,
723  PINDEX lines
724  );
725 
733  virtual void HandleDeleteMessage(
734  PINDEX messageNumber,
735  const PString & id
736  );
737 
738 
739  protected:
740  PBoolean OnOpen();
741 
742  virtual void OnUSER(
743  const PString & name
744  );
745  // Specify user name (mailbox).
746 
747  virtual void OnPASS(
748  const PString & passwd
749  );
750  // Specify password and log user in.
751 
752  virtual void OnQUIT();
753  // End connection, saving all changes (delete messages).
754 
755  virtual void OnRSET();
756  // Reset connection (undelete messages).
757 
758  virtual void OnNOOP();
759  // Do nothing.
760 
761  virtual void OnSTAT();
762  // Get number of messages in mailbox.
763 
767  virtual void OnLIST(
768  PINDEX msg
769  );
770 
771  virtual void OnRETR(
772  PINDEX msg
773  );
774  // Retrieve a message from mailbox.
775 
776  virtual void OnDELE(
777  PINDEX msg
778  );
779  // Delete a message from mailbox.
780 
781  virtual void OnTOP(
782  PINDEX msg,
783  PINDEX count
784  );
785  // Get the message header and top <CODE>count</CODE> lines of message.
786 
790  virtual void OnUIDL(
791  PINDEX msg
792  );
793 
800  virtual PBoolean OnUnknown(
801  const PCaselessString & command
802  );
803 
804 
805  // Member variables
810 };
811 
812 
839 {
840  PCLASSINFO(PRFC822Channel, PIndirectChannel);
841  public:
842  enum Direction {
845  };
849  Direction direction
850  );
851 
854  ~PRFC822Channel();
855 
856 
857  // Overrides from class PChannel.
862  PBoolean Close();
863 
872  virtual PBoolean Write(
873  const void * buf,
874  PINDEX len
875  );
876 
877 
882  void NewMessage(
883  Direction direction
884  );
885 
896 
907  const PString & boundary
908  );
909 
920  void NextPart(
921  const PString & boundary
922  );
923 
924 
928  void SetFromAddress(
929  const PString & fromAddress
930  );
931 
935  void SetToAddress(
936  const PString & toAddress
937  );
938 
942  void SetCC(
943  const PString & ccAddress
944  );
945 
949  void SetBCC(
950  const PString & bccAddress
951  );
952 
956  void SetSubject(
957  const PString & subject
958  );
959 
967  void SetContentType(
968  const PString & contentType
969  );
970 
979  const PFilePath & filename
980  );
981 
991  void SetTransferEncoding(
992  const PString & encoding,
993  PBoolean autoTranslate = true
994  );
995 
996 
1000  void SetHeaderField(
1001  const PString & name,
1002  const PString & value
1003  );
1004 
1005  // Common MIME header tags
1006  static const PCaselessString & MimeVersionTag();
1007  static const PCaselessString & FromTag();
1008  static const PCaselessString & ToTag();
1009  static const PCaselessString & CCTag();
1010  static const PCaselessString & BCCTag();
1011  static const PCaselessString & SubjectTag();
1012  static const PCaselessString & DateTag();
1013  static const PCaselessString & ReturnPathTag();
1014  static const PCaselessString & ReceivedTag();
1015  static const PCaselessString & MessageIDTag();
1016  static const PCaselessString & MailerTag();
1020 
1021 
1022  protected:
1023  PBoolean OnOpen();
1024 
1030  PBase64 * base64;
1031 };
1032 
1033 
1034 #endif // PTLIB_INETMAIL_H
1035 
1036 
1037 // End Of File ///////////////////////////////////////////////////////////////
bool writePartHeaders
Definition: inetmail.h:1027
void NewMessage(Direction direction)
Begin a new message.
static const PCaselessString & SubjectTag()
PBoolean eightBitMIME
Definition: inetmail.h:436
Definition: inetmail.h:843
virtual PBoolean HandleMessage(PCharArray &buffer, PBoolean starting, PBoolean completed)
Handle a received message.
static const PCaselessString & ContentTypeTag()
Definition: inetmail.h:493
This class contains the Multipurpose Internet Mail Extensions parameters and variables.
Definition: mime.h:48
bool writeHeaders
Definition: inetmail.h:1025
PString m_subject
Subject of message.
Definition: inetmail.h:99
static const PCaselessString & ContentTransferEncodingTag()
Definition: inetmail.h:1019
Definition: inetmail.h:844
virtual void OnHELO(const PCaselessString &remoteHost)
virtual void OnSTAT()
Allow the use of the plain old USER/PASS if APOP or SASL are not available.
Definition: inetmail.h:581
A TCP/IP socket for the Post Office Protocol version 3.
Definition: inetmail.h:675
virtual void OnEHLO(const PCaselessString &remoteHost)
PUnsignedArray messageSizes
Definition: inetmail.h:807
virtual void OnPASS(const PString &passwd)
Array of characters.
Definition: array.h:552
void SetFromAddress(const PString &fromAddress)
Set the sender address.
Definition: inetmail.h:442
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
static const PString & okResponse()
PSMTPServer()
Create a TCP/IP SMPTP protocol socket channel.
virtual PBoolean OnTextData(PCharArray &buffer, PBoolean &completed)
Read a standard text message that is being received by the socket.
virtual void OnQUIT()
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the channel.
User name was valid but ambiguous.
Definition: inetmail.h:291
PStringList m_bcc
Blind carbon copy list.
Definition: inetmail.h:98
Direction
Definition: inetmail.h:842
virtual void OnMAIL(const PCaselessString &sender)
Definition: inetmail.h:79
static const PCaselessString & MessageIDTag()
PString MultipartMessage()
Enter multipart MIME message mode.
Definition: inetmail.h:79
Definition: inetmail.h:494
void SetContentType(const PString &contentType)
Set the content type.
PString m_password
Password if credentials required.
Definition: inetmail.h:94
void SetHeaderField(const PString &name, const PString &value)
Set the and arbitrary header field.
A channel for sending/receiving RFC822 compliant mail messages.
Definition: inetmail.h:838
virtual void OnDATA()
Definition: inetmail.h:493
virtual void HandleSendMessage(PINDEX messageNumber, const PString &id, PINDEX lines)
Handle the sending of the specified message to the remote client.
PBoolean OnOpen()
This callback is executed when the Open() function is called with open channels.
User name was invalid.
Definition: inetmail.h:292
void SetCC(const PString &ccAddress)
Set the Carbon Copy address(es).
ForwardResult
Definition: inetmail.h:271
Parameters()
Definition: inetmail.h:85
Definition: inetmail.h:494
PINDEX messageBufferSize
Definition: inetmail.h:441
void SetToAddress(const PString &toAddress)
Set the recipient address(es).
Definition: inetmail.h:494
virtual PBoolean OnUnknown(const PCaselessString &command)
Handle an unknown command.
Definition: inetmail.h:77
void SetSubject(const PString &subject)
Set the message subject.
This is a dictionary collection class of PString objects, keyed by another string.
Definition: pstring.h:3151
This class describes a full description for a file on the particular platform.
Definition: filepath.h:61
PStringArray messageIDs
Definition: inetmail.h:808
LoginOptions
Definition: inetmail.h:579
Definition: inetmail.h:77
Definition: inetmail.h:495
static const PCaselessString & ReceivedTag()
This is a channel that operates indirectly through another channel(s).
Definition: indchan.h:45
This class is a variation of a string that ignores case.
Definition: pstring.h:2012
User may be on local machine, do LookUpName().
Definition: inetmail.h:272
PBoolean ProcessCommand()
Process commands, dispatching to the appropriate virtual function.
virtual void OnHELP()
static const PCaselessString & ContentTypeTag()
Definition: inetmail.h:1017
A TCP/IP socket for the Simple Mail Transfer Protocol.
Definition: inetmail.h:69
virtual void OnLIST(PINDEX msg)
Get the size of a message in mailbox.
PBoolean loggedIn
Definition: inetmail.h:658
enum PSMTPServer::@21 sendCommand
static const PCaselessString & ToTag()
static const PCaselessString & CCTag()
Definition: inetmail.h:493
PUnsignedArray GetMessageSizes()
Get an array of a integers representing the sizes of each of the messages in the mail box...
This is an array collection class of PString objects.
Definition: pstring.h:2365
PBYTEArray messageDeletions
Definition: inetmail.h:809
PBoolean OnOpen()
This callback is executed when the Open() function is called with open channels.
Definition: inetmail.h:76
virtual void OnRCPT(const PCaselessString &recipient)
Definition: inetmail.h:76
PMIMEInfo headers
Definition: inetmail.h:1026
Definition: inetmail.h:79
Definition: inetmail.h:77
A TCP/IP socket for the Simple Mail Transfer Protocol.
Definition: inetmail.h:134
~PPOP3Client()
Destroy the channel object.
A TCP/IP socket for process/application layer high level protocols.
Definition: inetprot.h:61
LookUpResult
Definition: inetmail.h:289
PBoolean BeginMessage(PINDEX messageNumber)
bool LogIn(const PString &username, const PString &password)
Log into the SMTP server using the mailbox and access codes specified.
Definition: inetmail.h:494
static const PCaselessString & DateTag()
PStringList m_cc
Carbon copy list.
Definition: inetmail.h:97
~PSMTPClient()
Destroy the channel object.
PPOP3Client()
Create a TCP/IP POP3 protocol socket channel.
virtual void OnSOML(const PCaselessString &sender)
Definition: inetmail.h:493
virtual void OnTURN()
Info sending email.
Definition: inetmail.h:83
Array of unsigned characters.
Definition: array.h:605
static const PCaselessString & MimeVersionTag()
PBoolean LogIn(const PString &username, const PString &password, int options=AllowUserPass)
Log into the POP server using the mailbox and access codes specified.
Definition: inetmail.h:493
Commands
Definition: inetmail.h:75
A TCP/IP socket for the Post Office Protocol version 3.
Definition: inetmail.h:550
Definition: inetmail.h:76
virtual ForwardResult ForwardDomain(PCaselessString &userDomain, PCaselessString &forwardDomainList)
Determine if a user for this domain may be on the local system, or should be forwarded.
virtual PBoolean OnMIMEData(PCharArray &buffer, PBoolean &completed)
Read an eight bit MIME message that is being received by the socket.
virtual PBoolean OnUnknown(const PCaselessString &command)
Handle an unknown command.
static const PCaselessString & ContentDispositionTag()
Definition: inetmail.h:493
virtual void HandleDeleteMessage(PINDEX messageNumber, const PString &id)
Handle the deleting of the specified message from the mail box.
PStringList m_toNames
Definition: inetmail.h:208
User may be forwarded to another SMTP host.
Definition: inetmail.h:273
PSMTPClient()
Create a TCP/IP SMPTP protocol socket channel.
Definition: inetmail.h:77
~PRFC822Channel()
Close the channel before destruction.
virtual PBoolean Close()
Close the socket, and if connected as a client, QUITs from server.
static const PCaselessString & ContentTransferEncodingTag()
virtual void OnEXPN(const PCaselessString &name)
void SetContentAttachment(const PFilePath &filename)
Set the content disposition for attachments.
bool PBoolean
Definition: object.h:174
PStringArray GetMessageHeaders()
Get an array of a strings representing the standard internet message headers of each of the messages ...
virtual PINDEX ParseResponse(const PString &line)
Parse a response line string into a response code and any extra info on the line. ...
static const PCaselessString & FromTag()
bool BeginMessage(const PString &from, const PString &to, PBoolean eightBitMIME=false)
Begin transmission of a message using the SMTP socket as a client.
Definition: inetmail.h:76
A TCP/IP socket for the Post Office Protocol version 3.
Definition: inetmail.h:487
virtual void OnDELE(PINDEX msg)
PPOP3Server()
Create a TCP/IP POP3 protocol socket channel.
PRFC822Channel(Direction direction)
Construct a RFC822 aware channel.
PBoolean Close()
Close the channel.
void NextPart(const PString &boundary)
Indicate that a new multipart message part is to begin.
The character string class.
Definition: pstring.h:108
Definition: inetmail.h:494
Definition: inetmail.h:78
static const PString & errResponse()
PString fromPath
Definition: inetmail.h:438
Use SASL if the AUTH command is supported by the server.
Definition: inetmail.h:583
PString m_fromAddress
Definition: inetmail.h:207
virtual void OnSEND(const PCaselessString &sender)
PStringList m_attachments
List of files to attach.
Definition: inetmail.h:101
bool m_haveHello
Definition: inetmail.h:205
PBoolean OnOpen()
This callback is executed when the Open() function is called with open channels.
Allow LOGIN and PLAIN mechanisms to be used.
Definition: inetmail.h:585
virtual PBoolean HandleOpenMailbox(const PString &username, const PString &password)
Log the specified user into the mail system and return sizes of each message in mail box...
This is a list collection class of PString objects.
Definition: pstring.h:2562
PString username
Definition: inetmail.h:806
User cannot be forwarded.
Definition: inetmail.h:274
static const PCaselessString & ReturnPathTag()
Definition: inetmail.h:442
static bool SendMail(const Parameters &params, PString &error)
Make a TCP/TLS connection and send the simple mail message.
virtual void OnNOOP()
void SetTransferEncoding(const PString &encoding, PBoolean autoTranslate=true)
Set the content transfer encoding.
PBoolean extendedHello
Definition: inetmail.h:435
virtual LookUpResult LookUpName(const PCaselessString &name, PString &expandedName)
Look up a name in the context of the SMTP server.
PString m_username
Username of credentials required.
Definition: inetmail.h:93
PBoolean DeleteMessage(PINDEX messageNumber)
Delete the message specified from the mail box.
PStringList toNames
Definition: inetmail.h:439
Definition: inetmail.h:78
PString m_bodyText
Body for message, if text.
Definition: inetmail.h:100
A TCP/IP socket for the Simple Mail Transfer Protocol.
Definition: inetmail.h:244
virtual void OnRSET()
Definition: inetmail.h:78
void ServerReset()
bool m_eightBitMIME
Eight bit MIME more.
Definition: inetmail.h:102
Some other error occurred in look up.
Definition: inetmail.h:293
Definition: inetmail.h:442
Definition: inetmail.h:78
StuffState endMIMEDetectState
Definition: inetmail.h:443
virtual void OnUIDL(PINDEX msg)
Get unique ID for message in mailbox.
virtual void OnSAML(const PCaselessString &sender)
virtual void OnSendMail(const PCaselessString &sender)
PStringToString m_extensions
Definition: inetmail.h:206
PString fromAddress
Definition: inetmail.h:437
PStringList toDomains
Definition: inetmail.h:440
static const PCaselessString & BCCTag()
Definition: inetmail.h:494
PString m_hostname
SMTP server host name.
Definition: inetmail.h:91
User name was valid and unique.
Definition: inetmail.h:290
StuffState
Definition: inetprot.h:392
void SetBCC(const PString &bccAddress)
Set the Blind Carbon Copy address(es).
virtual void OnQUIT()
static const PCaselessString & MailerTag()
PString m_from
Mail address of sender.
Definition: inetmail.h:95
PStringList m_to
Mail address of recipient.
Definition: inetmail.h:96
PBoolean OnOpen()
This callback is executed when the Open() function is called with open channels.
virtual void OnNOOP()
WORD m_port
SMTP port, zero is default for protocol.
Definition: inetmail.h:92
PMIMEInfo partHeaders
Definition: inetmail.h:1028
PBase64 * base64
Definition: inetmail.h:1030
A network communications channel.
Definition: socket.h:59
PBoolean ProcessCommand()
Process commands, dispatching to the appropriate virtual function.
PString apopBanner
Definition: inetmail.h:659
Definition: inetmail.h:77
bool m_sendingData
Definition: inetmail.h:209
Definition: inetmail.h:78
Definition: inetmail.h:76
virtual void OnRETR(PINDEX msg)
int GetMessageCount()
Get a count of the number of messages in the mail box.
virtual void OnUSER(const PString &name)
static const PCaselessString & ContentDispositionTag()
Definition: inetmail.h:1018
Commands
Definition: inetmail.h:492
Definition: inetmail.h:442
virtual void OnTOP(PINDEX msg, PINDEX count)
virtual void OnVRFY(const PCaselessString &name)
Definition: inetmail.h:495
virtual void OnRSET()
PBoolean OnOpen()
This callback is executed when the Open() function is called with open channels.
PStringList boundaries
Definition: inetmail.h:1029
virtual PBoolean Close()
Close the socket, and if connected as a client, QUITs from server.
PBoolean EndMessage()
End transmission of a message using the SMTP socket as a client.