xref: /haiku/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.h (revision 81ec973846ea4816c53ed8901822e43c8b06878d)
1 /*
2  * Copyright 2007-2012, Haiku Inc. All Rights Reserved.
3  * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
4  * Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
5  *
6  * Distributed under the terms of the MIT License.
7  */
8 #ifndef POP3_H
9 #define POP3_H
10 
11 
12 #include <map>
13 #include <vector>
14 
15 #include <DataIO.h>
16 #include <List.h>
17 #include <String.h>
18 #include <StringList.h>
19 #include <View.h>
20 
21 #include <MailProtocol.h>
22 #include <MailSettings.h>
23 
24 
25 class BSocket;
26 
27 
28 class POP3Protocol : public BInboundMailProtocol {
29 public:
30 								POP3Protocol(
31 									const BMailAccountSettings& settings);
32 								~POP3Protocol();
33 
34 			status_t			Connect();
35 			status_t			Disconnect();
36 
37 			status_t			SyncMessages();
38 			status_t			FetchBody(const entry_ref& ref);
39 			status_t			DeleteMessage(const entry_ref& ref);
40 
41 			status_t			Retrieve(int32 message, BPositionIO *write_to);
42 			status_t			GetHeader(int32 message, BPositionIO *write_to);
43 			void				Delete(int32 num);
44 
45 protected:
46 			// pop3 methods
47 			status_t			Open(const char *server, int port,
48 									int protocol);
49 			status_t			Login(const char *uid, const char *password,
50 									int method);
51 
52 			size_t				MessageSize(int32 index);
53 			status_t			Stat();
54 			int32				Messages(void);
55 			size_t				MailDropSize(void);
56 			void				CheckForDeletedMessages();
57 
58 			status_t			RetrieveInternal(const char *command,
59 									int32 message, BPositionIO *writeTo,
60 									bool showProgress);
61 
62 			int32				ReceiveLine(BString &line);
63 			status_t			SendCommand(const char* cmd);
64 			void				MD5Digest(unsigned char *in, char *out);
65 
66 private:
67 			status_t			_RetrieveUniqueIDs();
68 			void				_ReadManifest();
69 			void				_WriteManifest();
70 
71 private:
72 			BString				fLog;
73 			int32				fNumMessages;
74 			size_t				fMailDropSize;
75 			BList				fSizes;
76 			BMessage			fSettings;
77 
78 			BStringList			fManifest;
79 			BStringList			fUniqueIDs;
80 
81 			BString				fDestinationDir;
82 			int32				fFetchBodyLimit;
83 
84 			BSocket*			fServerConnection;
85 			bool				fUseSSL;
86 };
87 
88 
89 extern "C" status_t pop3_smtp_auth(const BMailAccountSettings& settings);
90 
91 
92 #endif	/* POP3_H */
93