author | alwin <alwin> | 2003-12-23 01:58:59 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-23 01:58:59 (UTC) |
commit | 127c50cc446de489c702400ebc5fc4874f6311b2 (patch) (unidiff) | |
tree | 86ba684107eb2258e22b613c8c0dfa1a0c8a1bda | |
parent | 04a7006c0392c02941e263d4d35edeeb2f98223d (diff) | |
download | opie-127c50cc446de489c702400ebc5fc4874f6311b2.zip opie-127c50cc446de489c702400ebc5fc4874f6311b2.tar.gz opie-127c50cc446de489c702400ebc5fc4874f6311b2.tar.bz2 |
UFFFFFFF
flushing send queue mostly finished.
Attention: To get it work you must apply the patches from the libetpan/
directory!
ToDo:
- when flush then select a smtp-account to use for when there are more
than one smtp accounts. (opiemail.cpp) This moment I just use the first one.
- the special funs in mboxwrapper (deleting range of mail, storing a message
to a folder) should go to all mailbox wrappers, means into the global interface
of them.
- cleanup/review the code of the smtp-wrapper.
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.cpp | 1 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.cpp | 66 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.h | 3 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 333 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.h | 18 | ||||
-rw-r--r-- | noncore/net/mail/mailwrapper.cpp | 1 | ||||
-rw-r--r-- | noncore/net/mail/mboxwrapper.cpp | 66 | ||||
-rw-r--r-- | noncore/net/mail/mboxwrapper.h | 3 | ||||
-rw-r--r-- | noncore/net/mail/opiemail.cpp | 19 | ||||
-rw-r--r-- | noncore/net/mail/smtpwrapper.cpp | 333 | ||||
-rw-r--r-- | noncore/net/mail/smtpwrapper.h | 18 |
11 files changed, 585 insertions, 276 deletions
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp index c5d4265..f8efd09 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp | |||
@@ -1,75 +1,74 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
3 | #include <sys/types.h> | 3 | #include <sys/types.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <fcntl.h> | 5 | #include <fcntl.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | 8 | ||
9 | #include "mailwrapper.h" | 9 | #include "mailwrapper.h" |
10 | #include "logindialog.h" | 10 | #include "logindialog.h" |
11 | //#include "mail.h" | ||
12 | #include "defines.h" | 11 | #include "defines.h" |
13 | 12 | ||
14 | Attachment::Attachment( DocLnk lnk ) | 13 | Attachment::Attachment( DocLnk lnk ) |
15 | { | 14 | { |
16 | doc = lnk; | 15 | doc = lnk; |
17 | size = QFileInfo( doc.file() ).size(); | 16 | size = QFileInfo( doc.file() ).size(); |
18 | } | 17 | } |
19 | 18 | ||
20 | Folder::Folder(const QString&tmp_name, const QString&sep ) | 19 | Folder::Folder(const QString&tmp_name, const QString&sep ) |
21 | { | 20 | { |
22 | name = tmp_name; | 21 | name = tmp_name; |
23 | nameDisplay = name; | 22 | nameDisplay = name; |
24 | separator = sep; | 23 | separator = sep; |
25 | } | 24 | } |
26 | 25 | ||
27 | const QString& Folder::Separator()const | 26 | const QString& Folder::Separator()const |
28 | { | 27 | { |
29 | return separator; | 28 | return separator; |
30 | } | 29 | } |
31 | 30 | ||
32 | IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix ) | 31 | IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix ) |
33 | : Folder( name,sep ),m_MaySelect(select) | 32 | : Folder( name,sep ),m_MaySelect(select) |
34 | { | 33 | { |
35 | // Decode IMAP foldername | 34 | // Decode IMAP foldername |
36 | nameDisplay = IMAPFolder::decodeFolderName( name ); | 35 | nameDisplay = IMAPFolder::decodeFolderName( name ); |
37 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); | 36 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); |
38 | 37 | ||
39 | if (prefix.length()>0) { | 38 | if (prefix.length()>0) { |
40 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { | 39 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { |
41 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); | 40 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); |
42 | } | 41 | } |
43 | } | 42 | } |
44 | } | 43 | } |
45 | 44 | ||
46 | static unsigned char base64chars[] = | 45 | static unsigned char base64chars[] = |
47 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; | 46 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; |
48 | 47 | ||
49 | /** | 48 | /** |
50 | * Decodes base64 encoded parts of the imapfolder name | 49 | * Decodes base64 encoded parts of the imapfolder name |
51 | * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc | 50 | * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc |
52 | */ | 51 | */ |
53 | QString IMAPFolder::decodeFolderName( const QString &name ) | 52 | QString IMAPFolder::decodeFolderName( const QString &name ) |
54 | { | 53 | { |
55 | unsigned char c, i, bitcount; | 54 | unsigned char c, i, bitcount; |
56 | unsigned long ucs4, utf16, bitbuf; | 55 | unsigned long ucs4, utf16, bitbuf; |
57 | unsigned char base64[256], utf8[6]; | 56 | unsigned char base64[256], utf8[6]; |
58 | unsigned long srcPtr = 0; | 57 | unsigned long srcPtr = 0; |
59 | QCString dst; | 58 | QCString dst; |
60 | QCString src = name.ascii(); | 59 | QCString src = name.ascii(); |
61 | 60 | ||
62 | /* initialize modified base64 decoding table */ | 61 | /* initialize modified base64 decoding table */ |
63 | memset(base64, UNDEFINED, sizeof(base64)); | 62 | memset(base64, UNDEFINED, sizeof(base64)); |
64 | for (i = 0; i < sizeof(base64chars); ++i) { | 63 | for (i = 0; i < sizeof(base64chars); ++i) { |
65 | base64[(int)base64chars[i]] = i; | 64 | base64[(int)base64chars[i]] = i; |
66 | } | 65 | } |
67 | 66 | ||
68 | /* loop until end of string */ | 67 | /* loop until end of string */ |
69 | while (srcPtr < src.length ()) { | 68 | while (srcPtr < src.length ()) { |
70 | c = src[srcPtr++]; | 69 | c = src[srcPtr++]; |
71 | /* deal with literal characters and &- */ | 70 | /* deal with literal characters and &- */ |
72 | if (c != '&' || src[srcPtr] == '-') { | 71 | if (c != '&' || src[srcPtr] == '-') { |
73 | /* encode literally */ | 72 | /* encode literally */ |
74 | dst += c; | 73 | dst += c; |
75 | /* skip over the '-' if this is an &- sequence */ | 74 | /* skip over the '-' if this is an &- sequence */ |
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp index 8117cef..293ae1b 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp | |||
@@ -156,64 +156,130 @@ RecBody MBOXwrapper::fetchBody( const RecMail &mail ) | |||
156 | QString p = MBOXPath+"/"; | 156 | QString p = MBOXPath+"/"; |
157 | p+=mail.getMbox(); | 157 | p+=mail.getMbox(); |
158 | mailmessage * msg; | 158 | mailmessage * msg; |
159 | char*data=0; | 159 | char*data=0; |
160 | size_t size; | 160 | size_t size; |
161 | 161 | ||
162 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 162 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); |
163 | mailfolder*folder; | 163 | mailfolder*folder; |
164 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 164 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); |
165 | r = mailfolder_connect(folder); | 165 | r = mailfolder_connect(folder); |
166 | if (r != MAIL_NO_ERROR) { | 166 | if (r != MAIL_NO_ERROR) { |
167 | qDebug("Error initializing mbox"); | 167 | qDebug("Error initializing mbox"); |
168 | mailfolder_free(folder); | 168 | mailfolder_free(folder); |
169 | mailstorage_free(storage); | 169 | mailstorage_free(storage); |
170 | return body; | 170 | return body; |
171 | } | 171 | } |
172 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 172 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
173 | if (r != MAIL_NO_ERROR) { | 173 | if (r != MAIL_NO_ERROR) { |
174 | qDebug("Error fetching mail %i",mail.getNumber()); | 174 | qDebug("Error fetching mail %i",mail.getNumber()); |
175 | mailfolder_free(folder); | 175 | mailfolder_free(folder); |
176 | mailstorage_free(storage); | 176 | mailstorage_free(storage); |
177 | return body; | 177 | return body; |
178 | } | 178 | } |
179 | r = mailmessage_fetch(msg,&data,&size); | 179 | r = mailmessage_fetch(msg,&data,&size); |
180 | if (r != MAIL_NO_ERROR) { | 180 | if (r != MAIL_NO_ERROR) { |
181 | qDebug("Error fetching mail %i",mail.getNumber()); | 181 | qDebug("Error fetching mail %i",mail.getNumber()); |
182 | mailfolder_free(folder); | 182 | mailfolder_free(folder); |
183 | mailstorage_free(storage); | 183 | mailstorage_free(storage); |
184 | mailmessage_free(msg); | 184 | mailmessage_free(msg); |
185 | return body; | 185 | return body; |
186 | } | 186 | } |
187 | body = parseMail(msg); | 187 | body = parseMail(msg); |
188 | mailmessage_fetch_result_free(msg,data); | 188 | mailmessage_fetch_result_free(msg,data); |
189 | mailfolder_free(folder); | 189 | mailfolder_free(folder); |
190 | mailstorage_free(storage); | 190 | mailstorage_free(storage); |
191 | 191 | ||
192 | return body; | 192 | return body; |
193 | } | 193 | } |
194 | 194 | ||
195 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) | 195 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) |
196 | { | 196 | { |
197 | qDebug("MBOX %i von %i",current,maximum); | 197 | qDebug("MBOX %i von %i",current,maximum); |
198 | } | 198 | } |
199 | 199 | ||
200 | void MBOXwrapper::createFolder(const QString&) | 200 | void MBOXwrapper::createFolder(const QString&) |
201 | { | 201 | { |
202 | } | 202 | } |
203 | 203 | ||
204 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 204 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
205 | { | 205 | { |
206 | QString p = MBOXPath+"/"; | 206 | QString p = MBOXPath+"/"; |
207 | p+=folder; | 207 | p+=folder; |
208 | mailmbox_folder*f = 0; | 208 | mailmbox_folder*f = 0; |
209 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 209 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
210 | if (r != MAIL_NO_ERROR) { | 210 | if (r != MAIL_NO_ERROR) { |
211 | qDebug("Error init folder"); | 211 | qDebug("Error init folder"); |
212 | return; | 212 | return; |
213 | } | 213 | } |
214 | r = mailmbox_append_message(f,msg,length); | 214 | r = mailmbox_append_message(f,msg,length); |
215 | if (r != MAIL_NO_ERROR) { | 215 | if (r != MAIL_NO_ERROR) { |
216 | qDebug("Error writing message folder"); | 216 | qDebug("Error writing message folder"); |
217 | } | 217 | } |
218 | mailmbox_done(f); | 218 | mailmbox_done(f); |
219 | } | 219 | } |
220 | |||
221 | void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) | ||
222 | { | ||
223 | RecBody body; | ||
224 | mailstorage*storage = mailstorage_new(NULL); | ||
225 | QString p = MBOXPath+"/"; | ||
226 | p+=mail.getMbox(); | ||
227 | mailmessage * msg; | ||
228 | char*data=0; | ||
229 | size_t size; | ||
230 | |||
231 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | ||
232 | mailfolder*folder; | ||
233 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | ||
234 | r = mailfolder_connect(folder); | ||
235 | if (r != MAIL_NO_ERROR) { | ||
236 | qDebug("Error initializing mbox"); | ||
237 | mailfolder_free(folder); | ||
238 | mailstorage_free(storage); | ||
239 | return; | ||
240 | } | ||
241 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | ||
242 | if (r != MAIL_NO_ERROR) { | ||
243 | qDebug("Error fetching mail %i",mail.getNumber()); | ||
244 | mailfolder_free(folder); | ||
245 | mailstorage_free(storage); | ||
246 | return; | ||
247 | } | ||
248 | r = mailmessage_fetch(msg,&data,&size); | ||
249 | if (r != MAIL_NO_ERROR) { | ||
250 | qDebug("Error fetching mail %i",mail.getNumber()); | ||
251 | mailfolder_free(folder); | ||
252 | mailstorage_free(storage); | ||
253 | mailmessage_free(msg); | ||
254 | return; | ||
255 | } | ||
256 | *target = data; | ||
257 | *length = size; | ||
258 | mailfolder_free(folder); | ||
259 | mailstorage_free(storage); | ||
260 | mailmessage_free(msg); | ||
261 | } | ||
262 | |||
263 | void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | ||
264 | { | ||
265 | QString p = MBOXPath+"/"; | ||
266 | p+=mailbox; | ||
267 | mailmbox_folder*f = 0; | ||
268 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | ||
269 | if (r != MAIL_NO_ERROR) { | ||
270 | qDebug("Error init folder"); | ||
271 | return; | ||
272 | } | ||
273 | for (unsigned int i=0; i < target.count();++i) { | ||
274 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); | ||
275 | if (r!=MAILMBOX_NO_ERROR) { | ||
276 | qDebug("error delete mail"); | ||
277 | } | ||
278 | } | ||
279 | r = mailmbox_expunge(f); | ||
280 | if (r != MAILMBOX_NO_ERROR) { | ||
281 | qDebug("error expunge mailbox"); | ||
282 | } | ||
283 | mailmbox_done(f); | ||
284 | } | ||
285 | |||
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.h b/noncore/net/mail/libmailwrapper/mboxwrapper.h index 1bbaf79..f64ad52 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.h +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.h | |||
@@ -1,32 +1,35 @@ | |||
1 | #ifndef __MBOX_WRAPPER_H | 1 | #ifndef __MBOX_WRAPPER_H |
2 | #define __MBOX_WRAPPER_H | 2 | #define __MBOX_WRAPPER_H |
3 | 3 | ||
4 | #include "genericwrapper.h" | 4 | #include "genericwrapper.h" |
5 | #include <qstring.h> | 5 | #include <qstring.h> |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | 9 | ||
10 | class MBOXwrapper : public Genericwrapper | 10 | class MBOXwrapper : public Genericwrapper |
11 | { | 11 | { |
12 | Q_OBJECT | 12 | Q_OBJECT |
13 | public: | 13 | public: |
14 | MBOXwrapper(const QString & dir); | 14 | MBOXwrapper(const QString & dir); |
15 | virtual ~MBOXwrapper(); | 15 | virtual ~MBOXwrapper(); |
16 | 16 | ||
17 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 17 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
18 | virtual QList<Folder>* listFolders(); | 18 | virtual QList<Folder>* listFolders(); |
19 | 19 | ||
20 | virtual void deleteMail(const RecMail&mail); | 20 | virtual void deleteMail(const RecMail&mail); |
21 | virtual void answeredMail(const RecMail&mail); | 21 | virtual void answeredMail(const RecMail&mail); |
22 | virtual void createFolder(const QString&aFolder); | 22 | virtual void createFolder(const QString&aFolder); |
23 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | 23 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); |
24 | 24 | ||
25 | virtual RecBody fetchBody( const RecMail &mail ); | 25 | virtual RecBody fetchBody( const RecMail &mail ); |
26 | static void mbox_progress( size_t current, size_t maximum ); | 26 | static void mbox_progress( size_t current, size_t maximum ); |
27 | 27 | ||
28 | virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length); | ||
29 | virtual void deleteMails(const QString & mailbox,QList<RecMail> &target); | ||
30 | |||
28 | protected: | 31 | protected: |
29 | QString MBOXPath; | 32 | QString MBOXPath; |
30 | }; | 33 | }; |
31 | 34 | ||
32 | #endif | 35 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index a6a46ba..b81a87f 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp | |||
@@ -1,84 +1,80 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
3 | #include <sys/types.h> | 3 | #include <sys/types.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <fcntl.h> | 5 | #include <fcntl.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | #include <qt.h> | ||
8 | 9 | ||
9 | #include <libetpan/libetpan.h> | 10 | #include <libetpan/libetpan.h> |
10 | #if 0 | ||
11 | #include <libetpan/mailimf.h> | ||
12 | #include <libetpan/mailsmtp.h> | ||
13 | #include <libetpan/mailstorage.h> | ||
14 | #include <libetpan/maildriver.h> | ||
15 | #endif | ||
16 | 11 | ||
17 | #include "smtpwrapper.h" | 12 | #include "smtpwrapper.h" |
18 | #include "mailwrapper.h" | 13 | #include "mailwrapper.h" |
19 | #include "mboxwrapper.h" | 14 | #include "mboxwrapper.h" |
20 | #include "logindialog.h" | 15 | #include "logindialog.h" |
16 | #include "mailtypes.h" | ||
21 | #include "defines.h" | 17 | #include "defines.h" |
22 | 18 | ||
23 | SMTPwrapper::SMTPwrapper( Settings *s ) | 19 | SMTPwrapper::SMTPwrapper( Settings *s ) |
24 | : QObject() | 20 | : QObject() |
25 | { | 21 | { |
26 | settings = s; | 22 | settings = s; |
27 | } | 23 | } |
28 | 24 | ||
29 | QString SMTPwrapper::mailsmtpError( int errnum ) | 25 | QString SMTPwrapper::mailsmtpError( int errnum ) |
30 | { | 26 | { |
31 | switch ( errnum ) { | 27 | switch ( errnum ) { |
32 | case MAILSMTP_NO_ERROR: | 28 | case MAILSMTP_NO_ERROR: |
33 | return tr( "No error" ); | 29 | return tr( "No error" ); |
34 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 30 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
35 | return tr( "Unexpected error code" ); | 31 | return tr( "Unexpected error code" ); |
36 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 32 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
37 | return tr( "Service not available" ); | 33 | return tr( "Service not available" ); |
38 | case MAILSMTP_ERROR_STREAM: | 34 | case MAILSMTP_ERROR_STREAM: |
39 | return tr( "Stream error" ); | 35 | return tr( "Stream error" ); |
40 | case MAILSMTP_ERROR_HOSTNAME: | 36 | case MAILSMTP_ERROR_HOSTNAME: |
41 | return tr( "gethostname() failed" ); | 37 | return tr( "gethostname() failed" ); |
42 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 38 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
43 | return tr( "Not implemented" ); | 39 | return tr( "Not implemented" ); |
44 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 40 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
45 | return tr( "Error, action not taken" ); | 41 | return tr( "Error, action not taken" ); |
46 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 42 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
47 | return tr( "Data exceeds storage allocation" ); | 43 | return tr( "Data exceeds storage allocation" ); |
48 | case MAILSMTP_ERROR_IN_PROCESSING: | 44 | case MAILSMTP_ERROR_IN_PROCESSING: |
49 | return tr( "Error in processing" ); | 45 | return tr( "Error in processing" ); |
50 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 46 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
51 | // return tr( "Insufficient system storage" ); | 47 | // return tr( "Insufficient system storage" ); |
52 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 48 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
53 | return tr( "Mailbox unavailable" ); | 49 | return tr( "Mailbox unavailable" ); |
54 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 50 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
55 | return tr( "Mailbox name not allowed" ); | 51 | return tr( "Mailbox name not allowed" ); |
56 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 52 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
57 | return tr( "Bad command sequence" ); | 53 | return tr( "Bad command sequence" ); |
58 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 54 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
59 | return tr( "User not local" ); | 55 | return tr( "User not local" ); |
60 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 56 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
61 | return tr( "Transaction failed" ); | 57 | return tr( "Transaction failed" ); |
62 | case MAILSMTP_ERROR_MEMORY: | 58 | case MAILSMTP_ERROR_MEMORY: |
63 | return tr( "Memory error" ); | 59 | return tr( "Memory error" ); |
64 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 60 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
65 | return tr( "Connection refused" ); | 61 | return tr( "Connection refused" ); |
66 | default: | 62 | default: |
67 | return tr( "Unknown error code" ); | 63 | return tr( "Unknown error code" ); |
68 | } | 64 | } |
69 | } | 65 | } |
70 | 66 | ||
71 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) | 67 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) |
72 | { | 68 | { |
73 | return mailimf_mailbox_new( strdup( name.latin1() ), | 69 | return mailimf_mailbox_new( strdup( name.latin1() ), |
74 | strdup( mail.latin1() ) ); | 70 | strdup( mail.latin1() ) ); |
75 | } | 71 | } |
76 | 72 | ||
77 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) | 73 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) |
78 | { | 74 | { |
79 | mailimf_address_list *addresses; | 75 | mailimf_address_list *addresses; |
80 | 76 | ||
81 | if ( addr.isEmpty() ) return NULL; | 77 | if ( addr.isEmpty() ) return NULL; |
82 | 78 | ||
83 | addresses = mailimf_address_list_new_empty(); | 79 | addresses = mailimf_address_list_new_empty(); |
84 | 80 | ||
@@ -147,499 +143,572 @@ err_free_fields: | |||
147 | mailimf_fields_free( fields ); | 143 | mailimf_fields_free( fields ); |
148 | err_free_reply: | 144 | err_free_reply: |
149 | mailimf_address_list_free( reply ); | 145 | mailimf_address_list_free( reply ); |
150 | mailimf_address_list_free( bcc ); | 146 | mailimf_address_list_free( bcc ); |
151 | mailimf_address_list_free( cc ); | 147 | mailimf_address_list_free( cc ); |
152 | mailimf_address_list_free( to ); | 148 | mailimf_address_list_free( to ); |
153 | err_free_from: | 149 | err_free_from: |
154 | mailimf_mailbox_list_free( from ); | 150 | mailimf_mailbox_list_free( from ); |
155 | err_free_fromBox: | 151 | err_free_fromBox: |
156 | mailimf_mailbox_free( fromBox ); | 152 | mailimf_mailbox_free( fromBox ); |
157 | err_free_sender: | 153 | err_free_sender: |
158 | mailimf_mailbox_free( sender ); | 154 | mailimf_mailbox_free( sender ); |
159 | err_free: | 155 | err_free: |
160 | free( subject ); | 156 | free( subject ); |
161 | qDebug( "createImfFields - error" ); | 157 | qDebug( "createImfFields - error" ); |
162 | 158 | ||
163 | return NULL; // Error :( | 159 | return NULL; // Error :( |
164 | } | 160 | } |
165 | 161 | ||
166 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | 162 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) |
167 | { | 163 | { |
168 | mailmime *txtPart; | 164 | mailmime *txtPart; |
169 | mailmime_fields *fields; | 165 | mailmime_fields *fields; |
170 | mailmime_content *content; | 166 | mailmime_content *content; |
171 | mailmime_parameter *param; | 167 | mailmime_parameter *param; |
172 | char *txt = strdup( str.latin1() ); | 168 | char *txt = strdup( str.latin1() ); |
173 | int err; | 169 | int err; |
174 | 170 | ||
175 | param = mailmime_parameter_new( strdup( "charset" ), | 171 | param = mailmime_parameter_new( strdup( "charset" ), |
176 | strdup( "iso-8859-1" ) ); | 172 | strdup( "iso-8859-1" ) ); |
177 | if ( param == NULL ) goto err_free; | 173 | if ( param == NULL ) goto err_free; |
178 | 174 | ||
179 | content = mailmime_content_new_with_str( "text/plain" ); | 175 | content = mailmime_content_new_with_str( "text/plain" ); |
180 | if ( content == NULL ) goto err_free_param; | 176 | if ( content == NULL ) goto err_free_param; |
181 | 177 | ||
182 | err = clist_append( content->ct_parameters, param ); | 178 | err = clist_append( content->ct_parameters, param ); |
183 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | 179 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; |
184 | 180 | ||
185 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); | 181 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); |
186 | if ( fields == NULL ) goto err_free_content; | 182 | if ( fields == NULL ) goto err_free_content; |
187 | 183 | ||
188 | txtPart = mailmime_new_empty( content, fields ); | 184 | txtPart = mailmime_new_empty( content, fields ); |
189 | if ( txtPart == NULL ) goto err_free_fields; | 185 | if ( txtPart == NULL ) goto err_free_fields; |
190 | 186 | ||
191 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); | 187 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); |
192 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 188 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
193 | 189 | ||
194 | return txtPart; // Success :) | 190 | return txtPart; // Success :) |
195 | 191 | ||
196 | err_free_txtPart: | 192 | err_free_txtPart: |
197 | mailmime_free( txtPart ); | 193 | mailmime_free( txtPart ); |
198 | err_free_fields: | 194 | err_free_fields: |
199 | mailmime_fields_free( fields ); | 195 | mailmime_fields_free( fields ); |
200 | err_free_content: | 196 | err_free_content: |
201 | mailmime_content_free( content ); | 197 | mailmime_content_free( content ); |
202 | err_free_param: | 198 | err_free_param: |
203 | mailmime_parameter_free( param ); | 199 | mailmime_parameter_free( param ); |
204 | err_free: | 200 | err_free: |
205 | free( txt ); | 201 | free( txt ); |
206 | qDebug( "buildTxtPart - error" ); | 202 | qDebug( "buildTxtPart - error" ); |
207 | 203 | ||
208 | return NULL; // Error :( | 204 | return NULL; // Error :( |
209 | } | 205 | } |
210 | 206 | ||
211 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype ) | 207 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) |
212 | { | 208 | { |
213 | mailmime * filePart; | 209 | mailmime * filePart = 0; |
214 | mailmime_fields * fields; | 210 | mailmime_fields * fields = 0; |
215 | mailmime_content * content; | 211 | mailmime_content * content = 0; |
216 | mailmime_parameter * param = NULL; | 212 | mailmime_parameter * param = 0; |
213 | char*name = 0; | ||
214 | char*file = 0; | ||
217 | int err; | 215 | int err; |
218 | 216 | ||
219 | int pos = filename.findRev( '/' ); | 217 | int pos = filename.findRev( '/' ); |
220 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 218 | |
221 | char *name = strdup( tmp.latin1() ); // just filename | 219 | if (filename.length()>0) { |
222 | char *file = strdup( filename.latin1() ); // full name with path | 220 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
221 | name = strdup( tmp.latin1() ); // just filename | ||
222 | file = strdup( filename.latin1() ); // full name with path | ||
223 | } | ||
223 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain | 224 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain |
224 | 225 | ||
225 | fields = mailmime_fields_new_filename( | 226 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; |
226 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, | 227 | int mechanism = MAILMIME_MECHANISM_BASE64; |
227 | MAILMIME_MECHANISM_BASE64 ); | 228 | |
228 | if ( fields == NULL ) goto err_free; | 229 | if ( mimetype.startsWith( "text/" ) ) { |
229 | |||
230 | content = mailmime_content_new_with_str( mime ); | ||
231 | if ( content == NULL ) goto err_free_fields; | ||
232 | |||
233 | if ( mimetype.compare( "text/plain" ) == 0 ) { | ||
234 | param = mailmime_parameter_new( strdup( "charset" ), | 230 | param = mailmime_parameter_new( strdup( "charset" ), |
235 | strdup( "iso-8859-1" ) ); | 231 | strdup( "iso-8859-1" ) ); |
236 | if ( param == NULL ) goto err_free_content; | 232 | disptype = MAILMIME_DISPOSITION_TYPE_INLINE; |
237 | 233 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | |
238 | err = clist_append( content->ct_parameters, param ); | ||
239 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; | ||
240 | } | 234 | } |
241 | 235 | ||
242 | filePart = mailmime_new_empty( content, fields ); | 236 | fields = mailmime_fields_new_filename( |
243 | if ( filePart == NULL ) goto err_free_param; | 237 | disptype, name, |
244 | 238 | mechanism ); | |
245 | err = mailmime_set_body_file( filePart, file ); | 239 | content = mailmime_content_new_with_str( mime ); |
246 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 240 | if (content!=0 && fields != 0) { |
241 | if (param) { | ||
242 | clist_append(content->ct_parameters,param); | ||
243 | param = 0; | ||
244 | } | ||
245 | if (filename.length()>0) { | ||
246 | QFileInfo f(filename); | ||
247 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); | ||
248 | clist_append(content->ct_parameters,param); | ||
249 | param = 0; | ||
250 | } | ||
251 | filePart = mailmime_new_empty( content, fields ); | ||
252 | } | ||
253 | if (filePart) { | ||
254 | if (filename.length()>0) { | ||
255 | err = mailmime_set_body_file( filePart, file ); | ||
256 | } else { | ||
257 | err = mailmime_set_body_text(filePart,strdup(TextContent.ascii()),TextContent.length()); | ||
258 | } | ||
259 | if (err != MAILIMF_NO_ERROR) { | ||
260 | qDebug("Error setting body with file %s",file); | ||
261 | mailmime_free( filePart ); | ||
262 | filePart = 0; | ||
263 | } | ||
264 | } | ||
247 | 265 | ||
266 | if (!filePart) { | ||
267 | if ( param != NULL ) { | ||
268 | mailmime_parameter_free( param ); | ||
269 | } | ||
270 | if (content) { | ||
271 | mailmime_content_free( content ); | ||
272 | } else { | ||
273 | if (mime) { | ||
274 | free( mime ); | ||
275 | } | ||
276 | } | ||
277 | if (fields) { | ||
278 | mailmime_fields_free( fields ); | ||
279 | } else { | ||
280 | if (name) { | ||
281 | free( name ); | ||
282 | } | ||
283 | if (file) { | ||
284 | free( file ); | ||
285 | } | ||
286 | } | ||
287 | } | ||
248 | return filePart; // Success :) | 288 | return filePart; // Success :) |
249 | 289 | ||
250 | err_free_filePart: | ||
251 | mailmime_free( filePart ); | ||
252 | err_free_param: | ||
253 | if ( param != NULL ) mailmime_parameter_free( param ); | ||
254 | err_free_content: | ||
255 | mailmime_content_free( content ); | ||
256 | err_free_fields: | ||
257 | mailmime_fields_free( fields ); | ||
258 | err_free: | ||
259 | free( name ); | ||
260 | free( mime ); | ||
261 | free( file ); | ||
262 | qDebug( "buildFilePart - error" ); | ||
263 | |||
264 | return NULL; // Error :( | ||
265 | } | 290 | } |
266 | 291 | ||
267 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) | 292 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) |
268 | { | 293 | { |
269 | const Attachment *it; | 294 | const Attachment *it; |
270 | /* work around for the brainfucked qlist which can not act with const values */ | 295 | unsigned int count = files.count(); |
271 | for ( it = ((QList<Attachment>)files).first(); it; it = ((QList<Attachment>)files).next() ) { | 296 | qDebug("List contains %i values",count); |
297 | for ( unsigned int i = 0; i < count; ++i ) { | ||
272 | qDebug( "Adding file" ); | 298 | qDebug( "Adding file" ); |
273 | mailmime *filePart; | 299 | mailmime *filePart; |
274 | int err; | 300 | int err; |
301 | it = ((QList<Attachment>)files).at(i); | ||
275 | 302 | ||
276 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); | 303 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); |
277 | if ( filePart == NULL ) goto err_free; | 304 | if ( filePart == NULL ) { |
278 | 305 | qDebug( "addFileParts: error adding file:" ); | |
306 | qDebug( it->getFileName() ); | ||
307 | continue; | ||
308 | } | ||
279 | err = mailmime_smart_add_part( message, filePart ); | 309 | err = mailmime_smart_add_part( message, filePart ); |
280 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 310 | if ( err != MAILIMF_NO_ERROR ) { |
281 | 311 | mailmime_free( filePart ); | |
282 | continue; // Success :) | 312 | qDebug("error smart add"); |
283 | 313 | } | |
284 | err_free_filePart: | ||
285 | mailmime_free( filePart ); | ||
286 | err_free: | ||
287 | qDebug( "addFileParts: error adding file:" ); | ||
288 | qDebug( it->getFileName() ); | ||
289 | } | 314 | } |
290 | } | 315 | } |
291 | 316 | ||
292 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) | 317 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) |
293 | { | 318 | { |
294 | mailmime *message, *txtPart; | 319 | mailmime *message, *txtPart; |
295 | mailimf_fields *fields; | 320 | mailimf_fields *fields; |
296 | int err; | 321 | int err; |
297 | 322 | ||
298 | fields = createImfFields( mail ); | 323 | fields = createImfFields( mail ); |
299 | if ( fields == NULL ) goto err_free; | 324 | if ( fields == NULL ) goto err_free; |
300 | 325 | ||
301 | message = mailmime_new_message_data( NULL ); | 326 | message = mailmime_new_message_data( NULL ); |
302 | if ( message == NULL ) goto err_free_fields; | 327 | if ( message == NULL ) goto err_free_fields; |
303 | 328 | ||
304 | mailmime_set_imf_fields( message, fields ); | 329 | mailmime_set_imf_fields( message, fields ); |
305 | 330 | ||
306 | txtPart = buildTxtPart( mail.getMessage() ); | 331 | if (mail.getAttachments().count()==0) { |
332 | txtPart = buildTxtPart( mail.getMessage() ); | ||
333 | } else { | ||
334 | txtPart = buildFilePart("","text/plain",mail.getMessage()); | ||
335 | } | ||
307 | if ( txtPart == NULL ) goto err_free_message; | 336 | if ( txtPart == NULL ) goto err_free_message; |
308 | 337 | ||
309 | err = mailmime_smart_add_part( message, txtPart ); | 338 | err = mailmime_smart_add_part( message, txtPart ); |
310 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 339 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
311 | 340 | ||
312 | addFileParts( message, mail.getAttachments() ); | 341 | addFileParts( message, mail.getAttachments() ); |
313 | 342 | ||
314 | return message; // Success :) | 343 | return message; // Success :) |
315 | 344 | ||
316 | err_free_txtPart: | 345 | err_free_txtPart: |
317 | mailmime_free( txtPart ); | 346 | mailmime_free( txtPart ); |
318 | err_free_message: | 347 | err_free_message: |
319 | mailmime_free( message ); | 348 | mailmime_free( message ); |
320 | err_free_fields: | 349 | err_free_fields: |
321 | mailimf_fields_free( fields ); | 350 | mailimf_fields_free( fields ); |
322 | err_free: | 351 | err_free: |
323 | qDebug( "createMimeMail: error" ); | 352 | qDebug( "createMimeMail: error" ); |
324 | 353 | ||
325 | return NULL; // Error :( | 354 | return NULL; // Error :( |
326 | } | 355 | } |
327 | 356 | ||
328 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) | 357 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) |
329 | { | 358 | { |
330 | mailimf_field *field; | 359 | mailimf_field *field; |
331 | clistiter *it; | 360 | clistiter *it; |
332 | 361 | ||
333 | it = clist_begin( fields->fld_list ); | 362 | it = clist_begin( fields->fld_list ); |
334 | while ( it ) { | 363 | while ( it ) { |
335 | field = (mailimf_field *) it->data; | 364 | field = (mailimf_field *) it->data; |
336 | if ( field->fld_type == type ) { | 365 | if ( field->fld_type == type ) { |
337 | return field; | 366 | return field; |
338 | } | 367 | } |
339 | it = it->next; | 368 | it = it->next; |
340 | } | 369 | } |
341 | 370 | ||
342 | return NULL; | 371 | return NULL; |
343 | } | 372 | } |
344 | 373 | ||
345 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) | 374 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) |
346 | { | 375 | { |
347 | clistiter *it, *it2; | 376 | clistiter *it, *it2; |
348 | 377 | ||
349 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | 378 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { |
350 | mailimf_address *addr; | 379 | mailimf_address *addr; |
351 | addr = (mailimf_address *) it->data; | 380 | addr = (mailimf_address *) it->data; |
352 | 381 | ||
353 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | 382 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { |
354 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | 383 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); |
355 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { | 384 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { |
356 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | 385 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; |
357 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | 386 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { |
358 | mailimf_mailbox *mbox; | 387 | mailimf_mailbox *mbox; |
359 | mbox = (mailimf_mailbox *) it2->data; | 388 | mbox = (mailimf_mailbox *) it2->data; |
360 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | 389 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); |
361 | } | 390 | } |
362 | } | 391 | } |
363 | } | 392 | } |
364 | } | 393 | } |
365 | 394 | ||
366 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) | 395 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) |
367 | { | 396 | { |
368 | clist *rcptList; | 397 | clist *rcptList; |
369 | mailimf_field *field; | 398 | mailimf_field *field; |
370 | 399 | ||
371 | rcptList = esmtp_address_list_new(); | 400 | rcptList = esmtp_address_list_new(); |
372 | 401 | ||
373 | field = getField( fields, MAILIMF_FIELD_TO ); | 402 | field = getField( fields, MAILIMF_FIELD_TO ); |
374 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) | 403 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) |
375 | && field->fld_data.fld_to->to_addr_list ) { | 404 | && field->fld_data.fld_to->to_addr_list ) { |
376 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); | 405 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); |
377 | } | 406 | } |
378 | 407 | ||
379 | field = getField( fields, MAILIMF_FIELD_CC ); | 408 | field = getField( fields, MAILIMF_FIELD_CC ); |
380 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) | 409 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) |
381 | && field->fld_data.fld_cc->cc_addr_list ) { | 410 | && field->fld_data.fld_cc->cc_addr_list ) { |
382 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); | 411 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); |
383 | } | 412 | } |
384 | 413 | ||
385 | field = getField( fields, MAILIMF_FIELD_BCC ); | 414 | field = getField( fields, MAILIMF_FIELD_BCC ); |
386 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) | 415 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) |
387 | && field->fld_data.fld_bcc->bcc_addr_list ) { | 416 | && field->fld_data.fld_bcc->bcc_addr_list ) { |
388 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); | 417 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); |
389 | } | 418 | } |
390 | 419 | ||
391 | return rcptList; | 420 | return rcptList; |
392 | } | 421 | } |
393 | 422 | ||
394 | char *SMTPwrapper::getFrom( mailmime *mail ) | 423 | char *SMTPwrapper::getFrom( mailimf_field *ffrom) |
395 | { | 424 | { |
396 | char *from = NULL; | 425 | char *from = NULL; |
397 | |||
398 | mailimf_field *ffrom; | ||
399 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | ||
400 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 426 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) |
401 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | 427 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { |
402 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | 428 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; |
403 | clistiter *it; | 429 | clistiter *it; |
404 | for ( it = clist_begin( cl ); it; it = it->next ) { | 430 | for ( it = clist_begin( cl ); it; it = it->next ) { |
405 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 431 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
406 | from = strdup( mb->mb_addr_spec ); | 432 | from = strdup( mb->mb_addr_spec ); |
407 | } | 433 | } |
408 | } | 434 | } |
409 | 435 | ||
410 | return from; | 436 | return from; |
411 | } | 437 | } |
412 | 438 | ||
413 | SMTPaccount *SMTPwrapper::getAccount(const QString&from ) | 439 | char *SMTPwrapper::getFrom( mailmime *mail ) |
440 | { | ||
441 | mailimf_field *ffrom = 0; | ||
442 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | ||
443 | return getFrom(ffrom); | ||
444 | } | ||
445 | |||
446 | SMTPaccount *SMTPwrapper::getAccount(const QString&name ) | ||
414 | { | 447 | { |
415 | SMTPaccount *smtp; | 448 | SMTPaccount *smtp; |
416 | 449 | ||
417 | QList<Account> list = settings->getAccounts(); | 450 | QList<Account> list = settings->getAccounts(); |
418 | Account *it; | 451 | Account *it; |
419 | for ( it = list.first(); it; it = list.next() ) { | 452 | for ( it = list.first(); it; it = list.next() ) { |
420 | if ( it->getType().compare( "SMTP" ) == 0 ) { | 453 | if ( it->getType().compare( "SMTP" ) == 0 ) { |
421 | smtp = static_cast<SMTPaccount *>(it); | 454 | smtp = static_cast<SMTPaccount *>(it); |
422 | if ( smtp->getMail().compare( from ) == 0 ) { | 455 | if ( smtp->getName()== name ) { |
423 | qDebug( "SMTPaccount found for" ); | 456 | qDebug( "SMTPaccount found for" ); |
424 | qDebug( from ); | 457 | qDebug( name ); |
425 | return smtp; | 458 | return smtp; |
426 | } | 459 | } |
427 | } | 460 | } |
428 | } | 461 | } |
429 | 462 | ||
430 | return NULL; | 463 | return NULL; |
431 | } | 464 | } |
432 | 465 | ||
433 | QString SMTPwrapper::getTmpFile() { | 466 | QString SMTPwrapper::getTmpFile() { |
434 | int num = 0; | 467 | int num = 0; |
435 | QString unique; | 468 | QString unique; |
436 | 469 | ||
437 | QDir dir( "/tmp" ); | 470 | QDir dir( "/tmp" ); |
438 | QStringList::Iterator it; | ||
439 | 471 | ||
440 | QStringList list = dir.entryList( "opiemail-tmp-*" ); | 472 | QStringList list = dir.entryList( "opiemail-tmp-*" ); |
473 | |||
441 | do { | 474 | do { |
442 | unique.setNum( num++ ); | 475 | unique.setNum( num++ ); |
443 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); | 476 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); |
444 | 477 | ||
445 | return "/tmp/opiemail-tmp-" + unique; | 478 | return "/tmp/opiemail-tmp-" + unique; |
446 | } | 479 | } |
447 | 480 | ||
448 | void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) | 481 | void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) |
449 | { | 482 | { |
450 | FILE *f; | 483 | FILE *f; |
451 | int err, col = 0; | 484 | int err, col = 0; |
452 | 485 | ||
453 | f = fopen( file.latin1(), "w" ); | 486 | f = fopen( file.latin1(), "w" ); |
454 | if ( f == NULL ) { | 487 | if ( f == NULL ) { |
455 | qDebug( "writeToFile: error opening file" ); | 488 | qDebug( "writeToFile: error opening file" ); |
456 | return; | 489 | return; |
457 | } | 490 | } |
458 | 491 | ||
459 | err = mailmime_write( f, &col, mail ); | 492 | err = mailmime_write( f, &col, mail ); |
460 | if ( err != MAILIMF_NO_ERROR ) { | 493 | if ( err != MAILIMF_NO_ERROR ) { |
461 | fclose( f ); | 494 | fclose( f ); |
462 | qDebug( "writeToFile: error writing mailmime" ); | 495 | qDebug( "writeToFile: error writing mailmime" ); |
463 | return; | 496 | return; |
464 | } | 497 | } |
465 | 498 | ||
466 | fclose( f ); | 499 | fclose( f ); |
467 | } | 500 | } |
468 | 501 | ||
469 | void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) | 502 | void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) |
470 | { | 503 | { |
471 | 504 | ||
472 | QFile msg_cache(file); | 505 | QFile msg_cache(file); |
473 | QString msg = ""; | 506 | QString msg = ""; |
474 | msg_cache.open(IO_ReadOnly); | 507 | msg_cache.open(IO_ReadOnly); |
475 | char*message = new char[4096]; | 508 | char*message = new char[4096]; |
476 | memset(message,0,4096); | 509 | memset(message,0,4096); |
477 | while (msg_cache.readBlock(message,4095)>0) { | 510 | while (msg_cache.readBlock(message,4095)>0) { |
478 | msg+=message; | 511 | msg+=message; |
479 | memset(message,0,4096); | 512 | memset(message,0,4096); |
480 | } | 513 | } |
481 | delete message; | 514 | delete message; |
482 | *data = (char*)malloc(msg.length()+1*sizeof(char)); | 515 | *data = (char*)malloc(msg.length()+1*sizeof(char)); |
483 | memset(*data,0,msg.length()+1); | 516 | memset(*data,0,msg.length()+1); |
484 | memcpy(*data,msg.ascii(),msg.length()); | 517 | memcpy(*data,msg.ascii(),msg.length()); |
485 | *size=msg.length(); | 518 | *size=msg.length(); |
486 | |||
487 | #if 0 | ||
488 | char *buf; | ||
489 | struct stat st; | ||
490 | int fd, count = 0, total = 0; | ||
491 | |||
492 | fd = open( file.latin1(), O_RDONLY, 0 ); | ||
493 | if ( fd == -1 ) return; | ||
494 | |||
495 | if ( fstat( fd, &st ) != 0 ) goto err_close; | ||
496 | if ( !st.st_size ) goto err_close; | ||
497 | |||
498 | buf = (char *) malloc( st.st_size ); | ||
499 | if ( !buf ) goto err_close; | ||
500 | |||
501 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { | ||
502 | count = read( fd, buf + total, st.st_size - total ); | ||
503 | total += count; | ||
504 | } | ||
505 | if ( count < 0 ) goto err_free; | ||
506 | |||
507 | *data = buf; | ||
508 | *size = st.st_size; | ||
509 | |||
510 | close( fd ); | ||
511 | |||
512 | return; // Success :) | ||
513 | |||
514 | err_free: | ||
515 | free( buf ); | ||
516 | err_close: | ||
517 | close( fd ); | ||
518 | #endif | ||
519 | } | 519 | } |
520 | 520 | ||
521 | void SMTPwrapper::progress( size_t current, size_t maximum ) | 521 | void SMTPwrapper::progress( size_t current, size_t maximum ) |
522 | { | 522 | { |
523 | qDebug( "Current: %i of %i", current, maximum ); | 523 | // qDebug( "Current: %i of %i", current, maximum ); |
524 | } | 524 | } |
525 | 525 | ||
526 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) | 526 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) |
527 | { | 527 | { |
528 | if (!mail) return; | 528 | if (!mail) return; |
529 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | 529 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); |
530 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | 530 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); |
531 | wrap->storeMessage(mail,length,box); | 531 | wrap->storeMessage(mail,length,box); |
532 | delete wrap; | 532 | delete wrap; |
533 | } | 533 | } |
534 | 534 | ||
535 | void SMTPwrapper::smtpSend( mailmime *mail,bool later ) | 535 | void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) |
536 | { | 536 | { |
537 | mailsmtp *session; | 537 | clist *rcpts = 0; |
538 | clist *rcpts; | 538 | char *from, *data; |
539 | char *from, *data, *server, *user = NULL, *pass = NULL; | ||
540 | size_t size; | 539 | size_t size; |
541 | int err; | ||
542 | bool ssl; | ||
543 | uint16_t port; | ||
544 | 540 | ||
545 | |||
546 | from = getFrom( mail ); | ||
547 | SMTPaccount *smtp = getAccount( from ); | ||
548 | if ( smtp == NULL ) { | 541 | if ( smtp == NULL ) { |
549 | free(from); | ||
550 | return; | 542 | return; |
551 | } | 543 | } |
552 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 544 | from = data = 0; |
553 | 545 | ||
554 | QString file = getTmpFile(); | 546 | QString file = getTmpFile(); |
555 | writeToFile( file, mail ); | 547 | writeToFile( file, mail ); |
556 | |||
557 | readFromFile( file, &data, &size ); | 548 | readFromFile( file, &data, &size ); |
558 | QFile f( file ); | 549 | QFile f( file ); |
559 | f.remove(); | 550 | f.remove(); |
560 | 551 | ||
561 | storeMail(data,size,(later?"Outgoing":"Sent")); | ||
562 | |||
563 | if (later) { | 552 | if (later) { |
564 | smtp_address_list_free( rcpts ); | 553 | storeMail(data,size,"Outgoing"); |
565 | if (data) free( data ); | 554 | if (data) free( data ); |
566 | if (from) free(from); | ||
567 | return; | 555 | return; |
568 | } | 556 | } |
557 | from = getFrom( mail ); | ||
558 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | ||
559 | smtpSend(from,rcpts,data,size,smtp); | ||
560 | } | ||
561 | |||
562 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) | ||
563 | { | ||
564 | char *server, *user, *pass; | ||
565 | bool ssl; | ||
566 | uint16_t port; | ||
567 | mailsmtp *session; | ||
568 | int err,result; | ||
569 | |||
570 | result = 1; | ||
571 | server = user = pass = 0; | ||
569 | server = strdup( smtp->getServer().latin1() ); | 572 | server = strdup( smtp->getServer().latin1() ); |
570 | ssl = smtp->getSSL(); | 573 | ssl = smtp->getSSL(); |
571 | port = smtp->getPort().toUInt(); | 574 | port = smtp->getPort().toUInt(); |
572 | 575 | ||
573 | session = mailsmtp_new( 20, &progress ); | 576 | session = mailsmtp_new( 20, &progress ); |
574 | if ( session == NULL ) goto free_mem; | 577 | if ( session == NULL ) goto free_mem; |
575 | 578 | ||
576 | qDebug( "Servername %s at port %i", server, port ); | 579 | qDebug( "Servername %s at port %i", server, port ); |
577 | if ( ssl ) { | 580 | if ( ssl ) { |
578 | qDebug( "SSL session" ); | 581 | qDebug( "SSL session" ); |
579 | err = mailsmtp_ssl_connect( session, server, port ); | 582 | err = mailsmtp_ssl_connect( session, server, port ); |
580 | } else { | 583 | } else { |
581 | qDebug( "No SSL session" ); | 584 | qDebug( "No SSL session" ); |
582 | err = mailsmtp_socket_connect( session, server, port ); | 585 | err = mailsmtp_socket_connect( session, server, port ); |
583 | } | 586 | } |
584 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; | 587 | if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} |
585 | 588 | ||
586 | err = mailsmtp_init( session ); | 589 | err = mailsmtp_init( session ); |
587 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 590 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} |
588 | 591 | ||
589 | qDebug( "INIT OK" ); | 592 | qDebug( "INIT OK" ); |
590 | 593 | ||
591 | if ( smtp->getLogin() ) { | 594 | if ( smtp->getLogin() ) { |
592 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | 595 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { |
593 | // get'em | 596 | // get'em |
594 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | 597 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); |
595 | login.show(); | 598 | login.show(); |
596 | if ( QDialog::Accepted == login.exec() ) { | 599 | if ( QDialog::Accepted == login.exec() ) { |
597 | // ok | 600 | // ok |
598 | user = strdup( login.getUser().latin1() ); | 601 | user = strdup( login.getUser().latin1() ); |
599 | pass = strdup( login.getPassword().latin1() ); | 602 | pass = strdup( login.getPassword().latin1() ); |
600 | } else { | 603 | } else { |
601 | goto free_con_session; | 604 | result = 0; goto free_con_session; |
602 | } | 605 | } |
603 | } else { | 606 | } else { |
604 | user = strdup( smtp->getUser().latin1() ); | 607 | user = strdup( smtp->getUser().latin1() ); |
605 | pass = strdup( smtp->getPassword().latin1() ); | 608 | pass = strdup( smtp->getPassword().latin1() ); |
606 | } | 609 | } |
607 | qDebug( "session->auth: %i", session->auth); | 610 | qDebug( "session->auth: %i", session->auth); |
608 | err = mailsmtp_auth( session, user, pass ); | 611 | err = mailsmtp_auth( session, user, pass ); |
609 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); | 612 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); |
610 | qDebug( "Done auth!" ); | 613 | qDebug( "Done auth!" ); |
611 | } | 614 | } |
612 | 615 | ||
613 | err = mailsmtp_send( session, from, rcpts, data, size ); | 616 | err = mailsmtp_send( session, from, rcpts, data, size ); |
614 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 617 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} |
615 | 618 | ||
616 | qDebug( "Mail sent." ); | 619 | qDebug( "Mail sent." ); |
620 | storeMail(data,size,"Sent"); | ||
617 | 621 | ||
618 | free_con_session: | 622 | free_con_session: |
619 | mailsmtp_quit( session ); | 623 | mailsmtp_quit( session ); |
620 | free_mem_session: | 624 | free_mem_session: |
621 | mailsmtp_free( session ); | 625 | mailsmtp_free( session ); |
622 | free_mem: | 626 | free_mem: |
623 | smtp_address_list_free( rcpts ); | 627 | if (rcpts) smtp_address_list_free( rcpts ); |
624 | if (data) free( data ); | 628 | if (data) free( data ); |
625 | if (from) free(from); | ||
626 | if (server) free( server ); | 629 | if (server) free( server ); |
630 | if (from) free( from ); | ||
627 | if ( smtp->getLogin() ) { | 631 | if ( smtp->getLogin() ) { |
628 | free( user ); | 632 | free( user ); |
629 | free( pass ); | 633 | free( pass ); |
630 | } | 634 | } |
631 | free( from ); | 635 | return result; |
632 | } | 636 | } |
633 | 637 | ||
634 | void SMTPwrapper::sendMail(const Mail&mail,bool later ) | 638 | void SMTPwrapper::sendMail(const Mail&mail,bool later ) |
635 | { | 639 | { |
636 | mailmime * mimeMail; | 640 | mailmime * mimeMail; |
637 | 641 | ||
642 | SMTPaccount *smtp = getAccount(mail.getName()); | ||
643 | |||
638 | mimeMail = createMimeMail(mail ); | 644 | mimeMail = createMimeMail(mail ); |
639 | if ( mimeMail == NULL ) { | 645 | if ( mimeMail == NULL ) { |
640 | qDebug( "sendMail: error creating mime mail" ); | 646 | qDebug( "sendMail: error creating mime mail" ); |
641 | } else { | 647 | } else { |
642 | smtpSend( mimeMail,later ); | 648 | smtpSend( mimeMail,later,smtp); |
643 | mailmime_free( mimeMail ); | 649 | mailmime_free( mimeMail ); |
650 | qDebug("Clean up done"); | ||
651 | } | ||
652 | } | ||
653 | |||
654 | int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) | ||
655 | { | ||
656 | char*data = 0; | ||
657 | size_t length = 0; | ||
658 | size_t curTok = 0; | ||
659 | mailimf_fields *fields = 0; | ||
660 | mailimf_field*ffrom = 0; | ||
661 | clist *rcpts = 0; | ||
662 | char*from = 0; | ||
663 | |||
664 | wrap->fetchRawBody(*which,&data,&length); | ||
665 | if (!data) return 0; | ||
666 | int err = mailimf_fields_parse( data, length, &curTok, &fields ); | ||
667 | if (err != MAILIMF_NO_ERROR) { | ||
668 | free(data); | ||
669 | delete wrap; | ||
670 | return 0; | ||
671 | } | ||
672 | |||
673 | rcpts = createRcptList( fields ); | ||
674 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); | ||
675 | from = getFrom(ffrom); | ||
676 | qDebug("Size: %i vs. %i",length,strlen(data)); | ||
677 | if (rcpts && from) { | ||
678 | return smtpSend(from,rcpts,data,strlen(data),smtp ); | ||
644 | } | 679 | } |
680 | return 0; | ||
681 | } | ||
682 | |||
683 | /* this is a special fun */ | ||
684 | void SMTPwrapper::flushOutbox(SMTPaccount*smtp) | ||
685 | { | ||
686 | if (!smtp) return; | ||
687 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | ||
688 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | ||
689 | if (!wrap) { | ||
690 | qDebug("memory error"); | ||
691 | return; | ||
692 | } | ||
693 | QList<RecMail> mailsToSend; | ||
694 | QList<RecMail> mailsToRemove; | ||
695 | QString mbox("Outgoing"); | ||
696 | wrap->listMessages(mbox,mailsToSend); | ||
697 | if (mailsToSend.count()==0) { | ||
698 | delete wrap; | ||
699 | return; | ||
700 | } | ||
701 | mailsToSend.setAutoDelete(false); | ||
702 | while (mailsToSend.count()>0) { | ||
703 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { | ||
704 | QMessageBox::critical(0,tr("Error sending mail"), | ||
705 | tr("Error sending queued mail - breaking")); | ||
706 | break; | ||
707 | } | ||
708 | mailsToRemove.append(mailsToSend.at(0)); | ||
709 | mailsToSend.removeFirst(); | ||
710 | } | ||
711 | wrap->deleteMails(mbox,mailsToRemove); | ||
712 | mailsToSend.setAutoDelete(true); | ||
713 | delete wrap; | ||
645 | } | 714 | } |
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h index 41e9a8c..c0dcc11 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.h +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h | |||
@@ -1,55 +1,63 @@ | |||
1 | #ifndef SMTPwrapper_H | 1 | #ifndef SMTPwrapper_H |
2 | #define SMTPwrapper_H | 2 | #define SMTPwrapper_H |
3 | 3 | ||
4 | #include <qpe/applnk.h> | 4 | #include <qpe/applnk.h> |
5 | 5 | ||
6 | #include <qbitarray.h> | 6 | #include <qbitarray.h> |
7 | #include <qdatetime.h> | 7 | #include <qdatetime.h> |
8 | #include <libetpan/clist.h> | 8 | #include <libetpan/clist.h> |
9 | 9 | ||
10 | #include "settings.h" | 10 | #include "settings.h" |
11 | 11 | ||
12 | class Mail; | 12 | class Mail; |
13 | class MBOXwrapper; | ||
14 | class RecMail; | ||
13 | class Attachment; | 15 | class Attachment; |
14 | struct mailimf_fields; | 16 | struct mailimf_fields; |
15 | struct mailimf_field; | 17 | struct mailimf_field; |
16 | struct mailimf_mailbox; | 18 | struct mailimf_mailbox; |
17 | struct mailmime; | 19 | struct mailmime; |
18 | struct mailimf_address_list; | 20 | struct mailimf_address_list; |
19 | 21 | ||
20 | class SMTPwrapper : public QObject | 22 | class SMTPwrapper : public QObject |
21 | { | 23 | { |
22 | Q_OBJECT | 24 | Q_OBJECT |
23 | 25 | ||
24 | public: | 26 | public: |
25 | SMTPwrapper( Settings *s ); | 27 | SMTPwrapper( Settings *s ); |
26 | virtual ~SMTPwrapper(){} | 28 | virtual ~SMTPwrapper(){} |
27 | void sendMail(const Mail& mail,bool later=false ); | 29 | void sendMail(const Mail& mail,bool later=false ); |
30 | void flushOutbox(SMTPaccount*smtp); | ||
28 | 31 | ||
29 | protected: | 32 | protected: |
30 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | 33 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); |
31 | mailimf_fields *createImfFields(const Mail &mail ); | 34 | mailimf_fields *createImfFields(const Mail &mail ); |
32 | mailmime *createMimeMail(const Mail&mail ); | 35 | mailmime *createMimeMail(const Mail&mail ); |
33 | 36 | ||
34 | mailimf_address_list *parseAddresses(const QString&addr ); | 37 | mailimf_address_list *parseAddresses(const QString&addr ); |
35 | void addFileParts( mailmime *message,const QList<Attachment>&files ); | 38 | void addFileParts( mailmime *message,const QList<Attachment>&files ); |
36 | mailmime *buildTxtPart(const QString&str ); | 39 | mailmime *buildTxtPart(const QString&str ); |
37 | mailmime *buildFilePart(const QString&filename,const QString&mimetype ); | 40 | mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); |
38 | void smtpSend( mailmime *mail,bool later ); | 41 | void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); |
39 | mailimf_field *getField( mailimf_fields *fields, int type ); | ||
40 | clist *createRcptList( mailimf_fields *fields ); | 42 | clist *createRcptList( mailimf_fields *fields ); |
41 | char *getFrom( mailmime *mail ); | ||
42 | SMTPaccount *getAccount(const QString&from ); | 43 | SMTPaccount *getAccount(const QString&from ); |
43 | void writeToFile(const QString&file, mailmime *mail ); | 44 | void writeToFile(const QString&file, mailmime *mail ); |
44 | void readFromFile(const QString&file, char **data, size_t *size ); | 45 | void readFromFile(const QString&file, char **data, size_t *size ); |
45 | void storeMail(char*mail, size_t length, const QString&box); | ||
46 | 46 | ||
47 | static void storeMail(char*mail, size_t length, const QString&box); | ||
47 | static QString mailsmtpError( int err ); | 48 | static QString mailsmtpError( int err ); |
48 | static QString getTmpFile(); | 49 | static QString getTmpFile(); |
49 | static void progress( size_t current, size_t maximum ); | 50 | static void progress( size_t current, size_t maximum ); |
50 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); | 51 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); |
52 | static char *getFrom( mailmime *mail ); | ||
53 | static char *getFrom( mailimf_field *ffrom); | ||
54 | static mailimf_field *getField( mailimf_fields *fields, int type ); | ||
55 | static int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); | ||
56 | |||
51 | void storeMail(mailmime*mail, const QString&box); | 57 | void storeMail(mailmime*mail, const QString&box); |
52 | Settings *settings; | 58 | Settings *settings; |
59 | |||
60 | int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); | ||
53 | }; | 61 | }; |
54 | 62 | ||
55 | #endif | 63 | #endif |
diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp index c5d4265..f8efd09 100644 --- a/noncore/net/mail/mailwrapper.cpp +++ b/noncore/net/mail/mailwrapper.cpp | |||
@@ -1,75 +1,74 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
3 | #include <sys/types.h> | 3 | #include <sys/types.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <fcntl.h> | 5 | #include <fcntl.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | 8 | ||
9 | #include "mailwrapper.h" | 9 | #include "mailwrapper.h" |
10 | #include "logindialog.h" | 10 | #include "logindialog.h" |
11 | //#include "mail.h" | ||
12 | #include "defines.h" | 11 | #include "defines.h" |
13 | 12 | ||
14 | Attachment::Attachment( DocLnk lnk ) | 13 | Attachment::Attachment( DocLnk lnk ) |
15 | { | 14 | { |
16 | doc = lnk; | 15 | doc = lnk; |
17 | size = QFileInfo( doc.file() ).size(); | 16 | size = QFileInfo( doc.file() ).size(); |
18 | } | 17 | } |
19 | 18 | ||
20 | Folder::Folder(const QString&tmp_name, const QString&sep ) | 19 | Folder::Folder(const QString&tmp_name, const QString&sep ) |
21 | { | 20 | { |
22 | name = tmp_name; | 21 | name = tmp_name; |
23 | nameDisplay = name; | 22 | nameDisplay = name; |
24 | separator = sep; | 23 | separator = sep; |
25 | } | 24 | } |
26 | 25 | ||
27 | const QString& Folder::Separator()const | 26 | const QString& Folder::Separator()const |
28 | { | 27 | { |
29 | return separator; | 28 | return separator; |
30 | } | 29 | } |
31 | 30 | ||
32 | IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix ) | 31 | IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix ) |
33 | : Folder( name,sep ),m_MaySelect(select) | 32 | : Folder( name,sep ),m_MaySelect(select) |
34 | { | 33 | { |
35 | // Decode IMAP foldername | 34 | // Decode IMAP foldername |
36 | nameDisplay = IMAPFolder::decodeFolderName( name ); | 35 | nameDisplay = IMAPFolder::decodeFolderName( name ); |
37 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); | 36 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); |
38 | 37 | ||
39 | if (prefix.length()>0) { | 38 | if (prefix.length()>0) { |
40 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { | 39 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { |
41 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); | 40 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); |
42 | } | 41 | } |
43 | } | 42 | } |
44 | } | 43 | } |
45 | 44 | ||
46 | static unsigned char base64chars[] = | 45 | static unsigned char base64chars[] = |
47 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; | 46 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; |
48 | 47 | ||
49 | /** | 48 | /** |
50 | * Decodes base64 encoded parts of the imapfolder name | 49 | * Decodes base64 encoded parts of the imapfolder name |
51 | * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc | 50 | * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc |
52 | */ | 51 | */ |
53 | QString IMAPFolder::decodeFolderName( const QString &name ) | 52 | QString IMAPFolder::decodeFolderName( const QString &name ) |
54 | { | 53 | { |
55 | unsigned char c, i, bitcount; | 54 | unsigned char c, i, bitcount; |
56 | unsigned long ucs4, utf16, bitbuf; | 55 | unsigned long ucs4, utf16, bitbuf; |
57 | unsigned char base64[256], utf8[6]; | 56 | unsigned char base64[256], utf8[6]; |
58 | unsigned long srcPtr = 0; | 57 | unsigned long srcPtr = 0; |
59 | QCString dst; | 58 | QCString dst; |
60 | QCString src = name.ascii(); | 59 | QCString src = name.ascii(); |
61 | 60 | ||
62 | /* initialize modified base64 decoding table */ | 61 | /* initialize modified base64 decoding table */ |
63 | memset(base64, UNDEFINED, sizeof(base64)); | 62 | memset(base64, UNDEFINED, sizeof(base64)); |
64 | for (i = 0; i < sizeof(base64chars); ++i) { | 63 | for (i = 0; i < sizeof(base64chars); ++i) { |
65 | base64[(int)base64chars[i]] = i; | 64 | base64[(int)base64chars[i]] = i; |
66 | } | 65 | } |
67 | 66 | ||
68 | /* loop until end of string */ | 67 | /* loop until end of string */ |
69 | while (srcPtr < src.length ()) { | 68 | while (srcPtr < src.length ()) { |
70 | c = src[srcPtr++]; | 69 | c = src[srcPtr++]; |
71 | /* deal with literal characters and &- */ | 70 | /* deal with literal characters and &- */ |
72 | if (c != '&' || src[srcPtr] == '-') { | 71 | if (c != '&' || src[srcPtr] == '-') { |
73 | /* encode literally */ | 72 | /* encode literally */ |
74 | dst += c; | 73 | dst += c; |
75 | /* skip over the '-' if this is an &- sequence */ | 74 | /* skip over the '-' if this is an &- sequence */ |
diff --git a/noncore/net/mail/mboxwrapper.cpp b/noncore/net/mail/mboxwrapper.cpp index 8117cef..293ae1b 100644 --- a/noncore/net/mail/mboxwrapper.cpp +++ b/noncore/net/mail/mboxwrapper.cpp | |||
@@ -156,64 +156,130 @@ RecBody MBOXwrapper::fetchBody( const RecMail &mail ) | |||
156 | QString p = MBOXPath+"/"; | 156 | QString p = MBOXPath+"/"; |
157 | p+=mail.getMbox(); | 157 | p+=mail.getMbox(); |
158 | mailmessage * msg; | 158 | mailmessage * msg; |
159 | char*data=0; | 159 | char*data=0; |
160 | size_t size; | 160 | size_t size; |
161 | 161 | ||
162 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 162 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); |
163 | mailfolder*folder; | 163 | mailfolder*folder; |
164 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 164 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); |
165 | r = mailfolder_connect(folder); | 165 | r = mailfolder_connect(folder); |
166 | if (r != MAIL_NO_ERROR) { | 166 | if (r != MAIL_NO_ERROR) { |
167 | qDebug("Error initializing mbox"); | 167 | qDebug("Error initializing mbox"); |
168 | mailfolder_free(folder); | 168 | mailfolder_free(folder); |
169 | mailstorage_free(storage); | 169 | mailstorage_free(storage); |
170 | return body; | 170 | return body; |
171 | } | 171 | } |
172 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 172 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
173 | if (r != MAIL_NO_ERROR) { | 173 | if (r != MAIL_NO_ERROR) { |
174 | qDebug("Error fetching mail %i",mail.getNumber()); | 174 | qDebug("Error fetching mail %i",mail.getNumber()); |
175 | mailfolder_free(folder); | 175 | mailfolder_free(folder); |
176 | mailstorage_free(storage); | 176 | mailstorage_free(storage); |
177 | return body; | 177 | return body; |
178 | } | 178 | } |
179 | r = mailmessage_fetch(msg,&data,&size); | 179 | r = mailmessage_fetch(msg,&data,&size); |
180 | if (r != MAIL_NO_ERROR) { | 180 | if (r != MAIL_NO_ERROR) { |
181 | qDebug("Error fetching mail %i",mail.getNumber()); | 181 | qDebug("Error fetching mail %i",mail.getNumber()); |
182 | mailfolder_free(folder); | 182 | mailfolder_free(folder); |
183 | mailstorage_free(storage); | 183 | mailstorage_free(storage); |
184 | mailmessage_free(msg); | 184 | mailmessage_free(msg); |
185 | return body; | 185 | return body; |
186 | } | 186 | } |
187 | body = parseMail(msg); | 187 | body = parseMail(msg); |
188 | mailmessage_fetch_result_free(msg,data); | 188 | mailmessage_fetch_result_free(msg,data); |
189 | mailfolder_free(folder); | 189 | mailfolder_free(folder); |
190 | mailstorage_free(storage); | 190 | mailstorage_free(storage); |
191 | 191 | ||
192 | return body; | 192 | return body; |
193 | } | 193 | } |
194 | 194 | ||
195 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) | 195 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) |
196 | { | 196 | { |
197 | qDebug("MBOX %i von %i",current,maximum); | 197 | qDebug("MBOX %i von %i",current,maximum); |
198 | } | 198 | } |
199 | 199 | ||
200 | void MBOXwrapper::createFolder(const QString&) | 200 | void MBOXwrapper::createFolder(const QString&) |
201 | { | 201 | { |
202 | } | 202 | } |
203 | 203 | ||
204 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 204 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
205 | { | 205 | { |
206 | QString p = MBOXPath+"/"; | 206 | QString p = MBOXPath+"/"; |
207 | p+=folder; | 207 | p+=folder; |
208 | mailmbox_folder*f = 0; | 208 | mailmbox_folder*f = 0; |
209 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 209 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
210 | if (r != MAIL_NO_ERROR) { | 210 | if (r != MAIL_NO_ERROR) { |
211 | qDebug("Error init folder"); | 211 | qDebug("Error init folder"); |
212 | return; | 212 | return; |
213 | } | 213 | } |
214 | r = mailmbox_append_message(f,msg,length); | 214 | r = mailmbox_append_message(f,msg,length); |
215 | if (r != MAIL_NO_ERROR) { | 215 | if (r != MAIL_NO_ERROR) { |
216 | qDebug("Error writing message folder"); | 216 | qDebug("Error writing message folder"); |
217 | } | 217 | } |
218 | mailmbox_done(f); | 218 | mailmbox_done(f); |
219 | } | 219 | } |
220 | |||
221 | void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) | ||
222 | { | ||
223 | RecBody body; | ||
224 | mailstorage*storage = mailstorage_new(NULL); | ||
225 | QString p = MBOXPath+"/"; | ||
226 | p+=mail.getMbox(); | ||
227 | mailmessage * msg; | ||
228 | char*data=0; | ||
229 | size_t size; | ||
230 | |||
231 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | ||
232 | mailfolder*folder; | ||
233 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | ||
234 | r = mailfolder_connect(folder); | ||
235 | if (r != MAIL_NO_ERROR) { | ||
236 | qDebug("Error initializing mbox"); | ||
237 | mailfolder_free(folder); | ||
238 | mailstorage_free(storage); | ||
239 | return; | ||
240 | } | ||
241 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | ||
242 | if (r != MAIL_NO_ERROR) { | ||
243 | qDebug("Error fetching mail %i",mail.getNumber()); | ||
244 | mailfolder_free(folder); | ||
245 | mailstorage_free(storage); | ||
246 | return; | ||
247 | } | ||
248 | r = mailmessage_fetch(msg,&data,&size); | ||
249 | if (r != MAIL_NO_ERROR) { | ||
250 | qDebug("Error fetching mail %i",mail.getNumber()); | ||
251 | mailfolder_free(folder); | ||
252 | mailstorage_free(storage); | ||
253 | mailmessage_free(msg); | ||
254 | return; | ||
255 | } | ||
256 | *target = data; | ||
257 | *length = size; | ||
258 | mailfolder_free(folder); | ||
259 | mailstorage_free(storage); | ||
260 | mailmessage_free(msg); | ||
261 | } | ||
262 | |||
263 | void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | ||
264 | { | ||
265 | QString p = MBOXPath+"/"; | ||
266 | p+=mailbox; | ||
267 | mailmbox_folder*f = 0; | ||
268 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | ||
269 | if (r != MAIL_NO_ERROR) { | ||
270 | qDebug("Error init folder"); | ||
271 | return; | ||
272 | } | ||
273 | for (unsigned int i=0; i < target.count();++i) { | ||
274 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); | ||
275 | if (r!=MAILMBOX_NO_ERROR) { | ||
276 | qDebug("error delete mail"); | ||
277 | } | ||
278 | } | ||
279 | r = mailmbox_expunge(f); | ||
280 | if (r != MAILMBOX_NO_ERROR) { | ||
281 | qDebug("error expunge mailbox"); | ||
282 | } | ||
283 | mailmbox_done(f); | ||
284 | } | ||
285 | |||
diff --git a/noncore/net/mail/mboxwrapper.h b/noncore/net/mail/mboxwrapper.h index 1bbaf79..f64ad52 100644 --- a/noncore/net/mail/mboxwrapper.h +++ b/noncore/net/mail/mboxwrapper.h | |||
@@ -1,32 +1,35 @@ | |||
1 | #ifndef __MBOX_WRAPPER_H | 1 | #ifndef __MBOX_WRAPPER_H |
2 | #define __MBOX_WRAPPER_H | 2 | #define __MBOX_WRAPPER_H |
3 | 3 | ||
4 | #include "genericwrapper.h" | 4 | #include "genericwrapper.h" |
5 | #include <qstring.h> | 5 | #include <qstring.h> |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | 9 | ||
10 | class MBOXwrapper : public Genericwrapper | 10 | class MBOXwrapper : public Genericwrapper |
11 | { | 11 | { |
12 | Q_OBJECT | 12 | Q_OBJECT |
13 | public: | 13 | public: |
14 | MBOXwrapper(const QString & dir); | 14 | MBOXwrapper(const QString & dir); |
15 | virtual ~MBOXwrapper(); | 15 | virtual ~MBOXwrapper(); |
16 | 16 | ||
17 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 17 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
18 | virtual QList<Folder>* listFolders(); | 18 | virtual QList<Folder>* listFolders(); |
19 | 19 | ||
20 | virtual void deleteMail(const RecMail&mail); | 20 | virtual void deleteMail(const RecMail&mail); |
21 | virtual void answeredMail(const RecMail&mail); | 21 | virtual void answeredMail(const RecMail&mail); |
22 | virtual void createFolder(const QString&aFolder); | 22 | virtual void createFolder(const QString&aFolder); |
23 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | 23 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); |
24 | 24 | ||
25 | virtual RecBody fetchBody( const RecMail &mail ); | 25 | virtual RecBody fetchBody( const RecMail &mail ); |
26 | static void mbox_progress( size_t current, size_t maximum ); | 26 | static void mbox_progress( size_t current, size_t maximum ); |
27 | 27 | ||
28 | virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length); | ||
29 | virtual void deleteMails(const QString & mailbox,QList<RecMail> &target); | ||
30 | |||
28 | protected: | 31 | protected: |
29 | QString MBOXPath; | 32 | QString MBOXPath; |
30 | }; | 33 | }; |
31 | 34 | ||
32 | #endif | 35 | #endif |
diff --git a/noncore/net/mail/opiemail.cpp b/noncore/net/mail/opiemail.cpp index 7ab4e0d..9257866 100644 --- a/noncore/net/mail/opiemail.cpp +++ b/noncore/net/mail/opiemail.cpp | |||
@@ -1,55 +1,74 @@ | |||
1 | #include <qmessagebox.h> | ||
1 | #include "opiemail.h" | 2 | #include "opiemail.h" |
2 | #include "editaccounts.h" | 3 | #include "editaccounts.h" |
3 | #include "composemail.h" | 4 | #include "composemail.h" |
5 | #include "smtpwrapper.h" | ||
4 | 6 | ||
5 | OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags ) | 7 | OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags ) |
6 | : MainWindow( parent, name, flags ) | 8 | : MainWindow( parent, name, flags ) |
7 | { | 9 | { |
8 | settings = new Settings(); | 10 | settings = new Settings(); |
9 | 11 | ||
10 | folderView->populate( settings->getAccounts() ); | 12 | folderView->populate( settings->getAccounts() ); |
11 | 13 | ||
12 | connect( composeMail, SIGNAL( activated() ), SLOT( slotComposeMail() ) ); | 14 | connect( composeMail, SIGNAL( activated() ), SLOT( slotComposeMail() ) ); |
13 | connect( sendQueued, SIGNAL( activated() ), SLOT( slotSendQueued() ) ); | 15 | connect( sendQueued, SIGNAL( activated() ), SLOT( slotSendQueued() ) ); |
14 | // connect( searchMails, SIGNAL( activated() ), SLOT( slotSearchMails() ) ); | 16 | // connect( searchMails, SIGNAL( activated() ), SLOT( slotSearchMails() ) ); |
15 | connect( editSettings, SIGNAL( activated() ), SLOT( slotEditSettings() ) ); | 17 | connect( editSettings, SIGNAL( activated() ), SLOT( slotEditSettings() ) ); |
16 | connect( editAccounts, SIGNAL( activated() ), SLOT( slotEditAccounts() ) ); | 18 | connect( editAccounts, SIGNAL( activated() ), SLOT( slotEditAccounts() ) ); |
17 | } | 19 | } |
18 | 20 | ||
19 | void OpieMail::slotComposeMail() | 21 | void OpieMail::slotComposeMail() |
20 | { | 22 | { |
21 | qDebug( "Compose Mail" ); | 23 | qDebug( "Compose Mail" ); |
22 | ComposeMail compose( settings, this, 0 , true ); | 24 | ComposeMail compose( settings, this, 0 , true ); |
23 | compose.showMaximized(); | 25 | compose.showMaximized(); |
24 | compose.slotAdjustColumns(); | 26 | compose.slotAdjustColumns(); |
25 | compose.exec(); | 27 | compose.exec(); |
26 | } | 28 | } |
27 | 29 | ||
28 | void OpieMail::slotSendQueued() | 30 | void OpieMail::slotSendQueued() |
29 | { | 31 | { |
30 | qDebug( "Send Queued" ); | 32 | qDebug( "Send Queued" ); |
33 | SMTPaccount *smtp = 0; | ||
34 | |||
35 | QList<Account> list = settings->getAccounts(); | ||
36 | Account *it; | ||
37 | // if (list.count()==1) { | ||
38 | for ( it = list.first(); it; it = list.next() ) { | ||
39 | if ( it->getType().compare( "SMTP" ) == 0 ) { | ||
40 | smtp = static_cast<SMTPaccount *>(it); | ||
41 | break; | ||
42 | } | ||
43 | } | ||
44 | // } | ||
45 | if (smtp) { | ||
46 | SMTPwrapper * wrap = new SMTPwrapper(settings); | ||
47 | wrap->flushOutbox(smtp); | ||
48 | QMessageBox::information(0,tr("Info"),tr("Mail queue flushed")); | ||
49 | } | ||
31 | } | 50 | } |
32 | 51 | ||
33 | void OpieMail::slotSearchMails() | 52 | void OpieMail::slotSearchMails() |
34 | { | 53 | { |
35 | qDebug( "Search Mails" ); | 54 | qDebug( "Search Mails" ); |
36 | } | 55 | } |
37 | 56 | ||
38 | void OpieMail::slotEditSettings() | 57 | void OpieMail::slotEditSettings() |
39 | { | 58 | { |
40 | qDebug( "Edit Settings" ); | 59 | qDebug( "Edit Settings" ); |
41 | } | 60 | } |
42 | 61 | ||
43 | void OpieMail::slotEditAccounts() | 62 | void OpieMail::slotEditAccounts() |
44 | { | 63 | { |
45 | qDebug( "Edit Accounts" ); | 64 | qDebug( "Edit Accounts" ); |
46 | EditAccounts eaDialog( settings, this, 0, true ); | 65 | EditAccounts eaDialog( settings, this, 0, true ); |
47 | eaDialog.showMaximized(); | 66 | eaDialog.showMaximized(); |
48 | eaDialog.slotAdjustColumns(); | 67 | eaDialog.slotAdjustColumns(); |
49 | eaDialog.exec(); | 68 | eaDialog.exec(); |
50 | if ( settings ) delete settings; | 69 | if ( settings ) delete settings; |
51 | settings = new Settings(); | 70 | settings = new Settings(); |
52 | 71 | ||
53 | folderView->populate( settings->getAccounts() ); | 72 | folderView->populate( settings->getAccounts() ); |
54 | } | 73 | } |
55 | 74 | ||
diff --git a/noncore/net/mail/smtpwrapper.cpp b/noncore/net/mail/smtpwrapper.cpp index a6a46ba..b81a87f 100644 --- a/noncore/net/mail/smtpwrapper.cpp +++ b/noncore/net/mail/smtpwrapper.cpp | |||
@@ -1,84 +1,80 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
3 | #include <sys/types.h> | 3 | #include <sys/types.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <fcntl.h> | 5 | #include <fcntl.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | #include <qt.h> | ||
8 | 9 | ||
9 | #include <libetpan/libetpan.h> | 10 | #include <libetpan/libetpan.h> |
10 | #if 0 | ||
11 | #include <libetpan/mailimf.h> | ||
12 | #include <libetpan/mailsmtp.h> | ||
13 | #include <libetpan/mailstorage.h> | ||
14 | #include <libetpan/maildriver.h> | ||
15 | #endif | ||
16 | 11 | ||
17 | #include "smtpwrapper.h" | 12 | #include "smtpwrapper.h" |
18 | #include "mailwrapper.h" | 13 | #include "mailwrapper.h" |
19 | #include "mboxwrapper.h" | 14 | #include "mboxwrapper.h" |
20 | #include "logindialog.h" | 15 | #include "logindialog.h" |
16 | #include "mailtypes.h" | ||
21 | #include "defines.h" | 17 | #include "defines.h" |
22 | 18 | ||
23 | SMTPwrapper::SMTPwrapper( Settings *s ) | 19 | SMTPwrapper::SMTPwrapper( Settings *s ) |
24 | : QObject() | 20 | : QObject() |
25 | { | 21 | { |
26 | settings = s; | 22 | settings = s; |
27 | } | 23 | } |
28 | 24 | ||
29 | QString SMTPwrapper::mailsmtpError( int errnum ) | 25 | QString SMTPwrapper::mailsmtpError( int errnum ) |
30 | { | 26 | { |
31 | switch ( errnum ) { | 27 | switch ( errnum ) { |
32 | case MAILSMTP_NO_ERROR: | 28 | case MAILSMTP_NO_ERROR: |
33 | return tr( "No error" ); | 29 | return tr( "No error" ); |
34 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 30 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
35 | return tr( "Unexpected error code" ); | 31 | return tr( "Unexpected error code" ); |
36 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 32 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
37 | return tr( "Service not available" ); | 33 | return tr( "Service not available" ); |
38 | case MAILSMTP_ERROR_STREAM: | 34 | case MAILSMTP_ERROR_STREAM: |
39 | return tr( "Stream error" ); | 35 | return tr( "Stream error" ); |
40 | case MAILSMTP_ERROR_HOSTNAME: | 36 | case MAILSMTP_ERROR_HOSTNAME: |
41 | return tr( "gethostname() failed" ); | 37 | return tr( "gethostname() failed" ); |
42 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 38 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
43 | return tr( "Not implemented" ); | 39 | return tr( "Not implemented" ); |
44 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 40 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
45 | return tr( "Error, action not taken" ); | 41 | return tr( "Error, action not taken" ); |
46 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 42 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
47 | return tr( "Data exceeds storage allocation" ); | 43 | return tr( "Data exceeds storage allocation" ); |
48 | case MAILSMTP_ERROR_IN_PROCESSING: | 44 | case MAILSMTP_ERROR_IN_PROCESSING: |
49 | return tr( "Error in processing" ); | 45 | return tr( "Error in processing" ); |
50 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 46 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
51 | // return tr( "Insufficient system storage" ); | 47 | // return tr( "Insufficient system storage" ); |
52 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 48 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
53 | return tr( "Mailbox unavailable" ); | 49 | return tr( "Mailbox unavailable" ); |
54 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 50 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
55 | return tr( "Mailbox name not allowed" ); | 51 | return tr( "Mailbox name not allowed" ); |
56 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 52 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
57 | return tr( "Bad command sequence" ); | 53 | return tr( "Bad command sequence" ); |
58 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 54 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
59 | return tr( "User not local" ); | 55 | return tr( "User not local" ); |
60 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 56 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
61 | return tr( "Transaction failed" ); | 57 | return tr( "Transaction failed" ); |
62 | case MAILSMTP_ERROR_MEMORY: | 58 | case MAILSMTP_ERROR_MEMORY: |
63 | return tr( "Memory error" ); | 59 | return tr( "Memory error" ); |
64 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 60 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
65 | return tr( "Connection refused" ); | 61 | return tr( "Connection refused" ); |
66 | default: | 62 | default: |
67 | return tr( "Unknown error code" ); | 63 | return tr( "Unknown error code" ); |
68 | } | 64 | } |
69 | } | 65 | } |
70 | 66 | ||
71 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) | 67 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) |
72 | { | 68 | { |
73 | return mailimf_mailbox_new( strdup( name.latin1() ), | 69 | return mailimf_mailbox_new( strdup( name.latin1() ), |
74 | strdup( mail.latin1() ) ); | 70 | strdup( mail.latin1() ) ); |
75 | } | 71 | } |
76 | 72 | ||
77 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) | 73 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) |
78 | { | 74 | { |
79 | mailimf_address_list *addresses; | 75 | mailimf_address_list *addresses; |
80 | 76 | ||
81 | if ( addr.isEmpty() ) return NULL; | 77 | if ( addr.isEmpty() ) return NULL; |
82 | 78 | ||
83 | addresses = mailimf_address_list_new_empty(); | 79 | addresses = mailimf_address_list_new_empty(); |
84 | 80 | ||
@@ -147,499 +143,572 @@ err_free_fields: | |||
147 | mailimf_fields_free( fields ); | 143 | mailimf_fields_free( fields ); |
148 | err_free_reply: | 144 | err_free_reply: |
149 | mailimf_address_list_free( reply ); | 145 | mailimf_address_list_free( reply ); |
150 | mailimf_address_list_free( bcc ); | 146 | mailimf_address_list_free( bcc ); |
151 | mailimf_address_list_free( cc ); | 147 | mailimf_address_list_free( cc ); |
152 | mailimf_address_list_free( to ); | 148 | mailimf_address_list_free( to ); |
153 | err_free_from: | 149 | err_free_from: |
154 | mailimf_mailbox_list_free( from ); | 150 | mailimf_mailbox_list_free( from ); |
155 | err_free_fromBox: | 151 | err_free_fromBox: |
156 | mailimf_mailbox_free( fromBox ); | 152 | mailimf_mailbox_free( fromBox ); |
157 | err_free_sender: | 153 | err_free_sender: |
158 | mailimf_mailbox_free( sender ); | 154 | mailimf_mailbox_free( sender ); |
159 | err_free: | 155 | err_free: |
160 | free( subject ); | 156 | free( subject ); |
161 | qDebug( "createImfFields - error" ); | 157 | qDebug( "createImfFields - error" ); |
162 | 158 | ||
163 | return NULL; // Error :( | 159 | return NULL; // Error :( |
164 | } | 160 | } |
165 | 161 | ||
166 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | 162 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) |
167 | { | 163 | { |
168 | mailmime *txtPart; | 164 | mailmime *txtPart; |
169 | mailmime_fields *fields; | 165 | mailmime_fields *fields; |
170 | mailmime_content *content; | 166 | mailmime_content *content; |
171 | mailmime_parameter *param; | 167 | mailmime_parameter *param; |
172 | char *txt = strdup( str.latin1() ); | 168 | char *txt = strdup( str.latin1() ); |
173 | int err; | 169 | int err; |
174 | 170 | ||
175 | param = mailmime_parameter_new( strdup( "charset" ), | 171 | param = mailmime_parameter_new( strdup( "charset" ), |
176 | strdup( "iso-8859-1" ) ); | 172 | strdup( "iso-8859-1" ) ); |
177 | if ( param == NULL ) goto err_free; | 173 | if ( param == NULL ) goto err_free; |
178 | 174 | ||
179 | content = mailmime_content_new_with_str( "text/plain" ); | 175 | content = mailmime_content_new_with_str( "text/plain" ); |
180 | if ( content == NULL ) goto err_free_param; | 176 | if ( content == NULL ) goto err_free_param; |
181 | 177 | ||
182 | err = clist_append( content->ct_parameters, param ); | 178 | err = clist_append( content->ct_parameters, param ); |
183 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | 179 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; |
184 | 180 | ||
185 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); | 181 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); |
186 | if ( fields == NULL ) goto err_free_content; | 182 | if ( fields == NULL ) goto err_free_content; |
187 | 183 | ||
188 | txtPart = mailmime_new_empty( content, fields ); | 184 | txtPart = mailmime_new_empty( content, fields ); |
189 | if ( txtPart == NULL ) goto err_free_fields; | 185 | if ( txtPart == NULL ) goto err_free_fields; |
190 | 186 | ||
191 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); | 187 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); |
192 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 188 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
193 | 189 | ||
194 | return txtPart; // Success :) | 190 | return txtPart; // Success :) |
195 | 191 | ||
196 | err_free_txtPart: | 192 | err_free_txtPart: |
197 | mailmime_free( txtPart ); | 193 | mailmime_free( txtPart ); |
198 | err_free_fields: | 194 | err_free_fields: |
199 | mailmime_fields_free( fields ); | 195 | mailmime_fields_free( fields ); |
200 | err_free_content: | 196 | err_free_content: |
201 | mailmime_content_free( content ); | 197 | mailmime_content_free( content ); |
202 | err_free_param: | 198 | err_free_param: |
203 | mailmime_parameter_free( param ); | 199 | mailmime_parameter_free( param ); |
204 | err_free: | 200 | err_free: |
205 | free( txt ); | 201 | free( txt ); |
206 | qDebug( "buildTxtPart - error" ); | 202 | qDebug( "buildTxtPart - error" ); |
207 | 203 | ||
208 | return NULL; // Error :( | 204 | return NULL; // Error :( |
209 | } | 205 | } |
210 | 206 | ||
211 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype ) | 207 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) |
212 | { | 208 | { |
213 | mailmime * filePart; | 209 | mailmime * filePart = 0; |
214 | mailmime_fields * fields; | 210 | mailmime_fields * fields = 0; |
215 | mailmime_content * content; | 211 | mailmime_content * content = 0; |
216 | mailmime_parameter * param = NULL; | 212 | mailmime_parameter * param = 0; |
213 | char*name = 0; | ||
214 | char*file = 0; | ||
217 | int err; | 215 | int err; |
218 | 216 | ||
219 | int pos = filename.findRev( '/' ); | 217 | int pos = filename.findRev( '/' ); |
220 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 218 | |
221 | char *name = strdup( tmp.latin1() ); // just filename | 219 | if (filename.length()>0) { |
222 | char *file = strdup( filename.latin1() ); // full name with path | 220 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
221 | name = strdup( tmp.latin1() ); // just filename | ||
222 | file = strdup( filename.latin1() ); // full name with path | ||
223 | } | ||
223 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain | 224 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain |
224 | 225 | ||
225 | fields = mailmime_fields_new_filename( | 226 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; |
226 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, | 227 | int mechanism = MAILMIME_MECHANISM_BASE64; |
227 | MAILMIME_MECHANISM_BASE64 ); | 228 | |
228 | if ( fields == NULL ) goto err_free; | 229 | if ( mimetype.startsWith( "text/" ) ) { |
229 | |||
230 | content = mailmime_content_new_with_str( mime ); | ||
231 | if ( content == NULL ) goto err_free_fields; | ||
232 | |||
233 | if ( mimetype.compare( "text/plain" ) == 0 ) { | ||
234 | param = mailmime_parameter_new( strdup( "charset" ), | 230 | param = mailmime_parameter_new( strdup( "charset" ), |
235 | strdup( "iso-8859-1" ) ); | 231 | strdup( "iso-8859-1" ) ); |
236 | if ( param == NULL ) goto err_free_content; | 232 | disptype = MAILMIME_DISPOSITION_TYPE_INLINE; |
237 | 233 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | |
238 | err = clist_append( content->ct_parameters, param ); | ||
239 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; | ||
240 | } | 234 | } |
241 | 235 | ||
242 | filePart = mailmime_new_empty( content, fields ); | 236 | fields = mailmime_fields_new_filename( |
243 | if ( filePart == NULL ) goto err_free_param; | 237 | disptype, name, |
244 | 238 | mechanism ); | |
245 | err = mailmime_set_body_file( filePart, file ); | 239 | content = mailmime_content_new_with_str( mime ); |
246 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 240 | if (content!=0 && fields != 0) { |
241 | if (param) { | ||
242 | clist_append(content->ct_parameters,param); | ||
243 | param = 0; | ||
244 | } | ||
245 | if (filename.length()>0) { | ||
246 | QFileInfo f(filename); | ||
247 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); | ||
248 | clist_append(content->ct_parameters,param); | ||
249 | param = 0; | ||
250 | } | ||
251 | filePart = mailmime_new_empty( content, fields ); | ||
252 | } | ||
253 | if (filePart) { | ||
254 | if (filename.length()>0) { | ||
255 | err = mailmime_set_body_file( filePart, file ); | ||
256 | } else { | ||
257 | err = mailmime_set_body_text(filePart,strdup(TextContent.ascii()),TextContent.length()); | ||
258 | } | ||
259 | if (err != MAILIMF_NO_ERROR) { | ||
260 | qDebug("Error setting body with file %s",file); | ||
261 | mailmime_free( filePart ); | ||
262 | filePart = 0; | ||
263 | } | ||
264 | } | ||
247 | 265 | ||
266 | if (!filePart) { | ||
267 | if ( param != NULL ) { | ||
268 | mailmime_parameter_free( param ); | ||
269 | } | ||
270 | if (content) { | ||
271 | mailmime_content_free( content ); | ||
272 | } else { | ||
273 | if (mime) { | ||
274 | free( mime ); | ||
275 | } | ||
276 | } | ||
277 | if (fields) { | ||
278 | mailmime_fields_free( fields ); | ||
279 | } else { | ||
280 | if (name) { | ||
281 | free( name ); | ||
282 | } | ||
283 | if (file) { | ||
284 | free( file ); | ||
285 | } | ||
286 | } | ||
287 | } | ||
248 | return filePart; // Success :) | 288 | return filePart; // Success :) |
249 | 289 | ||
250 | err_free_filePart: | ||
251 | mailmime_free( filePart ); | ||
252 | err_free_param: | ||
253 | if ( param != NULL ) mailmime_parameter_free( param ); | ||
254 | err_free_content: | ||
255 | mailmime_content_free( content ); | ||
256 | err_free_fields: | ||
257 | mailmime_fields_free( fields ); | ||
258 | err_free: | ||
259 | free( name ); | ||
260 | free( mime ); | ||
261 | free( file ); | ||
262 | qDebug( "buildFilePart - error" ); | ||
263 | |||
264 | return NULL; // Error :( | ||
265 | } | 290 | } |
266 | 291 | ||
267 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) | 292 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) |
268 | { | 293 | { |
269 | const Attachment *it; | 294 | const Attachment *it; |
270 | /* work around for the brainfucked qlist which can not act with const values */ | 295 | unsigned int count = files.count(); |
271 | for ( it = ((QList<Attachment>)files).first(); it; it = ((QList<Attachment>)files).next() ) { | 296 | qDebug("List contains %i values",count); |
297 | for ( unsigned int i = 0; i < count; ++i ) { | ||
272 | qDebug( "Adding file" ); | 298 | qDebug( "Adding file" ); |
273 | mailmime *filePart; | 299 | mailmime *filePart; |
274 | int err; | 300 | int err; |
301 | it = ((QList<Attachment>)files).at(i); | ||
275 | 302 | ||
276 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); | 303 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); |
277 | if ( filePart == NULL ) goto err_free; | 304 | if ( filePart == NULL ) { |
278 | 305 | qDebug( "addFileParts: error adding file:" ); | |
306 | qDebug( it->getFileName() ); | ||
307 | continue; | ||
308 | } | ||
279 | err = mailmime_smart_add_part( message, filePart ); | 309 | err = mailmime_smart_add_part( message, filePart ); |
280 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 310 | if ( err != MAILIMF_NO_ERROR ) { |
281 | 311 | mailmime_free( filePart ); | |
282 | continue; // Success :) | 312 | qDebug("error smart add"); |
283 | 313 | } | |
284 | err_free_filePart: | ||
285 | mailmime_free( filePart ); | ||
286 | err_free: | ||
287 | qDebug( "addFileParts: error adding file:" ); | ||
288 | qDebug( it->getFileName() ); | ||
289 | } | 314 | } |
290 | } | 315 | } |
291 | 316 | ||
292 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) | 317 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) |
293 | { | 318 | { |
294 | mailmime *message, *txtPart; | 319 | mailmime *message, *txtPart; |
295 | mailimf_fields *fields; | 320 | mailimf_fields *fields; |
296 | int err; | 321 | int err; |
297 | 322 | ||
298 | fields = createImfFields( mail ); | 323 | fields = createImfFields( mail ); |
299 | if ( fields == NULL ) goto err_free; | 324 | if ( fields == NULL ) goto err_free; |
300 | 325 | ||
301 | message = mailmime_new_message_data( NULL ); | 326 | message = mailmime_new_message_data( NULL ); |
302 | if ( message == NULL ) goto err_free_fields; | 327 | if ( message == NULL ) goto err_free_fields; |
303 | 328 | ||
304 | mailmime_set_imf_fields( message, fields ); | 329 | mailmime_set_imf_fields( message, fields ); |
305 | 330 | ||
306 | txtPart = buildTxtPart( mail.getMessage() ); | 331 | if (mail.getAttachments().count()==0) { |
332 | txtPart = buildTxtPart( mail.getMessage() ); | ||
333 | } else { | ||
334 | txtPart = buildFilePart("","text/plain",mail.getMessage()); | ||
335 | } | ||
307 | if ( txtPart == NULL ) goto err_free_message; | 336 | if ( txtPart == NULL ) goto err_free_message; |
308 | 337 | ||
309 | err = mailmime_smart_add_part( message, txtPart ); | 338 | err = mailmime_smart_add_part( message, txtPart ); |
310 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 339 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
311 | 340 | ||
312 | addFileParts( message, mail.getAttachments() ); | 341 | addFileParts( message, mail.getAttachments() ); |
313 | 342 | ||
314 | return message; // Success :) | 343 | return message; // Success :) |
315 | 344 | ||
316 | err_free_txtPart: | 345 | err_free_txtPart: |
317 | mailmime_free( txtPart ); | 346 | mailmime_free( txtPart ); |
318 | err_free_message: | 347 | err_free_message: |
319 | mailmime_free( message ); | 348 | mailmime_free( message ); |
320 | err_free_fields: | 349 | err_free_fields: |
321 | mailimf_fields_free( fields ); | 350 | mailimf_fields_free( fields ); |
322 | err_free: | 351 | err_free: |
323 | qDebug( "createMimeMail: error" ); | 352 | qDebug( "createMimeMail: error" ); |
324 | 353 | ||
325 | return NULL; // Error :( | 354 | return NULL; // Error :( |
326 | } | 355 | } |
327 | 356 | ||
328 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) | 357 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) |
329 | { | 358 | { |
330 | mailimf_field *field; | 359 | mailimf_field *field; |
331 | clistiter *it; | 360 | clistiter *it; |
332 | 361 | ||
333 | it = clist_begin( fields->fld_list ); | 362 | it = clist_begin( fields->fld_list ); |
334 | while ( it ) { | 363 | while ( it ) { |
335 | field = (mailimf_field *) it->data; | 364 | field = (mailimf_field *) it->data; |
336 | if ( field->fld_type == type ) { | 365 | if ( field->fld_type == type ) { |
337 | return field; | 366 | return field; |
338 | } | 367 | } |
339 | it = it->next; | 368 | it = it->next; |
340 | } | 369 | } |
341 | 370 | ||
342 | return NULL; | 371 | return NULL; |
343 | } | 372 | } |
344 | 373 | ||
345 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) | 374 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) |
346 | { | 375 | { |
347 | clistiter *it, *it2; | 376 | clistiter *it, *it2; |
348 | 377 | ||
349 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | 378 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { |
350 | mailimf_address *addr; | 379 | mailimf_address *addr; |
351 | addr = (mailimf_address *) it->data; | 380 | addr = (mailimf_address *) it->data; |
352 | 381 | ||
353 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | 382 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { |
354 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | 383 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); |
355 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { | 384 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { |
356 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | 385 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; |
357 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | 386 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { |
358 | mailimf_mailbox *mbox; | 387 | mailimf_mailbox *mbox; |
359 | mbox = (mailimf_mailbox *) it2->data; | 388 | mbox = (mailimf_mailbox *) it2->data; |
360 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | 389 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); |
361 | } | 390 | } |
362 | } | 391 | } |
363 | } | 392 | } |
364 | } | 393 | } |
365 | 394 | ||
366 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) | 395 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) |
367 | { | 396 | { |
368 | clist *rcptList; | 397 | clist *rcptList; |
369 | mailimf_field *field; | 398 | mailimf_field *field; |
370 | 399 | ||
371 | rcptList = esmtp_address_list_new(); | 400 | rcptList = esmtp_address_list_new(); |
372 | 401 | ||
373 | field = getField( fields, MAILIMF_FIELD_TO ); | 402 | field = getField( fields, MAILIMF_FIELD_TO ); |
374 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) | 403 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) |
375 | && field->fld_data.fld_to->to_addr_list ) { | 404 | && field->fld_data.fld_to->to_addr_list ) { |
376 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); | 405 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); |
377 | } | 406 | } |
378 | 407 | ||
379 | field = getField( fields, MAILIMF_FIELD_CC ); | 408 | field = getField( fields, MAILIMF_FIELD_CC ); |
380 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) | 409 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) |
381 | && field->fld_data.fld_cc->cc_addr_list ) { | 410 | && field->fld_data.fld_cc->cc_addr_list ) { |
382 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); | 411 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); |
383 | } | 412 | } |
384 | 413 | ||
385 | field = getField( fields, MAILIMF_FIELD_BCC ); | 414 | field = getField( fields, MAILIMF_FIELD_BCC ); |
386 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) | 415 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) |
387 | && field->fld_data.fld_bcc->bcc_addr_list ) { | 416 | && field->fld_data.fld_bcc->bcc_addr_list ) { |
388 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); | 417 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); |
389 | } | 418 | } |
390 | 419 | ||
391 | return rcptList; | 420 | return rcptList; |
392 | } | 421 | } |
393 | 422 | ||
394 | char *SMTPwrapper::getFrom( mailmime *mail ) | 423 | char *SMTPwrapper::getFrom( mailimf_field *ffrom) |
395 | { | 424 | { |
396 | char *from = NULL; | 425 | char *from = NULL; |
397 | |||
398 | mailimf_field *ffrom; | ||
399 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | ||
400 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 426 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) |
401 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | 427 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { |
402 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | 428 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; |
403 | clistiter *it; | 429 | clistiter *it; |
404 | for ( it = clist_begin( cl ); it; it = it->next ) { | 430 | for ( it = clist_begin( cl ); it; it = it->next ) { |
405 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 431 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
406 | from = strdup( mb->mb_addr_spec ); | 432 | from = strdup( mb->mb_addr_spec ); |
407 | } | 433 | } |
408 | } | 434 | } |
409 | 435 | ||
410 | return from; | 436 | return from; |
411 | } | 437 | } |
412 | 438 | ||
413 | SMTPaccount *SMTPwrapper::getAccount(const QString&from ) | 439 | char *SMTPwrapper::getFrom( mailmime *mail ) |
440 | { | ||
441 | mailimf_field *ffrom = 0; | ||
442 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | ||
443 | return getFrom(ffrom); | ||
444 | } | ||
445 | |||
446 | SMTPaccount *SMTPwrapper::getAccount(const QString&name ) | ||
414 | { | 447 | { |
415 | SMTPaccount *smtp; | 448 | SMTPaccount *smtp; |
416 | 449 | ||
417 | QList<Account> list = settings->getAccounts(); | 450 | QList<Account> list = settings->getAccounts(); |
418 | Account *it; | 451 | Account *it; |
419 | for ( it = list.first(); it; it = list.next() ) { | 452 | for ( it = list.first(); it; it = list.next() ) { |
420 | if ( it->getType().compare( "SMTP" ) == 0 ) { | 453 | if ( it->getType().compare( "SMTP" ) == 0 ) { |
421 | smtp = static_cast<SMTPaccount *>(it); | 454 | smtp = static_cast<SMTPaccount *>(it); |
422 | if ( smtp->getMail().compare( from ) == 0 ) { | 455 | if ( smtp->getName()== name ) { |
423 | qDebug( "SMTPaccount found for" ); | 456 | qDebug( "SMTPaccount found for" ); |
424 | qDebug( from ); | 457 | qDebug( name ); |
425 | return smtp; | 458 | return smtp; |
426 | } | 459 | } |
427 | } | 460 | } |
428 | } | 461 | } |
429 | 462 | ||
430 | return NULL; | 463 | return NULL; |
431 | } | 464 | } |
432 | 465 | ||
433 | QString SMTPwrapper::getTmpFile() { | 466 | QString SMTPwrapper::getTmpFile() { |
434 | int num = 0; | 467 | int num = 0; |
435 | QString unique; | 468 | QString unique; |
436 | 469 | ||
437 | QDir dir( "/tmp" ); | 470 | QDir dir( "/tmp" ); |
438 | QStringList::Iterator it; | ||
439 | 471 | ||
440 | QStringList list = dir.entryList( "opiemail-tmp-*" ); | 472 | QStringList list = dir.entryList( "opiemail-tmp-*" ); |
473 | |||
441 | do { | 474 | do { |
442 | unique.setNum( num++ ); | 475 | unique.setNum( num++ ); |
443 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); | 476 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); |
444 | 477 | ||
445 | return "/tmp/opiemail-tmp-" + unique; | 478 | return "/tmp/opiemail-tmp-" + unique; |
446 | } | 479 | } |
447 | 480 | ||
448 | void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) | 481 | void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) |
449 | { | 482 | { |
450 | FILE *f; | 483 | FILE *f; |
451 | int err, col = 0; | 484 | int err, col = 0; |
452 | 485 | ||
453 | f = fopen( file.latin1(), "w" ); | 486 | f = fopen( file.latin1(), "w" ); |
454 | if ( f == NULL ) { | 487 | if ( f == NULL ) { |
455 | qDebug( "writeToFile: error opening file" ); | 488 | qDebug( "writeToFile: error opening file" ); |
456 | return; | 489 | return; |
457 | } | 490 | } |
458 | 491 | ||
459 | err = mailmime_write( f, &col, mail ); | 492 | err = mailmime_write( f, &col, mail ); |
460 | if ( err != MAILIMF_NO_ERROR ) { | 493 | if ( err != MAILIMF_NO_ERROR ) { |
461 | fclose( f ); | 494 | fclose( f ); |
462 | qDebug( "writeToFile: error writing mailmime" ); | 495 | qDebug( "writeToFile: error writing mailmime" ); |
463 | return; | 496 | return; |
464 | } | 497 | } |
465 | 498 | ||
466 | fclose( f ); | 499 | fclose( f ); |
467 | } | 500 | } |
468 | 501 | ||
469 | void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) | 502 | void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) |
470 | { | 503 | { |
471 | 504 | ||
472 | QFile msg_cache(file); | 505 | QFile msg_cache(file); |
473 | QString msg = ""; | 506 | QString msg = ""; |
474 | msg_cache.open(IO_ReadOnly); | 507 | msg_cache.open(IO_ReadOnly); |
475 | char*message = new char[4096]; | 508 | char*message = new char[4096]; |
476 | memset(message,0,4096); | 509 | memset(message,0,4096); |
477 | while (msg_cache.readBlock(message,4095)>0) { | 510 | while (msg_cache.readBlock(message,4095)>0) { |
478 | msg+=message; | 511 | msg+=message; |
479 | memset(message,0,4096); | 512 | memset(message,0,4096); |
480 | } | 513 | } |
481 | delete message; | 514 | delete message; |
482 | *data = (char*)malloc(msg.length()+1*sizeof(char)); | 515 | *data = (char*)malloc(msg.length()+1*sizeof(char)); |
483 | memset(*data,0,msg.length()+1); | 516 | memset(*data,0,msg.length()+1); |
484 | memcpy(*data,msg.ascii(),msg.length()); | 517 | memcpy(*data,msg.ascii(),msg.length()); |
485 | *size=msg.length(); | 518 | *size=msg.length(); |
486 | |||
487 | #if 0 | ||
488 | char *buf; | ||
489 | struct stat st; | ||
490 | int fd, count = 0, total = 0; | ||
491 | |||
492 | fd = open( file.latin1(), O_RDONLY, 0 ); | ||
493 | if ( fd == -1 ) return; | ||
494 | |||
495 | if ( fstat( fd, &st ) != 0 ) goto err_close; | ||
496 | if ( !st.st_size ) goto err_close; | ||
497 | |||
498 | buf = (char *) malloc( st.st_size ); | ||
499 | if ( !buf ) goto err_close; | ||
500 | |||
501 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { | ||
502 | count = read( fd, buf + total, st.st_size - total ); | ||
503 | total += count; | ||
504 | } | ||
505 | if ( count < 0 ) goto err_free; | ||
506 | |||
507 | *data = buf; | ||
508 | *size = st.st_size; | ||
509 | |||
510 | close( fd ); | ||
511 | |||
512 | return; // Success :) | ||
513 | |||
514 | err_free: | ||
515 | free( buf ); | ||
516 | err_close: | ||
517 | close( fd ); | ||
518 | #endif | ||
519 | } | 519 | } |
520 | 520 | ||
521 | void SMTPwrapper::progress( size_t current, size_t maximum ) | 521 | void SMTPwrapper::progress( size_t current, size_t maximum ) |
522 | { | 522 | { |
523 | qDebug( "Current: %i of %i", current, maximum ); | 523 | // qDebug( "Current: %i of %i", current, maximum ); |
524 | } | 524 | } |
525 | 525 | ||
526 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) | 526 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) |
527 | { | 527 | { |
528 | if (!mail) return; | 528 | if (!mail) return; |
529 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | 529 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); |
530 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | 530 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); |
531 | wrap->storeMessage(mail,length,box); | 531 | wrap->storeMessage(mail,length,box); |
532 | delete wrap; | 532 | delete wrap; |
533 | } | 533 | } |
534 | 534 | ||
535 | void SMTPwrapper::smtpSend( mailmime *mail,bool later ) | 535 | void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) |
536 | { | 536 | { |
537 | mailsmtp *session; | 537 | clist *rcpts = 0; |
538 | clist *rcpts; | 538 | char *from, *data; |
539 | char *from, *data, *server, *user = NULL, *pass = NULL; | ||
540 | size_t size; | 539 | size_t size; |
541 | int err; | ||
542 | bool ssl; | ||
543 | uint16_t port; | ||
544 | 540 | ||
545 | |||
546 | from = getFrom( mail ); | ||
547 | SMTPaccount *smtp = getAccount( from ); | ||
548 | if ( smtp == NULL ) { | 541 | if ( smtp == NULL ) { |
549 | free(from); | ||
550 | return; | 542 | return; |
551 | } | 543 | } |
552 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 544 | from = data = 0; |
553 | 545 | ||
554 | QString file = getTmpFile(); | 546 | QString file = getTmpFile(); |
555 | writeToFile( file, mail ); | 547 | writeToFile( file, mail ); |
556 | |||
557 | readFromFile( file, &data, &size ); | 548 | readFromFile( file, &data, &size ); |
558 | QFile f( file ); | 549 | QFile f( file ); |
559 | f.remove(); | 550 | f.remove(); |
560 | 551 | ||
561 | storeMail(data,size,(later?"Outgoing":"Sent")); | ||
562 | |||
563 | if (later) { | 552 | if (later) { |
564 | smtp_address_list_free( rcpts ); | 553 | storeMail(data,size,"Outgoing"); |
565 | if (data) free( data ); | 554 | if (data) free( data ); |
566 | if (from) free(from); | ||
567 | return; | 555 | return; |
568 | } | 556 | } |
557 | from = getFrom( mail ); | ||
558 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | ||
559 | smtpSend(from,rcpts,data,size,smtp); | ||
560 | } | ||
561 | |||
562 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) | ||
563 | { | ||
564 | char *server, *user, *pass; | ||
565 | bool ssl; | ||
566 | uint16_t port; | ||
567 | mailsmtp *session; | ||
568 | int err,result; | ||
569 | |||
570 | result = 1; | ||
571 | server = user = pass = 0; | ||
569 | server = strdup( smtp->getServer().latin1() ); | 572 | server = strdup( smtp->getServer().latin1() ); |
570 | ssl = smtp->getSSL(); | 573 | ssl = smtp->getSSL(); |
571 | port = smtp->getPort().toUInt(); | 574 | port = smtp->getPort().toUInt(); |
572 | 575 | ||
573 | session = mailsmtp_new( 20, &progress ); | 576 | session = mailsmtp_new( 20, &progress ); |
574 | if ( session == NULL ) goto free_mem; | 577 | if ( session == NULL ) goto free_mem; |
575 | 578 | ||
576 | qDebug( "Servername %s at port %i", server, port ); | 579 | qDebug( "Servername %s at port %i", server, port ); |
577 | if ( ssl ) { | 580 | if ( ssl ) { |
578 | qDebug( "SSL session" ); | 581 | qDebug( "SSL session" ); |
579 | err = mailsmtp_ssl_connect( session, server, port ); | 582 | err = mailsmtp_ssl_connect( session, server, port ); |
580 | } else { | 583 | } else { |
581 | qDebug( "No SSL session" ); | 584 | qDebug( "No SSL session" ); |
582 | err = mailsmtp_socket_connect( session, server, port ); | 585 | err = mailsmtp_socket_connect( session, server, port ); |
583 | } | 586 | } |
584 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; | 587 | if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} |
585 | 588 | ||
586 | err = mailsmtp_init( session ); | 589 | err = mailsmtp_init( session ); |
587 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 590 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} |
588 | 591 | ||
589 | qDebug( "INIT OK" ); | 592 | qDebug( "INIT OK" ); |
590 | 593 | ||
591 | if ( smtp->getLogin() ) { | 594 | if ( smtp->getLogin() ) { |
592 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | 595 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { |
593 | // get'em | 596 | // get'em |
594 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | 597 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); |
595 | login.show(); | 598 | login.show(); |
596 | if ( QDialog::Accepted == login.exec() ) { | 599 | if ( QDialog::Accepted == login.exec() ) { |
597 | // ok | 600 | // ok |
598 | user = strdup( login.getUser().latin1() ); | 601 | user = strdup( login.getUser().latin1() ); |
599 | pass = strdup( login.getPassword().latin1() ); | 602 | pass = strdup( login.getPassword().latin1() ); |
600 | } else { | 603 | } else { |
601 | goto free_con_session; | 604 | result = 0; goto free_con_session; |
602 | } | 605 | } |
603 | } else { | 606 | } else { |
604 | user = strdup( smtp->getUser().latin1() ); | 607 | user = strdup( smtp->getUser().latin1() ); |
605 | pass = strdup( smtp->getPassword().latin1() ); | 608 | pass = strdup( smtp->getPassword().latin1() ); |
606 | } | 609 | } |
607 | qDebug( "session->auth: %i", session->auth); | 610 | qDebug( "session->auth: %i", session->auth); |
608 | err = mailsmtp_auth( session, user, pass ); | 611 | err = mailsmtp_auth( session, user, pass ); |
609 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); | 612 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); |
610 | qDebug( "Done auth!" ); | 613 | qDebug( "Done auth!" ); |
611 | } | 614 | } |
612 | 615 | ||
613 | err = mailsmtp_send( session, from, rcpts, data, size ); | 616 | err = mailsmtp_send( session, from, rcpts, data, size ); |
614 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 617 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} |
615 | 618 | ||
616 | qDebug( "Mail sent." ); | 619 | qDebug( "Mail sent." ); |
620 | storeMail(data,size,"Sent"); | ||
617 | 621 | ||
618 | free_con_session: | 622 | free_con_session: |
619 | mailsmtp_quit( session ); | 623 | mailsmtp_quit( session ); |
620 | free_mem_session: | 624 | free_mem_session: |
621 | mailsmtp_free( session ); | 625 | mailsmtp_free( session ); |
622 | free_mem: | 626 | free_mem: |
623 | smtp_address_list_free( rcpts ); | 627 | if (rcpts) smtp_address_list_free( rcpts ); |
624 | if (data) free( data ); | 628 | if (data) free( data ); |
625 | if (from) free(from); | ||
626 | if (server) free( server ); | 629 | if (server) free( server ); |
630 | if (from) free( from ); | ||
627 | if ( smtp->getLogin() ) { | 631 | if ( smtp->getLogin() ) { |
628 | free( user ); | 632 | free( user ); |
629 | free( pass ); | 633 | free( pass ); |
630 | } | 634 | } |
631 | free( from ); | 635 | return result; |
632 | } | 636 | } |
633 | 637 | ||
634 | void SMTPwrapper::sendMail(const Mail&mail,bool later ) | 638 | void SMTPwrapper::sendMail(const Mail&mail,bool later ) |
635 | { | 639 | { |
636 | mailmime * mimeMail; | 640 | mailmime * mimeMail; |
637 | 641 | ||
642 | SMTPaccount *smtp = getAccount(mail.getName()); | ||
643 | |||
638 | mimeMail = createMimeMail(mail ); | 644 | mimeMail = createMimeMail(mail ); |
639 | if ( mimeMail == NULL ) { | 645 | if ( mimeMail == NULL ) { |
640 | qDebug( "sendMail: error creating mime mail" ); | 646 | qDebug( "sendMail: error creating mime mail" ); |
641 | } else { | 647 | } else { |
642 | smtpSend( mimeMail,later ); | 648 | smtpSend( mimeMail,later,smtp); |
643 | mailmime_free( mimeMail ); | 649 | mailmime_free( mimeMail ); |
650 | qDebug("Clean up done"); | ||
651 | } | ||
652 | } | ||
653 | |||
654 | int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) | ||
655 | { | ||
656 | char*data = 0; | ||
657 | size_t length = 0; | ||
658 | size_t curTok = 0; | ||
659 | mailimf_fields *fields = 0; | ||
660 | mailimf_field*ffrom = 0; | ||
661 | clist *rcpts = 0; | ||
662 | char*from = 0; | ||
663 | |||
664 | wrap->fetchRawBody(*which,&data,&length); | ||
665 | if (!data) return 0; | ||
666 | int err = mailimf_fields_parse( data, length, &curTok, &fields ); | ||
667 | if (err != MAILIMF_NO_ERROR) { | ||
668 | free(data); | ||
669 | delete wrap; | ||
670 | return 0; | ||
671 | } | ||
672 | |||
673 | rcpts = createRcptList( fields ); | ||
674 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); | ||
675 | from = getFrom(ffrom); | ||
676 | qDebug("Size: %i vs. %i",length,strlen(data)); | ||
677 | if (rcpts && from) { | ||
678 | return smtpSend(from,rcpts,data,strlen(data),smtp ); | ||
644 | } | 679 | } |
680 | return 0; | ||
681 | } | ||
682 | |||
683 | /* this is a special fun */ | ||
684 | void SMTPwrapper::flushOutbox(SMTPaccount*smtp) | ||
685 | { | ||
686 | if (!smtp) return; | ||
687 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | ||
688 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | ||
689 | if (!wrap) { | ||
690 | qDebug("memory error"); | ||
691 | return; | ||
692 | } | ||
693 | QList<RecMail> mailsToSend; | ||
694 | QList<RecMail> mailsToRemove; | ||
695 | QString mbox("Outgoing"); | ||
696 | wrap->listMessages(mbox,mailsToSend); | ||
697 | if (mailsToSend.count()==0) { | ||
698 | delete wrap; | ||
699 | return; | ||
700 | } | ||
701 | mailsToSend.setAutoDelete(false); | ||
702 | while (mailsToSend.count()>0) { | ||
703 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { | ||
704 | QMessageBox::critical(0,tr("Error sending mail"), | ||
705 | tr("Error sending queued mail - breaking")); | ||
706 | break; | ||
707 | } | ||
708 | mailsToRemove.append(mailsToSend.at(0)); | ||
709 | mailsToSend.removeFirst(); | ||
710 | } | ||
711 | wrap->deleteMails(mbox,mailsToRemove); | ||
712 | mailsToSend.setAutoDelete(true); | ||
713 | delete wrap; | ||
645 | } | 714 | } |
diff --git a/noncore/net/mail/smtpwrapper.h b/noncore/net/mail/smtpwrapper.h index 41e9a8c..c0dcc11 100644 --- a/noncore/net/mail/smtpwrapper.h +++ b/noncore/net/mail/smtpwrapper.h | |||
@@ -1,55 +1,63 @@ | |||
1 | #ifndef SMTPwrapper_H | 1 | #ifndef SMTPwrapper_H |
2 | #define SMTPwrapper_H | 2 | #define SMTPwrapper_H |
3 | 3 | ||
4 | #include <qpe/applnk.h> | 4 | #include <qpe/applnk.h> |
5 | 5 | ||
6 | #include <qbitarray.h> | 6 | #include <qbitarray.h> |
7 | #include <qdatetime.h> | 7 | #include <qdatetime.h> |
8 | #include <libetpan/clist.h> | 8 | #include <libetpan/clist.h> |
9 | 9 | ||
10 | #include "settings.h" | 10 | #include "settings.h" |
11 | 11 | ||
12 | class Mail; | 12 | class Mail; |
13 | class MBOXwrapper; | ||
14 | class RecMail; | ||
13 | class Attachment; | 15 | class Attachment; |
14 | struct mailimf_fields; | 16 | struct mailimf_fields; |
15 | struct mailimf_field; | 17 | struct mailimf_field; |
16 | struct mailimf_mailbox; | 18 | struct mailimf_mailbox; |
17 | struct mailmime; | 19 | struct mailmime; |
18 | struct mailimf_address_list; | 20 | struct mailimf_address_list; |
19 | 21 | ||
20 | class SMTPwrapper : public QObject | 22 | class SMTPwrapper : public QObject |
21 | { | 23 | { |
22 | Q_OBJECT | 24 | Q_OBJECT |
23 | 25 | ||
24 | public: | 26 | public: |
25 | SMTPwrapper( Settings *s ); | 27 | SMTPwrapper( Settings *s ); |
26 | virtual ~SMTPwrapper(){} | 28 | virtual ~SMTPwrapper(){} |
27 | void sendMail(const Mail& mail,bool later=false ); | 29 | void sendMail(const Mail& mail,bool later=false ); |
30 | void flushOutbox(SMTPaccount*smtp); | ||
28 | 31 | ||
29 | protected: | 32 | protected: |
30 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | 33 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); |
31 | mailimf_fields *createImfFields(const Mail &mail ); | 34 | mailimf_fields *createImfFields(const Mail &mail ); |
32 | mailmime *createMimeMail(const Mail&mail ); | 35 | mailmime *createMimeMail(const Mail&mail ); |
33 | 36 | ||
34 | mailimf_address_list *parseAddresses(const QString&addr ); | 37 | mailimf_address_list *parseAddresses(const QString&addr ); |
35 | void addFileParts( mailmime *message,const QList<Attachment>&files ); | 38 | void addFileParts( mailmime *message,const QList<Attachment>&files ); |
36 | mailmime *buildTxtPart(const QString&str ); | 39 | mailmime *buildTxtPart(const QString&str ); |
37 | mailmime *buildFilePart(const QString&filename,const QString&mimetype ); | 40 | mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); |
38 | void smtpSend( mailmime *mail,bool later ); | 41 | void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); |
39 | mailimf_field *getField( mailimf_fields *fields, int type ); | ||
40 | clist *createRcptList( mailimf_fields *fields ); | 42 | clist *createRcptList( mailimf_fields *fields ); |
41 | char *getFrom( mailmime *mail ); | ||
42 | SMTPaccount *getAccount(const QString&from ); | 43 | SMTPaccount *getAccount(const QString&from ); |
43 | void writeToFile(const QString&file, mailmime *mail ); | 44 | void writeToFile(const QString&file, mailmime *mail ); |
44 | void readFromFile(const QString&file, char **data, size_t *size ); | 45 | void readFromFile(const QString&file, char **data, size_t *size ); |
45 | void storeMail(char*mail, size_t length, const QString&box); | ||
46 | 46 | ||
47 | static void storeMail(char*mail, size_t length, const QString&box); | ||
47 | static QString mailsmtpError( int err ); | 48 | static QString mailsmtpError( int err ); |
48 | static QString getTmpFile(); | 49 | static QString getTmpFile(); |
49 | static void progress( size_t current, size_t maximum ); | 50 | static void progress( size_t current, size_t maximum ); |
50 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); | 51 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); |
52 | static char *getFrom( mailmime *mail ); | ||
53 | static char *getFrom( mailimf_field *ffrom); | ||
54 | static mailimf_field *getField( mailimf_fields *fields, int type ); | ||
55 | static int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); | ||
56 | |||
51 | void storeMail(mailmime*mail, const QString&box); | 57 | void storeMail(mailmime*mail, const QString&box); |
52 | Settings *settings; | 58 | Settings *settings; |
59 | |||
60 | int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); | ||
53 | }; | 61 | }; |
54 | 62 | ||
55 | #endif | 63 | #endif |