1 /* 2 * Copyright 2007-2012, Haiku Inc. All Rights Reserved. 3 * Copyright 2001, Dr. Zoidberg Enterprises. All rights reserved. 4 * 5 * Distributed under the terms of the MIT License. 6 */ 7 #ifndef _MAIL_MESSAGE_H_ 8 #define _MAIL_MESSAGE_H_ 9 10 11 //! The main general purpose mail message class 12 13 14 #include <MailContainer.h> 15 16 17 // add our additional attributes 18 #define B_MAIL_ATTR_ACCOUNT "MAIL:account" 19 #define B_MAIL_ATTR_THREAD "MAIL:thread" 20 21 22 class BDirectory; 23 class BEntry; 24 25 26 enum mail_reply_to_mode { 27 B_MAIL_REPLY_TO = 0, 28 B_MAIL_REPLY_TO_ALL, 29 B_MAIL_REPLY_TO_SENDER 30 }; 31 32 33 class BEmailMessage : public BMailContainer { 34 public: 35 BEmailMessage(BPositionIO* stream = NULL, 36 bool ownStream = false, 37 uint32 defaultCharSet 38 = B_MAIL_NULL_CONVERSION); 39 BEmailMessage(const entry_ref* ref, 40 uint32 defaultCharSet 41 = B_MAIL_NULL_CONVERSION); 42 virtual ~BEmailMessage(); 43 44 status_t InitCheck() const; 45 BPositionIO* Data() const { return fData; } 46 // is only set if the message owns the data 47 48 BEmailMessage* ReplyMessage(mail_reply_to_mode replyTo, 49 bool accountFromMail, 50 const char* quoteStyle = "> "); 51 BEmailMessage* ForwardMessage(bool accountFromMail, 52 bool includeAttachments = false); 53 // These return messages with the body quoted and 54 // ready to send via the appropriate channel. ReplyMessage() 55 // addresses the message appropriately, but ForwardMessage() 56 // leaves it unaddressed. 57 58 const char* To() const; 59 const char* From() const; 60 const char* ReplyTo() const; 61 const char* CC() const; 62 const char* Subject() const; 63 time_t Date() const; 64 int Priority() const; 65 66 void SetSubject(const char* to, 67 uint32 charset = B_MAIL_NULL_CONVERSION, 68 mail_encoding encoding = null_encoding); 69 void SetReplyTo(const char* to, 70 uint32 charset = B_MAIL_NULL_CONVERSION, 71 mail_encoding encoding = null_encoding); 72 void SetFrom(const char* to, 73 uint32 charset = B_MAIL_NULL_CONVERSION, 74 mail_encoding encoding = null_encoding); 75 void SetTo(const char* to, 76 uint32 charset = B_MAIL_NULL_CONVERSION, 77 mail_encoding encoding = null_encoding); 78 void SetCC(const char* to, 79 uint32 charset = B_MAIL_NULL_CONVERSION, 80 mail_encoding encoding = null_encoding); 81 void SetBCC(const char* to); 82 void SetPriority(int to); 83 84 status_t GetName(char* name, int32 maxLength) const; 85 status_t GetName(BString* name) const; 86 87 void SendViaAccountFrom(BEmailMessage* message); 88 void SendViaAccount(const char* accountName); 89 void SendViaAccount(int32 account); 90 int32 Account() const; 91 status_t GetAccountName(BString& accountName) const; 92 93 virtual status_t AddComponent(BMailComponent *component); 94 virtual status_t RemoveComponent(BMailComponent *component); 95 virtual status_t RemoveComponent(int32 index); 96 97 virtual BMailComponent* GetComponent(int32 index, 98 bool parseNow = false); 99 virtual int32 CountComponents() const; 100 101 void Attach(entry_ref* ref, 102 bool includeAttributes = true); 103 bool IsComponentAttachment(int32 index); 104 105 void SetBodyTextTo(const char* text); 106 const char* BodyText(); 107 108 status_t SetBody(BTextMailComponent* body); 109 BTextMailComponent* Body(); 110 111 virtual status_t SetToRFC822(BPositionIO* data, size_t length, 112 bool parseNow = false); 113 virtual status_t RenderToRFC822(BPositionIO* renderTo); 114 115 status_t RenderTo(BDirectory* dir, 116 BEntry* message = NULL); 117 // Message will be set to the message file if not equal to NULL 118 119 status_t Send(bool sendNow); 120 121 private: 122 BTextMailComponent* _RetrieveTextBody(BMailComponent* component); 123 124 virtual void _ReservedMessage1(); 125 virtual void _ReservedMessage2(); 126 virtual void _ReservedMessage3(); 127 128 private: 129 BPositionIO* fData; 130 131 status_t fStatus; 132 int32 fAccountID; 133 char* fBCC; 134 135 int32 fComponentCount; 136 BMailComponent* fBody; 137 BTextMailComponent* fTextBody; 138 139 uint32 _reserved[5]; 140 }; 141 142 143 #endif // _MAIL_MESSAGE_H_ 144