xref: /haiku/headers/os/add-ons/mail_daemon/MailProtocol.h (revision 2f470aec1c92ce6917b8a903e343795dc77af41f)
1 #ifndef ZOIDBERG_MAIL_PROTOCOL_H
2 #define ZOIDBERG_MAIL_PROTOCOL_H
3 /* Protocol - the base class for protocol filters
4 **
5 ** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
6 */
7 
8 
9 #include <OS.h>
10 
11 #include <MailAddon.h>
12 
13 
14 class BHandler;
15 class BStringList;
16 class BMailChainRunner;
17 
18 class BMailProtocol : public BMailFilter
19 {
20   public:
21 	BMailProtocol(BMessage* settings, BMailChainRunner *runner);
22 	// Open a connection based on 'settings'.  'settings' will
23 	// contain a persistent uint32 ChainID field.  At most one
24 	// Protocol per ChainID will exist at a given time.
25 	// The constructor of Mail::Protocol initializes manifest.
26 	// It is your responsibility to fill in unique_ids, *and
27 	// to keep it updated* in the course of whatever nefarious
28 	// things your protocol does.
29 
30 	virtual ~BMailProtocol();
31 	// Close the connection and clean up.   This will be cal-
32 	// led after FetchMessage() or FetchNewMessage() returns
33 	// B_TIMED_OUT or B_ERROR, or when the settings for this
34 	// Protocol are changed.
35 
36 	virtual status_t GetMessage(
37 		const char* uid,
38 		BPositionIO** out_file, BMessage* out_headers,
39 		BPath* out_folder_location
40 	)=0;
41 	// Downloads the message with id uid, writing the message's
42 	// RFC2822 contents to *out_file and storing any headers it
43 	// wants to add other than those from the message itself into
44 	// out_headers.  It may store a path (if this type of account
45 	// supports folders) in *out_folder_location.
46 	//
47 	// Returns B_OK if the message is now available in out_file,
48 	// B_NAME_NOT_FOUND if there is no message with id 'uid' on
49 	// the server, or another error if the connection failed.
50 	//
51 	// B_OK will cause the message to be stored and processed.
52 	// B_NAME_NOT_FOUND will cause appropriate recovery to be
53 	// taken (if such exists) but not cause the connection to
54 	// be terminated.  Any other error will cause anything writen
55 	// to be discarded and and the connection closed.
56 
57 	// OBS:
58 	// The Protocol may replace *out_file with a custom (read-
59 	// only) BPositionIO-derived object that preserves the il-
60 	// lusion that the message is writen to *out_file, but in
61 	// fact only reads from the server and writes to *out_file
62 	// on demand.  This BPositionIO must guarantee that any
63 	// data returned by Read() has also been writen to *out_-
64 	// file.  It must return a read error if reading from the
65 	// network or writing to *out_file fails.
66 	//
67 	// The mail_daemon will delete *out_file before invoking
68 	// FetchMessage() or FetchNewMessage() again.
69 
70 	virtual status_t DeleteMessage(const char* uid)=0;
71 	// Removes the message from the server.  After this, it's
72 	// assumed (but not required) that GetMessage(uid,...)
73 	// et al will fail with B_NAME_NOT_FOUND.
74 
75 			void CheckForDeletedMessages();
76 	// You can call this to trigger a sweep for deleted messages.
77 	// Automatically called at the beginning of the chain.
78 
79 	//------MailFilter calls
80 	virtual status_t ProcessMailMessage
81 	(
82 		BPositionIO** io_message, BEntry* io_entry,
83 		BMessage* io_headers, BPath* io_folder, const char* io_uid
84 	);
85 
86   protected:
87 	BStringList *manifest, *unique_ids;
88   	BMessage *settings;
89 
90 	BMailChainRunner *runner;
91   private:
92   	inline void error_alert(const char *process, status_t error);
93 	virtual void _ReservedProtocol1();
94 	virtual void _ReservedProtocol2();
95 	virtual void _ReservedProtocol3();
96 	virtual void _ReservedProtocol4();
97 	virtual void _ReservedProtocol5();
98 
99 	friend class DeletePass;
100 
101 	BHandler *trash_monitor;
102 	BStringList *uids_on_disk;
103 
104 	uint32 _reserved[3];
105 };
106 
107 #endif // ZOIDBERG_MAIL_PROTOCOL_H
108