BPicture: Fix archive constructor.
[haiku.git] / src / kits / mail / b_mail_message.cpp
blob42a40b70ec9a6af99b50a03b4264cb91d77a4938
1 /* BMailMessage - compatibility wrapper to our mail message class
2 **
3 ** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
4 */
7 //------This entire document is a horrible, horrible hack. I apologize.
8 #include <Entry.h>
10 class _EXPORT BMailMessage;
12 #include <E-mail.h>
14 #include <MailAttachment.h>
15 #include <MailMessage.h>
17 #include <stdio.h>
18 #include <strings.h>
20 struct CharsetConversionEntry
22 const char *charset;
23 uint32 flavor;
26 extern const CharsetConversionEntry mail_charsets[];
29 BMailMessage::BMailMessage(void)
30 : fFields((BList *)(new BEmailMessage()))
34 BMailMessage::~BMailMessage(void)
36 delete ((BEmailMessage *)(fFields));
39 status_t BMailMessage::AddContent(const char *text, int32 length,
40 uint32 encoding, bool /*clobber*/)
42 BTextMailComponent *comp = new BTextMailComponent;
43 BMemoryIO io(text,length);
44 comp->SetDecodedData(&io);
46 comp->SetEncoding(quoted_printable,encoding);
48 //if (clobber)
49 ((BEmailMessage *)(fFields))->AddComponent(comp);
51 return B_OK;
54 status_t BMailMessage::AddContent(const char *text, int32 length,
55 const char *encoding, bool /*clobber*/)
57 BTextMailComponent *comp = new BTextMailComponent();
58 BMemoryIO io(text,length);
59 comp->SetDecodedData(&io);
61 uint32 encode = B_ISO1_CONVERSION;
62 //-----I'm assuming that encoding is one of the RFC charsets
63 //-----there are no docs. Am I right?
64 if (encoding != NULL) {
65 for (int32 i = 0; mail_charsets[i].charset != NULL; i++) {
66 if (strcasecmp(encoding,mail_charsets[i].charset) == 0) {
67 encode = mail_charsets[i].flavor;
68 break;
73 comp->SetEncoding(quoted_printable,encode);
75 //if (clobber)
76 ((BEmailMessage *)(fFields))->AddComponent(comp);
78 return B_OK;
81 status_t BMailMessage::AddEnclosure(entry_ref *ref, bool /*clobber*/)
83 ((BEmailMessage *)(fFields))->Attach(ref);
84 return B_OK;
87 status_t BMailMessage::AddEnclosure(const char *path, bool /*clobber*/)
89 BEntry entry(path);
90 status_t status;
91 if ((status = entry.InitCheck()) < B_OK)
92 return status;
94 entry_ref ref;
95 if ((status = entry.GetRef(&ref)) < B_OK)
96 return status;
98 ((BEmailMessage *)(fFields))->Attach(&ref);
99 return B_OK;
102 status_t BMailMessage::AddEnclosure(const char *MIME_type, void *data, int32 len,
103 bool /*clobber*/)
105 BSimpleMailAttachment *attach = new BSimpleMailAttachment;
106 attach->SetDecodedData(data,len);
107 attach->SetHeaderField("Content-Type",MIME_type);
109 ((BEmailMessage *)(fFields))->AddComponent(attach);
110 return B_OK;
113 status_t BMailMessage::AddHeaderField(uint32 /*encoding*/, const char *field_name, const char *str,
114 bool /*clobber*/)
116 //printf("First AddHeaderField. Args are %s%s\n",field_name,str);
118 BString string = field_name;
119 string.Truncate(string.Length() - 2); //----BMailMessage includes the ": "
120 ((BEmailMessage *)(fFields))->SetHeaderField(string.String(),str);
121 return B_OK;
124 status_t BMailMessage::AddHeaderField(const char *field_name, const char *str,
125 bool /*clobber*/)
127 //printf("Second AddHeaderField. Args are %s%s\n",field_name,str);
128 BString string = field_name;
129 string.Truncate(string.Length() - 2); //----BMailMessage includes the ": "
130 ((BEmailMessage *)(fFields))->SetHeaderField(string.String(),str);
131 return B_OK;
134 status_t BMailMessage::Send(bool send_now,
135 bool /*remove_when_I_have_completed_sending_this_message_to_your_preferred_SMTP_server*/)
137 return ((BEmailMessage *)(fFields))->Send(send_now);