-rw-r--r-- | kmicromail/libmailwrapper/abstractmail.cpp | 3 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/smtpwrapper.cpp | 7 |
2 files changed, 8 insertions, 2 deletions
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp index ed5c898..870985e 100644 --- a/kmicromail/libmailwrapper/abstractmail.cpp +++ b/kmicromail/libmailwrapper/abstractmail.cpp | |||
@@ -1,279 +1,282 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include "abstractmail.h" | 2 | #include "abstractmail.h" |
3 | #include "imapwrapper.h" | 3 | #include "imapwrapper.h" |
4 | #include "pop3wrapper.h" | 4 | #include "pop3wrapper.h" |
5 | #include "nntpwrapper.h" | 5 | #include "nntpwrapper.h" |
6 | #include "mhwrapper.h" | 6 | #include "mhwrapper.h" |
7 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
8 | #include <qpe/global.h> | 8 | #include <qpe/global.h> |
9 | 9 | ||
10 | 10 | ||
11 | #include <qprogressbar.h> | 11 | #include <qprogressbar.h> |
12 | #include <qapplication.h> | 12 | #include <qapplication.h> |
13 | #include <qmessagebox.h> | 13 | #include <qmessagebox.h> |
14 | #include <klocale.h> | 14 | #include <klocale.h> |
15 | #include <kdecore/kstandarddirs.h> | 15 | #include <kdecore/kstandarddirs.h> |
16 | #include <qfile.h> | 16 | #include <qfile.h> |
17 | #include <qtextstream.h> | 17 | #include <qtextstream.h> |
18 | #include <stdlib.h> | 18 | #include <stdlib.h> |
19 | #include <libetpan/mailmime_content.h> | 19 | #include <libetpan/mailmime_content.h> |
20 | #include <libetpan/mailmime.h> | 20 | #include <libetpan/mailmime.h> |
21 | 21 | ||
22 | using namespace Opie::Core; | 22 | using namespace Opie::Core; |
23 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) | 23 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) |
24 | { | 24 | { |
25 | return new IMAPwrapper(a); | 25 | return new IMAPwrapper(a); |
26 | } | 26 | } |
27 | 27 | ||
28 | AbstractMail* AbstractMail::getWrapper(POP3account *a) | 28 | AbstractMail* AbstractMail::getWrapper(POP3account *a) |
29 | { | 29 | { |
30 | return new POP3wrapper(a); | 30 | return new POP3wrapper(a); |
31 | } | 31 | } |
32 | 32 | ||
33 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) | 33 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) |
34 | { | 34 | { |
35 | return new NNTPwrapper(a); | 35 | return new NNTPwrapper(a); |
36 | } | 36 | } |
37 | 37 | ||
38 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) | 38 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) |
39 | { | 39 | { |
40 | return new MHwrapper(a,name); | 40 | return new MHwrapper(a,name); |
41 | } | 41 | } |
42 | 42 | ||
43 | AbstractMail* AbstractMail::getWrapper(Account*a) | 43 | AbstractMail* AbstractMail::getWrapper(Account*a) |
44 | { | 44 | { |
45 | if (!a) return 0; | 45 | if (!a) return 0; |
46 | switch (a->getType()) { | 46 | switch (a->getType()) { |
47 | case MAILLIB::A_IMAP: | 47 | case MAILLIB::A_IMAP: |
48 | return new IMAPwrapper((IMAPaccount*)a); | 48 | return new IMAPwrapper((IMAPaccount*)a); |
49 | break; | 49 | break; |
50 | case MAILLIB::A_POP3: | 50 | case MAILLIB::A_POP3: |
51 | return new POP3wrapper((POP3account*)a); | 51 | return new POP3wrapper((POP3account*)a); |
52 | break; | 52 | break; |
53 | case MAILLIB::A_NNTP: | 53 | case MAILLIB::A_NNTP: |
54 | return new NNTPwrapper((NNTPaccount*)a); | 54 | return new NNTPwrapper((NNTPaccount*)a); |
55 | break; | 55 | break; |
56 | default: | 56 | default: |
57 | return 0; | 57 | return 0; |
58 | } | 58 | } |
59 | } | 59 | } |
60 | 60 | ||
61 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) | 61 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) |
62 | { | 62 | { |
63 | // odebug << "Decode string start" << oendl; | 63 | // odebug << "Decode string start" << oendl; |
64 | char*result_text; | 64 | char*result_text; |
65 | size_t index = 0; | 65 | size_t index = 0; |
66 | /* reset for recursive use! */ | 66 | /* reset for recursive use! */ |
67 | size_t target_length = 0; | 67 | size_t target_length = 0; |
68 | result_text = 0; | 68 | result_text = 0; |
69 | int mimetype = MAILMIME_MECHANISM_7BIT; | 69 | int mimetype = MAILMIME_MECHANISM_7BIT; |
70 | if (enc.lower()=="quoted-printable") { | 70 | if (enc.lower()=="quoted-printable") { |
71 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 71 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
72 | } else if (enc.lower()=="base64") { | 72 | } else if (enc.lower()=="base64") { |
73 | mimetype = MAILMIME_MECHANISM_BASE64; | 73 | mimetype = MAILMIME_MECHANISM_BASE64; |
74 | } else if (enc.lower()=="8bit") { | 74 | } else if (enc.lower()=="8bit") { |
75 | mimetype = MAILMIME_MECHANISM_8BIT; | 75 | mimetype = MAILMIME_MECHANISM_8BIT; |
76 | } else if (enc.lower()=="binary") { | 76 | } else if (enc.lower()=="binary") { |
77 | mimetype = MAILMIME_MECHANISM_BINARY; | 77 | mimetype = MAILMIME_MECHANISM_BINARY; |
78 | } | 78 | } |
79 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, | 79 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, |
80 | &result_text,&target_length); | 80 | &result_text,&target_length); |
81 | 81 | ||
82 | encodedString* result = new encodedString(); | 82 | encodedString* result = new encodedString(); |
83 | if (err == MAILIMF_NO_ERROR) { | 83 | if (err == MAILIMF_NO_ERROR) { |
84 | result->setContent(result_text,target_length); | 84 | result->setContent(result_text,target_length); |
85 | } | 85 | } |
86 | //odebug << "Decode string finished" << oendl; | 86 | //odebug << "Decode string finished" << oendl; |
87 | return result; | 87 | return result; |
88 | } | 88 | } |
89 | 89 | ||
90 | QString AbstractMail::convert_String(const char*text) | 90 | QString AbstractMail::convert_String(const char*text) |
91 | { | 91 | { |
92 | size_t index = 0; | 92 | size_t index = 0; |
93 | char*res = 0; | 93 | char*res = 0; |
94 | int err = MAILIMF_NO_ERROR; | 94 | int err = MAILIMF_NO_ERROR; |
95 | 95 | ||
96 | QString result(text); | 96 | QString result(text); |
97 | //qDebug("convert_String %s ", text); | 97 | //qDebug("convert_String %s ", text); |
98 | //err = mailmime_encoded_phrase_parse("iso-8859-1", | 98 | //err = mailmime_encoded_phrase_parse("iso-8859-1", |
99 | // text, strlen(text),&index, "iso-8859-1",&res); | 99 | // text, strlen(text),&index, "iso-8859-1",&res); |
100 | err = mailmime_encoded_phrase_parse("iso-8859-1", | 100 | err = mailmime_encoded_phrase_parse("iso-8859-1", |
101 | text, strlen(text),&index, "utf-8",&res); | 101 | text, strlen(text),&index, "utf-8",&res); |
102 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { | 102 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { |
103 | result = QString::fromUtf8(res); | 103 | result = QString::fromUtf8(res); |
104 | } | 104 | } |
105 | //qDebug("convert_String:%s ",result.latin1() ); | 105 | //qDebug("convert_String:%s ",result.latin1() ); |
106 | if (res) free(res); | 106 | if (res) free(res); |
107 | return result; | 107 | return result; |
108 | } | 108 | } |
109 | 109 | ||
110 | /* cp & paste from launcher */ | 110 | /* cp & paste from launcher */ |
111 | QString AbstractMail::gen_attachment_id() | 111 | QString AbstractMail::gen_attachment_id() |
112 | { | 112 | { |
113 | QFile file( "/proc/sys/kernel/random/uuid" ); | 113 | QFile file( "/proc/sys/kernel/random/uuid" ); |
114 | if (!file.open(IO_ReadOnly ) ) | 114 | if (!file.open(IO_ReadOnly ) ) |
115 | return QString::null; | 115 | return QString::null; |
116 | 116 | ||
117 | QTextStream stream(&file); | 117 | QTextStream stream(&file); |
118 | 118 | ||
119 | return "{" + stream.read().stripWhiteSpace() + "}"; | 119 | return "{" + stream.read().stripWhiteSpace() + "}"; |
120 | } | 120 | } |
121 | 121 | ||
122 | int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) | 122 | int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) |
123 | { | 123 | { |
124 | return 0; | 124 | return 0; |
125 | } | 125 | } |
126 | 126 | ||
127 | QString AbstractMail::defaultLocalfolder() | 127 | QString AbstractMail::defaultLocalfolder() |
128 | { | 128 | { |
129 | // QString f = getenv( "HOME" ); | 129 | // QString f = getenv( "HOME" ); |
130 | QString f = locateLocal( "data", "kopiemail/localmail"); | 130 | QString f = locateLocal( "data", "kopiemail/localmail"); |
131 | // f += "/Applications/opiemail/localmail"; | 131 | // f += "/Applications/opiemail/localmail"; |
132 | return f; | 132 | return f; |
133 | } | 133 | } |
134 | 134 | ||
135 | QString AbstractMail::draftFolder() | 135 | QString AbstractMail::draftFolder() |
136 | { | 136 | { |
137 | return QString("Drafts"); | 137 | return QString("Drafts"); |
138 | } | 138 | } |
139 | 139 | ||
140 | /* temporary - will be removed when implemented in all classes */ | 140 | /* temporary - will be removed when implemented in all classes */ |
141 | void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) | 141 | void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) |
142 | { | 142 | { |
143 | } | 143 | } |
144 | void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) | 144 | void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) |
145 | { | 145 | { |
146 | //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); | 146 | //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); |
147 | // this is currently re-implemented in pop3wrapper and imapwrapper | 147 | // this is currently re-implemented in pop3wrapper and imapwrapper |
148 | int iii = 0; | 148 | int iii = 0; |
149 | int count = target.count(); | 149 | int count = target.count(); |
150 | QProgressBar wid ( count ); | 150 | QProgressBar wid ( count ); |
151 | wid.setCaption( i18n("Deleting ...")); | 151 | wid.setCaption( i18n("Deleting ...")); |
152 | wid.show(); | 152 | wid.show(); |
153 | while (iii < count ) { | 153 | while (iii < count ) { |
154 | Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); | 154 | Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); |
155 | wid.setProgress( iii ); | 155 | wid.setProgress( iii ); |
156 | wid.raise(); | 156 | wid.raise(); |
157 | qApp->processEvents(); | 157 | qApp->processEvents(); |
158 | RecMailP mail = (*target.at( iii )); | 158 | RecMailP mail = (*target.at( iii )); |
159 | deleteMail(mail); | 159 | deleteMail(mail); |
160 | ++iii; | 160 | ++iii; |
161 | } | 161 | } |
162 | } | 162 | } |
163 | 163 | ||
164 | void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail ) | 164 | void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail ) |
165 | { | 165 | { |
166 | //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1()); | 166 | //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1()); |
167 | // get local folder | 167 | // get local folder |
168 | Account * acc = getAccount(); | 168 | Account * acc = getAccount(); |
169 | if ( !acc ) return; | 169 | if ( !acc ) return; |
170 | QString lfName = acc->getLocalFolder(); | 170 | QString lfName = acc->getLocalFolder(); |
171 | if ( lfName.isEmpty() ) | 171 | if ( lfName.isEmpty() ) |
172 | lfName = acc->getAccountName(); | 172 | lfName = acc->getAccountName(); |
173 | // create local folder | 173 | // create local folder |
174 | if ( !targetMail->createMbox(lfName)) | 174 | if ( !targetMail->createMbox(lfName)) |
175 | { | 175 | { |
176 | QMessageBox::critical(0,i18n("Error creating new Folder"), | 176 | QMessageBox::critical(0,i18n("Error creating new Folder"), |
177 | i18n("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName)); | 177 | i18n("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName)); |
178 | return; | 178 | return; |
179 | } | 179 | } |
180 | QValueList<RecMailP> t; | 180 | QValueList<RecMailP> t; |
181 | listMessages(fromFolder->getName(),t,acc->getMaxMailSize() ); | 181 | listMessages(fromFolder->getName(),t,acc->getMaxMailSize() ); |
182 | if ( t.count() == 0 ) { | 182 | if ( t.count() == 0 ) { |
183 | qDebug("There are no new messages %s", fromFolder->getName().latin1()); | 183 | qDebug("There are no new messages %s", fromFolder->getName().latin1()); |
184 | Global::statusMessage(i18n("There are no new messages")); | 184 | Global::statusMessage(i18n("There are no new messages")); |
185 | return; | 185 | return; |
186 | } | 186 | } |
187 | Global::statusMessage(i18n("%1 :Downloading mails..."). arg(acc->getAccountName())); | ||
188 | qDebug(i18n("%1 :Downloading mails..."). arg(acc->getAccountName())); | ||
189 | qApp->processEvents(); | ||
187 | QValueList<RecMailP> e; | 190 | QValueList<RecMailP> e; |
188 | targetMail->listMessages(lfName,e,acc->getMaxMailSize() ); | 191 | targetMail->listMessages(lfName,e,acc->getMaxMailSize() ); |
189 | //qDebug("target has mails %d ", e.count()); | 192 | //qDebug("target has mails %d ", e.count()); |
190 | QValueList<RecMailP> n; | 193 | QValueList<RecMailP> n; |
191 | int iii = 0; | 194 | int iii = 0; |
192 | int count = t.count(); | 195 | int count = t.count(); |
193 | while (iii < count ) { | 196 | while (iii < count ) { |
194 | RecMailP r = (*t.at( iii )); | 197 | RecMailP r = (*t.at( iii )); |
195 | bool found = false; | 198 | bool found = false; |
196 | int jjj = 0; | 199 | int jjj = 0; |
197 | int countE = e.count(); | 200 | int countE = e.count(); |
198 | while (jjj < countE ) { | 201 | while (jjj < countE ) { |
199 | RecMailP re = (*e.at( jjj )); | 202 | RecMailP re = (*e.at( jjj )); |
200 | if ( re->isEqual(r) ) { | 203 | if ( re->isEqual(r) ) { |
201 | found = true; | 204 | found = true; |
202 | break; | 205 | break; |
203 | } | 206 | } |
204 | ++jjj; | 207 | ++jjj; |
205 | } | 208 | } |
206 | if ( !found ) { | 209 | if ( !found ) { |
207 | //qDebug("AAAdate *%s* ", r->isodate.latin1() ); | 210 | //qDebug("AAAdate *%s* ", r->isodate.latin1() ); |
208 | n.append( r ); | 211 | n.append( r ); |
209 | } | 212 | } |
210 | ++iii; | 213 | ++iii; |
211 | } | 214 | } |
212 | qDebug("Downloaded %d messages ",n.count() ); | 215 | qDebug("Downloaded %d messages ",n.count() ); |
213 | if ( n.count() == 0 ) { | 216 | if ( n.count() == 0 ) { |
214 | Global::statusMessage(i18n("There are no new messages")); | 217 | Global::statusMessage(i18n("There are no new messages")); |
215 | return; | 218 | return; |
216 | } | 219 | } |
217 | mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer()); | 220 | mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer()); |
218 | Global::statusMessage(i18n("Downloaded %1 messages").arg(n.count())); | 221 | Global::statusMessage(i18n("Downloaded %1 messages").arg(n.count())); |
219 | 222 | ||
220 | #if 0 | 223 | #if 0 |
221 | QValueList<RecMailP> t; | 224 | QValueList<RecMailP> t; |
222 | listMessages(fromFolder->getName(),t, maxSizeInKb); | 225 | listMessages(fromFolder->getName(),t, maxSizeInKb); |
223 | mvcpMailList( t,targetFolder,targetWrapper,moveit); | 226 | mvcpMailList( t,targetFolder,targetWrapper,moveit); |
224 | #endif | 227 | #endif |
225 | 228 | ||
226 | } | 229 | } |
227 | void AbstractMail::mvcpAllMails(const FolderP&fromFolder, | 230 | void AbstractMail::mvcpAllMails(const FolderP&fromFolder, |
228 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) | 231 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) |
229 | { | 232 | { |
230 | QValueList<RecMailP> t; | 233 | QValueList<RecMailP> t; |
231 | listMessages(fromFolder->getName(),t, maxSizeInKb); | 234 | listMessages(fromFolder->getName(),t, maxSizeInKb); |
232 | mvcpMailList( t,targetFolder,targetWrapper,moveit); | 235 | mvcpMailList( t,targetFolder,targetWrapper,moveit); |
233 | 236 | ||
234 | } | 237 | } |
235 | void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, | 238 | void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, |
236 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 239 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
237 | { | 240 | { |
238 | encodedString*st = 0; | 241 | encodedString*st = 0; |
239 | int iii = 0; | 242 | int iii = 0; |
240 | int count = t.count(); | 243 | int count = t.count(); |
241 | if ( count == 0 ) | 244 | if ( count == 0 ) |
242 | return; | 245 | return; |
243 | // wel, processevents is qite strange, we need a widget for getting | 246 | // wel, processevents is qite strange, we need a widget for getting |
244 | // Global::statusMessage(i18n("Copy2 message %1").arg(iii)); displaye | 247 | // Global::statusMessage(i18n("Copy2 message %1").arg(iii)); displaye |
245 | 248 | ||
246 | QProgressBar wid ( count ); | 249 | QProgressBar wid ( count ); |
247 | wid.setCaption( i18n("Copying...")); | 250 | wid.setCaption( i18n("Copying...")); |
248 | wid.show(); | 251 | wid.show(); |
249 | while (iii < count ) { | 252 | while (iii < count ) { |
250 | Global::statusMessage(i18n("Copy message %1 of %2").arg(iii).arg(count)); | 253 | Global::statusMessage(i18n("Copy message %1 of %2").arg(iii).arg(count)); |
251 | wid.setProgress( iii ); | 254 | wid.setProgress( iii ); |
252 | wid.raise(); | 255 | wid.raise(); |
253 | qApp->processEvents(); | 256 | qApp->processEvents(); |
254 | RecMailP r = (*t.at( iii )); | 257 | RecMailP r = (*t.at( iii )); |
255 | st = fetchRawBody(r); | 258 | st = fetchRawBody(r); |
256 | if (st) { | 259 | if (st) { |
257 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); | 260 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); |
258 | delete st; | 261 | delete st; |
259 | } | 262 | } |
260 | ++iii; | 263 | ++iii; |
261 | } | 264 | } |
262 | if (moveit) { | 265 | if (moveit) { |
263 | deleteMailList( t ); | 266 | deleteMailList( t ); |
264 | //deleteAllMail(fromFolder); | 267 | //deleteAllMail(fromFolder); |
265 | } | 268 | } |
266 | } | 269 | } |
267 | 270 | ||
268 | void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 271 | void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
269 | { | 272 | { |
270 | encodedString*st = 0; | 273 | encodedString*st = 0; |
271 | st = fetchRawBody(mail); | 274 | st = fetchRawBody(mail); |
272 | if (st) { | 275 | if (st) { |
273 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); | 276 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); |
274 | delete st; | 277 | delete st; |
275 | } | 278 | } |
276 | if (moveit) { | 279 | if (moveit) { |
277 | deleteMail(mail); | 280 | deleteMail(mail); |
278 | } | 281 | } |
279 | } | 282 | } |
diff --git a/kmicromail/libmailwrapper/smtpwrapper.cpp b/kmicromail/libmailwrapper/smtpwrapper.cpp index 845c71c..448a2e9 100644 --- a/kmicromail/libmailwrapper/smtpwrapper.cpp +++ b/kmicromail/libmailwrapper/smtpwrapper.cpp | |||
@@ -17,432 +17,435 @@ | |||
17 | #include <libetpan/libetpan.h> | 17 | #include <libetpan/libetpan.h> |
18 | #include <klocale.h> | 18 | #include <klocale.h> |
19 | #include <kglobal.h> | 19 | #include <kglobal.h> |
20 | #include <kconfig.h> | 20 | #include <kconfig.h> |
21 | 21 | ||
22 | 22 | ||
23 | using namespace Opie::Core; | 23 | using namespace Opie::Core; |
24 | progressMailSend*SMTPwrapper::sendProgress = 0; | 24 | progressMailSend*SMTPwrapper::sendProgress = 0; |
25 | 25 | ||
26 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) | 26 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) |
27 | : Generatemail() | 27 | : Generatemail() |
28 | { | 28 | { |
29 | m_SmtpAccount = aSmtp; | 29 | m_SmtpAccount = aSmtp; |
30 | KConfig cfg( locateLocal("config", "kopiemailrc" ) ); | 30 | KConfig cfg( locateLocal("config", "kopiemailrc" ) ); |
31 | cfg.setGroup( "Status" ); | 31 | cfg.setGroup( "Status" ); |
32 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); | 32 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); |
33 | emit queuedMails( m_queuedMail ); | 33 | emit queuedMails( m_queuedMail ); |
34 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); | 34 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); |
35 | m_smtp = 0; | 35 | m_smtp = 0; |
36 | } | 36 | } |
37 | 37 | ||
38 | SMTPwrapper::~SMTPwrapper() | 38 | SMTPwrapper::~SMTPwrapper() |
39 | { | 39 | { |
40 | disc_server(); | 40 | disc_server(); |
41 | } | 41 | } |
42 | 42 | ||
43 | void SMTPwrapper::emitQCop( int queued ) { | 43 | void SMTPwrapper::emitQCop( int queued ) { |
44 | #ifndef DESKTOP_VERSION | 44 | #ifndef DESKTOP_VERSION |
45 | // LR : not used in kde-pim | 45 | // LR : not used in kde-pim |
46 | //QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); | 46 | //QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); |
47 | //env << queued; | 47 | //env << queued; |
48 | #endif | 48 | #endif |
49 | } | 49 | } |
50 | 50 | ||
51 | QString SMTPwrapper::mailsmtpError( int errnum ) { | 51 | QString SMTPwrapper::mailsmtpError( int errnum ) { |
52 | switch ( errnum ) { | 52 | switch ( errnum ) { |
53 | case MAILSMTP_NO_ERROR: | 53 | case MAILSMTP_NO_ERROR: |
54 | return i18n( "No error" ); | 54 | return i18n( "No error" ); |
55 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 55 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
56 | return i18n( "Unexpected error code" ); | 56 | return i18n( "Unexpected error code" ); |
57 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 57 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
58 | return i18n( "Service not available" ); | 58 | return i18n( "Service not available" ); |
59 | case MAILSMTP_ERROR_STREAM: | 59 | case MAILSMTP_ERROR_STREAM: |
60 | return i18n( "Stream error" ); | 60 | return i18n( "Stream error" ); |
61 | case MAILSMTP_ERROR_HOSTNAME: | 61 | case MAILSMTP_ERROR_HOSTNAME: |
62 | return i18n( "gethostname() failed" ); | 62 | return i18n( "gethostname() failed" ); |
63 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 63 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
64 | return i18n( "Not implemented" ); | 64 | return i18n( "Not implemented" ); |
65 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 65 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
66 | return i18n( "Error, action not taken" ); | 66 | return i18n( "Error, action not taken" ); |
67 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 67 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
68 | return i18n( "Data exceeds storage allocation" ); | 68 | return i18n( "Data exceeds storage allocation" ); |
69 | case MAILSMTP_ERROR_IN_PROCESSING: | 69 | case MAILSMTP_ERROR_IN_PROCESSING: |
70 | return i18n( "Error in processing" ); | 70 | return i18n( "Error in processing" ); |
71 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: | 71 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: |
72 | return i18n( "Starttls not supported" ); | 72 | return i18n( "Starttls not supported" ); |
73 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 73 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
74 | // return i18n( "Insufficient system storage" ); | 74 | // return i18n( "Insufficient system storage" ); |
75 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 75 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
76 | return i18n( "Mailbox unavailable" ); | 76 | return i18n( "Mailbox unavailable" ); |
77 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 77 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
78 | return i18n( "Mailbox name not allowed" ); | 78 | return i18n( "Mailbox name not allowed" ); |
79 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 79 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
80 | return i18n( "Bad command sequence" ); | 80 | return i18n( "Bad command sequence" ); |
81 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 81 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
82 | return i18n( "User not local" ); | 82 | return i18n( "User not local" ); |
83 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 83 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
84 | return i18n( "Transaction failed" ); | 84 | return i18n( "Transaction failed" ); |
85 | case MAILSMTP_ERROR_MEMORY: | 85 | case MAILSMTP_ERROR_MEMORY: |
86 | return i18n( "Memory error" ); | 86 | return i18n( "Memory error" ); |
87 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 87 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
88 | return i18n( "Connection refused" ); | 88 | return i18n( "Connection refused" ); |
89 | default: | 89 | default: |
90 | return i18n( "Unknown error code" ); | 90 | return i18n( "Unknown error code" ); |
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | 94 | ||
95 | void SMTPwrapper::progress( size_t current, size_t maximum ) { | 95 | void SMTPwrapper::progress( size_t current, size_t maximum ) { |
96 | if (SMTPwrapper::sendProgress) { | 96 | if (SMTPwrapper::sendProgress) { |
97 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | 97 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); |
98 | qApp->processEvents(); | 98 | qApp->processEvents(); |
99 | } | 99 | } |
100 | } | 100 | } |
101 | 101 | ||
102 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { | 102 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { |
103 | if (!mail) | 103 | if (!mail) |
104 | return; | 104 | return; |
105 | QString localfolders = AbstractMail::defaultLocalfolder(); | 105 | QString localfolders = AbstractMail::defaultLocalfolder(); |
106 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 106 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
107 | wrap->createMbox(box); | 107 | wrap->createMbox(box); |
108 | wrap->storeMessage(mail,length,box); | 108 | wrap->storeMessage(mail,length,box); |
109 | delete wrap; | 109 | delete wrap; |
110 | } | 110 | } |
111 | 111 | ||
112 | bool SMTPwrapper::smtpSend( mailmime *mail,bool later) { | 112 | bool SMTPwrapper::smtpSend( mailmime *mail,bool later) { |
113 | clist *rcpts = 0; | 113 | clist *rcpts = 0; |
114 | char *from, *data; | 114 | char *from, *data; |
115 | size_t size; | 115 | size_t size; |
116 | 116 | ||
117 | from = data = 0; | 117 | from = data = 0; |
118 | 118 | ||
119 | mailmessage * msg = 0; | 119 | mailmessage * msg = 0; |
120 | msg = mime_message_init(mail); | 120 | msg = mime_message_init(mail); |
121 | mime_message_set_tmpdir(msg,getenv( "HOME" )); | 121 | mime_message_set_tmpdir(msg,getenv( "HOME" )); |
122 | int r = mailmessage_fetch(msg,&data,&size); | 122 | int r = mailmessage_fetch(msg,&data,&size); |
123 | mime_message_detach_mime(msg); | 123 | mime_message_detach_mime(msg); |
124 | mailmessage_free(msg); | 124 | mailmessage_free(msg); |
125 | if (r != MAIL_NO_ERROR || !data) { | 125 | if (r != MAIL_NO_ERROR || !data) { |
126 | if (data) | 126 | if (data) |
127 | free(data); | 127 | free(data); |
128 | qDebug("Error fetching mime... "); | 128 | qDebug("Error fetching mime... "); |
129 | return false; | 129 | return false; |
130 | } | 130 | } |
131 | msg = 0; | 131 | msg = 0; |
132 | if (later) { | 132 | if (later) { |
133 | storeMail(data,size,"Outgoing"); | 133 | storeMail(data,size,"Outgoing"); |
134 | if (data) | 134 | if (data) |
135 | free( data ); | 135 | free( data ); |
136 | KConfig cfg( locateLocal("config", "kopiemailrc" ) ); | 136 | KConfig cfg( locateLocal("config", "kopiemailrc" ) ); |
137 | cfg.setGroup( "Status" ); | 137 | cfg.setGroup( "Status" ); |
138 | cfg.writeEntry( "outgoing", ++m_queuedMail ); | 138 | cfg.writeEntry( "outgoing", ++m_queuedMail ); |
139 | emit queuedMails( m_queuedMail ); | 139 | emit queuedMails( m_queuedMail ); |
140 | return true; | 140 | return true; |
141 | } | 141 | } |
142 | from = getFrom( mail ); | 142 | from = getFrom( mail ); |
143 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 143 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
144 | bool result = smtpSend(from,rcpts,data,size); | 144 | bool result = smtpSend(from,rcpts,data,size); |
145 | if (data) { | 145 | if (data) { |
146 | free(data); | 146 | free(data); |
147 | } | 147 | } |
148 | if (from) { | 148 | if (from) { |
149 | free(from); | 149 | free(from); |
150 | } | 150 | } |
151 | if (rcpts) | 151 | if (rcpts) |
152 | smtp_address_list_free( rcpts ); | 152 | smtp_address_list_free( rcpts ); |
153 | return result; | 153 | return result; |
154 | } | 154 | } |
155 | 155 | ||
156 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) | 156 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) |
157 | { | 157 | { |
158 | if (data) { | 158 | if (data) { |
159 | storeMail(data,size,"Sendfailed"); | 159 | storeMail(data,size,"Sendfailed"); |
160 | } | 160 | } |
161 | if (failuremessage) { | 161 | if (failuremessage) { |
162 | QMessageBox::critical(0,i18n("Error sending mail"), | 162 | QMessageBox::critical(0,i18n("Error sending mail"), |
163 | failuremessage); | 163 | failuremessage); |
164 | } | 164 | } |
165 | } | 165 | } |
166 | 166 | ||
167 | int SMTPwrapper::start_smtp_tls() | 167 | int SMTPwrapper::start_smtp_tls() |
168 | { | 168 | { |
169 | if (!m_smtp) { | 169 | if (!m_smtp) { |
170 | return MAILSMTP_ERROR_IN_PROCESSING; | 170 | return MAILSMTP_ERROR_IN_PROCESSING; |
171 | } | 171 | } |
172 | int err = mailesmtp_starttls(m_smtp); | 172 | int err = mailesmtp_starttls(m_smtp); |
173 | if (err != MAILSMTP_NO_ERROR) return err; | 173 | if (err != MAILSMTP_NO_ERROR) return err; |
174 | mailstream_low * low; | 174 | mailstream_low * low; |
175 | mailstream_low * new_low; | 175 | mailstream_low * new_low; |
176 | low = mailstream_get_low(m_smtp->stream); | 176 | low = mailstream_get_low(m_smtp->stream); |
177 | if (!low) { | 177 | if (!low) { |
178 | return MAILSMTP_ERROR_IN_PROCESSING; | 178 | return MAILSMTP_ERROR_IN_PROCESSING; |
179 | } | 179 | } |
180 | int fd = mailstream_low_get_fd(low); | 180 | int fd = mailstream_low_get_fd(low); |
181 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 181 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
182 | mailstream_low_free(low); | 182 | mailstream_low_free(low); |
183 | mailstream_set_low(m_smtp->stream, new_low); | 183 | mailstream_set_low(m_smtp->stream, new_low); |
184 | } else { | 184 | } else { |
185 | return MAILSMTP_ERROR_IN_PROCESSING; | 185 | return MAILSMTP_ERROR_IN_PROCESSING; |
186 | } | 186 | } |
187 | return err; | 187 | return err; |
188 | } | 188 | } |
189 | 189 | ||
190 | void SMTPwrapper::connect_server() | 190 | void SMTPwrapper::connect_server() |
191 | { | 191 | { |
192 | QString server, user, pass; | 192 | QString server, user, pass; |
193 | bool ssl; | 193 | bool ssl; |
194 | uint16_t port; | 194 | uint16_t port; |
195 | ssl = false; | 195 | ssl = false; |
196 | bool try_tls = false; | 196 | bool try_tls = false; |
197 | bool force_tls=false; | 197 | bool force_tls=false; |
198 | QString failuretext = ""; | 198 | QString failuretext = ""; |
199 | 199 | ||
200 | if (m_smtp || !m_SmtpAccount) { | 200 | if (m_smtp || !m_SmtpAccount) { |
201 | return; | 201 | return; |
202 | } | 202 | } |
203 | server = m_SmtpAccount->getServer(); | 203 | server = m_SmtpAccount->getServer(); |
204 | if ( m_SmtpAccount->ConnectionType() == 3 ) { | 204 | if ( m_SmtpAccount->ConnectionType() == 3 ) { |
205 | ssl = true; | 205 | ssl = true; |
206 | try_tls = false; | 206 | try_tls = false; |
207 | } else if (m_SmtpAccount->ConnectionType() == 2) { | 207 | } else if (m_SmtpAccount->ConnectionType() == 2) { |
208 | force_tls = true; | 208 | force_tls = true; |
209 | try_tls = true; | ||
209 | } else if (m_SmtpAccount->ConnectionType() == 1) { | 210 | } else if (m_SmtpAccount->ConnectionType() == 1) { |
210 | try_tls = true; | 211 | try_tls = true; |
211 | } | 212 | } |
212 | int result = 1; | 213 | int result = 1; |
213 | port = m_SmtpAccount->getPort().toUInt(); | 214 | port = m_SmtpAccount->getPort().toUInt(); |
214 | 215 | ||
215 | m_smtp = mailsmtp_new( 20, &progress ); | 216 | m_smtp = mailsmtp_new( 20, &progress ); |
216 | if ( m_smtp == NULL ) { | 217 | if ( m_smtp == NULL ) { |
217 | /* no failure message cause this happens when problems with memory - than we | 218 | /* no failure message cause this happens when problems with memory - than we |
218 | we can not display any messagebox */ | 219 | we can not display any messagebox */ |
219 | return; | 220 | return; |
220 | } | 221 | } |
221 | 222 | ||
222 | int err = MAILSMTP_NO_ERROR; | 223 | int err = MAILSMTP_NO_ERROR; |
223 | ; // odebug << "Servername " << server << " at port " << port << "" << oendl; | 224 | ; // odebug << "Servername " << server << " at port " << port << "" << oendl; |
224 | if ( ssl ) { | 225 | if ( ssl ) { |
225 | qDebug("smtp: ssl_connect "); | 226 | qDebug("smtp: ssl_connect "); |
226 | err = mailsmtp_ssl_connect( m_smtp, server.latin1(), port ); | 227 | err = mailsmtp_ssl_connect( m_smtp, server.latin1(), port ); |
227 | } else { | 228 | } else { |
228 | ; // odebug << "No SSL session" << oendl; | 229 | ; // odebug << "No SSL session" << oendl; |
229 | err = mailsmtp_socket_connect( m_smtp, server.latin1(), port ); | 230 | err = mailsmtp_socket_connect( m_smtp, server.latin1(), port ); |
230 | } | 231 | } |
231 | if ( err != MAILSMTP_NO_ERROR ) { | 232 | if ( err != MAILSMTP_NO_ERROR ) { |
232 | qDebug("Error init SMTP connection" ); | 233 | qDebug("Error init SMTP connection" ); |
233 | failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err)); | 234 | failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err)); |
234 | result = 0; | 235 | result = 0; |
235 | } | 236 | } |
236 | 237 | ||
237 | qDebug("SMTP connection inited "); | 238 | qDebug("SMTP connection inited "); |
238 | /* switch to tls after init 'cause there it will send the ehlo */ | 239 | /* switch to tls after init 'cause there it will send the ehlo */ |
239 | if (result) { | 240 | if (result) { |
240 | err = mailsmtp_init( m_smtp ); | 241 | err = mailsmtp_init( m_smtp ); |
241 | if (err != MAILSMTP_NO_ERROR) { | 242 | if (err != MAILSMTP_NO_ERROR) { |
242 | result = 0; | 243 | result = 0; |
243 | qDebug("Error init SMTP connection "); | 244 | qDebug("Error init SMTP connection "); |
244 | failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err)); | 245 | failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err)); |
245 | } | 246 | } |
246 | } | 247 | } |
247 | if (result && try_tls) { | 248 | if (result && try_tls) { |
248 | qDebug("Smpt: Try tls "); | 249 | qDebug("Smpt: Try TLS... "); |
249 | err = start_smtp_tls(); | 250 | err = start_smtp_tls(); |
250 | if (err != MAILSMTP_NO_ERROR) { | 251 | if (err != MAILSMTP_NO_ERROR) { |
251 | try_tls = false; | 252 | try_tls = false; |
252 | qDebug("no tls "); | 253 | qDebug("Smpt: No TLS possible "); |
253 | } else { | 254 | } else { |
254 | err = mailesmtp_ehlo(m_smtp); | 255 | err = mailesmtp_ehlo(m_smtp); |
255 | if ( err != MAILSMTP_NO_ERROR ) | 256 | if ( err != MAILSMTP_NO_ERROR ) |
256 | result = 0; | 257 | result = 0; |
258 | else | ||
259 | qDebug("Smpt: Using TLS "); | ||
257 | } | 260 | } |
258 | } | 261 | } |
259 | //qDebug("mailesmtp_ehlo %d ",err ); | 262 | //qDebug("mailesmtp_ehlo %d ",err ); |
260 | if (!try_tls && force_tls) { | 263 | if (!try_tls && force_tls) { |
261 | result = 0; | 264 | result = 0; |
262 | failuretext = i18n("Error init SMTP tls:%1").arg(mailsmtpError(err)); | 265 | failuretext = i18n("Error init SMTP tls:%1").arg(mailsmtpError(err)); |
263 | } | 266 | } |
264 | 267 | ||
265 | if (result==1 && m_SmtpAccount->getLogin() ) { | 268 | if (result==1 && m_SmtpAccount->getLogin() ) { |
266 | ; // odebug << "smtp with auth" << oendl; | 269 | ; // odebug << "smtp with auth" << oendl; |
267 | if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { | 270 | if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { |
268 | // get'em | 271 | // get'em |
269 | LoginDialog login( m_SmtpAccount->getUser(), | 272 | LoginDialog login( m_SmtpAccount->getUser(), |
270 | m_SmtpAccount->getPassword(), NULL, 0, true ); | 273 | m_SmtpAccount->getPassword(), NULL, 0, true ); |
271 | login.show(); | 274 | login.show(); |
272 | if ( QDialog::Accepted == login.exec() ) { | 275 | if ( QDialog::Accepted == login.exec() ) { |
273 | // ok | 276 | // ok |
274 | user = login.getUser(); | 277 | user = login.getUser(); |
275 | pass = login.getPassword(); | 278 | pass = login.getPassword(); |
276 | } else { | 279 | } else { |
277 | result = 0; | 280 | result = 0; |
278 | failuretext=i18n("Login aborted - \nstoring mail to localfolder"); | 281 | failuretext=i18n("Login aborted - \nstoring mail to localfolder"); |
279 | } | 282 | } |
280 | } else { | 283 | } else { |
281 | user = m_SmtpAccount->getUser(); | 284 | user = m_SmtpAccount->getUser(); |
282 | pass = m_SmtpAccount->getPassword(); | 285 | pass = m_SmtpAccount->getPassword(); |
283 | } | 286 | } |
284 | ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl; | 287 | ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl; |
285 | if (result) { | 288 | if (result) { |
286 | err = mailsmtp_auth( m_smtp, (char*)user.latin1(), (char*)pass.latin1() ); | 289 | err = mailsmtp_auth( m_smtp, (char*)user.latin1(), (char*)pass.latin1() ); |
287 | if ( err == MAILSMTP_NO_ERROR ) { | 290 | if ( err == MAILSMTP_NO_ERROR ) { |
288 | qDebug("Smtp authentification ok "); | 291 | qDebug("Smtp authentification ok "); |
289 | } else { | 292 | } else { |
290 | failuretext = i18n("Authentification failed"); | 293 | failuretext = i18n("Authentification failed"); |
291 | result = 0; | 294 | result = 0; |
292 | } | 295 | } |
293 | } | 296 | } |
294 | } | 297 | } |
295 | if ( result == 0 ) { | 298 | if ( result == 0 ) { |
296 | mailsmtp_free(m_smtp); | 299 | mailsmtp_free(m_smtp); |
297 | m_smtp = 0; | 300 | m_smtp = 0; |
298 | } | 301 | } |
299 | } | 302 | } |
300 | 303 | ||
301 | void SMTPwrapper::disc_server() | 304 | void SMTPwrapper::disc_server() |
302 | { | 305 | { |
303 | if (m_smtp) { | 306 | if (m_smtp) { |
304 | mailsmtp_quit( m_smtp ); | 307 | mailsmtp_quit( m_smtp ); |
305 | mailsmtp_free( m_smtp ); | 308 | mailsmtp_free( m_smtp ); |
306 | m_smtp = 0; | 309 | m_smtp = 0; |
307 | } | 310 | } |
308 | } | 311 | } |
309 | 312 | ||
310 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) | 313 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) |
311 | { | 314 | { |
312 | int err,result; | 315 | int err,result; |
313 | QString failuretext = ""; | 316 | QString failuretext = ""; |
314 | 317 | ||
315 | connect_server(); | 318 | connect_server(); |
316 | 319 | ||
317 | result = 1; | 320 | result = 1; |
318 | if (m_smtp) { | 321 | if (m_smtp) { |
319 | err = mailsmtp_send( m_smtp, from, rcpts, data, size ); | 322 | err = mailsmtp_send( m_smtp, from, rcpts, data, size ); |
320 | if ( err != MAILSMTP_NO_ERROR ) { | 323 | if ( err != MAILSMTP_NO_ERROR ) { |
321 | qDebug("Error sending mail"); | 324 | qDebug("Error sending mail"); |
322 | failuretext=i18n("Error sending mail:\n%1").arg(mailsmtpError(err)); | 325 | failuretext=i18n("Error sending mail:\n%1").arg(mailsmtpError(err)); |
323 | result = 0; | 326 | result = 0; |
324 | } | 327 | } |
325 | } else { | 328 | } else { |
326 | result = 0; | 329 | result = 0; |
327 | } | 330 | } |
328 | 331 | ||
329 | if (!result) { | 332 | if (!result) { |
330 | storeFailedMail(data,size,failuretext); | 333 | storeFailedMail(data,size,failuretext); |
331 | } else { | 334 | } else { |
332 | ; // odebug << "Mail sent." << oendl; | 335 | ; // odebug << "Mail sent." << oendl; |
333 | storeMail(data,size,"Sent"); | 336 | storeMail(data,size,"Sent"); |
334 | } | 337 | } |
335 | return result; | 338 | return result; |
336 | } | 339 | } |
337 | 340 | ||
338 | bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) | 341 | bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) |
339 | { | 342 | { |
340 | mailmime * mimeMail; | 343 | mailmime * mimeMail; |
341 | bool result = true; | 344 | bool result = true; |
342 | mimeMail = createMimeMail(mail ); | 345 | mimeMail = createMimeMail(mail ); |
343 | if ( mimeMail == 0 ) { | 346 | if ( mimeMail == 0 ) { |
344 | qDebug("SMTP wrapper:Error creating mail! "); | 347 | qDebug("SMTP wrapper:Error creating mail! "); |
345 | return false; | 348 | return false; |
346 | } else { | 349 | } else { |
347 | sendProgress = new progressMailSend(); | 350 | sendProgress = new progressMailSend(); |
348 | sendProgress->show(); | 351 | sendProgress->show(); |
349 | sendProgress->setMaxMails(1); | 352 | sendProgress->setMaxMails(1); |
350 | result = smtpSend( mimeMail,later); | 353 | result = smtpSend( mimeMail,later); |
351 | ; // odebug << "Clean up done" << oendl; | 354 | ; // odebug << "Clean up done" << oendl; |
352 | sendProgress->hide(); | 355 | sendProgress->hide(); |
353 | delete sendProgress; | 356 | delete sendProgress; |
354 | sendProgress = 0; | 357 | sendProgress = 0; |
355 | mailmime_free( mimeMail ); | 358 | mailmime_free( mimeMail ); |
356 | if ( m_smtp ) { | 359 | if ( m_smtp ) { |
357 | mailsmtp_free(m_smtp); | 360 | mailsmtp_free(m_smtp); |
358 | m_smtp = 0; | 361 | m_smtp = 0; |
359 | } | 362 | } |
360 | } | 363 | } |
361 | return result; | 364 | return result; |
362 | } | 365 | } |
363 | 366 | ||
364 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { | 367 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { |
365 | size_t curTok = 0; | 368 | size_t curTok = 0; |
366 | mailimf_fields *fields = 0; | 369 | mailimf_fields *fields = 0; |
367 | mailimf_field*ffrom = 0; | 370 | mailimf_field*ffrom = 0; |
368 | clist *rcpts = 0; | 371 | clist *rcpts = 0; |
369 | char*from = 0; | 372 | char*from = 0; |
370 | int res = 0; | 373 | int res = 0; |
371 | 374 | ||
372 | encodedString * data = wrap->fetchRawBody(which); | 375 | encodedString * data = wrap->fetchRawBody(which); |
373 | if (!data) | 376 | if (!data) |
374 | return 0; | 377 | return 0; |
375 | int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); | 378 | int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); |
376 | if (err != MAILIMF_NO_ERROR) { | 379 | if (err != MAILIMF_NO_ERROR) { |
377 | delete data; | 380 | delete data; |
378 | delete wrap; | 381 | delete wrap; |
379 | return 0; | 382 | return 0; |
380 | } | 383 | } |
381 | 384 | ||
382 | rcpts = createRcptList( fields ); | 385 | rcpts = createRcptList( fields ); |
383 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); | 386 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); |
384 | from = getFrom(ffrom); | 387 | from = getFrom(ffrom); |
385 | 388 | ||
386 | if (rcpts && from) { | 389 | if (rcpts && from) { |
387 | res = smtpSend(from,rcpts,data->Content(),data->Length()); | 390 | res = smtpSend(from,rcpts,data->Content(),data->Length()); |
388 | } | 391 | } |
389 | if (fields) { | 392 | if (fields) { |
390 | mailimf_fields_free(fields); | 393 | mailimf_fields_free(fields); |
391 | fields = 0; | 394 | fields = 0; |
392 | } | 395 | } |
393 | if (data) { | 396 | if (data) { |
394 | delete data; | 397 | delete data; |
395 | } | 398 | } |
396 | if (from) { | 399 | if (from) { |
397 | free(from); | 400 | free(from); |
398 | } | 401 | } |
399 | if (rcpts) { | 402 | if (rcpts) { |
400 | smtp_address_list_free( rcpts ); | 403 | smtp_address_list_free( rcpts ); |
401 | } | 404 | } |
402 | return res; | 405 | return res; |
403 | } | 406 | } |
404 | 407 | ||
405 | /* this is a special fun */ | 408 | /* this is a special fun */ |
406 | bool SMTPwrapper::flushOutbox() { | 409 | bool SMTPwrapper::flushOutbox() { |
407 | bool returnValue = true; | 410 | bool returnValue = true; |
408 | 411 | ||
409 | ; // odebug << "Sending the queue" << oendl; | 412 | ; // odebug << "Sending the queue" << oendl; |
410 | if (!m_SmtpAccount) { | 413 | if (!m_SmtpAccount) { |
411 | ; // odebug << "No smtp account given" << oendl; | 414 | ; // odebug << "No smtp account given" << oendl; |
412 | return false; | 415 | return false; |
413 | } | 416 | } |
414 | 417 | ||
415 | bool reset_user_value = false; | 418 | bool reset_user_value = false; |
416 | QString localfolders = AbstractMail::defaultLocalfolder(); | 419 | QString localfolders = AbstractMail::defaultLocalfolder(); |
417 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 420 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
418 | if (!wrap) { | 421 | if (!wrap) { |
419 | ; // odebug << "memory error" << oendl; | 422 | ; // odebug << "memory error" << oendl; |
420 | return false; | 423 | return false; |
421 | } | 424 | } |
422 | QString oldPw, oldUser; | 425 | QString oldPw, oldUser; |
423 | QValueList<RecMailP> mailsToSend; | 426 | QValueList<RecMailP> mailsToSend; |
424 | QValueList<RecMailP> mailsToRemove; | 427 | QValueList<RecMailP> mailsToRemove; |
425 | QString mbox("Outgoing"); | 428 | QString mbox("Outgoing"); |
426 | wrap->listMessages(mbox,mailsToSend); | 429 | wrap->listMessages(mbox,mailsToSend); |
427 | if (mailsToSend.count()==0) { | 430 | if (mailsToSend.count()==0) { |
428 | delete wrap; | 431 | delete wrap; |
429 | ; // odebug << "No mails to send" << oendl; | 432 | ; // odebug << "No mails to send" << oendl; |
430 | return false; | 433 | return false; |
431 | } | 434 | } |
432 | 435 | ||
433 | oldPw = m_SmtpAccount->getPassword(); | 436 | oldPw = m_SmtpAccount->getPassword(); |
434 | oldUser = m_SmtpAccount->getUser(); | 437 | oldUser = m_SmtpAccount->getUser(); |
435 | if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { | 438 | if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { |
436 | // get'em | 439 | // get'em |
437 | QString user,pass; | 440 | QString user,pass; |
438 | LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); | 441 | LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); |
439 | login.show(); | 442 | login.show(); |
440 | if ( QDialog::Accepted == login.exec() ) { | 443 | if ( QDialog::Accepted == login.exec() ) { |
441 | // ok | 444 | // ok |
442 | user = login.getUser().latin1(); | 445 | user = login.getUser().latin1(); |
443 | pass = login.getPassword().latin1(); | 446 | pass = login.getPassword().latin1(); |
444 | reset_user_value = true; | 447 | reset_user_value = true; |
445 | m_SmtpAccount->setUser(user); | 448 | m_SmtpAccount->setUser(user); |
446 | m_SmtpAccount->setPassword(pass); | 449 | m_SmtpAccount->setPassword(pass); |
447 | } else { | 450 | } else { |
448 | return true; | 451 | return true; |