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