PTLib
Version 2.14.3
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
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
* $Revision: 25390 $
28
* $Author: rjongbloed $
29
* $Date: 2011-03-23 15:07:32 +1100 (Wed, 23 Mar 2011) $
30
*/
31
32
#ifndef PTLIB_INETMAIL_H
33
#define PTLIB_INETMAIL_H
34
35
#ifdef P_USE_PRAGMA
36
#pragma interface
37
#endif
38
39
#include <
ptclib/inetprot.h
>
40
#include <
ptclib/mime.h
>
41
42
class
PSocket
;
43
44
46
// PSMTP
47
73
class
PSMTP
:
public
PInternetProtocol
74
{
75
PCLASSINFO
(
PSMTP
,
PInternetProtocol
)
76
77
public
:
78
// New functions for class.
79
enum
Commands
{
80
HELO
,
EHLO
,
QUIT
,
HELP
,
NOOP
,
81
TURN
,
RSET
,
VRFY
,
EXPN
,
RCPT
,
82
MAIL
,
SEND
,
SAML
,
SOML
,
DATA
,
83
AUTH
,
NumCommands
84
};
85
86
protected
:
87
PSMTP
();
88
// Create a new SMTP protocol channel.
89
};
90
91
108
class
PSMTPClient
:
public
PSMTP
109
{
110
PCLASSINFO
(
PSMTPClient
,
PSMTP
)
111
112
public
:
119
PSMTPClient
();
120
124
~PSMTPClient
();
125
126
127
// Overrides from class PChannel.
133
virtual
PBoolean
Close
();
134
135
136
// New functions for class.
144
PBoolean
LogIn
(
145
const
PString
& username,
146
const
PString
& password
147
);
148
157
PBoolean
BeginMessage
(
158
const
PString
& from,
159
const
PString
& to,
160
PBoolean
eightBitMIME
=
false
161
);
162
PBoolean
BeginMessage
(
163
const
PString
& from,
164
const
PStringList
& toList,
165
PBoolean
eightBitMIME
=
false
166
);
167
173
PBoolean
EndMessage
();
174
175
176
protected
:
177
PBoolean
OnOpen
();
178
179
PBoolean
haveHello
;
180
PBoolean
extendedHello
;
181
PBoolean
eightBitMIME
;
182
PString
fromAddress
;
183
PStringList
toNames
;
184
PBoolean
sendingData
;
185
186
private
:
187
bool
InternalBeginMessage();
188
};
189
190
216
class
PSMTPServer
:
public
PSMTP
217
{
218
PCLASSINFO
(
PSMTPServer
,
PSMTP
)
219
220
public
:
227
PSMTPServer
();
228
229
230
// New functions for class.
238
PBoolean
ProcessCommand
();
239
240
void
ServerReset
();
241
// Reset the state of the SMTP server socket.
242
243
enum
ForwardResult
{
244
LocalDomain
,
245
WillForward
,
246
CannotForward
247
};
248
// Result of forward check
249
256
virtual
ForwardResult
ForwardDomain
(
257
PCaselessString
& userDomain,
258
PCaselessString
& forwardDomainList
259
);
260
261
enum
LookUpResult
{
262
ValidUser
,
263
AmbiguousUser
,
264
UnknownUser
,
265
LookUpError
266
};
267
// Result of user name look up
268
276
virtual
LookUpResult
LookUpName
(
277
const
PCaselessString
& name,
278
PString
& expandedName
279
);
280
290
virtual
PBoolean
HandleMessage
(
291
PCharArray
& buffer,
292
PBoolean
starting,
293
PBoolean
completed
294
295
);
296
297
298
protected
:
299
PBoolean
OnOpen
();
300
301
virtual
void
OnHELO
(
302
const
PCaselessString
& remoteHost
303
);
304
// Start connection.
305
306
virtual
void
OnEHLO
(
307
const
PCaselessString
& remoteHost
308
);
309
// Start extended SMTP connection.
310
311
virtual
void
OnQUIT
();
312
// close connection and die.
313
314
virtual
void
OnHELP
();
315
// get help.
316
317
virtual
void
OnNOOP
();
318
// do nothing
319
320
virtual
void
OnTURN
();
321
// switch places
322
323
virtual
void
OnRSET
();
324
// Reset state.
325
326
virtual
void
OnVRFY
(
327
const
PCaselessString
& name
328
);
329
// Verify address.
330
331
virtual
void
OnEXPN
(
332
const
PCaselessString
& name
333
);
334
// Expand alias.
335
336
virtual
void
OnRCPT
(
337
const
PCaselessString
& recipient
338
);
339
// Designate recipient
340
341
virtual
void
OnMAIL
(
342
const
PCaselessString
& sender
343
);
344
// Designate sender
345
346
virtual
void
OnSEND
(
347
const
PCaselessString
& sender
348
);
349
// send message to screen
350
351
virtual
void
OnSAML
(
352
const
PCaselessString
& sender
353
);
354
// send AND mail
355
356
virtual
void
OnSOML
(
357
const
PCaselessString
& sender
358
);
359
// send OR mail
360
361
virtual
void
OnDATA
();
362
// Message text.
363
370
virtual
PBoolean
OnUnknown
(
371
const
PCaselessString
& command
372
);
373
374
virtual
void
OnSendMail
(
375
const
PCaselessString
& sender
376
);
377
// Common code for OnMAIL(), OnSEND(), OnSOML() and OnSAML() funtions.
378
390
virtual
PBoolean
OnTextData
(
PCharArray
& buffer,
PBoolean
& completed);
391
403
virtual
PBoolean
OnMIMEData
(
PCharArray
& buffer,
PBoolean
& completed);
404
405
406
// Member variables
407
PBoolean
extendedHello
;
408
PBoolean
eightBitMIME
;
409
PString
fromAddress
;
410
PString
fromPath
;
411
PStringList
toNames
;
412
PStringList
toDomains
;
413
PINDEX
messageBufferSize
;
414
enum
{
WasMAIL
,
WasSEND
,
WasSAML
,
WasSOML
}
sendCommand
;
415
StuffState
endMIMEDetectState
;
416
};
417
418
420
// PPOP3
421
459
class
PPOP3
:
public
PInternetProtocol
460
{
461
PCLASSINFO
(
PPOP3
,
PInternetProtocol
)
462
463
public
:
464
enum
Commands
{
465
USER
,
PASS
,
QUIT
,
RSET
,
NOOP
,
STATcmd
,
466
LIST
,
RETR
,
DELE
,
APOP
,
TOP
,
UIDL
,
467
AUTH
,
NumCommands
468
};
469
470
471
protected
:
472
PPOP3
();
473
485
virtual
PINDEX
ParseResponse
(
486
const
PString
& line
487
);
488
489
// Member variables
490
static
const
PString
&
okResponse
();
491
static
const
PString
&
errResponse
();
492
};
493
494
522
class
PPOP3Client
:
public
PPOP3
523
{
524
PCLASSINFO
(
PPOP3Client
,
PPOP3
)
525
526
public
:
533
PPOP3Client
();
534
538
~PPOP3Client
();
539
540
541
// Overrides from class PChannel.
547
virtual
PBoolean
Close
();
548
549
550
// New functions for class.
551
enum
LoginOptions
552
{
553
AllowUserPass
= 1,
554
555
UseSASL
= 2,
556
557
AllowClearTextSASL
= 4
558
};
559
565
PBoolean
LogIn
(
566
const
PString
& username,
567
const
PString
& password,
568
int
options =
AllowUserPass
569
);
570
576
int
GetMessageCount
();
577
584
PUnsignedArray
GetMessageSizes
();
585
595
PStringArray
GetMessageHeaders
();
596
597
598
/* Begin the retrieval of an entire message. The application may then use
599
the <A>PApplicationSocket::ReadLine()</A> function with the
600
<CODE>unstuffLine</CODE> parameter set to true. Repeated calls until
601
its return valus is false will read the message headers and body.
602
603
@return
604
Array of strings continaing message headers.
605
*/
606
PBoolean
BeginMessage
(
607
PINDEX messageNumber
611
);
612
618
PBoolean
DeleteMessage
(
619
PINDEX messageNumber
620
/* Number of message to retrieve. This is an integer from 1 to the
621
maximum number of messages available.
622
*/
623
);
624
625
626
protected
:
627
PBoolean
OnOpen
();
628
629
// Member variables
630
PBoolean
loggedIn
;
631
PString
apopBanner
;
632
};
633
634
647
class
PPOP3Server
:
public
PPOP3
648
{
649
PCLASSINFO
(
PPOP3Server
,
PPOP3
)
650
651
public
:
658
PPOP3Server
();
659
660
661
// New functions for class.
669
PBoolean
ProcessCommand
();
670
680
virtual
PBoolean
HandleOpenMailbox
(
681
const
PString
&
username
,
682
const
PString
& password
683
);
684
692
virtual
void
HandleSendMessage
(
693
PINDEX messageNumber,
694
const
PString
&
id
,
695
PINDEX lines
696
);
697
705
virtual
void
HandleDeleteMessage
(
706
PINDEX messageNumber,
707
const
PString
&
id
708
);
709
710
711
protected
:
712
PBoolean
OnOpen
();
713
714
virtual
void
OnUSER
(
715
const
PString
& name
716
);
717
// Specify user name (mailbox).
718
719
virtual
void
OnPASS
(
720
const
PString
& passwd
721
);
722
// Specify password and log user in.
723
724
virtual
void
OnQUIT
();
725
// End connection, saving all changes (delete messages).
726
727
virtual
void
OnRSET
();
728
// Reset connection (undelete messages).
729
730
virtual
void
OnNOOP
();
731
// Do nothing.
732
733
virtual
void
OnSTAT
();
734
// Get number of messages in mailbox.
735
739
virtual
void
OnLIST
(
740
PINDEX msg
741
);
742
743
virtual
void
OnRETR
(
744
PINDEX msg
745
);
746
// Retrieve a message from mailbox.
747
748
virtual
void
OnDELE
(
749
PINDEX msg
750
);
751
// Delete a message from mailbox.
752
753
virtual
void
OnTOP
(
754
PINDEX msg,
755
PINDEX count
756
);
757
// Get the message header and top <CODE>count</CODE> lines of message.
758
762
virtual
void
OnUIDL
(
763
PINDEX msg
764
);
765
772
virtual
PBoolean
OnUnknown
(
773
const
PCaselessString
& command
774
);
775
776
777
// Member variables
778
PString
username
;
779
PUnsignedArray
messageSizes
;
780
PStringArray
messageIDs
;
781
PBYTEArray
messageDeletions
;
782
};
783
784
810
class
PRFC822Channel
:
public
PIndirectChannel
811
{
812
PCLASSINFO(
PRFC822Channel
,
PIndirectChannel
);
813
public
:
814
enum
Direction
{
815
Sending
,
816
Receiving
817
};
820
PRFC822Channel
(
821
Direction
direction
822
);
823
826
~PRFC822Channel
();
827
828
829
// Overrides from class PChannel.
834
PBoolean
Close
();
835
844
virtual
PBoolean
Write
(
845
const
void
* buf,
846
PINDEX len
847
);
848
849
854
void
NewMessage
(
855
Direction
direction
856
);
857
867
PString
MultipartMessage
();
868
878
PBoolean
MultipartMessage
(
879
const
PString
& boundary
880
);
881
892
void
NextPart
(
893
const
PString
& boundary
894
);
895
896
900
void
SetFromAddress
(
901
const
PString
& fromAddress
902
);
903
907
void
SetToAddress
(
908
const
PString
& toAddress
909
);
910
914
void
SetCC
(
915
const
PString
& ccAddress
916
);
917
921
void
SetBCC
(
922
const
PString
& bccAddress
923
);
924
928
void
SetSubject
(
929
const
PString
& subject
930
);
931
939
void
SetContentType
(
940
const
PString
& contentType
941
);
942
950
void
SetContentAttachment
(
951
const
PFilePath
& filename
952
);
953
963
void
SetTransferEncoding
(
964
const
PString
& encoding,
965
PBoolean
autoTranslate =
true
966
);
967
968
972
void
SetHeaderField
(
973
const
PString
& name,
974
const
PString
& value
975
);
976
977
// Common MIME header tags
978
static
const
PCaselessString
&
MimeVersionTag
();
979
static
const
PCaselessString
&
FromTag
();
980
static
const
PCaselessString
&
ToTag
();
981
static
const
PCaselessString
&
CCTag
();
982
static
const
PCaselessString
&
BCCTag
();
983
static
const
PCaselessString
&
SubjectTag
();
984
static
const
PCaselessString
&
DateTag
();
985
static
const
PCaselessString
&
ReturnPathTag
();
986
static
const
PCaselessString
&
ReceivedTag
();
987
static
const
PCaselessString
&
MessageIDTag
();
988
static
const
PCaselessString
&
MailerTag
();
989
static
const
PCaselessString
&
ContentTypeTag
() {
return
PMIMEInfo::ContentTypeTag
(); }
990
static
const
PCaselessString
&
ContentDispositionTag
() {
return
PMIMEInfo::ContentDispositionTag
(); }
991
static
const
PCaselessString
&
ContentTransferEncodingTag
() {
return
PMIMEInfo::ContentTransferEncodingTag
(); }
992
997
PBoolean
SendWithSMTP
(
998
const
PString
& hostname
999
);
1000
1005
PBoolean
SendWithSMTP
(
1006
PSMTPClient
* smtp
1007
);
1008
1009
1010
protected
:
1011
PBoolean
OnOpen
();
1012
1013
PBoolean
writeHeaders
;
1014
PMIMEInfo
headers
;
1015
PBoolean
writePartHeaders
;
1016
PMIMEInfo
partHeaders
;
1017
PStringList
boundaries
;
1018
PBase64
*
base64
;
1019
};
1020
1021
1022
#endif // PTLIB_INETMAIL_H
1023
1024
1025
// End Of File ///////////////////////////////////////////////////////////////
include
ptclib
inetmail.h
Generated on Fri Oct 10 2014 21:15:13 for PTLib by
1.8.3.1