xref: /haiku/headers/os/mail/MailMessage.h (revision fa84ff9eb17c6fc1fb438788995504d0d827d791)
1 #ifndef ZOIDBERG_MAIL_MESSAGE_H
2 #define ZOIDBERG_MAIL_MESSAGE_H
3 /* Message - the main general purpose mail message class
4 **
5 ** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
6 */
7 
8 
9 #include <MailContainer.h>
10 
11 
12 // add our additional attributes
13 #define B_MAIL_ATTR_ACCOUNT "MAIL:account"
14 #define B_MAIL_ATTR_THREAD "MAIL:thread"
15 
16 
17 class BDirectory;
18 
19 enum mail_reply_to_mode {
20 	B_MAIL_REPLY_TO = 0,
21 	B_MAIL_REPLY_TO_ALL,
22 	B_MAIL_REPLY_TO_SENDER
23 };
24 
25 class BEmailMessage : public BMailContainer {
26 	public:
27 		BEmailMessage(BPositionIO *mail_file = NULL, bool own = false, uint32 defaultCharSet = B_MAIL_NULL_CONVERSION);
28 		BEmailMessage(entry_ref *ref, uint32 defaultCharSet = B_MAIL_NULL_CONVERSION);
29 		virtual ~BEmailMessage();
30 
31 		status_t InitCheck() const;
32 		BPositionIO *Data() const { return fData; }
33 			// is only set if the message owns the data
34 
35 		BEmailMessage *ReplyMessage(mail_reply_to_mode replyTo, bool accountFromMail, const char *quote_style = "> ");
36 		BEmailMessage *ForwardMessage(bool accountFromMail, bool includeAttachments = false);
37 			// These return messages with the body quoted and
38 			// ready to send via the appropriate channel. ReplyMessage()
39 			// addresses the message appropriately, but ForwardMessage()
40 			// leaves it unaddressed.
41 
42 		const char *To();
43 		const char *From();
44 		const char *ReplyTo();
45 		const char *CC();
46 		const char *Subject();
47 		const char *Date();
48 		int Priority();
49 
50 		void SetSubject(const char *to, uint32 charset = B_MAIL_NULL_CONVERSION, mail_encoding encoding = null_encoding);
51 		void SetReplyTo(const char *to, uint32 charset = B_MAIL_NULL_CONVERSION, mail_encoding encoding = null_encoding);
52 		void SetFrom(const char *to, uint32 charset = B_MAIL_NULL_CONVERSION, mail_encoding encoding = null_encoding);
53 		void SetTo(const char *to, uint32 charset = B_MAIL_NULL_CONVERSION, mail_encoding encoding = null_encoding);
54 		void SetCC(const char *to, uint32 charset = B_MAIL_NULL_CONVERSION, mail_encoding encoding = null_encoding);
55 		void SetBCC(const char *to);
56 		void SetPriority(int to);
57 
58 		status_t GetName(char *name,int32 maxLength) const;
59 		status_t GetName(BString *name) const;
60 
61 		void SendViaAccountFrom(BEmailMessage *message);
62 		void SendViaAccount(const char *account_name);
63 		void SendViaAccount(int32 chain_id);
64 		int32 Account() const;
65 		status_t GetAccountName(char *account,int32 maxLength) const;
66 		status_t GetAccountName(BString *account) const;
67 
68 		virtual status_t AddComponent(BMailComponent *component);
69 		virtual status_t RemoveComponent(BMailComponent *component);
70 		virtual status_t RemoveComponent(int32 index);
71 
72 		virtual BMailComponent *GetComponent(int32 index, bool parse_now = false);
73 		virtual int32 CountComponents() const;
74 
75 		void Attach(entry_ref *ref, bool include_attributes = true);
76 		bool IsComponentAttachment(int32 index);
77 
78 		void SetBodyTextTo(const char *text);
79 		const char *BodyText();
80 
81 		status_t SetBody(BTextMailComponent *body);
82 		BTextMailComponent *Body();
83 
84 		virtual status_t SetToRFC822(BPositionIO *data, size_t length, bool parse_now = false);
85 		virtual status_t RenderToRFC822(BPositionIO *render_to);
86 
87 		status_t RenderTo(BDirectory *dir, BEntry *message = NULL);
88 			//---message will be set to the message file if not equal to NULL
89 
90 		status_t Send(bool send_now);
91 
92 	private:
93 		BTextMailComponent *RetrieveTextBody(BMailComponent *);
94 
95 		virtual void _ReservedMessage1();
96 		virtual void _ReservedMessage2();
97 		virtual void _ReservedMessage3();
98 
99 		BPositionIO *fData;
100 
101 		status_t _status;
102 		int32 _chain_id;
103 		char *_bcc;
104 
105 		int32 _num_components;
106 		BMailComponent *_body;
107 		BTextMailComponent *_text_body;
108 
109 		uint32 _reserved[5];
110 };
111 
112 #endif	/* ZOIDBERG_MAIL_MESSAGE_H */
113