1 /* BMailMessage - compatibility wrapper to our mail message class 2 ** 3 ** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved. 4 */ 5 6 7 //------This entire document is a horrible, horrible hack. I apologize. 8 #include <Entry.h> 9 10 class _EXPORT BMailMessage; 11 12 #include <E-mail.h> 13 14 #include <MailAttachment.h> 15 #include <MailMessage.h> 16 17 #include <stdio.h> 18 19 struct CharsetConversionEntry 20 { 21 const char *charset; 22 uint32 flavor; 23 }; 24 25 extern const CharsetConversionEntry mail_charsets[]; 26 27 28 BMailMessage::BMailMessage(void) 29 : fFields((BList *)(new BEmailMessage())) 30 { 31 } 32 33 BMailMessage::~BMailMessage(void) 34 { 35 delete ((BEmailMessage *)(fFields)); 36 } 37 38 status_t BMailMessage::AddContent(const char *text, int32 length, 39 uint32 encoding, bool /*clobber*/) 40 { 41 BTextMailComponent *comp = new BTextMailComponent; 42 BMemoryIO io(text,length); 43 comp->SetDecodedData(&io); 44 45 comp->SetEncoding(quoted_printable,encoding); 46 47 //if (clobber) 48 ((BEmailMessage *)(fFields))->AddComponent(comp); 49 50 return B_OK; 51 } 52 53 status_t BMailMessage::AddContent(const char *text, int32 length, 54 const char *encoding, bool /*clobber*/) 55 { 56 BTextMailComponent *comp = new BTextMailComponent(); 57 BMemoryIO io(text,length); 58 comp->SetDecodedData(&io); 59 60 uint32 encode = B_ISO1_CONVERSION; 61 //-----I'm assuming that encoding is one of the RFC charsets 62 //-----there are no docs. Am I right? 63 if (encoding != NULL) { 64 for (int32 i = 0; mail_charsets[i].charset != NULL; i++) { 65 if (strcasecmp(encoding,mail_charsets[i].charset) == 0) { 66 encode = mail_charsets[i].flavor; 67 break; 68 } 69 } 70 } 71 72 comp->SetEncoding(quoted_printable,encode); 73 74 //if (clobber) 75 ((BEmailMessage *)(fFields))->AddComponent(comp); 76 77 return B_OK; 78 } 79 80 status_t BMailMessage::AddEnclosure(entry_ref *ref, bool /*clobber*/) 81 { 82 ((BEmailMessage *)(fFields))->Attach(ref); 83 return B_OK; 84 } 85 86 status_t BMailMessage::AddEnclosure(const char *path, bool /*clobber*/) 87 { 88 BEntry entry(path); 89 status_t status; 90 if ((status = entry.InitCheck()) < B_OK) 91 return status; 92 93 entry_ref ref; 94 if ((status = entry.GetRef(&ref)) < B_OK) 95 return status; 96 97 ((BEmailMessage *)(fFields))->Attach(&ref); 98 return B_OK; 99 } 100 101 status_t BMailMessage::AddEnclosure(const char *MIME_type, void *data, int32 len, 102 bool /*clobber*/) 103 { 104 BSimpleMailAttachment *attach = new BSimpleMailAttachment; 105 attach->SetDecodedData(data,len); 106 attach->SetHeaderField("Content-Type",MIME_type); 107 108 ((BEmailMessage *)(fFields))->AddComponent(attach); 109 return B_OK; 110 } 111 112 status_t BMailMessage::AddHeaderField(uint32 /*encoding*/, const char *field_name, const char *str, 113 bool /*clobber*/) 114 { 115 //printf("First AddHeaderField. Args are %s%s\n",field_name,str); 116 117 BString string = field_name; 118 string.Truncate(string.Length() - 2); //----BMailMessage includes the ": " 119 ((BEmailMessage *)(fFields))->SetHeaderField(string.String(),str); 120 return B_OK; 121 } 122 123 status_t BMailMessage::AddHeaderField(const char *field_name, const char *str, 124 bool /*clobber*/) 125 { 126 //printf("Second AddHeaderField. Args are %s%s\n",field_name,str); 127 BString string = field_name; 128 string.Truncate(string.Length() - 2); //----BMailMessage includes the ": " 129 ((BEmailMessage *)(fFields))->SetHeaderField(string.String(),str); 130 return B_OK; 131 } 132 133 status_t BMailMessage::Send(bool send_now, 134 bool /*remove_when_I_have_completed_sending_this_message_to_your_preferred_SMTP_server*/) 135 { 136 return ((BEmailMessage *)(fFields))->Send(send_now); 137 } 138 139