1 /* BMailMessage - compatibility wrapper to our mail message class
3 ** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
7 //------This entire document is a horrible, horrible hack. I apologize.
10 class _EXPORT BMailMessage
;
14 #include <MailAttachment.h>
15 #include <MailMessage.h>
20 struct CharsetConversionEntry
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
);
49 ((BEmailMessage
*)(fFields
))->AddComponent(comp
);
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
;
73 comp
->SetEncoding(quoted_printable
,encode
);
76 ((BEmailMessage
*)(fFields
))->AddComponent(comp
);
81 status_t
BMailMessage::AddEnclosure(entry_ref
*ref
, bool /*clobber*/)
83 ((BEmailMessage
*)(fFields
))->Attach(ref
);
87 status_t
BMailMessage::AddEnclosure(const char *path
, bool /*clobber*/)
91 if ((status
= entry
.InitCheck()) < B_OK
)
95 if ((status
= entry
.GetRef(&ref
)) < B_OK
)
98 ((BEmailMessage
*)(fFields
))->Attach(&ref
);
102 status_t
BMailMessage::AddEnclosure(const char *MIME_type
, void *data
, int32 len
,
105 BSimpleMailAttachment
*attach
= new BSimpleMailAttachment
;
106 attach
->SetDecodedData(data
,len
);
107 attach
->SetHeaderField("Content-Type",MIME_type
);
109 ((BEmailMessage
*)(fFields
))->AddComponent(attach
);
113 status_t
BMailMessage::AddHeaderField(uint32
/*encoding*/, const char *field_name
, const char *str
,
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
);
124 status_t
BMailMessage::AddHeaderField(const char *field_name
, const char *str
,
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
);
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
);