23 files changed, 49 insertions, 7 deletions
diff --git a/noncore/net/mail/accountitem.cpp b/noncore/net/mail/accountitem.cpp index ae28313..c1574fd 100644 --- a/noncore/net/mail/accountitem.cpp +++ b/noncore/net/mail/accountitem.cpp | |||
@@ -1,1134 +1,1135 @@ | |||
1 | 1 | ||
2 | #include "accountitem.h" | 2 | #include "accountitem.h" |
3 | #include "accountview.h" | 3 | #include "accountview.h" |
4 | #include "newmaildir.h" | 4 | #include "newmaildir.h" |
5 | #include "nntpgroupsdlg.h" | 5 | #include "nntpgroupsdlg.h" |
6 | #include "defines.h" | 6 | #include "defines.h" |
7 | 7 | ||
8 | /* OPIE */ | ||
9 | #include <libmailwrapper/mailtypes.h> | 8 | #include <libmailwrapper/mailtypes.h> |
10 | #include <libmailwrapper/abstractmail.h> | 9 | #include <libmailwrapper/abstractmail.h> |
11 | #include <libmailwrapper/mailwrapper.h> | 10 | #include <libmailwrapper/mailwrapper.h> |
11 | /* OPIE */ | ||
12 | #include <opie2/odebug.h> | ||
12 | #include <qpe/qpeapplication.h> | 13 | #include <qpe/qpeapplication.h> |
13 | 14 | ||
14 | /* QT */ | 15 | /* QT */ |
15 | #include <qpopupmenu.h> | 16 | #include <qpopupmenu.h> |
16 | #include <qmessagebox.h> | 17 | #include <qmessagebox.h> |
17 | 18 | ||
18 | using namespace Opie::Core; | 19 | using namespace Opie::Core; |
19 | #define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );} | 20 | #define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );} |
20 | /** | 21 | /** |
21 | * POP3 Account stuff | 22 | * POP3 Account stuff |
22 | */ | 23 | */ |
23 | POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent ) | 24 | POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent ) |
24 | : AccountViewItem( parent ) | 25 | : AccountViewItem( parent ) |
25 | { | 26 | { |
26 | account = a; | 27 | account = a; |
27 | wrapper = AbstractMail::getWrapper( account ); | 28 | wrapper = AbstractMail::getWrapper( account ); |
28 | SETPIX(PIXMAP_POP3FOLDER); | 29 | SETPIX(PIXMAP_POP3FOLDER); |
29 | #if 0 | 30 | #if 0 |
30 | if (!account->getOffline()) | 31 | if (!account->getOffline()) |
31 | { | 32 | { |
32 | setPixmap( 0, ); | 33 | setPixmap( 0, ); |
33 | } | 34 | } |
34 | else | 35 | else |
35 | { | 36 | { |
36 | setPixmap( 0, PIXMAP_OFFLINE ); | 37 | setPixmap( 0, PIXMAP_OFFLINE ); |
37 | } | 38 | } |
38 | #endif | 39 | #endif |
39 | setText( 0, account->getAccountName() ); | 40 | setText( 0, account->getAccountName() ); |
40 | setOpen( true ); | 41 | setOpen( true ); |
41 | } | 42 | } |
42 | 43 | ||
43 | POP3viewItem::~POP3viewItem() | 44 | POP3viewItem::~POP3viewItem() |
44 | { | 45 | { |
45 | delete wrapper; | 46 | delete wrapper; |
46 | } | 47 | } |
47 | 48 | ||
48 | AbstractMail *POP3viewItem::getWrapper() | 49 | AbstractMail *POP3viewItem::getWrapper() |
49 | { | 50 | { |
50 | return wrapper; | 51 | return wrapper; |
51 | } | 52 | } |
52 | 53 | ||
53 | void POP3viewItem::refresh(QValueList<Opie::Core::OSmartPointer<RecMail> > & ) | 54 | void POP3viewItem::refresh(QValueList<Opie::Core::OSmartPointer<RecMail> > & ) |
54 | { | 55 | { |
55 | refresh(); | 56 | refresh(); |
56 | } | 57 | } |
57 | 58 | ||
58 | void POP3viewItem::refresh() | 59 | void POP3viewItem::refresh() |
59 | { | 60 | { |
60 | if (account->getOffline()) return; | 61 | if (account->getOffline()) return; |
61 | QValueList<FolderP> *folders = wrapper->listFolders(); | 62 | QValueList<FolderP> *folders = wrapper->listFolders(); |
62 | QListViewItem *child = firstChild(); | 63 | QListViewItem *child = firstChild(); |
63 | while ( child ) | 64 | while ( child ) |
64 | { | 65 | { |
65 | QListViewItem *tmp = child; | 66 | QListViewItem *tmp = child; |
66 | child = child->nextSibling(); | 67 | child = child->nextSibling(); |
67 | delete tmp; | 68 | delete tmp; |
68 | } | 69 | } |
69 | QValueList<FolderP>::ConstIterator it; | 70 | QValueList<FolderP>::ConstIterator it; |
70 | QListViewItem*item = 0; | 71 | QListViewItem*item = 0; |
71 | for ( it = folders->begin(); it!=folders->end(); ++it) | 72 | for ( it = folders->begin(); it!=folders->end(); ++it) |
72 | { | 73 | { |
73 | item = new POP3folderItem( (*it), this , item ); | 74 | item = new POP3folderItem( (*it), this , item ); |
74 | item->setSelectable( (*it)->may_select()); | 75 | item->setSelectable( (*it)->may_select()); |
75 | } | 76 | } |
76 | delete folders; | 77 | delete folders; |
77 | } | 78 | } |
78 | 79 | ||
79 | RECBODYP POP3viewItem::fetchBody( const RecMailP &mail ) | 80 | RECBODYP POP3viewItem::fetchBody( const RecMailP &mail ) |
80 | { | 81 | { |
81 | odebug << "POP3 fetchBody" << oendl; | 82 | odebug << "POP3 fetchBody" << oendl; |
82 | return wrapper->fetchBody( mail ); | 83 | return wrapper->fetchBody( mail ); |
83 | } | 84 | } |
84 | 85 | ||
85 | QPopupMenu * POP3viewItem::getContextMenu() | 86 | QPopupMenu * POP3viewItem::getContextMenu() |
86 | { | 87 | { |
87 | QPopupMenu *m = new QPopupMenu(0); | 88 | QPopupMenu *m = new QPopupMenu(0); |
88 | if (m) | 89 | if (m) |
89 | { | 90 | { |
90 | if (!account->getOffline()) | 91 | if (!account->getOffline()) |
91 | { | 92 | { |
92 | m->insertItem(QObject::tr("Disconnect",contextName),0); | 93 | m->insertItem(QObject::tr("Disconnect",contextName),0); |
93 | m->insertItem(QObject::tr("Set offline",contextName),1); | 94 | m->insertItem(QObject::tr("Set offline",contextName),1); |
94 | } | 95 | } |
95 | else | 96 | else |
96 | { | 97 | { |
97 | m->insertItem(QObject::tr("Set online",contextName),1); | 98 | m->insertItem(QObject::tr("Set online",contextName),1); |
98 | } | 99 | } |
99 | } | 100 | } |
100 | return m; | 101 | return m; |
101 | } | 102 | } |
102 | 103 | ||
103 | void POP3viewItem::disconnect() | 104 | void POP3viewItem::disconnect() |
104 | { | 105 | { |
105 | QListViewItem *child = firstChild(); | 106 | QListViewItem *child = firstChild(); |
106 | while ( child ) | 107 | while ( child ) |
107 | { | 108 | { |
108 | QListViewItem *tmp = child; | 109 | QListViewItem *tmp = child; |
109 | child = child->nextSibling(); | 110 | child = child->nextSibling(); |
110 | delete tmp; | 111 | delete tmp; |
111 | } | 112 | } |
112 | wrapper->logout(); | 113 | wrapper->logout(); |
113 | } | 114 | } |
114 | 115 | ||
115 | void POP3viewItem::setOnOffline() | 116 | void POP3viewItem::setOnOffline() |
116 | { | 117 | { |
117 | if (!account->getOffline()) | 118 | if (!account->getOffline()) |
118 | { | 119 | { |
119 | disconnect(); | 120 | disconnect(); |
120 | } | 121 | } |
121 | account->setOffline(!account->getOffline()); | 122 | account->setOffline(!account->getOffline()); |
122 | account->save(); | 123 | account->save(); |
123 | SETPIX(PIXMAP_POP3FOLDER); | 124 | SETPIX(PIXMAP_POP3FOLDER); |
124 | refresh(); | 125 | refresh(); |
125 | } | 126 | } |
126 | 127 | ||
127 | void POP3viewItem::contextMenuSelected(int which) | 128 | void POP3viewItem::contextMenuSelected(int which) |
128 | { | 129 | { |
129 | switch (which) | 130 | switch (which) |
130 | { | 131 | { |
131 | case 0: | 132 | case 0: |
132 | disconnect(); | 133 | disconnect(); |
133 | break; | 134 | break; |
134 | case 1: | 135 | case 1: |
135 | setOnOffline(); | 136 | setOnOffline(); |
136 | break; | 137 | break; |
137 | } | 138 | } |
138 | } | 139 | } |
139 | 140 | ||
140 | POP3folderItem::~POP3folderItem() | 141 | POP3folderItem::~POP3folderItem() |
141 | {} | 142 | {} |
142 | 143 | ||
143 | POP3folderItem::POP3folderItem( const FolderP&folderInit, POP3viewItem *parent , QListViewItem*after ) | 144 | POP3folderItem::POP3folderItem( const FolderP&folderInit, POP3viewItem *parent , QListViewItem*after ) |
144 | : AccountViewItem(folderInit,parent,after ) | 145 | : AccountViewItem(folderInit,parent,after ) |
145 | { | 146 | { |
146 | pop3 = parent; | 147 | pop3 = parent; |
147 | if (folder->getDisplayName().lower()!="inbox") | 148 | if (folder->getDisplayName().lower()!="inbox") |
148 | { | 149 | { |
149 | setPixmap( 0, PIXMAP_POP3FOLDER ); | 150 | setPixmap( 0, PIXMAP_POP3FOLDER ); |
150 | } | 151 | } |
151 | else | 152 | else |
152 | { | 153 | { |
153 | setPixmap( 0, PIXMAP_INBOXFOLDER); | 154 | setPixmap( 0, PIXMAP_INBOXFOLDER); |
154 | } | 155 | } |
155 | setText( 0, folder->getDisplayName() ); | 156 | setText( 0, folder->getDisplayName() ); |
156 | } | 157 | } |
157 | 158 | ||
158 | void POP3folderItem::refresh(QValueList<RecMailP>&target) | 159 | void POP3folderItem::refresh(QValueList<RecMailP>&target) |
159 | { | 160 | { |
160 | if (folder->may_select()) | 161 | if (folder->may_select()) |
161 | pop3->getWrapper()->listMessages( folder->getName(),target ); | 162 | pop3->getWrapper()->listMessages( folder->getName(),target ); |
162 | } | 163 | } |
163 | 164 | ||
164 | RECBODYP POP3folderItem::fetchBody(const RecMailP&aMail) | 165 | RECBODYP POP3folderItem::fetchBody(const RecMailP&aMail) |
165 | { | 166 | { |
166 | return pop3->getWrapper()->fetchBody(aMail); | 167 | return pop3->getWrapper()->fetchBody(aMail); |
167 | } | 168 | } |
168 | 169 | ||
169 | QPopupMenu * POP3folderItem::getContextMenu() | 170 | QPopupMenu * POP3folderItem::getContextMenu() |
170 | { | 171 | { |
171 | QPopupMenu *m = new QPopupMenu(0); | 172 | QPopupMenu *m = new QPopupMenu(0); |
172 | if (m) | 173 | if (m) |
173 | { | 174 | { |
174 | m->insertItem(QObject::tr("Refresh header list",contextName),0); | 175 | m->insertItem(QObject::tr("Refresh header list",contextName),0); |
175 | m->insertItem(QObject::tr("Delete all mails",contextName),1); | 176 | m->insertItem(QObject::tr("Delete all mails",contextName),1); |
176 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); | 177 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); |
177 | } | 178 | } |
178 | return m; | 179 | return m; |
179 | } | 180 | } |
180 | 181 | ||
181 | void POP3folderItem::downloadMails() | 182 | void POP3folderItem::downloadMails() |
182 | { | 183 | { |
183 | AccountView*bl = pop3->accountView(); | 184 | AccountView*bl = pop3->accountView(); |
184 | if (!bl) return; | 185 | if (!bl) return; |
185 | bl->downloadMails(folder,pop3->getWrapper()); | 186 | bl->downloadMails(folder,pop3->getWrapper()); |
186 | } | 187 | } |
187 | 188 | ||
188 | void POP3folderItem::contextMenuSelected(int which) | 189 | void POP3folderItem::contextMenuSelected(int which) |
189 | { | 190 | { |
190 | AccountView * view = (AccountView*)listView(); | 191 | AccountView * view = (AccountView*)listView(); |
191 | switch (which) | 192 | switch (which) |
192 | { | 193 | { |
193 | case 0: | 194 | case 0: |
194 | /* must be 'cause pop3 lists are cached */ | 195 | /* must be 'cause pop3 lists are cached */ |
195 | pop3->getWrapper()->logout(); | 196 | pop3->getWrapper()->logout(); |
196 | view->refreshCurrent(); | 197 | view->refreshCurrent(); |
197 | break; | 198 | break; |
198 | case 1: | 199 | case 1: |
199 | deleteAllMail(pop3->getWrapper(),folder); | 200 | deleteAllMail(pop3->getWrapper(),folder); |
200 | break; | 201 | break; |
201 | case 2: | 202 | case 2: |
202 | downloadMails(); | 203 | downloadMails(); |
203 | break; | 204 | break; |
204 | default: | 205 | default: |
205 | break; | 206 | break; |
206 | } | 207 | } |
207 | } | 208 | } |
208 | 209 | ||
209 | /** | 210 | /** |
210 | * NNTP Account stuff | 211 | * NNTP Account stuff |
211 | */ | 212 | */ |
212 | NNTPviewItem::NNTPviewItem( NNTPaccount *a, AccountView *parent ) | 213 | NNTPviewItem::NNTPviewItem( NNTPaccount *a, AccountView *parent ) |
213 | : AccountViewItem( parent ) | 214 | : AccountViewItem( parent ) |
214 | { | 215 | { |
215 | account = a; | 216 | account = a; |
216 | wrapper = AbstractMail::getWrapper( account ); | 217 | wrapper = AbstractMail::getWrapper( account ); |
217 | //FIXME | 218 | //FIXME |
218 | SETPIX(PIXMAP_POP3FOLDER); | 219 | SETPIX(PIXMAP_POP3FOLDER); |
219 | #if 0 | 220 | #if 0 |
220 | if (!account->getOffline()) | 221 | if (!account->getOffline()) |
221 | { | 222 | { |
222 | setPixmap( 0, ); | 223 | setPixmap( 0, ); |
223 | } | 224 | } |
224 | else | 225 | else |
225 | { | 226 | { |
226 | setPixmap( 0, PIXMAP_OFFLINE ); | 227 | setPixmap( 0, PIXMAP_OFFLINE ); |
227 | } | 228 | } |
228 | #endif | 229 | #endif |
229 | setText( 0, account->getAccountName() ); | 230 | setText( 0, account->getAccountName() ); |
230 | setOpen( true ); | 231 | setOpen( true ); |
231 | } | 232 | } |
232 | 233 | ||
233 | NNTPviewItem::~NNTPviewItem() | 234 | NNTPviewItem::~NNTPviewItem() |
234 | { | 235 | { |
235 | delete wrapper; | 236 | delete wrapper; |
236 | } | 237 | } |
237 | 238 | ||
238 | AbstractMail *NNTPviewItem::getWrapper() | 239 | AbstractMail *NNTPviewItem::getWrapper() |
239 | { | 240 | { |
240 | return wrapper; | 241 | return wrapper; |
241 | } | 242 | } |
242 | 243 | ||
243 | void NNTPviewItem::refresh( QValueList<RecMailP> & ) | 244 | void NNTPviewItem::refresh( QValueList<RecMailP> & ) |
244 | { | 245 | { |
245 | refresh(); | 246 | refresh(); |
246 | } | 247 | } |
247 | 248 | ||
248 | void NNTPviewItem::refresh() | 249 | void NNTPviewItem::refresh() |
249 | { | 250 | { |
250 | if (account->getOffline()) return; | 251 | if (account->getOffline()) return; |
251 | QValueList<FolderP> *folders = wrapper->listFolders(); | 252 | QValueList<FolderP> *folders = wrapper->listFolders(); |
252 | 253 | ||
253 | QListViewItem *child = firstChild(); | 254 | QListViewItem *child = firstChild(); |
254 | while ( child ) | 255 | while ( child ) |
255 | { | 256 | { |
256 | QListViewItem *tmp = child; | 257 | QListViewItem *tmp = child; |
257 | child = child->nextSibling(); | 258 | child = child->nextSibling(); |
258 | delete tmp; | 259 | delete tmp; |
259 | } | 260 | } |
260 | QValueList<FolderP>::ConstIterator it; | 261 | QValueList<FolderP>::ConstIterator it; |
261 | QListViewItem*item = 0; | 262 | QListViewItem*item = 0; |
262 | for ( it = folders->begin(); it!=folders->end(); ++it) | 263 | for ( it = folders->begin(); it!=folders->end(); ++it) |
263 | { | 264 | { |
264 | item = new NNTPfolderItem( (*it), this , item ); | 265 | item = new NNTPfolderItem( (*it), this , item ); |
265 | item->setSelectable( (*it)->may_select()); | 266 | item->setSelectable( (*it)->may_select()); |
266 | } | 267 | } |
267 | delete folders; | 268 | delete folders; |
268 | } | 269 | } |
269 | 270 | ||
270 | RECBODYP NNTPviewItem::fetchBody( const RecMailP &mail ) | 271 | RECBODYP NNTPviewItem::fetchBody( const RecMailP &mail ) |
271 | { | 272 | { |
272 | odebug << "NNTP fetchBody" << oendl; | 273 | odebug << "NNTP fetchBody" << oendl; |
273 | return wrapper->fetchBody( mail ); | 274 | return wrapper->fetchBody( mail ); |
274 | } | 275 | } |
275 | 276 | ||
276 | QPopupMenu * NNTPviewItem::getContextMenu() | 277 | QPopupMenu * NNTPviewItem::getContextMenu() |
277 | { | 278 | { |
278 | QPopupMenu *m = new QPopupMenu(0); | 279 | QPopupMenu *m = new QPopupMenu(0); |
279 | if (m) | 280 | if (m) |
280 | { | 281 | { |
281 | if (!account->getOffline()) | 282 | if (!account->getOffline()) |
282 | { | 283 | { |
283 | m->insertItem(QObject::tr("Disconnect",contextName),0); | 284 | m->insertItem(QObject::tr("Disconnect",contextName),0); |
284 | m->insertItem(QObject::tr("Set offline",contextName),1); | 285 | m->insertItem(QObject::tr("Set offline",contextName),1); |
285 | m->insertItem(QObject::tr("(Un-)Subscribe groups",contextName),2); | 286 | m->insertItem(QObject::tr("(Un-)Subscribe groups",contextName),2); |
286 | } | 287 | } |
287 | else | 288 | else |
288 | { | 289 | { |
289 | m->insertItem(QObject::tr("Set online",contextName),1); | 290 | m->insertItem(QObject::tr("Set online",contextName),1); |
290 | } | 291 | } |
291 | } | 292 | } |
292 | return m; | 293 | return m; |
293 | } | 294 | } |
294 | 295 | ||
295 | void NNTPviewItem::subscribeGroups() | 296 | void NNTPviewItem::subscribeGroups() |
296 | { | 297 | { |
297 | NNTPGroupsDlg dlg(account); | 298 | NNTPGroupsDlg dlg(account); |
298 | if (QPEApplication::execDialog(&dlg)== QDialog::Accepted ){ | 299 | if (QPEApplication::execDialog(&dlg)== QDialog::Accepted ){ |
299 | refresh(); | 300 | refresh(); |
300 | } | 301 | } |
301 | } | 302 | } |
302 | 303 | ||
303 | void NNTPviewItem::disconnect() | 304 | void NNTPviewItem::disconnect() |
304 | { | 305 | { |
305 | QListViewItem *child = firstChild(); | 306 | QListViewItem *child = firstChild(); |
306 | while ( child ) | 307 | while ( child ) |
307 | { | 308 | { |
308 | QListViewItem *tmp = child; | 309 | QListViewItem *tmp = child; |
309 | child = child->nextSibling(); | 310 | child = child->nextSibling(); |
310 | delete tmp; | 311 | delete tmp; |
311 | } | 312 | } |
312 | wrapper->logout(); | 313 | wrapper->logout(); |
313 | } | 314 | } |
314 | 315 | ||
315 | void NNTPviewItem::setOnOffline() | 316 | void NNTPviewItem::setOnOffline() |
316 | { | 317 | { |
317 | if (!account->getOffline()) | 318 | if (!account->getOffline()) |
318 | { | 319 | { |
319 | disconnect(); | 320 | disconnect(); |
320 | } | 321 | } |
321 | account->setOffline(!account->getOffline()); | 322 | account->setOffline(!account->getOffline()); |
322 | account->save(); | 323 | account->save(); |
323 | //FIXME | 324 | //FIXME |
324 | SETPIX(PIXMAP_POP3FOLDER); | 325 | SETPIX(PIXMAP_POP3FOLDER); |
325 | refresh(); | 326 | refresh(); |
326 | } | 327 | } |
327 | 328 | ||
328 | void NNTPviewItem::contextMenuSelected(int which) | 329 | void NNTPviewItem::contextMenuSelected(int which) |
329 | { | 330 | { |
330 | switch (which) | 331 | switch (which) |
331 | { | 332 | { |
332 | case 0: | 333 | case 0: |
333 | disconnect(); | 334 | disconnect(); |
334 | break; | 335 | break; |
335 | case 1: | 336 | case 1: |
336 | setOnOffline(); | 337 | setOnOffline(); |
337 | break; | 338 | break; |
338 | case 2: | 339 | case 2: |
339 | subscribeGroups(); | 340 | subscribeGroups(); |
340 | break; | 341 | break; |
341 | } | 342 | } |
342 | } | 343 | } |
343 | 344 | ||
344 | NNTPfolderItem::~NNTPfolderItem() | 345 | NNTPfolderItem::~NNTPfolderItem() |
345 | {} | 346 | {} |
346 | 347 | ||
347 | NNTPfolderItem::NNTPfolderItem( const FolderP &folderInit, NNTPviewItem *parent , QListViewItem*after ) | 348 | NNTPfolderItem::NNTPfolderItem( const FolderP &folderInit, NNTPviewItem *parent , QListViewItem*after ) |
348 | : AccountViewItem( folderInit, parent,after ) | 349 | : AccountViewItem( folderInit, parent,after ) |
349 | { | 350 | { |
350 | nntp = parent; | 351 | nntp = parent; |
351 | if (folder->getDisplayName().lower()!="inbox") | 352 | if (folder->getDisplayName().lower()!="inbox") |
352 | { | 353 | { |
353 | setPixmap( 0, PIXMAP_POP3FOLDER ); | 354 | setPixmap( 0, PIXMAP_POP3FOLDER ); |
354 | } | 355 | } |
355 | else | 356 | else |
356 | { | 357 | { |
357 | setPixmap( 0, PIXMAP_INBOXFOLDER); | 358 | setPixmap( 0, PIXMAP_INBOXFOLDER); |
358 | } | 359 | } |
359 | setText( 0, folder->getDisplayName() ); | 360 | setText( 0, folder->getDisplayName() ); |
360 | } | 361 | } |
361 | 362 | ||
362 | void NNTPfolderItem::refresh(QValueList<RecMailP>&target) | 363 | void NNTPfolderItem::refresh(QValueList<RecMailP>&target) |
363 | { | 364 | { |
364 | if (folder->may_select()) | 365 | if (folder->may_select()) |
365 | nntp->getWrapper()->listMessages( folder->getName(),target ); | 366 | nntp->getWrapper()->listMessages( folder->getName(),target ); |
366 | } | 367 | } |
367 | 368 | ||
368 | RECBODYP NNTPfolderItem::fetchBody(const RecMailP&aMail) | 369 | RECBODYP NNTPfolderItem::fetchBody(const RecMailP&aMail) |
369 | { | 370 | { |
370 | return nntp->getWrapper()->fetchBody(aMail); | 371 | return nntp->getWrapper()->fetchBody(aMail); |
371 | } | 372 | } |
372 | 373 | ||
373 | QPopupMenu * NNTPfolderItem::getContextMenu() | 374 | QPopupMenu * NNTPfolderItem::getContextMenu() |
374 | { | 375 | { |
375 | QPopupMenu *m = new QPopupMenu(0); | 376 | QPopupMenu *m = new QPopupMenu(0); |
376 | if (m) | 377 | if (m) |
377 | { | 378 | { |
378 | m->insertItem(QObject::tr("Refresh header list",contextName),0); | 379 | m->insertItem(QObject::tr("Refresh header list",contextName),0); |
379 | m->insertItem(QObject::tr("Copy all postings",contextName),1); | 380 | m->insertItem(QObject::tr("Copy all postings",contextName),1); |
380 | } | 381 | } |
381 | return m; | 382 | return m; |
382 | } | 383 | } |
383 | 384 | ||
384 | void NNTPfolderItem::downloadMails() | 385 | void NNTPfolderItem::downloadMails() |
385 | { | 386 | { |
386 | AccountView*bl = nntp->accountView(); | 387 | AccountView*bl = nntp->accountView(); |
387 | if (!bl) return; | 388 | if (!bl) return; |
388 | bl->downloadMails(folder,nntp->getWrapper()); | 389 | bl->downloadMails(folder,nntp->getWrapper()); |
389 | } | 390 | } |
390 | 391 | ||
391 | void NNTPfolderItem::contextMenuSelected(int which) | 392 | void NNTPfolderItem::contextMenuSelected(int which) |
392 | { | 393 | { |
393 | AccountView * view = (AccountView*)listView(); | 394 | AccountView * view = (AccountView*)listView(); |
394 | switch (which) | 395 | switch (which) |
395 | { | 396 | { |
396 | case 0: | 397 | case 0: |
397 | /* must be 'cause pop3 lists are cached */ | 398 | /* must be 'cause pop3 lists are cached */ |
398 | nntp->getWrapper()->logout(); | 399 | nntp->getWrapper()->logout(); |
399 | view->refreshCurrent(); | 400 | view->refreshCurrent(); |
400 | break; | 401 | break; |
401 | case 1: | 402 | case 1: |
402 | downloadMails(); | 403 | downloadMails(); |
403 | break; | 404 | break; |
404 | default: | 405 | default: |
405 | break; | 406 | break; |
406 | } | 407 | } |
407 | } | 408 | } |
408 | 409 | ||
409 | /** | 410 | /** |
410 | * IMAP Account stuff | 411 | * IMAP Account stuff |
411 | */ | 412 | */ |
412 | IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent ) | 413 | IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent ) |
413 | : AccountViewItem( parent ) | 414 | : AccountViewItem( parent ) |
414 | { | 415 | { |
415 | account = a; | 416 | account = a; |
416 | wrapper = AbstractMail::getWrapper( account ); | 417 | wrapper = AbstractMail::getWrapper( account ); |
417 | SETPIX(PIXMAP_IMAPFOLDER); | 418 | SETPIX(PIXMAP_IMAPFOLDER); |
418 | setText( 0, account->getAccountName() ); | 419 | setText( 0, account->getAccountName() ); |
419 | setOpen( true ); | 420 | setOpen( true ); |
420 | } | 421 | } |
421 | 422 | ||
422 | IMAPviewItem::~IMAPviewItem() | 423 | IMAPviewItem::~IMAPviewItem() |
423 | { | 424 | { |
424 | delete wrapper; | 425 | delete wrapper; |
425 | } | 426 | } |
426 | 427 | ||
427 | AbstractMail *IMAPviewItem::getWrapper() | 428 | AbstractMail *IMAPviewItem::getWrapper() |
428 | { | 429 | { |
429 | return wrapper; | 430 | return wrapper; |
430 | } | 431 | } |
431 | 432 | ||
432 | void IMAPviewItem::refresh(QValueList<RecMailP>&) | 433 | void IMAPviewItem::refresh(QValueList<RecMailP>&) |
433 | { | 434 | { |
434 | refreshFolders(false); | 435 | refreshFolders(false); |
435 | } | 436 | } |
436 | 437 | ||
437 | const QStringList&IMAPviewItem::subFolders() | 438 | const QStringList&IMAPviewItem::subFolders() |
438 | { | 439 | { |
439 | return currentFolders; | 440 | return currentFolders; |
440 | } | 441 | } |
441 | 442 | ||
442 | void IMAPviewItem::refreshFolders(bool force) | 443 | void IMAPviewItem::refreshFolders(bool force) |
443 | { | 444 | { |
444 | if (childCount()>0 && force==false) return; | 445 | if (childCount()>0 && force==false) return; |
445 | if (account->getOffline()) return; | 446 | if (account->getOffline()) return; |
446 | 447 | ||
447 | removeChilds(); | 448 | removeChilds(); |
448 | currentFolders.clear(); | 449 | currentFolders.clear(); |
449 | QValueList<FolderP> * folders = wrapper->listFolders(); | 450 | QValueList<FolderP> * folders = wrapper->listFolders(); |
450 | 451 | ||
451 | QValueList<FolderP>::Iterator it; | 452 | QValueList<FolderP>::Iterator it; |
452 | QListViewItem*item = 0; | 453 | QListViewItem*item = 0; |
453 | QListViewItem*titem = 0; | 454 | QListViewItem*titem = 0; |
454 | QString fname,del,search; | 455 | QString fname,del,search; |
455 | int pos; | 456 | int pos; |
456 | 457 | ||
457 | for ( it = folders->begin(); it!=folders->end(); ++it) | 458 | for ( it = folders->begin(); it!=folders->end(); ++it) |
458 | { | 459 | { |
459 | if ((*it)->getDisplayName().lower()=="inbox") | 460 | if ((*it)->getDisplayName().lower()=="inbox") |
460 | { | 461 | { |
461 | item = new IMAPfolderItem( (*it), this , item ); | 462 | item = new IMAPfolderItem( (*it), this , item ); |
462 | folders->remove(it); | 463 | folders->remove(it); |
463 | odebug << "inbox found" << oendl; | 464 | odebug << "inbox found" << oendl; |
464 | break; | 465 | break; |
465 | } | 466 | } |
466 | } | 467 | } |
467 | for ( it = folders->begin(); it!=folders->end(); ++it) | 468 | for ( it = folders->begin(); it!=folders->end(); ++it) |
468 | { | 469 | { |
469 | fname = (*it)->getDisplayName(); | 470 | fname = (*it)->getDisplayName(); |
470 | currentFolders.append((*it)->getName()); | 471 | currentFolders.append((*it)->getName()); |
471 | pos = fname.findRev((*it)->Separator()); | 472 | pos = fname.findRev((*it)->Separator()); |
472 | if (pos != -1) | 473 | if (pos != -1) |
473 | { | 474 | { |
474 | fname = fname.left(pos); | 475 | fname = fname.left(pos); |
475 | } | 476 | } |
476 | IMAPfolderItem*pitem = (IMAPfolderItem*)findSubItem(fname); | 477 | IMAPfolderItem*pitem = (IMAPfolderItem*)findSubItem(fname); |
477 | if (pitem) | 478 | if (pitem) |
478 | { | 479 | { |
479 | titem = item; | 480 | titem = item; |
480 | item = new IMAPfolderItem( (*it),pitem,pitem->firstChild(),this); | 481 | item = new IMAPfolderItem( (*it),pitem,pitem->firstChild(),this); |
481 | /* setup the short name */ | 482 | /* setup the short name */ |
482 | item->setText(0,(*it)->getDisplayName().right((*it)->getDisplayName().length()-pos-1)); | 483 | item->setText(0,(*it)->getDisplayName().right((*it)->getDisplayName().length()-pos-1)); |
483 | item = titem; | 484 | item = titem; |
484 | } | 485 | } |
485 | else | 486 | else |
486 | { | 487 | { |
487 | item = new IMAPfolderItem( (*it), this , item ); | 488 | item = new IMAPfolderItem( (*it), this , item ); |
488 | } | 489 | } |
489 | } | 490 | } |
490 | delete folders; | 491 | delete folders; |
491 | } | 492 | } |
492 | 493 | ||
493 | QPopupMenu * IMAPviewItem::getContextMenu() | 494 | QPopupMenu * IMAPviewItem::getContextMenu() |
494 | { | 495 | { |
495 | QPopupMenu *m = new QPopupMenu(0); | 496 | QPopupMenu *m = new QPopupMenu(0); |
496 | if (m) | 497 | if (m) |
497 | { | 498 | { |
498 | if (!account->getOffline()) | 499 | if (!account->getOffline()) |
499 | { | 500 | { |
500 | m->insertItem(QObject::tr("Refresh folder list",contextName),0); | 501 | m->insertItem(QObject::tr("Refresh folder list",contextName),0); |
501 | m->insertItem(QObject::tr("Create new folder",contextName),1); | 502 | m->insertItem(QObject::tr("Create new folder",contextName),1); |
502 | m->insertSeparator(); | 503 | m->insertSeparator(); |
503 | m->insertItem(QObject::tr("Disconnect",contextName),2); | 504 | m->insertItem(QObject::tr("Disconnect",contextName),2); |
504 | m->insertItem(QObject::tr("Set offline",contextName),3); | 505 | m->insertItem(QObject::tr("Set offline",contextName),3); |
505 | } | 506 | } |
506 | else | 507 | else |
507 | { | 508 | { |
508 | m->insertItem(QObject::tr("Set online",contextName),3); | 509 | m->insertItem(QObject::tr("Set online",contextName),3); |
509 | } | 510 | } |
510 | } | 511 | } |
511 | return m; | 512 | return m; |
512 | } | 513 | } |
513 | 514 | ||
514 | void IMAPviewItem::createNewFolder() | 515 | void IMAPviewItem::createNewFolder() |
515 | { | 516 | { |
516 | Newmdirdlg ndirdlg; | 517 | Newmdirdlg ndirdlg; |
517 | if ( QPEApplication::execDialog( &ndirdlg )) | 518 | if ( QPEApplication::execDialog( &ndirdlg )) |
518 | { | 519 | { |
519 | QString ndir = ndirdlg.Newdir(); | 520 | QString ndir = ndirdlg.Newdir(); |
520 | bool makesubs = ndirdlg.subpossible(); | 521 | bool makesubs = ndirdlg.subpossible(); |
521 | QString delemiter = "/"; | 522 | QString delemiter = "/"; |
522 | IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); | 523 | IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); |
523 | if (item) | 524 | if (item) |
524 | { | 525 | { |
525 | delemiter = item->Delemiter(); | 526 | delemiter = item->Delemiter(); |
526 | } | 527 | } |
527 | if (wrapper->createMbox(ndir,0,delemiter,makesubs)) | 528 | if (wrapper->createMbox(ndir,0,delemiter,makesubs)) |
528 | { | 529 | { |
529 | refreshFolders(true); | 530 | refreshFolders(true); |
530 | } | 531 | } |
531 | } | 532 | } |
532 | } | 533 | } |
533 | 534 | ||
534 | void IMAPviewItem::contextMenuSelected(int id) | 535 | void IMAPviewItem::contextMenuSelected(int id) |
535 | { | 536 | { |
536 | odebug << "Id selected: " << id << "" << oendl; | 537 | odebug << "Id selected: " << id << "" << oendl; |
537 | switch (id) | 538 | switch (id) |
538 | { | 539 | { |
539 | case 0: | 540 | case 0: |
540 | refreshFolders(true); | 541 | refreshFolders(true); |
541 | break; | 542 | break; |
542 | case 1: | 543 | case 1: |
543 | createNewFolder(); | 544 | createNewFolder(); |
544 | break; | 545 | break; |
545 | case 2: | 546 | case 2: |
546 | removeChilds(); | 547 | removeChilds(); |
547 | wrapper->logout(); | 548 | wrapper->logout(); |
548 | break; | 549 | break; |
549 | case 3: | 550 | case 3: |
550 | if (account->getOffline()==false) | 551 | if (account->getOffline()==false) |
551 | { | 552 | { |
552 | removeChilds(); | 553 | removeChilds(); |
553 | wrapper->logout(); | 554 | wrapper->logout(); |
554 | } | 555 | } |
555 | account->setOffline(!account->getOffline()); | 556 | account->setOffline(!account->getOffline()); |
556 | account->save(); | 557 | account->save(); |
557 | SETPIX(PIXMAP_IMAPFOLDER); | 558 | SETPIX(PIXMAP_IMAPFOLDER); |
558 | refreshFolders(false); | 559 | refreshFolders(false); |
559 | break; | 560 | break; |
560 | default: | 561 | default: |
561 | break; | 562 | break; |
562 | } | 563 | } |
563 | } | 564 | } |
564 | 565 | ||
565 | RECBODYP IMAPviewItem::fetchBody(const RecMailP&) | 566 | RECBODYP IMAPviewItem::fetchBody(const RecMailP&) |
566 | { | 567 | { |
567 | return new RecBody(); | 568 | return new RecBody(); |
568 | } | 569 | } |
569 | 570 | ||
570 | bool IMAPviewItem::offline() | 571 | bool IMAPviewItem::offline() |
571 | { | 572 | { |
572 | return account->getOffline(); | 573 | return account->getOffline(); |
573 | } | 574 | } |
574 | 575 | ||
575 | IMAPfolderItem::IMAPfolderItem( const FolderP& folderInit, IMAPviewItem *parent , QListViewItem*after ) | 576 | IMAPfolderItem::IMAPfolderItem( const FolderP& folderInit, IMAPviewItem *parent , QListViewItem*after ) |
576 | : AccountViewItem( folderInit, parent , after ) | 577 | : AccountViewItem( folderInit, parent , after ) |
577 | { | 578 | { |
578 | imap = parent; | 579 | imap = parent; |
579 | if (folder->getDisplayName().lower()!="inbox") | 580 | if (folder->getDisplayName().lower()!="inbox") |
580 | { | 581 | { |
581 | setPixmap( 0, PIXMAP_IMAPFOLDER ); | 582 | setPixmap( 0, PIXMAP_IMAPFOLDER ); |
582 | } | 583 | } |
583 | else | 584 | else |
584 | { | 585 | { |
585 | setPixmap( 0, PIXMAP_INBOXFOLDER); | 586 | setPixmap( 0, PIXMAP_INBOXFOLDER); |
586 | } | 587 | } |
587 | setText( 0, folder->getDisplayName() ); | 588 | setText( 0, folder->getDisplayName() ); |
588 | } | 589 | } |
589 | 590 | ||
590 | IMAPfolderItem::IMAPfolderItem(const FolderP &folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ) | 591 | IMAPfolderItem::IMAPfolderItem(const FolderP &folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ) |
591 | : AccountViewItem(folderInit, parent,after ) | 592 | : AccountViewItem(folderInit, parent,after ) |
592 | { | 593 | { |
593 | imap = master; | 594 | imap = master; |
594 | if (folder->getDisplayName().lower()!="inbox") | 595 | if (folder->getDisplayName().lower()!="inbox") |
595 | { | 596 | { |
596 | setPixmap( 0, PIXMAP_IMAPFOLDER ); | 597 | setPixmap( 0, PIXMAP_IMAPFOLDER ); |
597 | } | 598 | } |
598 | else | 599 | else |
599 | { | 600 | { |
600 | setPixmap( 0, PIXMAP_INBOXFOLDER); | 601 | setPixmap( 0, PIXMAP_INBOXFOLDER); |
601 | } | 602 | } |
602 | setText( 0, folder->getDisplayName() ); | 603 | setText( 0, folder->getDisplayName() ); |
603 | } | 604 | } |
604 | 605 | ||
605 | IMAPfolderItem::~IMAPfolderItem() | 606 | IMAPfolderItem::~IMAPfolderItem() |
606 | {} | 607 | {} |
607 | 608 | ||
608 | const QString& IMAPfolderItem::Delemiter()const | 609 | const QString& IMAPfolderItem::Delemiter()const |
609 | { | 610 | { |
610 | return folder->Separator(); | 611 | return folder->Separator(); |
611 | } | 612 | } |
612 | 613 | ||
613 | void IMAPfolderItem::refresh(QValueList<RecMailP>&target) | 614 | void IMAPfolderItem::refresh(QValueList<RecMailP>&target) |
614 | { | 615 | { |
615 | if (folder->may_select()) | 616 | if (folder->may_select()) |
616 | { | 617 | { |
617 | imap->getWrapper()->listMessages( folder->getName(),target ); | 618 | imap->getWrapper()->listMessages( folder->getName(),target ); |
618 | } | 619 | } |
619 | else | 620 | else |
620 | { | 621 | { |
621 | target.clear(); | 622 | target.clear(); |
622 | } | 623 | } |
623 | } | 624 | } |
624 | 625 | ||
625 | RECBODYP IMAPfolderItem::fetchBody(const RecMailP&aMail) | 626 | RECBODYP IMAPfolderItem::fetchBody(const RecMailP&aMail) |
626 | { | 627 | { |
627 | return imap->getWrapper()->fetchBody(aMail); | 628 | return imap->getWrapper()->fetchBody(aMail); |
628 | } | 629 | } |
629 | 630 | ||
630 | QPopupMenu * IMAPfolderItem::getContextMenu() | 631 | QPopupMenu * IMAPfolderItem::getContextMenu() |
631 | { | 632 | { |
632 | QPopupMenu *m = new QPopupMenu(0); | 633 | QPopupMenu *m = new QPopupMenu(0); |
633 | if (m) | 634 | if (m) |
634 | { | 635 | { |
635 | if (folder->may_select()) | 636 | if (folder->may_select()) |
636 | { | 637 | { |
637 | m->insertItem(QObject::tr("Refresh header list",contextName),0); | 638 | m->insertItem(QObject::tr("Refresh header list",contextName),0); |
638 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),4); | 639 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),4); |
639 | m->insertItem(QObject::tr("Delete all mails",contextName),1); | 640 | m->insertItem(QObject::tr("Delete all mails",contextName),1); |
640 | } | 641 | } |
641 | if (folder->no_inferior()==false) | 642 | if (folder->no_inferior()==false) |
642 | { | 643 | { |
643 | m->insertItem(QObject::tr("Create new subfolder",contextName),2); | 644 | m->insertItem(QObject::tr("Create new subfolder",contextName),2); |
644 | } | 645 | } |
645 | if (folder->getDisplayName().lower()!="inbox") | 646 | if (folder->getDisplayName().lower()!="inbox") |
646 | { | 647 | { |
647 | m->insertItem(QObject::tr("Delete folder",contextName),3); | 648 | m->insertItem(QObject::tr("Delete folder",contextName),3); |
648 | } | 649 | } |
649 | } | 650 | } |
650 | return m; | 651 | return m; |
651 | } | 652 | } |
652 | 653 | ||
653 | void IMAPfolderItem::createNewFolder() | 654 | void IMAPfolderItem::createNewFolder() |
654 | { | 655 | { |
655 | Newmdirdlg ndirdlg; | 656 | Newmdirdlg ndirdlg; |
656 | if ( QPEApplication::execDialog( &ndirdlg ) ) | 657 | if ( QPEApplication::execDialog( &ndirdlg ) ) |
657 | { | 658 | { |
658 | QString ndir = ndirdlg.Newdir(); | 659 | QString ndir = ndirdlg.Newdir(); |
659 | bool makesubs = ndirdlg.subpossible(); | 660 | bool makesubs = ndirdlg.subpossible(); |
660 | QString delemiter = Delemiter(); | 661 | QString delemiter = Delemiter(); |
661 | if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) | 662 | if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) |
662 | { | 663 | { |
663 | imap->refreshFolders(true); | 664 | imap->refreshFolders(true); |
664 | } | 665 | } |
665 | } | 666 | } |
666 | } | 667 | } |
667 | 668 | ||
668 | void IMAPfolderItem::deleteFolder() | 669 | void IMAPfolderItem::deleteFolder() |
669 | { | 670 | { |
670 | int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), | 671 | int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), |
671 | QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), | 672 | QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), |
672 | QObject::tr("Yes",contextName), | 673 | QObject::tr("Yes",contextName), |
673 | QObject::tr("No",contextName),QString::null,1,1); | 674 | QObject::tr("No",contextName),QString::null,1,1); |
674 | odebug << "Auswahl: " << yesno << "" << oendl; | 675 | odebug << "Auswahl: " << yesno << "" << oendl; |
675 | if (yesno == 0) | 676 | if (yesno == 0) |
676 | { | 677 | { |
677 | if (imap->getWrapper()->deleteMbox(folder)) | 678 | if (imap->getWrapper()->deleteMbox(folder)) |
678 | { | 679 | { |
679 | QListView*v=listView(); | 680 | QListView*v=listView(); |
680 | IMAPviewItem * box = imap; | 681 | IMAPviewItem * box = imap; |
681 | /* be carefull - after that this object is destroyd so don't use | 682 | /* be carefull - after that this object is destroyd so don't use |
682 | * any member of it after that call!!*/ | 683 | * any member of it after that call!!*/ |
683 | imap->refreshFolders(true); | 684 | imap->refreshFolders(true); |
684 | if (v) | 685 | if (v) |
685 | { | 686 | { |
686 | v->setSelected(box,true); | 687 | v->setSelected(box,true); |
687 | } | 688 | } |
688 | } | 689 | } |
689 | } | 690 | } |
690 | } | 691 | } |
691 | 692 | ||
692 | void IMAPfolderItem::downloadMails() | 693 | void IMAPfolderItem::downloadMails() |
693 | { | 694 | { |
694 | AccountView*bl = imap->accountView(); | 695 | AccountView*bl = imap->accountView(); |
695 | if (!bl) return; | 696 | if (!bl) return; |
696 | bl->downloadMails(folder,imap->getWrapper()); | 697 | bl->downloadMails(folder,imap->getWrapper()); |
697 | } | 698 | } |
698 | 699 | ||
699 | void IMAPfolderItem::contextMenuSelected(int id) | 700 | void IMAPfolderItem::contextMenuSelected(int id) |
700 | { | 701 | { |
701 | odebug << "Selected id: " << id << "" << oendl; | 702 | odebug << "Selected id: " << id << "" << oendl; |
702 | AccountView * view = (AccountView*)listView(); | 703 | AccountView * view = (AccountView*)listView(); |
703 | switch(id) | 704 | switch(id) |
704 | { | 705 | { |
705 | case 0: | 706 | case 0: |
706 | view->refreshCurrent(); | 707 | view->refreshCurrent(); |
707 | break; | 708 | break; |
708 | case 1: | 709 | case 1: |
709 | deleteAllMail(imap->getWrapper(),folder); | 710 | deleteAllMail(imap->getWrapper(),folder); |
710 | break; | 711 | break; |
711 | case 2: | 712 | case 2: |
712 | createNewFolder(); | 713 | createNewFolder(); |
713 | break; | 714 | break; |
714 | case 3: | 715 | case 3: |
715 | deleteFolder(); | 716 | deleteFolder(); |
716 | break; | 717 | break; |
717 | case 4: | 718 | case 4: |
718 | downloadMails(); | 719 | downloadMails(); |
719 | break; | 720 | break; |
720 | default: | 721 | default: |
721 | break; | 722 | break; |
722 | } | 723 | } |
723 | } | 724 | } |
724 | 725 | ||
725 | /** | 726 | /** |
726 | * MH Account stuff | 727 | * MH Account stuff |
727 | */ | 728 | */ |
728 | /* MH is a little bit different - the top folder can contains messages other than in IMAP and | 729 | /* MH is a little bit different - the top folder can contains messages other than in IMAP and |
729 | POP3 and MBOX */ | 730 | POP3 and MBOX */ |
730 | MHviewItem::MHviewItem( const QString&aPath, AccountView *parent ) | 731 | MHviewItem::MHviewItem( const QString&aPath, AccountView *parent ) |
731 | : AccountViewItem( parent ) | 732 | : AccountViewItem( parent ) |
732 | { | 733 | { |
733 | m_Path = aPath; | 734 | m_Path = aPath; |
734 | /* be carefull - the space within settext is wanted - thats why the string twice */ | 735 | /* be carefull - the space within settext is wanted - thats why the string twice */ |
735 | wrapper = AbstractMail::getWrapper( m_Path,"Local Folders"); | 736 | wrapper = AbstractMail::getWrapper( m_Path,"Local Folders"); |
736 | setPixmap( 0, PIXMAP_LOCALFOLDER ); | 737 | setPixmap( 0, PIXMAP_LOCALFOLDER ); |
737 | setText( 0, " Local Folders" ); | 738 | setText( 0, " Local Folders" ); |
738 | setOpen( true ); | 739 | setOpen( true ); |
739 | folder = 0; | 740 | folder = 0; |
740 | } | 741 | } |
741 | 742 | ||
742 | MHviewItem::~MHviewItem() | 743 | MHviewItem::~MHviewItem() |
743 | { | 744 | { |
744 | delete wrapper; | 745 | delete wrapper; |
745 | } | 746 | } |
746 | 747 | ||
747 | AbstractMail *MHviewItem::getWrapper() | 748 | AbstractMail *MHviewItem::getWrapper() |
748 | { | 749 | { |
749 | return wrapper; | 750 | return wrapper; |
750 | } | 751 | } |
751 | 752 | ||
752 | void MHviewItem::refresh( QValueList<RecMailP> & target) | 753 | void MHviewItem::refresh( QValueList<RecMailP> & target) |
753 | { | 754 | { |
754 | refresh(false); | 755 | refresh(false); |
755 | getWrapper()->listMessages( "",target ); | 756 | getWrapper()->listMessages( "",target ); |
756 | } | 757 | } |
757 | 758 | ||
758 | void MHviewItem::refresh(bool force) | 759 | void MHviewItem::refresh(bool force) |
759 | { | 760 | { |
760 | if (childCount()>0 && force==false) return; | 761 | if (childCount()>0 && force==false) return; |
761 | removeChilds(); | 762 | removeChilds(); |
762 | currentFolders.clear(); | 763 | currentFolders.clear(); |
763 | QValueList<FolderP> *folders = wrapper->listFolders(); | 764 | QValueList<FolderP> *folders = wrapper->listFolders(); |
764 | QValueList<FolderP>::ConstIterator it; | 765 | QValueList<FolderP>::ConstIterator it; |
765 | MHfolderItem*item = 0; | 766 | MHfolderItem*item = 0; |
766 | MHfolderItem*pmaster = 0; | 767 | MHfolderItem*pmaster = 0; |
767 | QString fname = ""; | 768 | QString fname = ""; |
768 | int pos; | 769 | int pos; |
769 | for ( it = folders->begin(); it!=folders->end(); ++it) | 770 | for ( it = folders->begin(); it!=folders->end(); ++it) |
770 | { | 771 | { |
771 | fname = (*it)->getDisplayName(); | 772 | fname = (*it)->getDisplayName(); |
772 | /* this folder itself */ | 773 | /* this folder itself */ |
773 | if (fname=="/") | 774 | if (fname=="/") |
774 | { | 775 | { |
775 | currentFolders.append(fname); | 776 | currentFolders.append(fname); |
776 | folder = (*it); | 777 | folder = (*it); |
777 | continue; | 778 | continue; |
778 | } | 779 | } |
779 | currentFolders.append(fname); | 780 | currentFolders.append(fname); |
780 | pos = fname.findRev("/"); | 781 | pos = fname.findRev("/"); |
781 | if (pos > 0) | 782 | if (pos > 0) |
782 | { | 783 | { |
783 | fname = fname.left(pos); | 784 | fname = fname.left(pos); |
784 | pmaster = (MHfolderItem*)findSubItem(fname); | 785 | pmaster = (MHfolderItem*)findSubItem(fname); |
785 | } | 786 | } |
786 | else | 787 | else |
787 | { | 788 | { |
788 | pmaster = 0; | 789 | pmaster = 0; |
789 | } | 790 | } |
790 | if (pmaster) | 791 | if (pmaster) |
791 | { | 792 | { |
792 | item = new MHfolderItem( (*it), pmaster, item, this ); | 793 | item = new MHfolderItem( (*it), pmaster, item, this ); |
793 | } | 794 | } |
794 | else | 795 | else |
795 | { | 796 | { |
796 | item = new MHfolderItem( (*it), this , item ); | 797 | item = new MHfolderItem( (*it), this , item ); |
797 | } | 798 | } |
798 | item->setSelectable((*it)->may_select()); | 799 | item->setSelectable((*it)->may_select()); |
799 | } | 800 | } |
800 | delete folders; | 801 | delete folders; |
801 | } | 802 | } |
802 | 803 | ||
803 | RECBODYP MHviewItem::fetchBody( const RecMailP &mail ) | 804 | RECBODYP MHviewItem::fetchBody( const RecMailP &mail ) |
804 | { | 805 | { |
805 | odebug << "MH fetchBody" << oendl; | 806 | odebug << "MH fetchBody" << oendl; |
806 | return wrapper->fetchBody( mail ); | 807 | return wrapper->fetchBody( mail ); |
807 | } | 808 | } |
808 | 809 | ||
809 | QPopupMenu * MHviewItem::getContextMenu() | 810 | QPopupMenu * MHviewItem::getContextMenu() |
810 | { | 811 | { |
811 | QPopupMenu *m = new QPopupMenu(0); | 812 | QPopupMenu *m = new QPopupMenu(0); |
812 | if (m) | 813 | if (m) |
813 | { | 814 | { |
814 | m->insertItem(QObject::tr("Refresh folder list",contextName),0); | 815 | m->insertItem(QObject::tr("Refresh folder list",contextName),0); |
815 | m->insertItem(QObject::tr("Create new folder",contextName),1); | 816 | m->insertItem(QObject::tr("Create new folder",contextName),1); |
816 | m->insertItem(QObject::tr("Delete all mails",contextName),2); | 817 | m->insertItem(QObject::tr("Delete all mails",contextName),2); |
817 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),3); | 818 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),3); |
818 | } | 819 | } |
819 | return m; | 820 | return m; |
820 | } | 821 | } |
821 | 822 | ||
822 | void MHviewItem::createFolder() | 823 | void MHviewItem::createFolder() |
823 | { | 824 | { |
824 | Newmdirdlg ndirdlg(0,0,true); | 825 | Newmdirdlg ndirdlg(0,0,true); |
825 | if ( QPEApplication::execDialog( &ndirdlg ) ) | 826 | if ( QPEApplication::execDialog( &ndirdlg ) ) |
826 | { | 827 | { |
827 | QString ndir = ndirdlg.Newdir(); | 828 | QString ndir = ndirdlg.Newdir(); |
828 | if (wrapper->createMbox(ndir)) | 829 | if (wrapper->createMbox(ndir)) |
829 | { | 830 | { |
830 | refresh(true); | 831 | refresh(true); |
831 | } | 832 | } |
832 | } | 833 | } |
833 | } | 834 | } |
834 | 835 | ||
835 | void MHviewItem::downloadMails() | 836 | void MHviewItem::downloadMails() |
836 | { | 837 | { |
837 | AccountView*bl = accountView(); | 838 | AccountView*bl = accountView(); |
838 | if (!bl) return; | 839 | if (!bl) return; |
839 | bl->downloadMails(folder,getWrapper()); | 840 | bl->downloadMails(folder,getWrapper()); |
840 | } | 841 | } |
841 | 842 | ||
842 | QStringList MHviewItem::subFolders() | 843 | QStringList MHviewItem::subFolders() |
843 | { | 844 | { |
844 | return currentFolders; | 845 | return currentFolders; |
845 | } | 846 | } |
846 | 847 | ||
847 | void MHviewItem::contextMenuSelected(int which) | 848 | void MHviewItem::contextMenuSelected(int which) |
848 | { | 849 | { |
849 | switch (which) | 850 | switch (which) |
850 | { | 851 | { |
851 | case 0: | 852 | case 0: |
852 | refresh(true); | 853 | refresh(true); |
853 | break; | 854 | break; |
854 | case 1: | 855 | case 1: |
855 | createFolder(); | 856 | createFolder(); |
856 | break; | 857 | break; |
857 | case 2: | 858 | case 2: |
858 | deleteAllMail(getWrapper(),folder); | 859 | deleteAllMail(getWrapper(),folder); |
859 | break; | 860 | break; |
860 | case 3: | 861 | case 3: |
861 | downloadMails(); | 862 | downloadMails(); |
862 | break; | 863 | break; |
863 | default: | 864 | default: |
864 | break; | 865 | break; |
865 | } | 866 | } |
866 | } | 867 | } |
867 | 868 | ||
868 | MHfolderItem::~MHfolderItem() | 869 | MHfolderItem::~MHfolderItem() |
869 | {} | 870 | {} |
870 | 871 | ||
871 | MHfolderItem::MHfolderItem( const FolderP &folderInit, MHviewItem *parent , QListViewItem*after ) | 872 | MHfolderItem::MHfolderItem( const FolderP &folderInit, MHviewItem *parent , QListViewItem*after ) |
872 | : AccountViewItem(folderInit, parent,after ) | 873 | : AccountViewItem(folderInit, parent,after ) |
873 | { | 874 | { |
874 | mbox = parent; | 875 | mbox = parent; |
875 | initName(); | 876 | initName(); |
876 | } | 877 | } |
877 | 878 | ||
878 | MHfolderItem::MHfolderItem(const FolderP& folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master) | 879 | MHfolderItem::MHfolderItem(const FolderP& folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master) |
879 | : AccountViewItem(folderInit, parent,after ) | 880 | : AccountViewItem(folderInit, parent,after ) |
880 | { | 881 | { |
881 | folder = folderInit; | 882 | folder = folderInit; |
882 | mbox = master; | 883 | mbox = master; |
883 | initName(); | 884 | initName(); |
884 | } | 885 | } |
885 | 886 | ||
886 | void MHfolderItem::initName() | 887 | void MHfolderItem::initName() |
887 | { | 888 | { |
888 | QString bName = folder->getDisplayName(); | 889 | QString bName = folder->getDisplayName(); |
889 | if (bName.startsWith("/")&&bName.length()>1) | 890 | if (bName.startsWith("/")&&bName.length()>1) |
890 | { | 891 | { |
891 | bName.replace(0,1,""); | 892 | bName.replace(0,1,""); |
892 | } | 893 | } |
893 | int pos = bName.findRev("/"); | 894 | int pos = bName.findRev("/"); |
894 | if (pos > 0) | 895 | if (pos > 0) |
895 | { | 896 | { |
896 | bName.replace(0,pos+1,""); | 897 | bName.replace(0,pos+1,""); |
897 | } | 898 | } |
898 | if (bName.lower() == "outgoing") | 899 | if (bName.lower() == "outgoing") |
899 | { | 900 | { |
900 | setPixmap( 0, PIXMAP_OUTBOXFOLDER ); | 901 | setPixmap( 0, PIXMAP_OUTBOXFOLDER ); |
901 | } | 902 | } |
902 | else if (bName.lower() == "inbox") | 903 | else if (bName.lower() == "inbox") |
903 | { | 904 | { |
904 | setPixmap( 0, PIXMAP_INBOXFOLDER); | 905 | setPixmap( 0, PIXMAP_INBOXFOLDER); |
905 | } else if (bName.lower() == "drafts") { | 906 | } else if (bName.lower() == "drafts") { |
906 | setPixmap(0, Resource::loadPixmap("inline/edit")); | 907 | setPixmap(0, Resource::loadPixmap("inline/edit")); |
907 | } else { | 908 | } else { |
908 | setPixmap( 0, PIXMAP_MBOXFOLDER ); | 909 | setPixmap( 0, PIXMAP_MBOXFOLDER ); |
909 | } | 910 | } |
910 | setText( 0, bName ); | 911 | setText( 0, bName ); |
911 | } | 912 | } |
912 | 913 | ||
913 | const FolderP&MHfolderItem::getFolder()const | 914 | const FolderP&MHfolderItem::getFolder()const |
914 | { | 915 | { |
915 | return folder; | 916 | return folder; |
916 | } | 917 | } |
917 | 918 | ||
918 | void MHfolderItem::refresh(QValueList<RecMailP>&target) | 919 | void MHfolderItem::refresh(QValueList<RecMailP>&target) |
919 | { | 920 | { |
920 | if (folder->may_select()) | 921 | if (folder->may_select()) |
921 | mbox->getWrapper()->listMessages( folder->getName(),target ); | 922 | mbox->getWrapper()->listMessages( folder->getName(),target ); |
922 | } | 923 | } |
923 | 924 | ||
924 | RECBODYP MHfolderItem::fetchBody(const RecMailP&aMail) | 925 | RECBODYP MHfolderItem::fetchBody(const RecMailP&aMail) |
925 | { | 926 | { |
926 | return mbox->getWrapper()->fetchBody(aMail); | 927 | return mbox->getWrapper()->fetchBody(aMail); |
927 | } | 928 | } |
928 | 929 | ||
929 | void MHfolderItem::deleteFolder() | 930 | void MHfolderItem::deleteFolder() |
930 | { | 931 | { |
931 | int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), | 932 | int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), |
932 | QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), | 933 | QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), |
933 | QObject::tr("Yes",contextName), | 934 | QObject::tr("Yes",contextName), |
934 | QObject::tr("No",contextName),QString::null,1,1); | 935 | QObject::tr("No",contextName),QString::null,1,1); |
935 | odebug << "Auswahl: " << yesno << "" << oendl; | 936 | odebug << "Auswahl: " << yesno << "" << oendl; |
936 | if (yesno == 0) | 937 | if (yesno == 0) |
937 | { | 938 | { |
938 | if (mbox->getWrapper()->deleteMbox(folder)) | 939 | if (mbox->getWrapper()->deleteMbox(folder)) |
939 | { | 940 | { |
940 | QListView*v=listView(); | 941 | QListView*v=listView(); |
941 | MHviewItem * box = mbox; | 942 | MHviewItem * box = mbox; |
942 | /* be carefull - after that this object is destroyd so don't use | 943 | /* be carefull - after that this object is destroyd so don't use |
943 | * any member of it after that call!!*/ | 944 | * any member of it after that call!!*/ |
944 | mbox->refresh(true); | 945 | mbox->refresh(true); |
945 | if (v) | 946 | if (v) |
946 | { | 947 | { |
947 | v->setSelected(box,true); | 948 | v->setSelected(box,true); |
948 | } | 949 | } |
949 | } | 950 | } |
950 | } | 951 | } |
951 | } | 952 | } |
952 | 953 | ||
953 | QPopupMenu * MHfolderItem::getContextMenu() | 954 | QPopupMenu * MHfolderItem::getContextMenu() |
954 | { | 955 | { |
955 | QPopupMenu *m = new QPopupMenu(0); | 956 | QPopupMenu *m = new QPopupMenu(0); |
956 | if (m) | 957 | if (m) |
957 | { | 958 | { |
958 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); | 959 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); |
959 | m->insertItem(QObject::tr("Delete all mails",contextName),0); | 960 | m->insertItem(QObject::tr("Delete all mails",contextName),0); |
960 | m->insertItem(QObject::tr("Create new subfolder",contextName),3); | 961 | m->insertItem(QObject::tr("Create new subfolder",contextName),3); |
961 | m->insertItem(QObject::tr("Delete folder",contextName),1); | 962 | m->insertItem(QObject::tr("Delete folder",contextName),1); |
962 | } | 963 | } |
963 | return m; | 964 | return m; |
964 | } | 965 | } |
965 | 966 | ||
966 | void MHfolderItem::downloadMails() | 967 | void MHfolderItem::downloadMails() |
967 | { | 968 | { |
968 | AccountView*bl = mbox->accountView(); | 969 | AccountView*bl = mbox->accountView(); |
969 | if (!bl) return; | 970 | if (!bl) return; |
970 | bl->downloadMails(folder,mbox->getWrapper()); | 971 | bl->downloadMails(folder,mbox->getWrapper()); |
971 | } | 972 | } |
972 | 973 | ||
973 | void MHfolderItem::createFolder() | 974 | void MHfolderItem::createFolder() |
974 | { | 975 | { |
975 | Newmdirdlg ndirdlg(0,0,true); | 976 | Newmdirdlg ndirdlg(0,0,true); |
976 | if ( QPEApplication::execDialog( &ndirdlg ) ) | 977 | if ( QPEApplication::execDialog( &ndirdlg ) ) |
977 | { | 978 | { |
978 | QString ndir = ndirdlg.Newdir(); | 979 | QString ndir = ndirdlg.Newdir(); |
979 | if (mbox->getWrapper()->createMbox(ndir,folder)) | 980 | if (mbox->getWrapper()->createMbox(ndir,folder)) |
980 | { | 981 | { |
981 | QListView*v=listView(); | 982 | QListView*v=listView(); |
982 | MHviewItem * box = mbox; | 983 | MHviewItem * box = mbox; |
983 | /* be carefull - after that this object is destroyd so don't use | 984 | /* be carefull - after that this object is destroyd so don't use |
984 | * any member of it after that call!!*/ | 985 | * any member of it after that call!!*/ |
985 | mbox->refresh(true); | 986 | mbox->refresh(true); |
986 | if (v) | 987 | if (v) |
987 | { | 988 | { |
988 | v->setSelected(box,true); | 989 | v->setSelected(box,true); |
989 | } | 990 | } |
990 | } | 991 | } |
991 | } | 992 | } |
992 | } | 993 | } |
993 | 994 | ||
994 | void MHfolderItem::contextMenuSelected(int which) | 995 | void MHfolderItem::contextMenuSelected(int which) |
995 | { | 996 | { |
996 | switch(which) | 997 | switch(which) |
997 | { | 998 | { |
998 | case 0: | 999 | case 0: |
999 | deleteAllMail(mbox->getWrapper(),folder); | 1000 | deleteAllMail(mbox->getWrapper(),folder); |
1000 | break; | 1001 | break; |
1001 | case 1: | 1002 | case 1: |
1002 | deleteFolder(); | 1003 | deleteFolder(); |
1003 | break; | 1004 | break; |
1004 | case 2: | 1005 | case 2: |
1005 | downloadMails(); | 1006 | downloadMails(); |
1006 | break; | 1007 | break; |
1007 | case 3: | 1008 | case 3: |
1008 | createFolder(); | 1009 | createFolder(); |
1009 | break; | 1010 | break; |
1010 | default: | 1011 | default: |
1011 | break; | 1012 | break; |
1012 | } | 1013 | } |
1013 | } | 1014 | } |
1014 | 1015 | ||
1015 | bool MHfolderItem::isDraftfolder() | 1016 | bool MHfolderItem::isDraftfolder() |
1016 | { | 1017 | { |
1017 | if (folder && folder->getName()==AbstractMail::defaultLocalfolder()+"/"+AbstractMail::draftFolder()) return true; | 1018 | if (folder && folder->getName()==AbstractMail::defaultLocalfolder()+"/"+AbstractMail::draftFolder()) return true; |
1018 | return false; | 1019 | return false; |
1019 | } | 1020 | } |
1020 | 1021 | ||
1021 | /** | 1022 | /** |
1022 | * Generic stuff | 1023 | * Generic stuff |
1023 | */ | 1024 | */ |
1024 | 1025 | ||
1025 | const QString AccountViewItem::contextName="AccountViewItem"; | 1026 | const QString AccountViewItem::contextName="AccountViewItem"; |
1026 | 1027 | ||
1027 | AccountViewItem::AccountViewItem( AccountView *parent ) | 1028 | AccountViewItem::AccountViewItem( AccountView *parent ) |
1028 | : QListViewItem( parent ) | 1029 | : QListViewItem( parent ) |
1029 | { | 1030 | { |
1030 | init(); | 1031 | init(); |
1031 | m_Backlink = parent; | 1032 | m_Backlink = parent; |
1032 | } | 1033 | } |
1033 | 1034 | ||
1034 | AccountViewItem::AccountViewItem( QListViewItem *parent) | 1035 | AccountViewItem::AccountViewItem( QListViewItem *parent) |
1035 | : QListViewItem( parent),folder(0) | 1036 | : QListViewItem( parent),folder(0) |
1036 | { | 1037 | { |
1037 | init(); | 1038 | init(); |
1038 | } | 1039 | } |
1039 | 1040 | ||
1040 | AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after ) | 1041 | AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after ) |
1041 | :QListViewItem( parent,after ),folder(0) | 1042 | :QListViewItem( parent,after ),folder(0) |
1042 | { | 1043 | { |
1043 | init(); | 1044 | init(); |
1044 | } | 1045 | } |
1045 | 1046 | ||
1046 | AccountViewItem::AccountViewItem( const Opie::Core::OSmartPointer<Folder>&folderInit,QListViewItem *parent , QListViewItem*after ) | 1047 | AccountViewItem::AccountViewItem( const Opie::Core::OSmartPointer<Folder>&folderInit,QListViewItem *parent , QListViewItem*after ) |
1047 | :QListViewItem( parent,after ),folder(folderInit) | 1048 | :QListViewItem( parent,after ),folder(folderInit) |
1048 | { | 1049 | { |
1049 | init(); | 1050 | init(); |
1050 | } | 1051 | } |
1051 | 1052 | ||
1052 | void AccountViewItem::init() | 1053 | void AccountViewItem::init() |
1053 | { | 1054 | { |
1054 | m_Backlink = 0; | 1055 | m_Backlink = 0; |
1055 | } | 1056 | } |
1056 | 1057 | ||
1057 | AccountViewItem::~AccountViewItem() | 1058 | AccountViewItem::~AccountViewItem() |
1058 | { | 1059 | { |
1059 | folder = 0; | 1060 | folder = 0; |
1060 | } | 1061 | } |
1061 | 1062 | ||
1062 | AccountView*AccountViewItem::accountView() | 1063 | AccountView*AccountViewItem::accountView() |
1063 | { | 1064 | { |
1064 | return m_Backlink; | 1065 | return m_Backlink; |
1065 | } | 1066 | } |
1066 | 1067 | ||
1067 | void AccountViewItem::deleteAllMail(AbstractMail*wrapper,const FolderP&folder) | 1068 | void AccountViewItem::deleteAllMail(AbstractMail*wrapper,const FolderP&folder) |
1068 | { | 1069 | { |
1069 | if (!wrapper) return; | 1070 | if (!wrapper) return; |
1070 | QString fname=""; | 1071 | QString fname=""; |
1071 | if (folder) fname = folder->getDisplayName(); | 1072 | if (folder) fname = folder->getDisplayName(); |
1072 | int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName), | 1073 | int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName), |
1073 | QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName). | 1074 | QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName). |
1074 | arg(fname), | 1075 | arg(fname), |
1075 | QObject::tr("Yes",contextName), | 1076 | QObject::tr("Yes",contextName), |
1076 | QObject::tr("No",contextName),QString::null,1,1); | 1077 | QObject::tr("No",contextName),QString::null,1,1); |
1077 | odebug << "Auswahl: " << yesno << "" << oendl; | 1078 | odebug << "Auswahl: " << yesno << "" << oendl; |
1078 | if (yesno == 0) | 1079 | if (yesno == 0) |
1079 | { | 1080 | { |
1080 | if (wrapper->deleteAllMail(folder)) | 1081 | if (wrapper->deleteAllMail(folder)) |
1081 | { | 1082 | { |
1082 | AccountView * view = (AccountView*)listView(); | 1083 | AccountView * view = (AccountView*)listView(); |
1083 | if (view) view->refreshCurrent(); | 1084 | if (view) view->refreshCurrent(); |
1084 | } | 1085 | } |
1085 | } | 1086 | } |
1086 | } | 1087 | } |
1087 | 1088 | ||
1088 | void AccountViewItem::removeChilds() | 1089 | void AccountViewItem::removeChilds() |
1089 | { | 1090 | { |
1090 | QListViewItem *child = firstChild(); | 1091 | QListViewItem *child = firstChild(); |
1091 | while ( child ) | 1092 | while ( child ) |
1092 | { | 1093 | { |
1093 | QListViewItem *tmp = child; | 1094 | QListViewItem *tmp = child; |
1094 | child = child->nextSibling(); | 1095 | child = child->nextSibling(); |
1095 | delete tmp; | 1096 | delete tmp; |
1096 | } | 1097 | } |
1097 | } | 1098 | } |
1098 | 1099 | ||
1099 | bool AccountViewItem::matchName(const QString&name)const | 1100 | bool AccountViewItem::matchName(const QString&name)const |
1100 | { | 1101 | { |
1101 | if (!folder) return false; | 1102 | if (!folder) return false; |
1102 | return folder->getDisplayName()==name; | 1103 | return folder->getDisplayName()==name; |
1103 | } | 1104 | } |
1104 | 1105 | ||
1105 | 1106 | ||
1106 | AccountViewItem*AccountViewItem::findSubItem(const QString&path,AccountViewItem*start) | 1107 | AccountViewItem*AccountViewItem::findSubItem(const QString&path,AccountViewItem*start) |
1107 | { | 1108 | { |
1108 | AccountViewItem*pitem,*sitem; | 1109 | AccountViewItem*pitem,*sitem; |
1109 | if (!start) pitem = (AccountViewItem*)firstChild(); | 1110 | if (!start) pitem = (AccountViewItem*)firstChild(); |
1110 | else pitem = (AccountViewItem*)start->firstChild(); | 1111 | else pitem = (AccountViewItem*)start->firstChild(); |
1111 | while (pitem) | 1112 | while (pitem) |
1112 | { | 1113 | { |
1113 | if (pitem->matchName(path)) | 1114 | if (pitem->matchName(path)) |
1114 | { | 1115 | { |
1115 | break; | 1116 | break; |
1116 | } | 1117 | } |
1117 | if (pitem->childCount()>0) | 1118 | if (pitem->childCount()>0) |
1118 | { | 1119 | { |
1119 | sitem = findSubItem(path,pitem); | 1120 | sitem = findSubItem(path,pitem); |
1120 | if (sitem) | 1121 | if (sitem) |
1121 | { | 1122 | { |
1122 | pitem = sitem; | 1123 | pitem = sitem; |
1123 | break; | 1124 | break; |
1124 | } | 1125 | } |
1125 | } | 1126 | } |
1126 | pitem=(AccountViewItem*)pitem->nextSibling(); | 1127 | pitem=(AccountViewItem*)pitem->nextSibling(); |
1127 | } | 1128 | } |
1128 | return pitem; | 1129 | return pitem; |
1129 | } | 1130 | } |
1130 | 1131 | ||
1131 | bool AccountViewItem::isDraftfolder() | 1132 | bool AccountViewItem::isDraftfolder() |
1132 | { | 1133 | { |
1133 | return false; | 1134 | return false; |
1134 | } | 1135 | } |
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp index 0052061..662e555 100644 --- a/noncore/net/mail/accountview.cpp +++ b/noncore/net/mail/accountview.cpp | |||
@@ -1,176 +1,178 @@ | |||
1 | 1 | ||
2 | #include "accountview.h" | 2 | #include "accountview.h" |
3 | #include "accountitem.h" | 3 | #include "accountitem.h" |
4 | #include "selectstore.h" | 4 | #include "selectstore.h" |
5 | 5 | ||
6 | /* OPIE */ | ||
7 | #include <libmailwrapper/settings.h> | 6 | #include <libmailwrapper/settings.h> |
8 | #include <libmailwrapper/mailwrapper.h> | 7 | #include <libmailwrapper/mailwrapper.h> |
9 | #include <libmailwrapper/mailtypes.h> | 8 | #include <libmailwrapper/mailtypes.h> |
10 | #include <libmailwrapper/abstractmail.h> | 9 | #include <libmailwrapper/abstractmail.h> |
10 | |||
11 | /* OPIE */ | ||
12 | #include <opie2/odebug.h> | ||
11 | #include <qpe/qpeapplication.h> | 13 | #include <qpe/qpeapplication.h> |
12 | 14 | ||
13 | /* QT */ | 15 | /* QT */ |
14 | #include <qmessagebox.h> | 16 | #include <qmessagebox.h> |
15 | #include <qpopupmenu.h> | 17 | #include <qpopupmenu.h> |
16 | 18 | ||
17 | using namespace Opie::Core; | 19 | using namespace Opie::Core; |
18 | AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) | 20 | AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) |
19 | : QListView( parent, name, flags ) | 21 | : QListView( parent, name, flags ) |
20 | { | 22 | { |
21 | connect( this, SIGNAL( selectionChanged(QListViewItem*) ), | 23 | connect( this, SIGNAL( selectionChanged(QListViewItem*) ), |
22 | SLOT( refresh(QListViewItem*) ) ); | 24 | SLOT( refresh(QListViewItem*) ) ); |
23 | connect( this, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this, | 25 | connect( this, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this, |
24 | SLOT( slotHold(int,QListViewItem*,const QPoint&,int) ) ); | 26 | SLOT( slotHold(int,QListViewItem*,const QPoint&,int) ) ); |
25 | setSorting(0); | 27 | setSorting(0); |
26 | } | 28 | } |
27 | 29 | ||
28 | AccountView::~AccountView() | 30 | AccountView::~AccountView() |
29 | { | 31 | { |
30 | imapAccounts.clear(); | 32 | imapAccounts.clear(); |
31 | mhAccounts.clear(); | 33 | mhAccounts.clear(); |
32 | } | 34 | } |
33 | 35 | ||
34 | void AccountView::slotContextMenu(int id) | 36 | void AccountView::slotContextMenu(int id) |
35 | { | 37 | { |
36 | AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); | 38 | AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); |
37 | if (!view) return; | 39 | if (!view) return; |
38 | view->contextMenuSelected(id); | 40 | view->contextMenuSelected(id); |
39 | } | 41 | } |
40 | 42 | ||
41 | void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) | 43 | void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) |
42 | { | 44 | { |
43 | if (button==1) {return;} | 45 | if (button==1) {return;} |
44 | if (!item) return; | 46 | if (!item) return; |
45 | AccountViewItem *view = static_cast<AccountViewItem *>(item); | 47 | AccountViewItem *view = static_cast<AccountViewItem *>(item); |
46 | QPopupMenu*m = view->getContextMenu(); | 48 | QPopupMenu*m = view->getContextMenu(); |
47 | if (!m) return; | 49 | if (!m) return; |
48 | connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int))); | 50 | connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int))); |
49 | m->setFocus(); | 51 | m->setFocus(); |
50 | m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); | 52 | m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); |
51 | delete m; | 53 | delete m; |
52 | } | 54 | } |
53 | 55 | ||
54 | void AccountView::populate( QList<Account> list ) | 56 | void AccountView::populate( QList<Account> list ) |
55 | { | 57 | { |
56 | clear(); | 58 | clear(); |
57 | 59 | ||
58 | imapAccounts.clear(); | 60 | imapAccounts.clear(); |
59 | mhAccounts.clear(); | 61 | mhAccounts.clear(); |
60 | 62 | ||
61 | mhAccounts.append(new MHviewItem(AbstractMail::defaultLocalfolder(),this)); | 63 | mhAccounts.append(new MHviewItem(AbstractMail::defaultLocalfolder(),this)); |
62 | 64 | ||
63 | Account *it; | 65 | Account *it; |
64 | for ( it = list.first(); it; it = list.next() ) | 66 | for ( it = list.first(); it; it = list.next() ) |
65 | { | 67 | { |
66 | if ( it->getType() == MAILLIB::A_IMAP ) | 68 | if ( it->getType() == MAILLIB::A_IMAP ) |
67 | { | 69 | { |
68 | IMAPaccount *imap = static_cast<IMAPaccount *>(it); | 70 | IMAPaccount *imap = static_cast<IMAPaccount *>(it); |
69 | odebug << "added IMAP " + imap->getAccountName() << oendl; | 71 | odebug << "added IMAP " + imap->getAccountName() << oendl; |
70 | imapAccounts.append(new IMAPviewItem( imap, this )); | 72 | imapAccounts.append(new IMAPviewItem( imap, this )); |
71 | } | 73 | } |
72 | else if ( it->getType() == MAILLIB::A_POP3 ) | 74 | else if ( it->getType() == MAILLIB::A_POP3 ) |
73 | { | 75 | { |
74 | POP3account *pop3 = static_cast<POP3account *>(it); | 76 | POP3account *pop3 = static_cast<POP3account *>(it); |
75 | odebug << "added POP3 " + pop3->getAccountName() << oendl; | 77 | odebug << "added POP3 " + pop3->getAccountName() << oendl; |
76 | /* must not be hold 'cause it isn't required */ | 78 | /* must not be hold 'cause it isn't required */ |
77 | (void) new POP3viewItem( pop3, this ); | 79 | (void) new POP3viewItem( pop3, this ); |
78 | } | 80 | } |
79 | else if ( it->getType() == MAILLIB::A_NNTP ) | 81 | else if ( it->getType() == MAILLIB::A_NNTP ) |
80 | { | 82 | { |
81 | NNTPaccount *nntp = static_cast<NNTPaccount *>(it); | 83 | NNTPaccount *nntp = static_cast<NNTPaccount *>(it); |
82 | odebug << "added NNTP " + nntp->getAccountName() << oendl; | 84 | odebug << "added NNTP " + nntp->getAccountName() << oendl; |
83 | /* must not be hold 'cause it isn't required */ | 85 | /* must not be hold 'cause it isn't required */ |
84 | (void) new NNTPviewItem( nntp, this ); | 86 | (void) new NNTPviewItem( nntp, this ); |
85 | } | 87 | } |
86 | } | 88 | } |
87 | } | 89 | } |
88 | 90 | ||
89 | void AccountView::refresh(QListViewItem *item) | 91 | void AccountView::refresh(QListViewItem *item) |
90 | { | 92 | { |
91 | 93 | ||
92 | odebug << "AccountView refresh..." << oendl; | 94 | odebug << "AccountView refresh..." << oendl; |
93 | if ( item ) | 95 | if ( item ) |
94 | { | 96 | { |
95 | m_currentItem = item; | 97 | m_currentItem = item; |
96 | QValueList<RecMailP> headerlist; | 98 | QValueList<RecMailP> headerlist; |
97 | AccountViewItem *view = static_cast<AccountViewItem *>(item); | 99 | AccountViewItem *view = static_cast<AccountViewItem *>(item); |
98 | view->refresh(headerlist); | 100 | view->refresh(headerlist); |
99 | emit refreshMailview(headerlist); | 101 | emit refreshMailview(headerlist); |
100 | } | 102 | } |
101 | } | 103 | } |
102 | 104 | ||
103 | void AccountView::refreshCurrent() | 105 | void AccountView::refreshCurrent() |
104 | { | 106 | { |
105 | m_currentItem = currentItem(); | 107 | m_currentItem = currentItem(); |
106 | if ( !m_currentItem ) return; | 108 | if ( !m_currentItem ) return; |
107 | QValueList<RecMailP> headerlist; | 109 | QValueList<RecMailP> headerlist; |
108 | AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); | 110 | AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); |
109 | view->refresh(headerlist); | 111 | view->refresh(headerlist); |
110 | emit refreshMailview(headerlist); | 112 | emit refreshMailview(headerlist); |
111 | } | 113 | } |
112 | 114 | ||
113 | void AccountView::refreshAll() | 115 | void AccountView::refreshAll() |
114 | { | 116 | { |
115 | } | 117 | } |
116 | 118 | ||
117 | RecBodyP AccountView::fetchBody(const RecMailP&aMail) | 119 | RecBodyP AccountView::fetchBody(const RecMailP&aMail) |
118 | { | 120 | { |
119 | QListViewItem*item = selectedItem (); | 121 | QListViewItem*item = selectedItem (); |
120 | if (!item) return new RecBody(); | 122 | if (!item) return new RecBody(); |
121 | AccountViewItem *view = static_cast<AccountViewItem *>(item); | 123 | AccountViewItem *view = static_cast<AccountViewItem *>(item); |
122 | return view->fetchBody(aMail); | 124 | return view->fetchBody(aMail); |
123 | } | 125 | } |
124 | 126 | ||
125 | void AccountView::setupFolderselect(Selectstore*sels) | 127 | void AccountView::setupFolderselect(Selectstore*sels) |
126 | { | 128 | { |
127 | QPEApplication::showDialog( sels ); | 129 | QPEApplication::showDialog( sels ); |
128 | QStringList sFolders; | 130 | QStringList sFolders; |
129 | unsigned int i = 0; | 131 | unsigned int i = 0; |
130 | for (i=0; i < mhAccounts.count();++i) | 132 | for (i=0; i < mhAccounts.count();++i) |
131 | { | 133 | { |
132 | mhAccounts[i]->refresh(false); | 134 | mhAccounts[i]->refresh(false); |
133 | sFolders = mhAccounts[i]->subFolders(); | 135 | sFolders = mhAccounts[i]->subFolders(); |
134 | sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders); | 136 | sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders); |
135 | } | 137 | } |
136 | for (i=0; i < imapAccounts.count();++i) | 138 | for (i=0; i < imapAccounts.count();++i) |
137 | { | 139 | { |
138 | if (imapAccounts[i]->offline()) | 140 | if (imapAccounts[i]->offline()) |
139 | continue; | 141 | continue; |
140 | imapAccounts[i]->refreshFolders(false); | 142 | imapAccounts[i]->refreshFolders(false); |
141 | sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders()); | 143 | sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders()); |
142 | } | 144 | } |
143 | } | 145 | } |
144 | 146 | ||
145 | void AccountView::downloadMails(const FolderP&fromFolder,AbstractMail*fromWrapper) | 147 | void AccountView::downloadMails(const FolderP&fromFolder,AbstractMail*fromWrapper) |
146 | { | 148 | { |
147 | AbstractMail*targetMail = 0; | 149 | AbstractMail*targetMail = 0; |
148 | QString targetFolder = ""; | 150 | QString targetFolder = ""; |
149 | Selectstore sels; | 151 | Selectstore sels; |
150 | setupFolderselect(&sels); | 152 | setupFolderselect(&sels); |
151 | if (!sels.exec()) return; | 153 | if (!sels.exec()) return; |
152 | targetMail = sels.currentMail(); | 154 | targetMail = sels.currentMail(); |
153 | targetFolder = sels.currentFolder(); | 155 | targetFolder = sels.currentFolder(); |
154 | if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || | 156 | if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || |
155 | targetFolder.isEmpty()) | 157 | targetFolder.isEmpty()) |
156 | { | 158 | { |
157 | return; | 159 | return; |
158 | } | 160 | } |
159 | if (sels.newFolder() && !targetMail->createMbox(targetFolder)) | 161 | if (sels.newFolder() && !targetMail->createMbox(targetFolder)) |
160 | { | 162 | { |
161 | QMessageBox::critical(0,tr("Error creating new Folder"), | 163 | QMessageBox::critical(0,tr("Error creating new Folder"), |
162 | tr("<center>Error while creating<br>new folder - breaking.</center>")); | 164 | tr("<center>Error while creating<br>new folder - breaking.</center>")); |
163 | return; | 165 | return; |
164 | } | 166 | } |
165 | odebug << "Targetfolder: " << targetFolder.latin1() << "" << oendl; | 167 | odebug << "Targetfolder: " << targetFolder.latin1() << "" << oendl; |
166 | odebug << "Fromfolder: " << fromFolder->getName().latin1() << "" << oendl; | 168 | odebug << "Fromfolder: " << fromFolder->getName().latin1() << "" << oendl; |
167 | fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails()); | 169 | fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails()); |
168 | refreshCurrent(); | 170 | refreshCurrent(); |
169 | } | 171 | } |
170 | 172 | ||
171 | bool AccountView::currentisDraft() | 173 | bool AccountView::currentisDraft() |
172 | { | 174 | { |
173 | AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); | 175 | AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); |
174 | if (!view) return false; | 176 | if (!view) return false; |
175 | return view->isDraftfolder(); | 177 | return view->isDraftfolder(); |
176 | } | 178 | } |
diff --git a/noncore/net/mail/composemail.cpp b/noncore/net/mail/composemail.cpp index fa703c4..b15e692 100644 --- a/noncore/net/mail/composemail.cpp +++ b/noncore/net/mail/composemail.cpp | |||
@@ -1,302 +1,303 @@ | |||
1 | #include <qt.h> | 1 | #include <qt.h> |
2 | 2 | ||
3 | #include <opie2/ofiledialog.h> | 3 | #include <opie2/ofiledialog.h> |
4 | #include <opie2/odebug.h> | ||
4 | #include <qpe/resource.h> | 5 | #include <qpe/resource.h> |
5 | #include <qpe/config.h> | 6 | #include <qpe/config.h> |
6 | #include <qpe/global.h> | 7 | #include <qpe/global.h> |
7 | #include <qpe/contact.h> | 8 | #include <qpe/contact.h> |
8 | 9 | ||
9 | #include "composemail.h" | 10 | #include "composemail.h" |
10 | 11 | ||
11 | #include <libmailwrapper/smtpwrapper.h> | 12 | #include <libmailwrapper/smtpwrapper.h> |
12 | #include <libmailwrapper/storemail.h> | 13 | #include <libmailwrapper/storemail.h> |
13 | #include <libmailwrapper/abstractmail.h> | 14 | #include <libmailwrapper/abstractmail.h> |
14 | #include <libmailwrapper/mailtypes.h> | 15 | #include <libmailwrapper/mailtypes.h> |
15 | 16 | ||
16 | using namespace Opie::Core; | 17 | using namespace Opie::Core; |
17 | using namespace Opie::Ui; | 18 | using namespace Opie::Ui; |
18 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) | 19 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) |
19 | : ComposeMailUI( parent, name, modal, flags ) | 20 | : ComposeMailUI( parent, name, modal, flags ) |
20 | { | 21 | { |
21 | settings = s; | 22 | settings = s; |
22 | m_replyid = ""; | 23 | m_replyid = ""; |
23 | 24 | ||
24 | QString vfilename = Global::applicationFileName("addressbook", | 25 | QString vfilename = Global::applicationFileName("addressbook", |
25 | "businesscard.vcf"); | 26 | "businesscard.vcf"); |
26 | Contact c; | 27 | Contact c; |
27 | if (QFile::exists(vfilename)) { | 28 | if (QFile::exists(vfilename)) { |
28 | c = Contact::readVCard( vfilename )[0]; | 29 | c = Contact::readVCard( vfilename )[0]; |
29 | } | 30 | } |
30 | 31 | ||
31 | QStringList mails = c.emailList(); | 32 | QStringList mails = c.emailList(); |
32 | QString defmail = c.defaultEmail(); | 33 | QString defmail = c.defaultEmail(); |
33 | 34 | ||
34 | if (defmail.length()!=0) { | 35 | if (defmail.length()!=0) { |
35 | fromBox->insertItem(defmail); | 36 | fromBox->insertItem(defmail); |
36 | } | 37 | } |
37 | QStringList::ConstIterator sit = mails.begin(); | 38 | QStringList::ConstIterator sit = mails.begin(); |
38 | for (;sit!=mails.end();++sit) { | 39 | for (;sit!=mails.end();++sit) { |
39 | if ( (*sit)==defmail) | 40 | if ( (*sit)==defmail) |
40 | continue; | 41 | continue; |
41 | fromBox->insertItem((*sit)); | 42 | fromBox->insertItem((*sit)); |
42 | } | 43 | } |
43 | senderNameEdit->setText(c.firstName()+" "+c.lastName()); | 44 | senderNameEdit->setText(c.firstName()+" "+c.lastName()); |
44 | Config cfg( "mail" ); | 45 | Config cfg( "mail" ); |
45 | cfg.setGroup( "Compose" ); | 46 | cfg.setGroup( "Compose" ); |
46 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); | 47 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); |
47 | 48 | ||
48 | attList->addColumn( tr( "Name" ) ); | 49 | attList->addColumn( tr( "Name" ) ); |
49 | attList->addColumn( tr( "Size" ) ); | 50 | attList->addColumn( tr( "Size" ) ); |
50 | 51 | ||
51 | QList<Account> accounts = settings->getAccounts(); | 52 | QList<Account> accounts = settings->getAccounts(); |
52 | 53 | ||
53 | Account *it; | 54 | Account *it; |
54 | for ( it = accounts.first(); it; it = accounts.next() ) { | 55 | for ( it = accounts.first(); it; it = accounts.next() ) { |
55 | if ( it->getType()==MAILLIB::A_SMTP ) { | 56 | if ( it->getType()==MAILLIB::A_SMTP ) { |
56 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); | 57 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); |
57 | smtpAccountBox->insertItem( smtp->getAccountName() ); | 58 | smtpAccountBox->insertItem( smtp->getAccountName() ); |
58 | smtpAccounts.append( smtp ); | 59 | smtpAccounts.append( smtp ); |
59 | } | 60 | } |
60 | } | 61 | } |
61 | 62 | ||
62 | if ( smtpAccounts.count() > 0 ) { | 63 | if ( smtpAccounts.count() > 0 ) { |
63 | fillValues( smtpAccountBox->currentItem() ); | 64 | fillValues( smtpAccountBox->currentItem() ); |
64 | } else { | 65 | } else { |
65 | QMessageBox::information( this, tr( "Problem" ), | 66 | QMessageBox::information( this, tr( "Problem" ), |
66 | tr( "<p>Please create an SMTP account first.</p>" ), | 67 | tr( "<p>Please create an SMTP account first.</p>" ), |
67 | tr( "Ok" ) ); | 68 | tr( "Ok" ) ); |
68 | return; | 69 | return; |
69 | } | 70 | } |
70 | 71 | ||
71 | connect( smtpAccountBox, SIGNAL( activated(int) ), SLOT( fillValues(int) ) ); | 72 | connect( smtpAccountBox, SIGNAL( activated(int) ), SLOT( fillValues(int) ) ); |
72 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); | 73 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); |
73 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); | 74 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); |
74 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); | 75 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); |
75 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); | 76 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); |
76 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); | 77 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); |
77 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); | 78 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); |
78 | } | 79 | } |
79 | 80 | ||
80 | void ComposeMail::pickAddress( QLineEdit *line ) | 81 | void ComposeMail::pickAddress( QLineEdit *line ) |
81 | { | 82 | { |
82 | QString names = AddressPicker::getNames(); | 83 | QString names = AddressPicker::getNames(); |
83 | if ( line->text().isEmpty() ) { | 84 | if ( line->text().isEmpty() ) { |
84 | line->setText( names ); | 85 | line->setText( names ); |
85 | } else if ( !names.isEmpty() ) { | 86 | } else if ( !names.isEmpty() ) { |
86 | line->setText( line->text() + ", " + names ); | 87 | line->setText( line->text() + ", " + names ); |
87 | } | 88 | } |
88 | } | 89 | } |
89 | 90 | ||
90 | 91 | ||
91 | void ComposeMail::setTo( const QString & to ) | 92 | void ComposeMail::setTo( const QString & to ) |
92 | { | 93 | { |
93 | toLine->setText( to ); | 94 | toLine->setText( to ); |
94 | } | 95 | } |
95 | 96 | ||
96 | void ComposeMail::setSubject( const QString & subject ) | 97 | void ComposeMail::setSubject( const QString & subject ) |
97 | { | 98 | { |
98 | subjectLine->setText( subject ); | 99 | subjectLine->setText( subject ); |
99 | } | 100 | } |
100 | 101 | ||
101 | void ComposeMail::setInReplyTo( const QString & messageId ) | 102 | void ComposeMail::setInReplyTo( const QString & messageId ) |
102 | { | 103 | { |
103 | m_replyid = messageId; | 104 | m_replyid = messageId; |
104 | } | 105 | } |
105 | 106 | ||
106 | void ComposeMail::setMessage( const QString & text ) | 107 | void ComposeMail::setMessage( const QString & text ) |
107 | { | 108 | { |
108 | message->setText( text ); | 109 | message->setText( text ); |
109 | } | 110 | } |
110 | 111 | ||
111 | 112 | ||
112 | void ComposeMail::pickAddressTo() | 113 | void ComposeMail::pickAddressTo() |
113 | { | 114 | { |
114 | pickAddress( toLine ); | 115 | pickAddress( toLine ); |
115 | } | 116 | } |
116 | 117 | ||
117 | void ComposeMail::pickAddressCC() | 118 | void ComposeMail::pickAddressCC() |
118 | { | 119 | { |
119 | pickAddress( ccLine ); | 120 | pickAddress( ccLine ); |
120 | } | 121 | } |
121 | 122 | ||
122 | void ComposeMail::pickAddressBCC() | 123 | void ComposeMail::pickAddressBCC() |
123 | { | 124 | { |
124 | pickAddress( bccLine ); | 125 | pickAddress( bccLine ); |
125 | } | 126 | } |
126 | 127 | ||
127 | void ComposeMail::pickAddressReply() | 128 | void ComposeMail::pickAddressReply() |
128 | { | 129 | { |
129 | pickAddress( replyLine ); | 130 | pickAddress( replyLine ); |
130 | } | 131 | } |
131 | 132 | ||
132 | void ComposeMail::fillValues( int ) | 133 | void ComposeMail::fillValues( int ) |
133 | { | 134 | { |
134 | #if 0 | 135 | #if 0 |
135 | SMTPaccount *smtp = smtpAccounts.at( current ); | 136 | SMTPaccount *smtp = smtpAccounts.at( current ); |
136 | ccLine->clear(); | 137 | ccLine->clear(); |
137 | if ( smtp->getUseCC() ) { | 138 | if ( smtp->getUseCC() ) { |
138 | ccLine->setText( smtp->getCC() ); | 139 | ccLine->setText( smtp->getCC() ); |
139 | } | 140 | } |
140 | bccLine->clear(); | 141 | bccLine->clear(); |
141 | if ( smtp->getUseBCC() ) { | 142 | if ( smtp->getUseBCC() ) { |
142 | bccLine->setText( smtp->getBCC() ); | 143 | bccLine->setText( smtp->getBCC() ); |
143 | } | 144 | } |
144 | replyLine->clear(); | 145 | replyLine->clear(); |
145 | if ( smtp->getUseReply() ) { | 146 | if ( smtp->getUseReply() ) { |
146 | replyLine->setText( smtp->getReply() ); | 147 | replyLine->setText( smtp->getReply() ); |
147 | } | 148 | } |
148 | sigMultiLine->setText( smtp->getSignature() ); | 149 | sigMultiLine->setText( smtp->getSignature() ); |
149 | #endif | 150 | #endif |
150 | } | 151 | } |
151 | 152 | ||
152 | void ComposeMail::slotAdjustColumns() | 153 | void ComposeMail::slotAdjustColumns() |
153 | { | 154 | { |
154 | int currPage = tabWidget->currentPageIndex(); | 155 | int currPage = tabWidget->currentPageIndex(); |
155 | 156 | ||
156 | tabWidget->showPage( attachTab ); | 157 | tabWidget->showPage( attachTab ); |
157 | attList->setColumnWidth( 0, attList->visibleWidth() - 80 ); | 158 | attList->setColumnWidth( 0, attList->visibleWidth() - 80 ); |
158 | attList->setColumnWidth( 1, 80 ); | 159 | attList->setColumnWidth( 1, 80 ); |
159 | 160 | ||
160 | tabWidget->setCurrentPage( currPage ); | 161 | tabWidget->setCurrentPage( currPage ); |
161 | } | 162 | } |
162 | 163 | ||
163 | void ComposeMail::addAttachment() | 164 | void ComposeMail::addAttachment() |
164 | { | 165 | { |
165 | DocLnk lnk = OFileDialog::getOpenFileName( 1, "/" ); | 166 | DocLnk lnk = OFileDialog::getOpenFileName( 1, "/" ); |
166 | if ( !lnk.name().isEmpty() ) { | 167 | if ( !lnk.name().isEmpty() ) { |
167 | Attachment *att = new Attachment( lnk ); | 168 | Attachment *att = new Attachment( lnk ); |
168 | (void) new AttachViewItem( attList, att ); | 169 | (void) new AttachViewItem( attList, att ); |
169 | } | 170 | } |
170 | } | 171 | } |
171 | 172 | ||
172 | void ComposeMail::removeAttachment() | 173 | void ComposeMail::removeAttachment() |
173 | { | 174 | { |
174 | if ( !attList->currentItem() ) { | 175 | if ( !attList->currentItem() ) { |
175 | QMessageBox::information( this, tr( "Error" ), | 176 | QMessageBox::information( this, tr( "Error" ), |
176 | tr( "<p>Please select a File.</p>" ), | 177 | tr( "<p>Please select a File.</p>" ), |
177 | tr( "Ok" ) ); | 178 | tr( "Ok" ) ); |
178 | } else { | 179 | } else { |
179 | attList->takeItem( attList->currentItem() ); | 180 | attList->takeItem( attList->currentItem() ); |
180 | } | 181 | } |
181 | } | 182 | } |
182 | 183 | ||
183 | void ComposeMail::accept() | 184 | void ComposeMail::accept() |
184 | { | 185 | { |
185 | if ( checkBoxLater->isChecked() ) { | 186 | if ( checkBoxLater->isChecked() ) { |
186 | odebug << "Send later" << oendl; | 187 | odebug << "Send later" << oendl; |
187 | } | 188 | } |
188 | 189 | ||
189 | #if 0 | 190 | #if 0 |
190 | qDebug( "Sending Mail with " + | 191 | qDebug( "Sending Mail with " + |
191 | smtpAccounts.at( smtpAccountBox->currentItem() )->getAccountName() ); | 192 | smtpAccounts.at( smtpAccountBox->currentItem() )->getAccountName() ); |
192 | #endif | 193 | #endif |
193 | Opie::Core::OSmartPointer<Mail> mail=new Mail; | 194 | Opie::Core::OSmartPointer<Mail> mail=new Mail; |
194 | 195 | ||
195 | SMTPaccount *smtp = smtpAccounts.at( smtpAccountBox->currentItem() ); | 196 | SMTPaccount *smtp = smtpAccounts.at( smtpAccountBox->currentItem() ); |
196 | mail->setMail(fromBox->currentText()); | 197 | mail->setMail(fromBox->currentText()); |
197 | 198 | ||
198 | if ( !toLine->text().isEmpty() ) { | 199 | if ( !toLine->text().isEmpty() ) { |
199 | mail->setTo( toLine->text() ); | 200 | mail->setTo( toLine->text() ); |
200 | } else { | 201 | } else { |
201 | QMessageBox::warning(0,tr("Sending mail"), | 202 | QMessageBox::warning(0,tr("Sending mail"), |
202 | tr("No Receiver spezified" ) ); | 203 | tr("No Receiver spezified" ) ); |
203 | return; | 204 | return; |
204 | } | 205 | } |
205 | mail->setName(senderNameEdit->text()); | 206 | mail->setName(senderNameEdit->text()); |
206 | mail->setCC( ccLine->text() ); | 207 | mail->setCC( ccLine->text() ); |
207 | mail->setBCC( bccLine->text() ); | 208 | mail->setBCC( bccLine->text() ); |
208 | mail->setReply( replyLine->text() ); | 209 | mail->setReply( replyLine->text() ); |
209 | mail->setSubject( subjectLine->text() ); | 210 | mail->setSubject( subjectLine->text() ); |
210 | if (!m_replyid.isEmpty()) { | 211 | if (!m_replyid.isEmpty()) { |
211 | QStringList ids; | 212 | QStringList ids; |
212 | ids.append(m_replyid); | 213 | ids.append(m_replyid); |
213 | mail->setInreply(ids); | 214 | mail->setInreply(ids); |
214 | } | 215 | } |
215 | QString txt = message->text(); | 216 | QString txt = message->text(); |
216 | if ( !sigMultiLine->text().isEmpty() ) { | 217 | if ( !sigMultiLine->text().isEmpty() ) { |
217 | txt.append( "\n--\n" ); | 218 | txt.append( "\n--\n" ); |
218 | txt.append( sigMultiLine->text() ); | 219 | txt.append( sigMultiLine->text() ); |
219 | } | 220 | } |
220 | mail->setMessage( txt ); | 221 | mail->setMessage( txt ); |
221 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); | 222 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); |
222 | while ( it != NULL ) { | 223 | while ( it != NULL ) { |
223 | mail->addAttachment( it->getAttachment() ); | 224 | mail->addAttachment( it->getAttachment() ); |
224 | it = (AttachViewItem *) it->nextSibling(); | 225 | it = (AttachViewItem *) it->nextSibling(); |
225 | } | 226 | } |
226 | 227 | ||
227 | SMTPwrapper wrapper( smtp ); | 228 | SMTPwrapper wrapper( smtp ); |
228 | wrapper.sendMail( mail,checkBoxLater->isChecked() ); | 229 | wrapper.sendMail( mail,checkBoxLater->isChecked() ); |
229 | 230 | ||
230 | QDialog::accept(); | 231 | QDialog::accept(); |
231 | } | 232 | } |
232 | 233 | ||
233 | void ComposeMail::reject() | 234 | void ComposeMail::reject() |
234 | { | 235 | { |
235 | int yesno = QMessageBox::warning(0,tr("Store message"), | 236 | int yesno = QMessageBox::warning(0,tr("Store message"), |
236 | tr("Store message into drafts?"), | 237 | tr("Store message into drafts?"), |
237 | tr("Yes"), | 238 | tr("Yes"), |
238 | tr("No"),QString::null,0,1); | 239 | tr("No"),QString::null,0,1); |
239 | 240 | ||
240 | if (yesno == 0) { | 241 | if (yesno == 0) { |
241 | Opie::Core::OSmartPointer<Mail> mail=new Mail(); | 242 | Opie::Core::OSmartPointer<Mail> mail=new Mail(); |
242 | mail->setMail(fromBox->currentText()); | 243 | mail->setMail(fromBox->currentText()); |
243 | mail->setTo( toLine->text() ); | 244 | mail->setTo( toLine->text() ); |
244 | mail->setName(senderNameEdit->text()); | 245 | mail->setName(senderNameEdit->text()); |
245 | mail->setCC( ccLine->text() ); | 246 | mail->setCC( ccLine->text() ); |
246 | mail->setBCC( bccLine->text() ); | 247 | mail->setBCC( bccLine->text() ); |
247 | mail->setReply( replyLine->text() ); | 248 | mail->setReply( replyLine->text() ); |
248 | mail->setSubject( subjectLine->text() ); | 249 | mail->setSubject( subjectLine->text() ); |
249 | if (!m_replyid.isEmpty()) { | 250 | if (!m_replyid.isEmpty()) { |
250 | QStringList ids; | 251 | QStringList ids; |
251 | ids.append(m_replyid); | 252 | ids.append(m_replyid); |
252 | mail->setInreply(ids); | 253 | mail->setInreply(ids); |
253 | } | 254 | } |
254 | QString txt = message->text(); | 255 | QString txt = message->text(); |
255 | if ( !sigMultiLine->text().isEmpty() ) { | 256 | if ( !sigMultiLine->text().isEmpty() ) { |
256 | txt.append( "\n--\n" ); | 257 | txt.append( "\n--\n" ); |
257 | txt.append( sigMultiLine->text() ); | 258 | txt.append( sigMultiLine->text() ); |
258 | } | 259 | } |
259 | odebug << txt << oendl; | 260 | odebug << txt << oendl; |
260 | mail->setMessage( txt ); | 261 | mail->setMessage( txt ); |
261 | 262 | ||
262 | /* only use the default drafts folder name! */ | 263 | /* only use the default drafts folder name! */ |
263 | Storemail wrapper(AbstractMail::draftFolder()); | 264 | Storemail wrapper(AbstractMail::draftFolder()); |
264 | wrapper.storeMail(mail); | 265 | wrapper.storeMail(mail); |
265 | 266 | ||
266 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); | 267 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); |
267 | /* attachments we will ignore! */ | 268 | /* attachments we will ignore! */ |
268 | if ( it != NULL ) { | 269 | if ( it != NULL ) { |
269 | QMessageBox::warning(0,tr("Store message"), | 270 | QMessageBox::warning(0,tr("Store message"), |
270 | tr("<center>Attachments will not be stored in \"Draft\" folder</center>")); | 271 | tr("<center>Attachments will not be stored in \"Draft\" folder</center>")); |
271 | } | 272 | } |
272 | } | 273 | } |
273 | QDialog::reject(); | 274 | QDialog::reject(); |
274 | } | 275 | } |
275 | 276 | ||
276 | ComposeMail::~ComposeMail() | 277 | ComposeMail::~ComposeMail() |
277 | { | 278 | { |
278 | } | 279 | } |
279 | 280 | ||
280 | void ComposeMail::reEditMail(const RecMailP¤t) | 281 | void ComposeMail::reEditMail(const RecMailP¤t) |
281 | { | 282 | { |
282 | RecMailP data = current; | 283 | RecMailP data = current; |
283 | message->setText(data->Wrapper()->fetchBody(current)->Bodytext()); | 284 | message->setText(data->Wrapper()->fetchBody(current)->Bodytext()); |
284 | subjectLine->setText( data->getSubject()); | 285 | subjectLine->setText( data->getSubject()); |
285 | toLine->setText(data->To().join(",")); | 286 | toLine->setText(data->To().join(",")); |
286 | ccLine->setText(data->CC().join(",")); | 287 | ccLine->setText(data->CC().join(",")); |
287 | bccLine->setText(data->Bcc().join(",")); | 288 | bccLine->setText(data->Bcc().join(",")); |
288 | replyLine->setText(data->Replyto()); | 289 | replyLine->setText(data->Replyto()); |
289 | } | 290 | } |
290 | 291 | ||
291 | AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) | 292 | AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) |
292 | : QListViewItem( parent ) | 293 | : QListViewItem( parent ) |
293 | { | 294 | { |
294 | attachment = att; | 295 | attachment = att; |
295 | odebug << att->getMimeType() << oendl; | 296 | odebug << att->getMimeType() << oendl; |
296 | setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ? | 297 | setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ? |
297 | Resource::loadPixmap( "UnknownDocument-14" ) : | 298 | Resource::loadPixmap( "UnknownDocument-14" ) : |
298 | attachment->getDocLnk().pixmap() ); | 299 | attachment->getDocLnk().pixmap() ); |
299 | setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); | 300 | setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); |
300 | setText( 1, QString::number( att->getSize() ) ); | 301 | setText( 1, QString::number( att->getSize() ) ); |
301 | } | 302 | } |
302 | 303 | ||
diff --git a/noncore/net/mail/editaccounts.cpp b/noncore/net/mail/editaccounts.cpp index de064ca..b0ce57d 100644 --- a/noncore/net/mail/editaccounts.cpp +++ b/noncore/net/mail/editaccounts.cpp | |||
@@ -1,594 +1,597 @@ | |||
1 | 1 | ||
2 | #include "defines.h" | 2 | #include "defines.h" |
3 | #include "editaccounts.h" | 3 | #include "editaccounts.h" |
4 | 4 | ||
5 | /* OPIE */ | 5 | /* OPIE */ |
6 | #include <opie2/odebug.h> | ||
6 | #include <qpe/qpeapplication.h> | 7 | #include <qpe/qpeapplication.h> |
7 | 8 | ||
8 | /* QT */ | 9 | /* QT */ |
9 | #include <qt.h> | 10 | #include <qt.h> |
10 | #include <qstringlist.h> | 11 | #include <qstringlist.h> |
11 | 12 | ||
12 | #include <libmailwrapper/nntpwrapper.h> | 13 | #include <libmailwrapper/nntpwrapper.h> |
13 | 14 | ||
15 | using namespace Opie::Core; | ||
16 | |||
14 | AccountListItem::AccountListItem( QListView *parent, Account *a) | 17 | AccountListItem::AccountListItem( QListView *parent, Account *a) |
15 | : QListViewItem( parent ) | 18 | : QListViewItem( parent ) |
16 | { | 19 | { |
17 | account = a; | 20 | account = a; |
18 | setText( 0, account->getAccountName() ); | 21 | setText( 0, account->getAccountName() ); |
19 | QString ttext = ""; | 22 | QString ttext = ""; |
20 | switch (account->getType()) { | 23 | switch (account->getType()) { |
21 | case MAILLIB::A_NNTP: | 24 | case MAILLIB::A_NNTP: |
22 | ttext="NNTP"; | 25 | ttext="NNTP"; |
23 | break; | 26 | break; |
24 | case MAILLIB::A_POP3: | 27 | case MAILLIB::A_POP3: |
25 | ttext = "POP3"; | 28 | ttext = "POP3"; |
26 | break; | 29 | break; |
27 | case MAILLIB::A_IMAP: | 30 | case MAILLIB::A_IMAP: |
28 | ttext = "IMAP"; | 31 | ttext = "IMAP"; |
29 | break; | 32 | break; |
30 | case MAILLIB::A_SMTP: | 33 | case MAILLIB::A_SMTP: |
31 | ttext = "SMTP"; | 34 | ttext = "SMTP"; |
32 | break; | 35 | break; |
33 | default: | 36 | default: |
34 | ttext = "UNKNOWN"; | 37 | ttext = "UNKNOWN"; |
35 | break; | 38 | break; |
36 | } | 39 | } |
37 | setText( 1, ttext); | 40 | setText( 1, ttext); |
38 | } | 41 | } |
39 | 42 | ||
40 | EditAccounts::EditAccounts( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) | 43 | EditAccounts::EditAccounts( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) |
41 | : EditAccountsUI( parent, name, modal, flags ) | 44 | : EditAccountsUI( parent, name, modal, flags ) |
42 | { | 45 | { |
43 | odebug << "New Account Configuration Widget" << oendl; | 46 | odebug << "New Account Configuration Widget" << oendl; |
44 | settings = s; | 47 | settings = s; |
45 | 48 | ||
46 | mailList->addColumn( tr( "Account" ) ); | 49 | mailList->addColumn( tr( "Account" ) ); |
47 | mailList->addColumn( tr( "Type" ) ); | 50 | mailList->addColumn( tr( "Type" ) ); |
48 | 51 | ||
49 | newsList->addColumn( tr( "Account" ) ); | 52 | newsList->addColumn( tr( "Account" ) ); |
50 | 53 | ||
51 | connect( newMail, SIGNAL( clicked() ), SLOT( slotNewMail() ) ); | 54 | connect( newMail, SIGNAL( clicked() ), SLOT( slotNewMail() ) ); |
52 | connect( editMail, SIGNAL( clicked() ), SLOT( slotEditMail() ) ); | 55 | connect( editMail, SIGNAL( clicked() ), SLOT( slotEditMail() ) ); |
53 | connect( deleteMail, SIGNAL( clicked() ), SLOT( slotDeleteMail() ) ); | 56 | connect( deleteMail, SIGNAL( clicked() ), SLOT( slotDeleteMail() ) ); |
54 | connect( newNews, SIGNAL( clicked() ), SLOT( slotNewNews() ) ); | 57 | connect( newNews, SIGNAL( clicked() ), SLOT( slotNewNews() ) ); |
55 | connect( editNews, SIGNAL( clicked() ), SLOT( slotEditNews() ) ); | 58 | connect( editNews, SIGNAL( clicked() ), SLOT( slotEditNews() ) ); |
56 | connect( deleteNews, SIGNAL( clicked() ), SLOT( slotDeleteNews() ) ); | 59 | connect( deleteNews, SIGNAL( clicked() ), SLOT( slotDeleteNews() ) ); |
57 | 60 | ||
58 | slotFillLists(); | 61 | slotFillLists(); |
59 | } | 62 | } |
60 | 63 | ||
61 | void EditAccounts::slotFillLists() | 64 | void EditAccounts::slotFillLists() |
62 | { | 65 | { |
63 | mailList->clear(); | 66 | mailList->clear(); |
64 | newsList->clear(); | 67 | newsList->clear(); |
65 | 68 | ||
66 | QList<Account> accounts = settings->getAccounts(); | 69 | QList<Account> accounts = settings->getAccounts(); |
67 | Account *it; | 70 | Account *it; |
68 | for ( it = accounts.first(); it; it = accounts.next() ) | 71 | for ( it = accounts.first(); it; it = accounts.next() ) |
69 | { | 72 | { |
70 | if ( it->getType()==MAILLIB::A_NNTP ) | 73 | if ( it->getType()==MAILLIB::A_NNTP ) |
71 | { | 74 | { |
72 | (void) new AccountListItem( newsList, it ); | 75 | (void) new AccountListItem( newsList, it ); |
73 | } | 76 | } |
74 | else | 77 | else |
75 | { | 78 | { |
76 | (void) new AccountListItem( mailList, it ); | 79 | (void) new AccountListItem( mailList, it ); |
77 | } | 80 | } |
78 | } | 81 | } |
79 | } | 82 | } |
80 | 83 | ||
81 | void EditAccounts::slotNewMail() | 84 | void EditAccounts::slotNewMail() |
82 | { | 85 | { |
83 | odebug << "New Mail Account" << oendl; | 86 | odebug << "New Mail Account" << oendl; |
84 | QString *selection = new QString(); | 87 | QString *selection = new QString(); |
85 | SelectMailType selType( selection, this, 0, true ); | 88 | SelectMailType selType( selection, this, 0, true ); |
86 | selType.show(); | 89 | selType.show(); |
87 | if ( QDialog::Accepted == selType.exec() ) | 90 | if ( QDialog::Accepted == selType.exec() ) |
88 | { | 91 | { |
89 | slotNewAccount( *selection ); | 92 | slotNewAccount( *selection ); |
90 | } | 93 | } |
91 | } | 94 | } |
92 | 95 | ||
93 | void EditAccounts::slotNewAccount( const QString &type ) | 96 | void EditAccounts::slotNewAccount( const QString &type ) |
94 | { | 97 | { |
95 | if ( type.compare( "IMAP" ) == 0 ) | 98 | if ( type.compare( "IMAP" ) == 0 ) |
96 | { | 99 | { |
97 | odebug << "-> config IMAP" << oendl; | 100 | odebug << "-> config IMAP" << oendl; |
98 | IMAPaccount *account = new IMAPaccount(); | 101 | IMAPaccount *account = new IMAPaccount(); |
99 | IMAPconfig imap( account, this, 0, true ); | 102 | IMAPconfig imap( account, this, 0, true ); |
100 | if ( QDialog::Accepted == QPEApplication::execDialog( &imap ) ) | 103 | if ( QDialog::Accepted == QPEApplication::execDialog( &imap ) ) |
101 | { | 104 | { |
102 | settings->addAccount( account ); | 105 | settings->addAccount( account ); |
103 | account->save(); | 106 | account->save(); |
104 | slotFillLists(); | 107 | slotFillLists(); |
105 | } | 108 | } |
106 | else | 109 | else |
107 | { | 110 | { |
108 | account->remove(); | 111 | account->remove(); |
109 | } | 112 | } |
110 | } | 113 | } |
111 | else if ( type.compare( "POP3" ) == 0 ) | 114 | else if ( type.compare( "POP3" ) == 0 ) |
112 | { | 115 | { |
113 | odebug << "-> config POP3" << oendl; | 116 | odebug << "-> config POP3" << oendl; |
114 | POP3account *account = new POP3account(); | 117 | POP3account *account = new POP3account(); |
115 | POP3config pop3( account, this, 0, true, WStyle_ContextHelp ); | 118 | POP3config pop3( account, this, 0, true, WStyle_ContextHelp ); |
116 | if ( QDialog::Accepted == QPEApplication::execDialog( &pop3 ) ) | 119 | if ( QDialog::Accepted == QPEApplication::execDialog( &pop3 ) ) |
117 | { | 120 | { |
118 | settings->addAccount( account ); | 121 | settings->addAccount( account ); |
119 | account->save(); | 122 | account->save(); |
120 | slotFillLists(); | 123 | slotFillLists(); |
121 | } | 124 | } |
122 | else | 125 | else |
123 | { | 126 | { |
124 | account->remove(); | 127 | account->remove(); |
125 | } | 128 | } |
126 | } | 129 | } |
127 | else if ( type.compare( "SMTP" ) == 0 ) | 130 | else if ( type.compare( "SMTP" ) == 0 ) |
128 | { | 131 | { |
129 | odebug << "-> config SMTP" << oendl; | 132 | odebug << "-> config SMTP" << oendl; |
130 | SMTPaccount *account = new SMTPaccount(); | 133 | SMTPaccount *account = new SMTPaccount(); |
131 | SMTPconfig smtp( account, this, 0, true, WStyle_ContextHelp ); | 134 | SMTPconfig smtp( account, this, 0, true, WStyle_ContextHelp ); |
132 | if ( QDialog::Accepted == QPEApplication::execDialog( &smtp ) ) | 135 | if ( QDialog::Accepted == QPEApplication::execDialog( &smtp ) ) |
133 | { | 136 | { |
134 | settings->addAccount( account ); | 137 | settings->addAccount( account ); |
135 | account->save(); | 138 | account->save(); |
136 | slotFillLists(); | 139 | slotFillLists(); |
137 | 140 | ||
138 | } | 141 | } |
139 | else | 142 | else |
140 | { | 143 | { |
141 | account->remove(); | 144 | account->remove(); |
142 | } | 145 | } |
143 | } | 146 | } |
144 | else if ( type.compare( "NNTP" ) == 0 ) | 147 | else if ( type.compare( "NNTP" ) == 0 ) |
145 | { | 148 | { |
146 | odebug << "-> config NNTP" << oendl; | 149 | odebug << "-> config NNTP" << oendl; |
147 | NNTPaccount *account = new NNTPaccount(); | 150 | NNTPaccount *account = new NNTPaccount(); |
148 | NNTPconfig nntp( account, this, 0, true, WStyle_ContextHelp ); | 151 | NNTPconfig nntp( account, this, 0, true, WStyle_ContextHelp ); |
149 | if ( QDialog::Accepted == QPEApplication::execDialog( &nntp ) ) | 152 | if ( QDialog::Accepted == QPEApplication::execDialog( &nntp ) ) |
150 | { | 153 | { |
151 | settings->addAccount( account ); | 154 | settings->addAccount( account ); |
152 | account->save(); | 155 | account->save(); |
153 | slotFillLists(); | 156 | slotFillLists(); |
154 | } | 157 | } |
155 | else | 158 | else |
156 | { | 159 | { |
157 | account->remove(); | 160 | account->remove(); |
158 | } | 161 | } |
159 | } | 162 | } |
160 | } | 163 | } |
161 | 164 | ||
162 | void EditAccounts::slotEditAccount( Account *account ) | 165 | void EditAccounts::slotEditAccount( Account *account ) |
163 | { | 166 | { |
164 | if ( account->getType() == MAILLIB::A_IMAP ) | 167 | if ( account->getType() == MAILLIB::A_IMAP ) |
165 | { | 168 | { |
166 | IMAPaccount *imapAcc = static_cast<IMAPaccount *>(account); | 169 | IMAPaccount *imapAcc = static_cast<IMAPaccount *>(account); |
167 | IMAPconfig imap( imapAcc, this, 0, true, WStyle_ContextHelp ); | 170 | IMAPconfig imap( imapAcc, this, 0, true, WStyle_ContextHelp ); |
168 | if ( QDialog::Accepted == QPEApplication::execDialog( &imap ) ) | 171 | if ( QDialog::Accepted == QPEApplication::execDialog( &imap ) ) |
169 | { | 172 | { |
170 | slotFillLists(); | 173 | slotFillLists(); |
171 | } | 174 | } |
172 | } | 175 | } |
173 | else if ( account->getType()==MAILLIB::A_POP3 ) | 176 | else if ( account->getType()==MAILLIB::A_POP3 ) |
174 | { | 177 | { |
175 | POP3account *pop3Acc = static_cast<POP3account *>(account); | 178 | POP3account *pop3Acc = static_cast<POP3account *>(account); |
176 | POP3config pop3( pop3Acc, this, 0, true, WStyle_ContextHelp ); | 179 | POP3config pop3( pop3Acc, this, 0, true, WStyle_ContextHelp ); |
177 | if ( QDialog::Accepted == QPEApplication::execDialog( &pop3 ) ) | 180 | if ( QDialog::Accepted == QPEApplication::execDialog( &pop3 ) ) |
178 | { | 181 | { |
179 | slotFillLists(); | 182 | slotFillLists(); |
180 | } | 183 | } |
181 | } | 184 | } |
182 | else if ( account->getType()==MAILLIB::A_SMTP ) | 185 | else if ( account->getType()==MAILLIB::A_SMTP ) |
183 | { | 186 | { |
184 | SMTPaccount *smtpAcc = static_cast<SMTPaccount *>(account); | 187 | SMTPaccount *smtpAcc = static_cast<SMTPaccount *>(account); |
185 | SMTPconfig smtp( smtpAcc, this, 0, true, WStyle_ContextHelp ); | 188 | SMTPconfig smtp( smtpAcc, this, 0, true, WStyle_ContextHelp ); |
186 | if ( QDialog::Accepted == QPEApplication::execDialog( &smtp ) ) | 189 | if ( QDialog::Accepted == QPEApplication::execDialog( &smtp ) ) |
187 | { | 190 | { |
188 | slotFillLists(); | 191 | slotFillLists(); |
189 | } | 192 | } |
190 | } | 193 | } |
191 | else if ( account->getType()==MAILLIB::A_NNTP) | 194 | else if ( account->getType()==MAILLIB::A_NNTP) |
192 | { | 195 | { |
193 | NNTPaccount *nntpAcc = static_cast<NNTPaccount *>(account); | 196 | NNTPaccount *nntpAcc = static_cast<NNTPaccount *>(account); |
194 | NNTPconfig nntp( nntpAcc, this, 0, true, WStyle_ContextHelp ); | 197 | NNTPconfig nntp( nntpAcc, this, 0, true, WStyle_ContextHelp ); |
195 | if ( QDialog::Accepted == QPEApplication::execDialog( &nntp ) ) | 198 | if ( QDialog::Accepted == QPEApplication::execDialog( &nntp ) ) |
196 | { | 199 | { |
197 | slotFillLists(); | 200 | slotFillLists(); |
198 | } | 201 | } |
199 | } | 202 | } |
200 | } | 203 | } |
201 | 204 | ||
202 | void EditAccounts::slotDeleteAccount( Account *account ) | 205 | void EditAccounts::slotDeleteAccount( Account *account ) |
203 | { | 206 | { |
204 | if ( QMessageBox::information( this, tr( "Question" ), | 207 | if ( QMessageBox::information( this, tr( "Question" ), |
205 | tr( "<p>Do you really want to delete the selected Account?</p>" ), | 208 | tr( "<p>Do you really want to delete the selected Account?</p>" ), |
206 | tr( "Yes" ), tr( "No" ) ) == 0 ) | 209 | tr( "Yes" ), tr( "No" ) ) == 0 ) |
207 | { | 210 | { |
208 | settings->delAccount( account ); | 211 | settings->delAccount( account ); |
209 | slotFillLists(); | 212 | slotFillLists(); |
210 | } | 213 | } |
211 | } | 214 | } |
212 | 215 | ||
213 | void EditAccounts::slotEditMail() | 216 | void EditAccounts::slotEditMail() |
214 | { | 217 | { |
215 | odebug << "Edit Mail Account" << oendl; | 218 | odebug << "Edit Mail Account" << oendl; |
216 | if ( !mailList->currentItem() ) | 219 | if ( !mailList->currentItem() ) |
217 | { | 220 | { |
218 | QMessageBox::information( this, tr( "Error" ), | 221 | QMessageBox::information( this, tr( "Error" ), |
219 | tr( "<p>Please select an account.</p>" ), | 222 | tr( "<p>Please select an account.</p>" ), |
220 | tr( "Ok" ) ); | 223 | tr( "Ok" ) ); |
221 | return; | 224 | return; |
222 | } | 225 | } |
223 | 226 | ||
224 | Account *a = ((AccountListItem *) mailList->currentItem())->getAccount(); | 227 | Account *a = ((AccountListItem *) mailList->currentItem())->getAccount(); |
225 | slotEditAccount( a ); | 228 | slotEditAccount( a ); |
226 | } | 229 | } |
227 | 230 | ||
228 | void EditAccounts::slotDeleteMail() | 231 | void EditAccounts::slotDeleteMail() |
229 | { | 232 | { |
230 | if ( !mailList->currentItem() ) | 233 | if ( !mailList->currentItem() ) |
231 | { | 234 | { |
232 | QMessageBox::information( this, tr( "Error" ), | 235 | QMessageBox::information( this, tr( "Error" ), |
233 | tr( "<p>Please select an account.</p>" ), | 236 | tr( "<p>Please select an account.</p>" ), |
234 | tr( "Ok" ) ); | 237 | tr( "Ok" ) ); |
235 | return; | 238 | return; |
236 | } | 239 | } |
237 | 240 | ||
238 | Account *a = ((AccountListItem *) mailList->currentItem())->getAccount(); | 241 | Account *a = ((AccountListItem *) mailList->currentItem())->getAccount(); |
239 | slotDeleteAccount( a ); | 242 | slotDeleteAccount( a ); |
240 | } | 243 | } |
241 | 244 | ||
242 | void EditAccounts::slotNewNews() | 245 | void EditAccounts::slotNewNews() |
243 | { | 246 | { |
244 | odebug << "New News Account" << oendl; | 247 | odebug << "New News Account" << oendl; |
245 | slotNewAccount( "NNTP" ); | 248 | slotNewAccount( "NNTP" ); |
246 | } | 249 | } |
247 | 250 | ||
248 | void EditAccounts::slotEditNews() | 251 | void EditAccounts::slotEditNews() |
249 | { | 252 | { |
250 | odebug << "Edit News Account" << oendl; | 253 | odebug << "Edit News Account" << oendl; |
251 | if ( !newsList->currentItem() ) | 254 | if ( !newsList->currentItem() ) |
252 | { | 255 | { |
253 | QMessageBox::information( this, tr( "Error" ), | 256 | QMessageBox::information( this, tr( "Error" ), |
254 | tr( "<p>Please select an account.</p>" ), | 257 | tr( "<p>Please select an account.</p>" ), |
255 | tr( "Ok" ) ); | 258 | tr( "Ok" ) ); |
256 | return; | 259 | return; |
257 | } | 260 | } |
258 | 261 | ||
259 | Account *a = ((AccountListItem *) newsList->currentItem())->getAccount(); | 262 | Account *a = ((AccountListItem *) newsList->currentItem())->getAccount(); |
260 | slotEditAccount( a ); | 263 | slotEditAccount( a ); |
261 | } | 264 | } |
262 | 265 | ||
263 | void EditAccounts::slotDeleteNews() | 266 | void EditAccounts::slotDeleteNews() |
264 | { | 267 | { |
265 | odebug << "Delete News Account" << oendl; | 268 | odebug << "Delete News Account" << oendl; |
266 | if ( !newsList->currentItem() ) | 269 | if ( !newsList->currentItem() ) |
267 | { | 270 | { |
268 | QMessageBox::information( this, tr( "Error" ), | 271 | QMessageBox::information( this, tr( "Error" ), |
269 | tr( "<p>Please select an account.</p>" ), | 272 | tr( "<p>Please select an account.</p>" ), |
270 | tr( "Ok" ) ); | 273 | tr( "Ok" ) ); |
271 | return; | 274 | return; |
272 | } | 275 | } |
273 | 276 | ||
274 | Account *a = ((AccountListItem *) newsList->currentItem())->getAccount(); | 277 | Account *a = ((AccountListItem *) newsList->currentItem())->getAccount(); |
275 | slotDeleteAccount( a ); | 278 | slotDeleteAccount( a ); |
276 | } | 279 | } |
277 | 280 | ||
278 | void EditAccounts::slotAdjustColumns() | 281 | void EditAccounts::slotAdjustColumns() |
279 | { | 282 | { |
280 | int currPage = configTab->currentPageIndex(); | 283 | int currPage = configTab->currentPageIndex(); |
281 | 284 | ||
282 | configTab->showPage( mailTab ); | 285 | configTab->showPage( mailTab ); |
283 | mailList->setColumnWidth( 0, mailList->visibleWidth() - 50 ); | 286 | mailList->setColumnWidth( 0, mailList->visibleWidth() - 50 ); |
284 | mailList->setColumnWidth( 1, 50 ); | 287 | mailList->setColumnWidth( 1, 50 ); |
285 | 288 | ||
286 | configTab->showPage( newsTab ); | 289 | configTab->showPage( newsTab ); |
287 | newsList->setColumnWidth( 0, newsList->visibleWidth() ); | 290 | newsList->setColumnWidth( 0, newsList->visibleWidth() ); |
288 | 291 | ||
289 | configTab->setCurrentPage( currPage ); | 292 | configTab->setCurrentPage( currPage ); |
290 | } | 293 | } |
291 | 294 | ||
292 | void EditAccounts::accept() | 295 | void EditAccounts::accept() |
293 | { | 296 | { |
294 | settings->saveAccounts(); | 297 | settings->saveAccounts(); |
295 | 298 | ||
296 | QDialog::accept(); | 299 | QDialog::accept(); |
297 | } | 300 | } |
298 | 301 | ||
299 | /** | 302 | /** |
300 | * SelectMailType | 303 | * SelectMailType |
301 | */ | 304 | */ |
302 | 305 | ||
303 | SelectMailType::SelectMailType( QString *selection, QWidget *parent, const char *name, bool modal, WFlags flags ) | 306 | SelectMailType::SelectMailType( QString *selection, QWidget *parent, const char *name, bool modal, WFlags flags ) |
304 | : SelectMailTypeUI( parent, name, modal, flags ) | 307 | : SelectMailTypeUI( parent, name, modal, flags ) |
305 | { | 308 | { |
306 | selected = selection; | 309 | selected = selection; |
307 | selected->replace( 0, selected->length(), typeBox->currentText() ); | 310 | selected->replace( 0, selected->length(), typeBox->currentText() ); |
308 | connect( typeBox, SIGNAL( activated(const QString&) ), SLOT( slotSelection(const QString&) ) ); | 311 | connect( typeBox, SIGNAL( activated(const QString&) ), SLOT( slotSelection(const QString&) ) ); |
309 | } | 312 | } |
310 | 313 | ||
311 | void SelectMailType::slotSelection( const QString &sel ) | 314 | void SelectMailType::slotSelection( const QString &sel ) |
312 | { | 315 | { |
313 | selected->replace( 0, selected->length(), sel ); | 316 | selected->replace( 0, selected->length(), sel ); |
314 | } | 317 | } |
315 | 318 | ||
316 | /** | 319 | /** |
317 | * IMAPconfig | 320 | * IMAPconfig |
318 | */ | 321 | */ |
319 | 322 | ||
320 | IMAPconfig::IMAPconfig( IMAPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) | 323 | IMAPconfig::IMAPconfig( IMAPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) |
321 | : IMAPconfigUI( parent, name, modal, flags ) | 324 | : IMAPconfigUI( parent, name, modal, flags ) |
322 | { | 325 | { |
323 | data = account; | 326 | data = account; |
324 | 327 | ||
325 | fillValues(); | 328 | fillValues(); |
326 | 329 | ||
327 | connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) ); | 330 | connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) ); |
328 | ComboBox1->insertItem( "Only if available", 0 ); | 331 | ComboBox1->insertItem( "Only if available", 0 ); |
329 | ComboBox1->insertItem( "Always, Negotiated", 1 ); | 332 | ComboBox1->insertItem( "Always, Negotiated", 1 ); |
330 | ComboBox1->insertItem( "Connect on secure port", 2 ); | 333 | ComboBox1->insertItem( "Connect on secure port", 2 ); |
331 | ComboBox1->insertItem( "Run command instead", 3 ); | 334 | ComboBox1->insertItem( "Run command instead", 3 ); |
332 | CommandEdit->hide(); | 335 | CommandEdit->hide(); |
333 | ComboBox1->setCurrentItem( data->ConnectionType() ); | 336 | ComboBox1->setCurrentItem( data->ConnectionType() ); |
334 | } | 337 | } |
335 | 338 | ||
336 | void IMAPconfig::slotConnectionToggle( int index ) | 339 | void IMAPconfig::slotConnectionToggle( int index ) |
337 | { | 340 | { |
338 | if ( index == 2 ) | 341 | if ( index == 2 ) |
339 | { | 342 | { |
340 | portLine->setText( IMAP_SSL_PORT ); | 343 | portLine->setText( IMAP_SSL_PORT ); |
341 | } | 344 | } |
342 | else if ( index == 3 ) | 345 | else if ( index == 3 ) |
343 | { | 346 | { |
344 | portLine->setText( IMAP_PORT ); | 347 | portLine->setText( IMAP_PORT ); |
345 | CommandEdit->show(); | 348 | CommandEdit->show(); |
346 | } | 349 | } |
347 | else | 350 | else |
348 | { | 351 | { |
349 | portLine->setText( IMAP_PORT ); | 352 | portLine->setText( IMAP_PORT ); |
350 | } | 353 | } |
351 | } | 354 | } |
352 | 355 | ||
353 | void IMAPconfig::fillValues() | 356 | void IMAPconfig::fillValues() |
354 | { | 357 | { |
355 | accountLine->setText( data->getAccountName() ); | 358 | accountLine->setText( data->getAccountName() ); |
356 | serverLine->setText( data->getServer() ); | 359 | serverLine->setText( data->getServer() ); |
357 | portLine->setText( data->getPort() ); | 360 | portLine->setText( data->getPort() ); |
358 | ComboBox1->setCurrentItem( data->ConnectionType() ); | 361 | ComboBox1->setCurrentItem( data->ConnectionType() ); |
359 | userLine->setText( data->getUser() ); | 362 | userLine->setText( data->getUser() ); |
360 | passLine->setText( data->getPassword() ); | 363 | passLine->setText( data->getPassword() ); |
361 | prefixLine->setText(data->getPrefix()); | 364 | prefixLine->setText(data->getPrefix()); |
362 | } | 365 | } |
363 | 366 | ||
364 | void IMAPconfig::accept() | 367 | void IMAPconfig::accept() |
365 | { | 368 | { |
366 | data->setAccountName( accountLine->text() ); | 369 | data->setAccountName( accountLine->text() ); |
367 | data->setServer( serverLine->text() ); | 370 | data->setServer( serverLine->text() ); |
368 | data->setPort( portLine->text() ); | 371 | data->setPort( portLine->text() ); |
369 | data->setConnectionType( ComboBox1->currentItem() ); | 372 | data->setConnectionType( ComboBox1->currentItem() ); |
370 | data->setUser( userLine->text() ); | 373 | data->setUser( userLine->text() ); |
371 | data->setPassword( passLine->text() ); | 374 | data->setPassword( passLine->text() ); |
372 | data->setPrefix(prefixLine->text()); | 375 | data->setPrefix(prefixLine->text()); |
373 | 376 | ||
374 | QDialog::accept(); | 377 | QDialog::accept(); |
375 | } | 378 | } |
376 | 379 | ||
377 | /** | 380 | /** |
378 | * POP3config | 381 | * POP3config |
379 | */ | 382 | */ |
380 | 383 | ||
381 | POP3config::POP3config( POP3account *account, QWidget *parent, const char *name, bool modal, WFlags flags ) | 384 | POP3config::POP3config( POP3account *account, QWidget *parent, const char *name, bool modal, WFlags flags ) |
382 | : POP3configUI( parent, name, modal, flags ) | 385 | : POP3configUI( parent, name, modal, flags ) |
383 | { | 386 | { |
384 | data = account; | 387 | data = account; |
385 | fillValues(); | 388 | fillValues(); |
386 | 389 | ||
387 | connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) ); | 390 | connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) ); |
388 | ComboBox1->insertItem( "Only if available", 0 ); | 391 | ComboBox1->insertItem( "Only if available", 0 ); |
389 | ComboBox1->insertItem( "Always, Negotiated", 1 ); | 392 | ComboBox1->insertItem( "Always, Negotiated", 1 ); |
390 | ComboBox1->insertItem( "Connect on secure port", 2 ); | 393 | ComboBox1->insertItem( "Connect on secure port", 2 ); |
391 | ComboBox1->insertItem( "Run command instead", 3 ); | 394 | ComboBox1->insertItem( "Run command instead", 3 ); |
392 | CommandEdit->hide(); | 395 | CommandEdit->hide(); |
393 | ComboBox1->setCurrentItem( data->ConnectionType() ); | 396 | ComboBox1->setCurrentItem( data->ConnectionType() ); |
394 | } | 397 | } |
395 | 398 | ||
396 | void POP3config::slotConnectionToggle( int index ) | 399 | void POP3config::slotConnectionToggle( int index ) |
397 | { | 400 | { |
398 | // 2 is ssl connection | 401 | // 2 is ssl connection |
399 | if ( index == 2 ) | 402 | if ( index == 2 ) |
400 | { | 403 | { |
401 | portLine->setText( POP3_SSL_PORT ); | 404 | portLine->setText( POP3_SSL_PORT ); |
402 | } | 405 | } |
403 | else if ( index == 3 ) | 406 | else if ( index == 3 ) |
404 | { | 407 | { |
405 | portLine->setText( POP3_PORT ); | 408 | portLine->setText( POP3_PORT ); |
406 | CommandEdit->show(); | 409 | CommandEdit->show(); |
407 | } | 410 | } |
408 | else | 411 | else |
409 | { | 412 | { |
410 | portLine->setText( POP3_PORT ); | 413 | portLine->setText( POP3_PORT ); |
411 | } | 414 | } |
412 | } | 415 | } |
413 | 416 | ||
414 | void POP3config::fillValues() | 417 | void POP3config::fillValues() |
415 | { | 418 | { |
416 | accountLine->setText( data->getAccountName() ); | 419 | accountLine->setText( data->getAccountName() ); |
417 | serverLine->setText( data->getServer() ); | 420 | serverLine->setText( data->getServer() ); |
418 | portLine->setText( data->getPort() ); | 421 | portLine->setText( data->getPort() ); |
419 | ComboBox1->setCurrentItem( data->ConnectionType() ); | 422 | ComboBox1->setCurrentItem( data->ConnectionType() ); |
420 | userLine->setText( data->getUser() ); | 423 | userLine->setText( data->getUser() ); |
421 | passLine->setText( data->getPassword() ); | 424 | passLine->setText( data->getPassword() ); |
422 | } | 425 | } |
423 | 426 | ||
424 | void POP3config::accept() | 427 | void POP3config::accept() |
425 | { | 428 | { |
426 | data->setAccountName( accountLine->text() ); | 429 | data->setAccountName( accountLine->text() ); |
427 | data->setServer( serverLine->text() ); | 430 | data->setServer( serverLine->text() ); |
428 | data->setPort( portLine->text() ); | 431 | data->setPort( portLine->text() ); |
429 | data->setConnectionType( ComboBox1->currentItem() ); | 432 | data->setConnectionType( ComboBox1->currentItem() ); |
430 | data->setUser( userLine->text() ); | 433 | data->setUser( userLine->text() ); |
431 | data->setPassword( passLine->text() ); | 434 | data->setPassword( passLine->text() ); |
432 | 435 | ||
433 | QDialog::accept(); | 436 | QDialog::accept(); |
434 | } | 437 | } |
435 | 438 | ||
436 | /** | 439 | /** |
437 | * SMTPconfig | 440 | * SMTPconfig |
438 | */ | 441 | */ |
439 | 442 | ||
440 | SMTPconfig::SMTPconfig( SMTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) | 443 | SMTPconfig::SMTPconfig( SMTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) |
441 | : SMTPconfigUI( parent, name, modal, flags ) | 444 | : SMTPconfigUI( parent, name, modal, flags ) |
442 | { | 445 | { |
443 | data = account; | 446 | data = account; |
444 | 447 | ||
445 | connect( loginBox, SIGNAL( toggled(bool) ), userLine, SLOT( setEnabled(bool) ) ); | 448 | connect( loginBox, SIGNAL( toggled(bool) ), userLine, SLOT( setEnabled(bool) ) ); |
446 | connect( loginBox, SIGNAL( toggled(bool) ), passLine, SLOT( setEnabled(bool) ) ); | 449 | connect( loginBox, SIGNAL( toggled(bool) ), passLine, SLOT( setEnabled(bool) ) ); |
447 | 450 | ||
448 | fillValues(); | 451 | fillValues(); |
449 | 452 | ||
450 | connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) ); | 453 | connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) ); |
451 | ComboBox1->insertItem( "Only if available", 0 ); | 454 | ComboBox1->insertItem( "Only if available", 0 ); |
452 | ComboBox1->insertItem( "Always, Negotiated", 1 ); | 455 | ComboBox1->insertItem( "Always, Negotiated", 1 ); |
453 | ComboBox1->insertItem( "Connect on secure port", 2 ); | 456 | ComboBox1->insertItem( "Connect on secure port", 2 ); |
454 | ComboBox1->insertItem( "Run command instead", 3 ); | 457 | ComboBox1->insertItem( "Run command instead", 3 ); |
455 | CommandEdit->hide(); | 458 | CommandEdit->hide(); |
456 | ComboBox1->setCurrentItem( data->ConnectionType() ); | 459 | ComboBox1->setCurrentItem( data->ConnectionType() ); |
457 | } | 460 | } |
458 | 461 | ||
459 | void SMTPconfig::slotConnectionToggle( int index ) | 462 | void SMTPconfig::slotConnectionToggle( int index ) |
460 | { | 463 | { |
461 | // 2 is ssl connection | 464 | // 2 is ssl connection |
462 | if ( index == 2 ) | 465 | if ( index == 2 ) |
463 | { | 466 | { |
464 | portLine->setText( SMTP_SSL_PORT ); | 467 | portLine->setText( SMTP_SSL_PORT ); |
465 | } | 468 | } |
466 | else if ( index == 3 ) | 469 | else if ( index == 3 ) |
467 | { | 470 | { |
468 | portLine->setText( SMTP_PORT ); | 471 | portLine->setText( SMTP_PORT ); |
469 | CommandEdit->show(); | 472 | CommandEdit->show(); |
470 | } | 473 | } |
471 | else | 474 | else |
472 | { | 475 | { |
473 | portLine->setText( SMTP_PORT ); | 476 | portLine->setText( SMTP_PORT ); |
474 | } | 477 | } |
475 | } | 478 | } |
476 | 479 | ||
477 | void SMTPconfig::fillValues() | 480 | void SMTPconfig::fillValues() |
478 | { | 481 | { |
479 | accountLine->setText( data->getAccountName() ); | 482 | accountLine->setText( data->getAccountName() ); |
480 | serverLine->setText( data->getServer() ); | 483 | serverLine->setText( data->getServer() ); |
481 | portLine->setText( data->getPort() ); | 484 | portLine->setText( data->getPort() ); |
482 | ComboBox1->setCurrentItem( data->ConnectionType() ); | 485 | ComboBox1->setCurrentItem( data->ConnectionType() ); |
483 | loginBox->setChecked( data->getLogin() ); | 486 | loginBox->setChecked( data->getLogin() ); |
484 | userLine->setText( data->getUser() ); | 487 | userLine->setText( data->getUser() ); |
485 | passLine->setText( data->getPassword() ); | 488 | passLine->setText( data->getPassword() ); |
486 | } | 489 | } |
487 | 490 | ||
488 | void SMTPconfig::accept() | 491 | void SMTPconfig::accept() |
489 | { | 492 | { |
490 | data->setAccountName( accountLine->text() ); | 493 | data->setAccountName( accountLine->text() ); |
491 | data->setServer( serverLine->text() ); | 494 | data->setServer( serverLine->text() ); |
492 | data->setPort( portLine->text() ); | 495 | data->setPort( portLine->text() ); |
493 | data->setConnectionType( ComboBox1->currentItem() ); | 496 | data->setConnectionType( ComboBox1->currentItem() ); |
494 | data->setLogin( loginBox->isChecked() ); | 497 | data->setLogin( loginBox->isChecked() ); |
495 | data->setUser( userLine->text() ); | 498 | data->setUser( userLine->text() ); |
496 | data->setPassword( passLine->text() ); | 499 | data->setPassword( passLine->text() ); |
497 | 500 | ||
498 | QDialog::accept(); | 501 | QDialog::accept(); |
499 | } | 502 | } |
500 | 503 | ||
501 | /** | 504 | /** |
502 | * NNTPconfig | 505 | * NNTPconfig |
503 | */ | 506 | */ |
504 | 507 | ||
505 | NNTPconfig::NNTPconfig( NNTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) | 508 | NNTPconfig::NNTPconfig( NNTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) |
506 | : NNTPconfigUI( parent, name, modal, flags ) | 509 | : NNTPconfigUI( parent, name, modal, flags ) |
507 | { | 510 | { |
508 | data = account; | 511 | data = account; |
509 | 512 | ||
510 | connect( loginBox, SIGNAL( toggled(bool) ), userLine, SLOT( setEnabled(bool) ) ); | 513 | connect( loginBox, SIGNAL( toggled(bool) ), userLine, SLOT( setEnabled(bool) ) ); |
511 | connect( loginBox, SIGNAL( toggled(bool) ), passLine, SLOT( setEnabled(bool) ) ); | 514 | connect( loginBox, SIGNAL( toggled(bool) ), passLine, SLOT( setEnabled(bool) ) ); |
512 | connect( GetNGButton, SIGNAL( clicked() ), this, SLOT( slotGetNG() ) ); | 515 | connect( GetNGButton, SIGNAL( clicked() ), this, SLOT( slotGetNG() ) ); |
513 | fillValues(); | 516 | fillValues(); |
514 | 517 | ||
515 | connect( sslBox, SIGNAL( toggled(bool) ), SLOT( slotSSL(bool) ) ); | 518 | connect( sslBox, SIGNAL( toggled(bool) ), SLOT( slotSSL(bool) ) ); |
516 | } | 519 | } |
517 | 520 | ||
518 | void NNTPconfig::slotGetNG() { | 521 | void NNTPconfig::slotGetNG() { |
519 | save(); | 522 | save(); |
520 | data->save(); | 523 | data->save(); |
521 | NNTPwrapper* tmp = new NNTPwrapper( data ); | 524 | NNTPwrapper* tmp = new NNTPwrapper( data ); |
522 | QStringList list = tmp->listAllNewsgroups(); | 525 | QStringList list = tmp->listAllNewsgroups(); |
523 | 526 | ||
524 | ListViewGroups->clear(); | 527 | ListViewGroups->clear(); |
525 | 528 | ||
526 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 529 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
527 | QCheckListItem *item; | 530 | QCheckListItem *item; |
528 | item = new QCheckListItem( ListViewGroups, (*it), QCheckListItem::CheckBox ); | 531 | item = new QCheckListItem( ListViewGroups, (*it), QCheckListItem::CheckBox ); |
529 | if ( subscribedGroups.contains( (*it) ) >= 1 ) { | 532 | if ( subscribedGroups.contains( (*it) ) >= 1 ) { |
530 | item->setOn( true ); | 533 | item->setOn( true ); |
531 | } | 534 | } |
532 | } | 535 | } |
533 | } | 536 | } |
534 | 537 | ||
535 | void NNTPconfig::slotSSL( bool enabled ) | 538 | void NNTPconfig::slotSSL( bool enabled ) |
536 | { | 539 | { |
537 | if ( enabled ) | 540 | if ( enabled ) |
538 | { | 541 | { |
539 | portLine->setText( NNTP_SSL_PORT ); | 542 | portLine->setText( NNTP_SSL_PORT ); |
540 | } | 543 | } |
541 | else | 544 | else |
542 | { | 545 | { |
543 | portLine->setText( NNTP_PORT ); | 546 | portLine->setText( NNTP_PORT ); |
544 | } | 547 | } |
545 | } | 548 | } |
546 | 549 | ||
547 | void NNTPconfig::fillValues() | 550 | void NNTPconfig::fillValues() |
548 | { | 551 | { |
549 | accountLine->setText( data->getAccountName() ); | 552 | accountLine->setText( data->getAccountName() ); |
550 | serverLine->setText( data->getServer() ); | 553 | serverLine->setText( data->getServer() ); |
551 | portLine->setText( data->getPort() ); | 554 | portLine->setText( data->getPort() ); |
552 | sslBox->setChecked( data->getSSL() ); | 555 | sslBox->setChecked( data->getSSL() ); |
553 | loginBox->setChecked( data->getLogin() ); | 556 | loginBox->setChecked( data->getLogin() ); |
554 | userLine->setText( data->getUser() ); | 557 | userLine->setText( data->getUser() ); |
555 | passLine->setText( data->getPassword() ); | 558 | passLine->setText( data->getPassword() ); |
556 | subscribedGroups = data->getGroups(); | 559 | subscribedGroups = data->getGroups(); |
557 | /* don't forget that - you will overwrite values if user clicks cancel! */ | 560 | /* don't forget that - you will overwrite values if user clicks cancel! */ |
558 | for ( QStringList::Iterator it = subscribedGroups.begin(); it != subscribedGroups.end(); ++it ) { | 561 | for ( QStringList::Iterator it = subscribedGroups.begin(); it != subscribedGroups.end(); ++it ) { |
559 | QCheckListItem *item; | 562 | QCheckListItem *item; |
560 | item = new QCheckListItem( ListViewGroups, (*it), QCheckListItem::CheckBox ); | 563 | item = new QCheckListItem( ListViewGroups, (*it), QCheckListItem::CheckBox ); |
561 | item->setOn( true ); | 564 | item->setOn( true ); |
562 | } | 565 | } |
563 | } | 566 | } |
564 | 567 | ||
565 | void NNTPconfig::save() | 568 | void NNTPconfig::save() |
566 | { | 569 | { |
567 | data->setAccountName( accountLine->text() ); | 570 | data->setAccountName( accountLine->text() ); |
568 | data->setServer( serverLine->text() ); | 571 | data->setServer( serverLine->text() ); |
569 | data->setPort( portLine->text() ); | 572 | data->setPort( portLine->text() ); |
570 | data->setSSL( sslBox->isChecked() ); | 573 | data->setSSL( sslBox->isChecked() ); |
571 | data->setLogin( loginBox->isChecked() ); | 574 | data->setLogin( loginBox->isChecked() ); |
572 | data->setUser( userLine->text() ); | 575 | data->setUser( userLine->text() ); |
573 | data->setPassword( passLine->text() ); | 576 | data->setPassword( passLine->text() ); |
574 | 577 | ||
575 | QListViewItemIterator list_it( ListViewGroups ); | 578 | QListViewItemIterator list_it( ListViewGroups ); |
576 | 579 | ||
577 | QStringList groupList; | 580 | QStringList groupList; |
578 | for ( ; list_it.current(); ++list_it ) { | 581 | for ( ; list_it.current(); ++list_it ) { |
579 | 582 | ||
580 | if ( ( (QCheckListItem*)list_it.current() )->isOn() ) { | 583 | if ( ( (QCheckListItem*)list_it.current() )->isOn() ) { |
581 | odebug << list_it.current()->text(0) << oendl; | 584 | odebug << list_it.current()->text(0) << oendl; |
582 | groupList.append( list_it.current()->text(0) ); | 585 | groupList.append( list_it.current()->text(0) ); |
583 | } | 586 | } |
584 | 587 | ||
585 | } | 588 | } |
586 | data->setGroups( groupList ); | 589 | data->setGroups( groupList ); |
587 | } | 590 | } |
588 | 591 | ||
589 | void NNTPconfig::accept() | 592 | void NNTPconfig::accept() |
590 | { | 593 | { |
591 | save(); | 594 | save(); |
592 | QDialog::accept(); | 595 | QDialog::accept(); |
593 | } | 596 | } |
594 | 597 | ||
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp index 1a26351..7c1c0e4 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.cpp +++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp | |||
@@ -1,168 +1,170 @@ | |||
1 | #include "abstractmail.h" | 1 | #include "abstractmail.h" |
2 | #include "imapwrapper.h" | 2 | #include "imapwrapper.h" |
3 | #include "pop3wrapper.h" | 3 | #include "pop3wrapper.h" |
4 | #include "nntpwrapper.h" | 4 | #include "nntpwrapper.h" |
5 | #include "mhwrapper.h" | 5 | #include "mhwrapper.h" |
6 | #include "mailtypes.h" | 6 | #include "mailtypes.h" |
7 | 7 | ||
8 | #include <opie2/odebug.h> | ||
9 | |||
8 | #include <qfile.h> | 10 | #include <qfile.h> |
9 | #include <qtextstream.h> | 11 | #include <qtextstream.h> |
10 | #include <stdlib.h> | 12 | #include <stdlib.h> |
11 | #include <libetpan/mailmime_content.h> | 13 | #include <libetpan/mailmime_content.h> |
12 | #include <libetpan/mailmime.h> | 14 | #include <libetpan/mailmime.h> |
13 | 15 | ||
14 | using namespace Opie::Core; | 16 | using namespace Opie::Core; |
15 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) | 17 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) |
16 | { | 18 | { |
17 | return new IMAPwrapper(a); | 19 | return new IMAPwrapper(a); |
18 | } | 20 | } |
19 | 21 | ||
20 | AbstractMail* AbstractMail::getWrapper(POP3account *a) | 22 | AbstractMail* AbstractMail::getWrapper(POP3account *a) |
21 | { | 23 | { |
22 | return new POP3wrapper(a); | 24 | return new POP3wrapper(a); |
23 | } | 25 | } |
24 | 26 | ||
25 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) | 27 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) |
26 | { | 28 | { |
27 | return new NNTPwrapper(a); | 29 | return new NNTPwrapper(a); |
28 | } | 30 | } |
29 | 31 | ||
30 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) | 32 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) |
31 | { | 33 | { |
32 | return new MHwrapper(a,name); | 34 | return new MHwrapper(a,name); |
33 | } | 35 | } |
34 | 36 | ||
35 | AbstractMail* AbstractMail::getWrapper(Account*a) | 37 | AbstractMail* AbstractMail::getWrapper(Account*a) |
36 | { | 38 | { |
37 | if (!a) return 0; | 39 | if (!a) return 0; |
38 | switch (a->getType()) { | 40 | switch (a->getType()) { |
39 | case MAILLIB::A_IMAP: | 41 | case MAILLIB::A_IMAP: |
40 | return new IMAPwrapper((IMAPaccount*)a); | 42 | return new IMAPwrapper((IMAPaccount*)a); |
41 | break; | 43 | break; |
42 | case MAILLIB::A_POP3: | 44 | case MAILLIB::A_POP3: |
43 | return new POP3wrapper((POP3account*)a); | 45 | return new POP3wrapper((POP3account*)a); |
44 | break; | 46 | break; |
45 | case MAILLIB::A_NNTP: | 47 | case MAILLIB::A_NNTP: |
46 | return new NNTPwrapper((NNTPaccount*)a); | 48 | return new NNTPwrapper((NNTPaccount*)a); |
47 | break; | 49 | break; |
48 | default: | 50 | default: |
49 | return 0; | 51 | return 0; |
50 | } | 52 | } |
51 | } | 53 | } |
52 | 54 | ||
53 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) | 55 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) |
54 | { | 56 | { |
55 | odebug << "Decode string start" << oendl; | 57 | odebug << "Decode string start" << oendl; |
56 | char*result_text; | 58 | char*result_text; |
57 | size_t index = 0; | 59 | size_t index = 0; |
58 | /* reset for recursive use! */ | 60 | /* reset for recursive use! */ |
59 | size_t target_length = 0; | 61 | size_t target_length = 0; |
60 | result_text = 0; | 62 | result_text = 0; |
61 | int mimetype = MAILMIME_MECHANISM_7BIT; | 63 | int mimetype = MAILMIME_MECHANISM_7BIT; |
62 | if (enc.lower()=="quoted-printable") { | 64 | if (enc.lower()=="quoted-printable") { |
63 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 65 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
64 | } else if (enc.lower()=="base64") { | 66 | } else if (enc.lower()=="base64") { |
65 | mimetype = MAILMIME_MECHANISM_BASE64; | 67 | mimetype = MAILMIME_MECHANISM_BASE64; |
66 | } else if (enc.lower()=="8bit") { | 68 | } else if (enc.lower()=="8bit") { |
67 | mimetype = MAILMIME_MECHANISM_8BIT; | 69 | mimetype = MAILMIME_MECHANISM_8BIT; |
68 | } else if (enc.lower()=="binary") { | 70 | } else if (enc.lower()=="binary") { |
69 | mimetype = MAILMIME_MECHANISM_BINARY; | 71 | mimetype = MAILMIME_MECHANISM_BINARY; |
70 | } | 72 | } |
71 | 73 | ||
72 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, | 74 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, |
73 | &result_text,&target_length); | 75 | &result_text,&target_length); |
74 | 76 | ||
75 | encodedString* result = new encodedString(); | 77 | encodedString* result = new encodedString(); |
76 | if (err == MAILIMF_NO_ERROR) { | 78 | if (err == MAILIMF_NO_ERROR) { |
77 | result->setContent(result_text,target_length); | 79 | result->setContent(result_text,target_length); |
78 | } | 80 | } |
79 | odebug << "Decode string finished" << oendl; | 81 | odebug << "Decode string finished" << oendl; |
80 | return result; | 82 | return result; |
81 | } | 83 | } |
82 | 84 | ||
83 | QString AbstractMail::convert_String(const char*text) | 85 | QString AbstractMail::convert_String(const char*text) |
84 | { | 86 | { |
85 | //size_t index = 0; | 87 | //size_t index = 0; |
86 | char*res = 0; | 88 | char*res = 0; |
87 | int err = MAILIMF_NO_ERROR; | 89 | int err = MAILIMF_NO_ERROR; |
88 | 90 | ||
89 | QString result(text); | 91 | QString result(text); |
90 | 92 | ||
91 | /* due a bug in libetpan it isn't usable this moment */ | 93 | /* due a bug in libetpan it isn't usable this moment */ |
92 | /* int err = mailmime_encoded_phrase_parse("iso-8859-1", | 94 | /* int err = mailmime_encoded_phrase_parse("iso-8859-1", |
93 | text, strlen(text),&index, "iso-8859-1",&res);*/ | 95 | text, strlen(text),&index, "iso-8859-1",&res);*/ |
94 | //odebug << "Input: " << text << "" << oendl; | 96 | //odebug << "Input: " << text << "" << oendl; |
95 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { | 97 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { |
96 | // result = QString(res); | 98 | // result = QString(res); |
97 | // odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl; | 99 | // odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl; |
98 | } | 100 | } |
99 | if (res) free(res); | 101 | if (res) free(res); |
100 | return result; | 102 | return result; |
101 | } | 103 | } |
102 | 104 | ||
103 | /* cp & paste from launcher */ | 105 | /* cp & paste from launcher */ |
104 | QString AbstractMail::gen_attachment_id() | 106 | QString AbstractMail::gen_attachment_id() |
105 | { | 107 | { |
106 | QFile file( "/proc/sys/kernel/random/uuid" ); | 108 | QFile file( "/proc/sys/kernel/random/uuid" ); |
107 | if (!file.open(IO_ReadOnly ) ) | 109 | if (!file.open(IO_ReadOnly ) ) |
108 | return QString::null; | 110 | return QString::null; |
109 | 111 | ||
110 | QTextStream stream(&file); | 112 | QTextStream stream(&file); |
111 | 113 | ||
112 | return "{" + stream.read().stripWhiteSpace() + "}"; | 114 | return "{" + stream.read().stripWhiteSpace() + "}"; |
113 | } | 115 | } |
114 | 116 | ||
115 | int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) | 117 | int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) |
116 | { | 118 | { |
117 | return 0; | 119 | return 0; |
118 | } | 120 | } |
119 | 121 | ||
120 | QString AbstractMail::defaultLocalfolder() | 122 | QString AbstractMail::defaultLocalfolder() |
121 | { | 123 | { |
122 | QString f = getenv( "HOME" ); | 124 | QString f = getenv( "HOME" ); |
123 | f += "/Applications/opiemail/localmail"; | 125 | f += "/Applications/opiemail/localmail"; |
124 | return f; | 126 | return f; |
125 | } | 127 | } |
126 | 128 | ||
127 | QString AbstractMail::draftFolder() | 129 | QString AbstractMail::draftFolder() |
128 | { | 130 | { |
129 | return QString("Drafts"); | 131 | return QString("Drafts"); |
130 | } | 132 | } |
131 | 133 | ||
132 | /* temporary - will be removed when implemented in all classes */ | 134 | /* temporary - will be removed when implemented in all classes */ |
133 | void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) | 135 | void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) |
134 | { | 136 | { |
135 | } | 137 | } |
136 | 138 | ||
137 | void AbstractMail::mvcpAllMails(const FolderP&fromFolder, | 139 | void AbstractMail::mvcpAllMails(const FolderP&fromFolder, |
138 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 140 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
139 | { | 141 | { |
140 | QValueList<RecMailP> t; | 142 | QValueList<RecMailP> t; |
141 | listMessages(fromFolder->getName(),t); | 143 | listMessages(fromFolder->getName(),t); |
142 | encodedString*st = 0; | 144 | encodedString*st = 0; |
143 | while (t.count()>0) { | 145 | while (t.count()>0) { |
144 | RecMailP r = (*t.begin()); | 146 | RecMailP r = (*t.begin()); |
145 | st = fetchRawBody(r); | 147 | st = fetchRawBody(r); |
146 | if (st) { | 148 | if (st) { |
147 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); | 149 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); |
148 | delete st; | 150 | delete st; |
149 | } | 151 | } |
150 | t.remove(t.begin()); | 152 | t.remove(t.begin()); |
151 | } | 153 | } |
152 | if (moveit) { | 154 | if (moveit) { |
153 | deleteAllMail(fromFolder); | 155 | deleteAllMail(fromFolder); |
154 | } | 156 | } |
155 | } | 157 | } |
156 | 158 | ||
157 | void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 159 | void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
158 | { | 160 | { |
159 | encodedString*st = 0; | 161 | encodedString*st = 0; |
160 | st = fetchRawBody(mail); | 162 | st = fetchRawBody(mail); |
161 | if (st) { | 163 | if (st) { |
162 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); | 164 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); |
163 | delete st; | 165 | delete st; |
164 | } | 166 | } |
165 | if (moveit) { | 167 | if (moveit) { |
166 | deleteMail(mail); | 168 | deleteMail(mail); |
167 | } | 169 | } |
168 | } | 170 | } |
diff --git a/noncore/net/mail/libmailwrapper/generatemail.cpp b/noncore/net/mail/libmailwrapper/generatemail.cpp index 36ec232..eb322a7 100644 --- a/noncore/net/mail/libmailwrapper/generatemail.cpp +++ b/noncore/net/mail/libmailwrapper/generatemail.cpp | |||
@@ -1,468 +1,470 @@ | |||
1 | #include "generatemail.h" | 1 | #include "generatemail.h" |
2 | #include "mailwrapper.h" | 2 | #include "mailwrapper.h" |
3 | 3 | ||
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | 5 | ||
6 | #include <opie2/odebug.h> | ||
7 | |||
6 | #include <qt.h> | 8 | #include <qt.h> |
7 | 9 | ||
8 | using namespace Opie::Core; | 10 | using namespace Opie::Core; |
9 | const char* Generatemail::USER_AGENT="OpieMail v0.6"; | 11 | const char* Generatemail::USER_AGENT="OpieMail v0.6"; |
10 | 12 | ||
11 | Generatemail::Generatemail() | 13 | Generatemail::Generatemail() |
12 | { | 14 | { |
13 | } | 15 | } |
14 | 16 | ||
15 | Generatemail::~Generatemail() | 17 | Generatemail::~Generatemail() |
16 | { | 18 | { |
17 | } | 19 | } |
18 | 20 | ||
19 | void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) { | 21 | void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) { |
20 | clistiter *it, *it2; | 22 | clistiter *it, *it2; |
21 | 23 | ||
22 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | 24 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { |
23 | mailimf_address *addr; | 25 | mailimf_address *addr; |
24 | addr = (mailimf_address *) it->data; | 26 | addr = (mailimf_address *) it->data; |
25 | 27 | ||
26 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | 28 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { |
27 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | 29 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); |
28 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { | 30 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { |
29 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | 31 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; |
30 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | 32 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { |
31 | mailimf_mailbox *mbox; | 33 | mailimf_mailbox *mbox; |
32 | mbox = (mailimf_mailbox *) it2->data; | 34 | mbox = (mailimf_mailbox *) it2->data; |
33 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | 35 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); |
34 | } | 36 | } |
35 | } | 37 | } |
36 | } | 38 | } |
37 | } | 39 | } |
38 | 40 | ||
39 | char *Generatemail::getFrom( mailimf_field *ffrom) { | 41 | char *Generatemail::getFrom( mailimf_field *ffrom) { |
40 | char *from = NULL; | 42 | char *from = NULL; |
41 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 43 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) |
42 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | 44 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { |
43 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | 45 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; |
44 | clistiter *it; | 46 | clistiter *it; |
45 | for ( it = clist_begin( cl ); it; it = it->next ) { | 47 | for ( it = clist_begin( cl ); it; it = it->next ) { |
46 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 48 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
47 | from = strdup( mb->mb_addr_spec ); | 49 | from = strdup( mb->mb_addr_spec ); |
48 | } | 50 | } |
49 | } | 51 | } |
50 | 52 | ||
51 | return from; | 53 | return from; |
52 | } | 54 | } |
53 | 55 | ||
54 | char *Generatemail::getFrom( mailmime *mail ) { | 56 | char *Generatemail::getFrom( mailmime *mail ) { |
55 | /* no need to delete - its just a pointer to structure content */ | 57 | /* no need to delete - its just a pointer to structure content */ |
56 | mailimf_field *ffrom = 0; | 58 | mailimf_field *ffrom = 0; |
57 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | 59 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); |
58 | return getFrom(ffrom); | 60 | return getFrom(ffrom); |
59 | } | 61 | } |
60 | 62 | ||
61 | mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) { | 63 | mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) { |
62 | mailimf_field *field; | 64 | mailimf_field *field; |
63 | clistiter *it; | 65 | clistiter *it; |
64 | 66 | ||
65 | it = clist_begin( fields->fld_list ); | 67 | it = clist_begin( fields->fld_list ); |
66 | while ( it ) { | 68 | while ( it ) { |
67 | field = (mailimf_field *) it->data; | 69 | field = (mailimf_field *) it->data; |
68 | if ( field->fld_type == type ) { | 70 | if ( field->fld_type == type ) { |
69 | return field; | 71 | return field; |
70 | } | 72 | } |
71 | it = it->next; | 73 | it = it->next; |
72 | } | 74 | } |
73 | 75 | ||
74 | return NULL; | 76 | return NULL; |
75 | } | 77 | } |
76 | 78 | ||
77 | mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) { | 79 | mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) { |
78 | mailimf_address_list *addresses; | 80 | mailimf_address_list *addresses; |
79 | 81 | ||
80 | if ( addr.isEmpty() ) | 82 | if ( addr.isEmpty() ) |
81 | return NULL; | 83 | return NULL; |
82 | 84 | ||
83 | addresses = mailimf_address_list_new_empty(); | 85 | addresses = mailimf_address_list_new_empty(); |
84 | 86 | ||
85 | bool literal_open = false; | 87 | bool literal_open = false; |
86 | unsigned int startpos = 0; | 88 | unsigned int startpos = 0; |
87 | QStringList list; | 89 | QStringList list; |
88 | QString s; | 90 | QString s; |
89 | unsigned int i = 0; | 91 | unsigned int i = 0; |
90 | for (; i < addr.length();++i) { | 92 | for (; i < addr.length();++i) { |
91 | switch (addr[i]) { | 93 | switch (addr[i]) { |
92 | case '\"': | 94 | case '\"': |
93 | literal_open = !literal_open; | 95 | literal_open = !literal_open; |
94 | break; | 96 | break; |
95 | case ',': | 97 | case ',': |
96 | if (!literal_open) { | 98 | if (!literal_open) { |
97 | s = addr.mid(startpos,i-startpos); | 99 | s = addr.mid(startpos,i-startpos); |
98 | if (!s.isEmpty()) { | 100 | if (!s.isEmpty()) { |
99 | list.append(s); | 101 | list.append(s); |
100 | odebug << "Appended " << s.latin1() << "" << oendl; | 102 | odebug << "Appended " << s.latin1() << "" << oendl; |
101 | } | 103 | } |
102 | // !!!! this is a MUST BE! | 104 | // !!!! this is a MUST BE! |
103 | startpos = ++i; | 105 | startpos = ++i; |
104 | } | 106 | } |
105 | break; | 107 | break; |
106 | default: | 108 | default: |
107 | break; | 109 | break; |
108 | } | 110 | } |
109 | } | 111 | } |
110 | s = addr.mid(startpos,i-startpos); | 112 | s = addr.mid(startpos,i-startpos); |
111 | if (!s.isEmpty()) { | 113 | if (!s.isEmpty()) { |
112 | list.append(s); | 114 | list.append(s); |
113 | odebug << "Appended " << s.latin1() << "" << oendl; | 115 | odebug << "Appended " << s.latin1() << "" << oendl; |
114 | } | 116 | } |
115 | QStringList::Iterator it; | 117 | QStringList::Iterator it; |
116 | for ( it = list.begin(); it != list.end(); it++ ) { | 118 | for ( it = list.begin(); it != list.end(); it++ ) { |
117 | int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); | 119 | int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); |
118 | if ( err != MAILIMF_NO_ERROR ) { | 120 | if ( err != MAILIMF_NO_ERROR ) { |
119 | odebug << "Error parsing" << oendl; | 121 | odebug << "Error parsing" << oendl; |
120 | odebug << *it << oendl; | 122 | odebug << *it << oendl; |
121 | } else { | 123 | } else { |
122 | odebug << "Parse success! " << (*it).latin1() << "" << oendl; | 124 | odebug << "Parse success! " << (*it).latin1() << "" << oendl; |
123 | } | 125 | } |
124 | } | 126 | } |
125 | return addresses; | 127 | return addresses; |
126 | } | 128 | } |
127 | 129 | ||
128 | mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { | 130 | mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { |
129 | mailmime * filePart = 0; | 131 | mailmime * filePart = 0; |
130 | mailmime_fields * fields = 0; | 132 | mailmime_fields * fields = 0; |
131 | mailmime_content * content = 0; | 133 | mailmime_content * content = 0; |
132 | mailmime_parameter * param = 0; | 134 | mailmime_parameter * param = 0; |
133 | char*name = 0; | 135 | char*name = 0; |
134 | char*file = 0; | 136 | char*file = 0; |
135 | int err; | 137 | int err; |
136 | 138 | ||
137 | int pos = filename.findRev( '/' ); | 139 | int pos = filename.findRev( '/' ); |
138 | 140 | ||
139 | if (filename.length()>0) { | 141 | if (filename.length()>0) { |
140 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 142 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
141 | name = strdup( tmp.latin1() ); // just filename | 143 | name = strdup( tmp.latin1() ); // just filename |
142 | file = strdup( filename.latin1() ); // full name with path | 144 | file = strdup( filename.latin1() ); // full name with path |
143 | } | 145 | } |
144 | 146 | ||
145 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; | 147 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; |
146 | int mechanism = MAILMIME_MECHANISM_BASE64; | 148 | int mechanism = MAILMIME_MECHANISM_BASE64; |
147 | 149 | ||
148 | if ( mimetype.startsWith( "text/" ) ) { | 150 | if ( mimetype.startsWith( "text/" ) ) { |
149 | param = mailmime_parameter_new( strdup( "charset" ), | 151 | param = mailmime_parameter_new( strdup( "charset" ), |
150 | strdup( "iso-8859-1" ) ); | 152 | strdup( "iso-8859-1" ) ); |
151 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 153 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
152 | } | 154 | } |
153 | 155 | ||
154 | fields = mailmime_fields_new_filename( | 156 | fields = mailmime_fields_new_filename( |
155 | disptype, name, | 157 | disptype, name, |
156 | mechanism ); | 158 | mechanism ); |
157 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); | 159 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); |
158 | if (content!=0 && fields != 0) { | 160 | if (content!=0 && fields != 0) { |
159 | if (param) { | 161 | if (param) { |
160 | clist_append(content->ct_parameters,param); | 162 | clist_append(content->ct_parameters,param); |
161 | param = 0; | 163 | param = 0; |
162 | } | 164 | } |
163 | if (filename.length()>0) { | 165 | if (filename.length()>0) { |
164 | QFileInfo f(filename); | 166 | QFileInfo f(filename); |
165 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); | 167 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); |
166 | clist_append(content->ct_parameters,param); | 168 | clist_append(content->ct_parameters,param); |
167 | param = 0; | 169 | param = 0; |
168 | } | 170 | } |
169 | filePart = mailmime_new_empty( content, fields ); | 171 | filePart = mailmime_new_empty( content, fields ); |
170 | } | 172 | } |
171 | if (filePart) { | 173 | if (filePart) { |
172 | if (filename.length()>0) { | 174 | if (filename.length()>0) { |
173 | err = mailmime_set_body_file( filePart, file ); | 175 | err = mailmime_set_body_file( filePart, file ); |
174 | } else { | 176 | } else { |
175 | err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); | 177 | err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); |
176 | } | 178 | } |
177 | if (err != MAILIMF_NO_ERROR) { | 179 | if (err != MAILIMF_NO_ERROR) { |
178 | odebug << "Error setting body with file " << file << "" << oendl; | 180 | odebug << "Error setting body with file " << file << "" << oendl; |
179 | mailmime_free( filePart ); | 181 | mailmime_free( filePart ); |
180 | filePart = 0; | 182 | filePart = 0; |
181 | } | 183 | } |
182 | } | 184 | } |
183 | 185 | ||
184 | if (!filePart) { | 186 | if (!filePart) { |
185 | if ( param != NULL ) { | 187 | if ( param != NULL ) { |
186 | mailmime_parameter_free( param ); | 188 | mailmime_parameter_free( param ); |
187 | } | 189 | } |
188 | if (content) { | 190 | if (content) { |
189 | mailmime_content_free( content ); | 191 | mailmime_content_free( content ); |
190 | } | 192 | } |
191 | if (fields) { | 193 | if (fields) { |
192 | mailmime_fields_free( fields ); | 194 | mailmime_fields_free( fields ); |
193 | } else { | 195 | } else { |
194 | if (name) { | 196 | if (name) { |
195 | free( name ); | 197 | free( name ); |
196 | } | 198 | } |
197 | if (file) { | 199 | if (file) { |
198 | free( file ); | 200 | free( file ); |
199 | } | 201 | } |
200 | } | 202 | } |
201 | } | 203 | } |
202 | return filePart; // Success :) | 204 | return filePart; // Success :) |
203 | 205 | ||
204 | } | 206 | } |
205 | 207 | ||
206 | void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) { | 208 | void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) { |
207 | const Attachment *it; | 209 | const Attachment *it; |
208 | unsigned int count = files.count(); | 210 | unsigned int count = files.count(); |
209 | odebug << "List contains " << count << " values" << oendl; | 211 | odebug << "List contains " << count << " values" << oendl; |
210 | for ( unsigned int i = 0; i < count; ++i ) { | 212 | for ( unsigned int i = 0; i < count; ++i ) { |
211 | odebug << "Adding file" << oendl; | 213 | odebug << "Adding file" << oendl; |
212 | mailmime *filePart; | 214 | mailmime *filePart; |
213 | int err; | 215 | int err; |
214 | it = ((QList<Attachment>)files).at(i); | 216 | it = ((QList<Attachment>)files).at(i); |
215 | 217 | ||
216 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); | 218 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); |
217 | if ( filePart == NULL ) { | 219 | if ( filePart == NULL ) { |
218 | odebug << "addFileParts: error adding file:" << oendl; | 220 | odebug << "addFileParts: error adding file:" << oendl; |
219 | odebug << it->getFileName() << oendl; | 221 | odebug << it->getFileName() << oendl; |
220 | continue; | 222 | continue; |
221 | } | 223 | } |
222 | err = mailmime_smart_add_part( message, filePart ); | 224 | err = mailmime_smart_add_part( message, filePart ); |
223 | if ( err != MAILIMF_NO_ERROR ) { | 225 | if ( err != MAILIMF_NO_ERROR ) { |
224 | mailmime_free( filePart ); | 226 | mailmime_free( filePart ); |
225 | odebug << "error smart add" << oendl; | 227 | odebug << "error smart add" << oendl; |
226 | } | 228 | } |
227 | } | 229 | } |
228 | } | 230 | } |
229 | 231 | ||
230 | mailmime *Generatemail::buildTxtPart(const QString&str ) { | 232 | mailmime *Generatemail::buildTxtPart(const QString&str ) { |
231 | mailmime *txtPart; | 233 | mailmime *txtPart; |
232 | mailmime_fields *fields; | 234 | mailmime_fields *fields; |
233 | mailmime_content *content; | 235 | mailmime_content *content; |
234 | mailmime_parameter *param; | 236 | mailmime_parameter *param; |
235 | int err; | 237 | int err; |
236 | 238 | ||
237 | param = mailmime_parameter_new( strdup( "charset" ), | 239 | param = mailmime_parameter_new( strdup( "charset" ), |
238 | strdup( "iso-8859-1" ) ); | 240 | strdup( "iso-8859-1" ) ); |
239 | if ( param == NULL ) | 241 | if ( param == NULL ) |
240 | goto err_free; | 242 | goto err_free; |
241 | 243 | ||
242 | content = mailmime_content_new_with_str( "text/plain" ); | 244 | content = mailmime_content_new_with_str( "text/plain" ); |
243 | if ( content == NULL ) | 245 | if ( content == NULL ) |
244 | goto err_free_param; | 246 | goto err_free_param; |
245 | 247 | ||
246 | err = clist_append( content->ct_parameters, param ); | 248 | err = clist_append( content->ct_parameters, param ); |
247 | if ( err != MAILIMF_NO_ERROR ) | 249 | if ( err != MAILIMF_NO_ERROR ) |
248 | goto err_free_content; | 250 | goto err_free_content; |
249 | 251 | ||
250 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); | 252 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); |
251 | if ( fields == NULL ) | 253 | if ( fields == NULL ) |
252 | goto err_free_content; | 254 | goto err_free_content; |
253 | 255 | ||
254 | txtPart = mailmime_new_empty( content, fields ); | 256 | txtPart = mailmime_new_empty( content, fields ); |
255 | if ( txtPart == NULL ) | 257 | if ( txtPart == NULL ) |
256 | goto err_free_fields; | 258 | goto err_free_fields; |
257 | 259 | ||
258 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); | 260 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); |
259 | if ( err != MAILIMF_NO_ERROR ) | 261 | if ( err != MAILIMF_NO_ERROR ) |
260 | goto err_free_txtPart; | 262 | goto err_free_txtPart; |
261 | 263 | ||
262 | return txtPart; // Success :) | 264 | return txtPart; // Success :) |
263 | 265 | ||
264 | err_free_txtPart: | 266 | err_free_txtPart: |
265 | mailmime_free( txtPart ); | 267 | mailmime_free( txtPart ); |
266 | err_free_fields: | 268 | err_free_fields: |
267 | mailmime_fields_free( fields ); | 269 | mailmime_fields_free( fields ); |
268 | err_free_content: | 270 | err_free_content: |
269 | mailmime_content_free( content ); | 271 | mailmime_content_free( content ); |
270 | err_free_param: | 272 | err_free_param: |
271 | mailmime_parameter_free( param ); | 273 | mailmime_parameter_free( param ); |
272 | err_free: | 274 | err_free: |
273 | odebug << "buildTxtPart - error" << oendl; | 275 | odebug << "buildTxtPart - error" << oendl; |
274 | 276 | ||
275 | return NULL; // Error :( | 277 | return NULL; // Error :( |
276 | } | 278 | } |
277 | 279 | ||
278 | mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { | 280 | mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { |
279 | return mailimf_mailbox_new( strdup( name.latin1() ), | 281 | return mailimf_mailbox_new( strdup( name.latin1() ), |
280 | strdup( mail.latin1() ) ); | 282 | strdup( mail.latin1() ) ); |
281 | } | 283 | } |
282 | 284 | ||
283 | mailimf_fields *Generatemail::createImfFields(const Opie::Core::OSmartPointer<Mail>&mail ) | 285 | mailimf_fields *Generatemail::createImfFields(const Opie::Core::OSmartPointer<Mail>&mail ) |
284 | { | 286 | { |
285 | mailimf_fields *fields = NULL; | 287 | mailimf_fields *fields = NULL; |
286 | mailimf_field *xmailer = NULL; | 288 | mailimf_field *xmailer = NULL; |
287 | mailimf_mailbox *sender=0,*fromBox=0; | 289 | mailimf_mailbox *sender=0,*fromBox=0; |
288 | mailimf_mailbox_list *from=0; | 290 | mailimf_mailbox_list *from=0; |
289 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; | 291 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; |
290 | clist*in_reply_to = 0; | 292 | clist*in_reply_to = 0; |
291 | char *subject = strdup( mail->getSubject().latin1() ); | 293 | char *subject = strdup( mail->getSubject().latin1() ); |
292 | int err; | 294 | int err; |
293 | int res = 1; | 295 | int res = 1; |
294 | 296 | ||
295 | sender = newMailbox( mail->getName(), mail->getMail() ); | 297 | sender = newMailbox( mail->getName(), mail->getMail() ); |
296 | if ( sender == NULL ) { | 298 | if ( sender == NULL ) { |
297 | res = 0; | 299 | res = 0; |
298 | } | 300 | } |
299 | 301 | ||
300 | if (res) { | 302 | if (res) { |
301 | fromBox = newMailbox( mail->getName(), mail->getMail() ); | 303 | fromBox = newMailbox( mail->getName(), mail->getMail() ); |
302 | } | 304 | } |
303 | if ( fromBox == NULL ) { | 305 | if ( fromBox == NULL ) { |
304 | res = 0; | 306 | res = 0; |
305 | } | 307 | } |
306 | 308 | ||
307 | if (res) { | 309 | if (res) { |
308 | from = mailimf_mailbox_list_new_empty(); | 310 | from = mailimf_mailbox_list_new_empty(); |
309 | } | 311 | } |
310 | if ( from == NULL ) { | 312 | if ( from == NULL ) { |
311 | res = 0; | 313 | res = 0; |
312 | } | 314 | } |
313 | 315 | ||
314 | if (res && from) { | 316 | if (res && from) { |
315 | err = mailimf_mailbox_list_add( from, fromBox ); | 317 | err = mailimf_mailbox_list_add( from, fromBox ); |
316 | if ( err != MAILIMF_NO_ERROR ) { | 318 | if ( err != MAILIMF_NO_ERROR ) { |
317 | res = 0; | 319 | res = 0; |
318 | } | 320 | } |
319 | } | 321 | } |
320 | 322 | ||
321 | if (res) to = parseAddresses( mail->getTo() ); | 323 | if (res) to = parseAddresses( mail->getTo() ); |
322 | if (res) cc = parseAddresses( mail->getCC() ); | 324 | if (res) cc = parseAddresses( mail->getCC() ); |
323 | if (res) bcc = parseAddresses( mail->getBCC() ); | 325 | if (res) bcc = parseAddresses( mail->getBCC() ); |
324 | if (res) reply = parseAddresses( mail->getReply() ); | 326 | if (res) reply = parseAddresses( mail->getReply() ); |
325 | 327 | ||
326 | if (res && mail->Inreply().count()>0) { | 328 | if (res && mail->Inreply().count()>0) { |
327 | in_reply_to = clist_new(); | 329 | in_reply_to = clist_new(); |
328 | char*c_reply; | 330 | char*c_reply; |
329 | unsigned int nsize = 0; | 331 | unsigned int nsize = 0; |
330 | for (QStringList::ConstIterator it=mail->Inreply().begin(); | 332 | for (QStringList::ConstIterator it=mail->Inreply().begin(); |
331 | it != mail->Inreply().end();++it) { | 333 | it != mail->Inreply().end();++it) { |
332 | if ((*it).isEmpty()) | 334 | if ((*it).isEmpty()) |
333 | continue; | 335 | continue; |
334 | QString h((*it)); | 336 | QString h((*it)); |
335 | while (h.length()>0 && h[0]=='<') { | 337 | while (h.length()>0 && h[0]=='<') { |
336 | h.remove(0,1); | 338 | h.remove(0,1); |
337 | } | 339 | } |
338 | while (h.length()>0 && h[h.length()-1]=='>') { | 340 | while (h.length()>0 && h[h.length()-1]=='>') { |
339 | h.remove(h.length()-1,1); | 341 | h.remove(h.length()-1,1); |
340 | } | 342 | } |
341 | if (h.isEmpty()) continue; | 343 | if (h.isEmpty()) continue; |
342 | nsize = strlen(h.latin1()); | 344 | nsize = strlen(h.latin1()); |
343 | /* yes! must be malloc! */ | 345 | /* yes! must be malloc! */ |
344 | c_reply = (char*)malloc( (nsize+1)*sizeof(char)); | 346 | c_reply = (char*)malloc( (nsize+1)*sizeof(char)); |
345 | memset(c_reply,0,nsize+1); | 347 | memset(c_reply,0,nsize+1); |
346 | memcpy(c_reply,h.latin1(),nsize); | 348 | memcpy(c_reply,h.latin1(),nsize); |
347 | clist_append(in_reply_to,c_reply); | 349 | clist_append(in_reply_to,c_reply); |
348 | odebug << "In reply to: " << c_reply << "" << oendl; | 350 | odebug << "In reply to: " << c_reply << "" << oendl; |
349 | } | 351 | } |
350 | } | 352 | } |
351 | 353 | ||
352 | if (res) { | 354 | if (res) { |
353 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | 355 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, |
354 | in_reply_to, NULL, subject ); | 356 | in_reply_to, NULL, subject ); |
355 | if ( fields == NULL ) { | 357 | if ( fields == NULL ) { |
356 | odebug << "Error creating mailimf fields" << oendl; | 358 | odebug << "Error creating mailimf fields" << oendl; |
357 | res = 0; | 359 | res = 0; |
358 | } | 360 | } |
359 | } | 361 | } |
360 | if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 362 | if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), |
361 | strdup( USER_AGENT ) ); | 363 | strdup( USER_AGENT ) ); |
362 | if ( xmailer == NULL ) { | 364 | if ( xmailer == NULL ) { |
363 | res = 0; | 365 | res = 0; |
364 | } else { | 366 | } else { |
365 | err = mailimf_fields_add( fields, xmailer ); | 367 | err = mailimf_fields_add( fields, xmailer ); |
366 | if ( err != MAILIMF_NO_ERROR ) { | 368 | if ( err != MAILIMF_NO_ERROR ) { |
367 | res = 0; | 369 | res = 0; |
368 | } | 370 | } |
369 | } | 371 | } |
370 | if (!res ) { | 372 | if (!res ) { |
371 | if (xmailer) { | 373 | if (xmailer) { |
372 | mailimf_field_free( xmailer ); | 374 | mailimf_field_free( xmailer ); |
373 | xmailer = NULL; | 375 | xmailer = NULL; |
374 | } | 376 | } |
375 | if (fields) { | 377 | if (fields) { |
376 | mailimf_fields_free( fields ); | 378 | mailimf_fields_free( fields ); |
377 | fields = NULL; | 379 | fields = NULL; |
378 | } else { | 380 | } else { |
379 | if (reply) | 381 | if (reply) |
380 | mailimf_address_list_free( reply ); | 382 | mailimf_address_list_free( reply ); |
381 | if (bcc) | 383 | if (bcc) |
382 | mailimf_address_list_free( bcc ); | 384 | mailimf_address_list_free( bcc ); |
383 | if (cc) | 385 | if (cc) |
384 | mailimf_address_list_free( cc ); | 386 | mailimf_address_list_free( cc ); |
385 | if (to) | 387 | if (to) |
386 | mailimf_address_list_free( to ); | 388 | mailimf_address_list_free( to ); |
387 | if (fromBox) { | 389 | if (fromBox) { |
388 | mailimf_mailbox_free( fromBox ); | 390 | mailimf_mailbox_free( fromBox ); |
389 | } else if (from) { | 391 | } else if (from) { |
390 | mailimf_mailbox_list_free( from ); | 392 | mailimf_mailbox_list_free( from ); |
391 | } | 393 | } |
392 | if (sender) { | 394 | if (sender) { |
393 | mailimf_mailbox_free( sender ); | 395 | mailimf_mailbox_free( sender ); |
394 | } | 396 | } |
395 | if (subject) { | 397 | if (subject) { |
396 | free( subject ); | 398 | free( subject ); |
397 | } | 399 | } |
398 | } | 400 | } |
399 | } | 401 | } |
400 | return fields; | 402 | return fields; |
401 | } | 403 | } |
402 | 404 | ||
403 | mailmime *Generatemail::createMimeMail(const Opie::Core::OSmartPointer<Mail> &mail ) { | 405 | mailmime *Generatemail::createMimeMail(const Opie::Core::OSmartPointer<Mail> &mail ) { |
404 | mailmime *message, *txtPart; | 406 | mailmime *message, *txtPart; |
405 | mailimf_fields *fields; | 407 | mailimf_fields *fields; |
406 | int err; | 408 | int err; |
407 | 409 | ||
408 | fields = createImfFields( mail ); | 410 | fields = createImfFields( mail ); |
409 | if ( fields == NULL ) | 411 | if ( fields == NULL ) |
410 | goto err_free; | 412 | goto err_free; |
411 | 413 | ||
412 | message = mailmime_new_message_data( NULL ); | 414 | message = mailmime_new_message_data( NULL ); |
413 | if ( message == NULL ) | 415 | if ( message == NULL ) |
414 | goto err_free_fields; | 416 | goto err_free_fields; |
415 | 417 | ||
416 | mailmime_set_imf_fields( message, fields ); | 418 | mailmime_set_imf_fields( message, fields ); |
417 | 419 | ||
418 | txtPart = buildTxtPart( mail->getMessage() ); | 420 | txtPart = buildTxtPart( mail->getMessage() ); |
419 | 421 | ||
420 | if ( txtPart == NULL ) | 422 | if ( txtPart == NULL ) |
421 | goto err_free_message; | 423 | goto err_free_message; |
422 | 424 | ||
423 | err = mailmime_smart_add_part( message, txtPart ); | 425 | err = mailmime_smart_add_part( message, txtPart ); |
424 | if ( err != MAILIMF_NO_ERROR ) | 426 | if ( err != MAILIMF_NO_ERROR ) |
425 | goto err_free_txtPart; | 427 | goto err_free_txtPart; |
426 | 428 | ||
427 | addFileParts( message, mail->getAttachments() ); | 429 | addFileParts( message, mail->getAttachments() ); |
428 | 430 | ||
429 | return message; // Success :) | 431 | return message; // Success :) |
430 | 432 | ||
431 | err_free_txtPart: | 433 | err_free_txtPart: |
432 | mailmime_free( txtPart ); | 434 | mailmime_free( txtPart ); |
433 | err_free_message: | 435 | err_free_message: |
434 | mailmime_free( message ); | 436 | mailmime_free( message ); |
435 | err_free_fields: | 437 | err_free_fields: |
436 | mailimf_fields_free( fields ); | 438 | mailimf_fields_free( fields ); |
437 | err_free: | 439 | err_free: |
438 | odebug << "createMimeMail: error" << oendl; | 440 | odebug << "createMimeMail: error" << oendl; |
439 | 441 | ||
440 | return NULL; // Error :( | 442 | return NULL; // Error :( |
441 | } | 443 | } |
442 | 444 | ||
443 | clist *Generatemail::createRcptList( mailimf_fields *fields ) { | 445 | clist *Generatemail::createRcptList( mailimf_fields *fields ) { |
444 | clist *rcptList; | 446 | clist *rcptList; |
445 | mailimf_field *field; | 447 | mailimf_field *field; |
446 | 448 | ||
447 | rcptList = esmtp_address_list_new(); | 449 | rcptList = esmtp_address_list_new(); |
448 | 450 | ||
449 | field = getField( fields, MAILIMF_FIELD_TO ); | 451 | field = getField( fields, MAILIMF_FIELD_TO ); |
450 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) | 452 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) |
451 | && field->fld_data.fld_to->to_addr_list ) { | 453 | && field->fld_data.fld_to->to_addr_list ) { |
452 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); | 454 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); |
453 | } | 455 | } |
454 | 456 | ||
455 | field = getField( fields, MAILIMF_FIELD_CC ); | 457 | field = getField( fields, MAILIMF_FIELD_CC ); |
456 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) | 458 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) |
457 | && field->fld_data.fld_cc->cc_addr_list ) { | 459 | && field->fld_data.fld_cc->cc_addr_list ) { |
458 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); | 460 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); |
459 | } | 461 | } |
460 | 462 | ||
461 | field = getField( fields, MAILIMF_FIELD_BCC ); | 463 | field = getField( fields, MAILIMF_FIELD_BCC ); |
462 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) | 464 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) |
463 | && field->fld_data.fld_bcc->bcc_addr_list ) { | 465 | && field->fld_data.fld_bcc->bcc_addr_list ) { |
464 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); | 466 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); |
465 | } | 467 | } |
466 | 468 | ||
467 | return rcptList; | 469 | return rcptList; |
468 | } | 470 | } |
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp index fae4c99..3e4293b 100644 --- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp | |||
@@ -1,476 +1,478 @@ | |||
1 | #include "genericwrapper.h" | 1 | #include "genericwrapper.h" |
2 | #include <libetpan/libetpan.h> | 2 | #include <libetpan/libetpan.h> |
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | 4 | ||
5 | #include <opie2/odebug.h> | ||
6 | |||
5 | using namespace Opie::Core; | 7 | using namespace Opie::Core; |
6 | Genericwrapper::Genericwrapper() | 8 | Genericwrapper::Genericwrapper() |
7 | : AbstractMail() | 9 | : AbstractMail() |
8 | { | 10 | { |
9 | bodyCache.clear(); | 11 | bodyCache.clear(); |
10 | m_storage = 0; | 12 | m_storage = 0; |
11 | m_folder = 0; | 13 | m_folder = 0; |
12 | } | 14 | } |
13 | 15 | ||
14 | Genericwrapper::~Genericwrapper() | 16 | Genericwrapper::~Genericwrapper() |
15 | { | 17 | { |
16 | if (m_folder) { | 18 | if (m_folder) { |
17 | mailfolder_free(m_folder); | 19 | mailfolder_free(m_folder); |
18 | } | 20 | } |
19 | if (m_storage) { | 21 | if (m_storage) { |
20 | mailstorage_free(m_storage); | 22 | mailstorage_free(m_storage); |
21 | } | 23 | } |
22 | cleanMimeCache(); | 24 | cleanMimeCache(); |
23 | } | 25 | } |
24 | 26 | ||
25 | void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) | 27 | void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) |
26 | { | 28 | { |
27 | if (!mime) { | 29 | if (!mime) { |
28 | return; | 30 | return; |
29 | } | 31 | } |
30 | mailmime_field*field = 0; | 32 | mailmime_field*field = 0; |
31 | mailmime_single_fields fields; | 33 | mailmime_single_fields fields; |
32 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 34 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
33 | if (mime->mm_mime_fields != NULL) { | 35 | if (mime->mm_mime_fields != NULL) { |
34 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, | 36 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, |
35 | mime->mm_content_type); | 37 | mime->mm_content_type); |
36 | } | 38 | } |
37 | 39 | ||
38 | mailmime_content*type = fields.fld_content; | 40 | mailmime_content*type = fields.fld_content; |
39 | clistcell*current; | 41 | clistcell*current; |
40 | if (!type) { | 42 | if (!type) { |
41 | target->setType("text"); | 43 | target->setType("text"); |
42 | target->setSubtype("plain"); | 44 | target->setSubtype("plain"); |
43 | } else { | 45 | } else { |
44 | target->setSubtype(type->ct_subtype); | 46 | target->setSubtype(type->ct_subtype); |
45 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { | 47 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { |
46 | case MAILMIME_DISCRETE_TYPE_TEXT: | 48 | case MAILMIME_DISCRETE_TYPE_TEXT: |
47 | target->setType("text"); | 49 | target->setType("text"); |
48 | break; | 50 | break; |
49 | case MAILMIME_DISCRETE_TYPE_IMAGE: | 51 | case MAILMIME_DISCRETE_TYPE_IMAGE: |
50 | target->setType("image"); | 52 | target->setType("image"); |
51 | break; | 53 | break; |
52 | case MAILMIME_DISCRETE_TYPE_AUDIO: | 54 | case MAILMIME_DISCRETE_TYPE_AUDIO: |
53 | target->setType("audio"); | 55 | target->setType("audio"); |
54 | break; | 56 | break; |
55 | case MAILMIME_DISCRETE_TYPE_VIDEO: | 57 | case MAILMIME_DISCRETE_TYPE_VIDEO: |
56 | target->setType("video"); | 58 | target->setType("video"); |
57 | break; | 59 | break; |
58 | case MAILMIME_DISCRETE_TYPE_APPLICATION: | 60 | case MAILMIME_DISCRETE_TYPE_APPLICATION: |
59 | target->setType("application"); | 61 | target->setType("application"); |
60 | break; | 62 | break; |
61 | case MAILMIME_DISCRETE_TYPE_EXTENSION: | 63 | case MAILMIME_DISCRETE_TYPE_EXTENSION: |
62 | default: | 64 | default: |
63 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { | 65 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { |
64 | target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); | 66 | target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); |
65 | } | 67 | } |
66 | break; | 68 | break; |
67 | } | 69 | } |
68 | if (type->ct_parameters) { | 70 | if (type->ct_parameters) { |
69 | fillParameters(target,type->ct_parameters); | 71 | fillParameters(target,type->ct_parameters); |
70 | } | 72 | } |
71 | } | 73 | } |
72 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { | 74 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { |
73 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { | 75 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { |
74 | field = (mailmime_field*)current->data; | 76 | field = (mailmime_field*)current->data; |
75 | switch(field->fld_type) { | 77 | switch(field->fld_type) { |
76 | case MAILMIME_FIELD_TRANSFER_ENCODING: | 78 | case MAILMIME_FIELD_TRANSFER_ENCODING: |
77 | target->setEncoding(getencoding(field->fld_data.fld_encoding)); | 79 | target->setEncoding(getencoding(field->fld_data.fld_encoding)); |
78 | break; | 80 | break; |
79 | case MAILMIME_FIELD_ID: | 81 | case MAILMIME_FIELD_ID: |
80 | target->setIdentifier(field->fld_data.fld_id); | 82 | target->setIdentifier(field->fld_data.fld_id); |
81 | break; | 83 | break; |
82 | case MAILMIME_FIELD_DESCRIPTION: | 84 | case MAILMIME_FIELD_DESCRIPTION: |
83 | target->setDescription(field->fld_data.fld_description); | 85 | target->setDescription(field->fld_data.fld_description); |
84 | break; | 86 | break; |
85 | default: | 87 | default: |
86 | break; | 88 | break; |
87 | } | 89 | } |
88 | } | 90 | } |
89 | } | 91 | } |
90 | } | 92 | } |
91 | 93 | ||
92 | void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) | 94 | void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) |
93 | { | 95 | { |
94 | if (!parameters) {return;} | 96 | if (!parameters) {return;} |
95 | clistcell*current=0; | 97 | clistcell*current=0; |
96 | mailmime_parameter*param; | 98 | mailmime_parameter*param; |
97 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { | 99 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { |
98 | param = (mailmime_parameter*)current->data; | 100 | param = (mailmime_parameter*)current->data; |
99 | if (param) { | 101 | if (param) { |
100 | target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 102 | target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
101 | } | 103 | } |
102 | } | 104 | } |
103 | } | 105 | } |
104 | 106 | ||
105 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) | 107 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) |
106 | { | 108 | { |
107 | QString enc="7bit"; | 109 | QString enc="7bit"; |
108 | if (!aEnc) return enc; | 110 | if (!aEnc) return enc; |
109 | switch(aEnc->enc_type) { | 111 | switch(aEnc->enc_type) { |
110 | case MAILMIME_MECHANISM_7BIT: | 112 | case MAILMIME_MECHANISM_7BIT: |
111 | enc = "7bit"; | 113 | enc = "7bit"; |
112 | break; | 114 | break; |
113 | case MAILMIME_MECHANISM_8BIT: | 115 | case MAILMIME_MECHANISM_8BIT: |
114 | enc = "8bit"; | 116 | enc = "8bit"; |
115 | break; | 117 | break; |
116 | case MAILMIME_MECHANISM_BINARY: | 118 | case MAILMIME_MECHANISM_BINARY: |
117 | enc = "binary"; | 119 | enc = "binary"; |
118 | break; | 120 | break; |
119 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: | 121 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: |
120 | enc = "quoted-printable"; | 122 | enc = "quoted-printable"; |
121 | break; | 123 | break; |
122 | case MAILMIME_MECHANISM_BASE64: | 124 | case MAILMIME_MECHANISM_BASE64: |
123 | enc = "base64"; | 125 | enc = "base64"; |
124 | break; | 126 | break; |
125 | case MAILMIME_MECHANISM_TOKEN: | 127 | case MAILMIME_MECHANISM_TOKEN: |
126 | default: | 128 | default: |
127 | if (aEnc->enc_token) { | 129 | if (aEnc->enc_token) { |
128 | enc = QString(aEnc->enc_token); | 130 | enc = QString(aEnc->enc_token); |
129 | } | 131 | } |
130 | break; | 132 | break; |
131 | } | 133 | } |
132 | return enc; | 134 | return enc; |
133 | } | 135 | } |
134 | 136 | ||
135 | void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) | 137 | void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) |
136 | { | 138 | { |
137 | if (current_rec >= 10) { | 139 | if (current_rec >= 10) { |
138 | odebug << "too deep recursion!" << oendl; | 140 | odebug << "too deep recursion!" << oendl; |
139 | } | 141 | } |
140 | if (!message || !mime) { | 142 | if (!message || !mime) { |
141 | return; | 143 | return; |
142 | } | 144 | } |
143 | int r; | 145 | int r; |
144 | char*data = 0; | 146 | char*data = 0; |
145 | size_t len; | 147 | size_t len; |
146 | clistiter * cur = 0; | 148 | clistiter * cur = 0; |
147 | QString b; | 149 | QString b; |
148 | RecPartP part = new RecPart(); | 150 | RecPartP part = new RecPart(); |
149 | 151 | ||
150 | switch (mime->mm_type) { | 152 | switch (mime->mm_type) { |
151 | case MAILMIME_SINGLE: | 153 | case MAILMIME_SINGLE: |
152 | { | 154 | { |
153 | QValueList<int>countlist = recList; | 155 | QValueList<int>countlist = recList; |
154 | countlist.append(current_count); | 156 | countlist.append(current_count); |
155 | r = mailmessage_fetch_section(message,mime,&data,&len); | 157 | r = mailmessage_fetch_section(message,mime,&data,&len); |
156 | part->setSize(len); | 158 | part->setSize(len); |
157 | part->setPositionlist(countlist); | 159 | part->setPositionlist(countlist); |
158 | b = gen_attachment_id(); | 160 | b = gen_attachment_id(); |
159 | part->setIdentifier(b); | 161 | part->setIdentifier(b); |
160 | fillSingleBody(part,message,mime); | 162 | fillSingleBody(part,message,mime); |
161 | if (part->Type()=="text" && target->Bodytext().isNull()) { | 163 | if (part->Type()=="text" && target->Bodytext().isNull()) { |
162 | encodedString*rs = new encodedString(); | 164 | encodedString*rs = new encodedString(); |
163 | rs->setContent(data,len); | 165 | rs->setContent(data,len); |
164 | encodedString*res = decode_String(rs,part->Encoding()); | 166 | encodedString*res = decode_String(rs,part->Encoding()); |
165 | if (countlist.count()>2) { | 167 | if (countlist.count()>2) { |
166 | bodyCache[b]=rs; | 168 | bodyCache[b]=rs; |
167 | target->addPart(part); | 169 | target->addPart(part); |
168 | } else { | 170 | } else { |
169 | delete rs; | 171 | delete rs; |
170 | } | 172 | } |
171 | b = QString(res->Content()); | 173 | b = QString(res->Content()); |
172 | delete res; | 174 | delete res; |
173 | target->setBodytext(b); | 175 | target->setBodytext(b); |
174 | target->setDescription(part); | 176 | target->setDescription(part); |
175 | } else { | 177 | } else { |
176 | bodyCache[b]=new encodedString(data,len); | 178 | bodyCache[b]=new encodedString(data,len); |
177 | target->addPart(part); | 179 | target->addPart(part); |
178 | } | 180 | } |
179 | } | 181 | } |
180 | break; | 182 | break; |
181 | case MAILMIME_MULTIPLE: | 183 | case MAILMIME_MULTIPLE: |
182 | { | 184 | { |
183 | unsigned int ccount = 1; | 185 | unsigned int ccount = 1; |
184 | mailmime*cbody=0; | 186 | mailmime*cbody=0; |
185 | QValueList<int>countlist = recList; | 187 | QValueList<int>countlist = recList; |
186 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { | 188 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { |
187 | cbody = (mailmime*)clist_content(cur); | 189 | cbody = (mailmime*)clist_content(cur); |
188 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | 190 | if (cbody->mm_type==MAILMIME_MULTIPLE) { |
189 | RecPartP targetPart = new RecPart(); | 191 | RecPartP targetPart = new RecPart(); |
190 | targetPart->setType("multipart"); | 192 | targetPart->setType("multipart"); |
191 | countlist.append(current_count); | 193 | countlist.append(current_count); |
192 | targetPart->setPositionlist(countlist); | 194 | targetPart->setPositionlist(countlist); |
193 | target->addPart(targetPart); | 195 | target->addPart(targetPart); |
194 | } | 196 | } |
195 | traverseBody(target,message, cbody,countlist,current_rec+1,ccount); | 197 | traverseBody(target,message, cbody,countlist,current_rec+1,ccount); |
196 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | 198 | if (cbody->mm_type==MAILMIME_MULTIPLE) { |
197 | countlist = recList; | 199 | countlist = recList; |
198 | } | 200 | } |
199 | ++ccount; | 201 | ++ccount; |
200 | } | 202 | } |
201 | } | 203 | } |
202 | break; | 204 | break; |
203 | case MAILMIME_MESSAGE: | 205 | case MAILMIME_MESSAGE: |
204 | { | 206 | { |
205 | QValueList<int>countlist = recList; | 207 | QValueList<int>countlist = recList; |
206 | countlist.append(current_count); | 208 | countlist.append(current_count); |
207 | /* the own header is always at recursion 0 - we don't need that */ | 209 | /* the own header is always at recursion 0 - we don't need that */ |
208 | if (current_rec > 0) { | 210 | if (current_rec > 0) { |
209 | part->setPositionlist(countlist); | 211 | part->setPositionlist(countlist); |
210 | r = mailmessage_fetch_section(message,mime,&data,&len); | 212 | r = mailmessage_fetch_section(message,mime,&data,&len); |
211 | part->setSize(len); | 213 | part->setSize(len); |
212 | part->setPositionlist(countlist); | 214 | part->setPositionlist(countlist); |
213 | b = gen_attachment_id(); | 215 | b = gen_attachment_id(); |
214 | part->setIdentifier(b); | 216 | part->setIdentifier(b); |
215 | part->setType("message"); | 217 | part->setType("message"); |
216 | part->setSubtype("rfc822"); | 218 | part->setSubtype("rfc822"); |
217 | bodyCache[b]=new encodedString(data,len); | 219 | bodyCache[b]=new encodedString(data,len); |
218 | target->addPart(part); | 220 | target->addPart(part); |
219 | } | 221 | } |
220 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { | 222 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { |
221 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); | 223 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); |
222 | } | 224 | } |
223 | } | 225 | } |
224 | break; | 226 | break; |
225 | } | 227 | } |
226 | } | 228 | } |
227 | 229 | ||
228 | RecBodyP Genericwrapper::parseMail( mailmessage * msg ) | 230 | RecBodyP Genericwrapper::parseMail( mailmessage * msg ) |
229 | { | 231 | { |
230 | int err = MAILIMF_NO_ERROR; | 232 | int err = MAILIMF_NO_ERROR; |
231 | mailmime_single_fields fields; | 233 | mailmime_single_fields fields; |
232 | /* is bound to msg and will be freed there */ | 234 | /* is bound to msg and will be freed there */ |
233 | mailmime * mime=0; | 235 | mailmime * mime=0; |
234 | RecBodyP body = new RecBody(); | 236 | RecBodyP body = new RecBody(); |
235 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 237 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
236 | err = mailmessage_get_bodystructure(msg,&mime); | 238 | err = mailmessage_get_bodystructure(msg,&mime); |
237 | QValueList<int>recList; | 239 | QValueList<int>recList; |
238 | traverseBody(body,msg,mime,recList); | 240 | traverseBody(body,msg,mime,recList); |
239 | return body; | 241 | return body; |
240 | } | 242 | } |
241 | 243 | ||
242 | QString Genericwrapper::parseDateTime( mailimf_date_time *date ) | 244 | QString Genericwrapper::parseDateTime( mailimf_date_time *date ) |
243 | { | 245 | { |
244 | char tmp[23]; | 246 | char tmp[23]; |
245 | 247 | ||
246 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | 248 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", |
247 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | 249 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); |
248 | 250 | ||
249 | return QString( tmp ); | 251 | return QString( tmp ); |
250 | } | 252 | } |
251 | 253 | ||
252 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) | 254 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) |
253 | { | 255 | { |
254 | QString result( "" ); | 256 | QString result( "" ); |
255 | 257 | ||
256 | bool first = true; | 258 | bool first = true; |
257 | if (list == 0) return result; | 259 | if (list == 0) return result; |
258 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | 260 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { |
259 | mailimf_address *addr = (mailimf_address *) current->data; | 261 | mailimf_address *addr = (mailimf_address *) current->data; |
260 | 262 | ||
261 | if ( !first ) { | 263 | if ( !first ) { |
262 | result.append( "," ); | 264 | result.append( "," ); |
263 | } else { | 265 | } else { |
264 | first = false; | 266 | first = false; |
265 | } | 267 | } |
266 | 268 | ||
267 | switch ( addr->ad_type ) { | 269 | switch ( addr->ad_type ) { |
268 | case MAILIMF_ADDRESS_MAILBOX: | 270 | case MAILIMF_ADDRESS_MAILBOX: |
269 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | 271 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); |
270 | break; | 272 | break; |
271 | case MAILIMF_ADDRESS_GROUP: | 273 | case MAILIMF_ADDRESS_GROUP: |
272 | result.append( parseGroup( addr->ad_data.ad_group ) ); | 274 | result.append( parseGroup( addr->ad_data.ad_group ) ); |
273 | break; | 275 | break; |
274 | default: | 276 | default: |
275 | odebug << "Generic: unkown mailimf address type" << oendl; | 277 | odebug << "Generic: unkown mailimf address type" << oendl; |
276 | break; | 278 | break; |
277 | } | 279 | } |
278 | } | 280 | } |
279 | 281 | ||
280 | return result; | 282 | return result; |
281 | } | 283 | } |
282 | 284 | ||
283 | QString Genericwrapper::parseGroup( mailimf_group *group ) | 285 | QString Genericwrapper::parseGroup( mailimf_group *group ) |
284 | { | 286 | { |
285 | QString result( "" ); | 287 | QString result( "" ); |
286 | 288 | ||
287 | result.append( group->grp_display_name ); | 289 | result.append( group->grp_display_name ); |
288 | result.append( ": " ); | 290 | result.append( ": " ); |
289 | 291 | ||
290 | if ( group->grp_mb_list != NULL ) { | 292 | if ( group->grp_mb_list != NULL ) { |
291 | result.append( parseMailboxList( group->grp_mb_list ) ); | 293 | result.append( parseMailboxList( group->grp_mb_list ) ); |
292 | } | 294 | } |
293 | 295 | ||
294 | result.append( ";" ); | 296 | result.append( ";" ); |
295 | 297 | ||
296 | return result; | 298 | return result; |
297 | } | 299 | } |
298 | 300 | ||
299 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) | 301 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) |
300 | { | 302 | { |
301 | QString result( "" ); | 303 | QString result( "" ); |
302 | 304 | ||
303 | if ( box->mb_display_name == NULL ) { | 305 | if ( box->mb_display_name == NULL ) { |
304 | result.append( box->mb_addr_spec ); | 306 | result.append( box->mb_addr_spec ); |
305 | } else { | 307 | } else { |
306 | result.append( convert_String(box->mb_display_name).latin1() ); | 308 | result.append( convert_String(box->mb_display_name).latin1() ); |
307 | result.append( " <" ); | 309 | result.append( " <" ); |
308 | result.append( box->mb_addr_spec ); | 310 | result.append( box->mb_addr_spec ); |
309 | result.append( ">" ); | 311 | result.append( ">" ); |
310 | } | 312 | } |
311 | 313 | ||
312 | return result; | 314 | return result; |
313 | } | 315 | } |
314 | 316 | ||
315 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) | 317 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) |
316 | { | 318 | { |
317 | QString result( "" ); | 319 | QString result( "" ); |
318 | 320 | ||
319 | bool first = true; | 321 | bool first = true; |
320 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { | 322 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { |
321 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | 323 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; |
322 | 324 | ||
323 | if ( !first ) { | 325 | if ( !first ) { |
324 | result.append( "," ); | 326 | result.append( "," ); |
325 | } else { | 327 | } else { |
326 | first = false; | 328 | first = false; |
327 | } | 329 | } |
328 | 330 | ||
329 | result.append( parseMailbox( box ) ); | 331 | result.append( parseMailbox( box ) ); |
330 | } | 332 | } |
331 | 333 | ||
332 | return result; | 334 | return result; |
333 | } | 335 | } |
334 | 336 | ||
335 | encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) | 337 | encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) |
336 | { | 338 | { |
337 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); | 339 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); |
338 | if (it==bodyCache.end()) return new encodedString(); | 340 | if (it==bodyCache.end()) return new encodedString(); |
339 | encodedString*t = decode_String(it.data(),part->Encoding()); | 341 | encodedString*t = decode_String(it.data(),part->Encoding()); |
340 | return t; | 342 | return t; |
341 | } | 343 | } |
342 | 344 | ||
343 | encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) | 345 | encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) |
344 | { | 346 | { |
345 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); | 347 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); |
346 | if (it==bodyCache.end()) return new encodedString(); | 348 | if (it==bodyCache.end()) return new encodedString(); |
347 | encodedString*t = it.data(); | 349 | encodedString*t = it.data(); |
348 | return t; | 350 | return t; |
349 | } | 351 | } |
350 | 352 | ||
351 | QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) | 353 | QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) |
352 | { | 354 | { |
353 | encodedString*t = fetchDecodedPart(mail,part); | 355 | encodedString*t = fetchDecodedPart(mail,part); |
354 | QString text=t->Content(); | 356 | QString text=t->Content(); |
355 | delete t; | 357 | delete t; |
356 | return text; | 358 | return text; |
357 | } | 359 | } |
358 | 360 | ||
359 | void Genericwrapper::cleanMimeCache() | 361 | void Genericwrapper::cleanMimeCache() |
360 | { | 362 | { |
361 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); | 363 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); |
362 | for (;it!=bodyCache.end();++it) { | 364 | for (;it!=bodyCache.end();++it) { |
363 | encodedString*t = it.data(); | 365 | encodedString*t = it.data(); |
364 | //it.setValue(0); | 366 | //it.setValue(0); |
365 | if (t) delete t; | 367 | if (t) delete t; |
366 | } | 368 | } |
367 | bodyCache.clear(); | 369 | bodyCache.clear(); |
368 | odebug << "Genericwrapper: cache cleaned" << oendl; | 370 | odebug << "Genericwrapper: cache cleaned" << oendl; |
369 | } | 371 | } |
370 | 372 | ||
371 | QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) | 373 | QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) |
372 | { | 374 | { |
373 | QStringList res; | 375 | QStringList res; |
374 | if (!in_replies || !in_replies->mid_list) return res; | 376 | if (!in_replies || !in_replies->mid_list) return res; |
375 | clistiter * current = 0; | 377 | clistiter * current = 0; |
376 | for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { | 378 | for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { |
377 | QString h((char*)current->data); | 379 | QString h((char*)current->data); |
378 | while (h.length()>0 && h[0]=='<') { | 380 | while (h.length()>0 && h[0]=='<') { |
379 | h.remove(0,1); | 381 | h.remove(0,1); |
380 | } | 382 | } |
381 | while (h.length()>0 && h[h.length()-1]=='>') { | 383 | while (h.length()>0 && h[h.length()-1]=='>') { |
382 | h.remove(h.length()-1,1); | 384 | h.remove(h.length()-1,1); |
383 | } | 385 | } |
384 | if (h.length()>0) { | 386 | if (h.length()>0) { |
385 | res.append(h); | 387 | res.append(h); |
386 | } | 388 | } |
387 | } | 389 | } |
388 | return res; | 390 | return res; |
389 | } | 391 | } |
390 | 392 | ||
391 | void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to) | 393 | void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to) |
392 | { | 394 | { |
393 | int r; | 395 | int r; |
394 | mailmessage_list * env_list = 0; | 396 | mailmessage_list * env_list = 0; |
395 | r = mailsession_get_messages_list(session,&env_list); | 397 | r = mailsession_get_messages_list(session,&env_list); |
396 | if (r != MAIL_NO_ERROR) { | 398 | if (r != MAIL_NO_ERROR) { |
397 | odebug << "Error message list" << oendl; | 399 | odebug << "Error message list" << oendl; |
398 | return; | 400 | return; |
399 | } | 401 | } |
400 | r = mailsession_get_envelopes_list(session, env_list); | 402 | r = mailsession_get_envelopes_list(session, env_list); |
401 | if (r != MAIL_NO_ERROR) { | 403 | if (r != MAIL_NO_ERROR) { |
402 | odebug << "Error filling message list" << oendl; | 404 | odebug << "Error filling message list" << oendl; |
403 | if (env_list) { | 405 | if (env_list) { |
404 | mailmessage_list_free(env_list); | 406 | mailmessage_list_free(env_list); |
405 | } | 407 | } |
406 | return; | 408 | return; |
407 | } | 409 | } |
408 | mailimf_references * refs = 0; | 410 | mailimf_references * refs = 0; |
409 | mailimf_in_reply_to * in_replies = 0; | 411 | mailimf_in_reply_to * in_replies = 0; |
410 | uint32_t i = 0; | 412 | uint32_t i = 0; |
411 | for(; i < carray_count(env_list->msg_tab) ; ++i) { | 413 | for(; i < carray_count(env_list->msg_tab) ; ++i) { |
412 | mailmessage * msg; | 414 | mailmessage * msg; |
413 | QBitArray mFlags(7); | 415 | QBitArray mFlags(7); |
414 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | 416 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); |
415 | if (msg->msg_fields == NULL) { | 417 | if (msg->msg_fields == NULL) { |
416 | //odebug << "could not fetch envelope of message " << i << "" << oendl; | 418 | //odebug << "could not fetch envelope of message " << i << "" << oendl; |
417 | continue; | 419 | continue; |
418 | } | 420 | } |
419 | RecMailP mail = new RecMail(); | 421 | RecMailP mail = new RecMail(); |
420 | mail->setWrapper(this); | 422 | mail->setWrapper(this); |
421 | mail_flags * flag_result = 0; | 423 | mail_flags * flag_result = 0; |
422 | r = mailmessage_get_flags(msg,&flag_result); | 424 | r = mailmessage_get_flags(msg,&flag_result); |
423 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | 425 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { |
424 | mFlags.setBit(FLAG_SEEN); | 426 | mFlags.setBit(FLAG_SEEN); |
425 | } | 427 | } |
426 | mailimf_single_fields single_fields; | 428 | mailimf_single_fields single_fields; |
427 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | 429 | mailimf_single_fields_init(&single_fields, msg->msg_fields); |
428 | mail->setMsgsize(msg->msg_size); | 430 | mail->setMsgsize(msg->msg_size); |
429 | mail->setFlags(mFlags); | 431 | mail->setFlags(mFlags); |
430 | mail->setMbox(mailbox); | 432 | mail->setMbox(mailbox); |
431 | mail->setNumber(msg->msg_index); | 433 | mail->setNumber(msg->msg_index); |
432 | if (single_fields.fld_subject) | 434 | if (single_fields.fld_subject) |
433 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | 435 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); |
434 | if (single_fields.fld_from) | 436 | if (single_fields.fld_from) |
435 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); | 437 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); |
436 | if (!mbox_as_to) { | 438 | if (!mbox_as_to) { |
437 | if (single_fields.fld_to) | 439 | if (single_fields.fld_to) |
438 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); | 440 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); |
439 | } else { | 441 | } else { |
440 | mail->setTo(mailbox); | 442 | mail->setTo(mailbox); |
441 | } | 443 | } |
442 | if (single_fields.fld_cc) | 444 | if (single_fields.fld_cc) |
443 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); | 445 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); |
444 | if (single_fields.fld_bcc) | 446 | if (single_fields.fld_bcc) |
445 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); | 447 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); |
446 | if (single_fields.fld_orig_date) | 448 | if (single_fields.fld_orig_date) |
447 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); | 449 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); |
448 | // crashes when accessing pop3 account? | 450 | // crashes when accessing pop3 account? |
449 | if (single_fields.fld_message_id->mid_value) { | 451 | if (single_fields.fld_message_id->mid_value) { |
450 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | 452 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); |
451 | odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; | 453 | odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; |
452 | } | 454 | } |
453 | 455 | ||
454 | if (single_fields.fld_reply_to) { | 456 | if (single_fields.fld_reply_to) { |
455 | QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); | 457 | QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); |
456 | if (t.count()>0) { | 458 | if (t.count()>0) { |
457 | mail->setReplyto(t[0]); | 459 | mail->setReplyto(t[0]); |
458 | } | 460 | } |
459 | } | 461 | } |
460 | #if 0 | 462 | #if 0 |
461 | refs = single_fields.fld_references; | 463 | refs = single_fields.fld_references; |
462 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 464 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
463 | char * text = (char*)refs->mid_list->first->data; | 465 | char * text = (char*)refs->mid_list->first->data; |
464 | mail->setReplyto(QString(text)); | 466 | mail->setReplyto(QString(text)); |
465 | } | 467 | } |
466 | #endif | 468 | #endif |
467 | if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && | 469 | if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && |
468 | clist_count(single_fields.fld_in_reply_to->mid_list)) { | 470 | clist_count(single_fields.fld_in_reply_to->mid_list)) { |
469 | mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); | 471 | mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); |
470 | } | 472 | } |
471 | target.append(mail); | 473 | target.append(mail); |
472 | } | 474 | } |
473 | if (env_list) { | 475 | if (env_list) { |
474 | mailmessage_list_free(env_list); | 476 | mailmessage_list_free(env_list); |
475 | } | 477 | } |
476 | } | 478 | } |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 35468fe..9b7c0e0 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,1187 +1,1188 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <libetpan/libetpan.h> | 2 | #include <libetpan/libetpan.h> |
3 | #include <qpe/global.h> | 3 | #include <qpe/global.h> |
4 | #include <opie2/oapplication.h> | 4 | #include <opie2/oapplication.h> |
5 | #include <opie2/odebug.h> | ||
5 | 6 | ||
6 | #include "imapwrapper.h" | 7 | #include "imapwrapper.h" |
7 | #include "mailtypes.h" | 8 | #include "mailtypes.h" |
8 | #include "logindialog.h" | 9 | #include "logindialog.h" |
9 | 10 | ||
10 | using namespace Opie::Core; | 11 | using namespace Opie::Core; |
11 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 12 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
12 | : AbstractMail() | 13 | : AbstractMail() |
13 | { | 14 | { |
14 | account = a; | 15 | account = a; |
15 | m_imap = 0; | 16 | m_imap = 0; |
16 | m_Lastmbox = ""; | 17 | m_Lastmbox = ""; |
17 | } | 18 | } |
18 | 19 | ||
19 | IMAPwrapper::~IMAPwrapper() | 20 | IMAPwrapper::~IMAPwrapper() |
20 | { | 21 | { |
21 | logout(); | 22 | logout(); |
22 | } | 23 | } |
23 | 24 | ||
24 | /* to avoid to often select statements in loops etc. | 25 | /* to avoid to often select statements in loops etc. |
25 | we trust that we are logged in and connection is established!*/ | 26 | we trust that we are logged in and connection is established!*/ |
26 | int IMAPwrapper::selectMbox(const QString&mbox) | 27 | int IMAPwrapper::selectMbox(const QString&mbox) |
27 | { | 28 | { |
28 | if (mbox == m_Lastmbox) { | 29 | if (mbox == m_Lastmbox) { |
29 | return MAILIMAP_NO_ERROR; | 30 | return MAILIMAP_NO_ERROR; |
30 | } | 31 | } |
31 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); | 32 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); |
32 | if ( err != MAILIMAP_NO_ERROR ) { | 33 | if ( err != MAILIMAP_NO_ERROR ) { |
33 | odebug << "error selecting mailbox: " << m_imap->imap_response << "" << oendl; | 34 | odebug << "error selecting mailbox: " << m_imap->imap_response << "" << oendl; |
34 | m_Lastmbox = ""; | 35 | m_Lastmbox = ""; |
35 | return err; | 36 | return err; |
36 | } | 37 | } |
37 | m_Lastmbox = mbox; | 38 | m_Lastmbox = mbox; |
38 | return err; | 39 | return err; |
39 | } | 40 | } |
40 | 41 | ||
41 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 42 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
42 | { | 43 | { |
43 | qApp->processEvents(); | 44 | qApp->processEvents(); |
44 | odebug << "IMAP: " << current << " of " << maximum << "" << oendl; | 45 | odebug << "IMAP: " << current << " of " << maximum << "" << oendl; |
45 | } | 46 | } |
46 | 47 | ||
47 | bool IMAPwrapper::start_tls(bool force_tls) | 48 | bool IMAPwrapper::start_tls(bool force_tls) |
48 | { | 49 | { |
49 | int err; | 50 | int err; |
50 | bool try_tls; | 51 | bool try_tls; |
51 | mailimap_capability_data * cap_data = 0; | 52 | mailimap_capability_data * cap_data = 0; |
52 | 53 | ||
53 | err = mailimap_capability(m_imap,&cap_data); | 54 | err = mailimap_capability(m_imap,&cap_data); |
54 | if (err != MAILIMAP_NO_ERROR) { | 55 | if (err != MAILIMAP_NO_ERROR) { |
55 | Global::statusMessage("error getting capabilities!"); | 56 | Global::statusMessage("error getting capabilities!"); |
56 | odebug << "error getting capabilities!" << oendl; | 57 | odebug << "error getting capabilities!" << oendl; |
57 | return false; | 58 | return false; |
58 | } | 59 | } |
59 | clistiter * cur; | 60 | clistiter * cur; |
60 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { | 61 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { |
61 | struct mailimap_capability * cap; | 62 | struct mailimap_capability * cap; |
62 | cap = (struct mailimap_capability *)clist_content(cur); | 63 | cap = (struct mailimap_capability *)clist_content(cur); |
63 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { | 64 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { |
64 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { | 65 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { |
65 | try_tls = true; | 66 | try_tls = true; |
66 | break; | 67 | break; |
67 | } | 68 | } |
68 | } | 69 | } |
69 | } | 70 | } |
70 | if (cap_data) { | 71 | if (cap_data) { |
71 | mailimap_capability_data_free(cap_data); | 72 | mailimap_capability_data_free(cap_data); |
72 | } | 73 | } |
73 | if (try_tls) { | 74 | if (try_tls) { |
74 | err = mailimap_starttls(m_imap); | 75 | err = mailimap_starttls(m_imap); |
75 | if (err != MAILIMAP_NO_ERROR && force_tls) { | 76 | if (err != MAILIMAP_NO_ERROR && force_tls) { |
76 | Global::statusMessage(tr("Server has no TLS support!")); | 77 | Global::statusMessage(tr("Server has no TLS support!")); |
77 | odebug << "Server has no TLS support!" << oendl; | 78 | odebug << "Server has no TLS support!" << oendl; |
78 | try_tls = false; | 79 | try_tls = false; |
79 | } else { | 80 | } else { |
80 | mailstream_low * low; | 81 | mailstream_low * low; |
81 | mailstream_low * new_low; | 82 | mailstream_low * new_low; |
82 | low = mailstream_get_low(m_imap->imap_stream); | 83 | low = mailstream_get_low(m_imap->imap_stream); |
83 | if (!low) { | 84 | if (!low) { |
84 | try_tls = false; | 85 | try_tls = false; |
85 | } else { | 86 | } else { |
86 | int fd = mailstream_low_get_fd(low); | 87 | int fd = mailstream_low_get_fd(low); |
87 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 88 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
88 | mailstream_low_free(low); | 89 | mailstream_low_free(low); |
89 | mailstream_set_low(m_imap->imap_stream, new_low); | 90 | mailstream_set_low(m_imap->imap_stream, new_low); |
90 | } else { | 91 | } else { |
91 | try_tls = false; | 92 | try_tls = false; |
92 | } | 93 | } |
93 | } | 94 | } |
94 | } | 95 | } |
95 | } | 96 | } |
96 | return try_tls; | 97 | return try_tls; |
97 | } | 98 | } |
98 | 99 | ||
99 | void IMAPwrapper::login() | 100 | void IMAPwrapper::login() |
100 | { | 101 | { |
101 | const char *server, *user, *pass; | 102 | const char *server, *user, *pass; |
102 | uint16_t port; | 103 | uint16_t port; |
103 | int err = MAILIMAP_NO_ERROR; | 104 | int err = MAILIMAP_NO_ERROR; |
104 | 105 | ||
105 | if (account->getOffline()) return; | 106 | if (account->getOffline()) return; |
106 | /* we are connected this moment */ | 107 | /* we are connected this moment */ |
107 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 108 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
108 | if (m_imap) { | 109 | if (m_imap) { |
109 | err = mailimap_noop(m_imap); | 110 | err = mailimap_noop(m_imap); |
110 | if (err!=MAILIMAP_NO_ERROR) { | 111 | if (err!=MAILIMAP_NO_ERROR) { |
111 | logout(); | 112 | logout(); |
112 | } else { | 113 | } else { |
113 | mailstream_flush(m_imap->imap_stream); | 114 | mailstream_flush(m_imap->imap_stream); |
114 | return; | 115 | return; |
115 | } | 116 | } |
116 | } | 117 | } |
117 | server = account->getServer().latin1(); | 118 | server = account->getServer().latin1(); |
118 | port = account->getPort().toUInt(); | 119 | port = account->getPort().toUInt(); |
119 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 120 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
120 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 121 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
121 | login.show(); | 122 | login.show(); |
122 | if ( QDialog::Accepted == login.exec() ) { | 123 | if ( QDialog::Accepted == login.exec() ) { |
123 | // ok | 124 | // ok |
124 | user = login.getUser().latin1(); | 125 | user = login.getUser().latin1(); |
125 | pass = login.getPassword().latin1(); | 126 | pass = login.getPassword().latin1(); |
126 | } else { | 127 | } else { |
127 | // cancel | 128 | // cancel |
128 | odebug << "IMAP: Login canceled" << oendl; | 129 | odebug << "IMAP: Login canceled" << oendl; |
129 | return; | 130 | return; |
130 | } | 131 | } |
131 | } else { | 132 | } else { |
132 | user = account->getUser().latin1(); | 133 | user = account->getUser().latin1(); |
133 | pass = account->getPassword().latin1(); | 134 | pass = account->getPassword().latin1(); |
134 | } | 135 | } |
135 | 136 | ||
136 | m_imap = mailimap_new( 20, &imap_progress ); | 137 | m_imap = mailimap_new( 20, &imap_progress ); |
137 | 138 | ||
138 | /* connect */ | 139 | /* connect */ |
139 | bool ssl = false; | 140 | bool ssl = false; |
140 | bool try_tls = false; | 141 | bool try_tls = false; |
141 | bool force_tls = false; | 142 | bool force_tls = false; |
142 | 143 | ||
143 | if ( account->ConnectionType() == 2 ) { | 144 | if ( account->ConnectionType() == 2 ) { |
144 | ssl = true; | 145 | ssl = true; |
145 | } | 146 | } |
146 | if (account->ConnectionType()==1) { | 147 | if (account->ConnectionType()==1) { |
147 | force_tls = true; | 148 | force_tls = true; |
148 | } | 149 | } |
149 | 150 | ||
150 | if ( ssl ) { | 151 | if ( ssl ) { |
151 | odebug << "using ssl" << oendl; | 152 | odebug << "using ssl" << oendl; |
152 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 153 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
153 | } else { | 154 | } else { |
154 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 155 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
155 | } | 156 | } |
156 | 157 | ||
157 | if ( err != MAILIMAP_NO_ERROR && | 158 | if ( err != MAILIMAP_NO_ERROR && |
158 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 159 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
159 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 160 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
160 | QString failure = ""; | 161 | QString failure = ""; |
161 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 162 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
162 | failure="Connection refused"; | 163 | failure="Connection refused"; |
163 | } else { | 164 | } else { |
164 | failure="Unknown failure"; | 165 | failure="Unknown failure"; |
165 | } | 166 | } |
166 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); | 167 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); |
167 | mailimap_free( m_imap ); | 168 | mailimap_free( m_imap ); |
168 | m_imap = 0; | 169 | m_imap = 0; |
169 | return; | 170 | return; |
170 | } | 171 | } |
171 | 172 | ||
172 | if (!ssl) { | 173 | if (!ssl) { |
173 | try_tls = start_tls(force_tls); | 174 | try_tls = start_tls(force_tls); |
174 | } | 175 | } |
175 | 176 | ||
176 | bool ok = true; | 177 | bool ok = true; |
177 | if (force_tls && !try_tls) { | 178 | if (force_tls && !try_tls) { |
178 | Global::statusMessage(tr("Server has no TLS support!")); | 179 | Global::statusMessage(tr("Server has no TLS support!")); |
179 | odebug << "Server has no TLS support!" << oendl; | 180 | odebug << "Server has no TLS support!" << oendl; |
180 | ok = false; | 181 | ok = false; |
181 | } | 182 | } |
182 | 183 | ||
183 | 184 | ||
184 | /* login */ | 185 | /* login */ |
185 | 186 | ||
186 | if (ok) { | 187 | if (ok) { |
187 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 188 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
188 | if ( err != MAILIMAP_NO_ERROR ) { | 189 | if ( err != MAILIMAP_NO_ERROR ) { |
189 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); | 190 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); |
190 | ok = false; | 191 | ok = false; |
191 | } | 192 | } |
192 | } | 193 | } |
193 | if (!ok) { | 194 | if (!ok) { |
194 | err = mailimap_close( m_imap ); | 195 | err = mailimap_close( m_imap ); |
195 | mailimap_free( m_imap ); | 196 | mailimap_free( m_imap ); |
196 | m_imap = 0; | 197 | m_imap = 0; |
197 | } | 198 | } |
198 | } | 199 | } |
199 | 200 | ||
200 | void IMAPwrapper::logout() | 201 | void IMAPwrapper::logout() |
201 | { | 202 | { |
202 | int err = MAILIMAP_NO_ERROR; | 203 | int err = MAILIMAP_NO_ERROR; |
203 | if (!m_imap) return; | 204 | if (!m_imap) return; |
204 | err = mailimap_logout( m_imap ); | 205 | err = mailimap_logout( m_imap ); |
205 | err = mailimap_close( m_imap ); | 206 | err = mailimap_close( m_imap ); |
206 | mailimap_free( m_imap ); | 207 | mailimap_free( m_imap ); |
207 | m_imap = 0; | 208 | m_imap = 0; |
208 | m_Lastmbox = ""; | 209 | m_Lastmbox = ""; |
209 | } | 210 | } |
210 | 211 | ||
211 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) | 212 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) |
212 | { | 213 | { |
213 | int err = MAILIMAP_NO_ERROR; | 214 | int err = MAILIMAP_NO_ERROR; |
214 | clist *result = 0; | 215 | clist *result = 0; |
215 | clistcell *current; | 216 | clistcell *current; |
216 | mailimap_fetch_type *fetchType = 0; | 217 | mailimap_fetch_type *fetchType = 0; |
217 | mailimap_set *set = 0; | 218 | mailimap_set *set = 0; |
218 | 219 | ||
219 | login(); | 220 | login(); |
220 | if (!m_imap) { | 221 | if (!m_imap) { |
221 | return; | 222 | return; |
222 | } | 223 | } |
223 | /* select mailbox READONLY for operations */ | 224 | /* select mailbox READONLY for operations */ |
224 | err = selectMbox(mailbox); | 225 | err = selectMbox(mailbox); |
225 | if ( err != MAILIMAP_NO_ERROR ) { | 226 | if ( err != MAILIMAP_NO_ERROR ) { |
226 | return; | 227 | return; |
227 | } | 228 | } |
228 | 229 | ||
229 | int last = m_imap->imap_selection_info->sel_exists; | 230 | int last = m_imap->imap_selection_info->sel_exists; |
230 | 231 | ||
231 | if (last == 0) { | 232 | if (last == 0) { |
232 | Global::statusMessage(tr("Mailbox has no mails")); | 233 | Global::statusMessage(tr("Mailbox has no mails")); |
233 | return; | 234 | return; |
234 | } else { | 235 | } else { |
235 | } | 236 | } |
236 | 237 | ||
237 | /* the range has to start at 1!!! not with 0!!!! */ | 238 | /* the range has to start at 1!!! not with 0!!!! */ |
238 | set = mailimap_set_new_interval( 1, last ); | 239 | set = mailimap_set_new_interval( 1, last ); |
239 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 240 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
240 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 241 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
241 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 242 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
242 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 243 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
243 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 244 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
244 | 245 | ||
245 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 246 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
246 | mailimap_set_free( set ); | 247 | mailimap_set_free( set ); |
247 | mailimap_fetch_type_free( fetchType ); | 248 | mailimap_fetch_type_free( fetchType ); |
248 | 249 | ||
249 | QString date,subject,from; | 250 | QString date,subject,from; |
250 | 251 | ||
251 | if ( err == MAILIMAP_NO_ERROR ) { | 252 | if ( err == MAILIMAP_NO_ERROR ) { |
252 | mailimap_msg_att * msg_att; | 253 | mailimap_msg_att * msg_att; |
253 | int i = 0; | 254 | int i = 0; |
254 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 255 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
255 | ++i; | 256 | ++i; |
256 | msg_att = (mailimap_msg_att*)current->data; | 257 | msg_att = (mailimap_msg_att*)current->data; |
257 | RecMail*m = parse_list_result(msg_att); | 258 | RecMail*m = parse_list_result(msg_att); |
258 | if (m) { | 259 | if (m) { |
259 | m->setNumber(i); | 260 | m->setNumber(i); |
260 | m->setMbox(mailbox); | 261 | m->setMbox(mailbox); |
261 | m->setWrapper(this); | 262 | m->setWrapper(this); |
262 | target.append(m); | 263 | target.append(m); |
263 | } | 264 | } |
264 | } | 265 | } |
265 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); | 266 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); |
266 | } else { | 267 | } else { |
267 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); | 268 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); |
268 | } | 269 | } |
269 | if (result) mailimap_fetch_list_free(result); | 270 | if (result) mailimap_fetch_list_free(result); |
270 | } | 271 | } |
271 | 272 | ||
272 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() | 273 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() |
273 | { | 274 | { |
274 | const char *path, *mask; | 275 | const char *path, *mask; |
275 | int err = MAILIMAP_NO_ERROR; | 276 | int err = MAILIMAP_NO_ERROR; |
276 | clist *result = 0; | 277 | clist *result = 0; |
277 | clistcell *current = 0; | 278 | clistcell *current = 0; |
278 | clistcell*cur_flag = 0; | 279 | clistcell*cur_flag = 0; |
279 | mailimap_mbx_list_flags*bflags = 0; | 280 | mailimap_mbx_list_flags*bflags = 0; |
280 | 281 | ||
281 | QValueList<FolderP>* folders = new QValueList<FolderP>(); | 282 | QValueList<FolderP>* folders = new QValueList<FolderP>(); |
282 | login(); | 283 | login(); |
283 | if (!m_imap) { | 284 | if (!m_imap) { |
284 | return folders; | 285 | return folders; |
285 | } | 286 | } |
286 | 287 | ||
287 | /* | 288 | /* |
288 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 289 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
289 | * We must not forget to filter them out in next loop! | 290 | * We must not forget to filter them out in next loop! |
290 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 291 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
291 | */ | 292 | */ |
292 | QString temp; | 293 | QString temp; |
293 | mask = "INBOX" ; | 294 | mask = "INBOX" ; |
294 | mailimap_mailbox_list *list; | 295 | mailimap_mailbox_list *list; |
295 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 296 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
296 | QString del; | 297 | QString del; |
297 | bool selectable = true; | 298 | bool selectable = true; |
298 | bool no_inferiors = false; | 299 | bool no_inferiors = false; |
299 | if ( err == MAILIMAP_NO_ERROR ) { | 300 | if ( err == MAILIMAP_NO_ERROR ) { |
300 | current = result->first; | 301 | current = result->first; |
301 | for ( int i = result->count; i > 0; i-- ) { | 302 | for ( int i = result->count; i > 0; i-- ) { |
302 | list = (mailimap_mailbox_list *) current->data; | 303 | list = (mailimap_mailbox_list *) current->data; |
303 | // it is better use the deep copy mechanism of qt itself | 304 | // it is better use the deep copy mechanism of qt itself |
304 | // instead of using strdup! | 305 | // instead of using strdup! |
305 | temp = list->mb_name; | 306 | temp = list->mb_name; |
306 | del = list->mb_delimiter; | 307 | del = list->mb_delimiter; |
307 | current = current->next; | 308 | current = current->next; |
308 | if ( (bflags = list->mb_flag) ) { | 309 | if ( (bflags = list->mb_flag) ) { |
309 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 310 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
310 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 311 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
311 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 312 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
312 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 313 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
313 | no_inferiors = true; | 314 | no_inferiors = true; |
314 | } | 315 | } |
315 | } | 316 | } |
316 | } | 317 | } |
317 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 318 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
318 | } | 319 | } |
319 | } else { | 320 | } else { |
320 | odebug << "error fetching folders: " << m_imap->imap_response << "" << oendl; | 321 | odebug << "error fetching folders: " << m_imap->imap_response << "" << oendl; |
321 | } | 322 | } |
322 | mailimap_list_result_free( result ); | 323 | mailimap_list_result_free( result ); |
323 | 324 | ||
324 | /* | 325 | /* |
325 | * second stage - get the other then inbox folders | 326 | * second stage - get the other then inbox folders |
326 | */ | 327 | */ |
327 | mask = "*" ; | 328 | mask = "*" ; |
328 | path = account->getPrefix().latin1(); | 329 | path = account->getPrefix().latin1(); |
329 | if (!path) path = ""; | 330 | if (!path) path = ""; |
330 | odebug << path << oendl; | 331 | odebug << path << oendl; |
331 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 332 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
332 | if ( err == MAILIMAP_NO_ERROR ) { | 333 | if ( err == MAILIMAP_NO_ERROR ) { |
333 | current = result->first; | 334 | current = result->first; |
334 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 335 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
335 | no_inferiors = false; | 336 | no_inferiors = false; |
336 | list = (mailimap_mailbox_list *) current->data; | 337 | list = (mailimap_mailbox_list *) current->data; |
337 | // it is better use the deep copy mechanism of qt itself | 338 | // it is better use the deep copy mechanism of qt itself |
338 | // instead of using strdup! | 339 | // instead of using strdup! |
339 | temp = list->mb_name; | 340 | temp = list->mb_name; |
340 | if (temp.lower()=="inbox") | 341 | if (temp.lower()=="inbox") |
341 | continue; | 342 | continue; |
342 | if (temp.lower()==account->getPrefix().lower()) | 343 | if (temp.lower()==account->getPrefix().lower()) |
343 | continue; | 344 | continue; |
344 | if ( (bflags = list->mb_flag) ) { | 345 | if ( (bflags = list->mb_flag) ) { |
345 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 346 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
346 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 347 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
347 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 348 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
348 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 349 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
349 | no_inferiors = true; | 350 | no_inferiors = true; |
350 | } | 351 | } |
351 | } | 352 | } |
352 | } | 353 | } |
353 | del = list->mb_delimiter; | 354 | del = list->mb_delimiter; |
354 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 355 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
355 | } | 356 | } |
356 | } else { | 357 | } else { |
357 | odebug << "error fetching folders " << m_imap->imap_response << "" << oendl; | 358 | odebug << "error fetching folders " << m_imap->imap_response << "" << oendl; |
358 | } | 359 | } |
359 | if (result) mailimap_list_result_free( result ); | 360 | if (result) mailimap_list_result_free( result ); |
360 | return folders; | 361 | return folders; |
361 | } | 362 | } |
362 | 363 | ||
363 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 364 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
364 | { | 365 | { |
365 | RecMail * m = 0; | 366 | RecMail * m = 0; |
366 | mailimap_msg_att_item *item=0; | 367 | mailimap_msg_att_item *item=0; |
367 | clistcell *current,*c,*cf; | 368 | clistcell *current,*c,*cf; |
368 | mailimap_msg_att_dynamic*flist; | 369 | mailimap_msg_att_dynamic*flist; |
369 | mailimap_flag_fetch*cflag; | 370 | mailimap_flag_fetch*cflag; |
370 | int size; | 371 | int size; |
371 | QBitArray mFlags(7); | 372 | QBitArray mFlags(7); |
372 | QStringList addresslist; | 373 | QStringList addresslist; |
373 | 374 | ||
374 | if (!m_att) { | 375 | if (!m_att) { |
375 | return m; | 376 | return m; |
376 | } | 377 | } |
377 | m = new RecMail(); | 378 | m = new RecMail(); |
378 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 379 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
379 | current = c; | 380 | current = c; |
380 | size = 0; | 381 | size = 0; |
381 | item = (mailimap_msg_att_item*)current->data; | 382 | item = (mailimap_msg_att_item*)current->data; |
382 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 383 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
383 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 384 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
384 | if (!flist->att_list) { | 385 | if (!flist->att_list) { |
385 | continue; | 386 | continue; |
386 | } | 387 | } |
387 | cf = flist->att_list->first; | 388 | cf = flist->att_list->first; |
388 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 389 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
389 | cflag = (mailimap_flag_fetch*)cf->data; | 390 | cflag = (mailimap_flag_fetch*)cf->data; |
390 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 391 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
391 | switch (cflag->fl_flag->fl_type) { | 392 | switch (cflag->fl_flag->fl_type) { |
392 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 393 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
393 | mFlags.setBit(FLAG_ANSWERED); | 394 | mFlags.setBit(FLAG_ANSWERED); |
394 | break; | 395 | break; |
395 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 396 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
396 | mFlags.setBit(FLAG_FLAGGED); | 397 | mFlags.setBit(FLAG_FLAGGED); |
397 | break; | 398 | break; |
398 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 399 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
399 | mFlags.setBit(FLAG_DELETED); | 400 | mFlags.setBit(FLAG_DELETED); |
400 | break; | 401 | break; |
401 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 402 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
402 | mFlags.setBit(FLAG_SEEN); | 403 | mFlags.setBit(FLAG_SEEN); |
403 | break; | 404 | break; |
404 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 405 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
405 | mFlags.setBit(FLAG_DRAFT); | 406 | mFlags.setBit(FLAG_DRAFT); |
406 | break; | 407 | break; |
407 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 408 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
408 | break; | 409 | break; |
409 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 410 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
410 | break; | 411 | break; |
411 | default: | 412 | default: |
412 | break; | 413 | break; |
413 | } | 414 | } |
414 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 415 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
415 | mFlags.setBit(FLAG_RECENT); | 416 | mFlags.setBit(FLAG_RECENT); |
416 | } | 417 | } |
417 | } | 418 | } |
418 | continue; | 419 | continue; |
419 | } | 420 | } |
420 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 421 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
421 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 422 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
422 | m->setDate(head->env_date); | 423 | m->setDate(head->env_date); |
423 | m->setSubject(convert_String((const char*)head->env_subject)); | 424 | m->setSubject(convert_String((const char*)head->env_subject)); |
424 | //m->setSubject(head->env_subject); | 425 | //m->setSubject(head->env_subject); |
425 | if (head->env_from!=NULL) { | 426 | if (head->env_from!=NULL) { |
426 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 427 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
427 | if (addresslist.count()) { | 428 | if (addresslist.count()) { |
428 | m->setFrom(addresslist.first()); | 429 | m->setFrom(addresslist.first()); |
429 | } | 430 | } |
430 | } | 431 | } |
431 | if (head->env_to!=NULL) { | 432 | if (head->env_to!=NULL) { |
432 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 433 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
433 | m->setTo(addresslist); | 434 | m->setTo(addresslist); |
434 | } | 435 | } |
435 | if (head->env_cc!=NULL) { | 436 | if (head->env_cc!=NULL) { |
436 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 437 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
437 | m->setCC(addresslist); | 438 | m->setCC(addresslist); |
438 | } | 439 | } |
439 | if (head->env_bcc!=NULL) { | 440 | if (head->env_bcc!=NULL) { |
440 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 441 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
441 | m->setBcc(addresslist); | 442 | m->setBcc(addresslist); |
442 | } | 443 | } |
443 | /* reply to address, eg. email. */ | 444 | /* reply to address, eg. email. */ |
444 | if (head->env_reply_to!=NULL) { | 445 | if (head->env_reply_to!=NULL) { |
445 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 446 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
446 | if (addresslist.count()) { | 447 | if (addresslist.count()) { |
447 | m->setReplyto(addresslist.first()); | 448 | m->setReplyto(addresslist.first()); |
448 | } | 449 | } |
449 | } | 450 | } |
450 | if (head->env_in_reply_to!=NULL) { | 451 | if (head->env_in_reply_to!=NULL) { |
451 | QString h(head->env_in_reply_to); | 452 | QString h(head->env_in_reply_to); |
452 | while (h.length()>0 && h[0]=='<') { | 453 | while (h.length()>0 && h[0]=='<') { |
453 | h.remove(0,1); | 454 | h.remove(0,1); |
454 | } | 455 | } |
455 | while (h.length()>0 && h[h.length()-1]=='>') { | 456 | while (h.length()>0 && h[h.length()-1]=='>') { |
456 | h.remove(h.length()-1,1); | 457 | h.remove(h.length()-1,1); |
457 | } | 458 | } |
458 | if (h.length()>0) { | 459 | if (h.length()>0) { |
459 | m->setInreply(QStringList(h)); | 460 | m->setInreply(QStringList(h)); |
460 | } | 461 | } |
461 | } | 462 | } |
462 | if (head->env_message_id) { | 463 | if (head->env_message_id) { |
463 | m->setMsgid(QString(head->env_message_id)); | 464 | m->setMsgid(QString(head->env_message_id)); |
464 | } | 465 | } |
465 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 466 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
466 | #if 0 | 467 | #if 0 |
467 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 468 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
468 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 469 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
469 | odebug << "" << d->dt_year << " " << d->dt_month << " " << d->dt_day << " - " << d->dt_hour << " " << d->dt_min << " " << d->dt_sec << "" << oendl; | 470 | odebug << "" << d->dt_year << " " << d->dt_month << " " << d->dt_day << " - " << d->dt_hour << " " << d->dt_min << " " << d->dt_sec << "" << oendl; |
470 | odebug << da.toString() << oendl; | 471 | odebug << da.toString() << oendl; |
471 | #endif | 472 | #endif |
472 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 473 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
473 | size = item->att_data.att_static->att_data.att_rfc822_size; | 474 | size = item->att_data.att_static->att_data.att_rfc822_size; |
474 | } | 475 | } |
475 | } | 476 | } |
476 | /* msg is already deleted */ | 477 | /* msg is already deleted */ |
477 | if (mFlags.testBit(FLAG_DELETED) && m) { | 478 | if (mFlags.testBit(FLAG_DELETED) && m) { |
478 | delete m; | 479 | delete m; |
479 | m = 0; | 480 | m = 0; |
480 | } | 481 | } |
481 | if (m) { | 482 | if (m) { |
482 | m->setFlags(mFlags); | 483 | m->setFlags(mFlags); |
483 | m->setMsgsize(size); | 484 | m->setMsgsize(size); |
484 | } | 485 | } |
485 | return m; | 486 | return m; |
486 | } | 487 | } |
487 | 488 | ||
488 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) | 489 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) |
489 | { | 490 | { |
490 | RecBodyP body = new RecBody(); | 491 | RecBodyP body = new RecBody(); |
491 | const char *mb; | 492 | const char *mb; |
492 | int err = MAILIMAP_NO_ERROR; | 493 | int err = MAILIMAP_NO_ERROR; |
493 | clist *result = 0; | 494 | clist *result = 0; |
494 | clistcell *current; | 495 | clistcell *current; |
495 | mailimap_fetch_att *fetchAtt = 0; | 496 | mailimap_fetch_att *fetchAtt = 0; |
496 | mailimap_fetch_type *fetchType = 0; | 497 | mailimap_fetch_type *fetchType = 0; |
497 | mailimap_set *set = 0; | 498 | mailimap_set *set = 0; |
498 | mailimap_body*body_desc = 0; | 499 | mailimap_body*body_desc = 0; |
499 | 500 | ||
500 | mb = mail->getMbox().latin1(); | 501 | mb = mail->getMbox().latin1(); |
501 | 502 | ||
502 | login(); | 503 | login(); |
503 | if (!m_imap) { | 504 | if (!m_imap) { |
504 | return body; | 505 | return body; |
505 | } | 506 | } |
506 | err = selectMbox(mail->getMbox()); | 507 | err = selectMbox(mail->getMbox()); |
507 | if ( err != MAILIMAP_NO_ERROR ) { | 508 | if ( err != MAILIMAP_NO_ERROR ) { |
508 | return body; | 509 | return body; |
509 | } | 510 | } |
510 | 511 | ||
511 | /* the range has to start at 1!!! not with 0!!!! */ | 512 | /* the range has to start at 1!!! not with 0!!!! */ |
512 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); | 513 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); |
513 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 514 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
514 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 515 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
515 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 516 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
516 | mailimap_set_free( set ); | 517 | mailimap_set_free( set ); |
517 | mailimap_fetch_type_free( fetchType ); | 518 | mailimap_fetch_type_free( fetchType ); |
518 | 519 | ||
519 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 520 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
520 | mailimap_msg_att * msg_att; | 521 | mailimap_msg_att * msg_att; |
521 | msg_att = (mailimap_msg_att*)current->data; | 522 | msg_att = (mailimap_msg_att*)current->data; |
522 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 523 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
523 | QValueList<int> path; | 524 | QValueList<int> path; |
524 | body_desc = item->att_data.att_static->att_data.att_body; | 525 | body_desc = item->att_data.att_static->att_data.att_body; |
525 | traverseBody(mail,body_desc,body,0,path); | 526 | traverseBody(mail,body_desc,body,0,path); |
526 | } else { | 527 | } else { |
527 | odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; | 528 | odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; |
528 | } | 529 | } |
529 | if (result) mailimap_fetch_list_free(result); | 530 | if (result) mailimap_fetch_list_free(result); |
530 | return body; | 531 | return body; |
531 | } | 532 | } |
532 | 533 | ||
533 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 534 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
534 | { | 535 | { |
535 | QStringList l; | 536 | QStringList l; |
536 | QString from; | 537 | QString from; |
537 | bool named_from; | 538 | bool named_from; |
538 | clistcell *current = NULL; | 539 | clistcell *current = NULL; |
539 | mailimap_address * current_address=NULL; | 540 | mailimap_address * current_address=NULL; |
540 | if (!list) { | 541 | if (!list) { |
541 | return l; | 542 | return l; |
542 | } | 543 | } |
543 | unsigned int count = 0; | 544 | unsigned int count = 0; |
544 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 545 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
545 | from = ""; | 546 | from = ""; |
546 | named_from = false; | 547 | named_from = false; |
547 | current_address=(mailimap_address*)current->data; | 548 | current_address=(mailimap_address*)current->data; |
548 | if (current_address->ad_personal_name){ | 549 | if (current_address->ad_personal_name){ |
549 | from+=convert_String((const char*)current_address->ad_personal_name); | 550 | from+=convert_String((const char*)current_address->ad_personal_name); |
550 | from+=" "; | 551 | from+=" "; |
551 | named_from = true; | 552 | named_from = true; |
552 | } | 553 | } |
553 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 554 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
554 | from+="<"; | 555 | from+="<"; |
555 | } | 556 | } |
556 | if (current_address->ad_mailbox_name) { | 557 | if (current_address->ad_mailbox_name) { |
557 | from+=QString(current_address->ad_mailbox_name); | 558 | from+=QString(current_address->ad_mailbox_name); |
558 | from+="@"; | 559 | from+="@"; |
559 | } | 560 | } |
560 | if (current_address->ad_host_name) { | 561 | if (current_address->ad_host_name) { |
561 | from+=QString(current_address->ad_host_name); | 562 | from+=QString(current_address->ad_host_name); |
562 | } | 563 | } |
563 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 564 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
564 | from+=">"; | 565 | from+=">"; |
565 | } | 566 | } |
566 | l.append(QString(from)); | 567 | l.append(QString(from)); |
567 | if (++count > 99) { | 568 | if (++count > 99) { |
568 | break; | 569 | break; |
569 | } | 570 | } |
570 | } | 571 | } |
571 | return l; | 572 | return l; |
572 | } | 573 | } |
573 | 574 | ||
574 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) | 575 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) |
575 | { | 576 | { |
576 | encodedString*res=new encodedString; | 577 | encodedString*res=new encodedString; |
577 | int err; | 578 | int err; |
578 | mailimap_fetch_type *fetchType; | 579 | mailimap_fetch_type *fetchType; |
579 | mailimap_set *set; | 580 | mailimap_set *set; |
580 | clistcell*current,*cur; | 581 | clistcell*current,*cur; |
581 | mailimap_section_part * section_part = 0; | 582 | mailimap_section_part * section_part = 0; |
582 | mailimap_section_spec * section_spec = 0; | 583 | mailimap_section_spec * section_spec = 0; |
583 | mailimap_section * section = 0; | 584 | mailimap_section * section = 0; |
584 | mailimap_fetch_att * fetch_att = 0; | 585 | mailimap_fetch_att * fetch_att = 0; |
585 | 586 | ||
586 | login(); | 587 | login(); |
587 | if (!m_imap) { | 588 | if (!m_imap) { |
588 | return res; | 589 | return res; |
589 | } | 590 | } |
590 | if (!internal_call) { | 591 | if (!internal_call) { |
591 | err = selectMbox(mail->getMbox()); | 592 | err = selectMbox(mail->getMbox()); |
592 | if ( err != MAILIMAP_NO_ERROR ) { | 593 | if ( err != MAILIMAP_NO_ERROR ) { |
593 | return res; | 594 | return res; |
594 | } | 595 | } |
595 | } | 596 | } |
596 | set = mailimap_set_new_single(mail->getNumber()); | 597 | set = mailimap_set_new_single(mail->getNumber()); |
597 | 598 | ||
598 | clist*id_list = 0; | 599 | clist*id_list = 0; |
599 | 600 | ||
600 | /* if path == empty then its a request for the whole rfc822 mail and generates | 601 | /* if path == empty then its a request for the whole rfc822 mail and generates |
601 | a "fetch <id> (body[])" statement on imap server */ | 602 | a "fetch <id> (body[])" statement on imap server */ |
602 | if (path.count()>0 ) { | 603 | if (path.count()>0 ) { |
603 | id_list = clist_new(); | 604 | id_list = clist_new(); |
604 | for (unsigned j=0; j < path.count();++j) { | 605 | for (unsigned j=0; j < path.count();++j) { |
605 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 606 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
606 | *p_id = path[j]; | 607 | *p_id = path[j]; |
607 | clist_append(id_list,p_id); | 608 | clist_append(id_list,p_id); |
608 | } | 609 | } |
609 | section_part = mailimap_section_part_new(id_list); | 610 | section_part = mailimap_section_part_new(id_list); |
610 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 611 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
611 | } | 612 | } |
612 | 613 | ||
613 | section = mailimap_section_new(section_spec); | 614 | section = mailimap_section_new(section_spec); |
614 | fetch_att = mailimap_fetch_att_new_body_section(section); | 615 | fetch_att = mailimap_fetch_att_new_body_section(section); |
615 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 616 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
616 | 617 | ||
617 | clist*result = 0; | 618 | clist*result = 0; |
618 | 619 | ||
619 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 620 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
620 | mailimap_set_free( set ); | 621 | mailimap_set_free( set ); |
621 | mailimap_fetch_type_free( fetchType ); | 622 | mailimap_fetch_type_free( fetchType ); |
622 | 623 | ||
623 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 624 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
624 | mailimap_msg_att * msg_att; | 625 | mailimap_msg_att * msg_att; |
625 | msg_att = (mailimap_msg_att*)current->data; | 626 | msg_att = (mailimap_msg_att*)current->data; |
626 | mailimap_msg_att_item*msg_att_item; | 627 | mailimap_msg_att_item*msg_att_item; |
627 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 628 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
628 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 629 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
629 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 630 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
630 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 631 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
631 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 632 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
632 | /* detach - we take over the content */ | 633 | /* detach - we take over the content */ |
633 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 634 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
634 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 635 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
635 | } | 636 | } |
636 | } | 637 | } |
637 | } | 638 | } |
638 | } else { | 639 | } else { |
639 | odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; | 640 | odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; |
640 | } | 641 | } |
641 | if (result) mailimap_fetch_list_free(result); | 642 | if (result) mailimap_fetch_list_free(result); |
642 | return res; | 643 | return res; |
643 | } | 644 | } |
644 | 645 | ||
645 | /* current_recursion is for recursive calls. | 646 | /* current_recursion is for recursive calls. |
646 | current_count means the position inside the internal loop! */ | 647 | current_count means the position inside the internal loop! */ |
647 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, | 648 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, |
648 | int current_recursion,QValueList<int>recList,int current_count) | 649 | int current_recursion,QValueList<int>recList,int current_count) |
649 | { | 650 | { |
650 | if (!body || current_recursion>=10) { | 651 | if (!body || current_recursion>=10) { |
651 | return; | 652 | return; |
652 | } | 653 | } |
653 | switch (body->bd_type) { | 654 | switch (body->bd_type) { |
654 | case MAILIMAP_BODY_1PART: | 655 | case MAILIMAP_BODY_1PART: |
655 | { | 656 | { |
656 | QValueList<int>countlist = recList; | 657 | QValueList<int>countlist = recList; |
657 | countlist.append(current_count); | 658 | countlist.append(current_count); |
658 | RecPartP currentPart = new RecPart(); | 659 | RecPartP currentPart = new RecPart(); |
659 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; | 660 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; |
660 | QString id(""); | 661 | QString id(""); |
661 | currentPart->setPositionlist(countlist); | 662 | currentPart->setPositionlist(countlist); |
662 | for (unsigned int j = 0; j < countlist.count();++j) { | 663 | for (unsigned int j = 0; j < countlist.count();++j) { |
663 | id+=(j>0?" ":""); | 664 | id+=(j>0?" ":""); |
664 | id+=QString("%1").arg(countlist[j]); | 665 | id+=QString("%1").arg(countlist[j]); |
665 | } | 666 | } |
666 | odebug << "ID = " << id.latin1() << "" << oendl; | 667 | odebug << "ID = " << id.latin1() << "" << oendl; |
667 | currentPart->setIdentifier(id); | 668 | currentPart->setIdentifier(id); |
668 | fillSinglePart(currentPart,part1); | 669 | fillSinglePart(currentPart,part1); |
669 | /* important: Check for is NULL 'cause a body can be empty! | 670 | /* important: Check for is NULL 'cause a body can be empty! |
670 | And we put it only into the mail if it is the FIRST part */ | 671 | And we put it only into the mail if it is the FIRST part */ |
671 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { | 672 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { |
672 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); | 673 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); |
673 | target_body->setDescription(currentPart); | 674 | target_body->setDescription(currentPart); |
674 | target_body->setBodytext(body_text); | 675 | target_body->setBodytext(body_text); |
675 | if (countlist.count()>1) { | 676 | if (countlist.count()>1) { |
676 | target_body->addPart(currentPart); | 677 | target_body->addPart(currentPart); |
677 | } | 678 | } |
678 | } else { | 679 | } else { |
679 | target_body->addPart(currentPart); | 680 | target_body->addPart(currentPart); |
680 | } | 681 | } |
681 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { | 682 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { |
682 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); | 683 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); |
683 | } | 684 | } |
684 | } | 685 | } |
685 | break; | 686 | break; |
686 | case MAILIMAP_BODY_MPART: | 687 | case MAILIMAP_BODY_MPART: |
687 | { | 688 | { |
688 | QValueList<int>countlist = recList; | 689 | QValueList<int>countlist = recList; |
689 | clistcell*current=0; | 690 | clistcell*current=0; |
690 | mailimap_body*current_body=0; | 691 | mailimap_body*current_body=0; |
691 | unsigned int ccount = 1; | 692 | unsigned int ccount = 1; |
692 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; | 693 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; |
693 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 694 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
694 | current_body = (mailimap_body*)current->data; | 695 | current_body = (mailimap_body*)current->data; |
695 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 696 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
696 | RecPartP targetPart = new RecPart(); | 697 | RecPartP targetPart = new RecPart(); |
697 | targetPart->setType("multipart"); | 698 | targetPart->setType("multipart"); |
698 | fillMultiPart(targetPart,mailDescription); | 699 | fillMultiPart(targetPart,mailDescription); |
699 | countlist.append(current_count); | 700 | countlist.append(current_count); |
700 | targetPart->setPositionlist(countlist); | 701 | targetPart->setPositionlist(countlist); |
701 | target_body->addPart(targetPart); | 702 | target_body->addPart(targetPart); |
702 | QString id(""); | 703 | QString id(""); |
703 | for (unsigned int j = 0; j < countlist.count();++j) { | 704 | for (unsigned int j = 0; j < countlist.count();++j) { |
704 | id+=(j>0?" ":""); | 705 | id+=(j>0?" ":""); |
705 | id+=QString("%1").arg(countlist[j]); | 706 | id+=QString("%1").arg(countlist[j]); |
706 | } | 707 | } |
707 | odebug << "ID(mpart) = " << id.latin1() << "" << oendl; | 708 | odebug << "ID(mpart) = " << id.latin1() << "" << oendl; |
708 | } | 709 | } |
709 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); | 710 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); |
710 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 711 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
711 | countlist = recList; | 712 | countlist = recList; |
712 | } | 713 | } |
713 | ++ccount; | 714 | ++ccount; |
714 | } | 715 | } |
715 | } | 716 | } |
716 | break; | 717 | break; |
717 | default: | 718 | default: |
718 | break; | 719 | break; |
719 | } | 720 | } |
720 | } | 721 | } |
721 | 722 | ||
722 | void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) | 723 | void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) |
723 | { | 724 | { |
724 | if (!Description) { | 725 | if (!Description) { |
725 | return; | 726 | return; |
726 | } | 727 | } |
727 | switch (Description->bd_type) { | 728 | switch (Description->bd_type) { |
728 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 729 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
729 | target_part->setType("text"); | 730 | target_part->setType("text"); |
730 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 731 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
731 | break; | 732 | break; |
732 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 733 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
733 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 734 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
734 | break; | 735 | break; |
735 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 736 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
736 | target_part->setType("message"); | 737 | target_part->setType("message"); |
737 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 738 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
738 | break; | 739 | break; |
739 | default: | 740 | default: |
740 | break; | 741 | break; |
741 | } | 742 | } |
742 | } | 743 | } |
743 | 744 | ||
744 | void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) | 745 | void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) |
745 | { | 746 | { |
746 | if (!which) { | 747 | if (!which) { |
747 | return; | 748 | return; |
748 | } | 749 | } |
749 | QString sub; | 750 | QString sub; |
750 | sub = which->bd_media_text; | 751 | sub = which->bd_media_text; |
751 | odebug << "Type= text/" << which->bd_media_text << "" << oendl; | 752 | odebug << "Type= text/" << which->bd_media_text << "" << oendl; |
752 | target_part->setSubtype(sub.lower()); | 753 | target_part->setSubtype(sub.lower()); |
753 | target_part->setLines(which->bd_lines); | 754 | target_part->setLines(which->bd_lines); |
754 | fillBodyFields(target_part,which->bd_fields); | 755 | fillBodyFields(target_part,which->bd_fields); |
755 | } | 756 | } |
756 | 757 | ||
757 | void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) | 758 | void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) |
758 | { | 759 | { |
759 | if (!which) { | 760 | if (!which) { |
760 | return; | 761 | return; |
761 | } | 762 | } |
762 | target_part->setSubtype("rfc822"); | 763 | target_part->setSubtype("rfc822"); |
763 | odebug << "Message part" << oendl; | 764 | odebug << "Message part" << oendl; |
764 | /* we set this type to text/plain */ | 765 | /* we set this type to text/plain */ |
765 | target_part->setLines(which->bd_lines); | 766 | target_part->setLines(which->bd_lines); |
766 | fillBodyFields(target_part,which->bd_fields); | 767 | fillBodyFields(target_part,which->bd_fields); |
767 | } | 768 | } |
768 | 769 | ||
769 | void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) | 770 | void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) |
770 | { | 771 | { |
771 | if (!which) return; | 772 | if (!which) return; |
772 | QString sub = which->bd_media_subtype; | 773 | QString sub = which->bd_media_subtype; |
773 | target_part->setSubtype(sub.lower()); | 774 | target_part->setSubtype(sub.lower()); |
774 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { | 775 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { |
775 | clistcell*cur = 0; | 776 | clistcell*cur = 0; |
776 | mailimap_single_body_fld_param*param=0; | 777 | mailimap_single_body_fld_param*param=0; |
777 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 778 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
778 | param = (mailimap_single_body_fld_param*)cur->data; | 779 | param = (mailimap_single_body_fld_param*)cur->data; |
779 | if (param) { | 780 | if (param) { |
780 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 781 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
781 | } | 782 | } |
782 | } | 783 | } |
783 | } | 784 | } |
784 | } | 785 | } |
785 | 786 | ||
786 | void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) | 787 | void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) |
787 | { | 788 | { |
788 | if (!which) { | 789 | if (!which) { |
789 | return; | 790 | return; |
790 | } | 791 | } |
791 | QString type,sub; | 792 | QString type,sub; |
792 | switch (which->bd_media_basic->med_type) { | 793 | switch (which->bd_media_basic->med_type) { |
793 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 794 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
794 | type = "application"; | 795 | type = "application"; |
795 | break; | 796 | break; |
796 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 797 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
797 | type = "audio"; | 798 | type = "audio"; |
798 | break; | 799 | break; |
799 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 800 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
800 | type = "image"; | 801 | type = "image"; |
801 | break; | 802 | break; |
802 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 803 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
803 | type = "message"; | 804 | type = "message"; |
804 | break; | 805 | break; |
805 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 806 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
806 | type = "video"; | 807 | type = "video"; |
807 | break; | 808 | break; |
808 | case MAILIMAP_MEDIA_BASIC_OTHER: | 809 | case MAILIMAP_MEDIA_BASIC_OTHER: |
809 | default: | 810 | default: |
810 | if (which->bd_media_basic->med_basic_type) { | 811 | if (which->bd_media_basic->med_basic_type) { |
811 | type = which->bd_media_basic->med_basic_type; | 812 | type = which->bd_media_basic->med_basic_type; |
812 | } else { | 813 | } else { |
813 | type = ""; | 814 | type = ""; |
814 | } | 815 | } |
815 | break; | 816 | break; |
816 | } | 817 | } |
817 | if (which->bd_media_basic->med_subtype) { | 818 | if (which->bd_media_basic->med_subtype) { |
818 | sub = which->bd_media_basic->med_subtype; | 819 | sub = which->bd_media_basic->med_subtype; |
819 | } else { | 820 | } else { |
820 | sub = ""; | 821 | sub = ""; |
821 | } | 822 | } |
822 | odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; | 823 | odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; |
823 | target_part->setType(type.lower()); | 824 | target_part->setType(type.lower()); |
824 | target_part->setSubtype(sub.lower()); | 825 | target_part->setSubtype(sub.lower()); |
825 | fillBodyFields(target_part,which->bd_fields); | 826 | fillBodyFields(target_part,which->bd_fields); |
826 | } | 827 | } |
827 | 828 | ||
828 | void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) | 829 | void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) |
829 | { | 830 | { |
830 | if (!which) return; | 831 | if (!which) return; |
831 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 832 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
832 | clistcell*cur; | 833 | clistcell*cur; |
833 | mailimap_single_body_fld_param*param=0; | 834 | mailimap_single_body_fld_param*param=0; |
834 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 835 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
835 | param = (mailimap_single_body_fld_param*)cur->data; | 836 | param = (mailimap_single_body_fld_param*)cur->data; |
836 | if (param) { | 837 | if (param) { |
837 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 838 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
838 | } | 839 | } |
839 | } | 840 | } |
840 | } | 841 | } |
841 | mailimap_body_fld_enc*enc = which->bd_encoding; | 842 | mailimap_body_fld_enc*enc = which->bd_encoding; |
842 | QString encoding(""); | 843 | QString encoding(""); |
843 | switch (enc->enc_type) { | 844 | switch (enc->enc_type) { |
844 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 845 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
845 | encoding = "7bit"; | 846 | encoding = "7bit"; |
846 | break; | 847 | break; |
847 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 848 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
848 | encoding = "8bit"; | 849 | encoding = "8bit"; |
849 | break; | 850 | break; |
850 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 851 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
851 | encoding="binary"; | 852 | encoding="binary"; |
852 | break; | 853 | break; |
853 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 854 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
854 | encoding="base64"; | 855 | encoding="base64"; |
855 | break; | 856 | break; |
856 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 857 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
857 | encoding="quoted-printable"; | 858 | encoding="quoted-printable"; |
858 | break; | 859 | break; |
859 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 860 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
860 | default: | 861 | default: |
861 | if (enc->enc_value) { | 862 | if (enc->enc_value) { |
862 | char*t=enc->enc_value; | 863 | char*t=enc->enc_value; |
863 | encoding=QString(enc->enc_value); | 864 | encoding=QString(enc->enc_value); |
864 | enc->enc_value=0L; | 865 | enc->enc_value=0L; |
865 | free(t); | 866 | free(t); |
866 | } | 867 | } |
867 | } | 868 | } |
868 | if (which->bd_description) { | 869 | if (which->bd_description) { |
869 | target_part->setDescription(QString(which->bd_description)); | 870 | target_part->setDescription(QString(which->bd_description)); |
870 | } | 871 | } |
871 | target_part->setEncoding(encoding); | 872 | target_part->setEncoding(encoding); |
872 | target_part->setSize(which->bd_size); | 873 | target_part->setSize(which->bd_size); |
873 | } | 874 | } |
874 | 875 | ||
875 | void IMAPwrapper::deleteMail(const RecMailP&mail) | 876 | void IMAPwrapper::deleteMail(const RecMailP&mail) |
876 | { | 877 | { |
877 | mailimap_flag_list*flist; | 878 | mailimap_flag_list*flist; |
878 | mailimap_set *set; | 879 | mailimap_set *set; |
879 | mailimap_store_att_flags * store_flags; | 880 | mailimap_store_att_flags * store_flags; |
880 | int err; | 881 | int err; |
881 | login(); | 882 | login(); |
882 | if (!m_imap) { | 883 | if (!m_imap) { |
883 | return; | 884 | return; |
884 | } | 885 | } |
885 | err = selectMbox(mail->getMbox()); | 886 | err = selectMbox(mail->getMbox()); |
886 | if ( err != MAILIMAP_NO_ERROR ) { | 887 | if ( err != MAILIMAP_NO_ERROR ) { |
887 | return; | 888 | return; |
888 | } | 889 | } |
889 | flist = mailimap_flag_list_new_empty(); | 890 | flist = mailimap_flag_list_new_empty(); |
890 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 891 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
891 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 892 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
892 | set = mailimap_set_new_single(mail->getNumber()); | 893 | set = mailimap_set_new_single(mail->getNumber()); |
893 | err = mailimap_store(m_imap,set,store_flags); | 894 | err = mailimap_store(m_imap,set,store_flags); |
894 | mailimap_set_free( set ); | 895 | mailimap_set_free( set ); |
895 | mailimap_store_att_flags_free(store_flags); | 896 | mailimap_store_att_flags_free(store_flags); |
896 | 897 | ||
897 | if (err != MAILIMAP_NO_ERROR) { | 898 | if (err != MAILIMAP_NO_ERROR) { |
898 | odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | 899 | odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; |
899 | return; | 900 | return; |
900 | } | 901 | } |
901 | odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | 902 | odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; |
902 | /* should we realy do that at this moment? */ | 903 | /* should we realy do that at this moment? */ |
903 | err = mailimap_expunge(m_imap); | 904 | err = mailimap_expunge(m_imap); |
904 | if (err != MAILIMAP_NO_ERROR) { | 905 | if (err != MAILIMAP_NO_ERROR) { |
905 | odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | 906 | odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; |
906 | } | 907 | } |
907 | odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; | 908 | odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; |
908 | } | 909 | } |
909 | 910 | ||
910 | void IMAPwrapper::answeredMail(const RecMailP&mail) | 911 | void IMAPwrapper::answeredMail(const RecMailP&mail) |
911 | { | 912 | { |
912 | mailimap_flag_list*flist; | 913 | mailimap_flag_list*flist; |
913 | mailimap_set *set; | 914 | mailimap_set *set; |
914 | mailimap_store_att_flags * store_flags; | 915 | mailimap_store_att_flags * store_flags; |
915 | int err; | 916 | int err; |
916 | login(); | 917 | login(); |
917 | if (!m_imap) { | 918 | if (!m_imap) { |
918 | return; | 919 | return; |
919 | } | 920 | } |
920 | err = selectMbox(mail->getMbox()); | 921 | err = selectMbox(mail->getMbox()); |
921 | if ( err != MAILIMAP_NO_ERROR ) { | 922 | if ( err != MAILIMAP_NO_ERROR ) { |
922 | return; | 923 | return; |
923 | } | 924 | } |
924 | flist = mailimap_flag_list_new_empty(); | 925 | flist = mailimap_flag_list_new_empty(); |
925 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 926 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
926 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 927 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
927 | set = mailimap_set_new_single(mail->getNumber()); | 928 | set = mailimap_set_new_single(mail->getNumber()); |
928 | err = mailimap_store(m_imap,set,store_flags); | 929 | err = mailimap_store(m_imap,set,store_flags); |
929 | mailimap_set_free( set ); | 930 | mailimap_set_free( set ); |
930 | mailimap_store_att_flags_free(store_flags); | 931 | mailimap_store_att_flags_free(store_flags); |
931 | 932 | ||
932 | if (err != MAILIMAP_NO_ERROR) { | 933 | if (err != MAILIMAP_NO_ERROR) { |
933 | odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; | 934 | odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; |
934 | return; | 935 | return; |
935 | } | 936 | } |
936 | } | 937 | } |
937 | 938 | ||
938 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 939 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) |
939 | { | 940 | { |
940 | QString body(""); | 941 | QString body(""); |
941 | encodedString*res = fetchRawPart(mail,path,internal_call); | 942 | encodedString*res = fetchRawPart(mail,path,internal_call); |
942 | encodedString*r = decode_String(res,enc); | 943 | encodedString*r = decode_String(res,enc); |
943 | delete res; | 944 | delete res; |
944 | if (r) { | 945 | if (r) { |
945 | if (r->Length()>0) { | 946 | if (r->Length()>0) { |
946 | body = r->Content(); | 947 | body = r->Content(); |
947 | } | 948 | } |
948 | delete r; | 949 | delete r; |
949 | } | 950 | } |
950 | return body; | 951 | return body; |
951 | } | 952 | } |
952 | 953 | ||
953 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) | 954 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) |
954 | { | 955 | { |
955 | return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); | 956 | return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); |
956 | } | 957 | } |
957 | 958 | ||
958 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) | 959 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) |
959 | { | 960 | { |
960 | encodedString*res = fetchRawPart(mail,part->Positionlist(),false); | 961 | encodedString*res = fetchRawPart(mail,part->Positionlist(),false); |
961 | encodedString*r = decode_String(res,part->Encoding()); | 962 | encodedString*r = decode_String(res,part->Encoding()); |
962 | delete res; | 963 | delete res; |
963 | return r; | 964 | return r; |
964 | } | 965 | } |
965 | 966 | ||
966 | encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) | 967 | encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) |
967 | { | 968 | { |
968 | return fetchRawPart(mail,part->Positionlist(),false); | 969 | return fetchRawPart(mail,part->Positionlist(),false); |
969 | } | 970 | } |
970 | 971 | ||
971 | int IMAPwrapper::deleteAllMail(const FolderP&folder) | 972 | int IMAPwrapper::deleteAllMail(const FolderP&folder) |
972 | { | 973 | { |
973 | login(); | 974 | login(); |
974 | if (!m_imap) { | 975 | if (!m_imap) { |
975 | return 0; | 976 | return 0; |
976 | } | 977 | } |
977 | mailimap_flag_list*flist; | 978 | mailimap_flag_list*flist; |
978 | mailimap_set *set; | 979 | mailimap_set *set; |
979 | mailimap_store_att_flags * store_flags; | 980 | mailimap_store_att_flags * store_flags; |
980 | int err = selectMbox(folder->getName()); | 981 | int err = selectMbox(folder->getName()); |
981 | if ( err != MAILIMAP_NO_ERROR ) { | 982 | if ( err != MAILIMAP_NO_ERROR ) { |
982 | return 0; | 983 | return 0; |
983 | } | 984 | } |
984 | 985 | ||
985 | int last = m_imap->imap_selection_info->sel_exists; | 986 | int last = m_imap->imap_selection_info->sel_exists; |
986 | if (last == 0) { | 987 | if (last == 0) { |
987 | Global::statusMessage(tr("Mailbox has no mails!")); | 988 | Global::statusMessage(tr("Mailbox has no mails!")); |
988 | return 0; | 989 | return 0; |
989 | } | 990 | } |
990 | flist = mailimap_flag_list_new_empty(); | 991 | flist = mailimap_flag_list_new_empty(); |
991 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 992 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
992 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 993 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
993 | set = mailimap_set_new_interval( 1, last ); | 994 | set = mailimap_set_new_interval( 1, last ); |
994 | err = mailimap_store(m_imap,set,store_flags); | 995 | err = mailimap_store(m_imap,set,store_flags); |
995 | mailimap_set_free( set ); | 996 | mailimap_set_free( set ); |
996 | mailimap_store_att_flags_free(store_flags); | 997 | mailimap_store_att_flags_free(store_flags); |
997 | if (err != MAILIMAP_NO_ERROR) { | 998 | if (err != MAILIMAP_NO_ERROR) { |
998 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | 999 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); |
999 | return 0; | 1000 | return 0; |
1000 | } | 1001 | } |
1001 | odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | 1002 | odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; |
1002 | /* should we realy do that at this moment? */ | 1003 | /* should we realy do that at this moment? */ |
1003 | err = mailimap_expunge(m_imap); | 1004 | err = mailimap_expunge(m_imap); |
1004 | if (err != MAILIMAP_NO_ERROR) { | 1005 | if (err != MAILIMAP_NO_ERROR) { |
1005 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | 1006 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); |
1006 | return 0; | 1007 | return 0; |
1007 | } | 1008 | } |
1008 | odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; | 1009 | odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; |
1009 | return 1; | 1010 | return 1; |
1010 | } | 1011 | } |
1011 | 1012 | ||
1012 | int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) | 1013 | int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) |
1013 | { | 1014 | { |
1014 | if (folder.length()==0) return 0; | 1015 | if (folder.length()==0) return 0; |
1015 | login(); | 1016 | login(); |
1016 | if (!m_imap) {return 0;} | 1017 | if (!m_imap) {return 0;} |
1017 | QString pre = account->getPrefix(); | 1018 | QString pre = account->getPrefix(); |
1018 | if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { | 1019 | if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { |
1019 | pre+=delemiter; | 1020 | pre+=delemiter; |
1020 | } | 1021 | } |
1021 | if (parentfolder) { | 1022 | if (parentfolder) { |
1022 | pre += parentfolder->getDisplayName()+delemiter; | 1023 | pre += parentfolder->getDisplayName()+delemiter; |
1023 | } | 1024 | } |
1024 | pre+=folder; | 1025 | pre+=folder; |
1025 | if (getsubfolder) { | 1026 | if (getsubfolder) { |
1026 | if (delemiter.length()>0) { | 1027 | if (delemiter.length()>0) { |
1027 | pre+=delemiter; | 1028 | pre+=delemiter; |
1028 | } else { | 1029 | } else { |
1029 | Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); | 1030 | Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); |
1030 | return 0; | 1031 | return 0; |
1031 | } | 1032 | } |
1032 | } | 1033 | } |
1033 | odebug << "Creating " << pre.latin1() << "" << oendl; | 1034 | odebug << "Creating " << pre.latin1() << "" << oendl; |
1034 | int res = mailimap_create(m_imap,pre.latin1()); | 1035 | int res = mailimap_create(m_imap,pre.latin1()); |
1035 | if (res != MAILIMAP_NO_ERROR) { | 1036 | if (res != MAILIMAP_NO_ERROR) { |
1036 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | 1037 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); |
1037 | return 0; | 1038 | return 0; |
1038 | } | 1039 | } |
1039 | return 1; | 1040 | return 1; |
1040 | } | 1041 | } |
1041 | 1042 | ||
1042 | int IMAPwrapper::deleteMbox(const FolderP&folder) | 1043 | int IMAPwrapper::deleteMbox(const FolderP&folder) |
1043 | { | 1044 | { |
1044 | if (!folder) return 0; | 1045 | if (!folder) return 0; |
1045 | login(); | 1046 | login(); |
1046 | if (!m_imap) {return 0;} | 1047 | if (!m_imap) {return 0;} |
1047 | int res = mailimap_delete(m_imap,folder->getName()); | 1048 | int res = mailimap_delete(m_imap,folder->getName()); |
1048 | if (res != MAILIMAP_NO_ERROR) { | 1049 | if (res != MAILIMAP_NO_ERROR) { |
1049 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | 1050 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); |
1050 | return 0; | 1051 | return 0; |
1051 | } | 1052 | } |
1052 | return 1; | 1053 | return 1; |
1053 | } | 1054 | } |
1054 | 1055 | ||
1055 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 1056 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
1056 | { | 1057 | { |
1057 | mailimap_status_att_list * att_list =0; | 1058 | mailimap_status_att_list * att_list =0; |
1058 | mailimap_mailbox_data_status * status=0; | 1059 | mailimap_mailbox_data_status * status=0; |
1059 | clistiter * cur = 0; | 1060 | clistiter * cur = 0; |
1060 | int r = 0; | 1061 | int r = 0; |
1061 | target_stat.message_count = 0; | 1062 | target_stat.message_count = 0; |
1062 | target_stat.message_unseen = 0; | 1063 | target_stat.message_unseen = 0; |
1063 | target_stat.message_recent = 0; | 1064 | target_stat.message_recent = 0; |
1064 | login(); | 1065 | login(); |
1065 | if (!m_imap) { | 1066 | if (!m_imap) { |
1066 | return; | 1067 | return; |
1067 | } | 1068 | } |
1068 | att_list = mailimap_status_att_list_new_empty(); | 1069 | att_list = mailimap_status_att_list_new_empty(); |
1069 | if (!att_list) return; | 1070 | if (!att_list) return; |
1070 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); | 1071 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); |
1071 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); | 1072 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); |
1072 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); | 1073 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); |
1073 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); | 1074 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); |
1074 | if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { | 1075 | if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { |
1075 | for (cur = clist_begin(status->st_info_list); | 1076 | for (cur = clist_begin(status->st_info_list); |
1076 | cur != NULL ; cur = clist_next(cur)) { | 1077 | cur != NULL ; cur = clist_next(cur)) { |
1077 | mailimap_status_info * status_info; | 1078 | mailimap_status_info * status_info; |
1078 | status_info = (mailimap_status_info *)clist_content(cur); | 1079 | status_info = (mailimap_status_info *)clist_content(cur); |
1079 | switch (status_info->st_att) { | 1080 | switch (status_info->st_att) { |
1080 | case MAILIMAP_STATUS_ATT_MESSAGES: | 1081 | case MAILIMAP_STATUS_ATT_MESSAGES: |
1081 | target_stat.message_count = status_info->st_value; | 1082 | target_stat.message_count = status_info->st_value; |
1082 | break; | 1083 | break; |
1083 | case MAILIMAP_STATUS_ATT_RECENT: | 1084 | case MAILIMAP_STATUS_ATT_RECENT: |
1084 | target_stat.message_recent = status_info->st_value; | 1085 | target_stat.message_recent = status_info->st_value; |
1085 | break; | 1086 | break; |
1086 | case MAILIMAP_STATUS_ATT_UNSEEN: | 1087 | case MAILIMAP_STATUS_ATT_UNSEEN: |
1087 | target_stat.message_unseen = status_info->st_value; | 1088 | target_stat.message_unseen = status_info->st_value; |
1088 | break; | 1089 | break; |
1089 | } | 1090 | } |
1090 | } | 1091 | } |
1091 | } else { | 1092 | } else { |
1092 | odebug << "Error retrieving status" << oendl; | 1093 | odebug << "Error retrieving status" << oendl; |
1093 | } | 1094 | } |
1094 | if (status) mailimap_mailbox_data_status_free(status); | 1095 | if (status) mailimap_mailbox_data_status_free(status); |
1095 | if (att_list) mailimap_status_att_list_free(att_list); | 1096 | if (att_list) mailimap_status_att_list_free(att_list); |
1096 | } | 1097 | } |
1097 | 1098 | ||
1098 | void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 1099 | void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
1099 | { | 1100 | { |
1100 | login(); | 1101 | login(); |
1101 | if (!m_imap) return; | 1102 | if (!m_imap) return; |
1102 | if (!msg) return; | 1103 | if (!msg) return; |
1103 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); | 1104 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); |
1104 | if (r != MAILIMAP_NO_ERROR) { | 1105 | if (r != MAILIMAP_NO_ERROR) { |
1105 | Global::statusMessage("Error storing mail!"); | 1106 | Global::statusMessage("Error storing mail!"); |
1106 | } | 1107 | } |
1107 | } | 1108 | } |
1108 | 1109 | ||
1109 | MAILLIB::ATYPE IMAPwrapper::getType()const | 1110 | MAILLIB::ATYPE IMAPwrapper::getType()const |
1110 | { | 1111 | { |
1111 | return account->getType(); | 1112 | return account->getType(); |
1112 | } | 1113 | } |
1113 | 1114 | ||
1114 | const QString&IMAPwrapper::getName()const | 1115 | const QString&IMAPwrapper::getName()const |
1115 | { | 1116 | { |
1116 | odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; | 1117 | odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; |
1117 | return account->getAccountName(); | 1118 | return account->getAccountName(); |
1118 | } | 1119 | } |
1119 | 1120 | ||
1120 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) | 1121 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) |
1121 | { | 1122 | { |
1122 | // dummy | 1123 | // dummy |
1123 | QValueList<int> path; | 1124 | QValueList<int> path; |
1124 | return fetchRawPart(mail,path,false); | 1125 | return fetchRawPart(mail,path,false); |
1125 | } | 1126 | } |
1126 | 1127 | ||
1127 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, | 1128 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, |
1128 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 1129 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
1129 | { | 1130 | { |
1130 | if (targetWrapper != this) { | 1131 | if (targetWrapper != this) { |
1131 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); | 1132 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); |
1132 | odebug << "Using generic" << oendl; | 1133 | odebug << "Using generic" << oendl; |
1133 | return; | 1134 | return; |
1134 | } | 1135 | } |
1135 | mailimap_set *set = 0; | 1136 | mailimap_set *set = 0; |
1136 | login(); | 1137 | login(); |
1137 | if (!m_imap) { | 1138 | if (!m_imap) { |
1138 | return; | 1139 | return; |
1139 | } | 1140 | } |
1140 | int err = selectMbox(fromFolder->getName()); | 1141 | int err = selectMbox(fromFolder->getName()); |
1141 | if ( err != MAILIMAP_NO_ERROR ) { | 1142 | if ( err != MAILIMAP_NO_ERROR ) { |
1142 | return; | 1143 | return; |
1143 | } | 1144 | } |
1144 | int last = m_imap->imap_selection_info->sel_exists; | 1145 | int last = m_imap->imap_selection_info->sel_exists; |
1145 | set = mailimap_set_new_interval( 1, last ); | 1146 | set = mailimap_set_new_interval( 1, last ); |
1146 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1147 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1147 | mailimap_set_free( set ); | 1148 | mailimap_set_free( set ); |
1148 | if ( err != MAILIMAP_NO_ERROR ) { | 1149 | if ( err != MAILIMAP_NO_ERROR ) { |
1149 | QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); | 1150 | QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); |
1150 | Global::statusMessage(error_msg); | 1151 | Global::statusMessage(error_msg); |
1151 | odebug << error_msg << oendl; | 1152 | odebug << error_msg << oendl; |
1152 | return; | 1153 | return; |
1153 | } | 1154 | } |
1154 | if (moveit) { | 1155 | if (moveit) { |
1155 | deleteAllMail(fromFolder); | 1156 | deleteAllMail(fromFolder); |
1156 | } | 1157 | } |
1157 | } | 1158 | } |
1158 | 1159 | ||
1159 | void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 1160 | void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
1160 | { | 1161 | { |
1161 | if (targetWrapper != this) { | 1162 | if (targetWrapper != this) { |
1162 | odebug << "Using generic" << oendl; | 1163 | odebug << "Using generic" << oendl; |
1163 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); | 1164 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); |
1164 | return; | 1165 | return; |
1165 | } | 1166 | } |
1166 | mailimap_set *set = 0; | 1167 | mailimap_set *set = 0; |
1167 | login(); | 1168 | login(); |
1168 | if (!m_imap) { | 1169 | if (!m_imap) { |
1169 | return; | 1170 | return; |
1170 | } | 1171 | } |
1171 | int err = selectMbox(mail->getMbox()); | 1172 | int err = selectMbox(mail->getMbox()); |
1172 | if ( err != MAILIMAP_NO_ERROR ) { | 1173 | if ( err != MAILIMAP_NO_ERROR ) { |
1173 | return; | 1174 | return; |
1174 | } | 1175 | } |
1175 | set = mailimap_set_new_single(mail->getNumber()); | 1176 | set = mailimap_set_new_single(mail->getNumber()); |
1176 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1177 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1177 | mailimap_set_free( set ); | 1178 | mailimap_set_free( set ); |
1178 | if ( err != MAILIMAP_NO_ERROR ) { | 1179 | if ( err != MAILIMAP_NO_ERROR ) { |
1179 | QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); | 1180 | QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); |
1180 | Global::statusMessage(error_msg); | 1181 | Global::statusMessage(error_msg); |
1181 | odebug << error_msg << oendl; | 1182 | odebug << error_msg << oendl; |
1182 | return; | 1183 | return; |
1183 | } | 1184 | } |
1184 | if (moveit) { | 1185 | if (moveit) { |
1185 | deleteMail(mail); | 1186 | deleteMail(mail); |
1186 | } | 1187 | } |
1187 | } | 1188 | } |
diff --git a/noncore/net/mail/libmailwrapper/logindialog.cpp b/noncore/net/mail/libmailwrapper/logindialog.cpp index c9ae190..ce705b2 100644 --- a/noncore/net/mail/libmailwrapper/logindialog.cpp +++ b/noncore/net/mail/libmailwrapper/logindialog.cpp | |||
@@ -1,29 +1,33 @@ | |||
1 | #include <qlineedit.h> | 1 | #include <qlineedit.h> |
2 | 2 | ||
3 | #include "logindialog.h" | 3 | #include "logindialog.h" |
4 | 4 | ||
5 | #include <opie2/odebug.h> | ||
6 | |||
7 | using namespace Opie::Core; | ||
8 | |||
5 | LoginDialog::LoginDialog(const QString&user,const QString&pass, QWidget *parent, const char *name, bool modal, WFlags flags ) | 9 | LoginDialog::LoginDialog(const QString&user,const QString&pass, QWidget *parent, const char *name, bool modal, WFlags flags ) |
6 | : LoginDialogUI( parent, name, modal, flags ) | 10 | : LoginDialogUI( parent, name, modal, flags ) |
7 | { | 11 | { |
8 | userLine->setText( (user.isEmpty()?QString(""):user) ); | 12 | userLine->setText( (user.isEmpty()?QString(""):user) ); |
9 | passLine->setText( (pass.isEmpty()?QString(""):pass) ); | 13 | passLine->setText( (pass.isEmpty()?QString(""):pass) ); |
10 | _user = user; | 14 | _user = user; |
11 | _pass = pass; | 15 | _pass = pass; |
12 | 16 | ||
13 | if ( user.isEmpty() ) { | 17 | if ( user.isEmpty() ) { |
14 | userLine->setFocus(); | 18 | userLine->setFocus(); |
15 | } else { | 19 | } else { |
16 | passLine->setFocus(); | 20 | passLine->setFocus(); |
17 | } | 21 | } |
18 | } | 22 | } |
19 | 23 | ||
20 | void LoginDialog::accept() | 24 | void LoginDialog::accept() |
21 | { | 25 | { |
22 | //_user.replace( 0, _user.length(), userLine->text() ); | 26 | //_user.replace( 0, _user.length(), userLine->text() ); |
23 | //_pass.replace( 0, _pass.length(), passLine->text() ); | 27 | //_pass.replace( 0, _pass.length(), passLine->text() ); |
24 | _user = userLine->text(); | 28 | _user = userLine->text(); |
25 | _pass = passLine->text(); | 29 | _pass = passLine->text(); |
26 | 30 | ||
27 | odebug << "User im accept: |" << _user.latin1() << "|" << oendl; | 31 | odebug << "User im accept: |" << _user.latin1() << "|" << oendl; |
28 | QDialog::accept(); | 32 | QDialog::accept(); |
29 | } | 33 | } |
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.cpp b/noncore/net/mail/libmailwrapper/mailtypes.cpp index 6d44db4..d4395a2 100644 --- a/noncore/net/mail/libmailwrapper/mailtypes.cpp +++ b/noncore/net/mail/libmailwrapper/mailtypes.cpp | |||
@@ -1,396 +1,399 @@ | |||
1 | #include "mailtypes.h" | 1 | #include "mailtypes.h" |
2 | |||
3 | #include <opie2/odebug.h> | ||
4 | |||
2 | #include <stdlib.h> | 5 | #include <stdlib.h> |
3 | 6 | ||
4 | using namespace Opie::Core; | 7 | using namespace Opie::Core; |
5 | RecMail::RecMail() | 8 | RecMail::RecMail() |
6 | :Opie::Core::ORefCount(),subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) | 9 | :Opie::Core::ORefCount(),subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) |
7 | { | 10 | { |
8 | init(); | 11 | init(); |
9 | } | 12 | } |
10 | 13 | ||
11 | RecMail::RecMail(const RecMail&old) | 14 | RecMail::RecMail(const RecMail&old) |
12 | :Opie::Core::ORefCount(),subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) | 15 | :Opie::Core::ORefCount(),subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) |
13 | { | 16 | { |
14 | init(); | 17 | init(); |
15 | copy_old(old); | 18 | copy_old(old); |
16 | odebug << "Copy constructor RecMail" << oendl; | 19 | odebug << "Copy constructor RecMail" << oendl; |
17 | } | 20 | } |
18 | 21 | ||
19 | RecMail::~RecMail() | 22 | RecMail::~RecMail() |
20 | { | 23 | { |
21 | wrapper = 0; | 24 | wrapper = 0; |
22 | } | 25 | } |
23 | 26 | ||
24 | void RecMail::copy_old(const RecMail&old) | 27 | void RecMail::copy_old(const RecMail&old) |
25 | { | 28 | { |
26 | subject = old.subject; | 29 | subject = old.subject; |
27 | date = old.date; | 30 | date = old.date; |
28 | mbox = old.mbox; | 31 | mbox = old.mbox; |
29 | msg_id = old.msg_id; | 32 | msg_id = old.msg_id; |
30 | msg_size = old.msg_size; | 33 | msg_size = old.msg_size; |
31 | msg_number = old.msg_number; | 34 | msg_number = old.msg_number; |
32 | from = old.from; | 35 | from = old.from; |
33 | msg_flags = old.msg_flags; | 36 | msg_flags = old.msg_flags; |
34 | to = old.to; | 37 | to = old.to; |
35 | cc = old.cc; | 38 | cc = old.cc; |
36 | bcc = old.bcc; | 39 | bcc = old.bcc; |
37 | wrapper = old.wrapper; | 40 | wrapper = old.wrapper; |
38 | in_reply_to = old.in_reply_to; | 41 | in_reply_to = old.in_reply_to; |
39 | references = old.references; | 42 | references = old.references; |
40 | replyto = old.replyto; | 43 | replyto = old.replyto; |
41 | } | 44 | } |
42 | 45 | ||
43 | void RecMail::init() | 46 | void RecMail::init() |
44 | { | 47 | { |
45 | to.clear(); | 48 | to.clear(); |
46 | cc.clear(); | 49 | cc.clear(); |
47 | bcc.clear(); | 50 | bcc.clear(); |
48 | in_reply_to.clear(); | 51 | in_reply_to.clear(); |
49 | references.clear(); | 52 | references.clear(); |
50 | wrapper = 0; | 53 | wrapper = 0; |
51 | } | 54 | } |
52 | 55 | ||
53 | void RecMail::setWrapper(AbstractMail*awrapper) | 56 | void RecMail::setWrapper(AbstractMail*awrapper) |
54 | { | 57 | { |
55 | wrapper = awrapper; | 58 | wrapper = awrapper; |
56 | } | 59 | } |
57 | 60 | ||
58 | AbstractMail* RecMail::Wrapper() | 61 | AbstractMail* RecMail::Wrapper() |
59 | { | 62 | { |
60 | return wrapper; | 63 | return wrapper; |
61 | } | 64 | } |
62 | 65 | ||
63 | void RecMail::setTo(const QStringList&list) | 66 | void RecMail::setTo(const QStringList&list) |
64 | { | 67 | { |
65 | to = list; | 68 | to = list; |
66 | } | 69 | } |
67 | 70 | ||
68 | const QStringList&RecMail::To()const | 71 | const QStringList&RecMail::To()const |
69 | { | 72 | { |
70 | return to; | 73 | return to; |
71 | } | 74 | } |
72 | 75 | ||
73 | void RecMail::setCC(const QStringList&list) | 76 | void RecMail::setCC(const QStringList&list) |
74 | { | 77 | { |
75 | cc = list; | 78 | cc = list; |
76 | } | 79 | } |
77 | 80 | ||
78 | const QStringList&RecMail::CC()const | 81 | const QStringList&RecMail::CC()const |
79 | { | 82 | { |
80 | return cc; | 83 | return cc; |
81 | } | 84 | } |
82 | 85 | ||
83 | void RecMail::setBcc(const QStringList&list) | 86 | void RecMail::setBcc(const QStringList&list) |
84 | { | 87 | { |
85 | bcc = list; | 88 | bcc = list; |
86 | } | 89 | } |
87 | 90 | ||
88 | const QStringList& RecMail::Bcc()const | 91 | const QStringList& RecMail::Bcc()const |
89 | { | 92 | { |
90 | return bcc; | 93 | return bcc; |
91 | } | 94 | } |
92 | 95 | ||
93 | void RecMail::setInreply(const QStringList&list) | 96 | void RecMail::setInreply(const QStringList&list) |
94 | { | 97 | { |
95 | in_reply_to = list; | 98 | in_reply_to = list; |
96 | } | 99 | } |
97 | 100 | ||
98 | const QStringList& RecMail::Inreply()const | 101 | const QStringList& RecMail::Inreply()const |
99 | { | 102 | { |
100 | return in_reply_to; | 103 | return in_reply_to; |
101 | } | 104 | } |
102 | 105 | ||
103 | void RecMail::setReferences(const QStringList&list) | 106 | void RecMail::setReferences(const QStringList&list) |
104 | { | 107 | { |
105 | references = list; | 108 | references = list; |
106 | } | 109 | } |
107 | 110 | ||
108 | const QStringList& RecMail::References()const | 111 | const QStringList& RecMail::References()const |
109 | { | 112 | { |
110 | return references; | 113 | return references; |
111 | } | 114 | } |
112 | 115 | ||
113 | RecPart::RecPart() | 116 | RecPart::RecPart() |
114 | : Opie::Core::ORefCount(), | 117 | : Opie::Core::ORefCount(), |
115 | m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) | 118 | m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) |
116 | { | 119 | { |
117 | m_Parameters.clear(); | 120 | m_Parameters.clear(); |
118 | m_poslist.clear(); | 121 | m_poslist.clear(); |
119 | } | 122 | } |
120 | 123 | ||
121 | RecPart::RecPart(const RecPart&old) | 124 | RecPart::RecPart(const RecPart&old) |
122 | : Opie::Core::ORefCount(), | 125 | : Opie::Core::ORefCount(), |
123 | m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) | 126 | m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) |
124 | { | 127 | { |
125 | m_type = old.m_type; | 128 | m_type = old.m_type; |
126 | m_subtype = old.m_subtype; | 129 | m_subtype = old.m_subtype; |
127 | m_identifier = old.m_identifier; | 130 | m_identifier = old.m_identifier; |
128 | m_encoding = old.m_encoding; | 131 | m_encoding = old.m_encoding; |
129 | m_description = old.m_description; | 132 | m_description = old.m_description; |
130 | m_lines = old.m_lines; | 133 | m_lines = old.m_lines; |
131 | m_size = old.m_size; | 134 | m_size = old.m_size; |
132 | m_Parameters = old.m_Parameters; | 135 | m_Parameters = old.m_Parameters; |
133 | m_poslist = old.m_poslist; | 136 | m_poslist = old.m_poslist; |
134 | odebug << "RecPart copy constructor" << oendl; | 137 | odebug << "RecPart copy constructor" << oendl; |
135 | } | 138 | } |
136 | 139 | ||
137 | RecPart::~RecPart() | 140 | RecPart::~RecPart() |
138 | { | 141 | { |
139 | } | 142 | } |
140 | 143 | ||
141 | void RecPart::setSize(unsigned int size) | 144 | void RecPart::setSize(unsigned int size) |
142 | { | 145 | { |
143 | m_size = size; | 146 | m_size = size; |
144 | } | 147 | } |
145 | 148 | ||
146 | const unsigned int RecPart::Size()const | 149 | const unsigned int RecPart::Size()const |
147 | { | 150 | { |
148 | return m_size; | 151 | return m_size; |
149 | } | 152 | } |
150 | 153 | ||
151 | void RecPart::setLines(unsigned int lines) | 154 | void RecPart::setLines(unsigned int lines) |
152 | { | 155 | { |
153 | m_lines = lines; | 156 | m_lines = lines; |
154 | } | 157 | } |
155 | 158 | ||
156 | const unsigned int RecPart::Lines()const | 159 | const unsigned int RecPart::Lines()const |
157 | { | 160 | { |
158 | return m_lines; | 161 | return m_lines; |
159 | } | 162 | } |
160 | 163 | ||
161 | const QString& RecPart::Type()const | 164 | const QString& RecPart::Type()const |
162 | { | 165 | { |
163 | return m_type; | 166 | return m_type; |
164 | } | 167 | } |
165 | 168 | ||
166 | void RecPart::setType(const QString&type) | 169 | void RecPart::setType(const QString&type) |
167 | { | 170 | { |
168 | m_type = type; | 171 | m_type = type; |
169 | } | 172 | } |
170 | 173 | ||
171 | const QString& RecPart::Subtype()const | 174 | const QString& RecPart::Subtype()const |
172 | { | 175 | { |
173 | return m_subtype; | 176 | return m_subtype; |
174 | } | 177 | } |
175 | 178 | ||
176 | void RecPart::setSubtype(const QString&subtype) | 179 | void RecPart::setSubtype(const QString&subtype) |
177 | { | 180 | { |
178 | m_subtype = subtype; | 181 | m_subtype = subtype; |
179 | } | 182 | } |
180 | 183 | ||
181 | const QString& RecPart::Identifier()const | 184 | const QString& RecPart::Identifier()const |
182 | { | 185 | { |
183 | return m_identifier; | 186 | return m_identifier; |
184 | } | 187 | } |
185 | 188 | ||
186 | void RecPart::setIdentifier(const QString&identifier) | 189 | void RecPart::setIdentifier(const QString&identifier) |
187 | { | 190 | { |
188 | m_identifier = identifier; | 191 | m_identifier = identifier; |
189 | } | 192 | } |
190 | 193 | ||
191 | const QString& RecPart::Encoding()const | 194 | const QString& RecPart::Encoding()const |
192 | { | 195 | { |
193 | return m_encoding; | 196 | return m_encoding; |
194 | } | 197 | } |
195 | 198 | ||
196 | void RecPart::setEncoding(const QString&encoding) | 199 | void RecPart::setEncoding(const QString&encoding) |
197 | { | 200 | { |
198 | m_encoding = encoding; | 201 | m_encoding = encoding; |
199 | } | 202 | } |
200 | 203 | ||
201 | const QString& RecPart::Description()const | 204 | const QString& RecPart::Description()const |
202 | { | 205 | { |
203 | return m_description; | 206 | return m_description; |
204 | } | 207 | } |
205 | 208 | ||
206 | void RecPart::setDescription(const QString&desc) | 209 | void RecPart::setDescription(const QString&desc) |
207 | { | 210 | { |
208 | m_description = desc; | 211 | m_description = desc; |
209 | } | 212 | } |
210 | 213 | ||
211 | void RecPart::setParameters(const part_plist_t&list) | 214 | void RecPart::setParameters(const part_plist_t&list) |
212 | { | 215 | { |
213 | m_Parameters = list; | 216 | m_Parameters = list; |
214 | } | 217 | } |
215 | 218 | ||
216 | const part_plist_t& RecPart::Parameters()const | 219 | const part_plist_t& RecPart::Parameters()const |
217 | { | 220 | { |
218 | return m_Parameters; | 221 | return m_Parameters; |
219 | } | 222 | } |
220 | 223 | ||
221 | void RecPart::addParameter(const QString&key,const QString&value) | 224 | void RecPart::addParameter(const QString&key,const QString&value) |
222 | { | 225 | { |
223 | m_Parameters[key]=value; | 226 | m_Parameters[key]=value; |
224 | } | 227 | } |
225 | 228 | ||
226 | const QString RecPart::searchParamter(const QString&key)const | 229 | const QString RecPart::searchParamter(const QString&key)const |
227 | { | 230 | { |
228 | QString value(""); | 231 | QString value(""); |
229 | part_plist_t::ConstIterator it = m_Parameters.find(key); | 232 | part_plist_t::ConstIterator it = m_Parameters.find(key); |
230 | if (it != m_Parameters.end()) { | 233 | if (it != m_Parameters.end()) { |
231 | value = it.data(); | 234 | value = it.data(); |
232 | } | 235 | } |
233 | return value; | 236 | return value; |
234 | } | 237 | } |
235 | 238 | ||
236 | void RecPart::setPositionlist(const QValueList<int>&poslist) | 239 | void RecPart::setPositionlist(const QValueList<int>&poslist) |
237 | { | 240 | { |
238 | m_poslist = poslist; | 241 | m_poslist = poslist; |
239 | } | 242 | } |
240 | 243 | ||
241 | const QValueList<int>& RecPart::Positionlist()const | 244 | const QValueList<int>& RecPart::Positionlist()const |
242 | { | 245 | { |
243 | return m_poslist; | 246 | return m_poslist; |
244 | } | 247 | } |
245 | 248 | ||
246 | RecBody::RecBody() | 249 | RecBody::RecBody() |
247 | : Opie::Core::ORefCount(),m_BodyText(),m_description(new RecPart()) | 250 | : Opie::Core::ORefCount(),m_BodyText(),m_description(new RecPart()) |
248 | { | 251 | { |
249 | m_PartsList.clear(); | 252 | m_PartsList.clear(); |
250 | } | 253 | } |
251 | 254 | ||
252 | RecBody::RecBody(const RecBody&old) | 255 | RecBody::RecBody(const RecBody&old) |
253 | :Opie::Core::ORefCount(),m_BodyText(),m_PartsList(),m_description(new RecPart()) | 256 | :Opie::Core::ORefCount(),m_BodyText(),m_PartsList(),m_description(new RecPart()) |
254 | { | 257 | { |
255 | m_BodyText = old.m_BodyText; | 258 | m_BodyText = old.m_BodyText; |
256 | m_PartsList = old.m_PartsList; | 259 | m_PartsList = old.m_PartsList; |
257 | m_description = old.m_description; | 260 | m_description = old.m_description; |
258 | odebug << "Recbody copy constructor" << oendl; | 261 | odebug << "Recbody copy constructor" << oendl; |
259 | } | 262 | } |
260 | 263 | ||
261 | RecBody::~RecBody() | 264 | RecBody::~RecBody() |
262 | { | 265 | { |
263 | } | 266 | } |
264 | 267 | ||
265 | void RecBody::setBodytext(const QString&bodyText) | 268 | void RecBody::setBodytext(const QString&bodyText) |
266 | { | 269 | { |
267 | m_BodyText = bodyText; | 270 | m_BodyText = bodyText; |
268 | } | 271 | } |
269 | 272 | ||
270 | const QString& RecBody::Bodytext()const | 273 | const QString& RecBody::Bodytext()const |
271 | { | 274 | { |
272 | return m_BodyText; | 275 | return m_BodyText; |
273 | } | 276 | } |
274 | 277 | ||
275 | void RecBody::setParts(const QValueList<RecPartP>&parts) | 278 | void RecBody::setParts(const QValueList<RecPartP>&parts) |
276 | { | 279 | { |
277 | m_PartsList.clear(); | 280 | m_PartsList.clear(); |
278 | m_PartsList = parts; | 281 | m_PartsList = parts; |
279 | } | 282 | } |
280 | 283 | ||
281 | const QValueList<RecPartP>& RecBody::Parts()const | 284 | const QValueList<RecPartP>& RecBody::Parts()const |
282 | { | 285 | { |
283 | return m_PartsList; | 286 | return m_PartsList; |
284 | } | 287 | } |
285 | 288 | ||
286 | void RecBody::addPart(const RecPartP& part) | 289 | void RecBody::addPart(const RecPartP& part) |
287 | { | 290 | { |
288 | m_PartsList.append(part); | 291 | m_PartsList.append(part); |
289 | } | 292 | } |
290 | 293 | ||
291 | void RecBody::setDescription(const RecPartP&des) | 294 | void RecBody::setDescription(const RecPartP&des) |
292 | { | 295 | { |
293 | m_description = des; | 296 | m_description = des; |
294 | } | 297 | } |
295 | 298 | ||
296 | const RecPartP& RecBody::Description()const | 299 | const RecPartP& RecBody::Description()const |
297 | { | 300 | { |
298 | return m_description; | 301 | return m_description; |
299 | } | 302 | } |
300 | 303 | ||
301 | /* handling encoded content */ | 304 | /* handling encoded content */ |
302 | encodedString::encodedString() | 305 | encodedString::encodedString() |
303 | { | 306 | { |
304 | init(); | 307 | init(); |
305 | } | 308 | } |
306 | 309 | ||
307 | encodedString::encodedString(const char*nContent,unsigned int nSize) | 310 | encodedString::encodedString(const char*nContent,unsigned int nSize) |
308 | { | 311 | { |
309 | init(); | 312 | init(); |
310 | setContent(nContent,nSize); | 313 | setContent(nContent,nSize); |
311 | } | 314 | } |
312 | 315 | ||
313 | encodedString::encodedString(char*nContent,unsigned int nSize) | 316 | encodedString::encodedString(char*nContent,unsigned int nSize) |
314 | { | 317 | { |
315 | init(); | 318 | init(); |
316 | setContent(nContent,nSize); | 319 | setContent(nContent,nSize); |
317 | } | 320 | } |
318 | 321 | ||
319 | encodedString::encodedString(const encodedString&old) | 322 | encodedString::encodedString(const encodedString&old) |
320 | { | 323 | { |
321 | init(); | 324 | init(); |
322 | copy_old(old); | 325 | copy_old(old); |
323 | odebug << "encodedeString: copy constructor!" << oendl; | 326 | odebug << "encodedeString: copy constructor!" << oendl; |
324 | } | 327 | } |
325 | 328 | ||
326 | encodedString& encodedString::operator=(const encodedString&old) | 329 | encodedString& encodedString::operator=(const encodedString&old) |
327 | { | 330 | { |
328 | init(); | 331 | init(); |
329 | copy_old(old); | 332 | copy_old(old); |
330 | odebug << "encodedString: assign operator!" << oendl; | 333 | odebug << "encodedString: assign operator!" << oendl; |
331 | return *this; | 334 | return *this; |
332 | } | 335 | } |
333 | 336 | ||
334 | encodedString::~encodedString() | 337 | encodedString::~encodedString() |
335 | { | 338 | { |
336 | clean(); | 339 | clean(); |
337 | } | 340 | } |
338 | 341 | ||
339 | void encodedString::init() | 342 | void encodedString::init() |
340 | { | 343 | { |
341 | content = 0; | 344 | content = 0; |
342 | size = 0; | 345 | size = 0; |
343 | } | 346 | } |
344 | 347 | ||
345 | void encodedString::clean() | 348 | void encodedString::clean() |
346 | { | 349 | { |
347 | if (content) { | 350 | if (content) { |
348 | free(content); | 351 | free(content); |
349 | } | 352 | } |
350 | content = 0; | 353 | content = 0; |
351 | size = 0; | 354 | size = 0; |
352 | } | 355 | } |
353 | 356 | ||
354 | void encodedString::copy_old(const encodedString&old) | 357 | void encodedString::copy_old(const encodedString&old) |
355 | { | 358 | { |
356 | clean(); | 359 | clean(); |
357 | if (old.size>0 && old.content) { | 360 | if (old.size>0 && old.content) { |
358 | content = (char*)malloc(old.size*sizeof(char)); | 361 | content = (char*)malloc(old.size*sizeof(char)); |
359 | memcpy(content,old.content,size); | 362 | memcpy(content,old.content,size); |
360 | size = old.size; | 363 | size = old.size; |
361 | } | 364 | } |
362 | } | 365 | } |
363 | 366 | ||
364 | const char*encodedString::Content()const | 367 | const char*encodedString::Content()const |
365 | { | 368 | { |
366 | return content; | 369 | return content; |
367 | } | 370 | } |
368 | 371 | ||
369 | const int encodedString::Length()const | 372 | const int encodedString::Length()const |
370 | { | 373 | { |
371 | return size; | 374 | return size; |
372 | } | 375 | } |
373 | 376 | ||
374 | void encodedString::setContent(const char*nContent,int nSize) | 377 | void encodedString::setContent(const char*nContent,int nSize) |
375 | { | 378 | { |
376 | if (nSize>0 && nContent) { | 379 | if (nSize>0 && nContent) { |
377 | content = (char*)malloc(nSize*sizeof(char)); | 380 | content = (char*)malloc(nSize*sizeof(char)); |
378 | memcpy(content,nContent,nSize); | 381 | memcpy(content,nContent,nSize); |
379 | size = nSize; | 382 | size = nSize; |
380 | } | 383 | } |
381 | } | 384 | } |
382 | 385 | ||
383 | void encodedString::setContent(char*nContent,int nSize) | 386 | void encodedString::setContent(char*nContent,int nSize) |
384 | { | 387 | { |
385 | content = nContent; | 388 | content = nContent; |
386 | size = nSize; | 389 | size = nSize; |
387 | } | 390 | } |
388 | 391 | ||
389 | folderStat&folderStat::operator=(const folderStat&old) | 392 | folderStat&folderStat::operator=(const folderStat&old) |
390 | { | 393 | { |
391 | message_count = old.message_count; | 394 | message_count = old.message_count; |
392 | message_unseen = old.message_unseen; | 395 | message_unseen = old.message_unseen; |
393 | message_recent = old.message_recent; | 396 | message_recent = old.message_recent; |
394 | return *this; | 397 | return *this; |
395 | } | 398 | } |
396 | 399 | ||
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp index df2112f..a030cca 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp | |||
@@ -1,336 +1,338 @@ | |||
1 | #include "mboxwrapper.h" | 1 | #include "mboxwrapper.h" |
2 | #include "mailtypes.h" | 2 | #include "mailtypes.h" |
3 | #include "mailwrapper.h" | 3 | #include "mailwrapper.h" |
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | #include <qdir.h> | 5 | #include <qdir.h> |
6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
7 | |||
8 | #include <opie2/odebug.h> | ||
7 | #include <qpe/global.h> | 9 | #include <qpe/global.h> |
8 | 10 | ||
9 | using namespace Opie::Core; | 11 | using namespace Opie::Core; |
10 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name) | 12 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name) |
11 | : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name) | 13 | : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name) |
12 | { | 14 | { |
13 | QDir dir(MBOXPath); | 15 | QDir dir(MBOXPath); |
14 | if (!dir.exists()) { | 16 | if (!dir.exists()) { |
15 | dir.mkdir(MBOXPath); | 17 | dir.mkdir(MBOXPath); |
16 | } | 18 | } |
17 | } | 19 | } |
18 | 20 | ||
19 | MBOXwrapper::~MBOXwrapper() | 21 | MBOXwrapper::~MBOXwrapper() |
20 | { | 22 | { |
21 | } | 23 | } |
22 | 24 | ||
23 | void MBOXwrapper::listMessages(const QString & mailbox, QValueList<RecMailP> &target ) | 25 | void MBOXwrapper::listMessages(const QString & mailbox, QValueList<RecMailP> &target ) |
24 | { | 26 | { |
25 | mailstorage*storage = mailstorage_new(NULL); | 27 | mailstorage*storage = mailstorage_new(NULL); |
26 | QString p = MBOXPath+"/"; | 28 | QString p = MBOXPath+"/"; |
27 | p+=mailbox; | 29 | p+=mailbox; |
28 | 30 | ||
29 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 31 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
30 | mailfolder*folder; | 32 | mailfolder*folder; |
31 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 33 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
32 | r = mailfolder_connect(folder); | 34 | r = mailfolder_connect(folder); |
33 | if (r != MAIL_NO_ERROR) { | 35 | if (r != MAIL_NO_ERROR) { |
34 | odebug << "Error initializing mbox" << oendl; | 36 | odebug << "Error initializing mbox" << oendl; |
35 | mailfolder_free(folder); | 37 | mailfolder_free(folder); |
36 | mailstorage_free(storage); | 38 | mailstorage_free(storage); |
37 | return; | 39 | return; |
38 | } | 40 | } |
39 | 41 | ||
40 | parseList(target,folder->fld_session,mailbox); | 42 | parseList(target,folder->fld_session,mailbox); |
41 | 43 | ||
42 | mailfolder_disconnect(folder); | 44 | mailfolder_disconnect(folder); |
43 | mailfolder_free(folder); | 45 | mailfolder_free(folder); |
44 | mailstorage_free(storage); | 46 | mailstorage_free(storage); |
45 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); | 47 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); |
46 | } | 48 | } |
47 | 49 | ||
48 | QValueList<Opie::Core::OSmartPointer<Folder> >* MBOXwrapper::listFolders() | 50 | QValueList<Opie::Core::OSmartPointer<Folder> >* MBOXwrapper::listFolders() |
49 | { | 51 | { |
50 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); | 52 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); |
51 | QDir dir(MBOXPath); | 53 | QDir dir(MBOXPath); |
52 | if (!dir.exists()) return folders; | 54 | if (!dir.exists()) return folders; |
53 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); | 55 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); |
54 | QStringList entries = dir.entryList(); | 56 | QStringList entries = dir.entryList(); |
55 | QStringList::ConstIterator it = entries.begin(); | 57 | QStringList::ConstIterator it = entries.begin(); |
56 | for (;it!=entries.end();++it) { | 58 | for (;it!=entries.end();++it) { |
57 | FolderP inb=new Folder(*it,"/"); | 59 | FolderP inb=new Folder(*it,"/"); |
58 | folders->append(inb); | 60 | folders->append(inb); |
59 | } | 61 | } |
60 | return folders; | 62 | return folders; |
61 | } | 63 | } |
62 | 64 | ||
63 | void MBOXwrapper::deleteMail(const RecMailP & mail) | 65 | void MBOXwrapper::deleteMail(const RecMailP & mail) |
64 | { | 66 | { |
65 | mailstorage*storage = mailstorage_new(NULL); | 67 | mailstorage*storage = mailstorage_new(NULL); |
66 | QString p = MBOXPath+"/"; | 68 | QString p = MBOXPath+"/"; |
67 | p+=mail->getMbox(); | 69 | p+=mail->getMbox(); |
68 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 70 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
69 | mailfolder*folder; | 71 | mailfolder*folder; |
70 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 72 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
71 | r = mailfolder_connect(folder); | 73 | r = mailfolder_connect(folder); |
72 | if (r != MAIL_NO_ERROR) { | 74 | if (r != MAIL_NO_ERROR) { |
73 | odebug << "Error initializing mbox" << oendl; | 75 | odebug << "Error initializing mbox" << oendl; |
74 | mailfolder_free(folder); | 76 | mailfolder_free(folder); |
75 | mailstorage_free(storage); | 77 | mailstorage_free(storage); |
76 | return; | 78 | return; |
77 | } | 79 | } |
78 | r = mailsession_remove_message(folder->fld_session,mail->getNumber()); | 80 | r = mailsession_remove_message(folder->fld_session,mail->getNumber()); |
79 | if (r != MAIL_NO_ERROR) { | 81 | if (r != MAIL_NO_ERROR) { |
80 | odebug << "error deleting mail" << oendl; | 82 | odebug << "error deleting mail" << oendl; |
81 | } | 83 | } |
82 | mailfolder_free(folder); | 84 | mailfolder_free(folder); |
83 | mailstorage_free(storage); | 85 | mailstorage_free(storage); |
84 | } | 86 | } |
85 | 87 | ||
86 | void MBOXwrapper::answeredMail(const RecMailP&) | 88 | void MBOXwrapper::answeredMail(const RecMailP&) |
87 | { | 89 | { |
88 | } | 90 | } |
89 | 91 | ||
90 | RecBodyP MBOXwrapper::fetchBody( const RecMailP &mail ) | 92 | RecBodyP MBOXwrapper::fetchBody( const RecMailP &mail ) |
91 | { | 93 | { |
92 | RecBodyP body = new RecBody(); | 94 | RecBodyP body = new RecBody(); |
93 | mailstorage*storage = mailstorage_new(NULL); | 95 | mailstorage*storage = mailstorage_new(NULL); |
94 | QString p = MBOXPath+"/"; | 96 | QString p = MBOXPath+"/"; |
95 | p+=mail->getMbox(); | 97 | p+=mail->getMbox(); |
96 | mailmessage * msg; | 98 | mailmessage * msg; |
97 | char*data=0; | 99 | char*data=0; |
98 | size_t size; | 100 | size_t size; |
99 | 101 | ||
100 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 102 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
101 | mailfolder*folder; | 103 | mailfolder*folder; |
102 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 104 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
103 | r = mailfolder_connect(folder); | 105 | r = mailfolder_connect(folder); |
104 | if (r != MAIL_NO_ERROR) { | 106 | if (r != MAIL_NO_ERROR) { |
105 | odebug << "Error initializing mbox" << oendl; | 107 | odebug << "Error initializing mbox" << oendl; |
106 | mailfolder_free(folder); | 108 | mailfolder_free(folder); |
107 | mailstorage_free(storage); | 109 | mailstorage_free(storage); |
108 | return body; | 110 | return body; |
109 | } | 111 | } |
110 | r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); | 112 | r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); |
111 | if (r != MAIL_NO_ERROR) { | 113 | if (r != MAIL_NO_ERROR) { |
112 | odebug << "Error fetching mail " << mail->getNumber() << "" << oendl; | 114 | odebug << "Error fetching mail " << mail->getNumber() << "" << oendl; |
113 | mailfolder_free(folder); | 115 | mailfolder_free(folder); |
114 | mailstorage_free(storage); | 116 | mailstorage_free(storage); |
115 | return body; | 117 | return body; |
116 | } | 118 | } |
117 | r = mailmessage_fetch(msg,&data,&size); | 119 | r = mailmessage_fetch(msg,&data,&size); |
118 | if (r != MAIL_NO_ERROR) { | 120 | if (r != MAIL_NO_ERROR) { |
119 | odebug << "Error fetching mail " << mail->getNumber() << "" << oendl; | 121 | odebug << "Error fetching mail " << mail->getNumber() << "" << oendl; |
120 | mailfolder_free(folder); | 122 | mailfolder_free(folder); |
121 | mailstorage_free(storage); | 123 | mailstorage_free(storage); |
122 | mailmessage_free(msg); | 124 | mailmessage_free(msg); |
123 | return body; | 125 | return body; |
124 | } | 126 | } |
125 | body = parseMail(msg); | 127 | body = parseMail(msg); |
126 | mailmessage_fetch_result_free(msg,data); | 128 | mailmessage_fetch_result_free(msg,data); |
127 | mailfolder_free(folder); | 129 | mailfolder_free(folder); |
128 | mailstorage_free(storage); | 130 | mailstorage_free(storage); |
129 | 131 | ||
130 | return body; | 132 | return body; |
131 | } | 133 | } |
132 | 134 | ||
133 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) | 135 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) |
134 | { | 136 | { |
135 | odebug << "MBOX " << current << " von " << maximum << "" << oendl; | 137 | odebug << "MBOX " << current << " von " << maximum << "" << oendl; |
136 | } | 138 | } |
137 | 139 | ||
138 | int MBOXwrapper::createMbox(const QString&folder,const FolderP&,const QString&,bool ) | 140 | int MBOXwrapper::createMbox(const QString&folder,const FolderP&,const QString&,bool ) |
139 | { | 141 | { |
140 | QString p = MBOXPath+"/"; | 142 | QString p = MBOXPath+"/"; |
141 | p+=folder; | 143 | p+=folder; |
142 | QFileInfo fi(p); | 144 | QFileInfo fi(p); |
143 | if (fi.exists()) { | 145 | if (fi.exists()) { |
144 | Global::statusMessage(tr("Mailbox exists.")); | 146 | Global::statusMessage(tr("Mailbox exists.")); |
145 | return 0; | 147 | return 0; |
146 | } | 148 | } |
147 | mailmbox_folder*f = 0; | 149 | mailmbox_folder*f = 0; |
148 | if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { | 150 | if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { |
149 | Global::statusMessage(tr("Error init folder")); | 151 | Global::statusMessage(tr("Error init folder")); |
150 | return 0; | 152 | return 0; |
151 | } | 153 | } |
152 | if (f) mailmbox_done(f); | 154 | if (f) mailmbox_done(f); |
153 | return 1; | 155 | return 1; |
154 | } | 156 | } |
155 | 157 | ||
156 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 158 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
157 | { | 159 | { |
158 | QString p = MBOXPath+"/"; | 160 | QString p = MBOXPath+"/"; |
159 | p+=folder; | 161 | p+=folder; |
160 | mailmbox_folder*f = 0; | 162 | mailmbox_folder*f = 0; |
161 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 163 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
162 | if (r != MAIL_NO_ERROR) { | 164 | if (r != MAIL_NO_ERROR) { |
163 | Global::statusMessage(tr("Error init folder")); | 165 | Global::statusMessage(tr("Error init folder")); |
164 | return; | 166 | return; |
165 | } | 167 | } |
166 | r = mailmbox_append_message(f,msg,length); | 168 | r = mailmbox_append_message(f,msg,length); |
167 | if (r != MAIL_NO_ERROR) { | 169 | if (r != MAIL_NO_ERROR) { |
168 | Global::statusMessage(tr("Error writing to message folder")); | 170 | Global::statusMessage(tr("Error writing to message folder")); |
169 | } | 171 | } |
170 | mailmbox_done(f); | 172 | mailmbox_done(f); |
171 | } | 173 | } |
172 | 174 | ||
173 | encodedString* MBOXwrapper::fetchRawBody(const RecMailP&mail) | 175 | encodedString* MBOXwrapper::fetchRawBody(const RecMailP&mail) |
174 | { | 176 | { |
175 | RecBody body; | 177 | RecBody body; |
176 | mailstorage*storage = mailstorage_new(NULL); | 178 | mailstorage*storage = mailstorage_new(NULL); |
177 | QString p = MBOXPath+"/"; | 179 | QString p = MBOXPath+"/"; |
178 | p+=mail->getMbox(); | 180 | p+=mail->getMbox(); |
179 | mailmessage * msg; | 181 | mailmessage * msg; |
180 | char*data=0; | 182 | char*data=0; |
181 | size_t size; | 183 | size_t size; |
182 | 184 | ||
183 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 185 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
184 | mailfolder*folder; | 186 | mailfolder*folder; |
185 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 187 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
186 | r = mailfolder_connect(folder); | 188 | r = mailfolder_connect(folder); |
187 | if (r != MAIL_NO_ERROR) { | 189 | if (r != MAIL_NO_ERROR) { |
188 | Global::statusMessage(tr("Error initializing mbox")); | 190 | Global::statusMessage(tr("Error initializing mbox")); |
189 | mailfolder_free(folder); | 191 | mailfolder_free(folder); |
190 | mailstorage_free(storage); | 192 | mailstorage_free(storage); |
191 | return 0; | 193 | return 0; |
192 | } | 194 | } |
193 | r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); | 195 | r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); |
194 | if (r != MAIL_NO_ERROR) { | 196 | if (r != MAIL_NO_ERROR) { |
195 | Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); | 197 | Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); |
196 | mailfolder_free(folder); | 198 | mailfolder_free(folder); |
197 | mailstorage_free(storage); | 199 | mailstorage_free(storage); |
198 | return 0; | 200 | return 0; |
199 | } | 201 | } |
200 | r = mailmessage_fetch(msg,&data,&size); | 202 | r = mailmessage_fetch(msg,&data,&size); |
201 | if (r != MAIL_NO_ERROR) { | 203 | if (r != MAIL_NO_ERROR) { |
202 | Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); | 204 | Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); |
203 | mailfolder_free(folder); | 205 | mailfolder_free(folder); |
204 | mailstorage_free(storage); | 206 | mailstorage_free(storage); |
205 | mailmessage_free(msg); | 207 | mailmessage_free(msg); |
206 | return 0; | 208 | return 0; |
207 | } | 209 | } |
208 | encodedString*result = new encodedString(data,size); | 210 | encodedString*result = new encodedString(data,size); |
209 | 211 | ||
210 | mailfolder_free(folder); | 212 | mailfolder_free(folder); |
211 | mailstorage_free(storage); | 213 | mailstorage_free(storage); |
212 | mailmessage_free(msg); | 214 | mailmessage_free(msg); |
213 | return result; | 215 | return result; |
214 | } | 216 | } |
215 | 217 | ||
216 | void MBOXwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) | 218 | void MBOXwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) |
217 | { | 219 | { |
218 | QString p = MBOXPath+"/"; | 220 | QString p = MBOXPath+"/"; |
219 | p+=mailbox; | 221 | p+=mailbox; |
220 | mailmbox_folder*f = 0; | 222 | mailmbox_folder*f = 0; |
221 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 223 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
222 | if (r != MAIL_NO_ERROR) { | 224 | if (r != MAIL_NO_ERROR) { |
223 | odebug << "Error init folder" << oendl; | 225 | odebug << "Error init folder" << oendl; |
224 | return; | 226 | return; |
225 | } | 227 | } |
226 | deleteMails(f,target); | 228 | deleteMails(f,target); |
227 | mailmbox_done(f); | 229 | mailmbox_done(f); |
228 | } | 230 | } |
229 | 231 | ||
230 | void MBOXwrapper::deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target) | 232 | void MBOXwrapper::deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target) |
231 | { | 233 | { |
232 | if (!f) return; | 234 | if (!f) return; |
233 | int r; | 235 | int r; |
234 | QValueList<RecMailP>::ConstIterator it; | 236 | QValueList<RecMailP>::ConstIterator it; |
235 | for (it=target.begin(); it != target.end();++it) { | 237 | for (it=target.begin(); it != target.end();++it) { |
236 | r = mailmbox_delete_msg(f,(*it)->getNumber()); | 238 | r = mailmbox_delete_msg(f,(*it)->getNumber()); |
237 | if (r!=MAILMBOX_NO_ERROR) { | 239 | if (r!=MAILMBOX_NO_ERROR) { |
238 | odebug << "error delete mail" << oendl; | 240 | odebug << "error delete mail" << oendl; |
239 | } | 241 | } |
240 | } | 242 | } |
241 | r = mailmbox_expunge(f); | 243 | r = mailmbox_expunge(f); |
242 | if (r != MAILMBOX_NO_ERROR) { | 244 | if (r != MAILMBOX_NO_ERROR) { |
243 | odebug << "error expunge mailbox" << oendl; | 245 | odebug << "error expunge mailbox" << oendl; |
244 | } | 246 | } |
245 | } | 247 | } |
246 | 248 | ||
247 | int MBOXwrapper::deleteAllMail(const FolderP&tfolder) | 249 | int MBOXwrapper::deleteAllMail(const FolderP&tfolder) |
248 | { | 250 | { |
249 | if (!tfolder) return 0; | 251 | if (!tfolder) return 0; |
250 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); | 252 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); |
251 | int res = 1; | 253 | int res = 1; |
252 | 254 | ||
253 | mailfolder*folder = 0; | 255 | mailfolder*folder = 0; |
254 | mailmessage_list*l=0; | 256 | mailmessage_list*l=0; |
255 | mailstorage*storage = mailstorage_new(NULL); | 257 | mailstorage*storage = mailstorage_new(NULL); |
256 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 258 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
257 | if (r != MAIL_NO_ERROR) { | 259 | if (r != MAIL_NO_ERROR) { |
258 | Global::statusMessage(tr("Error initializing mbox")); | 260 | Global::statusMessage(tr("Error initializing mbox")); |
259 | res = 0; | 261 | res = 0; |
260 | } | 262 | } |
261 | if (res) { | 263 | if (res) { |
262 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 264 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
263 | r = mailfolder_connect(folder); | 265 | r = mailfolder_connect(folder); |
264 | if (r != MAIL_NO_ERROR) { | 266 | if (r != MAIL_NO_ERROR) { |
265 | Global::statusMessage(tr("Error initializing mbox")); | 267 | Global::statusMessage(tr("Error initializing mbox")); |
266 | res = 0; | 268 | res = 0; |
267 | } | 269 | } |
268 | } | 270 | } |
269 | if (res) { | 271 | if (res) { |
270 | r = mailsession_get_messages_list(folder->fld_session,&l); | 272 | r = mailsession_get_messages_list(folder->fld_session,&l); |
271 | if (r != MAIL_NO_ERROR) { | 273 | if (r != MAIL_NO_ERROR) { |
272 | odebug << "Error message list" << oendl; | 274 | odebug << "Error message list" << oendl; |
273 | res=0; | 275 | res=0; |
274 | } | 276 | } |
275 | } | 277 | } |
276 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | 278 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { |
277 | r = mailsession_remove_message(folder->fld_session,i+1); | 279 | r = mailsession_remove_message(folder->fld_session,i+1); |
278 | if (r != MAIL_NO_ERROR) { | 280 | if (r != MAIL_NO_ERROR) { |
279 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 281 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
280 | res = 0; | 282 | res = 0; |
281 | break; | 283 | break; |
282 | } | 284 | } |
283 | } | 285 | } |
284 | if (l) mailmessage_list_free(l); | 286 | if (l) mailmessage_list_free(l); |
285 | if (folder) mailfolder_free(folder); | 287 | if (folder) mailfolder_free(folder); |
286 | if (storage) mailstorage_free(storage); | 288 | if (storage) mailstorage_free(storage); |
287 | return res; | 289 | return res; |
288 | } | 290 | } |
289 | 291 | ||
290 | int MBOXwrapper::deleteMbox(const FolderP&tfolder) | 292 | int MBOXwrapper::deleteMbox(const FolderP&tfolder) |
291 | { | 293 | { |
292 | if (!tfolder) return 0; | 294 | if (!tfolder) return 0; |
293 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); | 295 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); |
294 | QFile fi(p); | 296 | QFile fi(p); |
295 | if (!fi.exists()) { | 297 | if (!fi.exists()) { |
296 | Global::statusMessage(tr("Mailbox doesn't exist.")); | 298 | Global::statusMessage(tr("Mailbox doesn't exist.")); |
297 | return 0; | 299 | return 0; |
298 | } | 300 | } |
299 | if (!fi.remove()) { | 301 | if (!fi.remove()) { |
300 | Global::statusMessage(tr("Error deleting Mailbox.")); | 302 | Global::statusMessage(tr("Error deleting Mailbox.")); |
301 | return 0; | 303 | return 0; |
302 | } | 304 | } |
303 | return 1; | 305 | return 1; |
304 | } | 306 | } |
305 | 307 | ||
306 | void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 308 | void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
307 | { | 309 | { |
308 | mailfolder*folder = 0; | 310 | mailfolder*folder = 0; |
309 | mailstorage*storage = mailstorage_new(NULL); | 311 | mailstorage*storage = mailstorage_new(NULL); |
310 | target_stat.message_count = 0; | 312 | target_stat.message_count = 0; |
311 | target_stat.message_unseen = 0; | 313 | target_stat.message_unseen = 0; |
312 | target_stat.message_recent = 0; | 314 | target_stat.message_recent = 0; |
313 | QString p = MBOXPath+"/"+mailbox; | 315 | QString p = MBOXPath+"/"+mailbox; |
314 | QFile fi(p); | 316 | QFile fi(p); |
315 | if (!fi.exists()) { | 317 | if (!fi.exists()) { |
316 | Global::statusMessage(tr("Mailbox doesn't exist.")); | 318 | Global::statusMessage(tr("Mailbox doesn't exist.")); |
317 | return; | 319 | return; |
318 | } | 320 | } |
319 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 321 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
320 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 322 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
321 | r = mailfolder_connect(folder); | 323 | r = mailfolder_connect(folder); |
322 | r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, | 324 | r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, |
323 | &target_stat.message_recent,&target_stat.message_unseen); | 325 | &target_stat.message_recent,&target_stat.message_unseen); |
324 | if (folder) mailfolder_free(folder); | 326 | if (folder) mailfolder_free(folder); |
325 | if (storage) mailstorage_free(storage); | 327 | if (storage) mailstorage_free(storage); |
326 | } | 328 | } |
327 | 329 | ||
328 | MAILLIB::ATYPE MBOXwrapper::getType()const | 330 | MAILLIB::ATYPE MBOXwrapper::getType()const |
329 | { | 331 | { |
330 | return MAILLIB::A_MBOX; | 332 | return MAILLIB::A_MBOX; |
331 | } | 333 | } |
332 | 334 | ||
333 | const QString&MBOXwrapper::getName()const | 335 | const QString&MBOXwrapper::getName()const |
334 | { | 336 | { |
335 | return MBOXName; | 337 | return MBOXName; |
336 | } | 338 | } |
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.cpp b/noncore/net/mail/libmailwrapper/mhwrapper.cpp index cd7cecb..403afcf 100644 --- a/noncore/net/mail/libmailwrapper/mhwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mhwrapper.cpp | |||
@@ -1,442 +1,443 @@ | |||
1 | #include "mhwrapper.h" | 1 | #include "mhwrapper.h" |
2 | #include "mailtypes.h" | 2 | #include "mailtypes.h" |
3 | #include "mailwrapper.h" | 3 | #include "mailwrapper.h" |
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | #include <qdir.h> | 5 | #include <qdir.h> |
6 | #include <qmessagebox.h> | 6 | #include <qmessagebox.h> |
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | #include <qpe/global.h> | 8 | #include <qpe/global.h> |
9 | #include <opie2/oprocess.h> | 9 | #include <opie2/oprocess.h> |
10 | #include <opie2/odebug.h> | ||
10 | 11 | ||
11 | using namespace Opie::Core; | 12 | using namespace Opie::Core; |
12 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) | 13 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) |
13 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) | 14 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) |
14 | { | 15 | { |
15 | if (MHPath.length()>0) { | 16 | if (MHPath.length()>0) { |
16 | if (MHPath[MHPath.length()-1]=='/') { | 17 | if (MHPath[MHPath.length()-1]=='/') { |
17 | MHPath=MHPath.left(MHPath.length()-1); | 18 | MHPath=MHPath.left(MHPath.length()-1); |
18 | } | 19 | } |
19 | odebug << MHPath << oendl; | 20 | odebug << MHPath << oendl; |
20 | QDir dir(MHPath); | 21 | QDir dir(MHPath); |
21 | if (!dir.exists()) { | 22 | if (!dir.exists()) { |
22 | dir.mkdir(MHPath); | 23 | dir.mkdir(MHPath); |
23 | } | 24 | } |
24 | init_storage(); | 25 | init_storage(); |
25 | } | 26 | } |
26 | } | 27 | } |
27 | 28 | ||
28 | void MHwrapper::init_storage() | 29 | void MHwrapper::init_storage() |
29 | { | 30 | { |
30 | int r; | 31 | int r; |
31 | QString pre = MHPath; | 32 | QString pre = MHPath; |
32 | if (!m_storage) { | 33 | if (!m_storage) { |
33 | m_storage = mailstorage_new(NULL); | 34 | m_storage = mailstorage_new(NULL); |
34 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); | 35 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); |
35 | if (r != MAIL_NO_ERROR) { | 36 | if (r != MAIL_NO_ERROR) { |
36 | odebug << "error initializing storage" << oendl; | 37 | odebug << "error initializing storage" << oendl; |
37 | mailstorage_free(m_storage); | 38 | mailstorage_free(m_storage); |
38 | m_storage = 0; | 39 | m_storage = 0; |
39 | return; | 40 | return; |
40 | } | 41 | } |
41 | } | 42 | } |
42 | r = mailstorage_connect(m_storage); | 43 | r = mailstorage_connect(m_storage); |
43 | if (r!=MAIL_NO_ERROR) { | 44 | if (r!=MAIL_NO_ERROR) { |
44 | odebug << "error connecting storage" << oendl; | 45 | odebug << "error connecting storage" << oendl; |
45 | mailstorage_free(m_storage); | 46 | mailstorage_free(m_storage); |
46 | m_storage = 0; | 47 | m_storage = 0; |
47 | } | 48 | } |
48 | } | 49 | } |
49 | 50 | ||
50 | void MHwrapper::clean_storage() | 51 | void MHwrapper::clean_storage() |
51 | { | 52 | { |
52 | if (m_storage) { | 53 | if (m_storage) { |
53 | mailstorage_disconnect(m_storage); | 54 | mailstorage_disconnect(m_storage); |
54 | mailstorage_free(m_storage); | 55 | mailstorage_free(m_storage); |
55 | m_storage = 0; | 56 | m_storage = 0; |
56 | } | 57 | } |
57 | } | 58 | } |
58 | 59 | ||
59 | MHwrapper::~MHwrapper() | 60 | MHwrapper::~MHwrapper() |
60 | { | 61 | { |
61 | clean_storage(); | 62 | clean_storage(); |
62 | } | 63 | } |
63 | 64 | ||
64 | void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) | 65 | void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) |
65 | { | 66 | { |
66 | init_storage(); | 67 | init_storage(); |
67 | if (!m_storage) { | 68 | if (!m_storage) { |
68 | return; | 69 | return; |
69 | } | 70 | } |
70 | QString f = buildPath(mailbox); | 71 | QString f = buildPath(mailbox); |
71 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 72 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
72 | if (r!=MAIL_NO_ERROR) { | 73 | if (r!=MAIL_NO_ERROR) { |
73 | odebug << "listMessages: error selecting folder!" << oendl; | 74 | odebug << "listMessages: error selecting folder!" << oendl; |
74 | return; | 75 | return; |
75 | } | 76 | } |
76 | parseList(target,m_storage->sto_session,f); | 77 | parseList(target,m_storage->sto_session,f); |
77 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); | 78 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); |
78 | } | 79 | } |
79 | 80 | ||
80 | QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() | 81 | QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() |
81 | { | 82 | { |
82 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); | 83 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); |
83 | /* this is needed! */ | 84 | /* this is needed! */ |
84 | if (m_storage) mailstorage_disconnect(m_storage); | 85 | if (m_storage) mailstorage_disconnect(m_storage); |
85 | init_storage(); | 86 | init_storage(); |
86 | if (!m_storage) { | 87 | if (!m_storage) { |
87 | return folders; | 88 | return folders; |
88 | } | 89 | } |
89 | mail_list*flist = 0; | 90 | mail_list*flist = 0; |
90 | clistcell*current=0; | 91 | clistcell*current=0; |
91 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); | 92 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); |
92 | if (r != MAIL_NO_ERROR || !flist) { | 93 | if (r != MAIL_NO_ERROR || !flist) { |
93 | odebug << "error getting folder list" << oendl; | 94 | odebug << "error getting folder list" << oendl; |
94 | return folders; | 95 | return folders; |
95 | } | 96 | } |
96 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { | 97 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { |
97 | QString t = (char*)current->data; | 98 | QString t = (char*)current->data; |
98 | t.replace(0,MHPath.length(),""); | 99 | t.replace(0,MHPath.length(),""); |
99 | folders->append(new MHFolder(t,MHPath)); | 100 | folders->append(new MHFolder(t,MHPath)); |
100 | } | 101 | } |
101 | mail_list_free(flist); | 102 | mail_list_free(flist); |
102 | return folders; | 103 | return folders; |
103 | } | 104 | } |
104 | 105 | ||
105 | void MHwrapper::deleteMail(const RecMailP&mail) | 106 | void MHwrapper::deleteMail(const RecMailP&mail) |
106 | { | 107 | { |
107 | init_storage(); | 108 | init_storage(); |
108 | if (!m_storage) { | 109 | if (!m_storage) { |
109 | return; | 110 | return; |
110 | } | 111 | } |
111 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 112 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
112 | if (r!=MAIL_NO_ERROR) { | 113 | if (r!=MAIL_NO_ERROR) { |
113 | odebug << "error selecting folder!" << oendl; | 114 | odebug << "error selecting folder!" << oendl; |
114 | return; | 115 | return; |
115 | } | 116 | } |
116 | r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); | 117 | r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); |
117 | if (r != MAIL_NO_ERROR) { | 118 | if (r != MAIL_NO_ERROR) { |
118 | odebug << "error deleting mail" << oendl; | 119 | odebug << "error deleting mail" << oendl; |
119 | } | 120 | } |
120 | } | 121 | } |
121 | 122 | ||
122 | void MHwrapper::answeredMail(const RecMailP&) | 123 | void MHwrapper::answeredMail(const RecMailP&) |
123 | { | 124 | { |
124 | } | 125 | } |
125 | 126 | ||
126 | RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) | 127 | RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) |
127 | { | 128 | { |
128 | RecBodyP body = new RecBody(); | 129 | RecBodyP body = new RecBody(); |
129 | init_storage(); | 130 | init_storage(); |
130 | if (!m_storage) { | 131 | if (!m_storage) { |
131 | return body; | 132 | return body; |
132 | } | 133 | } |
133 | mailmessage * msg; | 134 | mailmessage * msg; |
134 | char*data=0; | 135 | char*data=0; |
135 | 136 | ||
136 | /* mail should hold the complete path! */ | 137 | /* mail should hold the complete path! */ |
137 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 138 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
138 | if (r != MAIL_NO_ERROR) { | 139 | if (r != MAIL_NO_ERROR) { |
139 | return body; | 140 | return body; |
140 | } | 141 | } |
141 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); | 142 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); |
142 | if (r != MAIL_NO_ERROR) { | 143 | if (r != MAIL_NO_ERROR) { |
143 | odebug << "Error fetching mail " << mail->getNumber() << "" << oendl; | 144 | odebug << "Error fetching mail " << mail->getNumber() << "" << oendl; |
144 | return body; | 145 | return body; |
145 | } | 146 | } |
146 | body = parseMail(msg); | 147 | body = parseMail(msg); |
147 | mailmessage_fetch_result_free(msg,data); | 148 | mailmessage_fetch_result_free(msg,data); |
148 | return body; | 149 | return body; |
149 | } | 150 | } |
150 | 151 | ||
151 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) | 152 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) |
152 | { | 153 | { |
153 | odebug << "MH " << current << " von " << maximum << "" << oendl; | 154 | odebug << "MH " << current << " von " << maximum << "" << oendl; |
154 | } | 155 | } |
155 | 156 | ||
156 | QString MHwrapper::buildPath(const QString&p) | 157 | QString MHwrapper::buildPath(const QString&p) |
157 | { | 158 | { |
158 | QString f=""; | 159 | QString f=""; |
159 | if (p.length()==0||p=="/") | 160 | if (p.length()==0||p=="/") |
160 | return MHPath; | 161 | return MHPath; |
161 | if (!p.startsWith(MHPath)) { | 162 | if (!p.startsWith(MHPath)) { |
162 | f+=MHPath; | 163 | f+=MHPath; |
163 | } | 164 | } |
164 | if (!p.startsWith("/")) { | 165 | if (!p.startsWith("/")) { |
165 | f+="/"; | 166 | f+="/"; |
166 | } | 167 | } |
167 | f+=p; | 168 | f+=p; |
168 | return f; | 169 | return f; |
169 | } | 170 | } |
170 | 171 | ||
171 | int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) | 172 | int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) |
172 | { | 173 | { |
173 | init_storage(); | 174 | init_storage(); |
174 | if (!m_storage) { | 175 | if (!m_storage) { |
175 | return 0; | 176 | return 0; |
176 | } | 177 | } |
177 | QString f; | 178 | QString f; |
178 | if (!pfolder) { | 179 | if (!pfolder) { |
179 | // toplevel folder | 180 | // toplevel folder |
180 | f = buildPath(folder); | 181 | f = buildPath(folder); |
181 | } else { | 182 | } else { |
182 | f = pfolder->getName(); | 183 | f = pfolder->getName(); |
183 | f+="/"; | 184 | f+="/"; |
184 | f+=folder; | 185 | f+=folder; |
185 | } | 186 | } |
186 | odebug << f << oendl; | 187 | odebug << f << oendl; |
187 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); | 188 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); |
188 | if (r != MAIL_NO_ERROR) { | 189 | if (r != MAIL_NO_ERROR) { |
189 | odebug << "error creating folder " << r << "" << oendl; | 190 | odebug << "error creating folder " << r << "" << oendl; |
190 | return 0; | 191 | return 0; |
191 | } | 192 | } |
192 | odebug << "Folder created" << oendl; | 193 | odebug << "Folder created" << oendl; |
193 | return 1; | 194 | return 1; |
194 | } | 195 | } |
195 | 196 | ||
196 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) | 197 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) |
197 | { | 198 | { |
198 | init_storage(); | 199 | init_storage(); |
199 | if (!m_storage) { | 200 | if (!m_storage) { |
200 | return; | 201 | return; |
201 | } | 202 | } |
202 | QString f = buildPath(Folder); | 203 | QString f = buildPath(Folder); |
203 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 204 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
204 | if (r!=MAIL_NO_ERROR) { | 205 | if (r!=MAIL_NO_ERROR) { |
205 | odebug << "error selecting folder!" << oendl; | 206 | odebug << "error selecting folder!" << oendl; |
206 | return; | 207 | return; |
207 | } | 208 | } |
208 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); | 209 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); |
209 | if (r!=MAIL_NO_ERROR) { | 210 | if (r!=MAIL_NO_ERROR) { |
210 | odebug << "error storing mail" << oendl; | 211 | odebug << "error storing mail" << oendl; |
211 | } | 212 | } |
212 | return; | 213 | return; |
213 | } | 214 | } |
214 | 215 | ||
215 | encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) | 216 | encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) |
216 | { | 217 | { |
217 | encodedString*result = 0; | 218 | encodedString*result = 0; |
218 | init_storage(); | 219 | init_storage(); |
219 | if (!m_storage) { | 220 | if (!m_storage) { |
220 | return result; | 221 | return result; |
221 | } | 222 | } |
222 | mailmessage * msg = 0; | 223 | mailmessage * msg = 0; |
223 | char*data=0; | 224 | char*data=0; |
224 | size_t size; | 225 | size_t size; |
225 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 226 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
226 | if (r!=MAIL_NO_ERROR) { | 227 | if (r!=MAIL_NO_ERROR) { |
227 | odebug << "error selecting folder!" << oendl; | 228 | odebug << "error selecting folder!" << oendl; |
228 | return result; | 229 | return result; |
229 | } | 230 | } |
230 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); | 231 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); |
231 | if (r != MAIL_NO_ERROR) { | 232 | if (r != MAIL_NO_ERROR) { |
232 | Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); | 233 | Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); |
233 | return 0; | 234 | return 0; |
234 | } | 235 | } |
235 | r = mailmessage_fetch(msg,&data,&size); | 236 | r = mailmessage_fetch(msg,&data,&size); |
236 | if (r != MAIL_NO_ERROR) { | 237 | if (r != MAIL_NO_ERROR) { |
237 | Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); | 238 | Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); |
238 | if (msg) mailmessage_free(msg); | 239 | if (msg) mailmessage_free(msg); |
239 | return 0; | 240 | return 0; |
240 | } | 241 | } |
241 | result = new encodedString(data,size); | 242 | result = new encodedString(data,size); |
242 | if (msg) mailmessage_free(msg); | 243 | if (msg) mailmessage_free(msg); |
243 | return result; | 244 | return result; |
244 | } | 245 | } |
245 | 246 | ||
246 | void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) | 247 | void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) |
247 | { | 248 | { |
248 | QString f = buildPath(mailbox); | 249 | QString f = buildPath(mailbox); |
249 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 250 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
250 | if (r!=MAIL_NO_ERROR) { | 251 | if (r!=MAIL_NO_ERROR) { |
251 | odebug << "deleteMails: error selecting folder!" << oendl; | 252 | odebug << "deleteMails: error selecting folder!" << oendl; |
252 | return; | 253 | return; |
253 | } | 254 | } |
254 | QValueList<RecMailP>::ConstIterator it; | 255 | QValueList<RecMailP>::ConstIterator it; |
255 | for (it=target.begin(); it!=target.end();++it) { | 256 | for (it=target.begin(); it!=target.end();++it) { |
256 | r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); | 257 | r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); |
257 | if (r != MAIL_NO_ERROR) { | 258 | if (r != MAIL_NO_ERROR) { |
258 | odebug << "error deleting mail" << oendl; | 259 | odebug << "error deleting mail" << oendl; |
259 | break; | 260 | break; |
260 | } | 261 | } |
261 | } | 262 | } |
262 | } | 263 | } |
263 | 264 | ||
264 | int MHwrapper::deleteAllMail(const FolderP&tfolder) | 265 | int MHwrapper::deleteAllMail(const FolderP&tfolder) |
265 | { | 266 | { |
266 | init_storage(); | 267 | init_storage(); |
267 | if (!m_storage) { | 268 | if (!m_storage) { |
268 | return 0; | 269 | return 0; |
269 | } | 270 | } |
270 | int res = 1; | 271 | int res = 1; |
271 | if (!tfolder) return 0; | 272 | if (!tfolder) return 0; |
272 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 273 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
273 | if (r!=MAIL_NO_ERROR) { | 274 | if (r!=MAIL_NO_ERROR) { |
274 | odebug << "error selecting folder!" << oendl; | 275 | odebug << "error selecting folder!" << oendl; |
275 | return 0; | 276 | return 0; |
276 | } | 277 | } |
277 | mailmessage_list*l=0; | 278 | mailmessage_list*l=0; |
278 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | 279 | r = mailsession_get_messages_list(m_storage->sto_session,&l); |
279 | if (r != MAIL_NO_ERROR) { | 280 | if (r != MAIL_NO_ERROR) { |
280 | odebug << "Error message list" << oendl; | 281 | odebug << "Error message list" << oendl; |
281 | res = 0; | 282 | res = 0; |
282 | } | 283 | } |
283 | unsigned j = 0; | 284 | unsigned j = 0; |
284 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | 285 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { |
285 | mailmessage * msg; | 286 | mailmessage * msg; |
286 | msg = (mailmessage*)carray_get(l->msg_tab, i); | 287 | msg = (mailmessage*)carray_get(l->msg_tab, i); |
287 | j = msg->msg_index; | 288 | j = msg->msg_index; |
288 | r = mailsession_remove_message(m_storage->sto_session,j); | 289 | r = mailsession_remove_message(m_storage->sto_session,j); |
289 | if (r != MAIL_NO_ERROR) { | 290 | if (r != MAIL_NO_ERROR) { |
290 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 291 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
291 | res = 0; | 292 | res = 0; |
292 | break; | 293 | break; |
293 | } | 294 | } |
294 | } | 295 | } |
295 | if (l) mailmessage_list_free(l); | 296 | if (l) mailmessage_list_free(l); |
296 | return res; | 297 | return res; |
297 | } | 298 | } |
298 | 299 | ||
299 | int MHwrapper::deleteMbox(const FolderP&tfolder) | 300 | int MHwrapper::deleteMbox(const FolderP&tfolder) |
300 | { | 301 | { |
301 | init_storage(); | 302 | init_storage(); |
302 | if (!m_storage) { | 303 | if (!m_storage) { |
303 | return 0; | 304 | return 0; |
304 | } | 305 | } |
305 | if (!tfolder) return 0; | 306 | if (!tfolder) return 0; |
306 | if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; | 307 | if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; |
307 | 308 | ||
308 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 309 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
309 | 310 | ||
310 | if (r != MAIL_NO_ERROR) { | 311 | if (r != MAIL_NO_ERROR) { |
311 | odebug << "error deleting mail box" << oendl; | 312 | odebug << "error deleting mail box" << oendl; |
312 | return 0; | 313 | return 0; |
313 | } | 314 | } |
314 | QString cmd = "rm -rf "+tfolder->getName(); | 315 | QString cmd = "rm -rf "+tfolder->getName(); |
315 | QStringList command; | 316 | QStringList command; |
316 | command << "/bin/sh"; | 317 | command << "/bin/sh"; |
317 | command << "-c"; | 318 | command << "-c"; |
318 | command << cmd.latin1(); | 319 | command << cmd.latin1(); |
319 | OProcess *process = new OProcess(); | 320 | OProcess *process = new OProcess(); |
320 | 321 | ||
321 | connect(process, SIGNAL(processExited(Opie::Core::OProcess*)), | 322 | connect(process, SIGNAL(processExited(Opie::Core::OProcess*)), |
322 | this, SLOT( processEnded(Opie::Core::OProcess*))); | 323 | this, SLOT( processEnded(Opie::Core::OProcess*))); |
323 | connect(process, SIGNAL( receivedStderr(Opie::Core::OProcess*,char*,int)), | 324 | connect(process, SIGNAL( receivedStderr(Opie::Core::OProcess*,char*,int)), |
324 | this, SLOT( oprocessStderr(Opie::Core::OProcess*,char*,int))); | 325 | this, SLOT( oprocessStderr(Opie::Core::OProcess*,char*,int))); |
325 | 326 | ||
326 | *process << command; | 327 | *process << command; |
327 | removeMboxfailed = false; | 328 | removeMboxfailed = false; |
328 | if(!process->start(OProcess::Block, OProcess::All) ) { | 329 | if(!process->start(OProcess::Block, OProcess::All) ) { |
329 | odebug << "could not start process" << oendl; | 330 | odebug << "could not start process" << oendl; |
330 | return 0; | 331 | return 0; |
331 | } | 332 | } |
332 | odebug << "mail box deleted" << oendl; | 333 | odebug << "mail box deleted" << oendl; |
333 | return 1; | 334 | return 1; |
334 | } | 335 | } |
335 | 336 | ||
336 | void MHwrapper::processEnded(OProcess *p) | 337 | void MHwrapper::processEnded(OProcess *p) |
337 | { | 338 | { |
338 | if (p) delete p; | 339 | if (p) delete p; |
339 | } | 340 | } |
340 | 341 | ||
341 | void MHwrapper::oprocessStderr(OProcess*, char *buffer, int ) | 342 | void MHwrapper::oprocessStderr(OProcess*, char *buffer, int ) |
342 | { | 343 | { |
343 | QString lineStr = buffer; | 344 | QString lineStr = buffer; |
344 | QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") ); | 345 | QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") ); |
345 | removeMboxfailed = true; | 346 | removeMboxfailed = true; |
346 | } | 347 | } |
347 | 348 | ||
348 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 349 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
349 | { | 350 | { |
350 | init_storage(); | 351 | init_storage(); |
351 | if (!m_storage) { | 352 | if (!m_storage) { |
352 | return; | 353 | return; |
353 | } | 354 | } |
354 | target_stat.message_count = 0; | 355 | target_stat.message_count = 0; |
355 | target_stat.message_unseen = 0; | 356 | target_stat.message_unseen = 0; |
356 | target_stat.message_recent = 0; | 357 | target_stat.message_recent = 0; |
357 | QString f = buildPath(mailbox); | 358 | QString f = buildPath(mailbox); |
358 | int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, | 359 | int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, |
359 | &target_stat.message_recent,&target_stat.message_unseen); | 360 | &target_stat.message_recent,&target_stat.message_unseen); |
360 | if (r != MAIL_NO_ERROR) { | 361 | if (r != MAIL_NO_ERROR) { |
361 | Global::statusMessage(tr("Error retrieving status")); | 362 | Global::statusMessage(tr("Error retrieving status")); |
362 | } | 363 | } |
363 | } | 364 | } |
364 | 365 | ||
365 | MAILLIB::ATYPE MHwrapper::getType()const | 366 | MAILLIB::ATYPE MHwrapper::getType()const |
366 | { | 367 | { |
367 | return MAILLIB::A_MH; | 368 | return MAILLIB::A_MH; |
368 | } | 369 | } |
369 | 370 | ||
370 | const QString&MHwrapper::getName()const | 371 | const QString&MHwrapper::getName()const |
371 | { | 372 | { |
372 | return MHName; | 373 | return MHName; |
373 | } | 374 | } |
374 | void MHwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 375 | void MHwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
375 | { | 376 | { |
376 | init_storage(); | 377 | init_storage(); |
377 | if (!m_storage) { | 378 | if (!m_storage) { |
378 | return; | 379 | return; |
379 | } | 380 | } |
380 | if (targetWrapper != this) { | 381 | if (targetWrapper != this) { |
381 | odebug << "Using generic" << oendl; | 382 | odebug << "Using generic" << oendl; |
382 | Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); | 383 | Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); |
383 | return; | 384 | return; |
384 | } | 385 | } |
385 | odebug << "Using internal routines for move/copy" << oendl; | 386 | odebug << "Using internal routines for move/copy" << oendl; |
386 | QString tf = buildPath(targetFolder); | 387 | QString tf = buildPath(targetFolder); |
387 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 388 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
388 | if (r != MAIL_NO_ERROR) { | 389 | if (r != MAIL_NO_ERROR) { |
389 | odebug << "Error selecting source mailbox" << oendl; | 390 | odebug << "Error selecting source mailbox" << oendl; |
390 | return; | 391 | return; |
391 | } | 392 | } |
392 | if (moveit) { | 393 | if (moveit) { |
393 | r = mailsession_move_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); | 394 | r = mailsession_move_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); |
394 | } else { | 395 | } else { |
395 | r = mailsession_copy_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); | 396 | r = mailsession_copy_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); |
396 | } | 397 | } |
397 | if (r != MAIL_NO_ERROR) { | 398 | if (r != MAIL_NO_ERROR) { |
398 | odebug << "Error copy/moving mail internal (" << r << ")" << oendl; | 399 | odebug << "Error copy/moving mail internal (" << r << ")" << oendl; |
399 | } | 400 | } |
400 | } | 401 | } |
401 | 402 | ||
402 | void MHwrapper::mvcpAllMails(const FolderP&fromFolder, | 403 | void MHwrapper::mvcpAllMails(const FolderP&fromFolder, |
403 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 404 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
404 | { | 405 | { |
405 | init_storage(); | 406 | init_storage(); |
406 | if (!m_storage) { | 407 | if (!m_storage) { |
407 | return; | 408 | return; |
408 | } | 409 | } |
409 | if (targetWrapper != this) { | 410 | if (targetWrapper != this) { |
410 | odebug << "Using generic" << oendl; | 411 | odebug << "Using generic" << oendl; |
411 | Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); | 412 | Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); |
412 | return; | 413 | return; |
413 | } | 414 | } |
414 | if (!fromFolder) return; | 415 | if (!fromFolder) return; |
415 | int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1()); | 416 | int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1()); |
416 | if (r!=MAIL_NO_ERROR) { | 417 | if (r!=MAIL_NO_ERROR) { |
417 | odebug << "error selecting source folder!" << oendl; | 418 | odebug << "error selecting source folder!" << oendl; |
418 | return; | 419 | return; |
419 | } | 420 | } |
420 | QString tf = buildPath(targetFolder); | 421 | QString tf = buildPath(targetFolder); |
421 | mailmessage_list*l=0; | 422 | mailmessage_list*l=0; |
422 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | 423 | r = mailsession_get_messages_list(m_storage->sto_session,&l); |
423 | if (r != MAIL_NO_ERROR) { | 424 | if (r != MAIL_NO_ERROR) { |
424 | odebug << "Error message list" << oendl; | 425 | odebug << "Error message list" << oendl; |
425 | } | 426 | } |
426 | unsigned j = 0; | 427 | unsigned j = 0; |
427 | for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) { | 428 | for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) { |
428 | mailmessage * msg; | 429 | mailmessage * msg; |
429 | msg = (mailmessage*)carray_get(l->msg_tab, i); | 430 | msg = (mailmessage*)carray_get(l->msg_tab, i); |
430 | j = msg->msg_index; | 431 | j = msg->msg_index; |
431 | if (moveit) { | 432 | if (moveit) { |
432 | r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1()); | 433 | r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1()); |
433 | } else { | 434 | } else { |
434 | r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1()); | 435 | r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1()); |
435 | } | 436 | } |
436 | if (r != MAIL_NO_ERROR) { | 437 | if (r != MAIL_NO_ERROR) { |
437 | odebug << "Error copy/moving mail internal (" << r << ")" << oendl; | 438 | odebug << "Error copy/moving mail internal (" << r << ")" << oendl; |
438 | break; | 439 | break; |
439 | } | 440 | } |
440 | } | 441 | } |
441 | if (l) mailmessage_list_free(l); | 442 | if (l) mailmessage_list_free(l); |
442 | } | 443 | } |
diff --git a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp index 5d5011a..c99b97c 100644 --- a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp | |||
@@ -1,288 +1,289 @@ | |||
1 | #include "nntpwrapper.h" | 1 | #include "nntpwrapper.h" |
2 | #include "logindialog.h" | 2 | #include "logindialog.h" |
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | 4 | ||
5 | #include <qfile.h> | 5 | #include <qfile.h> |
6 | 6 | ||
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | 8 | ||
9 | #include <libetpan/libetpan.h> | 9 | #include <libetpan/libetpan.h> |
10 | 10 | ||
11 | #include <opie2/odebug.h> | ||
11 | 12 | ||
12 | #define HARD_MSG_SIZE_LIMIT 5242880 | 13 | #define HARD_MSG_SIZE_LIMIT 5242880 |
13 | 14 | ||
14 | using namespace Opie::Core; | 15 | using namespace Opie::Core; |
15 | NNTPwrapper::NNTPwrapper( NNTPaccount *a ) | 16 | NNTPwrapper::NNTPwrapper( NNTPaccount *a ) |
16 | : Genericwrapper() { | 17 | : Genericwrapper() { |
17 | account = a; | 18 | account = a; |
18 | m_nntp = NULL; | 19 | m_nntp = NULL; |
19 | msgTempName = a->getFileName()+"_msg_cache"; | 20 | msgTempName = a->getFileName()+"_msg_cache"; |
20 | last_msg_id = 0; | 21 | last_msg_id = 0; |
21 | } | 22 | } |
22 | 23 | ||
23 | NNTPwrapper::~NNTPwrapper() { | 24 | NNTPwrapper::~NNTPwrapper() { |
24 | logout(); | 25 | logout(); |
25 | QFile msg_cache(msgTempName); | 26 | QFile msg_cache(msgTempName); |
26 | if (msg_cache.exists()) { | 27 | if (msg_cache.exists()) { |
27 | msg_cache.remove(); | 28 | msg_cache.remove(); |
28 | } | 29 | } |
29 | } | 30 | } |
30 | 31 | ||
31 | void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) { | 32 | void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) { |
32 | odebug << "NNTP: " << current << " of " << maximum << "" << oendl; | 33 | odebug << "NNTP: " << current << " of " << maximum << "" << oendl; |
33 | } | 34 | } |
34 | 35 | ||
35 | 36 | ||
36 | RecBodyP NNTPwrapper::fetchBody( const RecMailP &mail ) { | 37 | RecBodyP NNTPwrapper::fetchBody( const RecMailP &mail ) { |
37 | int err = NEWSNNTP_NO_ERROR; | 38 | int err = NEWSNNTP_NO_ERROR; |
38 | char *message = 0; | 39 | char *message = 0; |
39 | size_t length = 0; | 40 | size_t length = 0; |
40 | 41 | ||
41 | RecBodyP body = new RecBody(); | 42 | RecBodyP body = new RecBody(); |
42 | login(); | 43 | login(); |
43 | if ( !m_nntp ) { | 44 | if ( !m_nntp ) { |
44 | return body; | 45 | return body; |
45 | } | 46 | } |
46 | 47 | ||
47 | mailmessage * mailmsg; | 48 | mailmessage * mailmsg; |
48 | if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { | 49 | if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { |
49 | odebug << "Message to large: " << mail->Msgsize() << "" << oendl; | 50 | odebug << "Message to large: " << mail->Msgsize() << "" << oendl; |
50 | return body; | 51 | return body; |
51 | } | 52 | } |
52 | 53 | ||
53 | QFile msg_cache(msgTempName); | 54 | QFile msg_cache(msgTempName); |
54 | 55 | ||
55 | cleanMimeCache(); | 56 | cleanMimeCache(); |
56 | 57 | ||
57 | if (mail->getNumber()!=last_msg_id) { | 58 | if (mail->getNumber()!=last_msg_id) { |
58 | if (msg_cache.exists()) { | 59 | if (msg_cache.exists()) { |
59 | msg_cache.remove(); | 60 | msg_cache.remove(); |
60 | } | 61 | } |
61 | msg_cache.open(IO_ReadWrite|IO_Truncate); | 62 | msg_cache.open(IO_ReadWrite|IO_Truncate); |
62 | last_msg_id = mail->getNumber(); | 63 | last_msg_id = mail->getNumber(); |
63 | err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); | 64 | err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); |
64 | err = mailmessage_fetch(mailmsg,&message,&length); | 65 | err = mailmessage_fetch(mailmsg,&message,&length); |
65 | msg_cache.writeBlock(message,length); | 66 | msg_cache.writeBlock(message,length); |
66 | } else { | 67 | } else { |
67 | QString msg=""; | 68 | QString msg=""; |
68 | msg_cache.open(IO_ReadOnly); | 69 | msg_cache.open(IO_ReadOnly); |
69 | message = new char[4096]; | 70 | message = new char[4096]; |
70 | memset(message,0,4096); | 71 | memset(message,0,4096); |
71 | while (msg_cache.readBlock(message,4095)>0) { | 72 | while (msg_cache.readBlock(message,4095)>0) { |
72 | msg+=message; | 73 | msg+=message; |
73 | memset(message,0,4096); | 74 | memset(message,0,4096); |
74 | } | 75 | } |
75 | delete message; | 76 | delete message; |
76 | message = (char*)malloc(msg.length()+1*sizeof(char)); | 77 | message = (char*)malloc(msg.length()+1*sizeof(char)); |
77 | memset(message,0,msg.length()+1); | 78 | memset(message,0,msg.length()+1); |
78 | memcpy(message,msg.latin1(),msg.length()); | 79 | memcpy(message,msg.latin1(),msg.length()); |
79 | /* transform to libetpan stuff */ | 80 | /* transform to libetpan stuff */ |
80 | mailmsg = mailmessage_new(); | 81 | mailmsg = mailmessage_new(); |
81 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); | 82 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); |
82 | generic_message_t * msg_data; | 83 | generic_message_t * msg_data; |
83 | msg_data = (generic_message_t *)mailmsg->msg_data; | 84 | msg_data = (generic_message_t *)mailmsg->msg_data; |
84 | msg_data->msg_fetched = 1; | 85 | msg_data->msg_fetched = 1; |
85 | msg_data->msg_message = message; | 86 | msg_data->msg_message = message; |
86 | msg_data->msg_length = strlen(message); | 87 | msg_data->msg_length = strlen(message); |
87 | } | 88 | } |
88 | body = parseMail(mailmsg); | 89 | body = parseMail(mailmsg); |
89 | 90 | ||
90 | /* clean up */ | 91 | /* clean up */ |
91 | if (mailmsg) | 92 | if (mailmsg) |
92 | mailmessage_free(mailmsg); | 93 | mailmessage_free(mailmsg); |
93 | if (message) | 94 | if (message) |
94 | free(message); | 95 | free(message); |
95 | 96 | ||
96 | return body; | 97 | return body; |
97 | } | 98 | } |
98 | 99 | ||
99 | 100 | ||
100 | void NNTPwrapper::listMessages(const QString & which, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) | 101 | void NNTPwrapper::listMessages(const QString & which, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) |
101 | { | 102 | { |
102 | login(); | 103 | login(); |
103 | if (!m_nntp) | 104 | if (!m_nntp) |
104 | return; | 105 | return; |
105 | uint32_t res_messages,res_recent,res_unseen; | 106 | uint32_t res_messages,res_recent,res_unseen; |
106 | mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen); | 107 | mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen); |
107 | parseList(target,m_nntp->sto_session,which,true); | 108 | parseList(target,m_nntp->sto_session,which,true); |
108 | } | 109 | } |
109 | 110 | ||
110 | void NNTPwrapper::login() | 111 | void NNTPwrapper::login() |
111 | { | 112 | { |
112 | if (account->getOffline()) | 113 | if (account->getOffline()) |
113 | return; | 114 | return; |
114 | /* we'll hold the line */ | 115 | /* we'll hold the line */ |
115 | if ( m_nntp != NULL ) | 116 | if ( m_nntp != NULL ) |
116 | return; | 117 | return; |
117 | 118 | ||
118 | const char *server, *user, *pass; | 119 | const char *server, *user, *pass; |
119 | QString User,Pass; | 120 | QString User,Pass; |
120 | uint16_t port; | 121 | uint16_t port; |
121 | int err = NEWSNNTP_NO_ERROR; | 122 | int err = NEWSNNTP_NO_ERROR; |
122 | 123 | ||
123 | server = account->getServer().latin1(); | 124 | server = account->getServer().latin1(); |
124 | port = account->getPort().toUInt(); | 125 | port = account->getPort().toUInt(); |
125 | 126 | ||
126 | user = pass = 0; | 127 | user = pass = 0; |
127 | 128 | ||
128 | if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) { | 129 | if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) { |
129 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 130 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
130 | login.show(); | 131 | login.show(); |
131 | if ( QDialog::Accepted == login.exec() ) { | 132 | if ( QDialog::Accepted == login.exec() ) { |
132 | // ok | 133 | // ok |
133 | User = login.getUser().latin1(); | 134 | User = login.getUser().latin1(); |
134 | Pass = login.getPassword().latin1(); | 135 | Pass = login.getPassword().latin1(); |
135 | } else { | 136 | } else { |
136 | // cancel | 137 | // cancel |
137 | odebug << "NNTP: Login canceled" << oendl; | 138 | odebug << "NNTP: Login canceled" << oendl; |
138 | return; | 139 | return; |
139 | } | 140 | } |
140 | } else { | 141 | } else { |
141 | User = account->getUser().latin1(); | 142 | User = account->getUser().latin1(); |
142 | Pass = account->getPassword().latin1(); | 143 | Pass = account->getPassword().latin1(); |
143 | } | 144 | } |
144 | 145 | ||
145 | if (User.isEmpty()) { | 146 | if (User.isEmpty()) { |
146 | user=0; | 147 | user=0; |
147 | pass = 0; | 148 | pass = 0; |
148 | } else { | 149 | } else { |
149 | user=User.latin1(); | 150 | user=User.latin1(); |
150 | pass=Pass.latin1(); | 151 | pass=Pass.latin1(); |
151 | } | 152 | } |
152 | // bool ssl = account->getSSL(); | 153 | // bool ssl = account->getSSL(); |
153 | 154 | ||
154 | m_nntp=mailstorage_new(NULL); | 155 | m_nntp=mailstorage_new(NULL); |
155 | 156 | ||
156 | int conntypeset = account->ConnectionType(); | 157 | int conntypeset = account->ConnectionType(); |
157 | int conntype = 0; | 158 | int conntype = 0; |
158 | if ( conntypeset == 3 ) { | 159 | if ( conntypeset == 3 ) { |
159 | conntype = CONNECTION_TYPE_COMMAND; | 160 | conntype = CONNECTION_TYPE_COMMAND; |
160 | } else if ( conntypeset == 2 ) { | 161 | } else if ( conntypeset == 2 ) { |
161 | conntype = CONNECTION_TYPE_TLS; | 162 | conntype = CONNECTION_TYPE_TLS; |
162 | } else if ( conntypeset == 1 ) { | 163 | } else if ( conntypeset == 1 ) { |
163 | conntype = CONNECTION_TYPE_STARTTLS; | 164 | conntype = CONNECTION_TYPE_STARTTLS; |
164 | } else if ( conntypeset == 0 ) { | 165 | } else if ( conntypeset == 0 ) { |
165 | conntype = CONNECTION_TYPE_TRY_STARTTLS; | 166 | conntype = CONNECTION_TYPE_TRY_STARTTLS; |
166 | } | 167 | } |
167 | 168 | ||
168 | nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN, | 169 | nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN, |
169 | (char*)user,(char*)pass,0,0,0); | 170 | (char*)user,(char*)pass,0,0,0); |
170 | 171 | ||
171 | err = mailstorage_connect( m_nntp ); | 172 | err = mailstorage_connect( m_nntp ); |
172 | 173 | ||
173 | if (err != NEWSNNTP_NO_ERROR) { | 174 | if (err != NEWSNNTP_NO_ERROR) { |
174 | odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; | 175 | odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; |
175 | // Global::statusMessage(tr("Error initializing folder")); | 176 | // Global::statusMessage(tr("Error initializing folder")); |
176 | mailstorage_free(m_nntp); | 177 | mailstorage_free(m_nntp); |
177 | m_nntp = 0; | 178 | m_nntp = 0; |
178 | 179 | ||
179 | } else { | 180 | } else { |
180 | mailsession * session = m_nntp->sto_session; | 181 | mailsession * session = m_nntp->sto_session; |
181 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; | 182 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; |
182 | news->nntp_progr_fun = &nntp_progress; | 183 | news->nntp_progr_fun = &nntp_progress; |
183 | } | 184 | } |
184 | 185 | ||
185 | } | 186 | } |
186 | 187 | ||
187 | void NNTPwrapper::logout() | 188 | void NNTPwrapper::logout() |
188 | { | 189 | { |
189 | int err = NEWSNNTP_NO_ERROR; | 190 | int err = NEWSNNTP_NO_ERROR; |
190 | if ( m_nntp == NULL ) | 191 | if ( m_nntp == NULL ) |
191 | return; | 192 | return; |
192 | mailstorage_free(m_nntp); | 193 | mailstorage_free(m_nntp); |
193 | m_nntp = 0; | 194 | m_nntp = 0; |
194 | } | 195 | } |
195 | 196 | ||
196 | QValueList<Opie::Core::OSmartPointer<Folder> >* NNTPwrapper::listFolders() { | 197 | QValueList<Opie::Core::OSmartPointer<Folder> >* NNTPwrapper::listFolders() { |
197 | 198 | ||
198 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); | 199 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); |
199 | QStringList groups; | 200 | QStringList groups; |
200 | if (account) { | 201 | if (account) { |
201 | groups = account->getGroups(); | 202 | groups = account->getGroups(); |
202 | } | 203 | } |
203 | for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) { | 204 | for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) { |
204 | folders->append(new Folder((*it),".")); | 205 | folders->append(new Folder((*it),".")); |
205 | } | 206 | } |
206 | return folders; | 207 | return folders; |
207 | } | 208 | } |
208 | 209 | ||
209 | /* we made this method in raw nntp access of etpan and not via generic interface | 210 | /* we made this method in raw nntp access of etpan and not via generic interface |
210 | * 'cause in that case there will be doubled copy operations. eg. the etpan would | 211 | * 'cause in that case there will be doubled copy operations. eg. the etpan would |
211 | * copy that stuff into its own structures and we must copy it into useable c++ | 212 | * copy that stuff into its own structures and we must copy it into useable c++ |
212 | * structures for our frontend. this would not make sense, so it is better to reimplement | 213 | * structures for our frontend. this would not make sense, so it is better to reimplement |
213 | * the stuff from generic interface of etpan but copy it direct to qt classes. | 214 | * the stuff from generic interface of etpan but copy it direct to qt classes. |
214 | */ | 215 | */ |
215 | QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) { | 216 | QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) { |
216 | login(); | 217 | login(); |
217 | QStringList res; | 218 | QStringList res; |
218 | clist *result = 0; | 219 | clist *result = 0; |
219 | clistcell *current = 0; | 220 | clistcell *current = 0; |
220 | newsnntp_group_description *group; | 221 | newsnntp_group_description *group; |
221 | 222 | ||
222 | if ( m_nntp ) { | 223 | if ( m_nntp ) { |
223 | mailsession * session = m_nntp->sto_session; | 224 | mailsession * session = m_nntp->sto_session; |
224 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; | 225 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; |
225 | int err = NEWSNNTP_NO_ERROR; | 226 | int err = NEWSNNTP_NO_ERROR; |
226 | if (mask.isEmpty()) { | 227 | if (mask.isEmpty()) { |
227 | err = newsnntp_list(news, &result); | 228 | err = newsnntp_list(news, &result); |
228 | } else { | 229 | } else { |
229 | /* taken from generic wrapper of etpan */ | 230 | /* taken from generic wrapper of etpan */ |
230 | QString nmask = mask+".*"; | 231 | QString nmask = mask+".*"; |
231 | err = newsnntp_list_active(news, nmask.latin1(), &result); | 232 | err = newsnntp_list_active(news, nmask.latin1(), &result); |
232 | } | 233 | } |
233 | if ( err == NEWSNNTP_NO_ERROR && result) { | 234 | if ( err == NEWSNNTP_NO_ERROR && result) { |
234 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) { | 235 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) { |
235 | group = ( newsnntp_group_description* ) current->data; | 236 | group = ( newsnntp_group_description* ) current->data; |
236 | if (!group||!group->grp_name||strlen(group->grp_name)==0) continue; | 237 | if (!group||!group->grp_name||strlen(group->grp_name)==0) continue; |
237 | res.append(group->grp_name); | 238 | res.append(group->grp_name); |
238 | } | 239 | } |
239 | } | 240 | } |
240 | } | 241 | } |
241 | if (result) { | 242 | if (result) { |
242 | newsnntp_list_free(result); | 243 | newsnntp_list_free(result); |
243 | } | 244 | } |
244 | return res; | 245 | return res; |
245 | } | 246 | } |
246 | 247 | ||
247 | void NNTPwrapper::answeredMail(const RecMailP&) {} | 248 | void NNTPwrapper::answeredMail(const RecMailP&) {} |
248 | 249 | ||
249 | void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { | 250 | void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { |
250 | login(); | 251 | login(); |
251 | target_stat.message_count = 0; | 252 | target_stat.message_count = 0; |
252 | target_stat.message_unseen = 0; | 253 | target_stat.message_unseen = 0; |
253 | target_stat.message_recent = 0; | 254 | target_stat.message_recent = 0; |
254 | if (!m_nntp) | 255 | if (!m_nntp) |
255 | return; | 256 | return; |
256 | int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, | 257 | int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, |
257 | &target_stat.message_recent,&target_stat.message_unseen); | 258 | &target_stat.message_recent,&target_stat.message_unseen); |
258 | } | 259 | } |
259 | 260 | ||
260 | 261 | ||
261 | encodedString* NNTPwrapper::fetchRawBody(const RecMailP&mail) { | 262 | encodedString* NNTPwrapper::fetchRawBody(const RecMailP&mail) { |
262 | char*target=0; | 263 | char*target=0; |
263 | size_t length=0; | 264 | size_t length=0; |
264 | encodedString*res = 0; | 265 | encodedString*res = 0; |
265 | mailmessage * mailmsg = 0; | 266 | mailmessage * mailmsg = 0; |
266 | int err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); | 267 | int err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); |
267 | err = mailmessage_fetch(mailmsg,&target,&length); | 268 | err = mailmessage_fetch(mailmsg,&target,&length); |
268 | if (mailmsg) | 269 | if (mailmsg) |
269 | mailmessage_free(mailmsg); | 270 | mailmessage_free(mailmsg); |
270 | if (target) { | 271 | if (target) { |
271 | res = new encodedString(target,length); | 272 | res = new encodedString(target,length); |
272 | } | 273 | } |
273 | return res; | 274 | return res; |
274 | } | 275 | } |
275 | 276 | ||
276 | MAILLIB::ATYPE NNTPwrapper::getType()const { | 277 | MAILLIB::ATYPE NNTPwrapper::getType()const { |
277 | return account->getType(); | 278 | return account->getType(); |
278 | } | 279 | } |
279 | 280 | ||
280 | const QString&NNTPwrapper::getName()const{ | 281 | const QString&NNTPwrapper::getName()const{ |
281 | return account->getAccountName(); | 282 | return account->getAccountName(); |
282 | } | 283 | } |
283 | 284 | ||
284 | void NNTPwrapper::deleteMail(const RecMailP&) { | 285 | void NNTPwrapper::deleteMail(const RecMailP&) { |
285 | } | 286 | } |
286 | 287 | ||
287 | int NNTPwrapper::deleteAllMail(const FolderP&) { | 288 | int NNTPwrapper::deleteAllMail(const FolderP&) { |
288 | } | 289 | } |
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index c586c29..3cfd1ee 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |||
@@ -1,264 +1,265 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include "pop3wrapper.h" | 2 | #include "pop3wrapper.h" |
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | #include "logindialog.h" | 4 | #include "logindialog.h" |
5 | #include <libetpan/libetpan.h> | 5 | #include <libetpan/libetpan.h> |
6 | |||
7 | #include <opie2/odebug.h> | ||
6 | #include <qpe/global.h> | 8 | #include <qpe/global.h> |
7 | #include <qfile.h> | 9 | #include <qfile.h> |
8 | //#include <qstring.h> | ||
9 | 10 | ||
10 | /* we don't fetch messages larger than 5 MB */ | 11 | /* we don't fetch messages larger than 5 MB */ |
11 | #define HARD_MSG_SIZE_LIMIT 5242880 | 12 | #define HARD_MSG_SIZE_LIMIT 5242880 |
12 | 13 | ||
13 | using namespace Opie::Core; | 14 | using namespace Opie::Core; |
14 | POP3wrapper::POP3wrapper( POP3account *a ) | 15 | POP3wrapper::POP3wrapper( POP3account *a ) |
15 | : Genericwrapper() { | 16 | : Genericwrapper() { |
16 | account = a; | 17 | account = a; |
17 | m_pop3 = NULL; | 18 | m_pop3 = NULL; |
18 | msgTempName = a->getFileName()+"_msg_cache"; | 19 | msgTempName = a->getFileName()+"_msg_cache"; |
19 | last_msg_id = 0; | 20 | last_msg_id = 0; |
20 | } | 21 | } |
21 | 22 | ||
22 | POP3wrapper::~POP3wrapper() { | 23 | POP3wrapper::~POP3wrapper() { |
23 | logout(); | 24 | logout(); |
24 | QFile msg_cache(msgTempName); | 25 | QFile msg_cache(msgTempName); |
25 | if (msg_cache.exists()) { | 26 | if (msg_cache.exists()) { |
26 | msg_cache.remove(); | 27 | msg_cache.remove(); |
27 | } | 28 | } |
28 | } | 29 | } |
29 | 30 | ||
30 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { | 31 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { |
31 | odebug << "POP3: " << current << " of " << maximum << "" << oendl; | 32 | odebug << "POP3: " << current << " of " << maximum << "" << oendl; |
32 | } | 33 | } |
33 | 34 | ||
34 | RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { | 35 | RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { |
35 | int err = MAILPOP3_NO_ERROR; | 36 | int err = MAILPOP3_NO_ERROR; |
36 | char *message = 0; | 37 | char *message = 0; |
37 | size_t length = 0; | 38 | size_t length = 0; |
38 | 39 | ||
39 | RecBodyP body = new RecBody(); | 40 | RecBodyP body = new RecBody(); |
40 | 41 | ||
41 | login(); | 42 | login(); |
42 | if ( !m_pop3 ) { | 43 | if ( !m_pop3 ) { |
43 | return body; | 44 | return body; |
44 | } | 45 | } |
45 | 46 | ||
46 | mailmessage * mailmsg; | 47 | mailmessage * mailmsg; |
47 | if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { | 48 | if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { |
48 | odebug << "Message to large: " << mail->Msgsize() << "" << oendl; | 49 | odebug << "Message to large: " << mail->Msgsize() << "" << oendl; |
49 | return body; | 50 | return body; |
50 | } | 51 | } |
51 | 52 | ||
52 | QFile msg_cache(msgTempName); | 53 | QFile msg_cache(msgTempName); |
53 | 54 | ||
54 | cleanMimeCache(); | 55 | cleanMimeCache(); |
55 | 56 | ||
56 | if (mail->getNumber()!=last_msg_id) { | 57 | if (mail->getNumber()!=last_msg_id) { |
57 | if (msg_cache.exists()) { | 58 | if (msg_cache.exists()) { |
58 | msg_cache.remove(); | 59 | msg_cache.remove(); |
59 | } | 60 | } |
60 | msg_cache.open(IO_ReadWrite|IO_Truncate); | 61 | msg_cache.open(IO_ReadWrite|IO_Truncate); |
61 | last_msg_id = mail->getNumber(); | 62 | last_msg_id = mail->getNumber(); |
62 | err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); | 63 | err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); |
63 | err = mailmessage_fetch(mailmsg,&message,&length); | 64 | err = mailmessage_fetch(mailmsg,&message,&length); |
64 | msg_cache.writeBlock(message,length); | 65 | msg_cache.writeBlock(message,length); |
65 | } else { | 66 | } else { |
66 | QString msg=""; | 67 | QString msg=""; |
67 | msg_cache.open(IO_ReadOnly); | 68 | msg_cache.open(IO_ReadOnly); |
68 | message = new char[4096]; | 69 | message = new char[4096]; |
69 | memset(message,0,4096); | 70 | memset(message,0,4096); |
70 | while (msg_cache.readBlock(message,4095)>0) { | 71 | while (msg_cache.readBlock(message,4095)>0) { |
71 | msg+=message; | 72 | msg+=message; |
72 | memset(message,0,4096); | 73 | memset(message,0,4096); |
73 | } | 74 | } |
74 | delete message; | 75 | delete message; |
75 | message = (char*)malloc(msg.length()+1*sizeof(char)); | 76 | message = (char*)malloc(msg.length()+1*sizeof(char)); |
76 | memset(message,0,msg.length()+1); | 77 | memset(message,0,msg.length()+1); |
77 | memcpy(message,msg.latin1(),msg.length()); | 78 | memcpy(message,msg.latin1(),msg.length()); |
78 | /* transform to libetpan stuff */ | 79 | /* transform to libetpan stuff */ |
79 | mailmsg = mailmessage_new(); | 80 | mailmsg = mailmessage_new(); |
80 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); | 81 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); |
81 | generic_message_t * msg_data; | 82 | generic_message_t * msg_data; |
82 | msg_data = (generic_message_t *)mailmsg->msg_data; | 83 | msg_data = (generic_message_t *)mailmsg->msg_data; |
83 | msg_data->msg_fetched = 1; | 84 | msg_data->msg_fetched = 1; |
84 | msg_data->msg_message = message; | 85 | msg_data->msg_message = message; |
85 | msg_data->msg_length = strlen(message); | 86 | msg_data->msg_length = strlen(message); |
86 | } | 87 | } |
87 | body = parseMail(mailmsg); | 88 | body = parseMail(mailmsg); |
88 | 89 | ||
89 | /* clean up */ | 90 | /* clean up */ |
90 | if (mailmsg) | 91 | if (mailmsg) |
91 | mailmessage_free(mailmsg); | 92 | mailmessage_free(mailmsg); |
92 | if (message) | 93 | if (message) |
93 | free(message); | 94 | free(message); |
94 | 95 | ||
95 | return body; | 96 | return body; |
96 | } | 97 | } |
97 | 98 | ||
98 | void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) | 99 | void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) |
99 | { | 100 | { |
100 | login(); | 101 | login(); |
101 | if (!m_pop3) | 102 | if (!m_pop3) |
102 | return; | 103 | return; |
103 | uint32_t res_messages,res_recent,res_unseen; | 104 | uint32_t res_messages,res_recent,res_unseen; |
104 | mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); | 105 | mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); |
105 | parseList(target,m_pop3->sto_session,"INBOX"); | 106 | parseList(target,m_pop3->sto_session,"INBOX"); |
106 | Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); | 107 | Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); |
107 | } | 108 | } |
108 | 109 | ||
109 | void POP3wrapper::login() | 110 | void POP3wrapper::login() |
110 | { | 111 | { |
111 | if (account->getOffline()) | 112 | if (account->getOffline()) |
112 | return; | 113 | return; |
113 | /* we'll hold the line */ | 114 | /* we'll hold the line */ |
114 | if ( m_pop3 != NULL ) | 115 | if ( m_pop3 != NULL ) |
115 | return; | 116 | return; |
116 | 117 | ||
117 | const char *server, *user, *pass; | 118 | const char *server, *user, *pass; |
118 | uint16_t port; | 119 | uint16_t port; |
119 | int err = MAILPOP3_NO_ERROR; | 120 | int err = MAILPOP3_NO_ERROR; |
120 | 121 | ||
121 | server = account->getServer().latin1(); | 122 | server = account->getServer().latin1(); |
122 | port = account->getPort().toUInt(); | 123 | port = account->getPort().toUInt(); |
123 | 124 | ||
124 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 125 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
125 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 126 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
126 | login.show(); | 127 | login.show(); |
127 | if ( QDialog::Accepted == login.exec() ) { | 128 | if ( QDialog::Accepted == login.exec() ) { |
128 | // ok | 129 | // ok |
129 | user = login.getUser().latin1(); | 130 | user = login.getUser().latin1(); |
130 | pass = login.getPassword().latin1(); | 131 | pass = login.getPassword().latin1(); |
131 | } else { | 132 | } else { |
132 | // cancel | 133 | // cancel |
133 | odebug << "POP3: Login canceled" << oendl; | 134 | odebug << "POP3: Login canceled" << oendl; |
134 | return; | 135 | return; |
135 | } | 136 | } |
136 | } else { | 137 | } else { |
137 | user = account->getUser().latin1(); | 138 | user = account->getUser().latin1(); |
138 | pass = account->getPassword().latin1(); | 139 | pass = account->getPassword().latin1(); |
139 | } | 140 | } |
140 | 141 | ||
141 | // bool ssl = account->getSSL(); | 142 | // bool ssl = account->getSSL(); |
142 | 143 | ||
143 | m_pop3=mailstorage_new(NULL); | 144 | m_pop3=mailstorage_new(NULL); |
144 | 145 | ||
145 | int conntypeset = account->ConnectionType(); | 146 | int conntypeset = account->ConnectionType(); |
146 | int conntype = 0; | 147 | int conntype = 0; |
147 | if ( conntypeset == 3 ) { | 148 | if ( conntypeset == 3 ) { |
148 | conntype = CONNECTION_TYPE_COMMAND; | 149 | conntype = CONNECTION_TYPE_COMMAND; |
149 | } else if ( conntypeset == 2 ) { | 150 | } else if ( conntypeset == 2 ) { |
150 | conntype = CONNECTION_TYPE_TLS; | 151 | conntype = CONNECTION_TYPE_TLS; |
151 | } else if ( conntypeset == 1 ) { | 152 | } else if ( conntypeset == 1 ) { |
152 | conntype = CONNECTION_TYPE_STARTTLS; | 153 | conntype = CONNECTION_TYPE_STARTTLS; |
153 | } else if ( conntypeset == 0 ) { | 154 | } else if ( conntypeset == 0 ) { |
154 | conntype = CONNECTION_TYPE_TRY_STARTTLS; | 155 | conntype = CONNECTION_TYPE_TRY_STARTTLS; |
155 | } | 156 | } |
156 | 157 | ||
157 | //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); | 158 | //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); |
158 | 159 | ||
159 | pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, | 160 | pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, |
160 | (char*)user,(char*)pass,0,0,0); | 161 | (char*)user,(char*)pass,0,0,0); |
161 | 162 | ||
162 | 163 | ||
163 | err = mailstorage_connect(m_pop3); | 164 | err = mailstorage_connect(m_pop3); |
164 | if (err != MAIL_NO_ERROR) { | 165 | if (err != MAIL_NO_ERROR) { |
165 | odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; | 166 | odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; |
166 | Global::statusMessage(tr("Error initializing folder")); | 167 | Global::statusMessage(tr("Error initializing folder")); |
167 | mailstorage_free(m_pop3); | 168 | mailstorage_free(m_pop3); |
168 | m_pop3 = 0; | 169 | m_pop3 = 0; |
169 | } else { | 170 | } else { |
170 | mailsession * session = m_pop3->sto_session; | 171 | mailsession * session = m_pop3->sto_session; |
171 | mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; | 172 | mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; |
172 | if (mail) { | 173 | if (mail) { |
173 | mail->pop3_progr_fun = &pop3_progress; | 174 | mail->pop3_progr_fun = &pop3_progress; |
174 | } | 175 | } |
175 | } | 176 | } |
176 | } | 177 | } |
177 | 178 | ||
178 | void POP3wrapper::logout() | 179 | void POP3wrapper::logout() |
179 | { | 180 | { |
180 | if ( m_pop3 == NULL ) | 181 | if ( m_pop3 == NULL ) |
181 | return; | 182 | return; |
182 | mailstorage_free(m_pop3); | 183 | mailstorage_free(m_pop3); |
183 | m_pop3 = 0; | 184 | m_pop3 = 0; |
184 | } | 185 | } |
185 | 186 | ||
186 | 187 | ||
187 | QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { | 188 | QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { |
188 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); | 189 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); |
189 | FolderP inb=new Folder("INBOX","/"); | 190 | FolderP inb=new Folder("INBOX","/"); |
190 | folders->append(inb); | 191 | folders->append(inb); |
191 | return folders; | 192 | return folders; |
192 | } | 193 | } |
193 | 194 | ||
194 | void POP3wrapper::deleteMail(const RecMailP&mail) { | 195 | void POP3wrapper::deleteMail(const RecMailP&mail) { |
195 | login(); | 196 | login(); |
196 | if (!m_pop3) | 197 | if (!m_pop3) |
197 | return; | 198 | return; |
198 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); | 199 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); |
199 | if (err != MAIL_NO_ERROR) { | 200 | if (err != MAIL_NO_ERROR) { |
200 | Global::statusMessage(tr("error deleting mail")); | 201 | Global::statusMessage(tr("error deleting mail")); |
201 | } | 202 | } |
202 | } | 203 | } |
203 | 204 | ||
204 | void POP3wrapper::answeredMail(const RecMailP&) {} | 205 | void POP3wrapper::answeredMail(const RecMailP&) {} |
205 | 206 | ||
206 | int POP3wrapper::deleteAllMail(const FolderP&) { | 207 | int POP3wrapper::deleteAllMail(const FolderP&) { |
207 | login(); | 208 | login(); |
208 | if (!m_pop3) | 209 | if (!m_pop3) |
209 | return 0; | 210 | return 0; |
210 | int res = 1; | 211 | int res = 1; |
211 | 212 | ||
212 | uint32_t result = 0; | 213 | uint32_t result = 0; |
213 | int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); | 214 | int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); |
214 | if (err != MAIL_NO_ERROR) { | 215 | if (err != MAIL_NO_ERROR) { |
215 | Global::statusMessage(tr("Error getting folder info")); | 216 | Global::statusMessage(tr("Error getting folder info")); |
216 | return 0; | 217 | return 0; |
217 | } | 218 | } |
218 | for (unsigned int i = 0; i < result; ++i) { | 219 | for (unsigned int i = 0; i < result; ++i) { |
219 | err = mailsession_remove_message(m_pop3->sto_session,i+1); | 220 | err = mailsession_remove_message(m_pop3->sto_session,i+1); |
220 | if (err != MAIL_NO_ERROR) { | 221 | if (err != MAIL_NO_ERROR) { |
221 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 222 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
222 | res=0; | 223 | res=0; |
223 | } | 224 | } |
224 | break; | 225 | break; |
225 | } | 226 | } |
226 | return res; | 227 | return res; |
227 | } | 228 | } |
228 | 229 | ||
229 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { | 230 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { |
230 | login(); | 231 | login(); |
231 | target_stat.message_count = 0; | 232 | target_stat.message_count = 0; |
232 | target_stat.message_unseen = 0; | 233 | target_stat.message_unseen = 0; |
233 | target_stat.message_recent = 0; | 234 | target_stat.message_recent = 0; |
234 | if (!m_pop3) | 235 | if (!m_pop3) |
235 | return; | 236 | return; |
236 | int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, | 237 | int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, |
237 | &target_stat.message_recent,&target_stat.message_unseen); | 238 | &target_stat.message_recent,&target_stat.message_unseen); |
238 | if (r != MAIL_NO_ERROR) { | 239 | if (r != MAIL_NO_ERROR) { |
239 | odebug << "error getting folter status." << oendl; | 240 | odebug << "error getting folter status." << oendl; |
240 | } | 241 | } |
241 | } | 242 | } |
242 | 243 | ||
243 | encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { | 244 | encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { |
244 | char*target=0; | 245 | char*target=0; |
245 | size_t length=0; | 246 | size_t length=0; |
246 | encodedString*res = 0; | 247 | encodedString*res = 0; |
247 | mailmessage * mailmsg = 0; | 248 | mailmessage * mailmsg = 0; |
248 | int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); | 249 | int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); |
249 | err = mailmessage_fetch(mailmsg,&target,&length); | 250 | err = mailmessage_fetch(mailmsg,&target,&length); |
250 | if (mailmsg) | 251 | if (mailmsg) |
251 | mailmessage_free(mailmsg); | 252 | mailmessage_free(mailmsg); |
252 | if (target) { | 253 | if (target) { |
253 | res = new encodedString(target,length); | 254 | res = new encodedString(target,length); |
254 | } | 255 | } |
255 | return res; | 256 | return res; |
256 | } | 257 | } |
257 | 258 | ||
258 | MAILLIB::ATYPE POP3wrapper::getType()const { | 259 | MAILLIB::ATYPE POP3wrapper::getType()const { |
259 | return account->getType(); | 260 | return account->getType(); |
260 | } | 261 | } |
261 | 262 | ||
262 | const QString&POP3wrapper::getName()const{ | 263 | const QString&POP3wrapper::getName()const{ |
263 | return account->getAccountName(); | 264 | return account->getAccountName(); |
264 | } | 265 | } |
diff --git a/noncore/net/mail/libmailwrapper/settings.cpp b/noncore/net/mail/libmailwrapper/settings.cpp index de36eeb..3c9b25c 100644 --- a/noncore/net/mail/libmailwrapper/settings.cpp +++ b/noncore/net/mail/libmailwrapper/settings.cpp | |||
@@ -1,440 +1,441 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <qdir.h> | 2 | #include <qdir.h> |
3 | 3 | ||
4 | #include <opie2/odebug.h> | ||
4 | #include <qpe/config.h> | 5 | #include <qpe/config.h> |
5 | 6 | ||
6 | #include "settings.h" | 7 | #include "settings.h" |
7 | //#include "defines.h" | 8 | //#include "defines.h" |
8 | 9 | ||
9 | #define IMAP_PORT "143" | 10 | #define IMAP_PORT "143" |
10 | #define IMAP_SSL_PORT "993" | 11 | #define IMAP_SSL_PORT "993" |
11 | #define SMTP_PORT "25" | 12 | #define SMTP_PORT "25" |
12 | #define SMTP_SSL_PORT "465" | 13 | #define SMTP_SSL_PORT "465" |
13 | #define POP3_PORT "110" | 14 | #define POP3_PORT "110" |
14 | #define POP3_SSL_PORT "995" | 15 | #define POP3_SSL_PORT "995" |
15 | #define NNTP_PORT "119" | 16 | #define NNTP_PORT "119" |
16 | #define NNTP_SSL_PORT "563" | 17 | #define NNTP_SSL_PORT "563" |
17 | 18 | ||
18 | 19 | ||
19 | Settings::Settings() | 20 | Settings::Settings() |
20 | : QObject() | 21 | : QObject() |
21 | { | 22 | { |
22 | updateAccounts(); | 23 | updateAccounts(); |
23 | } | 24 | } |
24 | 25 | ||
25 | void Settings::checkDirectory() | 26 | void Settings::checkDirectory() |
26 | { | 27 | { |
27 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { | 28 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { |
28 | system( "mkdir -p $HOME/Applications/opiemail" ); | 29 | system( "mkdir -p $HOME/Applications/opiemail" ); |
29 | odebug << "$HOME/Applications/opiemail created" << oendl; | 30 | odebug << "$HOME/Applications/opiemail created" << oendl; |
30 | } | 31 | } |
31 | } | 32 | } |
32 | 33 | ||
33 | QList<Account> Settings::getAccounts() | 34 | QList<Account> Settings::getAccounts() |
34 | { | 35 | { |
35 | return accounts; | 36 | return accounts; |
36 | } | 37 | } |
37 | 38 | ||
38 | void Settings::addAccount( Account *account ) | 39 | void Settings::addAccount( Account *account ) |
39 | { | 40 | { |
40 | accounts.append( account ); | 41 | accounts.append( account ); |
41 | } | 42 | } |
42 | 43 | ||
43 | void Settings::delAccount( Account *account ) | 44 | void Settings::delAccount( Account *account ) |
44 | { | 45 | { |
45 | accounts.remove( account ); | 46 | accounts.remove( account ); |
46 | account->remove(); | 47 | account->remove(); |
47 | } | 48 | } |
48 | 49 | ||
49 | void Settings::updateAccounts() | 50 | void Settings::updateAccounts() |
50 | { | 51 | { |
51 | accounts.clear(); | 52 | accounts.clear(); |
52 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | 53 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); |
53 | QStringList::Iterator it; | 54 | QStringList::Iterator it; |
54 | 55 | ||
55 | QStringList imap = dir.entryList( "imap-*" ); | 56 | QStringList imap = dir.entryList( "imap-*" ); |
56 | for ( it = imap.begin(); it != imap.end(); it++ ) { | 57 | for ( it = imap.begin(); it != imap.end(); it++ ) { |
57 | odebug << "Added IMAP account" << oendl; | 58 | odebug << "Added IMAP account" << oendl; |
58 | IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); | 59 | IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); |
59 | accounts.append( account ); | 60 | accounts.append( account ); |
60 | } | 61 | } |
61 | 62 | ||
62 | QStringList pop3 = dir.entryList( "pop3-*" ); | 63 | QStringList pop3 = dir.entryList( "pop3-*" ); |
63 | for ( it = pop3.begin(); it != pop3.end(); it++ ) { | 64 | for ( it = pop3.begin(); it != pop3.end(); it++ ) { |
64 | odebug << "Added POP account" << oendl; | 65 | odebug << "Added POP account" << oendl; |
65 | POP3account *account = new POP3account( (*it).replace(0, 5, "") ); | 66 | POP3account *account = new POP3account( (*it).replace(0, 5, "") ); |
66 | accounts.append( account ); | 67 | accounts.append( account ); |
67 | } | 68 | } |
68 | 69 | ||
69 | QStringList smtp = dir.entryList( "smtp-*" ); | 70 | QStringList smtp = dir.entryList( "smtp-*" ); |
70 | for ( it = smtp.begin(); it != smtp.end(); it++ ) { | 71 | for ( it = smtp.begin(); it != smtp.end(); it++ ) { |
71 | odebug << "Added SMTP account" << oendl; | 72 | odebug << "Added SMTP account" << oendl; |
72 | SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); | 73 | SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); |
73 | accounts.append( account ); | 74 | accounts.append( account ); |
74 | } | 75 | } |
75 | 76 | ||
76 | QStringList nntp = dir.entryList( "nntp-*" ); | 77 | QStringList nntp = dir.entryList( "nntp-*" ); |
77 | for ( it = nntp.begin(); it != nntp.end(); it++ ) { | 78 | for ( it = nntp.begin(); it != nntp.end(); it++ ) { |
78 | odebug << "Added NNTP account" << oendl; | 79 | odebug << "Added NNTP account" << oendl; |
79 | NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); | 80 | NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); |
80 | accounts.append( account ); | 81 | accounts.append( account ); |
81 | } | 82 | } |
82 | 83 | ||
83 | readAccounts(); | 84 | readAccounts(); |
84 | } | 85 | } |
85 | 86 | ||
86 | void Settings::saveAccounts() | 87 | void Settings::saveAccounts() |
87 | { | 88 | { |
88 | checkDirectory(); | 89 | checkDirectory(); |
89 | Account *it; | 90 | Account *it; |
90 | 91 | ||
91 | for ( it = accounts.first(); it; it = accounts.next() ) { | 92 | for ( it = accounts.first(); it; it = accounts.next() ) { |
92 | it->save(); | 93 | it->save(); |
93 | } | 94 | } |
94 | } | 95 | } |
95 | 96 | ||
96 | void Settings::readAccounts() | 97 | void Settings::readAccounts() |
97 | { | 98 | { |
98 | checkDirectory(); | 99 | checkDirectory(); |
99 | Account *it; | 100 | Account *it; |
100 | 101 | ||
101 | for ( it = accounts.first(); it; it = accounts.next() ) { | 102 | for ( it = accounts.first(); it; it = accounts.next() ) { |
102 | it->read(); | 103 | it->read(); |
103 | } | 104 | } |
104 | } | 105 | } |
105 | 106 | ||
106 | Account::Account() | 107 | Account::Account() |
107 | { | 108 | { |
108 | accountName = "changeMe"; | 109 | accountName = "changeMe"; |
109 | type = MAILLIB::A_UNDEFINED; | 110 | type = MAILLIB::A_UNDEFINED; |
110 | ssl = false; | 111 | ssl = false; |
111 | connectionType = 1; | 112 | connectionType = 1; |
112 | offline = false; | 113 | offline = false; |
113 | } | 114 | } |
114 | 115 | ||
115 | void Account::remove() | 116 | void Account::remove() |
116 | { | 117 | { |
117 | QFile file( getFileName() ); | 118 | QFile file( getFileName() ); |
118 | file.remove(); | 119 | file.remove(); |
119 | } | 120 | } |
120 | 121 | ||
121 | IMAPaccount::IMAPaccount() | 122 | IMAPaccount::IMAPaccount() |
122 | : Account() | 123 | : Account() |
123 | { | 124 | { |
124 | file = IMAPaccount::getUniqueFileName(); | 125 | file = IMAPaccount::getUniqueFileName(); |
125 | accountName = "New IMAP Account"; | 126 | accountName = "New IMAP Account"; |
126 | ssl = false; | 127 | ssl = false; |
127 | connectionType = 1; | 128 | connectionType = 1; |
128 | type = MAILLIB::A_IMAP; | 129 | type = MAILLIB::A_IMAP; |
129 | port = IMAP_PORT; | 130 | port = IMAP_PORT; |
130 | } | 131 | } |
131 | 132 | ||
132 | IMAPaccount::IMAPaccount( QString filename ) | 133 | IMAPaccount::IMAPaccount( QString filename ) |
133 | : Account() | 134 | : Account() |
134 | { | 135 | { |
135 | file = filename; | 136 | file = filename; |
136 | accountName = "New IMAP Account"; | 137 | accountName = "New IMAP Account"; |
137 | ssl = false; | 138 | ssl = false; |
138 | connectionType = 1; | 139 | connectionType = 1; |
139 | type = MAILLIB::A_IMAP; | 140 | type = MAILLIB::A_IMAP; |
140 | port = IMAP_PORT; | 141 | port = IMAP_PORT; |
141 | } | 142 | } |
142 | 143 | ||
143 | QString IMAPaccount::getUniqueFileName() | 144 | QString IMAPaccount::getUniqueFileName() |
144 | { | 145 | { |
145 | int num = 0; | 146 | int num = 0; |
146 | QString unique; | 147 | QString unique; |
147 | 148 | ||
148 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | 149 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); |
149 | 150 | ||
150 | QStringList imap = dir.entryList( "imap-*" ); | 151 | QStringList imap = dir.entryList( "imap-*" ); |
151 | do { | 152 | do { |
152 | unique.setNum( num++ ); | 153 | unique.setNum( num++ ); |
153 | } while ( imap.contains( "imap-" + unique ) > 0 ); | 154 | } while ( imap.contains( "imap-" + unique ) > 0 ); |
154 | 155 | ||
155 | return unique; | 156 | return unique; |
156 | } | 157 | } |
157 | 158 | ||
158 | void IMAPaccount::read() | 159 | void IMAPaccount::read() |
159 | { | 160 | { |
160 | Config *conf = new Config( getFileName(), Config::File ); | 161 | Config *conf = new Config( getFileName(), Config::File ); |
161 | conf->setGroup( "IMAP Account" ); | 162 | conf->setGroup( "IMAP Account" ); |
162 | accountName = conf->readEntry( "Account","" ); | 163 | accountName = conf->readEntry( "Account","" ); |
163 | if (accountName.isNull()) accountName = ""; | 164 | if (accountName.isNull()) accountName = ""; |
164 | server = conf->readEntry( "Server","" ); | 165 | server = conf->readEntry( "Server","" ); |
165 | if (server.isNull()) server=""; | 166 | if (server.isNull()) server=""; |
166 | port = conf->readEntry( "Port","" ); | 167 | port = conf->readEntry( "Port","" ); |
167 | if (port.isNull()) port="143"; | 168 | if (port.isNull()) port="143"; |
168 | connectionType = conf->readNumEntry( "ConnectionType" ); | 169 | connectionType = conf->readNumEntry( "ConnectionType" ); |
169 | ssl = conf->readBoolEntry( "SSL",false ); | 170 | ssl = conf->readBoolEntry( "SSL",false ); |
170 | user = conf->readEntry( "User","" ); | 171 | user = conf->readEntry( "User","" ); |
171 | if (user.isNull()) user = ""; | 172 | if (user.isNull()) user = ""; |
172 | password = conf->readEntryCrypt( "Password","" ); | 173 | password = conf->readEntryCrypt( "Password","" ); |
173 | if (password.isNull()) password = ""; | 174 | if (password.isNull()) password = ""; |
174 | prefix = conf->readEntry("MailPrefix",""); | 175 | prefix = conf->readEntry("MailPrefix",""); |
175 | if (prefix.isNull()) prefix = ""; | 176 | if (prefix.isNull()) prefix = ""; |
176 | offline = conf->readBoolEntry("Offline",false); | 177 | offline = conf->readBoolEntry("Offline",false); |
177 | delete conf; | 178 | delete conf; |
178 | } | 179 | } |
179 | 180 | ||
180 | void IMAPaccount::save() | 181 | void IMAPaccount::save() |
181 | { | 182 | { |
182 | odebug << "saving " + getFileName() << oendl; | 183 | odebug << "saving " + getFileName() << oendl; |
183 | Settings::checkDirectory(); | 184 | Settings::checkDirectory(); |
184 | 185 | ||
185 | Config *conf = new Config( getFileName(), Config::File ); | 186 | Config *conf = new Config( getFileName(), Config::File ); |
186 | conf->setGroup( "IMAP Account" ); | 187 | conf->setGroup( "IMAP Account" ); |
187 | conf->writeEntry( "Account", accountName ); | 188 | conf->writeEntry( "Account", accountName ); |
188 | conf->writeEntry( "Server", server ); | 189 | conf->writeEntry( "Server", server ); |
189 | conf->writeEntry( "Port", port ); | 190 | conf->writeEntry( "Port", port ); |
190 | conf->writeEntry( "SSL", ssl ); | 191 | conf->writeEntry( "SSL", ssl ); |
191 | conf->writeEntry( "ConnectionType", connectionType ); | 192 | conf->writeEntry( "ConnectionType", connectionType ); |
192 | conf->writeEntry( "User", user ); | 193 | conf->writeEntry( "User", user ); |
193 | conf->writeEntryCrypt( "Password", password ); | 194 | conf->writeEntryCrypt( "Password", password ); |
194 | conf->writeEntry( "MailPrefix",prefix); | 195 | conf->writeEntry( "MailPrefix",prefix); |
195 | conf->writeEntry( "Offline",offline); | 196 | conf->writeEntry( "Offline",offline); |
196 | conf->write(); | 197 | conf->write(); |
197 | delete conf; | 198 | delete conf; |
198 | } | 199 | } |
199 | 200 | ||
200 | 201 | ||
201 | QString IMAPaccount::getFileName() | 202 | QString IMAPaccount::getFileName() |
202 | { | 203 | { |
203 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/imap-" + file; | 204 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/imap-" + file; |
204 | } | 205 | } |
205 | 206 | ||
206 | POP3account::POP3account() | 207 | POP3account::POP3account() |
207 | : Account() | 208 | : Account() |
208 | { | 209 | { |
209 | file = POP3account::getUniqueFileName(); | 210 | file = POP3account::getUniqueFileName(); |
210 | accountName = "New POP3 Account"; | 211 | accountName = "New POP3 Account"; |
211 | ssl = false; | 212 | ssl = false; |
212 | connectionType = 1; | 213 | connectionType = 1; |
213 | type = MAILLIB::A_POP3; | 214 | type = MAILLIB::A_POP3; |
214 | port = POP3_PORT; | 215 | port = POP3_PORT; |
215 | } | 216 | } |
216 | 217 | ||
217 | POP3account::POP3account( QString filename ) | 218 | POP3account::POP3account( QString filename ) |
218 | : Account() | 219 | : Account() |
219 | { | 220 | { |
220 | file = filename; | 221 | file = filename; |
221 | accountName = "New POP3 Account"; | 222 | accountName = "New POP3 Account"; |
222 | ssl = false; | 223 | ssl = false; |
223 | connectionType = 1; | 224 | connectionType = 1; |
224 | type = MAILLIB::A_POP3; | 225 | type = MAILLIB::A_POP3; |
225 | port = POP3_PORT; | 226 | port = POP3_PORT; |
226 | } | 227 | } |
227 | 228 | ||
228 | QString POP3account::getUniqueFileName() | 229 | QString POP3account::getUniqueFileName() |
229 | { | 230 | { |
230 | int num = 0; | 231 | int num = 0; |
231 | QString unique; | 232 | QString unique; |
232 | 233 | ||
233 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | 234 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); |
234 | 235 | ||
235 | QStringList imap = dir.entryList( "pop3-*" ); | 236 | QStringList imap = dir.entryList( "pop3-*" ); |
236 | do { | 237 | do { |
237 | unique.setNum( num++ ); | 238 | unique.setNum( num++ ); |
238 | } while ( imap.contains( "pop3-" + unique ) > 0 ); | 239 | } while ( imap.contains( "pop3-" + unique ) > 0 ); |
239 | 240 | ||
240 | return unique; | 241 | return unique; |
241 | } | 242 | } |
242 | 243 | ||
243 | void POP3account::read() | 244 | void POP3account::read() |
244 | { | 245 | { |
245 | Config *conf = new Config( getFileName(), Config::File ); | 246 | Config *conf = new Config( getFileName(), Config::File ); |
246 | conf->setGroup( "POP3 Account" ); | 247 | conf->setGroup( "POP3 Account" ); |
247 | accountName = conf->readEntry( "Account" ); | 248 | accountName = conf->readEntry( "Account" ); |
248 | server = conf->readEntry( "Server" ); | 249 | server = conf->readEntry( "Server" ); |
249 | port = conf->readEntry( "Port" ); | 250 | port = conf->readEntry( "Port" ); |
250 | ssl = conf->readBoolEntry( "SSL" ); | 251 | ssl = conf->readBoolEntry( "SSL" ); |
251 | connectionType = conf->readNumEntry( "ConnectionType" ); | 252 | connectionType = conf->readNumEntry( "ConnectionType" ); |
252 | user = conf->readEntry( "User" ); | 253 | user = conf->readEntry( "User" ); |
253 | password = conf->readEntryCrypt( "Password" ); | 254 | password = conf->readEntryCrypt( "Password" ); |
254 | offline = conf->readBoolEntry("Offline",false); | 255 | offline = conf->readBoolEntry("Offline",false); |
255 | delete conf; | 256 | delete conf; |
256 | } | 257 | } |
257 | 258 | ||
258 | void POP3account::save() | 259 | void POP3account::save() |
259 | { | 260 | { |
260 | odebug << "saving " + getFileName() << oendl; | 261 | odebug << "saving " + getFileName() << oendl; |
261 | Settings::checkDirectory(); | 262 | Settings::checkDirectory(); |
262 | 263 | ||
263 | Config *conf = new Config( getFileName(), Config::File ); | 264 | Config *conf = new Config( getFileName(), Config::File ); |
264 | conf->setGroup( "POP3 Account" ); | 265 | conf->setGroup( "POP3 Account" ); |
265 | conf->writeEntry( "Account", accountName ); | 266 | conf->writeEntry( "Account", accountName ); |
266 | conf->writeEntry( "Server", server ); | 267 | conf->writeEntry( "Server", server ); |
267 | conf->writeEntry( "Port", port ); | 268 | conf->writeEntry( "Port", port ); |
268 | conf->writeEntry( "SSL", ssl ); | 269 | conf->writeEntry( "SSL", ssl ); |
269 | conf->writeEntry( "ConnectionType", connectionType ); | 270 | conf->writeEntry( "ConnectionType", connectionType ); |
270 | conf->writeEntry( "User", user ); | 271 | conf->writeEntry( "User", user ); |
271 | conf->writeEntryCrypt( "Password", password ); | 272 | conf->writeEntryCrypt( "Password", password ); |
272 | conf->writeEntry( "Offline",offline); | 273 | conf->writeEntry( "Offline",offline); |
273 | conf->write(); | 274 | conf->write(); |
274 | delete conf; | 275 | delete conf; |
275 | } | 276 | } |
276 | 277 | ||
277 | 278 | ||
278 | QString POP3account::getFileName() | 279 | QString POP3account::getFileName() |
279 | { | 280 | { |
280 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/pop3-" + file; | 281 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/pop3-" + file; |
281 | } | 282 | } |
282 | 283 | ||
283 | SMTPaccount::SMTPaccount() | 284 | SMTPaccount::SMTPaccount() |
284 | : Account() | 285 | : Account() |
285 | { | 286 | { |
286 | file = SMTPaccount::getUniqueFileName(); | 287 | file = SMTPaccount::getUniqueFileName(); |
287 | accountName = "New SMTP Account"; | 288 | accountName = "New SMTP Account"; |
288 | ssl = false; | 289 | ssl = false; |
289 | connectionType = 1; | 290 | connectionType = 1; |
290 | login = false; | 291 | login = false; |
291 | useCC = false; | 292 | useCC = false; |
292 | useBCC = false; | 293 | useBCC = false; |
293 | useReply = false; | 294 | useReply = false; |
294 | type = MAILLIB::A_SMTP; | 295 | type = MAILLIB::A_SMTP; |
295 | port = SMTP_PORT; | 296 | port = SMTP_PORT; |
296 | } | 297 | } |
297 | 298 | ||
298 | SMTPaccount::SMTPaccount( QString filename ) | 299 | SMTPaccount::SMTPaccount( QString filename ) |
299 | : Account() | 300 | : Account() |
300 | { | 301 | { |
301 | file = filename; | 302 | file = filename; |
302 | accountName = "New SMTP Account"; | 303 | accountName = "New SMTP Account"; |
303 | ssl = false; | 304 | ssl = false; |
304 | connectionType = 1; | 305 | connectionType = 1; |
305 | login = false; | 306 | login = false; |
306 | type = MAILLIB::A_SMTP; | 307 | type = MAILLIB::A_SMTP; |
307 | port = SMTP_PORT; | 308 | port = SMTP_PORT; |
308 | } | 309 | } |
309 | 310 | ||
310 | QString SMTPaccount::getUniqueFileName() | 311 | QString SMTPaccount::getUniqueFileName() |
311 | { | 312 | { |
312 | int num = 0; | 313 | int num = 0; |
313 | QString unique; | 314 | QString unique; |
314 | 315 | ||
315 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | 316 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); |
316 | 317 | ||
317 | QStringList imap = dir.entryList( "smtp-*" ); | 318 | QStringList imap = dir.entryList( "smtp-*" ); |
318 | do { | 319 | do { |
319 | unique.setNum( num++ ); | 320 | unique.setNum( num++ ); |
320 | } while ( imap.contains( "smtp-" + unique ) > 0 ); | 321 | } while ( imap.contains( "smtp-" + unique ) > 0 ); |
321 | 322 | ||
322 | return unique; | 323 | return unique; |
323 | } | 324 | } |
324 | 325 | ||
325 | void SMTPaccount::read() | 326 | void SMTPaccount::read() |
326 | { | 327 | { |
327 | Config *conf = new Config( getFileName(), Config::File ); | 328 | Config *conf = new Config( getFileName(), Config::File ); |
328 | conf->setGroup( "SMTP Account" ); | 329 | conf->setGroup( "SMTP Account" ); |
329 | accountName = conf->readEntry( "Account" ); | 330 | accountName = conf->readEntry( "Account" ); |
330 | server = conf->readEntry( "Server" ); | 331 | server = conf->readEntry( "Server" ); |
331 | port = conf->readEntry( "Port" ); | 332 | port = conf->readEntry( "Port" ); |
332 | ssl = conf->readBoolEntry( "SSL" ); | 333 | ssl = conf->readBoolEntry( "SSL" ); |
333 | connectionType = conf->readNumEntry( "ConnectionType" ); | 334 | connectionType = conf->readNumEntry( "ConnectionType" ); |
334 | login = conf->readBoolEntry( "Login" ); | 335 | login = conf->readBoolEntry( "Login" ); |
335 | user = conf->readEntry( "User" ); | 336 | user = conf->readEntry( "User" ); |
336 | password = conf->readEntryCrypt( "Password" ); | 337 | password = conf->readEntryCrypt( "Password" ); |
337 | delete conf; | 338 | delete conf; |
338 | } | 339 | } |
339 | 340 | ||
340 | void SMTPaccount::save() | 341 | void SMTPaccount::save() |
341 | { | 342 | { |
342 | odebug << "saving " + getFileName() << oendl; | 343 | odebug << "saving " + getFileName() << oendl; |
343 | Settings::checkDirectory(); | 344 | Settings::checkDirectory(); |
344 | 345 | ||
345 | Config *conf = new Config( getFileName(), Config::File ); | 346 | Config *conf = new Config( getFileName(), Config::File ); |
346 | conf->setGroup( "SMTP Account" ); | 347 | conf->setGroup( "SMTP Account" ); |
347 | conf->writeEntry( "Account", accountName ); | 348 | conf->writeEntry( "Account", accountName ); |
348 | conf->writeEntry( "Server", server ); | 349 | conf->writeEntry( "Server", server ); |
349 | conf->writeEntry( "Port", port ); | 350 | conf->writeEntry( "Port", port ); |
350 | conf->writeEntry( "SSL", ssl ); | 351 | conf->writeEntry( "SSL", ssl ); |
351 | conf->writeEntry( "ConnectionType", connectionType ); | 352 | conf->writeEntry( "ConnectionType", connectionType ); |
352 | conf->writeEntry( "Login", login ); | 353 | conf->writeEntry( "Login", login ); |
353 | conf->writeEntry( "User", user ); | 354 | conf->writeEntry( "User", user ); |
354 | conf->writeEntryCrypt( "Password", password ); | 355 | conf->writeEntryCrypt( "Password", password ); |
355 | conf->write(); | 356 | conf->write(); |
356 | delete conf; | 357 | delete conf; |
357 | } | 358 | } |
358 | 359 | ||
359 | 360 | ||
360 | QString SMTPaccount::getFileName() | 361 | QString SMTPaccount::getFileName() |
361 | { | 362 | { |
362 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/smtp-" + file; | 363 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/smtp-" + file; |
363 | } | 364 | } |
364 | 365 | ||
365 | NNTPaccount::NNTPaccount() | 366 | NNTPaccount::NNTPaccount() |
366 | : Account() | 367 | : Account() |
367 | { | 368 | { |
368 | file = NNTPaccount::getUniqueFileName(); | 369 | file = NNTPaccount::getUniqueFileName(); |
369 | accountName = "New NNTP Account"; | 370 | accountName = "New NNTP Account"; |
370 | ssl = false; | 371 | ssl = false; |
371 | login = false; | 372 | login = false; |
372 | type = MAILLIB::A_NNTP; | 373 | type = MAILLIB::A_NNTP; |
373 | port = NNTP_PORT; | 374 | port = NNTP_PORT; |
374 | } | 375 | } |
375 | 376 | ||
376 | NNTPaccount::NNTPaccount( QString filename ) | 377 | NNTPaccount::NNTPaccount( QString filename ) |
377 | : Account() | 378 | : Account() |
378 | { | 379 | { |
379 | file = filename; | 380 | file = filename; |
380 | accountName = "New NNTP Account"; | 381 | accountName = "New NNTP Account"; |
381 | ssl = false; | 382 | ssl = false; |
382 | login = false; | 383 | login = false; |
383 | type = MAILLIB::A_NNTP; | 384 | type = MAILLIB::A_NNTP; |
384 | port = NNTP_PORT; | 385 | port = NNTP_PORT; |
385 | } | 386 | } |
386 | 387 | ||
387 | QString NNTPaccount::getUniqueFileName() | 388 | QString NNTPaccount::getUniqueFileName() |
388 | { | 389 | { |
389 | int num = 0; | 390 | int num = 0; |
390 | QString unique; | 391 | QString unique; |
391 | 392 | ||
392 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | 393 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); |
393 | 394 | ||
394 | QStringList imap = dir.entryList( "nntp-*" ); | 395 | QStringList imap = dir.entryList( "nntp-*" ); |
395 | do { | 396 | do { |
396 | unique.setNum( num++ ); | 397 | unique.setNum( num++ ); |
397 | } while ( imap.contains( "nntp-" + unique ) > 0 ); | 398 | } while ( imap.contains( "nntp-" + unique ) > 0 ); |
398 | 399 | ||
399 | return unique; | 400 | return unique; |
400 | } | 401 | } |
401 | 402 | ||
402 | void NNTPaccount::read() | 403 | void NNTPaccount::read() |
403 | { | 404 | { |
404 | Config *conf = new Config( getFileName(), Config::File ); | 405 | Config *conf = new Config( getFileName(), Config::File ); |
405 | conf->setGroup( "NNTP Account" ); | 406 | conf->setGroup( "NNTP Account" ); |
406 | accountName = conf->readEntry( "Account" ); | 407 | accountName = conf->readEntry( "Account" ); |
407 | server = conf->readEntry( "Server" ); | 408 | server = conf->readEntry( "Server" ); |
408 | port = conf->readEntry( "Port" ); | 409 | port = conf->readEntry( "Port" ); |
409 | ssl = conf->readBoolEntry( "SSL" ); | 410 | ssl = conf->readBoolEntry( "SSL" ); |
410 | login = conf->readBoolEntry( "Login" ); | 411 | login = conf->readBoolEntry( "Login" ); |
411 | user = conf->readEntry( "User" ); | 412 | user = conf->readEntry( "User" ); |
412 | password = conf->readEntryCrypt( "Password" ); | 413 | password = conf->readEntryCrypt( "Password" ); |
413 | subscribedGroups = conf->readListEntry( "Subscribed", ',' ); | 414 | subscribedGroups = conf->readListEntry( "Subscribed", ',' ); |
414 | delete conf; | 415 | delete conf; |
415 | } | 416 | } |
416 | 417 | ||
417 | void NNTPaccount::save() | 418 | void NNTPaccount::save() |
418 | { | 419 | { |
419 | odebug << "saving " + getFileName() << oendl; | 420 | odebug << "saving " + getFileName() << oendl; |
420 | Settings::checkDirectory(); | 421 | Settings::checkDirectory(); |
421 | 422 | ||
422 | Config *conf = new Config( getFileName(), Config::File ); | 423 | Config *conf = new Config( getFileName(), Config::File ); |
423 | conf->setGroup( "NNTP Account" ); | 424 | conf->setGroup( "NNTP Account" ); |
424 | conf->writeEntry( "Account", accountName ); | 425 | conf->writeEntry( "Account", accountName ); |
425 | conf->writeEntry( "Server", server ); | 426 | conf->writeEntry( "Server", server ); |
426 | conf->writeEntry( "Port", port ); | 427 | conf->writeEntry( "Port", port ); |
427 | conf->writeEntry( "SSL", ssl ); | 428 | conf->writeEntry( "SSL", ssl ); |
428 | conf->writeEntry( "Login", login ); | 429 | conf->writeEntry( "Login", login ); |
429 | conf->writeEntry( "User", user ); | 430 | conf->writeEntry( "User", user ); |
430 | conf->writeEntryCrypt( "Password", password ); | 431 | conf->writeEntryCrypt( "Password", password ); |
431 | conf->writeEntry( "Subscribed" , subscribedGroups, ',' ); | 432 | conf->writeEntry( "Subscribed" , subscribedGroups, ',' ); |
432 | conf->write(); | 433 | conf->write(); |
433 | delete conf; | 434 | delete conf; |
434 | } | 435 | } |
435 | 436 | ||
436 | 437 | ||
437 | QString NNTPaccount::getFileName() | 438 | QString NNTPaccount::getFileName() |
438 | { | 439 | { |
439 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/nntp-" + file; | 440 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/nntp-" + file; |
440 | } | 441 | } |
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index ba78c3b..db7a8ee 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp | |||
@@ -1,455 +1,456 @@ | |||
1 | #include "smtpwrapper.h" | 1 | #include "smtpwrapper.h" |
2 | #include "mailwrapper.h" | 2 | #include "mailwrapper.h" |
3 | #include "abstractmail.h" | 3 | #include "abstractmail.h" |
4 | #include "logindialog.h" | 4 | #include "logindialog.h" |
5 | #include "mailtypes.h" | 5 | #include "mailtypes.h" |
6 | #include "sendmailprogress.h" | 6 | #include "sendmailprogress.h" |
7 | 7 | ||
8 | #include <opie2/odebug.h> | ||
8 | #include <qt.h> | 9 | #include <qt.h> |
9 | 10 | ||
10 | #include <qpe/config.h> | 11 | #include <qpe/config.h> |
11 | #include <qpe/qcopenvelope_qws.h> | 12 | #include <qpe/qcopenvelope_qws.h> |
12 | 13 | ||
13 | #include <libetpan/libetpan.h> | 14 | #include <libetpan/libetpan.h> |
14 | 15 | ||
15 | 16 | ||
16 | using namespace Opie::Core; | 17 | using namespace Opie::Core; |
17 | progressMailSend*SMTPwrapper::sendProgress = 0; | 18 | progressMailSend*SMTPwrapper::sendProgress = 0; |
18 | 19 | ||
19 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) | 20 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) |
20 | : Generatemail() | 21 | : Generatemail() |
21 | { | 22 | { |
22 | m_SmtpAccount = aSmtp; | 23 | m_SmtpAccount = aSmtp; |
23 | Config cfg( "mail" ); | 24 | Config cfg( "mail" ); |
24 | cfg.setGroup( "Status" ); | 25 | cfg.setGroup( "Status" ); |
25 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); | 26 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); |
26 | emit queuedMails( m_queuedMail ); | 27 | emit queuedMails( m_queuedMail ); |
27 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); | 28 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); |
28 | m_smtp = 0; | 29 | m_smtp = 0; |
29 | } | 30 | } |
30 | 31 | ||
31 | SMTPwrapper::~SMTPwrapper() | 32 | SMTPwrapper::~SMTPwrapper() |
32 | { | 33 | { |
33 | disc_server(); | 34 | disc_server(); |
34 | } | 35 | } |
35 | 36 | ||
36 | void SMTPwrapper::emitQCop( int queued ) { | 37 | void SMTPwrapper::emitQCop( int queued ) { |
37 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); | 38 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); |
38 | env << queued; | 39 | env << queued; |
39 | } | 40 | } |
40 | 41 | ||
41 | QString SMTPwrapper::mailsmtpError( int errnum ) { | 42 | QString SMTPwrapper::mailsmtpError( int errnum ) { |
42 | switch ( errnum ) { | 43 | switch ( errnum ) { |
43 | case MAILSMTP_NO_ERROR: | 44 | case MAILSMTP_NO_ERROR: |
44 | return tr( "No error" ); | 45 | return tr( "No error" ); |
45 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 46 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
46 | return tr( "Unexpected error code" ); | 47 | return tr( "Unexpected error code" ); |
47 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 48 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
48 | return tr( "Service not available" ); | 49 | return tr( "Service not available" ); |
49 | case MAILSMTP_ERROR_STREAM: | 50 | case MAILSMTP_ERROR_STREAM: |
50 | return tr( "Stream error" ); | 51 | return tr( "Stream error" ); |
51 | case MAILSMTP_ERROR_HOSTNAME: | 52 | case MAILSMTP_ERROR_HOSTNAME: |
52 | return tr( "gethostname() failed" ); | 53 | return tr( "gethostname() failed" ); |
53 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 54 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
54 | return tr( "Not implemented" ); | 55 | return tr( "Not implemented" ); |
55 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 56 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
56 | return tr( "Error, action not taken" ); | 57 | return tr( "Error, action not taken" ); |
57 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 58 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
58 | return tr( "Data exceeds storage allocation" ); | 59 | return tr( "Data exceeds storage allocation" ); |
59 | case MAILSMTP_ERROR_IN_PROCESSING: | 60 | case MAILSMTP_ERROR_IN_PROCESSING: |
60 | return tr( "Error in processing" ); | 61 | return tr( "Error in processing" ); |
61 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: | 62 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: |
62 | return tr( "Starttls not supported" ); | 63 | return tr( "Starttls not supported" ); |
63 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 64 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
64 | // return tr( "Insufficient system storage" ); | 65 | // return tr( "Insufficient system storage" ); |
65 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 66 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
66 | return tr( "Mailbox unavailable" ); | 67 | return tr( "Mailbox unavailable" ); |
67 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 68 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
68 | return tr( "Mailbox name not allowed" ); | 69 | return tr( "Mailbox name not allowed" ); |
69 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 70 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
70 | return tr( "Bad command sequence" ); | 71 | return tr( "Bad command sequence" ); |
71 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 72 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
72 | return tr( "User not local" ); | 73 | return tr( "User not local" ); |
73 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 74 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
74 | return tr( "Transaction failed" ); | 75 | return tr( "Transaction failed" ); |
75 | case MAILSMTP_ERROR_MEMORY: | 76 | case MAILSMTP_ERROR_MEMORY: |
76 | return tr( "Memory error" ); | 77 | return tr( "Memory error" ); |
77 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 78 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
78 | return tr( "Connection refused" ); | 79 | return tr( "Connection refused" ); |
79 | default: | 80 | default: |
80 | return tr( "Unknown error code" ); | 81 | return tr( "Unknown error code" ); |
81 | } | 82 | } |
82 | } | 83 | } |
83 | 84 | ||
84 | 85 | ||
85 | void SMTPwrapper::progress( size_t current, size_t maximum ) { | 86 | void SMTPwrapper::progress( size_t current, size_t maximum ) { |
86 | if (SMTPwrapper::sendProgress) { | 87 | if (SMTPwrapper::sendProgress) { |
87 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | 88 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); |
88 | qApp->processEvents(); | 89 | qApp->processEvents(); |
89 | } | 90 | } |
90 | } | 91 | } |
91 | 92 | ||
92 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { | 93 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { |
93 | if (!mail) | 94 | if (!mail) |
94 | return; | 95 | return; |
95 | QString localfolders = AbstractMail::defaultLocalfolder(); | 96 | QString localfolders = AbstractMail::defaultLocalfolder(); |
96 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 97 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
97 | wrap->createMbox(box); | 98 | wrap->createMbox(box); |
98 | wrap->storeMessage(mail,length,box); | 99 | wrap->storeMessage(mail,length,box); |
99 | delete wrap; | 100 | delete wrap; |
100 | } | 101 | } |
101 | 102 | ||
102 | void SMTPwrapper::smtpSend( mailmime *mail,bool later) { | 103 | void SMTPwrapper::smtpSend( mailmime *mail,bool later) { |
103 | clist *rcpts = 0; | 104 | clist *rcpts = 0; |
104 | char *from, *data; | 105 | char *from, *data; |
105 | size_t size; | 106 | size_t size; |
106 | 107 | ||
107 | from = data = 0; | 108 | from = data = 0; |
108 | 109 | ||
109 | mailmessage * msg = 0; | 110 | mailmessage * msg = 0; |
110 | msg = mime_message_init(mail); | 111 | msg = mime_message_init(mail); |
111 | mime_message_set_tmpdir(msg,getenv( "HOME" )); | 112 | mime_message_set_tmpdir(msg,getenv( "HOME" )); |
112 | int r = mailmessage_fetch(msg,&data,&size); | 113 | int r = mailmessage_fetch(msg,&data,&size); |
113 | mime_message_detach_mime(msg); | 114 | mime_message_detach_mime(msg); |
114 | mailmessage_free(msg); | 115 | mailmessage_free(msg); |
115 | if (r != MAIL_NO_ERROR || !data) { | 116 | if (r != MAIL_NO_ERROR || !data) { |
116 | if (data) | 117 | if (data) |
117 | free(data); | 118 | free(data); |
118 | odebug << "Error fetching mime..." << oendl; | 119 | odebug << "Error fetching mime..." << oendl; |
119 | return; | 120 | return; |
120 | } | 121 | } |
121 | msg = 0; | 122 | msg = 0; |
122 | if (later) { | 123 | if (later) { |
123 | storeMail(data,size,"Outgoing"); | 124 | storeMail(data,size,"Outgoing"); |
124 | if (data) | 125 | if (data) |
125 | free( data ); | 126 | free( data ); |
126 | Config cfg( "mail" ); | 127 | Config cfg( "mail" ); |
127 | cfg.setGroup( "Status" ); | 128 | cfg.setGroup( "Status" ); |
128 | cfg.writeEntry( "outgoing", ++m_queuedMail ); | 129 | cfg.writeEntry( "outgoing", ++m_queuedMail ); |
129 | emit queuedMails( m_queuedMail ); | 130 | emit queuedMails( m_queuedMail ); |
130 | return; | 131 | return; |
131 | } | 132 | } |
132 | from = getFrom( mail ); | 133 | from = getFrom( mail ); |
133 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 134 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
134 | smtpSend(from,rcpts,data,size); | 135 | smtpSend(from,rcpts,data,size); |
135 | if (data) { | 136 | if (data) { |
136 | free(data); | 137 | free(data); |
137 | } | 138 | } |
138 | if (from) { | 139 | if (from) { |
139 | free(from); | 140 | free(from); |
140 | } | 141 | } |
141 | if (rcpts) | 142 | if (rcpts) |
142 | smtp_address_list_free( rcpts ); | 143 | smtp_address_list_free( rcpts ); |
143 | } | 144 | } |
144 | 145 | ||
145 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) | 146 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) |
146 | { | 147 | { |
147 | if (data) { | 148 | if (data) { |
148 | storeMail(data,size,"Sendfailed"); | 149 | storeMail(data,size,"Sendfailed"); |
149 | } | 150 | } |
150 | if (failuremessage) { | 151 | if (failuremessage) { |
151 | QMessageBox::critical(0,tr("Error sending mail"), | 152 | QMessageBox::critical(0,tr("Error sending mail"), |
152 | tr("<center>%1</center>").arg(failuremessage)); | 153 | tr("<center>%1</center>").arg(failuremessage)); |
153 | } | 154 | } |
154 | } | 155 | } |
155 | 156 | ||
156 | int SMTPwrapper::start_smtp_tls() | 157 | int SMTPwrapper::start_smtp_tls() |
157 | { | 158 | { |
158 | if (!m_smtp) { | 159 | if (!m_smtp) { |
159 | return MAILSMTP_ERROR_IN_PROCESSING; | 160 | return MAILSMTP_ERROR_IN_PROCESSING; |
160 | } | 161 | } |
161 | int err = mailesmtp_starttls(m_smtp); | 162 | int err = mailesmtp_starttls(m_smtp); |
162 | if (err != MAILSMTP_NO_ERROR) return err; | 163 | if (err != MAILSMTP_NO_ERROR) return err; |
163 | mailstream_low * low; | 164 | mailstream_low * low; |
164 | mailstream_low * new_low; | 165 | mailstream_low * new_low; |
165 | low = mailstream_get_low(m_smtp->stream); | 166 | low = mailstream_get_low(m_smtp->stream); |
166 | if (!low) { | 167 | if (!low) { |
167 | return MAILSMTP_ERROR_IN_PROCESSING; | 168 | return MAILSMTP_ERROR_IN_PROCESSING; |
168 | } | 169 | } |
169 | int fd = mailstream_low_get_fd(low); | 170 | int fd = mailstream_low_get_fd(low); |
170 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 171 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
171 | mailstream_low_free(low); | 172 | mailstream_low_free(low); |
172 | mailstream_set_low(m_smtp->stream, new_low); | 173 | mailstream_set_low(m_smtp->stream, new_low); |
173 | } else { | 174 | } else { |
174 | return MAILSMTP_ERROR_IN_PROCESSING; | 175 | return MAILSMTP_ERROR_IN_PROCESSING; |
175 | } | 176 | } |
176 | return err; | 177 | return err; |
177 | } | 178 | } |
178 | 179 | ||
179 | void SMTPwrapper::connect_server() | 180 | void SMTPwrapper::connect_server() |
180 | { | 181 | { |
181 | const char *server, *user, *pass; | 182 | const char *server, *user, *pass; |
182 | bool ssl; | 183 | bool ssl; |
183 | uint16_t port; | 184 | uint16_t port; |
184 | ssl = false; | 185 | ssl = false; |
185 | bool try_tls = true; | 186 | bool try_tls = true; |
186 | bool force_tls=false; | 187 | bool force_tls=false; |
187 | server = user = pass = 0; | 188 | server = user = pass = 0; |
188 | QString failuretext = ""; | 189 | QString failuretext = ""; |
189 | 190 | ||
190 | if (m_smtp || !m_SmtpAccount) { | 191 | if (m_smtp || !m_SmtpAccount) { |
191 | return; | 192 | return; |
192 | } | 193 | } |
193 | server = m_SmtpAccount->getServer().latin1(); | 194 | server = m_SmtpAccount->getServer().latin1(); |
194 | if ( m_SmtpAccount->ConnectionType() == 2 ) { | 195 | if ( m_SmtpAccount->ConnectionType() == 2 ) { |
195 | ssl = true; | 196 | ssl = true; |
196 | try_tls = false; | 197 | try_tls = false; |
197 | } else if (m_SmtpAccount->ConnectionType() == 1) { | 198 | } else if (m_SmtpAccount->ConnectionType() == 1) { |
198 | force_tls = true; | 199 | force_tls = true; |
199 | } | 200 | } |
200 | int result = 1; | 201 | int result = 1; |
201 | port = m_SmtpAccount->getPort().toUInt(); | 202 | port = m_SmtpAccount->getPort().toUInt(); |
202 | 203 | ||
203 | m_smtp = mailsmtp_new( 20, &progress ); | 204 | m_smtp = mailsmtp_new( 20, &progress ); |
204 | if ( m_smtp == NULL ) { | 205 | if ( m_smtp == NULL ) { |
205 | /* no failure message cause this happens when problems with memory - than we | 206 | /* no failure message cause this happens when problems with memory - than we |
206 | we can not display any messagebox */ | 207 | we can not display any messagebox */ |
207 | return; | 208 | return; |
208 | } | 209 | } |
209 | 210 | ||
210 | int err = MAILSMTP_NO_ERROR; | 211 | int err = MAILSMTP_NO_ERROR; |
211 | odebug << "Servername " << server << " at port " << port << "" << oendl; | 212 | odebug << "Servername " << server << " at port " << port << "" << oendl; |
212 | if ( ssl ) { | 213 | if ( ssl ) { |
213 | odebug << "SSL session" << oendl; | 214 | odebug << "SSL session" << oendl; |
214 | err = mailsmtp_ssl_connect( m_smtp, server, port ); | 215 | err = mailsmtp_ssl_connect( m_smtp, server, port ); |
215 | } else { | 216 | } else { |
216 | odebug << "No SSL session" << oendl; | 217 | odebug << "No SSL session" << oendl; |
217 | err = mailsmtp_socket_connect( m_smtp, server, port ); | 218 | err = mailsmtp_socket_connect( m_smtp, server, port ); |
218 | } | 219 | } |
219 | if ( err != MAILSMTP_NO_ERROR ) { | 220 | if ( err != MAILSMTP_NO_ERROR ) { |
220 | odebug << "Error init connection" << oendl; | 221 | odebug << "Error init connection" << oendl; |
221 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); | 222 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); |
222 | result = 0; | 223 | result = 0; |
223 | } | 224 | } |
224 | 225 | ||
225 | /* switch to tls after init 'cause there it will send the ehlo */ | 226 | /* switch to tls after init 'cause there it will send the ehlo */ |
226 | if (result) { | 227 | if (result) { |
227 | err = mailsmtp_init( m_smtp ); | 228 | err = mailsmtp_init( m_smtp ); |
228 | if (err != MAILSMTP_NO_ERROR) { | 229 | if (err != MAILSMTP_NO_ERROR) { |
229 | result = 0; | 230 | result = 0; |
230 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); | 231 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); |
231 | } | 232 | } |
232 | } | 233 | } |
233 | 234 | ||
234 | if (try_tls) { | 235 | if (try_tls) { |
235 | err = start_smtp_tls(); | 236 | err = start_smtp_tls(); |
236 | if (err != MAILSMTP_NO_ERROR) { | 237 | if (err != MAILSMTP_NO_ERROR) { |
237 | try_tls = false; | 238 | try_tls = false; |
238 | } else { | 239 | } else { |
239 | err = mailesmtp_ehlo(m_smtp); | 240 | err = mailesmtp_ehlo(m_smtp); |
240 | } | 241 | } |
241 | } | 242 | } |
242 | 243 | ||
243 | if (!try_tls && force_tls) { | 244 | if (!try_tls && force_tls) { |
244 | result = 0; | 245 | result = 0; |
245 | failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); | 246 | failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); |
246 | } | 247 | } |
247 | 248 | ||
248 | if (result==1 && m_SmtpAccount->getLogin() ) { | 249 | if (result==1 && m_SmtpAccount->getLogin() ) { |
249 | odebug << "smtp with auth" << oendl; | 250 | odebug << "smtp with auth" << oendl; |
250 | if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { | 251 | if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { |
251 | // get'em | 252 | // get'em |
252 | LoginDialog login( m_SmtpAccount->getUser(), | 253 | LoginDialog login( m_SmtpAccount->getUser(), |
253 | m_SmtpAccount->getPassword(), NULL, 0, true ); | 254 | m_SmtpAccount->getPassword(), NULL, 0, true ); |
254 | login.show(); | 255 | login.show(); |
255 | if ( QDialog::Accepted == login.exec() ) { | 256 | if ( QDialog::Accepted == login.exec() ) { |
256 | // ok | 257 | // ok |
257 | user = login.getUser().latin1(); | 258 | user = login.getUser().latin1(); |
258 | pass = login.getPassword().latin1(); | 259 | pass = login.getPassword().latin1(); |
259 | } else { | 260 | } else { |
260 | result = 0; | 261 | result = 0; |
261 | failuretext=tr("Login aborted - storing mail to localfolder"); | 262 | failuretext=tr("Login aborted - storing mail to localfolder"); |
262 | } | 263 | } |
263 | } else { | 264 | } else { |
264 | user = m_SmtpAccount->getUser().latin1(); | 265 | user = m_SmtpAccount->getUser().latin1(); |
265 | pass = m_SmtpAccount->getPassword().latin1(); | 266 | pass = m_SmtpAccount->getPassword().latin1(); |
266 | } | 267 | } |
267 | odebug << "session->auth: " << m_smtp->auth << "" << oendl; | 268 | odebug << "session->auth: " << m_smtp->auth << "" << oendl; |
268 | if (result) { | 269 | if (result) { |
269 | err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass ); | 270 | err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass ); |
270 | if ( err == MAILSMTP_NO_ERROR ) { | 271 | if ( err == MAILSMTP_NO_ERROR ) { |
271 | odebug << "auth ok" << oendl; | 272 | odebug << "auth ok" << oendl; |
272 | } else { | 273 | } else { |
273 | failuretext = tr("Authentification failed"); | 274 | failuretext = tr("Authentification failed"); |
274 | result = 0; | 275 | result = 0; |
275 | } | 276 | } |
276 | } | 277 | } |
277 | } | 278 | } |
278 | } | 279 | } |
279 | 280 | ||
280 | void SMTPwrapper::disc_server() | 281 | void SMTPwrapper::disc_server() |
281 | { | 282 | { |
282 | if (m_smtp) { | 283 | if (m_smtp) { |
283 | mailsmtp_quit( m_smtp ); | 284 | mailsmtp_quit( m_smtp ); |
284 | mailsmtp_free( m_smtp ); | 285 | mailsmtp_free( m_smtp ); |
285 | m_smtp = 0; | 286 | m_smtp = 0; |
286 | } | 287 | } |
287 | } | 288 | } |
288 | 289 | ||
289 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) | 290 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) |
290 | { | 291 | { |
291 | int err,result; | 292 | int err,result; |
292 | QString failuretext = ""; | 293 | QString failuretext = ""; |
293 | 294 | ||
294 | connect_server(); | 295 | connect_server(); |
295 | 296 | ||
296 | result = 1; | 297 | result = 1; |
297 | if (m_smtp) { | 298 | if (m_smtp) { |
298 | err = mailsmtp_send( m_smtp, from, rcpts, data, size ); | 299 | err = mailsmtp_send( m_smtp, from, rcpts, data, size ); |
299 | if ( err != MAILSMTP_NO_ERROR ) { | 300 | if ( err != MAILSMTP_NO_ERROR ) { |
300 | failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); | 301 | failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); |
301 | result = 0; | 302 | result = 0; |
302 | } | 303 | } |
303 | } else { | 304 | } else { |
304 | result = 0; | 305 | result = 0; |
305 | } | 306 | } |
306 | 307 | ||
307 | if (!result) { | 308 | if (!result) { |
308 | storeFailedMail(data,size,failuretext); | 309 | storeFailedMail(data,size,failuretext); |
309 | } else { | 310 | } else { |
310 | odebug << "Mail sent." << oendl; | 311 | odebug << "Mail sent." << oendl; |
311 | storeMail(data,size,"Sent"); | 312 | storeMail(data,size,"Sent"); |
312 | } | 313 | } |
313 | return result; | 314 | return result; |
314 | } | 315 | } |
315 | 316 | ||
316 | void SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) | 317 | void SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) |
317 | { | 318 | { |
318 | mailmime * mimeMail; | 319 | mailmime * mimeMail; |
319 | 320 | ||
320 | mimeMail = createMimeMail(mail ); | 321 | mimeMail = createMimeMail(mail ); |
321 | if ( mimeMail == NULL ) { | 322 | if ( mimeMail == NULL ) { |
322 | odebug << "sendMail: error creating mime mail" << oendl; | 323 | odebug << "sendMail: error creating mime mail" << oendl; |
323 | } else { | 324 | } else { |
324 | sendProgress = new progressMailSend(); | 325 | sendProgress = new progressMailSend(); |
325 | sendProgress->show(); | 326 | sendProgress->show(); |
326 | sendProgress->setMaxMails(1); | 327 | sendProgress->setMaxMails(1); |
327 | smtpSend( mimeMail,later); | 328 | smtpSend( mimeMail,later); |
328 | odebug << "Clean up done" << oendl; | 329 | odebug << "Clean up done" << oendl; |
329 | sendProgress->hide(); | 330 | sendProgress->hide(); |
330 | delete sendProgress; | 331 | delete sendProgress; |
331 | sendProgress = 0; | 332 | sendProgress = 0; |
332 | mailmime_free( mimeMail ); | 333 | mailmime_free( mimeMail ); |
333 | } | 334 | } |
334 | } | 335 | } |
335 | 336 | ||
336 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { | 337 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { |
337 | size_t curTok = 0; | 338 | size_t curTok = 0; |
338 | mailimf_fields *fields = 0; | 339 | mailimf_fields *fields = 0; |
339 | mailimf_field*ffrom = 0; | 340 | mailimf_field*ffrom = 0; |
340 | clist *rcpts = 0; | 341 | clist *rcpts = 0; |
341 | char*from = 0; | 342 | char*from = 0; |
342 | int res = 0; | 343 | int res = 0; |
343 | 344 | ||
344 | encodedString * data = wrap->fetchRawBody(which); | 345 | encodedString * data = wrap->fetchRawBody(which); |
345 | if (!data) | 346 | if (!data) |
346 | return 0; | 347 | return 0; |
347 | int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); | 348 | int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); |
348 | if (err != MAILIMF_NO_ERROR) { | 349 | if (err != MAILIMF_NO_ERROR) { |
349 | delete data; | 350 | delete data; |
350 | delete wrap; | 351 | delete wrap; |
351 | return 0; | 352 | return 0; |
352 | } | 353 | } |
353 | 354 | ||
354 | rcpts = createRcptList( fields ); | 355 | rcpts = createRcptList( fields ); |
355 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); | 356 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); |
356 | from = getFrom(ffrom); | 357 | from = getFrom(ffrom); |
357 | 358 | ||
358 | if (rcpts && from) { | 359 | if (rcpts && from) { |
359 | res = smtpSend(from,rcpts,data->Content(),data->Length()); | 360 | res = smtpSend(from,rcpts,data->Content(),data->Length()); |
360 | } | 361 | } |
361 | if (fields) { | 362 | if (fields) { |
362 | mailimf_fields_free(fields); | 363 | mailimf_fields_free(fields); |
363 | fields = 0; | 364 | fields = 0; |
364 | } | 365 | } |
365 | if (data) { | 366 | if (data) { |
366 | delete data; | 367 | delete data; |
367 | } | 368 | } |
368 | if (from) { | 369 | if (from) { |
369 | free(from); | 370 | free(from); |
370 | } | 371 | } |
371 | if (rcpts) { | 372 | if (rcpts) { |
372 | smtp_address_list_free( rcpts ); | 373 | smtp_address_list_free( rcpts ); |
373 | } | 374 | } |
374 | return res; | 375 | return res; |
375 | } | 376 | } |
376 | 377 | ||
377 | /* this is a special fun */ | 378 | /* this is a special fun */ |
378 | bool SMTPwrapper::flushOutbox() { | 379 | bool SMTPwrapper::flushOutbox() { |
379 | bool returnValue = true; | 380 | bool returnValue = true; |
380 | 381 | ||
381 | odebug << "Sending the queue" << oendl; | 382 | odebug << "Sending the queue" << oendl; |
382 | if (!m_SmtpAccount) { | 383 | if (!m_SmtpAccount) { |
383 | odebug << "No smtp account given" << oendl; | 384 | odebug << "No smtp account given" << oendl; |
384 | return false; | 385 | return false; |
385 | } | 386 | } |
386 | 387 | ||
387 | bool reset_user_value = false; | 388 | bool reset_user_value = false; |
388 | QString localfolders = AbstractMail::defaultLocalfolder(); | 389 | QString localfolders = AbstractMail::defaultLocalfolder(); |
389 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 390 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
390 | if (!wrap) { | 391 | if (!wrap) { |
391 | odebug << "memory error" << oendl; | 392 | odebug << "memory error" << oendl; |
392 | return false; | 393 | return false; |
393 | } | 394 | } |
394 | QString oldPw, oldUser; | 395 | QString oldPw, oldUser; |
395 | QValueList<RecMailP> mailsToSend; | 396 | QValueList<RecMailP> mailsToSend; |
396 | QValueList<RecMailP> mailsToRemove; | 397 | QValueList<RecMailP> mailsToRemove; |
397 | QString mbox("Outgoing"); | 398 | QString mbox("Outgoing"); |
398 | wrap->listMessages(mbox,mailsToSend); | 399 | wrap->listMessages(mbox,mailsToSend); |
399 | if (mailsToSend.count()==0) { | 400 | if (mailsToSend.count()==0) { |
400 | delete wrap; | 401 | delete wrap; |
401 | odebug << "No mails to send" << oendl; | 402 | odebug << "No mails to send" << oendl; |
402 | return false; | 403 | return false; |
403 | } | 404 | } |
404 | 405 | ||
405 | oldPw = m_SmtpAccount->getPassword(); | 406 | oldPw = m_SmtpAccount->getPassword(); |
406 | oldUser = m_SmtpAccount->getUser(); | 407 | oldUser = m_SmtpAccount->getUser(); |
407 | if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { | 408 | if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { |
408 | // get'em | 409 | // get'em |
409 | QString user,pass; | 410 | QString user,pass; |
410 | LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); | 411 | LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); |
411 | login.show(); | 412 | login.show(); |
412 | if ( QDialog::Accepted == login.exec() ) { | 413 | if ( QDialog::Accepted == login.exec() ) { |
413 | // ok | 414 | // ok |
414 | user = login.getUser().latin1(); | 415 | user = login.getUser().latin1(); |
415 | pass = login.getPassword().latin1(); | 416 | pass = login.getPassword().latin1(); |
416 | reset_user_value = true; | 417 | reset_user_value = true; |
417 | m_SmtpAccount->setUser(user); | 418 | m_SmtpAccount->setUser(user); |
418 | m_SmtpAccount->setPassword(pass); | 419 | m_SmtpAccount->setPassword(pass); |
419 | } else { | 420 | } else { |
420 | return true; | 421 | return true; |
421 | } | 422 | } |
422 | } | 423 | } |
423 | 424 | ||
424 | 425 | ||
425 | sendProgress = new progressMailSend(); | 426 | sendProgress = new progressMailSend(); |
426 | sendProgress->show(); | 427 | sendProgress->show(); |
427 | sendProgress->setMaxMails(mailsToSend.count()); | 428 | sendProgress->setMaxMails(mailsToSend.count()); |
428 | 429 | ||
429 | while (mailsToSend.count()>0) { | 430 | while (mailsToSend.count()>0) { |
430 | if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) { | 431 | if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) { |
431 | QMessageBox::critical(0,tr("Error sending mail"), | 432 | QMessageBox::critical(0,tr("Error sending mail"), |
432 | tr("Error sending queued mail - breaking")); | 433 | tr("Error sending queued mail - breaking")); |
433 | returnValue = false; | 434 | returnValue = false; |
434 | break; | 435 | break; |
435 | } | 436 | } |
436 | mailsToRemove.append((*mailsToSend.begin())); | 437 | mailsToRemove.append((*mailsToSend.begin())); |
437 | mailsToSend.remove(mailsToSend.begin()); | 438 | mailsToSend.remove(mailsToSend.begin()); |
438 | sendProgress->setCurrentMails(mailsToRemove.count()); | 439 | sendProgress->setCurrentMails(mailsToRemove.count()); |
439 | } | 440 | } |
440 | if (reset_user_value) { | 441 | if (reset_user_value) { |
441 | m_SmtpAccount->setUser(oldUser); | 442 | m_SmtpAccount->setUser(oldUser); |
442 | m_SmtpAccount->setPassword(oldPw); | 443 | m_SmtpAccount->setPassword(oldPw); |
443 | } | 444 | } |
444 | Config cfg( "mail" ); | 445 | Config cfg( "mail" ); |
445 | cfg.setGroup( "Status" ); | 446 | cfg.setGroup( "Status" ); |
446 | m_queuedMail = 0; | 447 | m_queuedMail = 0; |
447 | cfg.writeEntry( "outgoing", m_queuedMail ); | 448 | cfg.writeEntry( "outgoing", m_queuedMail ); |
448 | emit queuedMails( m_queuedMail ); | 449 | emit queuedMails( m_queuedMail ); |
449 | sendProgress->hide(); | 450 | sendProgress->hide(); |
450 | delete sendProgress; | 451 | delete sendProgress; |
451 | sendProgress = 0; | 452 | sendProgress = 0; |
452 | wrap->deleteMails(mbox,mailsToRemove); | 453 | wrap->deleteMails(mbox,mailsToRemove); |
453 | delete wrap; | 454 | delete wrap; |
454 | return returnValue; | 455 | return returnValue; |
455 | } | 456 | } |
diff --git a/noncore/net/mail/libmailwrapper/statusmail.cpp b/noncore/net/mail/libmailwrapper/statusmail.cpp index 51383f6..7e14df3 100644 --- a/noncore/net/mail/libmailwrapper/statusmail.cpp +++ b/noncore/net/mail/libmailwrapper/statusmail.cpp | |||
@@ -1,90 +1,94 @@ | |||
1 | #include "statusmail.h" | 1 | #include "statusmail.h" |
2 | 2 | ||
3 | #include <opie2/odebug.h> | ||
4 | |||
5 | using namespace Opie::Core; | ||
6 | |||
3 | StatusMail::StatusMail(QList<Account>&list) | 7 | StatusMail::StatusMail(QList<Account>&list) |
4 | { | 8 | { |
5 | currentImapStat.message_count=0; | 9 | currentImapStat.message_count=0; |
6 | currentImapStat.message_unseen=0; | 10 | currentImapStat.message_unseen=0; |
7 | currentImapStat.message_recent=0; | 11 | currentImapStat.message_recent=0; |
8 | lastPop3Stat = currentImapStat; | 12 | lastPop3Stat = currentImapStat; |
9 | currentPop3Stat = currentImapStat; | 13 | currentPop3Stat = currentImapStat; |
10 | connectionList.setAutoDelete(true); | 14 | connectionList.setAutoDelete(true); |
11 | connectionList.clear(); | 15 | connectionList.clear(); |
12 | initAccounts(list); | 16 | initAccounts(list); |
13 | } | 17 | } |
14 | 18 | ||
15 | StatusMail::~StatusMail() | 19 | StatusMail::~StatusMail() |
16 | { | 20 | { |
17 | } | 21 | } |
18 | 22 | ||
19 | void StatusMail::initAccounts(QList<Account>&accounts) | 23 | void StatusMail::initAccounts(QList<Account>&accounts) |
20 | { | 24 | { |
21 | 25 | ||
22 | Account *it; | 26 | Account *it; |
23 | folderStat currentStat; | 27 | folderStat currentStat; |
24 | AbstractMail * current = 0; | 28 | AbstractMail * current = 0; |
25 | currentPop3Stat.message_count=0; | 29 | currentPop3Stat.message_count=0; |
26 | currentPop3Stat.message_recent=0; | 30 | currentPop3Stat.message_recent=0; |
27 | currentPop3Stat.message_unseen=0; | 31 | currentPop3Stat.message_unseen=0; |
28 | for ( it = accounts.first(); it; it = accounts.next() ) { | 32 | for ( it = accounts.first(); it; it = accounts.next() ) { |
29 | if ( it->getType()==MAILLIB::A_IMAP && !it->getOffline() ) { | 33 | if ( it->getType()==MAILLIB::A_IMAP && !it->getOffline() ) { |
30 | IMAPaccount*ima = static_cast<IMAPaccount *>(it); | 34 | IMAPaccount*ima = static_cast<IMAPaccount *>(it); |
31 | current = AbstractMail::getWrapper(ima); | 35 | current = AbstractMail::getWrapper(ima); |
32 | connectionList.append(current); | 36 | connectionList.append(current); |
33 | current->statusFolder(currentStat); | 37 | current->statusFolder(currentStat); |
34 | currentImapStat.message_count+=currentStat.message_unseen; | 38 | currentImapStat.message_count+=currentStat.message_unseen; |
35 | currentImapStat.message_count+=currentStat.message_recent; | 39 | currentImapStat.message_count+=currentStat.message_recent; |
36 | currentImapStat.message_count+=currentStat.message_count; | 40 | currentImapStat.message_count+=currentStat.message_count; |
37 | } else if ( it->getType() == MAILLIB::A_POP3 && !it->getOffline() ) { | 41 | } else if ( it->getType() == MAILLIB::A_POP3 && !it->getOffline() ) { |
38 | POP3account *pop3 = static_cast<POP3account *>(it); | 42 | POP3account *pop3 = static_cast<POP3account *>(it); |
39 | current = AbstractMail::getWrapper(pop3); | 43 | current = AbstractMail::getWrapper(pop3); |
40 | connectionList.append(current); | 44 | connectionList.append(current); |
41 | current->statusFolder(currentStat); | 45 | current->statusFolder(currentStat); |
42 | currentPop3Stat.message_count+=currentStat.message_count; | 46 | currentPop3Stat.message_count+=currentStat.message_count; |
43 | } | 47 | } |
44 | current->logout(); | 48 | current->logout(); |
45 | } | 49 | } |
46 | odebug << "Pop3 init count: " << currentPop3Stat.message_count << "" << oendl; | 50 | odebug << "Pop3 init count: " << currentPop3Stat.message_count << "" << oendl; |
47 | currentPop3Stat.message_recent = currentPop3Stat.message_unseen = 0; | 51 | currentPop3Stat.message_recent = currentPop3Stat.message_unseen = 0; |
48 | lastPop3Stat.message_unseen = currentPop3Stat.message_unseen; | 52 | lastPop3Stat.message_unseen = currentPop3Stat.message_unseen; |
49 | lastPop3Stat.message_recent = currentPop3Stat.message_recent; | 53 | lastPop3Stat.message_recent = currentPop3Stat.message_recent; |
50 | lastPop3Stat.message_count = currentPop3Stat.message_count; | 54 | lastPop3Stat.message_count = currentPop3Stat.message_count; |
51 | } | 55 | } |
52 | 56 | ||
53 | void StatusMail::reset_status() | 57 | void StatusMail::reset_status() |
54 | { | 58 | { |
55 | lastPop3Stat = currentPop3Stat; | 59 | lastPop3Stat = currentPop3Stat; |
56 | } | 60 | } |
57 | 61 | ||
58 | void StatusMail::check_current_stat(folderStat&targetStat) | 62 | void StatusMail::check_current_stat(folderStat&targetStat) |
59 | { | 63 | { |
60 | AbstractMail*it = 0; | 64 | AbstractMail*it = 0; |
61 | folderStat currentStat; | 65 | folderStat currentStat; |
62 | currentPop3Stat.message_recent = 0; | 66 | currentPop3Stat.message_recent = 0; |
63 | currentPop3Stat.message_count = 0; | 67 | currentPop3Stat.message_count = 0; |
64 | currentPop3Stat.message_unseen = 0; | 68 | currentPop3Stat.message_unseen = 0; |
65 | currentImapStat = currentPop3Stat; | 69 | currentImapStat = currentPop3Stat; |
66 | for ( it = connectionList.first(); it; it = connectionList.next() ) { | 70 | for ( it = connectionList.first(); it; it = connectionList.next() ) { |
67 | it->statusFolder(currentStat); | 71 | it->statusFolder(currentStat); |
68 | it->logout(); | 72 | it->logout(); |
69 | if (it->getType() == MAILLIB::A_IMAP) { | 73 | if (it->getType() == MAILLIB::A_IMAP) { |
70 | currentImapStat.message_unseen+=currentStat.message_unseen; | 74 | currentImapStat.message_unseen+=currentStat.message_unseen; |
71 | currentImapStat.message_recent+=currentStat.message_recent; | 75 | currentImapStat.message_recent+=currentStat.message_recent; |
72 | currentImapStat.message_count+=currentStat.message_count; | 76 | currentImapStat.message_count+=currentStat.message_count; |
73 | } else if (it->getType() == MAILLIB::A_POP3) { | 77 | } else if (it->getType() == MAILLIB::A_POP3) { |
74 | currentPop3Stat.message_count+=currentStat.message_count; | 78 | currentPop3Stat.message_count+=currentStat.message_count; |
75 | odebug << "Pop3 count: " << currentPop3Stat.message_count << "" << oendl; | 79 | odebug << "Pop3 count: " << currentPop3Stat.message_count << "" << oendl; |
76 | } | 80 | } |
77 | } | 81 | } |
78 | odebug << "Pop3 last: " << lastPop3Stat.message_count << "" << oendl; | 82 | odebug << "Pop3 last: " << lastPop3Stat.message_count << "" << oendl; |
79 | if (currentPop3Stat.message_count > lastPop3Stat.message_count) { | 83 | if (currentPop3Stat.message_count > lastPop3Stat.message_count) { |
80 | currentPop3Stat.message_recent = currentPop3Stat.message_count - lastPop3Stat.message_count; | 84 | currentPop3Stat.message_recent = currentPop3Stat.message_count - lastPop3Stat.message_count; |
81 | currentPop3Stat.message_unseen = currentPop3Stat.message_recent; | 85 | currentPop3Stat.message_unseen = currentPop3Stat.message_recent; |
82 | } else { | 86 | } else { |
83 | lastPop3Stat.message_count = currentPop3Stat.message_count; | 87 | lastPop3Stat.message_count = currentPop3Stat.message_count; |
84 | currentPop3Stat.message_recent = currentPop3Stat.message_unseen = 0; | 88 | currentPop3Stat.message_recent = currentPop3Stat.message_unseen = 0; |
85 | } | 89 | } |
86 | targetStat = currentImapStat; | 90 | targetStat = currentImapStat; |
87 | targetStat.message_unseen+=currentPop3Stat.message_unseen; | 91 | targetStat.message_unseen+=currentPop3Stat.message_unseen; |
88 | targetStat.message_recent+=currentPop3Stat.message_recent; | 92 | targetStat.message_recent+=currentPop3Stat.message_recent; |
89 | targetStat.message_count+=currentPop3Stat.message_count; | 93 | targetStat.message_count+=currentPop3Stat.message_count; |
90 | } | 94 | } |
diff --git a/noncore/net/mail/libmailwrapper/storemail.cpp b/noncore/net/mail/libmailwrapper/storemail.cpp index 546d756..4add8a1 100644 --- a/noncore/net/mail/libmailwrapper/storemail.cpp +++ b/noncore/net/mail/libmailwrapper/storemail.cpp | |||
@@ -1,91 +1,91 @@ | |||
1 | #include "storemail.h" | 1 | #include "storemail.h" |
2 | #include "mailwrapper.h" | 2 | #include "mailwrapper.h" |
3 | #include "settings.h" | 3 | #include "settings.h" |
4 | #include "abstractmail.h" | 4 | #include "abstractmail.h" |
5 | 5 | ||
6 | #include <libetpan/libetpan.h> | 6 | #include <libetpan/libetpan.h> |
7 | 7 | #include <opie2/odebug.h> | |
8 | #include <qstring.h> | 8 | #include <qstring.h> |
9 | 9 | ||
10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
11 | 11 | ||
12 | using namespace Opie::Core; | 12 | using namespace Opie::Core; |
13 | Storemail::Storemail(Account*aAccount,const QString&aFolder) | 13 | Storemail::Storemail(Account*aAccount,const QString&aFolder) |
14 | : Generatemail() | 14 | : Generatemail() |
15 | { | 15 | { |
16 | wrapper = 0; | 16 | wrapper = 0; |
17 | m_Account = aAccount; | 17 | m_Account = aAccount; |
18 | m_tfolder = aFolder; | 18 | m_tfolder = aFolder; |
19 | wrapper = AbstractMail::getWrapper(m_Account); | 19 | wrapper = AbstractMail::getWrapper(m_Account); |
20 | if (wrapper) { | 20 | if (wrapper) { |
21 | wrapper->createMbox(m_tfolder); | 21 | wrapper->createMbox(m_tfolder); |
22 | } | 22 | } |
23 | } | 23 | } |
24 | 24 | ||
25 | Storemail::Storemail(const QString&dir,const QString&aFolder) | 25 | Storemail::Storemail(const QString&dir,const QString&aFolder) |
26 | : Generatemail() | 26 | : Generatemail() |
27 | { | 27 | { |
28 | wrapper = 0; | 28 | wrapper = 0; |
29 | m_Account = 0; | 29 | m_Account = 0; |
30 | m_tfolder = aFolder; | 30 | m_tfolder = aFolder; |
31 | wrapper = AbstractMail::getWrapper(dir); | 31 | wrapper = AbstractMail::getWrapper(dir); |
32 | if (wrapper) { | 32 | if (wrapper) { |
33 | wrapper->createMbox(m_tfolder); | 33 | wrapper->createMbox(m_tfolder); |
34 | } | 34 | } |
35 | } | 35 | } |
36 | 36 | ||
37 | Storemail::Storemail(const QString&aFolder) | 37 | Storemail::Storemail(const QString&aFolder) |
38 | : Generatemail() | 38 | : Generatemail() |
39 | { | 39 | { |
40 | wrapper = 0; | 40 | wrapper = 0; |
41 | m_Account = 0; | 41 | m_Account = 0; |
42 | m_tfolder = aFolder; | 42 | m_tfolder = aFolder; |
43 | wrapper = AbstractMail::getWrapper(AbstractMail::defaultLocalfolder()); | 43 | wrapper = AbstractMail::getWrapper(AbstractMail::defaultLocalfolder()); |
44 | if (wrapper) { | 44 | if (wrapper) { |
45 | wrapper->createMbox(m_tfolder); | 45 | wrapper->createMbox(m_tfolder); |
46 | } | 46 | } |
47 | } | 47 | } |
48 | 48 | ||
49 | Storemail::~Storemail() | 49 | Storemail::~Storemail() |
50 | { | 50 | { |
51 | } | 51 | } |
52 | 52 | ||
53 | int Storemail::storeMail(const Opie::Core::OSmartPointer<Mail>&mail) | 53 | int Storemail::storeMail(const Opie::Core::OSmartPointer<Mail>&mail) |
54 | { | 54 | { |
55 | if (!wrapper) return 0; | 55 | if (!wrapper) return 0; |
56 | int ret = 1; | 56 | int ret = 1; |
57 | 57 | ||
58 | mailmime * mimeMail = 0; | 58 | mailmime * mimeMail = 0; |
59 | mimeMail = createMimeMail(mail ); | 59 | mimeMail = createMimeMail(mail ); |
60 | if ( mimeMail == NULL ) { | 60 | if ( mimeMail == NULL ) { |
61 | odebug << "storeMail: error creating mime mail" << oendl; | 61 | odebug << "storeMail: error creating mime mail" << oendl; |
62 | return 0; | 62 | return 0; |
63 | } | 63 | } |
64 | char *data; | 64 | char *data; |
65 | size_t size; | 65 | size_t size; |
66 | data = 0; | 66 | data = 0; |
67 | 67 | ||
68 | mailmessage * msg = 0; | 68 | mailmessage * msg = 0; |
69 | msg = mime_message_init(mimeMail); | 69 | msg = mime_message_init(mimeMail); |
70 | mime_message_set_tmpdir(msg,getenv( "HOME" )); | 70 | mime_message_set_tmpdir(msg,getenv( "HOME" )); |
71 | int r = mailmessage_fetch(msg,&data,&size); | 71 | int r = mailmessage_fetch(msg,&data,&size); |
72 | mime_message_detach_mime(msg); | 72 | mime_message_detach_mime(msg); |
73 | mailmessage_free(msg); | 73 | mailmessage_free(msg); |
74 | msg = 0; | 74 | msg = 0; |
75 | if (r != MAIL_NO_ERROR || !data) { | 75 | if (r != MAIL_NO_ERROR || !data) { |
76 | odebug << "Error fetching mime..." << oendl; | 76 | odebug << "Error fetching mime..." << oendl; |
77 | ret = 0; | 77 | ret = 0; |
78 | } | 78 | } |
79 | 79 | ||
80 | if (ret) { | 80 | if (ret) { |
81 | wrapper->storeMessage(data,size,m_tfolder); | 81 | wrapper->storeMessage(data,size,m_tfolder); |
82 | } | 82 | } |
83 | 83 | ||
84 | if (data) { | 84 | if (data) { |
85 | free(data); | 85 | free(data); |
86 | } | 86 | } |
87 | if (mimeMail) { | 87 | if (mimeMail) { |
88 | mailmime_free( mimeMail ); | 88 | mailmime_free( mimeMail ); |
89 | } | 89 | } |
90 | return ret; | 90 | return ret; |
91 | } | 91 | } |
diff --git a/noncore/net/mail/mainwindow.cpp b/noncore/net/mail/mainwindow.cpp index 4c87d64..979b73a 100644 --- a/noncore/net/mail/mainwindow.cpp +++ b/noncore/net/mail/mainwindow.cpp | |||
@@ -1,216 +1,218 @@ | |||
1 | #include <qlabel.h> | 1 | #include <qlabel.h> |
2 | #include <qvbox.h> | 2 | #include <qvbox.h> |
3 | #include <qheader.h> | 3 | #include <qheader.h> |
4 | #include <qtimer.h> | 4 | #include <qtimer.h> |
5 | #include <qlayout.h> | 5 | #include <qlayout.h> |
6 | 6 | ||
7 | #include <opie2/odebug.h> | ||
7 | #include <qpe/qpeapplication.h> | 8 | #include <qpe/qpeapplication.h> |
8 | 9 | ||
9 | #include "defines.h" | 10 | #include "defines.h" |
10 | #include "mainwindow.h" | 11 | #include "mainwindow.h" |
11 | 12 | ||
13 | using namespace Opie::Core; | ||
12 | 14 | ||
13 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags ) | 15 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags ) |
14 | : QMainWindow( parent, name, flags ) | 16 | : QMainWindow( parent, name, flags ) |
15 | { | 17 | { |
16 | 18 | ||
17 | setCaption( tr( "Mail" ) ); | 19 | setCaption( tr( "Mail" ) ); |
18 | setToolBarsMovable( false ); | 20 | setToolBarsMovable( false ); |
19 | 21 | ||
20 | toolBar = new QToolBar( this ); | 22 | toolBar = new QToolBar( this ); |
21 | menuBar = new QMenuBar( toolBar ); | 23 | menuBar = new QMenuBar( toolBar ); |
22 | mailMenu = new QPopupMenu( menuBar ); | 24 | mailMenu = new QPopupMenu( menuBar ); |
23 | menuBar->insertItem( tr( "Mail" ), mailMenu ); | 25 | menuBar->insertItem( tr( "Mail" ), mailMenu ); |
24 | settingsMenu = new QPopupMenu( menuBar ); | 26 | settingsMenu = new QPopupMenu( menuBar ); |
25 | menuBar->insertItem( tr( "Settings" ), settingsMenu ); | 27 | menuBar->insertItem( tr( "Settings" ), settingsMenu ); |
26 | 28 | ||
27 | addToolBar( toolBar ); | 29 | addToolBar( toolBar ); |
28 | toolBar->setHorizontalStretchable( true ); | 30 | toolBar->setHorizontalStretchable( true ); |
29 | 31 | ||
30 | QLabel *spacer = new QLabel( toolBar ); | 32 | QLabel *spacer = new QLabel( toolBar ); |
31 | spacer->setBackgroundMode( QWidget::PaletteButton ); | 33 | spacer->setBackgroundMode( QWidget::PaletteButton ); |
32 | toolBar->setStretchableWidget( spacer ); | 34 | toolBar->setStretchableWidget( spacer ); |
33 | 35 | ||
34 | composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL, | 36 | composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL, |
35 | 0, 0, this ); | 37 | 0, 0, this ); |
36 | composeMail->addTo( toolBar ); | 38 | composeMail->addTo( toolBar ); |
37 | composeMail->addTo( mailMenu ); | 39 | composeMail->addTo( mailMenu ); |
38 | 40 | ||
39 | sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED, | 41 | sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED, |
40 | 0, 0, this ); | 42 | 0, 0, this ); |
41 | sendQueued->addTo( toolBar ); | 43 | sendQueued->addTo( toolBar ); |
42 | sendQueued->addTo( mailMenu ); | 44 | sendQueued->addTo( mailMenu ); |
43 | 45 | ||
44 | /* | 46 | /* |
45 | syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC, | 47 | syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC, |
46 | 0, 0, this ); | 48 | 0, 0, this ); |
47 | syncFolders->addTo( toolBar ); | 49 | syncFolders->addTo( toolBar ); |
48 | syncFolders->addTo( mailMenu ); | 50 | syncFolders->addTo( mailMenu ); |
49 | */ | 51 | */ |
50 | 52 | ||
51 | showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS, | 53 | showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS, |
52 | 0, 0, this, 0, true ); | 54 | 0, 0, this, 0, true ); |
53 | showFolders->addTo( toolBar ); | 55 | showFolders->addTo( toolBar ); |
54 | showFolders->addTo( mailMenu ); | 56 | showFolders->addTo( mailMenu ); |
55 | showFolders->setOn( true ); | 57 | showFolders->setOn( true ); |
56 | connect(showFolders, SIGNAL( toggled(bool) ), | 58 | connect(showFolders, SIGNAL( toggled(bool) ), |
57 | SLOT( slotShowFolders(bool) ) ); | 59 | SLOT( slotShowFolders(bool) ) ); |
58 | 60 | ||
59 | /* | 61 | /* |
60 | searchMails = new QAction( tr( "Search mails" ), QIconSet( Resource::loadPixmap("find") ), | 62 | searchMails = new QAction( tr( "Search mails" ), QIconSet( Resource::loadPixmap("find") ), |
61 | 0, 0, this ); | 63 | 0, 0, this ); |
62 | searchMails->addTo( toolBar ); | 64 | searchMails->addTo( toolBar ); |
63 | searchMails->addTo( mailMenu ); | 65 | searchMails->addTo( mailMenu ); |
64 | */ | 66 | */ |
65 | 67 | ||
66 | deleteMails = new QAction(tr("Delete Mail"), QIconSet( Resource::loadPixmap("trash")), 0, 0, this); | 68 | deleteMails = new QAction(tr("Delete Mail"), QIconSet( Resource::loadPixmap("trash")), 0, 0, this); |
67 | deleteMails->addTo( toolBar ); | 69 | deleteMails->addTo( toolBar ); |
68 | deleteMails->addTo( mailMenu ); | 70 | deleteMails->addTo( mailMenu ); |
69 | connect( deleteMails, SIGNAL( activated() ), | 71 | connect( deleteMails, SIGNAL( activated() ), |
70 | SLOT( slotDeleteMail() ) ); | 72 | SLOT( slotDeleteMail() ) ); |
71 | 73 | ||
72 | editSettings = new QAction( tr( "Edit settings" ), QIconSet( Resource::loadPixmap("SettingsIcon") ) , | 74 | editSettings = new QAction( tr( "Edit settings" ), QIconSet( Resource::loadPixmap("SettingsIcon") ) , |
73 | 0, 0, this ); | 75 | 0, 0, this ); |
74 | editSettings->addTo( settingsMenu ); | 76 | editSettings->addTo( settingsMenu ); |
75 | connect( editSettings, SIGNAL( activated() ), | 77 | connect( editSettings, SIGNAL( activated() ), |
76 | SLOT( slotEditSettings() ) ); | 78 | SLOT( slotEditSettings() ) ); |
77 | editAccounts = new QAction( tr( "Configure accounts" ), QIconSet( Resource::loadPixmap("mail/editaccounts") ) , | 79 | editAccounts = new QAction( tr( "Configure accounts" ), QIconSet( Resource::loadPixmap("mail/editaccounts") ) , |
78 | 0, 0, this ); | 80 | 0, 0, this ); |
79 | editAccounts->addTo( settingsMenu ); | 81 | editAccounts->addTo( settingsMenu ); |
80 | 82 | ||
81 | //setCentralWidget( view ); | 83 | //setCentralWidget( view ); |
82 | 84 | ||
83 | QVBox* wrapperBox = new QVBox( this ); | 85 | QVBox* wrapperBox = new QVBox( this ); |
84 | setCentralWidget( wrapperBox ); | 86 | setCentralWidget( wrapperBox ); |
85 | 87 | ||
86 | QWidget *view = new QWidget( wrapperBox ); | 88 | QWidget *view = new QWidget( wrapperBox ); |
87 | 89 | ||
88 | layout = new QBoxLayout ( view, QBoxLayout::LeftToRight ); | 90 | layout = new QBoxLayout ( view, QBoxLayout::LeftToRight ); |
89 | 91 | ||
90 | folderView = new AccountView( view ); | 92 | folderView = new AccountView( view ); |
91 | folderView->header()->hide(); | 93 | folderView->header()->hide(); |
92 | folderView->setRootIsDecorated( true ); | 94 | folderView->setRootIsDecorated( true ); |
93 | folderView->addColumn( tr( "Mailbox" ) ); | 95 | folderView->addColumn( tr( "Mailbox" ) ); |
94 | 96 | ||
95 | layout->addWidget( folderView ); | 97 | layout->addWidget( folderView ); |
96 | 98 | ||
97 | mailView = new QListView( view ); | 99 | mailView = new QListView( view ); |
98 | mailView->addColumn( tr( "" ) ); | 100 | mailView->addColumn( tr( "" ) ); |
99 | mailView->addColumn( tr( "Subject" ),QListView::Manual ); | 101 | mailView->addColumn( tr( "Subject" ),QListView::Manual ); |
100 | mailView->addColumn( tr( "Sender" ),QListView::Manual ); | 102 | mailView->addColumn( tr( "Sender" ),QListView::Manual ); |
101 | mailView->addColumn( tr( "Size" ),QListView::Manual); | 103 | mailView->addColumn( tr( "Size" ),QListView::Manual); |
102 | mailView->addColumn( tr( "Date" )); | 104 | mailView->addColumn( tr( "Date" )); |
103 | mailView->setAllColumnsShowFocus(true); | 105 | mailView->setAllColumnsShowFocus(true); |
104 | mailView->setSorting(-1); | 106 | mailView->setSorting(-1); |
105 | 107 | ||
106 | statusWidget = new StatusWidget( wrapperBox ); | 108 | statusWidget = new StatusWidget( wrapperBox ); |
107 | statusWidget->hide(); | 109 | statusWidget->hide(); |
108 | 110 | ||
109 | layout->addWidget( mailView ); | 111 | layout->addWidget( mailView ); |
110 | layout->setStretchFactor( folderView, 1 ); | 112 | layout->setStretchFactor( folderView, 1 ); |
111 | layout->setStretchFactor( mailView, 2 ); | 113 | layout->setStretchFactor( mailView, 2 ); |
112 | 114 | ||
113 | slotAdjustLayout(); | 115 | slotAdjustLayout(); |
114 | 116 | ||
115 | QPEApplication::setStylusOperation( mailView->viewport(),QPEApplication::RightOnHold); | 117 | QPEApplication::setStylusOperation( mailView->viewport(),QPEApplication::RightOnHold); |
116 | QPEApplication::setStylusOperation( folderView->viewport(),QPEApplication::RightOnHold); | 118 | QPEApplication::setStylusOperation( folderView->viewport(),QPEApplication::RightOnHold); |
117 | 119 | ||
118 | connect( mailView, SIGNAL( mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ),this, | 120 | connect( mailView, SIGNAL( mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ),this, |
119 | SLOT( mailLeftClicked(int,QListViewItem*,const QPoint&,int) ) ); | 121 | SLOT( mailLeftClicked(int,QListViewItem*,const QPoint&,int) ) ); |
120 | connect( mailView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this, | 122 | connect( mailView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this, |
121 | SLOT( mailHold(int,QListViewItem*,const QPoint&,int) ) ); | 123 | SLOT( mailHold(int,QListViewItem*,const QPoint&,int) ) ); |
122 | connect(folderView, SIGNAL(refreshMailview(const QValueList<RecMailP>&)), | 124 | connect(folderView, SIGNAL(refreshMailview(const QValueList<RecMailP>&)), |
123 | this,SLOT(refreshMailView(const QValueList<RecMailP>&))); | 125 | this,SLOT(refreshMailView(const QValueList<RecMailP>&))); |
124 | connect( composeMail, SIGNAL( activated() ), SLOT( slotComposeMail() ) ); | 126 | connect( composeMail, SIGNAL( activated() ), SLOT( slotComposeMail() ) ); |
125 | connect( sendQueued, SIGNAL( activated() ), SLOT( slotSendQueued() ) ); | 127 | connect( sendQueued, SIGNAL( activated() ), SLOT( slotSendQueued() ) ); |
126 | // connect( searchMails, SIGNAL( activated() ), SLOT( slotSearchMails() ) ); | 128 | // connect( searchMails, SIGNAL( activated() ), SLOT( slotSearchMails() ) ); |
127 | connect( editAccounts, SIGNAL( activated() ), SLOT( slotEditAccounts() ) ); | 129 | connect( editAccounts, SIGNAL( activated() ), SLOT( slotEditAccounts() ) ); |
128 | // Added by Stefan Eilers to allow starting by addressbook.. | 130 | // Added by Stefan Eilers to allow starting by addressbook.. |
129 | // copied from old mail2 | 131 | // copied from old mail2 |
130 | #if !defined(QT_NO_COP) | 132 | #if !defined(QT_NO_COP) |
131 | connect( qApp, SIGNAL( appMessage(const QCString&,const QByteArray&) ), | 133 | connect( qApp, SIGNAL( appMessage(const QCString&,const QByteArray&) ), |
132 | this, SLOT( appMessage(const QCString&,const QByteArray&) ) ); | 134 | this, SLOT( appMessage(const QCString&,const QByteArray&) ) ); |
133 | #endif | 135 | #endif |
134 | 136 | ||
135 | QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) ); | 137 | QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) ); |
136 | } | 138 | } |
137 | 139 | ||
138 | MainWindow::~MainWindow() | 140 | MainWindow::~MainWindow() |
139 | { | 141 | { |
140 | } | 142 | } |
141 | 143 | ||
142 | void MainWindow::appMessage(const QCString &, const QByteArray &) | 144 | void MainWindow::appMessage(const QCString &, const QByteArray &) |
143 | { | 145 | { |
144 | odebug << "appMessage not reached" << oendl; | 146 | odebug << "appMessage not reached" << oendl; |
145 | } | 147 | } |
146 | 148 | ||
147 | void MainWindow::slotAdjustLayout() { | 149 | void MainWindow::slotAdjustLayout() { |
148 | 150 | ||
149 | QWidget *d = QApplication::desktop(); | 151 | QWidget *d = QApplication::desktop(); |
150 | 152 | ||
151 | if ( d->width() < d->height() ) { | 153 | if ( d->width() < d->height() ) { |
152 | layout->setDirection( QBoxLayout::TopToBottom ); | 154 | layout->setDirection( QBoxLayout::TopToBottom ); |
153 | } else { | 155 | } else { |
154 | layout->setDirection( QBoxLayout::LeftToRight ); | 156 | layout->setDirection( QBoxLayout::LeftToRight ); |
155 | } | 157 | } |
156 | } | 158 | } |
157 | 159 | ||
158 | void MainWindow::slotAdjustColumns() | 160 | void MainWindow::slotAdjustColumns() |
159 | { | 161 | { |
160 | bool hidden = folderView->isHidden(); | 162 | bool hidden = folderView->isHidden(); |
161 | if ( hidden ) folderView->show(); | 163 | if ( hidden ) folderView->show(); |
162 | folderView->setColumnWidth( 0, folderView->visibleWidth() ); | 164 | folderView->setColumnWidth( 0, folderView->visibleWidth() ); |
163 | if ( hidden ) folderView->hide(); | 165 | if ( hidden ) folderView->hide(); |
164 | 166 | ||
165 | mailView->setColumnWidth( 0, 10 ); | 167 | mailView->setColumnWidth( 0, 10 ); |
166 | mailView->setColumnWidth( 1, mailView->visibleWidth() - 130 ); | 168 | mailView->setColumnWidth( 1, mailView->visibleWidth() - 130 ); |
167 | mailView->setColumnWidth( 2, 80 ); | 169 | mailView->setColumnWidth( 2, 80 ); |
168 | mailView->setColumnWidth( 3, 50 ); | 170 | mailView->setColumnWidth( 3, 50 ); |
169 | mailView->setColumnWidth( 4, 50 ); | 171 | mailView->setColumnWidth( 4, 50 ); |
170 | } | 172 | } |
171 | 173 | ||
172 | void MainWindow::slotEditSettings() | 174 | void MainWindow::slotEditSettings() |
173 | { | 175 | { |
174 | } | 176 | } |
175 | 177 | ||
176 | void MainWindow::slotShowFolders( bool ) | 178 | void MainWindow::slotShowFolders( bool ) |
177 | { | 179 | { |
178 | odebug << "slotShowFolders not reached" << oendl; | 180 | odebug << "slotShowFolders not reached" << oendl; |
179 | } | 181 | } |
180 | 182 | ||
181 | void MainWindow::refreshMailView(const QValueList<RecMailP>&) | 183 | void MainWindow::refreshMailView(const QValueList<RecMailP>&) |
182 | { | 184 | { |
183 | odebug << "refreshMailView not reached" << oendl; | 185 | odebug << "refreshMailView not reached" << oendl; |
184 | } | 186 | } |
185 | 187 | ||
186 | void MainWindow::mailLeftClicked(int, QListViewItem *,const QPoint&,int ) | 188 | void MainWindow::mailLeftClicked(int, QListViewItem *,const QPoint&,int ) |
187 | { | 189 | { |
188 | odebug << "mailLeftClicked not reached" << oendl; | 190 | odebug << "mailLeftClicked not reached" << oendl; |
189 | } | 191 | } |
190 | 192 | ||
191 | void MainWindow::displayMail() | 193 | void MainWindow::displayMail() |
192 | { | 194 | { |
193 | odebug << "displayMail not reached" << oendl; | 195 | odebug << "displayMail not reached" << oendl; |
194 | } | 196 | } |
195 | 197 | ||
196 | void MainWindow::slotDeleteMail() | 198 | void MainWindow::slotDeleteMail() |
197 | { | 199 | { |
198 | odebug << "deleteMail not reached" << oendl; | 200 | odebug << "deleteMail not reached" << oendl; |
199 | } | 201 | } |
200 | 202 | ||
201 | void MainWindow::mailHold(int, QListViewItem *,const QPoint&,int ) | 203 | void MainWindow::mailHold(int, QListViewItem *,const QPoint&,int ) |
202 | { | 204 | { |
203 | odebug << "mailHold not reached" << oendl; | 205 | odebug << "mailHold not reached" << oendl; |
204 | } | 206 | } |
205 | 207 | ||
206 | void MainWindow::slotSendQueued() | 208 | void MainWindow::slotSendQueued() |
207 | { | 209 | { |
208 | } | 210 | } |
209 | 211 | ||
210 | void MainWindow::slotEditAccounts() | 212 | void MainWindow::slotEditAccounts() |
211 | { | 213 | { |
212 | } | 214 | } |
213 | 215 | ||
214 | void MainWindow::slotComposeMail() | 216 | void MainWindow::slotComposeMail() |
215 | { | 217 | { |
216 | } | 218 | } |
diff --git a/noncore/net/mail/nntpgroups.cpp b/noncore/net/mail/nntpgroups.cpp index 3243ee3..d81d8b1 100644 --- a/noncore/net/mail/nntpgroups.cpp +++ b/noncore/net/mail/nntpgroups.cpp | |||
@@ -1,62 +1,64 @@ | |||
1 | #include "nntpgroups.h" | 1 | #include "nntpgroups.h" |
2 | 2 | ||
3 | #include <libmailwrapper/settings.h> | 3 | #include <libmailwrapper/settings.h> |
4 | 4 | #include <opie2/odebug.h> | |
5 | #include <qlistview.h> | 5 | #include <qlistview.h> |
6 | #include <qlineedit.h> | 6 | #include <qlineedit.h> |
7 | 7 | ||
8 | using namespace Opie::Core; | ||
9 | |||
8 | NNTPGroups::NNTPGroups(NNTPaccount *account, QWidget* parent, const char* name, WFlags fl) | 10 | NNTPGroups::NNTPGroups(NNTPaccount *account, QWidget* parent, const char* name, WFlags fl) |
9 | : NNTPGroupsUI(parent,name,fl),subscribedGroups() | 11 | : NNTPGroupsUI(parent,name,fl),subscribedGroups() |
10 | { | 12 | { |
11 | m_Account = account; | 13 | m_Account = account; |
12 | fillGroups(); | 14 | fillGroups(); |
13 | } | 15 | } |
14 | 16 | ||
15 | NNTPGroups::~NNTPGroups() | 17 | NNTPGroups::~NNTPGroups() |
16 | { | 18 | { |
17 | 19 | ||
18 | } | 20 | } |
19 | 21 | ||
20 | void NNTPGroups::slotGetNG() | 22 | void NNTPGroups::slotGetNG() |
21 | { | 23 | { |
22 | if (!m_Account) return; | 24 | if (!m_Account) return; |
23 | GroupListView->clear(); | 25 | GroupListView->clear(); |
24 | NNTPwrapper tmp( m_Account ); | 26 | NNTPwrapper tmp( m_Account ); |
25 | QString filter = Groupfilteredit->text(); | 27 | QString filter = Groupfilteredit->text(); |
26 | QStringList list = tmp.listAllNewsgroups(filter); | 28 | QStringList list = tmp.listAllNewsgroups(filter); |
27 | subscribedGroupsNotListed = subscribedGroups; | 29 | subscribedGroupsNotListed = subscribedGroups; |
28 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 30 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
29 | QCheckListItem *item; | 31 | QCheckListItem *item; |
30 | item = new QCheckListItem( GroupListView, (*it), QCheckListItem::CheckBox ); | 32 | item = new QCheckListItem( GroupListView, (*it), QCheckListItem::CheckBox ); |
31 | if ( subscribedGroups.contains( (*it) ) >= 1 ) { | 33 | if ( subscribedGroups.contains( (*it) ) >= 1 ) { |
32 | item->setOn( true ); | 34 | item->setOn( true ); |
33 | subscribedGroupsNotListed.remove((*it)); | 35 | subscribedGroupsNotListed.remove((*it)); |
34 | } | 36 | } |
35 | } | 37 | } |
36 | } | 38 | } |
37 | 39 | ||
38 | void NNTPGroups::fillGroups() | 40 | void NNTPGroups::fillGroups() |
39 | { | 41 | { |
40 | if (!m_Account) return; | 42 | if (!m_Account) return; |
41 | subscribedGroups = m_Account->getGroups(); | 43 | subscribedGroups = m_Account->getGroups(); |
42 | for ( QStringList::Iterator it = subscribedGroups.begin(); it != subscribedGroups.end(); ++it ) { | 44 | for ( QStringList::Iterator it = subscribedGroups.begin(); it != subscribedGroups.end(); ++it ) { |
43 | QCheckListItem *item; | 45 | QCheckListItem *item; |
44 | item = new QCheckListItem( GroupListView, (*it), QCheckListItem::CheckBox ); | 46 | item = new QCheckListItem( GroupListView, (*it), QCheckListItem::CheckBox ); |
45 | item->setOn( true ); | 47 | item->setOn( true ); |
46 | } | 48 | } |
47 | } | 49 | } |
48 | 50 | ||
49 | void NNTPGroups::storeValues() | 51 | void NNTPGroups::storeValues() |
50 | { | 52 | { |
51 | if (!m_Account) return; | 53 | if (!m_Account) return; |
52 | QListViewItemIterator list_it( GroupListView ); | 54 | QListViewItemIterator list_it( GroupListView ); |
53 | subscribedGroups.clear(); | 55 | subscribedGroups.clear(); |
54 | for ( ; list_it.current(); ++list_it ) { | 56 | for ( ; list_it.current(); ++list_it ) { |
55 | if ( ( (QCheckListItem*)list_it.current() )->isOn() ) { | 57 | if ( ( (QCheckListItem*)list_it.current() )->isOn() ) { |
56 | odebug << list_it.current()->text(0) << oendl; | 58 | odebug << list_it.current()->text(0) << oendl; |
57 | subscribedGroups.append( list_it.current()->text(0) ); | 59 | subscribedGroups.append( list_it.current()->text(0) ); |
58 | } | 60 | } |
59 | } | 61 | } |
60 | subscribedGroups+=subscribedGroupsNotListed; | 62 | subscribedGroups+=subscribedGroupsNotListed; |
61 | m_Account->setGroups( subscribedGroups ); | 63 | m_Account->setGroups( subscribedGroups ); |
62 | } | 64 | } |
diff --git a/noncore/net/mail/opiemail.cpp b/noncore/net/mail/opiemail.cpp index 0669b5a..5399c3c 100644 --- a/noncore/net/mail/opiemail.cpp +++ b/noncore/net/mail/opiemail.cpp | |||
@@ -1,280 +1,283 @@ | |||
1 | 1 | ||
2 | #include "settingsdialog.h" | 2 | #include "settingsdialog.h" |
3 | #include "opiemail.h" | 3 | #include "opiemail.h" |
4 | #include "editaccounts.h" | 4 | #include "editaccounts.h" |
5 | #include "composemail.h" | 5 | #include "composemail.h" |
6 | #include "mailistviewitem.h" | 6 | #include "mailistviewitem.h" |
7 | #include "viewmail.h" | 7 | #include "viewmail.h" |
8 | #include "selectstore.h" | 8 | #include "selectstore.h" |
9 | #include "selectsmtp.h" | 9 | #include "selectsmtp.h" |
10 | 10 | ||
11 | /* OPIE */ | ||
12 | #include <libmailwrapper/smtpwrapper.h> | 11 | #include <libmailwrapper/smtpwrapper.h> |
13 | #include <libmailwrapper/mailtypes.h> | 12 | #include <libmailwrapper/mailtypes.h> |
14 | #include <libmailwrapper/abstractmail.h> | 13 | #include <libmailwrapper/abstractmail.h> |
14 | /* OPIE */ | ||
15 | #include <opie2/odebug.h> | ||
15 | #include <qpe/resource.h> | 16 | #include <qpe/resource.h> |
16 | #include <qpe/qpeapplication.h> | 17 | #include <qpe/qpeapplication.h> |
17 | 18 | ||
18 | /* QT */ | 19 | /* QT */ |
19 | 20 | ||
21 | using namespace Opie::Core; | ||
22 | |||
20 | OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags ) | 23 | OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags ) |
21 | : MainWindow( parent, name, WStyle_ContextHelp ) | 24 | : MainWindow( parent, name, WStyle_ContextHelp ) |
22 | { | 25 | { |
23 | settings = new Settings(); | 26 | settings = new Settings(); |
24 | 27 | ||
25 | folderView->populate( settings->getAccounts() ); | 28 | folderView->populate( settings->getAccounts() ); |
26 | } | 29 | } |
27 | 30 | ||
28 | OpieMail::~OpieMail() | 31 | OpieMail::~OpieMail() |
29 | { | 32 | { |
30 | if (settings) delete settings; | 33 | if (settings) delete settings; |
31 | } | 34 | } |
32 | 35 | ||
33 | void OpieMail::appMessage(const QCString &msg, const QByteArray &data) | 36 | void OpieMail::appMessage(const QCString &msg, const QByteArray &data) |
34 | { | 37 | { |
35 | // copied from old mail2 | 38 | // copied from old mail2 |
36 | if (msg == "writeMail(QString,QString)") | 39 | if (msg == "writeMail(QString,QString)") |
37 | { | 40 | { |
38 | QDataStream stream(data,IO_ReadOnly); | 41 | QDataStream stream(data,IO_ReadOnly); |
39 | QString name, email; | 42 | QString name, email; |
40 | stream >> name >> email; | 43 | stream >> name >> email; |
41 | // removing the whitespaces at beginning and end is needed! | 44 | // removing the whitespaces at beginning and end is needed! |
42 | slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace()); | 45 | slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace()); |
43 | } | 46 | } |
44 | else if (msg == "newMail()") | 47 | else if (msg == "newMail()") |
45 | { | 48 | { |
46 | slotComposeMail(); | 49 | slotComposeMail(); |
47 | } | 50 | } |
48 | } | 51 | } |
49 | 52 | ||
50 | void OpieMail::slotwriteMail(const QString&name,const QString&email) | 53 | void OpieMail::slotwriteMail(const QString&name,const QString&email) |
51 | { | 54 | { |
52 | ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp ); | 55 | ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp ); |
53 | if (!email.isEmpty()) | 56 | if (!email.isEmpty()) |
54 | { | 57 | { |
55 | if (!name.isEmpty()) | 58 | if (!name.isEmpty()) |
56 | { | 59 | { |
57 | compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); | 60 | compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); |
58 | } | 61 | } |
59 | else | 62 | else |
60 | { | 63 | { |
61 | compose.setTo(email); | 64 | compose.setTo(email); |
62 | } | 65 | } |
63 | } | 66 | } |
64 | compose.slotAdjustColumns(); | 67 | compose.slotAdjustColumns(); |
65 | QPEApplication::execDialog( &compose ); | 68 | QPEApplication::execDialog( &compose ); |
66 | } | 69 | } |
67 | 70 | ||
68 | void OpieMail::slotComposeMail() | 71 | void OpieMail::slotComposeMail() |
69 | { | 72 | { |
70 | odebug << "Compose Mail" << oendl; | 73 | odebug << "Compose Mail" << oendl; |
71 | slotwriteMail(0l,0l); | 74 | slotwriteMail(0l,0l); |
72 | } | 75 | } |
73 | 76 | ||
74 | void OpieMail::slotSendQueued() | 77 | void OpieMail::slotSendQueued() |
75 | { | 78 | { |
76 | odebug << "Send Queued" << oendl; | 79 | odebug << "Send Queued" << oendl; |
77 | SMTPaccount *smtp = 0; | 80 | SMTPaccount *smtp = 0; |
78 | 81 | ||
79 | QList<Account> list = settings->getAccounts(); | 82 | QList<Account> list = settings->getAccounts(); |
80 | QList<SMTPaccount> smtpList; | 83 | QList<SMTPaccount> smtpList; |
81 | smtpList.setAutoDelete(false); | 84 | smtpList.setAutoDelete(false); |
82 | Account *it; | 85 | Account *it; |
83 | for ( it = list.first(); it; it = list.next() ) | 86 | for ( it = list.first(); it; it = list.next() ) |
84 | { | 87 | { |
85 | if ( it->getType() == MAILLIB::A_SMTP ) | 88 | if ( it->getType() == MAILLIB::A_SMTP ) |
86 | { | 89 | { |
87 | smtp = static_cast<SMTPaccount *>(it); | 90 | smtp = static_cast<SMTPaccount *>(it); |
88 | smtpList.append(smtp); | 91 | smtpList.append(smtp); |
89 | } | 92 | } |
90 | } | 93 | } |
91 | if (smtpList.count()==0) | 94 | if (smtpList.count()==0) |
92 | { | 95 | { |
93 | QMessageBox::information(0,tr("Info"),tr("Define a smtp account first")); | 96 | QMessageBox::information(0,tr("Info"),tr("Define a smtp account first")); |
94 | return; | 97 | return; |
95 | } | 98 | } |
96 | if (smtpList.count()==1) | 99 | if (smtpList.count()==1) |
97 | { | 100 | { |
98 | smtp = smtpList.at(0); | 101 | smtp = smtpList.at(0); |
99 | } | 102 | } |
100 | else | 103 | else |
101 | { | 104 | { |
102 | smtp = 0; | 105 | smtp = 0; |
103 | selectsmtp selsmtp; | 106 | selectsmtp selsmtp; |
104 | selsmtp.setSelectionlist(&smtpList); | 107 | selsmtp.setSelectionlist(&smtpList); |
105 | if ( QPEApplication::execDialog( &selsmtp ) == QDialog::Accepted ) | 108 | if ( QPEApplication::execDialog( &selsmtp ) == QDialog::Accepted ) |
106 | { | 109 | { |
107 | smtp = selsmtp.selected_smtp(); | 110 | smtp = selsmtp.selected_smtp(); |
108 | } | 111 | } |
109 | } | 112 | } |
110 | if (smtp) | 113 | if (smtp) |
111 | { | 114 | { |
112 | SMTPwrapper * wrap = new SMTPwrapper(smtp); | 115 | SMTPwrapper * wrap = new SMTPwrapper(smtp); |
113 | if ( wrap->flushOutbox() ) | 116 | if ( wrap->flushOutbox() ) |
114 | { | 117 | { |
115 | QMessageBox::information(0,tr("Info"),tr("Mail queue flushed")); | 118 | QMessageBox::information(0,tr("Info"),tr("Mail queue flushed")); |
116 | } | 119 | } |
117 | delete wrap; | 120 | delete wrap; |
118 | } | 121 | } |
119 | } | 122 | } |
120 | 123 | ||
121 | void OpieMail::slotSearchMails() | 124 | void OpieMail::slotSearchMails() |
122 | { | 125 | { |
123 | odebug << "Search Mails" << oendl; | 126 | odebug << "Search Mails" << oendl; |
124 | } | 127 | } |
125 | 128 | ||
126 | void OpieMail::slotEditSettings() | 129 | void OpieMail::slotEditSettings() |
127 | { | 130 | { |
128 | SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp ); | 131 | SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp ); |
129 | QPEApplication::execDialog( &settingsDialog ); | 132 | QPEApplication::execDialog( &settingsDialog ); |
130 | } | 133 | } |
131 | 134 | ||
132 | void OpieMail::slotEditAccounts() | 135 | void OpieMail::slotEditAccounts() |
133 | { | 136 | { |
134 | odebug << "Edit Accounts" << oendl; | 137 | odebug << "Edit Accounts" << oendl; |
135 | EditAccounts eaDialog( settings, this, 0, true, WStyle_ContextHelp ); | 138 | EditAccounts eaDialog( settings, this, 0, true, WStyle_ContextHelp ); |
136 | eaDialog.slotAdjustColumns(); | 139 | eaDialog.slotAdjustColumns(); |
137 | QPEApplication::execDialog( &eaDialog ); | 140 | QPEApplication::execDialog( &eaDialog ); |
138 | if ( settings ) delete settings; | 141 | if ( settings ) delete settings; |
139 | settings = new Settings(); | 142 | settings = new Settings(); |
140 | 143 | ||
141 | folderView->populate( settings->getAccounts() ); | 144 | folderView->populate( settings->getAccounts() ); |
142 | } | 145 | } |
143 | 146 | ||
144 | void OpieMail::displayMail() | 147 | void OpieMail::displayMail() |
145 | { | 148 | { |
146 | QListViewItem*item = mailView->currentItem(); | 149 | QListViewItem*item = mailView->currentItem(); |
147 | if (!item) return; | 150 | if (!item) return; |
148 | RecMailP mail = ((MailListViewItem*)item)->data(); | 151 | RecMailP mail = ((MailListViewItem*)item)->data(); |
149 | RecBodyP body = folderView->fetchBody(mail); | 152 | RecBodyP body = folderView->fetchBody(mail); |
150 | ViewMail readMail( this,"", Qt::WType_Modal | WStyle_ContextHelp ); | 153 | ViewMail readMail( this,"", Qt::WType_Modal | WStyle_ContextHelp ); |
151 | readMail.setBody( body ); | 154 | readMail.setBody( body ); |
152 | readMail.setMail( mail ); | 155 | readMail.setMail( mail ); |
153 | readMail.showMaximized(); | 156 | readMail.showMaximized(); |
154 | readMail.exec(); | 157 | readMail.exec(); |
155 | 158 | ||
156 | if ( readMail.deleted ) | 159 | if ( readMail.deleted ) |
157 | { | 160 | { |
158 | folderView->refreshCurrent(); | 161 | folderView->refreshCurrent(); |
159 | } | 162 | } |
160 | else | 163 | else |
161 | { | 164 | { |
162 | ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "" ) ); | 165 | ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "" ) ); |
163 | } | 166 | } |
164 | } | 167 | } |
165 | 168 | ||
166 | void OpieMail::slotDeleteMail() | 169 | void OpieMail::slotDeleteMail() |
167 | { | 170 | { |
168 | if (!mailView->currentItem()) return; | 171 | if (!mailView->currentItem()) return; |
169 | RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); | 172 | RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); |
170 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) | 173 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) |
171 | { | 174 | { |
172 | mail->Wrapper()->deleteMail( mail ); | 175 | mail->Wrapper()->deleteMail( mail ); |
173 | folderView->refreshCurrent(); | 176 | folderView->refreshCurrent(); |
174 | } | 177 | } |
175 | } | 178 | } |
176 | 179 | ||
177 | void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int ) | 180 | void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int ) |
178 | { | 181 | { |
179 | if (!mailView->currentItem()) return; | 182 | if (!mailView->currentItem()) return; |
180 | MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType(); | 183 | MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType(); |
181 | /* just the RIGHT button - or hold on pda */ | 184 | /* just the RIGHT button - or hold on pda */ |
182 | if (button!=2) {return;} | 185 | if (button!=2) {return;} |
183 | odebug << "Event right/hold" << oendl; | 186 | odebug << "Event right/hold" << oendl; |
184 | if (!item) return; | 187 | if (!item) return; |
185 | QPopupMenu *m = new QPopupMenu(0); | 188 | QPopupMenu *m = new QPopupMenu(0); |
186 | if (m) | 189 | if (m) |
187 | { | 190 | { |
188 | if (mailtype==MAILLIB::A_NNTP) { | 191 | if (mailtype==MAILLIB::A_NNTP) { |
189 | m->insertItem(tr("Read this posting"),this,SLOT(displayMail())); | 192 | m->insertItem(tr("Read this posting"),this,SLOT(displayMail())); |
190 | // m->insertItem(tr("Copy this posting"),this,SLOT(slotMoveCopyMail())); | 193 | // m->insertItem(tr("Copy this posting"),this,SLOT(slotMoveCopyMail())); |
191 | } else { | 194 | } else { |
192 | if (folderView->currentisDraft()) { | 195 | if (folderView->currentisDraft()) { |
193 | m->insertItem(tr("Edit this mail"),this,SLOT(reEditMail())); | 196 | m->insertItem(tr("Edit this mail"),this,SLOT(reEditMail())); |
194 | } | 197 | } |
195 | m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); | 198 | m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); |
196 | m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); | 199 | m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); |
197 | m->insertItem(tr("Copy/Move this mail"),this,SLOT(slotMoveCopyMail())); | 200 | m->insertItem(tr("Copy/Move this mail"),this,SLOT(slotMoveCopyMail())); |
198 | } | 201 | } |
199 | m->setFocus(); | 202 | m->setFocus(); |
200 | m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); | 203 | m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); |
201 | delete m; | 204 | delete m; |
202 | } | 205 | } |
203 | } | 206 | } |
204 | 207 | ||
205 | void OpieMail::slotShowFolders( bool show ) | 208 | void OpieMail::slotShowFolders( bool show ) |
206 | { | 209 | { |
207 | odebug << "Show Folders" << oendl; | 210 | odebug << "Show Folders" << oendl; |
208 | if ( show && folderView->isHidden() ) | 211 | if ( show && folderView->isHidden() ) |
209 | { | 212 | { |
210 | odebug << "-> showing" << oendl; | 213 | odebug << "-> showing" << oendl; |
211 | folderView->show(); | 214 | folderView->show(); |
212 | } | 215 | } |
213 | else if ( !show && !folderView->isHidden() ) | 216 | else if ( !show && !folderView->isHidden() ) |
214 | { | 217 | { |
215 | odebug << "-> hiding" << oendl; | 218 | odebug << "-> hiding" << oendl; |
216 | folderView->hide(); | 219 | folderView->hide(); |
217 | } | 220 | } |
218 | } | 221 | } |
219 | 222 | ||
220 | void OpieMail::refreshMailView(const QValueList<RecMailP>&list) | 223 | void OpieMail::refreshMailView(const QValueList<RecMailP>&list) |
221 | { | 224 | { |
222 | MailListViewItem*item = 0; | 225 | MailListViewItem*item = 0; |
223 | mailView->clear(); | 226 | mailView->clear(); |
224 | 227 | ||
225 | QValueList<RecMailP>::ConstIterator it; | 228 | QValueList<RecMailP>::ConstIterator it; |
226 | for (it = list.begin(); it != list.end();++it) | 229 | for (it = list.begin(); it != list.end();++it) |
227 | { | 230 | { |
228 | item = new MailListViewItem(mailView,item); | 231 | item = new MailListViewItem(mailView,item); |
229 | item->storeData((*it)); | 232 | item->storeData((*it)); |
230 | item->showEntry(); | 233 | item->showEntry(); |
231 | } | 234 | } |
232 | } | 235 | } |
233 | 236 | ||
234 | void OpieMail::mailLeftClicked(int button, QListViewItem *item,const QPoint&,int ) | 237 | void OpieMail::mailLeftClicked(int button, QListViewItem *item,const QPoint&,int ) |
235 | { | 238 | { |
236 | /* just LEFT button - or tap with stylus on pda */ | 239 | /* just LEFT button - or tap with stylus on pda */ |
237 | if (button!=1) return; | 240 | if (button!=1) return; |
238 | if (!item) return; | 241 | if (!item) return; |
239 | if (folderView->currentisDraft()) { | 242 | if (folderView->currentisDraft()) { |
240 | reEditMail(); | 243 | reEditMail(); |
241 | } else { | 244 | } else { |
242 | displayMail(); | 245 | displayMail(); |
243 | } | 246 | } |
244 | } | 247 | } |
245 | 248 | ||
246 | void OpieMail::slotMoveCopyMail() | 249 | void OpieMail::slotMoveCopyMail() |
247 | { | 250 | { |
248 | if (!mailView->currentItem()) return; | 251 | if (!mailView->currentItem()) return; |
249 | RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); | 252 | RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); |
250 | AbstractMail*targetMail = 0; | 253 | AbstractMail*targetMail = 0; |
251 | QString targetFolder = ""; | 254 | QString targetFolder = ""; |
252 | Selectstore sels; | 255 | Selectstore sels; |
253 | folderView->setupFolderselect(&sels); | 256 | folderView->setupFolderselect(&sels); |
254 | if (!sels.exec()) return; | 257 | if (!sels.exec()) return; |
255 | targetMail = sels.currentMail(); | 258 | targetMail = sels.currentMail(); |
256 | targetFolder = sels.currentFolder(); | 259 | targetFolder = sels.currentFolder(); |
257 | if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || | 260 | if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || |
258 | targetFolder.isEmpty()) | 261 | targetFolder.isEmpty()) |
259 | { | 262 | { |
260 | return; | 263 | return; |
261 | } | 264 | } |
262 | if (sels.newFolder() && !targetMail->createMbox(targetFolder)) | 265 | if (sels.newFolder() && !targetMail->createMbox(targetFolder)) |
263 | { | 266 | { |
264 | QMessageBox::critical(0,tr("Error creating new Folder"), | 267 | QMessageBox::critical(0,tr("Error creating new Folder"), |
265 | tr("<center>Error while creating<br>new folder - breaking.</center>")); | 268 | tr("<center>Error while creating<br>new folder - breaking.</center>")); |
266 | return; | 269 | return; |
267 | } | 270 | } |
268 | mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails()); | 271 | mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails()); |
269 | folderView->refreshCurrent(); | 272 | folderView->refreshCurrent(); |
270 | } | 273 | } |
271 | 274 | ||
272 | void OpieMail::reEditMail() | 275 | void OpieMail::reEditMail() |
273 | { | 276 | { |
274 | if (!mailView->currentItem()) return; | 277 | if (!mailView->currentItem()) return; |
275 | 278 | ||
276 | ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp ); | 279 | ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp ); |
277 | compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data()); | 280 | compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data()); |
278 | compose.slotAdjustColumns(); | 281 | compose.slotAdjustColumns(); |
279 | QPEApplication::execDialog( &compose ); | 282 | QPEApplication::execDialog( &compose ); |
280 | } | 283 | } |
diff --git a/noncore/net/mail/taskbarapplet/mailapplet.cpp b/noncore/net/mail/taskbarapplet/mailapplet.cpp index cac9048..2fc1d01 100644 --- a/noncore/net/mail/taskbarapplet/mailapplet.cpp +++ b/noncore/net/mail/taskbarapplet/mailapplet.cpp | |||
@@ -1,145 +1,145 @@ | |||
1 | #include <qpainter.h> | 1 | #include <qpainter.h> |
2 | #include <qtimer.h> | 2 | #include <qtimer.h> |
3 | 3 | ||
4 | #include <qpe/qcopenvelope_qws.h> | 4 | #include <qpe/qcopenvelope_qws.h> |
5 | #include <qpe/resource.h> | 5 | #include <qpe/resource.h> |
6 | #include <qpe/config.h> | 6 | #include <qpe/config.h> |
7 | #include <qpe/applnk.h> | 7 | #include <qpe/applnk.h> |
8 | 8 | #include <opie2/odebug.h> | |
9 | #include <opie2/odevice.h> | 9 | #include <opie2/odevice.h> |
10 | 10 | ||
11 | #include <libmailwrapper/settings.h> | 11 | #include <libmailwrapper/settings.h> |
12 | 12 | ||
13 | #include "mailapplet.h" | 13 | #include "mailapplet.h" |
14 | 14 | ||
15 | using namespace Opie::Core; | 15 | using namespace Opie::Core; |
16 | 16 | ||
17 | MailApplet::MailApplet( QWidget *parent ) | 17 | MailApplet::MailApplet( QWidget *parent ) |
18 | : QWidget( parent ) { | 18 | : QWidget( parent ) { |
19 | 19 | ||
20 | m_config = new Config( "mail" ); | 20 | m_config = new Config( "mail" ); |
21 | m_config->setGroup( "Applet" ); | 21 | m_config->setGroup( "Applet" ); |
22 | 22 | ||
23 | setFixedWidth( AppLnk::smallIconSize() ); | 23 | setFixedWidth( AppLnk::smallIconSize() ); |
24 | setFixedHeight( AppLnk::smallIconSize() ); | 24 | setFixedHeight( AppLnk::smallIconSize() ); |
25 | 25 | ||
26 | hide(); | 26 | hide(); |
27 | 27 | ||
28 | m_newMails = 0; | 28 | m_newMails = 0; |
29 | m_statusMail = 0l; | 29 | m_statusMail = 0l; |
30 | 30 | ||
31 | if ( !m_config->readBoolEntry( "Disabled", false ) ) { | 31 | if ( !m_config->readBoolEntry( "Disabled", false ) ) { |
32 | // delay 5 sec until the whole mail backend gets started .-) | 32 | // delay 5 sec until the whole mail backend gets started .-) |
33 | QTimer::singleShot( 5000, this, SLOT( startup() ) ); | 33 | QTimer::singleShot( 5000, this, SLOT( startup() ) ); |
34 | } | 34 | } |
35 | repaint( true ); | 35 | repaint( true ); |
36 | } | 36 | } |
37 | 37 | ||
38 | 38 | ||
39 | MailApplet::~MailApplet() { | 39 | MailApplet::~MailApplet() { |
40 | if ( m_statusMail ) | 40 | if ( m_statusMail ) |
41 | delete m_statusMail; | 41 | delete m_statusMail; |
42 | if ( m_config ) | 42 | if ( m_config ) |
43 | delete m_config; | 43 | delete m_config; |
44 | } | 44 | } |
45 | 45 | ||
46 | void MailApplet::paintEvent( QPaintEvent* ) { | 46 | void MailApplet::paintEvent( QPaintEvent* ) { |
47 | QPainter p( this ); | 47 | QPainter p( this ); |
48 | p.drawPixmap( 0, 0, Resource::loadPixmap( "mail/inbox" ) ); | 48 | p.drawPixmap( 0, 0, Resource::loadPixmap( "mail/inbox" ) ); |
49 | QFont f( "vera", AppLnk::smallIconSize() ); | 49 | QFont f( "vera", AppLnk::smallIconSize() ); |
50 | QFontMetrics fm( f ); | 50 | QFontMetrics fm( f ); |
51 | p.setFont( f ); | 51 | p.setFont( f ); |
52 | p.setPen( Qt::blue ); | 52 | p.setPen( Qt::blue ); |
53 | p.drawText( AppLnk::smallIconSize()/3, AppLnk::smallIconSize() - 2, QString::number( m_newMails ) ); | 53 | p.drawText( AppLnk::smallIconSize()/3, AppLnk::smallIconSize() - 2, QString::number( m_newMails ) ); |
54 | return; | 54 | return; |
55 | 55 | ||
56 | } | 56 | } |
57 | 57 | ||
58 | void MailApplet::mouseReleaseEvent( QMouseEvent* e ) { | 58 | void MailApplet::mouseReleaseEvent( QMouseEvent* e ) { |
59 | slotClicked(); | 59 | slotClicked(); |
60 | } | 60 | } |
61 | 61 | ||
62 | void MailApplet::slotClicked() { | 62 | void MailApplet::slotClicked() { |
63 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 63 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
64 | e << QString( "opiemail" ); | 64 | e << QString( "opiemail" ); |
65 | 65 | ||
66 | ODevice *device = ODevice::inst(); | 66 | ODevice *device = ODevice::inst(); |
67 | if ( !device-> ledList().isEmpty() ) { | 67 | if ( !device-> ledList().isEmpty() ) { |
68 | OLed led = ( device->ledList().contains( Led_Mail ) ) ? Led_Mail : device->ledList()[0]; | 68 | OLed led = ( device->ledList().contains( Led_Mail ) ) ? Led_Mail : device->ledList()[0]; |
69 | 69 | ||
70 | device->setLedState( led, Led_Off ); | 70 | device->setLedState( led, Led_Off ); |
71 | } | 71 | } |
72 | 72 | ||
73 | if (m_statusMail) | 73 | if (m_statusMail) |
74 | m_statusMail->reset_status(); | 74 | m_statusMail->reset_status(); |
75 | 75 | ||
76 | hide(); | 76 | hide(); |
77 | } | 77 | } |
78 | 78 | ||
79 | void MailApplet::startup() { | 79 | void MailApplet::startup() { |
80 | Settings *settings = new Settings(); | 80 | Settings *settings = new Settings(); |
81 | QList<Account> ma = settings->getAccounts(); | 81 | QList<Account> ma = settings->getAccounts(); |
82 | m_statusMail = new StatusMail( ma ); | 82 | m_statusMail = new StatusMail( ma ); |
83 | delete settings; | 83 | delete settings; |
84 | 84 | ||
85 | m_intervalMs = m_config->readNumEntry( "CheckEvery", 5 ) * 60000; | 85 | m_intervalMs = m_config->readNumEntry( "CheckEvery", 5 ) * 60000; |
86 | m_intervalTimer = new QTimer(); | 86 | m_intervalTimer = new QTimer(); |
87 | m_intervalTimer->start( m_intervalMs ); | 87 | m_intervalTimer->start( m_intervalMs ); |
88 | connect( m_intervalTimer, SIGNAL( timeout() ), this, SLOT( slotCheck() ) ); | 88 | connect( m_intervalTimer, SIGNAL( timeout() ), this, SLOT( slotCheck() ) ); |
89 | } | 89 | } |
90 | 90 | ||
91 | void MailApplet::slotCheck() { | 91 | void MailApplet::slotCheck() { |
92 | // Check wether the check interval has been changed. | 92 | // Check wether the check interval has been changed. |
93 | int newIntervalMs = m_config->readNumEntry( "CheckEvery", 5 ) * 60000; | 93 | int newIntervalMs = m_config->readNumEntry( "CheckEvery", 5 ) * 60000; |
94 | if ( newIntervalMs != m_intervalMs ) { | 94 | if ( newIntervalMs != m_intervalMs ) { |
95 | m_intervalTimer->changeInterval( newIntervalMs ); | 95 | m_intervalTimer->changeInterval( newIntervalMs ); |
96 | m_intervalMs = newIntervalMs; | 96 | m_intervalMs = newIntervalMs; |
97 | } | 97 | } |
98 | 98 | ||
99 | if (m_statusMail == 0) { | 99 | if (m_statusMail == 0) { |
100 | return; | 100 | return; |
101 | } | 101 | } |
102 | 102 | ||
103 | folderStat stat; | 103 | folderStat stat; |
104 | m_statusMail->check_current_stat( stat ); | 104 | m_statusMail->check_current_stat( stat ); |
105 | int newMailsOld = m_newMails; | 105 | int newMailsOld = m_newMails; |
106 | m_newMails = stat.message_unseen; | 106 | m_newMails = stat.message_unseen; |
107 | odebug << QString( "test %1" ).arg( m_newMails ) << oendl; | 107 | odebug << QString( "test %1" ).arg( m_newMails ) << oendl; |
108 | if ( m_newMails > 0 && newMailsOld != m_newMails ) { | 108 | if ( m_newMails > 0 && newMailsOld != m_newMails ) { |
109 | ODevice *device = ODevice::inst(); | 109 | ODevice *device = ODevice::inst(); |
110 | if ( isHidden() ) | 110 | if ( isHidden() ) |
111 | show(); | 111 | show(); |
112 | if ( m_config->readBoolEntry( "BlinkLed", true ) ) { | 112 | if ( m_config->readBoolEntry( "BlinkLed", true ) ) { |
113 | if ( !device->ledList().isEmpty() ) { | 113 | if ( !device->ledList().isEmpty() ) { |
114 | OLed led = ( device->ledList().contains( Led_Mail ) ) ? Led_Mail : device->ledList()[0]; | 114 | OLed led = ( device->ledList().contains( Led_Mail ) ) ? Led_Mail : device->ledList()[0]; |
115 | device->setLedState( led, device->ledStateList( led ).contains( Led_BlinkSlow ) ? Led_BlinkSlow : Led_On ); | 115 | device->setLedState( led, device->ledStateList( led ).contains( Led_BlinkSlow ) ? Led_BlinkSlow : Led_On ); |
116 | } | 116 | } |
117 | } | 117 | } |
118 | if ( m_config->readBoolEntry( "PlaySound", false ) ) | 118 | if ( m_config->readBoolEntry( "PlaySound", false ) ) |
119 | device->playAlarmSound(); | 119 | device->playAlarmSound(); |
120 | 120 | ||
121 | Config cfg( "mail" ); | 121 | Config cfg( "mail" ); |
122 | cfg.setGroup( "Status" ); | 122 | cfg.setGroup( "Status" ); |
123 | cfg.writeEntry( "newMails", m_newMails ); | 123 | cfg.writeEntry( "newMails", m_newMails ); |
124 | QCopEnvelope env( "QPE/Pim", "newMails(int)" ); | 124 | QCopEnvelope env( "QPE/Pim", "newMails(int)" ); |
125 | env << m_newMails; | 125 | env << m_newMails; |
126 | repaint( true ); | 126 | repaint( true ); |
127 | 127 | ||
128 | } else { | 128 | } else { |
129 | ODevice *device = ODevice::inst(); | 129 | ODevice *device = ODevice::inst(); |
130 | if ( !isHidden() ) | 130 | if ( !isHidden() ) |
131 | hide(); | 131 | hide(); |
132 | if ( !device->ledList().isEmpty() ) { | 132 | if ( !device->ledList().isEmpty() ) { |
133 | OLed led = ( device->ledList().contains( Led_Mail ) ) ? Led_Mail : device->ledList()[0]; | 133 | OLed led = ( device->ledList().contains( Led_Mail ) ) ? Led_Mail : device->ledList()[0]; |
134 | device->setLedState( led, Led_Off ); | 134 | device->setLedState( led, Led_Off ); |
135 | } | 135 | } |
136 | 136 | ||
137 | if ( newMailsOld != m_newMails ) { | 137 | if ( newMailsOld != m_newMails ) { |
138 | Config cfg( "mail" ); | 138 | Config cfg( "mail" ); |
139 | cfg.setGroup( "Status" ); | 139 | cfg.setGroup( "Status" ); |
140 | cfg.writeEntry( "newMails", m_newMails ); | 140 | cfg.writeEntry( "newMails", m_newMails ); |
141 | QCopEnvelope env( "QPE/Pim", "newMails(int)" ); | 141 | QCopEnvelope env( "QPE/Pim", "newMails(int)" ); |
142 | env << m_newMails; | 142 | env << m_newMails; |
143 | } | 143 | } |
144 | } | 144 | } |
145 | } | 145 | } |
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp index a574ea1..7267bcb 100644 --- a/noncore/net/mail/viewmail.cpp +++ b/noncore/net/mail/viewmail.cpp | |||
@@ -1,477 +1,480 @@ | |||
1 | #include "composemail.h" | 1 | #include "composemail.h" |
2 | #include "viewmail.h" | 2 | #include "viewmail.h" |
3 | 3 | ||
4 | /* OPIE */ | 4 | /* OPIE */ |
5 | #include <libmailwrapper/settings.h> | 5 | #include <libmailwrapper/settings.h> |
6 | #include <libmailwrapper/abstractmail.h> | 6 | #include <libmailwrapper/abstractmail.h> |
7 | #include <libmailwrapper/mailtypes.h> | 7 | #include <libmailwrapper/mailtypes.h> |
8 | 8 | ||
9 | #include <opie2/odebug.h> | ||
9 | #include <opie2/ofiledialog.h> | 10 | #include <opie2/ofiledialog.h> |
10 | #include <qpe/config.h> | 11 | #include <qpe/config.h> |
11 | #include <qpe/qpeapplication.h> | 12 | #include <qpe/qpeapplication.h> |
12 | 13 | ||
13 | /* QT */ | 14 | /* QT */ |
14 | #include <qtextbrowser.h> | 15 | #include <qtextbrowser.h> |
15 | #include <qmessagebox.h> | 16 | #include <qmessagebox.h> |
16 | #include <qtextstream.h> | 17 | #include <qtextstream.h> |
17 | #include <qaction.h> | 18 | #include <qaction.h> |
18 | #include <qpopupmenu.h> | 19 | #include <qpopupmenu.h> |
19 | #include <qfile.h> | 20 | #include <qfile.h> |
20 | 21 | ||
21 | using namespace Opie::Ui; | 22 | using namespace Opie::Ui; |
23 | using namespace Opie::Core; | ||
24 | |||
22 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, | 25 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, |
23 | const QString&fsize,int num,const QValueList<int>&path) | 26 | const QString&fsize,int num,const QValueList<int>&path) |
24 | : QListViewItem(parent,after),_partNum(num) | 27 | : QListViewItem(parent,after),_partNum(num) |
25 | { | 28 | { |
26 | _path=path; | 29 | _path=path; |
27 | setText(0, mime); | 30 | setText(0, mime); |
28 | setText(1, desc); | 31 | setText(1, desc); |
29 | setText(2, file); | 32 | setText(2, file); |
30 | setText(3, fsize); | 33 | setText(3, fsize); |
31 | } | 34 | } |
32 | 35 | ||
33 | AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, | 36 | AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, |
34 | const QString&fsize,int num,const QValueList<int>&path) | 37 | const QString&fsize,int num,const QValueList<int>&path) |
35 | : QListViewItem(parent,after),_partNum(num) | 38 | : QListViewItem(parent,after),_partNum(num) |
36 | { | 39 | { |
37 | _path=path; | 40 | _path=path; |
38 | setText(0, mime); | 41 | setText(0, mime); |
39 | setText(1, desc); | 42 | setText(1, desc); |
40 | setText(2, file); | 43 | setText(2, file); |
41 | setText(3, fsize); | 44 | setText(3, fsize); |
42 | } | 45 | } |
43 | 46 | ||
44 | bool AttachItem::isParentof(const QValueList<int>&path) | 47 | bool AttachItem::isParentof(const QValueList<int>&path) |
45 | { | 48 | { |
46 | /* if not set, then no parent */ | 49 | /* if not set, then no parent */ |
47 | if (path.count()==0||_path.count()==0) return false; | 50 | if (path.count()==0||_path.count()==0) return false; |
48 | /* the parent must have one digit less then a child */ | 51 | /* the parent must have one digit less then a child */ |
49 | if (path.count()!=_path.count()+1) return false; | 52 | if (path.count()!=_path.count()+1) return false; |
50 | for (unsigned int i=0; i < _path.count();++i) | 53 | for (unsigned int i=0; i < _path.count();++i) |
51 | { | 54 | { |
52 | if (_path[i]!=path[i]) return false; | 55 | if (_path[i]!=path[i]) return false; |
53 | } | 56 | } |
54 | return true; | 57 | return true; |
55 | } | 58 | } |
56 | 59 | ||
57 | AttachItem* ViewMail::searchParent(const QValueList<int>&path) | 60 | AttachItem* ViewMail::searchParent(const QValueList<int>&path) |
58 | { | 61 | { |
59 | QListViewItemIterator it( attachments ); | 62 | QListViewItemIterator it( attachments ); |
60 | for ( ; it.current(); ++it ) | 63 | for ( ; it.current(); ++it ) |
61 | { | 64 | { |
62 | AttachItem*ati = (AttachItem*)it.current(); | 65 | AttachItem*ati = (AttachItem*)it.current(); |
63 | if (ati->isParentof(path)) return ati; | 66 | if (ati->isParentof(path)) return ati; |
64 | } | 67 | } |
65 | return 0; | 68 | return 0; |
66 | } | 69 | } |
67 | 70 | ||
68 | AttachItem* ViewMail::lastChild(AttachItem*parent) | 71 | AttachItem* ViewMail::lastChild(AttachItem*parent) |
69 | { | 72 | { |
70 | if (!parent) return 0; | 73 | if (!parent) return 0; |
71 | AttachItem* item = (AttachItem*)parent->firstChild(); | 74 | AttachItem* item = (AttachItem*)parent->firstChild(); |
72 | if (!item) return item; | 75 | if (!item) return item; |
73 | AttachItem*temp=0; | 76 | AttachItem*temp=0; |
74 | while( (temp=(AttachItem*)item->nextSibling())) | 77 | while( (temp=(AttachItem*)item->nextSibling())) |
75 | { | 78 | { |
76 | item = temp; | 79 | item = temp; |
77 | } | 80 | } |
78 | return item; | 81 | return item; |
79 | } | 82 | } |
80 | 83 | ||
81 | void ViewMail::setBody(const RecBodyP&body ) | 84 | void ViewMail::setBody(const RecBodyP&body ) |
82 | { | 85 | { |
83 | 86 | ||
84 | m_body = body; | 87 | m_body = body; |
85 | m_mail[2] = body->Bodytext(); | 88 | m_mail[2] = body->Bodytext(); |
86 | attachbutton->setEnabled(body->Parts().count()>0); | 89 | attachbutton->setEnabled(body->Parts().count()>0); |
87 | attachments->setEnabled(body->Parts().count()>0); | 90 | attachments->setEnabled(body->Parts().count()>0); |
88 | if (body->Parts().count()==0) | 91 | if (body->Parts().count()==0) |
89 | { | 92 | { |
90 | return; | 93 | return; |
91 | } | 94 | } |
92 | AttachItem * curItem=0; | 95 | AttachItem * curItem=0; |
93 | AttachItem * parentItem = 0; | 96 | AttachItem * parentItem = 0; |
94 | QString type=body->Description()->Type()+"/"+body->Description()->Subtype(); | 97 | QString type=body->Description()->Type()+"/"+body->Description()->Subtype(); |
95 | QString desc,fsize; | 98 | QString desc,fsize; |
96 | double s = body->Description()->Size(); | 99 | double s = body->Description()->Size(); |
97 | int w; | 100 | int w; |
98 | w=0; | 101 | w=0; |
99 | 102 | ||
100 | while (s>1024) | 103 | while (s>1024) |
101 | { | 104 | { |
102 | s/=1024; | 105 | s/=1024; |
103 | ++w; | 106 | ++w; |
104 | if (w>=2) break; | 107 | if (w>=2) break; |
105 | } | 108 | } |
106 | 109 | ||
107 | QString q=""; | 110 | QString q=""; |
108 | switch(w) | 111 | switch(w) |
109 | { | 112 | { |
110 | case 1: | 113 | case 1: |
111 | q="k"; | 114 | q="k"; |
112 | break; | 115 | break; |
113 | case 2: | 116 | case 2: |
114 | q="M"; | 117 | q="M"; |
115 | break; | 118 | break; |
116 | default: | 119 | default: |
117 | break; | 120 | break; |
118 | } | 121 | } |
119 | 122 | ||
120 | { | 123 | { |
121 | /* I did not found a method to make a CONTENT reset on a QTextStream | 124 | /* I did not found a method to make a CONTENT reset on a QTextStream |
122 | so I use this construct that the stream will re-constructed in each | 125 | so I use this construct that the stream will re-constructed in each |
123 | loop. To let it work, the textstream is packed into a own area of | 126 | loop. To let it work, the textstream is packed into a own area of |
124 | code is it will be destructed after finishing its small job. | 127 | code is it will be destructed after finishing its small job. |
125 | */ | 128 | */ |
126 | QTextOStream o(&fsize); | 129 | QTextOStream o(&fsize); |
127 | if (w>0) o.precision(2); else o.precision(0); | 130 | if (w>0) o.precision(2); else o.precision(0); |
128 | o.setf(QTextStream::fixed); | 131 | o.setf(QTextStream::fixed); |
129 | o << s << " " << q << "Byte"; | 132 | o << s << " " << q << "Byte"; |
130 | } | 133 | } |
131 | 134 | ||
132 | curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body->Description()->Positionlist()); | 135 | curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body->Description()->Positionlist()); |
133 | QString filename = ""; | 136 | QString filename = ""; |
134 | 137 | ||
135 | for (unsigned int i = 0; i < body->Parts().count();++i) | 138 | for (unsigned int i = 0; i < body->Parts().count();++i) |
136 | { | 139 | { |
137 | filename = ""; | 140 | filename = ""; |
138 | type = body->Parts()[i]->Type()+"/"+body->Parts()[i]->Subtype(); | 141 | type = body->Parts()[i]->Type()+"/"+body->Parts()[i]->Subtype(); |
139 | part_plist_t::ConstIterator it = body->Parts()[i]->Parameters().begin(); | 142 | part_plist_t::ConstIterator it = body->Parts()[i]->Parameters().begin(); |
140 | for (;it!=body->Parts()[i]->Parameters().end();++it) | 143 | for (;it!=body->Parts()[i]->Parameters().end();++it) |
141 | { | 144 | { |
142 | odebug << it.key() << oendl; | 145 | odebug << it.key() << oendl; |
143 | if (it.key().lower()=="name") | 146 | if (it.key().lower()=="name") |
144 | { | 147 | { |
145 | filename=it.data(); | 148 | filename=it.data(); |
146 | } | 149 | } |
147 | } | 150 | } |
148 | s = body->Parts()[i]->Size(); | 151 | s = body->Parts()[i]->Size(); |
149 | w = 0; | 152 | w = 0; |
150 | while (s>1024) | 153 | while (s>1024) |
151 | { | 154 | { |
152 | s/=1024; | 155 | s/=1024; |
153 | ++w; | 156 | ++w; |
154 | if (w>=2) break; | 157 | if (w>=2) break; |
155 | } | 158 | } |
156 | switch(w) | 159 | switch(w) |
157 | { | 160 | { |
158 | case 1: | 161 | case 1: |
159 | q="k"; | 162 | q="k"; |
160 | break; | 163 | break; |
161 | case 2: | 164 | case 2: |
162 | q="M"; | 165 | q="M"; |
163 | break; | 166 | break; |
164 | default: | 167 | default: |
165 | q=""; | 168 | q=""; |
166 | break; | 169 | break; |
167 | } | 170 | } |
168 | QTextOStream o(&fsize); | 171 | QTextOStream o(&fsize); |
169 | if (w>0) o.precision(2); else o.precision(0); | 172 | if (w>0) o.precision(2); else o.precision(0); |
170 | o.setf(QTextStream::fixed); | 173 | o.setf(QTextStream::fixed); |
171 | o << s << " " << q << "Byte"; | 174 | o << s << " " << q << "Byte"; |
172 | desc = body->Parts()[i]->Description(); | 175 | desc = body->Parts()[i]->Description(); |
173 | parentItem = searchParent(body->Parts()[i]->Positionlist()); | 176 | parentItem = searchParent(body->Parts()[i]->Positionlist()); |
174 | if (parentItem) | 177 | if (parentItem) |
175 | { | 178 | { |
176 | AttachItem*temp = lastChild(parentItem); | 179 | AttachItem*temp = lastChild(parentItem); |
177 | if (temp) curItem = temp; | 180 | if (temp) curItem = temp; |
178 | curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); | 181 | curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); |
179 | attachments->setRootIsDecorated(true); | 182 | attachments->setRootIsDecorated(true); |
180 | curItem = parentItem; | 183 | curItem = parentItem; |
181 | } | 184 | } |
182 | else | 185 | else |
183 | { | 186 | { |
184 | curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); | 187 | curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); |
185 | } | 188 | } |
186 | } | 189 | } |
187 | } | 190 | } |
188 | 191 | ||
189 | 192 | ||
190 | void ViewMail::slotShowHtml( bool state ) | 193 | void ViewMail::slotShowHtml( bool state ) |
191 | { | 194 | { |
192 | m_showHtml = state; | 195 | m_showHtml = state; |
193 | setText(); | 196 | setText(); |
194 | } | 197 | } |
195 | 198 | ||
196 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) | 199 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) |
197 | { | 200 | { |
198 | if (!item ) | 201 | if (!item ) |
199 | return; | 202 | return; |
200 | 203 | ||
201 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) | 204 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) |
202 | { | 205 | { |
203 | setText(); | 206 | setText(); |
204 | return; | 207 | return; |
205 | } | 208 | } |
206 | QPopupMenu *menu = new QPopupMenu(); | 209 | QPopupMenu *menu = new QPopupMenu(); |
207 | int ret=0; | 210 | int ret=0; |
208 | 211 | ||
209 | if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) | 212 | if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) |
210 | { | 213 | { |
211 | menu->insertItem( tr( "Show Text" ), 1 ); | 214 | menu->insertItem( tr( "Show Text" ), 1 ); |
212 | } | 215 | } |
213 | menu->insertItem( tr( "Save Attachment" ), 0 ); | 216 | menu->insertItem( tr( "Save Attachment" ), 0 ); |
214 | menu->insertSeparator(1); | 217 | menu->insertSeparator(1); |
215 | 218 | ||
216 | ret = menu->exec( point, 0 ); | 219 | ret = menu->exec( point, 0 ); |
217 | 220 | ||
218 | switch(ret) | 221 | switch(ret) |
219 | { | 222 | { |
220 | case 0: | 223 | case 0: |
221 | { | 224 | { |
222 | MimeTypes types; | 225 | MimeTypes types; |
223 | types.insert( "all", "*" ); | 226 | types.insert( "all", "*" ); |
224 | QString str = OFileDialog::getSaveFileName( 1, | 227 | QString str = OFileDialog::getSaveFileName( 1, |
225 | "/", item->text( 2 ) , types, 0 ); | 228 | "/", item->text( 2 ) , types, 0 ); |
226 | 229 | ||
227 | if( !str.isEmpty() ) | 230 | if( !str.isEmpty() ) |
228 | { | 231 | { |
229 | encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); | 232 | encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); |
230 | if (content) | 233 | if (content) |
231 | { | 234 | { |
232 | QFile output(str); | 235 | QFile output(str); |
233 | output.open(IO_WriteOnly); | 236 | output.open(IO_WriteOnly); |
234 | output.writeBlock(content->Content(),content->Length()); | 237 | output.writeBlock(content->Content(),content->Length()); |
235 | output.close(); | 238 | output.close(); |
236 | delete content; | 239 | delete content; |
237 | } | 240 | } |
238 | } | 241 | } |
239 | } | 242 | } |
240 | break ; | 243 | break ; |
241 | 244 | ||
242 | case 1: | 245 | case 1: |
243 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) | 246 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) |
244 | { | 247 | { |
245 | setText(); | 248 | setText(); |
246 | } | 249 | } |
247 | else | 250 | else |
248 | { | 251 | { |
249 | if ( m_recMail->Wrapper() != 0l ) | 252 | if ( m_recMail->Wrapper() != 0l ) |
250 | { // make sure that there is a wrapper , even after delete or simular actions | 253 | { // make sure that there is a wrapper , even after delete or simular actions |
251 | browser->setText( m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); | 254 | browser->setText( m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); |
252 | } | 255 | } |
253 | } | 256 | } |
254 | break; | 257 | break; |
255 | } | 258 | } |
256 | delete menu; | 259 | delete menu; |
257 | } | 260 | } |
258 | 261 | ||
259 | 262 | ||
260 | void ViewMail::setMail(const RecMailP&mail ) | 263 | void ViewMail::setMail(const RecMailP&mail ) |
261 | { | 264 | { |
262 | 265 | ||
263 | m_recMail = mail; | 266 | m_recMail = mail; |
264 | 267 | ||
265 | m_mail[0] = mail->getFrom(); | 268 | m_mail[0] = mail->getFrom(); |
266 | m_mail[1] = mail->getSubject(); | 269 | m_mail[1] = mail->getSubject(); |
267 | m_mail[3] = mail->getDate(); | 270 | m_mail[3] = mail->getDate(); |
268 | m_mail[4] = mail->Msgid(); | 271 | m_mail[4] = mail->Msgid(); |
269 | 272 | ||
270 | m_mail2[0] = mail->To(); | 273 | m_mail2[0] = mail->To(); |
271 | m_mail2[1] = mail->CC(); | 274 | m_mail2[1] = mail->CC(); |
272 | m_mail2[2] = mail->Bcc(); | 275 | m_mail2[2] = mail->Bcc(); |
273 | 276 | ||
274 | setText(); | 277 | setText(); |
275 | } | 278 | } |
276 | 279 | ||
277 | 280 | ||
278 | 281 | ||
279 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) | 282 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) |
280 | : ViewMailBase(parent, name, fl), _inLoop(false) | 283 | : ViewMailBase(parent, name, fl), _inLoop(false) |
281 | { | 284 | { |
282 | m_gotBody = false; | 285 | m_gotBody = false; |
283 | deleted = false; | 286 | deleted = false; |
284 | 287 | ||
285 | connect( reply, SIGNAL(activated()), SLOT(slotReply())); | 288 | connect( reply, SIGNAL(activated()), SLOT(slotReply())); |
286 | connect( forward, SIGNAL(activated()), SLOT(slotForward())); | 289 | connect( forward, SIGNAL(activated()), SLOT(slotForward())); |
287 | connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); | 290 | connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); |
288 | connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); | 291 | connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); |
289 | 292 | ||
290 | attachments->setEnabled(m_gotBody); | 293 | attachments->setEnabled(m_gotBody); |
291 | connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); | 294 | connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); |
292 | 295 | ||
293 | readConfig(); | 296 | readConfig(); |
294 | attachments->setSorting(-1); | 297 | attachments->setSorting(-1); |
295 | } | 298 | } |
296 | 299 | ||
297 | void ViewMail::readConfig() | 300 | void ViewMail::readConfig() |
298 | { | 301 | { |
299 | Config cfg( "mail" ); | 302 | Config cfg( "mail" ); |
300 | cfg.setGroup( "Settings" ); | 303 | cfg.setGroup( "Settings" ); |
301 | m_showHtml = cfg.readBoolEntry( "showHtml", false ); | 304 | m_showHtml = cfg.readBoolEntry( "showHtml", false ); |
302 | showHtml->setOn( m_showHtml ); | 305 | showHtml->setOn( m_showHtml ); |
303 | } | 306 | } |
304 | 307 | ||
305 | void ViewMail::setText() | 308 | void ViewMail::setText() |
306 | { | 309 | { |
307 | 310 | ||
308 | QString toString; | 311 | QString toString; |
309 | QString ccString; | 312 | QString ccString; |
310 | QString bccString; | 313 | QString bccString; |
311 | 314 | ||
312 | for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) | 315 | for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) |
313 | { | 316 | { |
314 | toString += (*it); | 317 | toString += (*it); |
315 | } | 318 | } |
316 | for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) | 319 | for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) |
317 | { | 320 | { |
318 | ccString += (*it); | 321 | ccString += (*it); |
319 | } | 322 | } |
320 | for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) | 323 | for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) |
321 | { | 324 | { |
322 | bccString += (*it); | 325 | bccString += (*it); |
323 | } | 326 | } |
324 | 327 | ||
325 | setCaption( caption().arg( m_mail[0] ) ); | 328 | setCaption( caption().arg( m_mail[0] ) ); |
326 | 329 | ||
327 | m_mailHtml = "<html><body>" | 330 | m_mailHtml = "<html><body>" |
328 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" | 331 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" |
329 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" | 332 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" |
330 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" | 333 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" |
331 | "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" | 334 | "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" |
332 | "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + | 335 | "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + |
333 | tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" | 336 | tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" |
334 | "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + | 337 | "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + |
335 | "</td></tr></table><font face=fixed>"; | 338 | "</td></tr></table><font face=fixed>"; |
336 | 339 | ||
337 | if ( !m_showHtml ) | 340 | if ( !m_showHtml ) |
338 | { | 341 | { |
339 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); | 342 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); |
340 | } | 343 | } |
341 | else | 344 | else |
342 | { | 345 | { |
343 | browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); | 346 | browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); |
344 | } | 347 | } |
345 | // remove later in favor of a real handling | 348 | // remove later in favor of a real handling |
346 | m_gotBody = true; | 349 | m_gotBody = true; |
347 | } | 350 | } |
348 | 351 | ||
349 | 352 | ||
350 | ViewMail::~ViewMail() | 353 | ViewMail::~ViewMail() |
351 | { | 354 | { |
352 | m_recMail->Wrapper()->cleanMimeCache(); | 355 | m_recMail->Wrapper()->cleanMimeCache(); |
353 | hide(); | 356 | hide(); |
354 | } | 357 | } |
355 | 358 | ||
356 | void ViewMail::hide() | 359 | void ViewMail::hide() |
357 | { | 360 | { |
358 | QWidget::hide(); | 361 | QWidget::hide(); |
359 | 362 | ||
360 | if (_inLoop) | 363 | if (_inLoop) |
361 | { | 364 | { |
362 | _inLoop = false; | 365 | _inLoop = false; |
363 | qApp->exit_loop(); | 366 | qApp->exit_loop(); |
364 | 367 | ||
365 | } | 368 | } |
366 | 369 | ||
367 | } | 370 | } |
368 | 371 | ||
369 | void ViewMail::exec() | 372 | void ViewMail::exec() |
370 | { | 373 | { |
371 | show(); | 374 | show(); |
372 | 375 | ||
373 | if (!_inLoop) | 376 | if (!_inLoop) |
374 | { | 377 | { |
375 | _inLoop = true; | 378 | _inLoop = true; |
376 | qApp->enter_loop(); | 379 | qApp->enter_loop(); |
377 | } | 380 | } |
378 | 381 | ||
379 | } | 382 | } |
380 | 383 | ||
381 | QString ViewMail::deHtml(const QString &string) | 384 | QString ViewMail::deHtml(const QString &string) |
382 | { | 385 | { |
383 | QString string_ = string; | 386 | QString string_ = string; |
384 | string_.replace(QRegExp("&"), "&"); | 387 | string_.replace(QRegExp("&"), "&"); |
385 | string_.replace(QRegExp("<"), "<"); | 388 | string_.replace(QRegExp("<"), "<"); |
386 | string_.replace(QRegExp(">"), ">"); | 389 | string_.replace(QRegExp(">"), ">"); |
387 | string_.replace(QRegExp("\\n"), "<br>"); | 390 | string_.replace(QRegExp("\\n"), "<br>"); |
388 | return string_; | 391 | return string_; |
389 | } | 392 | } |
390 | 393 | ||
391 | void ViewMail::slotReply() | 394 | void ViewMail::slotReply() |
392 | { | 395 | { |
393 | if (!m_gotBody) | 396 | if (!m_gotBody) |
394 | { | 397 | { |
395 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); | 398 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); |
396 | return; | 399 | return; |
397 | } | 400 | } |
398 | 401 | ||
399 | QString rtext; | 402 | QString rtext; |
400 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose | 403 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose |
401 | .arg( m_mail[0] ) | 404 | .arg( m_mail[0] ) |
402 | .arg( m_mail[3] ); | 405 | .arg( m_mail[3] ); |
403 | 406 | ||
404 | QString text = m_mail[2]; | 407 | QString text = m_mail[2]; |
405 | QStringList lines = QStringList::split(QRegExp("\\n"), text); | 408 | QStringList lines = QStringList::split(QRegExp("\\n"), text); |
406 | QStringList::Iterator it; | 409 | QStringList::Iterator it; |
407 | for (it = lines.begin(); it != lines.end(); it++) | 410 | for (it = lines.begin(); it != lines.end(); it++) |
408 | { | 411 | { |
409 | rtext += "> " + *it + "\n"; | 412 | rtext += "> " + *it + "\n"; |
410 | } | 413 | } |
411 | rtext += "\n"; | 414 | rtext += "\n"; |
412 | 415 | ||
413 | QString prefix; | 416 | QString prefix; |
414 | if ( m_mail[1].find(QRegExp("^Re: .*$")) != -1) prefix = ""; | 417 | if ( m_mail[1].find(QRegExp("^Re: .*$")) != -1) prefix = ""; |
415 | else prefix = "Re: "; // no i18n on purpose | 418 | else prefix = "Re: "; // no i18n on purpose |
416 | 419 | ||
417 | Settings *settings = new Settings(); | 420 | Settings *settings = new Settings(); |
418 | ComposeMail composer( settings ,this, 0, true); | 421 | ComposeMail composer( settings ,this, 0, true); |
419 | if (m_recMail->Replyto().isEmpty()) { | 422 | if (m_recMail->Replyto().isEmpty()) { |
420 | composer.setTo( m_recMail->getFrom()); | 423 | composer.setTo( m_recMail->getFrom()); |
421 | } else { | 424 | } else { |
422 | composer.setTo( m_recMail->Replyto()); | 425 | composer.setTo( m_recMail->Replyto()); |
423 | } | 426 | } |
424 | composer.setSubject( prefix + m_mail[1] ); | 427 | composer.setSubject( prefix + m_mail[1] ); |
425 | composer.setMessage( rtext ); | 428 | composer.setMessage( rtext ); |
426 | composer.setInReplyTo(m_recMail->Msgid()); | 429 | composer.setInReplyTo(m_recMail->Msgid()); |
427 | 430 | ||
428 | if ( QDialog::Accepted == QPEApplication::execDialog( &composer ) ) | 431 | if ( QDialog::Accepted == QPEApplication::execDialog( &composer ) ) |
429 | { | 432 | { |
430 | m_recMail->Wrapper()->answeredMail(m_recMail); | 433 | m_recMail->Wrapper()->answeredMail(m_recMail); |
431 | } | 434 | } |
432 | } | 435 | } |
433 | 436 | ||
434 | void ViewMail::slotForward() | 437 | void ViewMail::slotForward() |
435 | { | 438 | { |
436 | if (!m_gotBody) | 439 | if (!m_gotBody) |
437 | { | 440 | { |
438 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); | 441 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); |
439 | return; | 442 | return; |
440 | } | 443 | } |
441 | 444 | ||
442 | QString ftext; | 445 | QString ftext; |
443 | ftext += QString("\n----- Forwarded message from %1 -----\n\n") | 446 | ftext += QString("\n----- Forwarded message from %1 -----\n\n") |
444 | .arg( m_mail[0] ); | 447 | .arg( m_mail[0] ); |
445 | if (!m_mail[3].isNull()) | 448 | if (!m_mail[3].isNull()) |
446 | ftext += QString("Date: %1\n") | 449 | ftext += QString("Date: %1\n") |
447 | .arg( m_mail[3] ); | 450 | .arg( m_mail[3] ); |
448 | if (!m_mail[0].isNull()) | 451 | if (!m_mail[0].isNull()) |
449 | ftext += QString("From: %1\n") | 452 | ftext += QString("From: %1\n") |
450 | .arg( m_mail[0] ); | 453 | .arg( m_mail[0] ); |
451 | if (!m_mail[1].isNull()) | 454 | if (!m_mail[1].isNull()) |
452 | ftext += QString("Subject: %1\n") | 455 | ftext += QString("Subject: %1\n") |
453 | .arg( m_mail[1] ); | 456 | .arg( m_mail[1] ); |
454 | 457 | ||
455 | ftext += QString("\n%1\n") | 458 | ftext += QString("\n%1\n") |
456 | .arg( m_mail[2]); | 459 | .arg( m_mail[2]); |
457 | 460 | ||
458 | ftext += QString("----- End forwarded message -----\n"); | 461 | ftext += QString("----- End forwarded message -----\n"); |
459 | 462 | ||
460 | Settings *settings = new Settings(); | 463 | Settings *settings = new Settings(); |
461 | ComposeMail composer( settings ,this, 0, true); | 464 | ComposeMail composer( settings ,this, 0, true); |
462 | composer.setSubject( "Fwd: " + m_mail[1] ); | 465 | composer.setSubject( "Fwd: " + m_mail[1] ); |
463 | composer.setMessage( ftext ); | 466 | composer.setMessage( ftext ); |
464 | if ( QDialog::Accepted == QPEApplication::execDialog( &composer )) | 467 | if ( QDialog::Accepted == QPEApplication::execDialog( &composer )) |
465 | { | 468 | { |
466 | } | 469 | } |
467 | } | 470 | } |
468 | 471 | ||
469 | void ViewMail::slotDeleteMail( ) | 472 | void ViewMail::slotDeleteMail( ) |
470 | { | 473 | { |
471 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) | 474 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) |
472 | { | 475 | { |
473 | m_recMail->Wrapper()->deleteMail( m_recMail ); | 476 | m_recMail->Wrapper()->deleteMail( m_recMail ); |
474 | hide(); | 477 | hide(); |
475 | deleted = true; | 478 | deleted = true; |
476 | } | 479 | } |
477 | } | 480 | } |