author | alwin <alwin> | 2004-02-22 23:56:05 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-02-22 23:56:05 (UTC) |
commit | eba25a5ebeca30b7124e7fae80685dbd1c9a985d (patch) (unidiff) | |
tree | d62dd266e9b57f3eae34612f5d0fc4cf0b625c20 /noncore/net/mailit/emailclient.cpp | |
parent | 666a49773d06ac94c19996d763854725c2f7a578 (diff) | |
download | opie-eba25a5ebeca30b7124e7fae80685dbd1c9a985d.zip opie-eba25a5ebeca30b7124e7fae80685dbd1c9a985d.tar.gz opie-eba25a5ebeca30b7124e7fae80685dbd1c9a985d.tar.bz2 |
moved mailit into unsupported area 'cause replaced by opiemail3
Diffstat (limited to 'noncore/net/mailit/emailclient.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mailit/emailclient.cpp | 1042 |
1 files changed, 0 insertions, 1042 deletions
diff --git a/noncore/net/mailit/emailclient.cpp b/noncore/net/mailit/emailclient.cpp deleted file mode 100644 index 8359acf..0000000 --- a/noncore/net/mailit/emailclient.cpp +++ b/dev/null | |||
@@ -1,1042 +0,0 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qt Palmtop Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include <qapplication.h> | ||
21 | #include <qmessagebox.h> | ||
22 | #include <qvbox.h> | ||
23 | #include <qfile.h> | ||
24 | #include <qcheckbox.h> | ||
25 | #include <qmenubar.h> | ||
26 | #include <qaction.h> | ||
27 | #include <qwhatsthis.h> | ||
28 | #include <qpe/resource.h> | ||
29 | #include "emailclient.h" | ||
30 | #include "writemail.h" | ||
31 | |||
32 | QCollection::Item AccountList::newItem(QCollection::Item d) | ||
33 | { | ||
34 | return dupl( (MailAccount *) d); | ||
35 | } | ||
36 | |||
37 | MailAccount* AccountList::dupl(MailAccount *in) | ||
38 | { | ||
39 | ac = new MailAccount(*in); | ||
40 | return ac; | ||
41 | } | ||
42 | |||
43 | EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl ) | ||
44 | : QMainWindow( parent, name, fl ) | ||
45 | { | ||
46 | emailHandler = new EmailHandler(); | ||
47 | addressList = new AddressList(); | ||
48 | |||
49 | sending = FALSE; | ||
50 | receiving = FALSE; | ||
51 | previewingMail = FALSE; | ||
52 | mailIdCount = 1; | ||
53 | accountIdCount = 1; | ||
54 | allAccounts = FALSE; | ||
55 | |||
56 | init(); | ||
57 | |||
58 | |||
59 | |||
60 | connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) ); | ||
61 | |||
62 | connect(emailHandler, SIGNAL(smtpError(int,const QString &)), this, | ||
63 | SLOT(smtpError(int,const QString &)) ); | ||
64 | connect(emailHandler, SIGNAL(popError(int,const QString &)), this, | ||
65 | SLOT(popError(int,const QString &)) ); | ||
66 | |||
67 | connect(inboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(inboxItemSelected()) ); | ||
68 | connect(outboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(outboxItemSelected()) ); | ||
69 | |||
70 | connect(inboxView, SIGNAL(pressed(QListViewItem *)), this, SLOT(inboxItemPressed()) ); | ||
71 | connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemReleased()) ); | ||
72 | |||
73 | connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this, | ||
74 | SLOT(mailArrived(const Email &, bool)) ); | ||
75 | connect(emailHandler, SIGNAL(mailTransfered(int)), this, | ||
76 | SLOT(allMailArrived(int)) ); | ||
77 | |||
78 | mailconf = new Config("mailit"); | ||
79 | //In case Synchronize is not defined in settings.txt | ||
80 | |||
81 | readSettings(); | ||
82 | |||
83 | updateAccounts(); | ||
84 | |||
85 | lineShift = "\n"; | ||
86 | readMail(); | ||
87 | lineShift = "\r\n"; | ||
88 | |||
89 | mailboxView->setCurrentTab(0); //ensure that inbox has focus | ||
90 | |||
91 | /*channel = new QCopChannel( "QPE/Application/mailit", this ); | ||
92 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | ||
93 | this, SLOT(receive(const QCString&, const QByteArray&)) );*/ | ||
94 | |||
95 | } | ||
96 | |||
97 | |||
98 | EmailClient::~EmailClient() | ||
99 | { | ||
100 | //needs to be moved from destructor to closewindow event | ||
101 | saveMail(getPath(FALSE) + "inbox.txt", inboxView); | ||
102 | //does not currently work. Defining outbox in the same | ||
103 | //format as inbox is not a good solution as they have | ||
104 | //different properties | ||
105 | saveMail(getPath(FALSE) + "outbox.txt", outboxView); | ||
106 | saveSettings(); | ||
107 | |||
108 | mailconf->write(); | ||
109 | delete mailconf; | ||
110 | |||
111 | } | ||
112 | |||
113 | void EmailClient::init() | ||
114 | { | ||
115 | initStatusBar(this); | ||
116 | |||
117 | setToolBarsMovable(FALSE); | ||
118 | |||
119 | bar = new QToolBar(this); | ||
120 | QWhatsThis::add(bar,tr("Main operation toolbar")); | ||
121 | bar->setHorizontalStretchable( TRUE ); | ||
122 | |||
123 | mb = new QMenuBar( bar ); | ||
124 | |||
125 | QPopupMenu *mail = new QPopupMenu(mb); | ||
126 | mb->insertItem( tr( "&Mail" ), mail); | ||
127 | |||
128 | QPopupMenu *configure = new QPopupMenu(mb); | ||
129 | mb->insertItem( tr( "Accounts" ), configure); | ||
130 | |||
131 | selectAccountMenu = new QPopupMenu(mb); | ||
132 | editAccountMenu = new QPopupMenu(mb); | ||
133 | deleteAccountMenu = new QPopupMenu(mb); | ||
134 | |||
135 | mail->insertItem(tr("Get Mail in"), selectAccountMenu); | ||
136 | configure->insertItem(tr("Edit account"), editAccountMenu); | ||
137 | configure->insertItem(tr("Delete account"), deleteAccountMenu); | ||
138 | |||
139 | bar = new QToolBar(this); | ||
140 | |||
141 | getMailButton = new QToolButton(Resource::loadPixmap("mailit/getmail"),tr("getMail"),tr("select account"), this,SLOT(getAllNewMail()),bar); | ||
142 | QWhatsThis::add(getMailButton,tr("Click to download mail via all available accounts.\n Press and hold to select the desired account.")); | ||
143 | |||
144 | getMailButton->setPopup(selectAccountMenu); | ||
145 | |||
146 | sendMailButton = new QAction(tr("Send mail"), Resource::loadPixmap("mailit/sendqueue"), QString::null, 0, this, 0); | ||
147 | connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) ); | ||
148 | sendMailButton->addTo(bar); | ||
149 | sendMailButton->addTo(mail); | ||
150 | sendMailButton->setWhatsThis("Send mail queued in the outbox"); | ||
151 | |||
152 | composeButton = new QAction(tr("Compose"), Resource::loadPixmap("new"), QString::null, 0, this, 0); | ||
153 | connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) ); | ||
154 | composeButton->addTo(bar); | ||
155 | composeButton->addTo(mail); | ||
156 | composeButton->setWhatsThis("Compose a new mail"); | ||
157 | |||
158 | cancelButton = new QAction(tr("Cancel transfer"), Resource::loadPixmap("close"), QString::null, 0, this, 0); | ||
159 | connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) ); | ||
160 | cancelButton->addTo(mail); | ||
161 | cancelButton->addTo(bar); | ||
162 | cancelButton->setEnabled(FALSE); | ||
163 | cancelButton->setWhatsThis("Stop the currently active mail transfer"); | ||
164 | |||
165 | |||
166 | deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); | ||
167 | connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); | ||
168 | deleteButton->addTo(bar); | ||
169 | deleteButton->setWhatsThis("Remove the currently selected eMail(s)"); | ||
170 | |||
171 | mailboxView = new OTabWidget( this, "mailboxView" ); | ||
172 | |||
173 | QWidget* widget = new QWidget( mailboxView, "widget" ); | ||
174 | grid_2 = new QGridLayout( widget ); | ||
175 | // grid_2->setSpacing(6); | ||
176 | // grid_2->setMargin( 11 ); | ||
177 | |||
178 | inboxView = new QListView( widget, "inboxView" ); | ||
179 | inboxView->addColumn( tr( "From" ) ); | ||
180 | inboxView->addColumn( tr( "Subject" ) ); | ||
181 | inboxView->addColumn( tr( "Date" ) ); | ||
182 | inboxView->setMinimumSize( QSize( 0, 0 ) ); | ||
183 | inboxView->setAllColumnsShowFocus(TRUE); | ||
184 | QWhatsThis::add(inboxView,QWidget::tr("This is the inbox view.\n" | ||
185 | "It keeps the fetched mail which can be \n" | ||
186 | "viewed by double clicking the entry.\n" | ||
187 | "blue attachment icon shows whether this \n" | ||
188 | "mailhas attachments.\n")); | ||
189 | |||
190 | grid_2->addWidget( inboxView, 2, 0 ); | ||
191 | mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) ); | ||
192 | |||
193 | QWidget* widget_2 = new QWidget( mailboxView, "widget_2" ); | ||
194 | grid_3 = new QGridLayout( widget_2 ); | ||
195 | // grid_3->setSpacing(6); | ||
196 | // grid_3->setMargin( 11 ); | ||
197 | |||
198 | outboxView = new QListView( widget_2, "outboxView" ); | ||
199 | outboxView->addColumn( tr( "To" ) ); | ||
200 | outboxView->addColumn( tr( "Subject" ) ); | ||
201 | outboxView->setAllColumnsShowFocus(TRUE); | ||
202 | |||
203 | QWhatsThis::add(outboxView,QWidget::tr("This is the outbox view.\n" | ||
204 | "It keeps the queued mails to send which can be \n" | ||
205 | "reviewed by double clicking the entry.")); | ||
206 | grid_3->addWidget( outboxView, 0, 0 ); | ||
207 | mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) ); | ||
208 | |||
209 | setCentralWidget(mailboxView); | ||
210 | |||
211 | } | ||
212 | |||
213 | void EmailClient::initStatusBar(QWidget* parent) | ||
214 | { | ||
215 | statusBar = new QStatusBar(parent); | ||
216 | statusBar->setSizeGripEnabled(FALSE); | ||
217 | |||
218 | status1Label = new QLabel( tr("Idle"), statusBar); | ||
219 | status2Label = new QLabel("", statusBar); | ||
220 | connect(emailHandler, SIGNAL(updatePopStatus(const QString &)), | ||
221 | status2Label, SLOT(setText(const QString &)) ); | ||
222 | connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)), | ||
223 | status2Label, SLOT(setText(const QString &)) ); | ||
224 | |||
225 | progressBar = new QProgressBar(statusBar); | ||
226 | |||
227 | connect(emailHandler, SIGNAL(mailboxSize(int)), | ||
228 | this, SLOT(setTotalSize(int)) ); | ||
229 | connect(emailHandler, SIGNAL(currentMailSize(int)), | ||
230 | this, SLOT(setMailSize(int)) ); | ||
231 | connect(emailHandler, SIGNAL(downloadedSize(int)), | ||
232 | this, SLOT(setDownloadedSize(int)) ); | ||
233 | |||
234 | statusBar->addWidget(status1Label); | ||
235 | statusBar->addWidget(progressBar); | ||
236 | statusBar->addWidget(status2Label); | ||
237 | |||
238 | } | ||
239 | |||
240 | void EmailClient::compose() | ||
241 | { | ||
242 | emit composeRequested(); | ||
243 | } | ||
244 | |||
245 | void EmailClient::cancel() | ||
246 | { | ||
247 | emailHandler->cancel(); | ||
248 | } | ||
249 | |||
250 | AddressList* EmailClient::getAdrListRef() | ||
251 | { | ||
252 | return addressList; | ||
253 | } | ||
254 | |||
255 | //this needs to be rewritten to syncronize with outboxView | ||
256 | void EmailClient::enqueMail(const Email &mail) | ||
257 | { | ||
258 | if (accountList.count() == 0) { | ||
259 | QMessageBox::warning(qApp->activeWindow(), | ||
260 | tr("No account selected"), tr("You must create an account"), "OK\n"); | ||
261 | return; | ||
262 | } | ||
263 | |||
264 | if (accountList.count() > 0) { | ||
265 | currentAccount = accountList.first(); | ||
266 | qWarning("using account " + currentAccount->name); | ||
267 | } | ||
268 | |||
269 | Email addMail = mail; | ||
270 | addMail.from = currentAccount->name; | ||
271 | addMail.fromMail = currentAccount->emailAddress; | ||
272 | addMail.rawMail.prepend("From: \"" + addMail.from + "\" <" + addMail.fromMail + ">\n"); | ||
273 | item = new EmailListItem(outboxView, addMail, false); | ||
274 | |||
275 | mailboxView->setCurrentTab(1); | ||
276 | |||
277 | } | ||
278 | |||
279 | void EmailClient::sendQuedMail() | ||
280 | { | ||
281 | int count = 0; | ||
282 | |||
283 | if (accountList.count() == 0) { | ||
284 | QMessageBox::warning(qApp->activeWindow(), tr("No account selected"), tr("You must create an account"), "OK\n"); | ||
285 | return; | ||
286 | } | ||
287 | //traverse listview, find messages to send | ||
288 | if (! sending) { | ||
289 | item = (EmailListItem *) outboxView->firstChild(); | ||
290 | if (item != NULL) { | ||
291 | while (item != NULL) { | ||
292 | quedMessages.append(item->getMail()); | ||
293 | item = (EmailListItem *) item->nextSibling(); | ||
294 | count++; | ||
295 | } | ||
296 | setMailAccount(); | ||
297 | emailHandler->sendMail(&quedMessages); | ||
298 | sending = TRUE; | ||
299 | sendMailButton->setEnabled(FALSE); | ||
300 | cancelButton->setEnabled(TRUE); | ||
301 | } else { | ||
302 | qWarning("sendQuedMail(): no messages to send"); | ||
303 | } | ||
304 | } | ||
305 | } | ||
306 | |||
307 | void EmailClient::setMailAccount() | ||
308 | { | ||
309 | emailHandler->setAccount(*currentAccount); | ||
310 | } | ||
311 | |||
312 | void EmailClient::mailSent() | ||
313 | { | ||
314 | sending = FALSE; | ||
315 | sendMailButton->setEnabled(TRUE); | ||
316 | |||
317 | quedMessages.clear(); | ||
318 | outboxView->clear(); //should be moved to an sentBox | ||
319 | } | ||
320 | |||
321 | void EmailClient::getNewMail() { | ||
322 | |||
323 | if (accountList.count() == 0) { | ||
324 | QMessageBox::warning(qApp->activeWindow(),tr("No account selected"), | ||
325 | tr("You must create an account"), "OK\n"); | ||
326 | return; | ||
327 | } | ||
328 | |||
329 | setMailAccount(); | ||
330 | |||
331 | receiving = TRUE; | ||
332 | previewingMail = TRUE; | ||
333 | getMailButton->setEnabled(FALSE); | ||
334 | cancelButton->setEnabled(TRUE); | ||
335 | selectAccountMenu->setEnabled(FALSE); | ||
336 | |||
337 | status1Label->setText(currentAccount->accountName + " headers"); | ||
338 | progressBar->reset(); | ||
339 | |||
340 | //get any previous mails not downloaded and add to queue | ||
341 | /*mailDownloadList.clear(); | ||
342 | Email *mailPtr; | ||
343 | item = (EmailListItem *) inboxView->firstChild(); | ||
344 | while (item != NULL) { | ||
345 | mailPtr = item->getMail(); | ||
346 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { | ||
347 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); | ||
348 | } | ||
349 | item = (EmailListItem *) item->nextSibling(); | ||
350 | }*/ | ||
351 | |||
352 | emailHandler->getMailHeaders(); | ||
353 | |||
354 | } | ||
355 | |||
356 | void EmailClient::getAllNewMail() | ||
357 | { | ||
358 | allAccounts = TRUE; | ||
359 | currentAccount = accountList.first(); | ||
360 | getNewMail(); | ||
361 | } | ||
362 | |||
363 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) | ||
364 | { | ||
365 | Enclosure *ePtr; | ||
366 | Email newMail; | ||
367 | int thisMailId; | ||
368 | emailHandler->parse( mail.rawMail, lineShift, &newMail); | ||
369 | mailconf->setGroup(newMail.id); | ||
370 | |||
371 | if (fromDisk) | ||
372 | { | ||
373 | |||
374 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); | ||
375 | newMail.size = mailconf->readNumEntry("size"); | ||
376 | newMail.serverId = mailconf->readNumEntry("serverid"); | ||
377 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); | ||
378 | } | ||
379 | else | ||
380 | { //mail arrived from server | ||
381 | |||
382 | newMail.serverId = mail.serverId; | ||
383 | newMail.size = mail.size; | ||
384 | newMail.downloaded = mail.downloaded; | ||
385 | |||
386 | newMail.fromAccountId = emailHandler->getAccount()->id; | ||
387 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); | ||
388 | } | ||
389 | |||
390 | //add if read or not | ||
391 | newMail.read = mailconf->readBoolEntry("mailread"); | ||
392 | |||
393 | //check if new mail | ||
394 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { | ||
395 | thisMailId = mailIdCount; | ||
396 | mailIdCount++; | ||
397 | |||
398 | //set server count, so that if the user aborts, the new | ||
399 | //header is not reloaded | ||
400 | if ((currentAccount)&&(currentAccount->synchronize)) | ||
401 | currentAccount->lastServerMailCount++; | ||
402 | |||
403 | mailconf->writeEntry("internalmailid", thisMailId); | ||
404 | mailconf->writeEntry("downloaded", newMail.downloaded); | ||
405 | mailconf->writeEntry("size", (int) newMail.size); | ||
406 | mailconf->writeEntry("serverid", newMail.serverId); | ||
407 | |||
408 | //addressList->addContact(newMail.fromMail, newMail.from); | ||
409 | } | ||
410 | |||
411 | mailconf->writeEntry("downloaded", newMail.downloaded); | ||
412 | |||
413 | QString stringMailId; | ||
414 | stringMailId.setNum(thisMailId); | ||
415 | //see if any attatchments needs to be stored | ||
416 | |||
417 | for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { | ||
418 | QString stringId; | ||
419 | stringId.setNum(ePtr->id); | ||
420 | |||
421 | int id = mailconf->readNumEntry("enclosureid_" + stringId); | ||
422 | if (id != ePtr->id) { //new entry | ||
423 | mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); | ||
424 | mailconf->writeEntry("name_" + stringId, ePtr->originalName); | ||
425 | mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); | ||
426 | mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); | ||
427 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | ||
428 | mailconf->writeEntry("installed_" + stringId, FALSE); | ||
429 | |||
430 | ePtr->name = stringMailId + "_" + stringId; | ||
431 | ePtr->path = getPath(TRUE); | ||
432 | if (emailHandler->getEnclosure(ePtr)) { //file saved | ||
433 | ePtr->saved = TRUE; | ||
434 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | ||
435 | mailconf->writeEntry("filename_" + stringId, ePtr->name); | ||
436 | mailconf->writeEntry("path_" + stringId, ePtr->path); | ||
437 | } else { | ||
438 | ePtr->saved = FALSE; | ||
439 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | ||
440 | } | ||
441 | } else { | ||
442 | ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); | ||
443 | ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); | ||
444 | if (ePtr->saved) { | ||
445 | ePtr->name = mailconf->readEntry("filename_" + stringId); | ||
446 | ePtr->path = mailconf->readEntry("path_" + stringId); | ||
447 | } | ||
448 | } | ||
449 | } | ||
450 | |||
451 | bool found=false; | ||
452 | |||
453 | if (!fromDisk) | ||
454 | { | ||
455 | |||
456 | Email *mailPtr; | ||
457 | item = (EmailListItem *) inboxView->firstChild(); | ||
458 | while ((item != NULL)&&(!found)) | ||
459 | { | ||
460 | mailPtr = item->getMail(); | ||
461 | if (mailPtr->id == newMail.id) { | ||
462 | item->setMail(newMail); | ||
463 | emit mailUpdated(item->getMail()); | ||
464 | found = true; | ||
465 | } | ||
466 | item = (EmailListItem *) item->nextSibling(); | ||
467 | } | ||
468 | } | ||
469 | if ((!found)||(fromDisk)) { | ||
470 | item = new EmailListItem(inboxView, newMail, TRUE); | ||
471 | } | ||
472 | // if (item->getMail()->files.count()>0) | ||
473 | // { | ||
474 | // item->setPixmap(0, Resource::loadPixmap("mailit/attach")); | ||
475 | // } | ||
476 | /*if (!newMail.downloaded) | ||
477 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ | ||
478 | |||
479 | mailboxView->setCurrentTab(0); | ||
480 | |||
481 | } | ||
482 | |||
483 | void EmailClient::allMailArrived(int /*count*/) | ||
484 | { | ||
485 | // not previewing means all mailtransfer has been done | ||
486 | /*if (!previewingMail) {*/ | ||
487 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { | ||
488 | emit newCaption("Mailit - " + currentAccount->accountName); | ||
489 | getNewMail(); | ||
490 | return; | ||
491 | } else { | ||
492 | allAccounts = FALSE; | ||
493 | receiving = FALSE; | ||
494 | getMailButton->setEnabled(TRUE); | ||
495 | cancelButton->setEnabled(FALSE); | ||
496 | selectAccountMenu->setEnabled(TRUE); | ||
497 | status1Label->setText("Idle"); | ||
498 | |||
499 | progressBar->reset(); | ||
500 | return; | ||
501 | } | ||
502 | //} | ||
503 | |||
504 | // all headers downloaded from server, start downloading remaining mails | ||
505 | previewingMail = FALSE; | ||
506 | status1Label->setText(currentAccount->accountName); | ||
507 | progressBar->reset(); | ||
508 | |||
509 | |||
510 | mailboxView->setCurrentTab(0); | ||
511 | } | ||
512 | |||
513 | |||
514 | void EmailClient::moveMailFront(Email *mailPtr) | ||
515 | { | ||
516 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { | ||
517 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); | ||
518 | } | ||
519 | } | ||
520 | |||
521 | void EmailClient::smtpError(int code, const QString & Msg) | ||
522 | { | ||
523 | QString temp; | ||
524 | |||
525 | if (code == ErrUnknownResponse) { | ||
526 | temp = tr("<qt>Unknown response from server</qt>"); | ||
527 | if( ! Msg.isEmpty() ) | ||
528 | temp += Msg; | ||
529 | } else if (code == QSocket::ErrHostNotFound) { | ||
530 | temp = tr("<qt>host not found</qt>"); | ||
531 | } else if (code == QSocket::ErrConnectionRefused) { | ||
532 | temp = tr("<qt>connection refused</qt>"); | ||
533 | } else if (code == QSocket::ErrSocketRead) { | ||
534 | temp = tr("<qt>socket packet error</qt>"); | ||
535 | } | ||
536 | |||
537 | if (code != ErrCancel) { | ||
538 | QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); | ||
539 | } else { | ||
540 | status2Label->setText("Aborted by user"); | ||
541 | } | ||
542 | |||
543 | sending = FALSE; | ||
544 | sendMailButton->setEnabled(TRUE); | ||
545 | cancelButton->setEnabled(FALSE); | ||
546 | quedMessages.clear(); | ||
547 | } | ||
548 | |||
549 | void EmailClient::popError(int code, const QString & Msg) | ||
550 | { | ||
551 | QString temp; | ||
552 | |||
553 | if (code == ErrUnknownResponse) { | ||
554 | temp = tr("<qt>Unknown response from server</qt>"); | ||
555 | if( ! Msg.isEmpty() ) | ||
556 | temp += Msg; | ||
557 | } else if (code == ErrLoginFailed) { | ||
558 | temp = tr("<qt>Login failed\nCheck user name and password</qt>"); | ||
559 | } else if (code == QSocket::ErrHostNotFound) { | ||
560 | temp = tr("<qt>host not found</qt>"); | ||
561 | } else if (code == QSocket::ErrConnectionRefused) { | ||
562 | temp = tr("<qt>connection refused</qt>"); | ||
563 | } else if (code == QSocket::ErrSocketRead) { | ||
564 | temp = tr("<qt>socket packet error</qt>"); | ||
565 | } | ||
566 | |||
567 | if (code != ErrCancel) { | ||
568 | QMessageBox::warning(qApp->activeWindow(), tr("Receiving error"), temp, tr("OK\n")); | ||
569 | |||
570 | } else { | ||
571 | status2Label->setText("Aborted by user"); | ||
572 | } | ||
573 | |||
574 | receiving = FALSE; | ||
575 | getMailButton->setEnabled(TRUE); | ||
576 | cancelButton->setEnabled(FALSE); | ||
577 | selectAccountMenu->setEnabled(TRUE); | ||
578 | } | ||
579 | |||
580 | void EmailClient::inboxItemSelected() | ||
581 | { | ||
582 | //killTimer(timerID); | ||
583 | |||
584 | item = (EmailListItem*) inboxView->selectedItem(); | ||
585 | if (item != NULL) { | ||
586 | emit viewEmail(inboxView, item->getMail()); | ||
587 | } | ||
588 | } | ||
589 | |||
590 | void EmailClient::outboxItemSelected() | ||
591 | { | ||
592 | //killTimer(timerID); | ||
593 | |||
594 | item = (EmailListItem*) outboxView->selectedItem(); | ||
595 | if (item != NULL) { | ||
596 | emit viewEmail(outboxView, item->getMail()); | ||
597 | } | ||
598 | |||
599 | } | ||
600 | |||
601 | void EmailClient::readMail() | ||
602 | { | ||
603 | Email mail; | ||
604 | int start, stop; | ||
605 | QString s, del; | ||
606 | |||
607 | QFile f(getPath(FALSE) + "inbox.txt"); | ||
608 | |||
609 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | ||
610 | QTextStream t( &f ); // use a text stream | ||
611 | s = t.read(); | ||
612 | f.close(); | ||
613 | |||
614 | start = 0; | ||
615 | del = "\n.\n"; | ||
616 | while ((uint) start < s.length()) { | ||
617 | stop = s.find(del, start); | ||
618 | if (stop == -1) | ||
619 | stop = s.length() - del.length(); | ||
620 | |||
621 | mail.rawMail = s.mid(start, stop + del.length() - start ); | ||
622 | start = stop + del.length(); | ||
623 | mailArrived(mail, TRUE); | ||
624 | } | ||
625 | } | ||
626 | |||
627 | QFile fo(getPath(FALSE) + "outbox.txt"); | ||
628 | if ( fo.open(IO_ReadOnly) ) { // file opened successfully | ||
629 | QTextStream t( &fo ); // use a text stream | ||
630 | s = t.read(); | ||
631 | fo.close(); | ||
632 | |||
633 | start = 0; | ||
634 | del = "\n.\n"; | ||
635 | while ((uint) start < s.length()) { | ||
636 | stop = s.find(del, start); | ||
637 | if (stop == -1) | ||
638 | stop = s.length() - del.length(); | ||
639 | |||
640 | mail.rawMail = s.mid(start, stop + del.length() - start ); | ||
641 | start = stop + del.length(); | ||
642 | emailHandler->parse(mail.rawMail, lineShift, &mail); | ||
643 | mail.sent = false; | ||
644 | mail.received = false; | ||
645 | enqueMail(mail); | ||
646 | |||
647 | } | ||
648 | } | ||
649 | } | ||
650 | |||
651 | void EmailClient::saveMail(const QString &fileName, QListView *view) | ||
652 | { | ||
653 | QFile f(fileName); | ||
654 | Email *mail; | ||
655 | |||
656 | if (! f.open(IO_WriteOnly) ) { | ||
657 | qWarning("could not open file"); | ||
658 | return; | ||
659 | } | ||
660 | item = (EmailListItem *) view->firstChild(); | ||
661 | QTextStream t(&f); | ||
662 | while (item != NULL) { | ||
663 | mail = item->getMail(); | ||
664 | t << mail->rawMail; | ||
665 | |||
666 | mailconf->setGroup(mail->id); | ||
667 | mailconf->writeEntry("mailread", mail->read); | ||
668 | |||
669 | item = (EmailListItem *) item->nextSibling(); | ||
670 | } | ||
671 | f.close(); | ||
672 | } | ||
673 | |||
674 | //paths for mailit, is settings, inbox, enclosures | ||
675 | QString EmailClient::getPath(bool enclosurePath) | ||
676 | { | ||
677 | QString basePath = "qtmail"; | ||
678 | QString enclosures = "enclosures"; | ||
679 | |||
680 | QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); | ||
681 | if ( !dir.exists() ) | ||
682 | dir.mkdir( dir.path() ); | ||
683 | |||
684 | if (enclosurePath) { | ||
685 | dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); | ||
686 | |||
687 | if ( !dir.exists() ) | ||
688 | dir.mkdir( dir.path() ); | ||
689 | |||
690 | return (dir.path() + "/"); | ||
691 | |||
692 | } | ||
693 | return (dir.path() + "/"); | ||
694 | } | ||
695 | |||
696 | void EmailClient::readSettings() | ||
697 | { | ||
698 | int y,acc_count; | ||
699 | |||
700 | mailconf->setGroup("mailitglobal"); | ||
701 | acc_count=mailconf->readNumEntry("Accounts",0); | ||
702 | |||
703 | for (int accountPos = 0;accountPos<acc_count ; accountPos++) | ||
704 | { | ||
705 | mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ... | ||
706 | account.accountName = mailconf->readEntry("AccName",""); | ||
707 | account.name = mailconf->readEntry("UserName",""); | ||
708 | account.emailAddress = mailconf->readEntry("Email",""); | ||
709 | account.popUserName = mailconf->readEntry("POPUser",""); | ||
710 | account.popPasswd = mailconf->readEntryCrypt("POPPassword",""); | ||
711 | account.popServer = mailconf->readEntry("POPServer",""); | ||
712 | account.smtpServer = mailconf->readEntry("SMTPServer",""); | ||
713 | account.id = mailconf->readNumEntry("AccountId",0); | ||
714 | account.syncLimit = mailconf->readNumEntry("HeaderLimit",0); | ||
715 | account.lastServerMailCount = 0; | ||
716 | account.synchronize = FALSE; | ||
717 | |||
718 | account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes"); | ||
719 | if (account.synchronize) | ||
720 | { | ||
721 | mailconf->readNumEntry("LASTSERVERMAILCOUNT",0); | ||
722 | } | ||
723 | |||
724 | accountList.append(&account); | ||
725 | } | ||
726 | |||
727 | mailconf->setGroup("mailitglobal"); | ||
728 | |||
729 | if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) | ||
730 | { | ||
731 | mailIdCount = y; | ||
732 | } | ||
733 | if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) | ||
734 | { | ||
735 | accountIdCount = y; | ||
736 | } | ||
737 | } | ||
738 | |||
739 | void EmailClient::saveSettings() | ||
740 | { | ||
741 | int acc_count=0; | ||
742 | MailAccount *accountPtr; | ||
743 | |||
744 | |||
745 | if (!mailconf) | ||
746 | { | ||
747 | qWarning("could not save settings"); | ||
748 | return; | ||
749 | } | ||
750 | |||
751 | for (accountPtr = accountList.first(); accountPtr != 0; | ||
752 | accountPtr = accountList.next()) | ||
753 | { | ||
754 | mailconf->setGroup("Account_"+QString::number(++acc_count)); | ||
755 | mailconf->writeEntry("AccName",accountPtr->accountName ); | ||
756 | mailconf->writeEntry("UserName",accountPtr->name); | ||
757 | mailconf->writeEntry("Email",accountPtr->emailAddress); | ||
758 | mailconf->writeEntry("POPUser",accountPtr->popUserName); | ||
759 | mailconf->writeEntryCrypt("POPPassword",accountPtr->popPasswd); | ||
760 | mailconf->writeEntry("POPServer",accountPtr->popServer); | ||
761 | mailconf->writeEntry("SMTPServer",accountPtr->smtpServer); | ||
762 | mailconf->writeEntry("AccountId",accountPtr->id); | ||
763 | if (accountPtr->synchronize) | ||
764 | { | ||
765 | mailconf->writeEntry("Synchronize","Yes"); | ||
766 | mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit); | ||
767 | mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount); | ||
768 | } | ||
769 | else | ||
770 | { | ||
771 | mailconf->writeEntry("Synchronize", "No"); | ||
772 | } | ||
773 | } | ||
774 | |||
775 | mailconf->setGroup("mailitglobal"); | ||
776 | mailconf->writeEntry("Accounts",acc_count); | ||
777 | mailconf->writeEntry("mailidcount", mailIdCount); | ||
778 | mailconf->writeEntry("accountidcount", accountIdCount); | ||
779 | } | ||
780 | |||
781 | void EmailClient::selectAccount(int id) | ||
782 | { | ||
783 | if (accountList.count() > 0) { | ||
784 | currentAccount = accountList.at(id); | ||
785 | emit newCaption("Mailit - " + currentAccount->accountName); | ||
786 | getNewMail(); | ||
787 | } else { | ||
788 | emit newCaption( tr("Mailit ! No account defined") ); | ||
789 | } | ||
790 | } | ||
791 | |||
792 | void EmailClient::editAccount(int id) | ||
793 | { | ||
794 | MailAccount *newAccount; | ||
795 | |||
796 | editAccountView = new EditAccount(this, "account", TRUE); | ||
797 | if (id == newAccountId) { //new account | ||
798 | newAccount = new MailAccount; | ||
799 | editAccountView->setAccount(newAccount); | ||
800 | } else { | ||
801 | newAccount = accountList.at(id); | ||
802 | editAccountView->setAccount(newAccount, FALSE); | ||
803 | } | ||
804 | |||
805 | editAccountView->showMaximized(); | ||
806 | editAccountView->exec(); | ||
807 | |||
808 | if (editAccountView->result() == QDialog::Accepted) { | ||
809 | if (id == newAccountId) { | ||
810 | newAccount->id = accountIdCount; | ||
811 | accountIdCount++; | ||
812 | accountList.append(newAccount); | ||
813 | updateAccounts(); | ||
814 | } else { | ||
815 | updateAccounts(); | ||
816 | } | ||
817 | } | ||
818 | |||
819 | delete editAccountView; | ||
820 | } | ||
821 | |||
822 | void EmailClient::deleteAccount(int id) | ||
823 | { | ||
824 | MailAccount *newAccount; | ||
825 | QString message; | ||
826 | |||
827 | newAccount = accountList.at(id); | ||
828 | message = tr("Delete account:\n") + newAccount->accountName; | ||
829 | switch( QMessageBox::warning( this, "Mailit", message, | ||
830 | "Yes", "No", 0, 0, 1 ) ) { | ||
831 | |||
832 | case 0: accountList.remove(id); | ||
833 | updateAccounts(); | ||
834 | break; | ||
835 | case 1: | ||
836 | break; | ||
837 | } | ||
838 | } | ||
839 | |||
840 | void EmailClient::updateAccounts() | ||
841 | { | ||
842 | MailAccount *accountPtr; | ||
843 | |||
844 | //rebuild menus, clear all first | ||
845 | editAccountMenu->clear(); | ||
846 | selectAccountMenu->clear(); | ||
847 | deleteAccountMenu->clear(); | ||
848 | |||
849 | newAccountId = editAccountMenu->insertItem( tr("New"), this, | ||
850 | SLOT(editAccount(int)) ); | ||
851 | editAccountMenu->insertSeparator(); | ||
852 | |||
853 | idCount = 0; | ||
854 | for (accountPtr = accountList.first(); accountPtr != 0; | ||
855 | accountPtr = accountList.next()) { | ||
856 | |||
857 | editAccountMenu->insertItem(accountPtr->accountName, | ||
858 | this, SLOT(editAccount(int)), 0, idCount); | ||
859 | selectAccountMenu->insertItem(accountPtr->accountName, | ||
860 | this, SLOT(selectAccount(int)), 0, idCount); | ||
861 | deleteAccountMenu->insertItem(accountPtr->accountName, | ||
862 | this, SLOT(deleteAccount(int)), 0, idCount); | ||
863 | idCount++; | ||
864 | } | ||
865 | } | ||
866 | |||
867 | void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) | ||
868 | { | ||
869 | Email *mPtr; | ||
870 | Enclosure *ePtr; | ||
871 | |||
872 | if (inbox) | ||
873 | { | ||
874 | mPtr = mailItem->getMail(); | ||
875 | |||
876 | //if mail is in queue for download, remove it from | ||
877 | //queue if possible | ||
878 | if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { | ||
879 | if ( !mPtr->downloaded ) | ||
880 | mailDownloadList.remove(mPtr->serverId, mPtr->size); | ||
881 | } | ||
882 | |||
883 | mailconf->setGroup(mPtr->id); | ||
884 | mailconf->clearGroup(); | ||
885 | |||
886 | //delete any temporary attatchemnts storing | ||
887 | for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { | ||
888 | if (ePtr->saved) { | ||
889 | QFile::remove( (ePtr->path + ePtr->name) ); | ||
890 | } | ||
891 | } | ||
892 | inboxView->takeItem(mailItem); | ||
893 | } | ||
894 | else | ||
895 | { | ||
896 | outboxView->takeItem(mailItem); | ||
897 | } | ||
898 | } | ||
899 | |||
900 | void EmailClient::setMailSize(int size) | ||
901 | { | ||
902 | progressBar->reset(); | ||
903 | progressBar->setTotalSteps(size); | ||
904 | } | ||
905 | |||
906 | void EmailClient::setTotalSize(int /*size*/) | ||
907 | { | ||
908 | |||
909 | } | ||
910 | |||
911 | void EmailClient::setDownloadedSize(int size) | ||
912 | { | ||
913 | int total = progressBar->totalSteps(); | ||
914 | |||
915 | if (size < total) { | ||
916 | progressBar->setProgress(size); | ||
917 | } else { | ||
918 | progressBar->setProgress(total); | ||
919 | } | ||
920 | } | ||
921 | |||
922 | void EmailClient::deleteItem() | ||
923 | { | ||
924 | bool inbox=mailboxView->currentTab()==0; | ||
925 | QListView* box; | ||
926 | |||
927 | EmailListItem* eli; | ||
928 | // int pos; | ||
929 | |||
930 | inbox ? box=inboxView : box=outboxView; | ||
931 | |||
932 | eli=(EmailListItem*)box->selectedItem(); | ||
933 | |||
934 | if (eli) | ||
935 | { | ||
936 | box->setSelected(eli->itemBelow(),true); //select the previous item | ||
937 | |||
938 | deleteMail(eli,(bool&)inbox); //remove mail entry | ||
939 | } | ||
940 | } | ||
941 | |||
942 | void EmailClient::inboxItemPressed() | ||
943 | { | ||
944 | // timerID=startTimer(500); | ||
945 | } | ||
946 | |||
947 | void EmailClient::inboxItemReleased() | ||
948 | { | ||
949 | // killTimer(timerID); | ||
950 | } | ||
951 | |||
952 | /*void EmailClient::timerEvent(QTimerEvent *e) | ||
953 | { | ||
954 | //killTimer(timerID); | ||
955 | |||
956 | |||
957 | QPopupMenu *action = new QPopupMenu(this); | ||
958 | |||
959 | int reply=0; | ||
960 | |||
961 | action->insertItem(tr( "Reply To" ),this,SLOT(reply())); | ||
962 | action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); | ||
963 | action->insertItem( tr( "Forward" ), this,SLOT(forward())); | ||
964 | action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); | ||
965 | |||
966 | action->exec(QCursor::pos()); | ||
967 | |||
968 | if (action) delete action; | ||
969 | |||
970 | }*/ | ||
971 | |||
972 | Email* EmailClient::getCurrentMail() | ||
973 | { | ||
974 | EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); | ||
975 | if (eli!=NULL) | ||
976 | return eli->getMail(); | ||
977 | else | ||
978 | return NULL; | ||
979 | } | ||
980 | |||
981 | void EmailClient::download(Email* mail) | ||
982 | { | ||
983 | MailAccount* acc=0; | ||
984 | |||
985 | tempMailDownloadList.clear(); | ||
986 | tempMailDownloadList.sizeInsert(mail->serverId, mail->size); | ||
987 | |||
988 | acc=accountList.at(mail->fromAccountId-1); | ||
989 | if (acc) | ||
990 | { | ||
991 | emailHandler->setAccount(*acc); | ||
992 | emailHandler->getMailByList(&tempMailDownloadList); | ||
993 | } | ||
994 | else | ||
995 | QMessageBox::warning(qApp->activeWindow(), | ||
996 | tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n"); | ||
997 | } | ||
998 | |||
999 | void EmailClient::receive(const QCString& /*msg*/, const QByteArray& /*data*/) | ||
1000 | { | ||
1001 | /*if (msg=="getMail()") | ||
1002 | { | ||
1003 | //QDialog qd(qApp->activeWindow(),"Getting mail",true); | ||
1004 | QVBoxLayout *vbProg = new QVBoxLayout( &qd ); | ||
1005 | |||
1006 | initStatusBar(&qd); | ||
1007 | |||
1008 | if (statusBar==0) | ||
1009 | { | ||
1010 | qDebug("No Bar ..."); | ||
1011 | //statusBar=new ProgressBar(&qd); | ||
1012 | } | ||
1013 | statusBar->show(); | ||
1014 | vbProg->addWidget(statusBar); | ||
1015 | qd.showMaximized(); | ||
1016 | qd.show(); | ||
1017 | emit getAllNewMail(); | ||
1018 | //qd.exec(); | ||
1019 | } | ||
1020 | else if (msg=="compose()") | ||
1021 | { | ||
1022 | QDialog qd(qApp->activeWindow(),"Getting mail",true); | ||
1023 | |||
1024 | WriteMail wm(&qd,"write new mail"); | ||
1025 | QVBoxLayout vbProg( &qd ); | ||
1026 | |||
1027 | wm.showMaximized(); | ||
1028 | vbProg.addWidget(&wm); | ||
1029 | |||
1030 | qd.showMaximized(); | ||
1031 | |||
1032 | emit composeRequested(); | ||
1033 | qd.exec(); | ||
1034 | |||
1035 | QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n"); | ||
1036 | } | ||
1037 | |||
1038 | else if (msg=="dialog()") | ||
1039 | { | ||
1040 | QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n"); | ||
1041 | }*/ | ||
1042 | } | ||