xref: /haiku/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.h (revision bab64f65bb775dc23060e276f1f1c4498ab7af6c)
1 /*
2  * Copyright 2007-2016, 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 
39 			status_t			Retrieve(int32 message, BPositionIO* to);
40 			status_t			GetHeader(int32 message, BPositionIO* to);
41 			void				Delete(int32 index);
42 
43 protected:
44 	virtual	status_t			HandleFetchBody(const entry_ref& ref,
45 									const BMessenger& replyTo);
46 
47 			// pop3 methods
48 			status_t			Open(const char* server, int port,
49 									int protocol);
50 			status_t			Login(const char* uid, const char* password,
51 									int method);
52 
53 			size_t				MessageSize(int32 index);
54 			status_t			Stat();
55 			int32				Messages(void);
56 			size_t				MailDropSize(void);
57 			void				CheckForDeletedMessages();
58 
59 			status_t			RetrieveInternal(const char* command,
60 									int32 message, BPositionIO* to,
61 									bool showProgress);
62 
63 			ssize_t				ReceiveLine(BString& line);
64 			status_t			SendCommand(const char* cmd);
65 			void				MD5Digest(unsigned char* in, char* out);
66 
67 private:
68 			status_t			_RetrieveUniqueIDs();
69 			void				_ReadManifest();
70 			void				_WriteManifest();
71 
72 private:
73 			BString				fLog;
74 			int32				fNumMessages;
75 			size_t				fMailDropSize;
76 			std::vector<size_t>	fSizes;
77 			off_t				fTotalSize;
78 			BMessage			fSettings;
79 
80 			BStringList			fManifest;
81 			BStringList			fUniqueIDs;
82 
83 			BString				fDestinationDir;
84 			int32				fFetchBodyLimit;
85 
86 			BSocket*			fServerConnection;
87 			bool				fUseSSL;
88 };
89 
90 
91 extern "C" status_t pop3_smtp_auth(const BMailAccountSettings& settings);
92 
93 
94 #endif	/* POP3_H */
95