summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mailit/emailclient.cpp2
-rw-r--r--noncore/net/mailit/emailhandler.cpp15
-rw-r--r--noncore/unsupported/mailit/emailclient.cpp2
-rw-r--r--noncore/unsupported/mailit/emailhandler.cpp15
4 files changed, 22 insertions, 12 deletions
diff --git a/noncore/net/mailit/emailclient.cpp b/noncore/net/mailit/emailclient.cpp
index 749a4e9..90664bb 100644
--- a/noncore/net/mailit/emailclient.cpp
+++ b/noncore/net/mailit/emailclient.cpp
@@ -1,1042 +1,1042 @@
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,const QString &)), this, 62 connect(emailHandler, SIGNAL(smtpError(int,const QString &)), this,
63 SLOT(smtpError(int,const QString &)) ); 63 SLOT(smtpError(int,const QString &)) );
64 connect(emailHandler, SIGNAL(popError(int,const QString &)), this, 64 connect(emailHandler, SIGNAL(popError(int,const QString &)), this,
65 SLOT(popError(int,const QString &)) ); 65 SLOT(popError(int,const QString &)) );
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, const QString & Msg) 521void EmailClient::smtpError(int code, const QString & Msg)
522{ 522{
523 QString temp; 523 QString temp;
524 524
525 if (code == ErrUnknownResponse) { 525 if (code == ErrUnknownResponse) {
526 temp = tr("<qt>Unknown response from server</qt>"); 526 temp = tr("<qt>Unknown response from server</qt>");
527 if( ! Msg.isEmpty() ) 527 if( ! Msg.isEmpty() )
528 temp += Msg; 528 temp += Msg;
529 } else if (code == QSocket::ErrHostNotFound) { 529 } else if (code == QSocket::ErrHostNotFound) {
530 temp = tr("<qt>host not found</qt>"); 530 temp = tr("<qt>host not found</qt>");
531 } else if (code == QSocket::ErrConnectionRefused) { 531 } else if (code == QSocket::ErrConnectionRefused) {
532 temp = tr("<qt>connection refused</qt>"); 532 temp = tr("<qt>connection refused</qt>");
533 } else if (code == QSocket::ErrSocketRead) { 533 } else if (code == QSocket::ErrSocketRead) {
534 temp = tr("<qt>socket packet error</qt>"); 534 temp = tr("<qt>socket packet error</qt>");
535 } 535 }
536 536
537 if (code != ErrCancel) { 537 if (code != ErrCancel) {
538 QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); 538 QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n");
539 } else { 539 } else {
540 status2Label->setText("Aborted by user"); 540 status2Label->setText("Aborted by user");
541 } 541 }
542 542
543 sending = FALSE; 543 sending = FALSE;
544 sendMailButton->setEnabled(TRUE); 544 sendMailButton->setEnabled(TRUE);
545 cancelButton->setEnabled(FALSE); 545 cancelButton->setEnabled(FALSE);
546 quedMessages.clear(); 546 quedMessages.clear();
547} 547}
548 548
549void EmailClient::popError(int code, const QString & Msg) 549void EmailClient::popError(int code, const QString & Msg)
550{ 550{
551 QString temp; 551 QString temp;
552 552
553 if (code == ErrUnknownResponse) { 553 if (code == ErrUnknownResponse) {
554 temp = tr("<qt>Unknown response from server</qt>"); 554 temp = tr("<qt>Unknown response from server</qt>");
555 if( ! Msg.isEmpty() ) 555 if( ! Msg.isEmpty() )
556 temp += Msg; 556 temp += Msg;
557 } else if (code == ErrLoginFailed) { 557 } else if (code == ErrLoginFailed) {
558 temp = tr("<qt>Login failed\nCheck user name and password</qt>"); 558 temp = tr("<qt>Login failed\nCheck user name and password</qt>");
559 } else if (code == QSocket::ErrHostNotFound) { 559 } else if (code == QSocket::ErrHostNotFound) {
560 temp = tr("<qt>host not found</qt>"); 560 temp = tr("<qt>host not found</qt>");
561 } else if (code == QSocket::ErrConnectionRefused) { 561 } else if (code == QSocket::ErrConnectionRefused) {
562 temp = tr("<qt>connection refused</qt>"); 562 temp = tr("<qt>connection refused</qt>");
563 } else if (code == QSocket::ErrSocketRead) { 563 } else if (code == QSocket::ErrSocketRead) {
564 temp = tr("<qt>socket packet error</qt>"); 564 temp = tr("<qt>socket packet error</qt>");
565 } 565 }
566 566
567 if (code != ErrCancel) { 567 if (code != ErrCancel) {
568 QMessageBox::warning(qApp->activeWindow(), tr("Receiving error"), temp, tr("OK\n")); 568 QMessageBox::warning(qApp->activeWindow(), tr("Receiving error"), temp, tr("OK\n"));
569 569
570 } else { 570 } else {
571 status2Label->setText("Aborted by user"); 571 status2Label->setText("Aborted by user");
572 } 572 }
573 573
574 receiving = FALSE; 574 receiving = FALSE;
575 getMailButton->setEnabled(TRUE); 575 getMailButton->setEnabled(TRUE);
576 cancelButton->setEnabled(FALSE); 576 cancelButton->setEnabled(FALSE);
577 selectAccountMenu->setEnabled(TRUE); 577 selectAccountMenu->setEnabled(TRUE);
578} 578}
579 579
580void EmailClient::inboxItemSelected() 580void EmailClient::inboxItemSelected()
581{ 581{
582 //killTimer(timerID); 582 //killTimer(timerID);
583 583
584 item = (EmailListItem*) inboxView->selectedItem(); 584 item = (EmailListItem*) inboxView->selectedItem();
585 if (item != NULL) { 585 if (item != NULL) {
586 emit viewEmail(inboxView, item->getMail()); 586 emit viewEmail(inboxView, item->getMail());
587 } 587 }
588} 588}
589 589
590void EmailClient::outboxItemSelected() 590void EmailClient::outboxItemSelected()
591{ 591{
592 //killTimer(timerID); 592 //killTimer(timerID);
593 593
594 item = (EmailListItem*) outboxView->selectedItem(); 594 item = (EmailListItem*) outboxView->selectedItem();
595 if (item != NULL) { 595 if (item != NULL) {
596 emit viewEmail(outboxView, item->getMail()); 596 emit viewEmail(outboxView, item->getMail());
597 } 597 }
598 598
599} 599}
600 600
601void EmailClient::readMail() 601void EmailClient::readMail()
602{ 602{
603 Email mail; 603 Email mail;
604 int start, stop; 604 int start, stop;
605 QString s, del; 605 QString s, del;
606 606
607 QFile f(getPath(FALSE) + "inbox.txt"); 607 QFile f(getPath(FALSE) + "inbox.txt");
608 608
609 if ( f.open(IO_ReadOnly) ) { // file opened successfully 609 if ( f.open(IO_ReadOnly) ) { // file opened successfully
610 QTextStream t( &f ); // use a text stream 610 QTextStream t( &f ); // use a text stream
611 s = t.read(); 611 s = t.read();
612 f.close(); 612 f.close();
613 613
614 start = 0; 614 start = 0;
615 del = "\n.\n"; 615 del = "\n.\n";
616 while ((uint) start < s.length()) { 616 while ((uint) start < s.length()) {
617 stop = s.find(del, start); 617 stop = s.find(del, start);
618 if (stop == -1) 618 if (stop == -1)
619 stop = s.length() - del.length(); 619 stop = s.length() - del.length();
620 620
621 mail.rawMail = s.mid(start, stop + del.length() - start ); 621 mail.rawMail = s.mid(start, stop + del.length() - start );
622 start = stop + del.length(); 622 start = stop + del.length();
623 mailArrived(mail, TRUE); 623 mailArrived(mail, TRUE);
624 } 624 }
625 } 625 }
626 626
627 QFile fo(getPath(FALSE) + "outbox.txt"); 627 QFile fo(getPath(FALSE) + "outbox.txt");
628 if ( fo.open(IO_ReadOnly) ) { // file opened successfully 628 if ( fo.open(IO_ReadOnly) ) { // file opened successfully
629 QTextStream t( &fo ); // use a text stream 629 QTextStream t( &fo ); // use a text stream
630 s = t.read(); 630 s = t.read();
631 fo.close(); 631 fo.close();
632 632
633 start = 0; 633 start = 0;
634 del = "\n.\n"; 634 del = "\n.\n";
635 while ((uint) start < s.length()) { 635 while ((uint) start < s.length()) {
636 stop = s.find(del, start); 636 stop = s.find(del, start);
637 if (stop == -1) 637 if (stop == -1)
638 stop = s.length() - del.length(); 638 stop = s.length() - del.length();
639 639
640 mail.rawMail = s.mid(start, stop + del.length() - start ); 640 mail.rawMail = s.mid(start, stop + del.length() - start );
641 start = stop + del.length(); 641 start = stop + del.length();
642 emailHandler->parse(mail.rawMail, lineShift, &mail); 642 emailHandler->parse(mail.rawMail, lineShift, &mail);
643 mail.sent = false; 643 mail.sent = false;
644 mail.received = false; 644 mail.received = false;
645 enqueMail(mail); 645 enqueMail(mail);
646 646
647 } 647 }
648 } 648 }
649} 649}
650 650
651void EmailClient::saveMail(const QString &fileName, QListView *view) 651void EmailClient::saveMail(const QString &fileName, QListView *view)
652{ 652{
653 QFile f(fileName); 653 QFile f(fileName);
654 Email *mail; 654 Email *mail;
655 655
656 if (! f.open(IO_WriteOnly) ) { 656 if (! f.open(IO_WriteOnly) ) {
657 qWarning("could not open file"); 657 qWarning("could not open file");
658 return; 658 return;
659 } 659 }
660 item = (EmailListItem *) view->firstChild(); 660 item = (EmailListItem *) view->firstChild();
661 QTextStream t(&f); 661 QTextStream t(&f);
662 while (item != NULL) { 662 while (item != NULL) {
663 mail = item->getMail(); 663 mail = item->getMail();
664 t << mail->rawMail; 664 t << mail->rawMail;
665 665
666 mailconf->setGroup(mail->id); 666 mailconf->setGroup(mail->id);
667 mailconf->writeEntry("mailread", mail->read); 667 mailconf->writeEntry("mailread", mail->read);
668 668
669 item = (EmailListItem *) item->nextSibling(); 669 item = (EmailListItem *) item->nextSibling();
670 } 670 }
671 f.close(); 671 f.close();
672} 672}
673 673
674//paths for mailit, is settings, inbox, enclosures 674//paths for mailit, is settings, inbox, enclosures
675QString EmailClient::getPath(bool enclosurePath) 675QString EmailClient::getPath(bool enclosurePath)
676{ 676{
677 QString basePath = "qtmail"; 677 QString basePath = "qtmail";
678 QString enclosures = "enclosures"; 678 QString enclosures = "enclosures";
679 679
680 QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); 680 QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath);
681 if ( !dir.exists() ) 681 if ( !dir.exists() )
682 dir.mkdir( dir.path() ); 682 dir.mkdir( dir.path() );
683 683
684 if (enclosurePath) { 684 if (enclosurePath) {
685 dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); 685 dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures);
686 686
687 if ( !dir.exists() ) 687 if ( !dir.exists() )
688 dir.mkdir( dir.path() ); 688 dir.mkdir( dir.path() );
689 689
690 return (dir.path() + "/"); 690 return (dir.path() + "/");
691 691
692 } 692 }
693 return (dir.path() + "/"); 693 return (dir.path() + "/");
694} 694}
695 695
696void EmailClient::readSettings() 696void EmailClient::readSettings()
697{ 697{
698 int y,acc_count; 698 int y,acc_count;
699 699
700 mailconf->setGroup("mailitglobal"); 700 mailconf->setGroup("mailitglobal");
701 acc_count=mailconf->readNumEntry("Accounts",0); 701 acc_count=mailconf->readNumEntry("Accounts",0);
702 702
703 for (int accountPos = 0;accountPos<acc_count ; accountPos++) 703 for (int accountPos = 0;accountPos<acc_count ; accountPos++)
704 { 704 {
705 mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ... 705 mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ...
706 account.accountName = mailconf->readEntry("AccName",""); 706 account.accountName = mailconf->readEntry("AccName","");
707 account.name = mailconf->readEntry("UserName",""); 707 account.name = mailconf->readEntry("UserName","");
708 account.emailAddress = mailconf->readEntry("Email",""); 708 account.emailAddress = mailconf->readEntry("Email","");
709 account.popUserName = mailconf->readEntry("POPUser",""); 709 account.popUserName = mailconf->readEntry("POPUser","");
710 account.popPasswd = mailconf->readEntryCrypt("POPPassword",""); 710 account.popPasswd = mailconf->readEntryCrypt("POPPassword","");
711 account.popServer = mailconf->readEntry("POPServer",""); 711 account.popServer = mailconf->readEntry("POPServer","");
712 account.smtpServer = mailconf->readEntry("SMTPServer",""); 712 account.smtpServer = mailconf->readEntry("SMTPServer","");
713 account.id = mailconf->readNumEntry("AccountId",0); 713 account.id = mailconf->readNumEntry("AccountId",0);
714 account.syncLimit = mailconf->readNumEntry("HeaderLimit",0); 714 account.syncLimit = mailconf->readNumEntry("HeaderLimit",0);
715 account.lastServerMailCount = 0; 715 account.lastServerMailCount = 0;
716 account.synchronize = FALSE; 716 account.synchronize = FALSE;
717 717
718 account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes"); 718 account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes");
719 if (account.synchronize) 719 if (account.synchronize)
720 { 720 {
721 mailconf->readNumEntry("LASTSERVERMAILCOUNT",0); 721 mailconf->readNumEntry("LASTSERVERMAILCOUNT",0);
722 } 722 }
723 723
724 accountList.append(&account); 724 accountList.append(&account);
725 } 725 }
726 726
727 mailconf->setGroup("mailitglobal"); 727 mailconf->setGroup("mailitglobal");
728 728
729 if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) 729 if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1)
730 { 730 {
731 mailIdCount = y; 731 mailIdCount = y;
732 } 732 }
733 if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) 733 if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1)
734 { 734 {
735 accountIdCount = y; 735 accountIdCount = y;
736 } 736 }
737} 737}
738 738
739void EmailClient::saveSettings() 739void EmailClient::saveSettings()
740{ 740{
741 int acc_count=0; 741 int acc_count=0;
742 MailAccount *accountPtr; 742 MailAccount *accountPtr;
743 743
744 744
745 if (!mailconf) 745 if (!mailconf)
746 { 746 {
747 qWarning("could not save settings"); 747 qWarning("could not save settings");
748 return; 748 return;
749 } 749 }
750 750
751 for (accountPtr = accountList.first(); accountPtr != 0; 751 for (accountPtr = accountList.first(); accountPtr != 0;
752 accountPtr = accountList.next()) 752 accountPtr = accountList.next())
753 { 753 {
754 mailconf->setGroup("Account_"+QString::number(++acc_count)); 754 mailconf->setGroup("Account_"+QString::number(++acc_count));
755 mailconf->writeEntry("AccName",accountPtr->accountName ); 755 mailconf->writeEntry("AccName",accountPtr->accountName );
756 mailconf->writeEntry("UserName",accountPtr->name); 756 mailconf->writeEntry("UserName",accountPtr->name);
757 mailconf->writeEntry("Email",accountPtr->emailAddress); 757 mailconf->writeEntry("Email",accountPtr->emailAddress);
758 mailconf->writeEntry("POPUser",accountPtr->popUserName); 758 mailconf->writeEntry("POPUser",accountPtr->popUserName);
759 mailconf->writeEntryCrypt("POPPassword",accountPtr->popPasswd); 759 mailconf->writeEntryCrypt("POPPassword",accountPtr->popPasswd);
760 mailconf->writeEntry("POPServer",accountPtr->popServer); 760 mailconf->writeEntry("POPServer",accountPtr->popServer);
761 mailconf->writeEntry("SMTPServer",accountPtr->smtpServer); 761 mailconf->writeEntry("SMTPServer",accountPtr->smtpServer);
762 mailconf->writeEntry("AccountId",accountPtr->id); 762 mailconf->writeEntry("AccountId",accountPtr->id);
763 if (accountPtr->synchronize) 763 if (accountPtr->synchronize)
764 { 764 {
765 mailconf->writeEntry("Synchronize","Yes"); 765 mailconf->writeEntry("Synchronize","Yes");
766 mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit); 766 mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit);
767 mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount); 767 mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount);
768 } 768 }
769 else 769 else
770 { 770 {
771 mailconf->writeEntry("Synchronize", "No"); 771 mailconf->writeEntry("Synchronize", "No");
772 } 772 }
773 } 773 }
774 774
775 mailconf->setGroup("mailitglobal"); 775 mailconf->setGroup("mailitglobal");
776 mailconf->writeEntry("Accounts",acc_count); 776 mailconf->writeEntry("Accounts",acc_count);
777 mailconf->writeEntry("mailidcount", mailIdCount); 777 mailconf->writeEntry("mailidcount", mailIdCount);
778 mailconf->writeEntry("accountidcount", accountIdCount); 778 mailconf->writeEntry("accountidcount", accountIdCount);
779} 779}
780 780
781void EmailClient::selectAccount(int id) 781void EmailClient::selectAccount(int id)
782{ 782{
783 if (accountList.count() > 0) { 783 if (accountList.count() > 0) {
784 currentAccount = accountList.at(id); 784 currentAccount = accountList.at(id);
785 emit newCaption("Mailit - " + currentAccount->accountName); 785 emit newCaption("Mailit - " + currentAccount->accountName);
786 getNewMail(); 786 getNewMail();
787 } else { 787 } else {
788 emit newCaption("Mailit ! No account defined"); 788 emit newCaption("Mailit ! No account defined");
789 } 789 }
790} 790}
791 791
792void EmailClient::editAccount(int id) 792void EmailClient::editAccount(int id)
793{ 793{
794 MailAccount *newAccount; 794 MailAccount *newAccount;
795 795
796 editAccountView = new EditAccount(this, "account", TRUE); 796 editAccountView = new EditAccount(this, "account", TRUE);
797 if (id == newAccountId) { //new account 797 if (id == newAccountId) { //new account
798 newAccount = new MailAccount; 798 newAccount = new MailAccount;
799 editAccountView->setAccount(newAccount); 799 editAccountView->setAccount(newAccount);
800 } else { 800 } else {
801 newAccount = accountList.at(id); 801 newAccount = accountList.at(id);
802 editAccountView->setAccount(newAccount, FALSE); 802 editAccountView->setAccount(newAccount, FALSE);
803 } 803 }
804 804
805 editAccountView->showMaximized(); 805 editAccountView->showMaximized();
806 editAccountView->exec(); 806 editAccountView->exec();
807 807
808 if (editAccountView->result() == QDialog::Accepted) { 808 if (editAccountView->result() == QDialog::Accepted) {
809 if (id == newAccountId) { 809 if (id == newAccountId) {
810 newAccount->id = accountIdCount; 810 newAccount->id = accountIdCount;
811 accountIdCount++; 811 accountIdCount++;
812 accountList.append(newAccount); 812 accountList.append(newAccount);
813 updateAccounts(); 813 updateAccounts();
814 } else { 814 } else {
815 updateAccounts(); 815 updateAccounts();
816 } 816 }
817 } 817 }
818 818
819 delete editAccountView; 819 delete editAccountView;
820} 820}
821 821
822void EmailClient::deleteAccount(int id) 822void EmailClient::deleteAccount(int id)
823{ 823{
824 MailAccount *newAccount; 824 MailAccount *newAccount;
825 QString message; 825 QString message;
826 826
827 newAccount = accountList.at(id); 827 newAccount = accountList.at(id);
828 message = "Delete account:\n" + newAccount->accountName; 828 message = "Delete account:\n" + newAccount->accountName;
829 switch( QMessageBox::warning( this, "Mailit", message, 829 switch( QMessageBox::warning( this, "Mailit", message,
830 "Yes", "No", 0, 0, 1 ) ) { 830 "Yes", "No", 0, 0, 1 ) ) {
831 831
832 case 0: accountList.remove(id); 832 case 0: accountList.remove(id);
833 updateAccounts(); 833 updateAccounts();
834 break; 834 break;
835 case 1: 835 case 1:
836 break; 836 break;
837 } 837 }
838} 838}
839 839
840void EmailClient::updateAccounts() 840void EmailClient::updateAccounts()
841{ 841{
842 MailAccount *accountPtr; 842 MailAccount *accountPtr;
843 843
844 //rebuild menus, clear all first 844 //rebuild menus, clear all first
845 editAccountMenu->clear(); 845 editAccountMenu->clear();
846 selectAccountMenu->clear(); 846 selectAccountMenu->clear();
847 deleteAccountMenu->clear(); 847 deleteAccountMenu->clear();
848 848
849 newAccountId = editAccountMenu->insertItem("New", this, 849 newAccountId = editAccountMenu->insertItem("New", this,
850 SLOT(editAccount(int)) ); 850 SLOT(editAccount(int)) );
851 editAccountMenu->insertSeparator(); 851 editAccountMenu->insertSeparator();
852 852
853 idCount = 0; 853 idCount = 0;
854 for (accountPtr = accountList.first(); accountPtr != 0; 854 for (accountPtr = accountList.first(); accountPtr != 0;
855 accountPtr = accountList.next()) { 855 accountPtr = accountList.next()) {
856 856
857 editAccountMenu->insertItem(accountPtr->accountName, 857 editAccountMenu->insertItem(accountPtr->accountName,
858 this, SLOT(editAccount(int)), 0, idCount); 858 this, SLOT(editAccount(int)), 0, idCount);
859 selectAccountMenu->insertItem(accountPtr->accountName, 859 selectAccountMenu->insertItem(accountPtr->accountName,
860 this, SLOT(selectAccount(int)), 0, idCount); 860 this, SLOT(selectAccount(int)), 0, idCount);
861 deleteAccountMenu->insertItem(accountPtr->accountName, 861 deleteAccountMenu->insertItem(accountPtr->accountName,
862 this, SLOT(deleteAccount(int)), 0, idCount); 862 this, SLOT(deleteAccount(int)), 0, idCount);
863 idCount++; 863 idCount++;
864 } 864 }
865} 865}
866 866
867void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) 867void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox)
868{ 868{
869 Email *mPtr; 869 Email *mPtr;
870 Enclosure *ePtr; 870 Enclosure *ePtr;
871 871
872 if (inbox) 872 if (inbox)
873 { 873 {
874 mPtr = mailItem->getMail(); 874 mPtr = mailItem->getMail();
875 875
876 //if mail is in queue for download, remove it from 876 //if mail is in queue for download, remove it from
877 //queue if possible 877 //queue if possible
878 if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { 878 if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) {
879 if ( !mPtr->downloaded ) 879 if ( !mPtr->downloaded )
880 mailDownloadList.remove(mPtr->serverId, mPtr->size); 880 mailDownloadList.remove(mPtr->serverId, mPtr->size);
881 } 881 }
882 882
883 mailconf->setGroup(mPtr->id); 883 mailconf->setGroup(mPtr->id);
884 mailconf->clearGroup(); 884 mailconf->clearGroup();
885 885
886 //delete any temporary attatchemnts storing 886 //delete any temporary attatchemnts storing
887 for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { 887 for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) {
888 if (ePtr->saved) { 888 if (ePtr->saved) {
889 QFile::remove( (ePtr->path + ePtr->name) ); 889 QFile::remove( (ePtr->path + ePtr->name) );
890 } 890 }
891 } 891 }
892 inboxView->takeItem(mailItem); 892 inboxView->takeItem(mailItem);
893 } 893 }
894 else 894 else
895 { 895 {
896 outboxView->takeItem(mailItem); 896 outboxView->takeItem(mailItem);
897 } 897 }
898} 898}
899 899
900void EmailClient::setMailSize(int size) 900void EmailClient::setMailSize(int size)
901{ 901{
902 progressBar->reset(); 902 progressBar->reset();
903 progressBar->setTotalSteps(size); 903 progressBar->setTotalSteps(size);
904} 904}
905 905
906void EmailClient::setTotalSize(int /*size*/) 906void EmailClient::setTotalSize(int /*size*/)
907{ 907{
908 908
909} 909}
910 910
911void EmailClient::setDownloadedSize(int size) 911void EmailClient::setDownloadedSize(int size)
912{ 912{
913 int total = progressBar->totalSteps(); 913 int total = progressBar->totalSteps();
914 914
915 if (size < total) { 915 if (size < total) {
916 progressBar->setProgress(size); 916 progressBar->setProgress(size);
917 } else { 917 } else {
918 progressBar->setProgress(total); 918 progressBar->setProgress(total);
919 } 919 }
920} 920}
921 921
922void EmailClient::deleteItem() 922void EmailClient::deleteItem()
923{ 923{
924 bool inbox=mailboxView->currentTab()==0; 924 bool inbox=mailboxView->currentTab()==0;
925 QListView* box; 925 QListView* box;
926 926
927 EmailListItem* eli; 927 EmailListItem* eli;
928 // int pos; 928 // int pos;
929 929
930 inbox ? box=inboxView : box=outboxView; 930 inbox ? box=inboxView : box=outboxView;
931 931
932 eli=(EmailListItem*)box->selectedItem(); 932 eli=(EmailListItem*)box->selectedItem();
933 933
934 if (eli) 934 if (eli)
935 { 935 {
936 box->setSelected(eli->itemBelow(),true); //select the previous item 936 box->setSelected(eli->itemBelow(),true); //select the previous item
937 937
938 deleteMail(eli,(bool&)inbox); //remove mail entry 938 deleteMail(eli,(bool&)inbox); //remove mail entry
939 } 939 }
940} 940}
941 941
942void EmailClient::inboxItemPressed() 942void EmailClient::inboxItemPressed()
943{ 943{
944// timerID=startTimer(500); 944// timerID=startTimer(500);
945} 945}
946 946
947void EmailClient::inboxItemReleased() 947void EmailClient::inboxItemReleased()
948{ 948{
949 // killTimer(timerID); 949 // killTimer(timerID);
950} 950}
951 951
952/*void EmailClient::timerEvent(QTimerEvent *e) 952/*void EmailClient::timerEvent(QTimerEvent *e)
953{ 953{
954 //killTimer(timerID); 954 //killTimer(timerID);
955 955
956 956
957 QPopupMenu *action = new QPopupMenu(this); 957 QPopupMenu *action = new QPopupMenu(this);
958 958
959 int reply=0; 959 int reply=0;
960 960
961 action->insertItem(tr( "Reply To" ),this,SLOT(reply())); 961 action->insertItem(tr( "Reply To" ),this,SLOT(reply()));
962 action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); 962 action->insertItem( tr( "Reply All" ),this,SLOT(replyAll()));
963 action->insertItem( tr( "Forward" ), this,SLOT(forward())); 963 action->insertItem( tr( "Forward" ), this,SLOT(forward()));
964 action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); 964 action->insertItem( tr( "Remove Mail" ), this,SLOT(remove()));
965 965
966 action->exec(QCursor::pos()); 966 action->exec(QCursor::pos());
967 967
968 if (action) delete action; 968 if (action) delete action;
969 969
970}*/ 970}*/
971 971
972Email* EmailClient::getCurrentMail() 972Email* EmailClient::getCurrentMail()
973{ 973{
974 EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); 974 EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem());
975 if (eli!=NULL) 975 if (eli!=NULL)
976 return eli->getMail(); 976 return eli->getMail();
977 else 977 else
978 return NULL; 978 return NULL;
979} 979}
980 980
981void EmailClient::download(Email* mail) 981void EmailClient::download(Email* mail)
982{ 982{
983 MailAccount* acc=0; 983 MailAccount* acc=0;
984 984
985 tempMailDownloadList.clear(); 985 tempMailDownloadList.clear();
986 tempMailDownloadList.sizeInsert(mail->serverId, mail->size); 986 tempMailDownloadList.sizeInsert(mail->serverId, mail->size);
987 987
988 acc=accountList.at(mail->fromAccountId-1); 988 acc=accountList.at(mail->fromAccountId-1);
989 if (acc) 989 if (acc)
990 { 990 {
991 emailHandler->setAccount(*acc); 991 emailHandler->setAccount(*acc);
992 emailHandler->getMailByList(&tempMailDownloadList); 992 emailHandler->getMailByList(&tempMailDownloadList);
993 } 993 }
994 else 994 else
995 QMessageBox::warning(qApp->activeWindow(), 995 QMessageBox::warning(qApp->activeWindow(),
996 tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n"); 996 tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n");
997} 997}
998 998
999void EmailClient::receive(const QCString& /*msg*/, const QByteArray& /*data*/) 999void EmailClient::receive(const QCString& /*msg*/, const QByteArray& /*data*/)
1000{ 1000{
1001 /*if (msg=="getMail()") 1001 /*if (msg=="getMail()")
1002 { 1002 {
1003 //QDialog qd(qApp->activeWindow(),"Getting mail",true); 1003 //QDialog qd(qApp->activeWindow(),"Getting mail",true);
1004 QVBoxLayout *vbProg = new QVBoxLayout( &qd ); 1004 QVBoxLayout *vbProg = new QVBoxLayout( &qd );
1005 1005
1006 initStatusBar(&qd); 1006 initStatusBar(&qd);
1007 1007
1008 if (statusBar==0) 1008 if (statusBar==0)
1009 { 1009 {
1010 qDebug("No Bar ..."); 1010 qDebug("No Bar ...");
1011 //statusBar=new ProgressBar(&qd); 1011 //statusBar=new ProgressBar(&qd);
1012 } 1012 }
1013 statusBar->show(); 1013 statusBar->show();
1014 vbProg->addWidget(statusBar); 1014 vbProg->addWidget(statusBar);
1015 qd.showMaximized(); 1015 qd.showMaximized();
1016 qd.show(); 1016 qd.show();
1017 emit getAllNewMail(); 1017 emit getAllNewMail();
1018 //qd.exec(); 1018 //qd.exec();
1019 } 1019 }
1020 else if (msg=="compose()") 1020 else if (msg=="compose()")
1021 { 1021 {
1022 QDialog qd(qApp->activeWindow(),"Getting mail",true); 1022 QDialog qd(qApp->activeWindow(),"Getting mail",true);
1023 1023
1024 WriteMail wm(&qd,"write new mail"); 1024 WriteMail wm(&qd,"write new mail");
1025 QVBoxLayout vbProg( &qd ); 1025 QVBoxLayout vbProg( &qd );
1026 1026
1027 wm.showMaximized(); 1027 wm.showMaximized();
1028 vbProg.addWidget(&wm); 1028 vbProg.addWidget(&wm);
1029 1029
1030 qd.showMaximized(); 1030 qd.showMaximized();
1031 1031
1032 emit composeRequested(); 1032 emit composeRequested();
1033 qd.exec(); 1033 qd.exec();
1034 1034
1035 QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n"); 1035 QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n");
1036 } 1036 }
1037 1037
1038 else if (msg=="dialog()") 1038 else if (msg=="dialog()")
1039 { 1039 {
1040 QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n"); 1040 QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n");
1041 }*/ 1041 }*/
1042} 1042}
diff --git a/noncore/net/mailit/emailhandler.cpp b/noncore/net/mailit/emailhandler.cpp
index 5b8bda1..06e978d 100644
--- a/noncore/net/mailit/emailhandler.cpp
+++ b/noncore/net/mailit/emailhandler.cpp
@@ -1,625 +1,630 @@
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, const QString &)), this, 47 connect(smtpClient, SIGNAL(errorOccurred(int, const QString &)), this,
48 SIGNAL(smtpError(int, const QString &)) ); 48 SIGNAL(smtpError(int, const QString &)) );
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, const QString &)), this, 53 connect(popClient, SIGNAL(errorOccurred(int, const QString &)), this,
54 SIGNAL(popError(int, const QString &)) ); 54 SIGNAL(popError(int, const QString &)) );
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 = QString::null;
75 userName += " <" + mailAccount.emailAddress + ">"; 75 // not supported by ALL SMTP servers in the MAIL From field
76 // userName = "\""+mailAccount.name+"\"";
77 userName += "<" + mailAccount.emailAddress + ">";
76 78
77 for (currentMail = mailList->first(); currentMail != 0; 79 for (currentMail = mailList->first(); currentMail != 0;
78 currentMail = mailList->next()) { 80 currentMail = mailList->next()) {
79 81
80 if (encodeMime(currentMail) == 0) { 82 if (encodeMime(currentMail) == 0) {
81 smtpClient->addMail(userName, currentMail->subject, 83 smtpClient->addMail(userName, currentMail->subject,
82 currentMail->recipients, currentMail->rawMail); 84 currentMail->recipients, currentMail->rawMail);
83 } else { //error 85 } else { //error
84 temp = tr("Could not locate all files in \nmail with subject: ") + 86 temp = tr("Could not locate all files in \nmail with subject: ") +
85 currentMail->subject; 87 currentMail->subject;
86 temp += tr("\nMail has NOT been sent"); 88 temp += tr("\nMail has NOT been sent");
87 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); 89 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n"));
88 90
89 } 91 }
90 } 92 }
91 smtpClient->newConnection(mailAccount.smtpServer, 25); 93 smtpClient->newConnection(mailAccount.smtpServer, 25);
92} 94}
93 95
94void EmailHandler::setAccount(MailAccount account) 96void EmailHandler::setAccount(MailAccount account)
95{ 97{
96 mailAccount = account; 98 mailAccount = account;
97} 99}
98 100
99void EmailHandler::getMail() 101void EmailHandler::getMail()
100{ 102{
101 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); 103 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
102 if (mailAccount.synchronize) { 104 if (mailAccount.synchronize) {
103 popClient->setSynchronize(mailAccount.lastServerMailCount); 105 popClient->setSynchronize(mailAccount.lastServerMailCount);
104 } else { 106 } else {
105 popClient->removeSynchronize(); 107 popClient->removeSynchronize();
106 } 108 }
107 109
108 headers = FALSE; 110 headers = FALSE;
109 //popClient->headersOnly(headers, 0); 111 //popClient->headersOnly(headers, 0);
110 popClient->newConnection(mailAccount.popServer, 110); 112 popClient->newConnection(mailAccount.popServer, 110);
111} 113}
112 114
113void EmailHandler::getMailHeaders() 115void EmailHandler::getMailHeaders()
114{ 116{
115 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); 117 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
116 mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); 118 mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize();
117 119
118 headers = TRUE; 120 headers = TRUE;
119 popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all 121 popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all
120 qDebug("Initiating connection"); 122 qDebug("Initiating connection");
121 popClient->newConnection(mailAccount.popServer, 110); 123 popClient->newConnection(mailAccount.popServer, 110);
122} 124}
123 125
124void EmailHandler::getMailByList(MailList *mailList) 126void EmailHandler::getMailByList(MailList *mailList)
125{ 127{
126 if (mailList->count() == 0) { //should not occur though 128 if (mailList->count() == 0) { //should not occur though
127 emit mailTransfered(0); 129 emit mailTransfered(0);
128 return; 130 return;
129 } 131 }
130 132
131 headers = FALSE; 133 headers = FALSE;
132 popClient->headersOnly(FALSE, 0); 134 popClient->headersOnly(FALSE, 0);
133 135
134 popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd); 136 popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd);
135 popClient->setSelectedMails(mailList); 137 popClient->setSelectedMails(mailList);
136 popClient->newConnection(mailAccount.popServer, 110); 138 popClient->newConnection(mailAccount.popServer, 110);
137 } 139 }
138 140
139void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) 141void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete)
140{ 142{
141 Email mail; 143 Email mail;
142 144
143 mail.rawMail = message; 145 mail.rawMail = message;
144 mail.serverId = id; 146 mail.serverId = id;
145 mail.size = size; 147 mail.size = size;
146 mail.downloaded = complete; 148 mail.downloaded = complete;
147 149
148 emit mailArrived(mail, FALSE); 150 emit mailArrived(mail, FALSE);
149} 151}
150 152
151bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mail) 153bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mail)
152{ 154{
153 QString temp, boundary; 155 QString temp, boundary;
154 int pos; 156 int pos;
155 QString delimiter, header, body, mimeHeader, mimeBody; 157 QString delimiter, header, body, mimeHeader, mimeBody;
156 QString content, contentType, contentAttribute, id, encoding; 158 QString content, contentType, contentAttribute, id, encoding;
157 QString fileName, storedName; 159 QString fileName, storedName;
158 int enclosureId = 0; 160 int enclosureId = 0;
159 161
160 mail->rawMail = in; 162 mail->rawMail = in;
161 mail->received = TRUE; 163 mail->received = TRUE;
162 mail->files.setAutoDelete(TRUE); 164 mail->files.setAutoDelete(TRUE);
163 165
164 temp = lineShift + "." + lineShift; 166 temp = lineShift + "." + lineShift;
165 167
166 if (in.right(temp.length()) != temp) { 168 if (in.right(temp.length()) != temp) {
167 mail->rawMail += temp; 169 mail->rawMail += temp;
168 } 170 }
169 171
170 172
171 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" 173 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n"
172 pos = in.find(delimiter, 0, FALSE); 174 pos = in.find(delimiter, 0, FALSE);
173 header = in.left(pos); 175 header = in.left(pos);
174 body = in.right(in.length() - pos - delimiter.length()); 176 body = in.right(in.length() - pos - delimiter.length());
175 if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) 177 if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n'))
176 body.truncate(body.length()-2); 178 body.truncate(body.length()-2);
177 179
178 // TextParser p(header, lineShift); 180 // TextParser p(header, lineShift);
179 TextParser * lp = new TextParser(header, lineShift); 181 TextParser * lp = new TextParser(header, lineShift);
180#define p (*lp) 182#define p (*lp)
181 183
182 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { 184 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) {
183 pos++; 185 pos++;
184 if (p.separatorAt(pos) == ' ') { 186 if (p.separatorAt(pos) == ' ') {
185 mail->from = p.getString(&pos, '<', false); 187 mail->from = p.getString(&pos, '<', false);
186 mail->from = mail->from.stripWhiteSpace(); 188 mail->from = mail->from.stripWhiteSpace();
187 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { 189 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) {
188 mail->from = mail->from.left(mail->from.length() - 1); 190 mail->from = mail->from.left(mail->from.length() - 1);
189 mail->from = mail->from.right(mail->from.length() - 1); 191 mail->from = mail->from.right(mail->from.length() - 1);
190 } 192 }
191 pos++; 193 pos++;
192 mail->fromMail = p.getString(&pos, '>', false); 194 mail->fromMail = p.getString(&pos, '>', false);
193 } else { 195 } else {
194 if (p.separatorAt(pos) == '<') //No name.. nasty 196 if (p.separatorAt(pos) == '<') //No name.. nasty
195 pos++; 197 pos++;
196 //pos++; 198 //pos++;
197 mail->fromMail = p.getString(&pos, 'z', TRUE); 199 mail->fromMail = p.getString(&pos, 'z', TRUE);
198 if (mail->fromMail.at(mail->fromMail.length()-1) == '>') 200 if (mail->fromMail.at(mail->fromMail.length()-1) == '>')
199 mail->fromMail.truncate(mail->fromMail.length() - 1); 201 mail->fromMail.truncate(mail->fromMail.length() - 1);
200 mail->from=mail->fromMail; 202 mail->from=mail->fromMail;
201 } 203 }
202 } 204 }
203 205
204 pos=0; 206 pos=0;
205 207
206 //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: 208 //Search for To: after the FROM: attribute to prevent hitting the Delivered-To:
207 while((pos = p.find("TO",':', pos+1, TRUE))!=-1) 209 while((pos = p.find("TO",':', pos+1, TRUE))!=-1)
208 { 210 {
209 QString rec; 211 QString rec;
210 212
211 if (p.separatorAt(pos-1)!='-') //The - separator means that this is a Delivered-To: or Reply-To: 213 if (p.separatorAt(pos-1)!='-') //The - separator means that this is a Delivered-To: or Reply-To:
212 { 214 {
213 pos++; 215 pos++;
214 mail->recipients.append(p.getString(&pos, '\r', TRUE)); 216 mail->recipients.append(p.getString(&pos, '\r', TRUE));
215 } 217 }
216 } 218 }
217 // 219 //
218 //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); 220 //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") );
219 221
220 if ((pos = p.find("CC",':', 0, TRUE)) != -1) 222 if ((pos = p.find("CC",':', 0, TRUE)) != -1)
221 { 223 {
222 pos++; 224 pos++;
223 mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); 225 mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) );
224 } 226 }
225 227
226 if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { 228 if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) {
227 pos++; 229 pos++;
228 mail->subject = p.getString(&pos, 'z', TRUE); 230 mail->subject = p.getString(&pos, 'z', TRUE);
229 } 231 }
230 232
231 if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { 233 if ((pos = p.find("DATE",':', 0, TRUE)) != -1) {
232 pos++; 234 pos++;
233 mail->date = p.getString(&pos, 'z', TRUE); 235 mail->date = p.getString(&pos, 'z', TRUE);
234 } 236 }
235 237
236 238
237 239
238 if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { 240 if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) {
239 pos++; 241 pos++;
240 if ( (p.wordAt(pos).upper() == "ID") && 242 if ( (p.wordAt(pos).upper() == "ID") &&
241 (p.separatorAt(pos) == ':') ) { 243 (p.separatorAt(pos) == ':') ) {
242 244
243 id = p.getString(&pos, 'z', TRUE); 245 id = p.getString(&pos, 'z', TRUE);
244 mail->id = id; 246 mail->id = id;
245 } 247 }
246 } 248 }
247 249
248 pos = 0; 250 pos = 0;
249 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { 251 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) {
250 pos++; 252 pos++;
251 if ( (p.wordAt(pos).upper() == "VERSION") && 253 if ( (p.wordAt(pos).upper() == "VERSION") &&
252 (p.separatorAt(pos) == ':') ) { 254 (p.separatorAt(pos) == ':') ) {
253 pos++; 255 pos++;
254 if (p.getString(&pos, 'z', true) == "1.0") { 256 if (p.getString(&pos, 'z', true) == "1.0") {
255 mail->mimeType = 1; 257 mail->mimeType = 1;
256 } 258 }
257 } 259 }
258 } 260 }
259 261
260 if (mail->mimeType == 1) { 262 if (mail->mimeType == 1) {
261 boundary = ""; 263 boundary = "";
262 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { 264 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) {
263 pos++; 265 pos++;
264 boundary = p.getString(&pos, 'z', true); 266 boundary = p.getString(&pos, 'z', true);
265 if (boundary[0] == '"') { 267 if (boundary[0] == '"') {
266 boundary = boundary.left(boundary.length() - 1); //strip " 268 boundary = boundary.left(boundary.length() - 1); //strip "
267 boundary = boundary.right(boundary.length() - 1); //strip " 269 boundary = boundary.right(boundary.length() - 1); //strip "
268 } 270 }
269 boundary = "--" + boundary; //create boundary field 271 boundary = "--" + boundary; //create boundary field
270 } 272 }
271 273
272 if (boundary == "") { //fooled by Mime-Version 274 if (boundary == "") { //fooled by Mime-Version
273 mail->body = body; 275 mail->body = body;
274 mail->bodyPlain = body; 276 mail->bodyPlain = body;
275 delete lp; 277 delete lp;
276 return mail; 278 return mail;
277 } 279 }
278 280
279 while (body.length() > 0) { 281 while (body.length() > 0) {
280 pos = body.find(boundary, 0, FALSE); 282 pos = body.find(boundary, 0, FALSE);
281 pos = body.find(delimiter, pos, FALSE); 283 pos = body.find(delimiter, pos, FALSE);
282 mimeHeader = body.left(pos); 284 mimeHeader = body.left(pos);
283 mimeBody = body.right(body.length() - pos - delimiter.length()); 285 mimeBody = body.right(body.length() - pos - delimiter.length());
284 TextParser bp(mimeHeader, lineShift); 286 TextParser bp(mimeHeader, lineShift);
285 287
286 contentType = ""; 288 contentType = "";
287 contentAttribute = ""; 289 contentAttribute = "";
288 fileName = ""; 290 fileName = "";
289 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) { 291 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) {
290 pos++; 292 pos++;
291 if ( (bp.wordAt(pos).upper() == "TYPE") && 293 if ( (bp.wordAt(pos).upper() == "TYPE") &&
292 (bp.separatorAt(pos) == ':') ) { 294 (bp.separatorAt(pos) == ':') ) {
293 contentType = bp.nextWord().upper(); 295 contentType = bp.nextWord().upper();
294 if (bp.nextSeparator() == '/') 296 if (bp.nextSeparator() == '/')
295 contentAttribute = bp.nextWord().upper(); 297 contentAttribute = bp.nextWord().upper();
296 content = contentType + "/" + contentAttribute; 298 content = contentType + "/" + contentAttribute;
297 } 299 }
298 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) { 300 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) {
299 pos++; 301 pos++;
300 encoding = bp.getString(&pos, 'z', TRUE); 302 encoding = bp.getString(&pos, 'z', TRUE);
301 } 303 }
302 304
303 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) { 305 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) {
304 pos++; 306 pos++;
305 fileName = bp.getString(&pos, 'z', TRUE); 307 fileName = bp.getString(&pos, 'z', TRUE);
306 fileName = fileName.right(fileName.length() - 1); 308 fileName = fileName.right(fileName.length() - 1);
307 fileName = fileName.left(fileName.length() - 1); 309 fileName = fileName.left(fileName.length() - 1);
308 } 310 }
309 311
310 } 312 }
311 pos = mimeBody.find(boundary, 0, FALSE); 313 pos = mimeBody.find(boundary, 0, FALSE);
312 if (pos == -1) //should not occur, malformed mail 314 if (pos == -1) //should not occur, malformed mail
313 pos = mimeBody.length(); 315 pos = mimeBody.length();
314 body = mimeBody.right(mimeBody.length() - pos); 316 body = mimeBody.right(mimeBody.length() - pos);
315 mimeBody = mimeBody.left(pos); 317 mimeBody = mimeBody.left(pos);
316 318
317 if (fileName != "") { //attatchments of some type, audio, image etc. 319 if (fileName != "") { //attatchments of some type, audio, image etc.
318 320
319 Enclosure e; 321 Enclosure e;
320 e.id = enclosureId; 322 e.id = enclosureId;
321 e.originalName = fileName; 323 e.originalName = fileName;
322 e.contentType = contentType; 324 e.contentType = contentType;
323 e.contentAttribute = contentAttribute; 325 e.contentAttribute = contentAttribute;
324 e.encoding = encoding; 326 e.encoding = encoding;
325 e.body = mimeBody; 327 e.body = mimeBody;
326 e.saved = FALSE; 328 e.saved = FALSE;
327 mail->addEnclosure(&e); 329 mail->addEnclosure(&e);
328 enclosureId++; 330 enclosureId++;
329 331
330 } else if (contentType == "TEXT") { 332 } else if (contentType == "TEXT") {
331 if (contentAttribute == "PLAIN") { 333 if (contentAttribute == "PLAIN") {
332 mail->body = mimeBody; 334 mail->body = mimeBody;
333 mail->bodyPlain = mimeBody; 335 mail->bodyPlain = mimeBody;
334 } 336 }
335 if (contentAttribute == "HTML") { 337 if (contentAttribute == "HTML") {
336 mail->body = mimeBody; 338 mail->body = mimeBody;
337 } 339 }
338 } 340 }
339 } 341 }
340 } else { 342 } else {
341 mail->bodyPlain = body; 343 mail->bodyPlain = body;
342 mail->body = body; 344 mail->body = body;
343 } 345 }
344 delete lp; 346 delete lp;
345 return TRUE; 347 return TRUE;
346} 348}
347 349
348bool EmailHandler::getEnclosure(Enclosure *ePtr) 350bool EmailHandler::getEnclosure(Enclosure *ePtr)
349{ 351{
350 QFile f(ePtr->path + ePtr->name); 352 QFile f(ePtr->path + ePtr->name);
351 char src[4]; 353 char src[4];
352 char *destPtr; 354 char *destPtr;
353 QByteArray buffer; 355 QByteArray buffer;
354 uint bufCount, pos, decodedCount, size, x; 356 uint bufCount, pos, decodedCount, size, x;
355 357
356 if (! f.open(IO_WriteOnly) ) { 358 if (! f.open(IO_WriteOnly) ) {
357 qWarning("could not save: " + ePtr->path + ePtr->name); 359 qWarning("could not save: " + ePtr->path + ePtr->name);
358 return FALSE; 360 return FALSE;
359 } 361 }
360 362
361 if (ePtr->encoding.upper() == "BASE64") { 363 if (ePtr->encoding.upper() == "BASE64") {
362 size = (ePtr->body.length() * 3 / 4); //approximate size (always above) 364 size = (ePtr->body.length() * 3 / 4); //approximate size (always above)
363 buffer.resize(size); 365 buffer.resize(size);
364 bufCount = 0; 366 bufCount = 0;
365 pos = 0; 367 pos = 0;
366 destPtr = buffer.data(); 368 destPtr = buffer.data();
367 369
368 while (pos < ePtr->body.length()) { 370 while (pos < ePtr->body.length()) {
369 decodedCount = 4; 371 decodedCount = 4;
370 x = 0; 372 x = 0;
371 while ( (x < 4) && (pos < ePtr->body.length()) ) { 373 while ( (x < 4) && (pos < ePtr->body.length()) ) {
372 src[x] = ePtr->body[pos].latin1(); 374 src[x] = ePtr->body[pos].latin1();
373 pos++; 375 pos++;
374 if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ') 376 if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ')
375 x--; 377 x--;
376 x++; 378 x++;
377 } 379 }
378 if (x > 1) { 380 if (x > 1) {
379 decodedCount = parse64base(src, destPtr); 381 decodedCount = parse64base(src, destPtr);
380 destPtr += decodedCount; 382 destPtr += decodedCount;
381 bufCount += decodedCount; 383 bufCount += decodedCount;
382 } 384 }
383 } 385 }
384 386
385 buffer.resize(bufCount); //set correct length of file 387 buffer.resize(bufCount); //set correct length of file
386 f.writeBlock(buffer); 388 f.writeBlock(buffer);
387 } else { 389 } else {
388 QTextStream t(&f); 390 QTextStream t(&f);
389 t << ePtr->body; 391 t << ePtr->body;
390 } 392 }
391 return TRUE; 393 return TRUE;
392} 394}
393 395
394int EmailHandler::parse64base(char *src, char *bufOut) { 396int EmailHandler::parse64base(char *src, char *bufOut) {
395 397
396 char c, z; 398 char c, z;
397 char li[4]; 399 char li[4];
398 int processed; 400 int processed;
399 401
400 //conversion table withouth table... 402 //conversion table withouth table...
401 for (int x = 0; x < 4; x++) { 403 for (int x = 0; x < 4; x++) {
402 c = src[x]; 404 c = src[x];
403 405
404 if ( (int) c >= 'A' && (int) c <= 'Z') 406 if ( (int) c >= 'A' && (int) c <= 'Z')
405 li[x] = (int) c - (int) 'A'; 407 li[x] = (int) c - (int) 'A';
406 if ( (int) c >= 'a' && (int) c <= 'z') 408 if ( (int) c >= 'a' && (int) c <= 'z')
407 li[x] = (int) c - (int) 'a' + 26; 409 li[x] = (int) c - (int) 'a' + 26;
408 if ( (int) c >= '0' && (int) c <= '9') 410 if ( (int) c >= '0' && (int) c <= '9')
409 li[x] = (int) c - (int) '0' + 52; 411 li[x] = (int) c - (int) '0' + 52;
410 if (c == '+') 412 if (c == '+')
411 li[x] = 62; 413 li[x] = 62;
412 if (c == '/') 414 if (c == '/')
413 li[x] = 63; 415 li[x] = 63;
414 } 416 }
415 417
416 processed = 1; 418 processed = 1;
417 bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits 419 bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits
418 bufOut[0] <<= 2; 420 bufOut[0] <<= 2;
419 z = li[1] >> 4; 421 z = li[1] >> 4;
420 bufOut[0] = bufOut[0] | z; //first byte retrived 422 bufOut[0] = bufOut[0] | z; //first byte retrived
421 423
422 if (src[2] != '=') { 424 if (src[2] != '=') {
423 bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits 425 bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits
424 bufOut[1] <<= 4; 426 bufOut[1] <<= 4;
425 z = li[2] >> 2; 427 z = li[2] >> 2;
426 bufOut[1] = bufOut[1] | z; //second byte retrived 428 bufOut[1] = bufOut[1] | z; //second byte retrived
427 processed++; 429 processed++;
428 430
429 if (src[3] != '=') { 431 if (src[3] != '=') {
430 bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits 432 bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits
431 bufOut[2] <<= 6; 433 bufOut[2] <<= 6;
432 z = li[3]; 434 z = li[3];
433 bufOut[2] = bufOut[2] | z; //third byte retrieved 435 bufOut[2] = bufOut[2] | z; //third byte retrieved
434 processed++; 436 processed++;
435 } 437 }
436 } 438 }
437 return processed; 439 return processed;
438} 440}
439 441
440int EmailHandler::encodeMime(Email *mail) 442int EmailHandler::encodeMime(Email *mail)
441{ 443{
442 444
443 QString fileName, fileType, contentType, newBody, boundary; 445 QString fileName, fileType, contentType, newBody, boundary;
444 Enclosure *ePtr; 446 Enclosure *ePtr;
447 QString userName;
445 448
446 QString userName = mailAccount.name; 449 if ( ! mailAccount.name.isEmpty() ) {
447 if (userName.length()>0) //only embrace it if there is a user name 450 userName = "\"" + mailAccount.name + "\" <" + mailAccount.emailAddress + ">";
448 userName += " <" + mailAccount.emailAddress + ">"; 451 } else {
452 userName = "<" + mailAccount.emailAddress + ">";
453 }
449 454
450 //add standard headers 455 //add standard headers
451 newBody = "From: " + userName + "\r\nTo: "; 456 newBody = "From: " + userName + "\r\nTo: ";
452 for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) { 457 for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) {
453 newBody += *it + " "; 458 newBody += *it + " ";
454 } 459 }
455 460
456 newBody += "\r\nCC: "; 461 newBody += "\r\nCC: ";
457 462
458 for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) { 463 for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) {
459 newBody += *it + " "; 464 newBody += *it + " ";
460 } 465 }
461 466
462 newBody += "\r\nSubject: " + mail->subject + "\r\n"; 467 newBody += "\r\nSubject: " + mail->subject + "\r\n";
463 468
464 if (mail->files.count() == 0) { //just a simple mail 469 if (mail->files.count() == 0) { //just a simple mail
465 newBody += "\r\n" + mail->body; 470 newBody += "\r\n" + mail->body;
466 mail->rawMail = newBody; 471 mail->rawMail = newBody;
467 return 0; 472 return 0;
468 } 473 }
469 474
470 //Build mime encoded mail 475 //Build mime encoded mail
471 boundary = "-----4345=next_bound=0495----"; 476 boundary = "-----4345=next_bound=0495----";
472 477
473 newBody += "Mime-Version: 1.0\r\n"; 478 newBody += "Mime-Version: 1.0\r\n";
474 newBody += "Content-Type: multipart/mixed; boundary=\"" + 479 newBody += "Content-Type: multipart/mixed; boundary=\"" +
475 boundary + "\"\r\n\r\n"; 480 boundary + "\"\r\n\r\n";
476 481
477 newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n"; 482 newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n";
478 newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n"; 483 newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n";
479 newBody += mail->body; 484 newBody += mail->body;
480 485
481 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 486 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
482 fileName = ePtr->originalName; 487 fileName = ePtr->originalName;
483 fileType = ePtr->contentType; 488 fileType = ePtr->contentType;
484 QFileInfo fi(fileName); 489 QFileInfo fi(fileName);
485 490
486 // This specification of contentType is temporary 491 // This specification of contentType is temporary
487 contentType = ""; 492 contentType = "";
488 if (fileType == "Picture") { 493 if (fileType == "Picture") {
489 contentType = "image/x-image"; 494 contentType = "image/x-image";
490 } else if (fileType == "Document") { 495 } else if (fileType == "Document") {
491 contentType = "text/plain"; 496 contentType = "text/plain";
492 } else if (fileType == "Sound") { 497 } else if (fileType == "Sound") {
493 contentType = "audio/x-wav"; 498 contentType = "audio/x-wav";
494 } else if (fileType == "Movie") { 499 } else if (fileType == "Movie") {
495 contentType = "video/mpeg"; 500 contentType = "video/mpeg";
496 } else { 501 } else {
497 contentType = "application/octet-stream"; 502 contentType = "application/octet-stream";
498 } 503 }
499 504
500 newBody += "\r\n\r\n--" + boundary + "\r\n"; 505 newBody += "\r\n\r\n--" + boundary + "\r\n";
501 newBody += "Content-Type: " + contentType + "; name=\"" + 506 newBody += "Content-Type: " + contentType + "; name=\"" +
502 fi.fileName() + "\"\r\n"; 507 fi.fileName() + "\"\r\n";
503 newBody += "Content-Transfer-Encoding: base64\r\n"; 508 newBody += "Content-Transfer-Encoding: base64\r\n";
504 newBody += "Content-Disposition: inline; filename=\"" + 509 newBody += "Content-Disposition: inline; filename=\"" +
505 fi.fileName() + "\"\r\n\r\n"; 510 fi.fileName() + "\"\r\n\r\n";
506 511
507 if (encodeFile(fileName, &newBody) == -1) //file not found? 512 if (encodeFile(fileName, &newBody) == -1) //file not found?
508 return -1; 513 return -1;
509 } 514 }
510 515
511 newBody += "\r\n\r\n--" + boundary + "--"; 516 newBody += "\r\n\r\n--" + boundary + "--";
512 mail->rawMail = newBody; 517 mail->rawMail = newBody;
513 518
514 return 0; 519 return 0;
515} 520}
516 521
517int EmailHandler::encodeFile(const QString &fileName, QString *toBody) 522int EmailHandler::encodeFile(const QString &fileName, QString *toBody)
518{ 523{
519 char *fileData; 524 char *fileData;
520 char *dataPtr; 525 char *dataPtr;
521 QString temp; 526 QString temp;
522 uint dataSize, count; 527 uint dataSize, count;
523 QFile f(fileName); 528 QFile f(fileName);
524 529
525 if (! f.open(IO_ReadOnly) ) { 530 if (! f.open(IO_ReadOnly) ) {
526 qWarning("could not open file: " + fileName); 531 qWarning("could not open file: " + fileName);
527 return -1; 532 return -1;
528 } 533 }
529 QTextStream s(&f); 534 QTextStream s(&f);
530 dataSize = f.size(); 535 dataSize = f.size();
531 fileData = (char *) malloc(dataSize + 3); 536 fileData = (char *) malloc(dataSize + 3);
532 s.readRawBytes(fileData, dataSize); 537 s.readRawBytes(fileData, dataSize);
533 538
534 temp = ""; 539 temp = "";
535 dataPtr = fileData; 540 dataPtr = fileData;
536 count = 0; 541 count = 0;
537 while (dataSize > 0) { 542 while (dataSize > 0) {
538 if (dataSize < 3) { 543 if (dataSize < 3) {
539 encode64base(dataPtr, &temp, dataSize); 544 encode64base(dataPtr, &temp, dataSize);
540 dataSize = 0; 545 dataSize = 0;
541 } else { 546 } else {
542 encode64base(dataPtr, &temp, 3); 547 encode64base(dataPtr, &temp, 3);
543 dataSize -= 3; 548 dataSize -= 3;
544 dataPtr += 3; 549 dataPtr += 3;
545 count += 4; 550 count += 4;
546 } 551 }
547 if (count > 72) { 552 if (count > 72) {
548 count = 0; 553 count = 0;
549 temp += "\r\n"; 554 temp += "\r\n";
550 } 555 }
551 } 556 }
552 toBody->append(temp); 557 toBody->append(temp);
553 558
554 delete(fileData); 559 delete(fileData);
555 f.close(); 560 f.close();
556 return 0; 561 return 0;
557} 562}
558 563
559void EmailHandler::encode64base(char *src, QString *dest, int len) 564void EmailHandler::encode64base(char *src, QString *dest, int len)
560{ 565{
561 QString temp; 566 QString temp;
562 uchar c; 567 uchar c;
563 uchar bufOut[4]; 568 uchar bufOut[4];
564 569
565 bufOut[0] = src[0]; 570 bufOut[0] = src[0];
566 bufOut[0] >>= 2; //Done byte 0 571 bufOut[0] >>= 2; //Done byte 0
567 572
568 bufOut[1] = src[0]; 573 bufOut[1] = src[0];
569 bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits 574 bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits
570 bufOut[1] <<= 4; //copy up 4 places 575 bufOut[1] <<= 4; //copy up 4 places
571 if (len > 1) { 576 if (len > 1) {
572 c = src[1]; 577 c = src[1];
573 } else { 578 } else {
574 c = 0; 579 c = 0;
575 } 580 }
576 581
577 c = c & (16 + 32 + 64 + 128); 582 c = c & (16 + 32 + 64 + 128);
578 c >>= 4; 583 c >>= 4;
579 bufOut[1] = bufOut[1] | c; //Done byte 1 584 bufOut[1] = bufOut[1] | c; //Done byte 1
580 585
581 bufOut[2] = src[1]; 586 bufOut[2] = src[1];
582 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8); 587 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8);
583 bufOut[2] <<= 2; 588 bufOut[2] <<= 2;
584 if (len > 2) { 589 if (len > 2) {
585 c = src[2]; 590 c = src[2];
586 } else { 591 } else {
587 c = 0; 592 c = 0;
588 } 593 }
589 c >>= 6; 594 c >>= 6;
590 bufOut[2] = bufOut[2] | c; 595 bufOut[2] = bufOut[2] | c;
591 596
592 bufOut[3] = src[2]; 597 bufOut[3] = src[2];
593 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32); 598 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32);
594 599
595 if (len == 1) { 600 if (len == 1) {
596 bufOut[2] = 64; 601 bufOut[2] = 64;
597 bufOut[3] = 64; 602 bufOut[3] = 64;
598 } 603 }
599 if (len == 2) { 604 if (len == 2) {
600 bufOut[3] = 64; 605 bufOut[3] = 64;
601 } 606 }
602 for (int x = 0; x < 4; x++) { 607 for (int x = 0; x < 4; x++) {
603 if (bufOut[x] <= 25) 608 if (bufOut[x] <= 25)
604 bufOut[x] += (uint) 'A'; 609 bufOut[x] += (uint) 'A';
605 else if (bufOut[x] >= 26 && bufOut[x] <= 51) 610 else if (bufOut[x] >= 26 && bufOut[x] <= 51)
606 bufOut[x] += (uint) 'a' - 26; 611 bufOut[x] += (uint) 'a' - 26;
607 else if (bufOut[x] >= 52 && bufOut[x] <= 61) 612 else if (bufOut[x] >= 52 && bufOut[x] <= 61)
608 bufOut[x] += (uint) '0' - 52; 613 bufOut[x] += (uint) '0' - 52;
609 else if (bufOut[x] == 62) 614 else if (bufOut[x] == 62)
610 bufOut[x] = '+'; 615 bufOut[x] = '+';
611 else if (bufOut[x] == 63) 616 else if (bufOut[x] == 63)
612 bufOut[x] = '/'; 617 bufOut[x] = '/';
613 else if (bufOut[x] == 64) 618 else if (bufOut[x] == 64)
614 bufOut[x] = '='; 619 bufOut[x] = '=';
615 620
616 dest->append(bufOut[x]); 621 dest->append(bufOut[x]);
617 } 622 }
618} 623}
619 624
620void EmailHandler::cancel() 625void EmailHandler::cancel()
621{ 626{
622 popClient->errorHandling(ErrCancel); 627 popClient->errorHandling(ErrCancel);
623 smtpClient->errorHandling(ErrCancel); 628 smtpClient->errorHandling(ErrCancel);
624} 629}
625 630
diff --git a/noncore/unsupported/mailit/emailclient.cpp b/noncore/unsupported/mailit/emailclient.cpp
index 749a4e9..90664bb 100644
--- a/noncore/unsupported/mailit/emailclient.cpp
+++ b/noncore/unsupported/mailit/emailclient.cpp
@@ -1,1042 +1,1042 @@
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,const QString &)), this, 62 connect(emailHandler, SIGNAL(smtpError(int,const QString &)), this,
63 SLOT(smtpError(int,const QString &)) ); 63 SLOT(smtpError(int,const QString &)) );
64 connect(emailHandler, SIGNAL(popError(int,const QString &)), this, 64 connect(emailHandler, SIGNAL(popError(int,const QString &)), this,
65 SLOT(popError(int,const QString &)) ); 65 SLOT(popError(int,const QString &)) );
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, const QString & Msg) 521void EmailClient::smtpError(int code, const QString & Msg)
522{ 522{
523 QString temp; 523 QString temp;
524 524
525 if (code == ErrUnknownResponse) { 525 if (code == ErrUnknownResponse) {
526 temp = tr("<qt>Unknown response from server</qt>"); 526 temp = tr("<qt>Unknown response from server</qt>");
527 if( ! Msg.isEmpty() ) 527 if( ! Msg.isEmpty() )
528 temp += Msg; 528 temp += Msg;
529 } else if (code == QSocket::ErrHostNotFound) { 529 } else if (code == QSocket::ErrHostNotFound) {
530 temp = tr("<qt>host not found</qt>"); 530 temp = tr("<qt>host not found</qt>");
531 } else if (code == QSocket::ErrConnectionRefused) { 531 } else if (code == QSocket::ErrConnectionRefused) {
532 temp = tr("<qt>connection refused</qt>"); 532 temp = tr("<qt>connection refused</qt>");
533 } else if (code == QSocket::ErrSocketRead) { 533 } else if (code == QSocket::ErrSocketRead) {
534 temp = tr("<qt>socket packet error</qt>"); 534 temp = tr("<qt>socket packet error</qt>");
535 } 535 }
536 536
537 if (code != ErrCancel) { 537 if (code != ErrCancel) {
538 QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); 538 QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n");
539 } else { 539 } else {
540 status2Label->setText("Aborted by user"); 540 status2Label->setText("Aborted by user");
541 } 541 }
542 542
543 sending = FALSE; 543 sending = FALSE;
544 sendMailButton->setEnabled(TRUE); 544 sendMailButton->setEnabled(TRUE);
545 cancelButton->setEnabled(FALSE); 545 cancelButton->setEnabled(FALSE);
546 quedMessages.clear(); 546 quedMessages.clear();
547} 547}
548 548
549void EmailClient::popError(int code, const QString & Msg) 549void EmailClient::popError(int code, const QString & Msg)
550{ 550{
551 QString temp; 551 QString temp;
552 552
553 if (code == ErrUnknownResponse) { 553 if (code == ErrUnknownResponse) {
554 temp = tr("<qt>Unknown response from server</qt>"); 554 temp = tr("<qt>Unknown response from server</qt>");
555 if( ! Msg.isEmpty() ) 555 if( ! Msg.isEmpty() )
556 temp += Msg; 556 temp += Msg;
557 } else if (code == ErrLoginFailed) { 557 } else if (code == ErrLoginFailed) {
558 temp = tr("<qt>Login failed\nCheck user name and password</qt>"); 558 temp = tr("<qt>Login failed\nCheck user name and password</qt>");
559 } else if (code == QSocket::ErrHostNotFound) { 559 } else if (code == QSocket::ErrHostNotFound) {
560 temp = tr("<qt>host not found</qt>"); 560 temp = tr("<qt>host not found</qt>");
561 } else if (code == QSocket::ErrConnectionRefused) { 561 } else if (code == QSocket::ErrConnectionRefused) {
562 temp = tr("<qt>connection refused</qt>"); 562 temp = tr("<qt>connection refused</qt>");
563 } else if (code == QSocket::ErrSocketRead) { 563 } else if (code == QSocket::ErrSocketRead) {
564 temp = tr("<qt>socket packet error</qt>"); 564 temp = tr("<qt>socket packet error</qt>");
565 } 565 }
566 566
567 if (code != ErrCancel) { 567 if (code != ErrCancel) {
568 QMessageBox::warning(qApp->activeWindow(), tr("Receiving error"), temp, tr("OK\n")); 568 QMessageBox::warning(qApp->activeWindow(), tr("Receiving error"), temp, tr("OK\n"));
569 569
570 } else { 570 } else {
571 status2Label->setText("Aborted by user"); 571 status2Label->setText("Aborted by user");
572 } 572 }
573 573
574 receiving = FALSE; 574 receiving = FALSE;
575 getMailButton->setEnabled(TRUE); 575 getMailButton->setEnabled(TRUE);
576 cancelButton->setEnabled(FALSE); 576 cancelButton->setEnabled(FALSE);
577 selectAccountMenu->setEnabled(TRUE); 577 selectAccountMenu->setEnabled(TRUE);
578} 578}
579 579
580void EmailClient::inboxItemSelected() 580void EmailClient::inboxItemSelected()
581{ 581{
582 //killTimer(timerID); 582 //killTimer(timerID);
583 583
584 item = (EmailListItem*) inboxView->selectedItem(); 584 item = (EmailListItem*) inboxView->selectedItem();
585 if (item != NULL) { 585 if (item != NULL) {
586 emit viewEmail(inboxView, item->getMail()); 586 emit viewEmail(inboxView, item->getMail());
587 } 587 }
588} 588}
589 589
590void EmailClient::outboxItemSelected() 590void EmailClient::outboxItemSelected()
591{ 591{
592 //killTimer(timerID); 592 //killTimer(timerID);
593 593
594 item = (EmailListItem*) outboxView->selectedItem(); 594 item = (EmailListItem*) outboxView->selectedItem();
595 if (item != NULL) { 595 if (item != NULL) {
596 emit viewEmail(outboxView, item->getMail()); 596 emit viewEmail(outboxView, item->getMail());
597 } 597 }
598 598
599} 599}
600 600
601void EmailClient::readMail() 601void EmailClient::readMail()
602{ 602{
603 Email mail; 603 Email mail;
604 int start, stop; 604 int start, stop;
605 QString s, del; 605 QString s, del;
606 606
607 QFile f(getPath(FALSE) + "inbox.txt"); 607 QFile f(getPath(FALSE) + "inbox.txt");
608 608
609 if ( f.open(IO_ReadOnly) ) { // file opened successfully 609 if ( f.open(IO_ReadOnly) ) { // file opened successfully
610 QTextStream t( &f ); // use a text stream 610 QTextStream t( &f ); // use a text stream
611 s = t.read(); 611 s = t.read();
612 f.close(); 612 f.close();
613 613
614 start = 0; 614 start = 0;
615 del = "\n.\n"; 615 del = "\n.\n";
616 while ((uint) start < s.length()) { 616 while ((uint) start < s.length()) {
617 stop = s.find(del, start); 617 stop = s.find(del, start);
618 if (stop == -1) 618 if (stop == -1)
619 stop = s.length() - del.length(); 619 stop = s.length() - del.length();
620 620
621 mail.rawMail = s.mid(start, stop + del.length() - start ); 621 mail.rawMail = s.mid(start, stop + del.length() - start );
622 start = stop + del.length(); 622 start = stop + del.length();
623 mailArrived(mail, TRUE); 623 mailArrived(mail, TRUE);
624 } 624 }
625 } 625 }
626 626
627 QFile fo(getPath(FALSE) + "outbox.txt"); 627 QFile fo(getPath(FALSE) + "outbox.txt");
628 if ( fo.open(IO_ReadOnly) ) { // file opened successfully 628 if ( fo.open(IO_ReadOnly) ) { // file opened successfully
629 QTextStream t( &fo ); // use a text stream 629 QTextStream t( &fo ); // use a text stream
630 s = t.read(); 630 s = t.read();
631 fo.close(); 631 fo.close();
632 632
633 start = 0; 633 start = 0;
634 del = "\n.\n"; 634 del = "\n.\n";
635 while ((uint) start < s.length()) { 635 while ((uint) start < s.length()) {
636 stop = s.find(del, start); 636 stop = s.find(del, start);
637 if (stop == -1) 637 if (stop == -1)
638 stop = s.length() - del.length(); 638 stop = s.length() - del.length();
639 639
640 mail.rawMail = s.mid(start, stop + del.length() - start ); 640 mail.rawMail = s.mid(start, stop + del.length() - start );
641 start = stop + del.length(); 641 start = stop + del.length();
642 emailHandler->parse(mail.rawMail, lineShift, &mail); 642 emailHandler->parse(mail.rawMail, lineShift, &mail);
643 mail.sent = false; 643 mail.sent = false;
644 mail.received = false; 644 mail.received = false;
645 enqueMail(mail); 645 enqueMail(mail);
646 646
647 } 647 }
648 } 648 }
649} 649}
650 650
651void EmailClient::saveMail(const QString &fileName, QListView *view) 651void EmailClient::saveMail(const QString &fileName, QListView *view)
652{ 652{
653 QFile f(fileName); 653 QFile f(fileName);
654 Email *mail; 654 Email *mail;
655 655
656 if (! f.open(IO_WriteOnly) ) { 656 if (! f.open(IO_WriteOnly) ) {
657 qWarning("could not open file"); 657 qWarning("could not open file");
658 return; 658 return;
659 } 659 }
660 item = (EmailListItem *) view->firstChild(); 660 item = (EmailListItem *) view->firstChild();
661 QTextStream t(&f); 661 QTextStream t(&f);
662 while (item != NULL) { 662 while (item != NULL) {
663 mail = item->getMail(); 663 mail = item->getMail();
664 t << mail->rawMail; 664 t << mail->rawMail;
665 665
666 mailconf->setGroup(mail->id); 666 mailconf->setGroup(mail->id);
667 mailconf->writeEntry("mailread", mail->read); 667 mailconf->writeEntry("mailread", mail->read);
668 668
669 item = (EmailListItem *) item->nextSibling(); 669 item = (EmailListItem *) item->nextSibling();
670 } 670 }
671 f.close(); 671 f.close();
672} 672}
673 673
674//paths for mailit, is settings, inbox, enclosures 674//paths for mailit, is settings, inbox, enclosures
675QString EmailClient::getPath(bool enclosurePath) 675QString EmailClient::getPath(bool enclosurePath)
676{ 676{
677 QString basePath = "qtmail"; 677 QString basePath = "qtmail";
678 QString enclosures = "enclosures"; 678 QString enclosures = "enclosures";
679 679
680 QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); 680 QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath);
681 if ( !dir.exists() ) 681 if ( !dir.exists() )
682 dir.mkdir( dir.path() ); 682 dir.mkdir( dir.path() );
683 683
684 if (enclosurePath) { 684 if (enclosurePath) {
685 dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); 685 dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures);
686 686
687 if ( !dir.exists() ) 687 if ( !dir.exists() )
688 dir.mkdir( dir.path() ); 688 dir.mkdir( dir.path() );
689 689
690 return (dir.path() + "/"); 690 return (dir.path() + "/");
691 691
692 } 692 }
693 return (dir.path() + "/"); 693 return (dir.path() + "/");
694} 694}
695 695
696void EmailClient::readSettings() 696void EmailClient::readSettings()
697{ 697{
698 int y,acc_count; 698 int y,acc_count;
699 699
700 mailconf->setGroup("mailitglobal"); 700 mailconf->setGroup("mailitglobal");
701 acc_count=mailconf->readNumEntry("Accounts",0); 701 acc_count=mailconf->readNumEntry("Accounts",0);
702 702
703 for (int accountPos = 0;accountPos<acc_count ; accountPos++) 703 for (int accountPos = 0;accountPos<acc_count ; accountPos++)
704 { 704 {
705 mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ... 705 mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ...
706 account.accountName = mailconf->readEntry("AccName",""); 706 account.accountName = mailconf->readEntry("AccName","");
707 account.name = mailconf->readEntry("UserName",""); 707 account.name = mailconf->readEntry("UserName","");
708 account.emailAddress = mailconf->readEntry("Email",""); 708 account.emailAddress = mailconf->readEntry("Email","");
709 account.popUserName = mailconf->readEntry("POPUser",""); 709 account.popUserName = mailconf->readEntry("POPUser","");
710 account.popPasswd = mailconf->readEntryCrypt("POPPassword",""); 710 account.popPasswd = mailconf->readEntryCrypt("POPPassword","");
711 account.popServer = mailconf->readEntry("POPServer",""); 711 account.popServer = mailconf->readEntry("POPServer","");
712 account.smtpServer = mailconf->readEntry("SMTPServer",""); 712 account.smtpServer = mailconf->readEntry("SMTPServer","");
713 account.id = mailconf->readNumEntry("AccountId",0); 713 account.id = mailconf->readNumEntry("AccountId",0);
714 account.syncLimit = mailconf->readNumEntry("HeaderLimit",0); 714 account.syncLimit = mailconf->readNumEntry("HeaderLimit",0);
715 account.lastServerMailCount = 0; 715 account.lastServerMailCount = 0;
716 account.synchronize = FALSE; 716 account.synchronize = FALSE;
717 717
718 account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes"); 718 account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes");
719 if (account.synchronize) 719 if (account.synchronize)
720 { 720 {
721 mailconf->readNumEntry("LASTSERVERMAILCOUNT",0); 721 mailconf->readNumEntry("LASTSERVERMAILCOUNT",0);
722 } 722 }
723 723
724 accountList.append(&account); 724 accountList.append(&account);
725 } 725 }
726 726
727 mailconf->setGroup("mailitglobal"); 727 mailconf->setGroup("mailitglobal");
728 728
729 if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) 729 if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1)
730 { 730 {
731 mailIdCount = y; 731 mailIdCount = y;
732 } 732 }
733 if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) 733 if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1)
734 { 734 {
735 accountIdCount = y; 735 accountIdCount = y;
736 } 736 }
737} 737}
738 738
739void EmailClient::saveSettings() 739void EmailClient::saveSettings()
740{ 740{
741 int acc_count=0; 741 int acc_count=0;
742 MailAccount *accountPtr; 742 MailAccount *accountPtr;
743 743
744 744
745 if (!mailconf) 745 if (!mailconf)
746 { 746 {
747 qWarning("could not save settings"); 747 qWarning("could not save settings");
748 return; 748 return;
749 } 749 }
750 750
751 for (accountPtr = accountList.first(); accountPtr != 0; 751 for (accountPtr = accountList.first(); accountPtr != 0;
752 accountPtr = accountList.next()) 752 accountPtr = accountList.next())
753 { 753 {
754 mailconf->setGroup("Account_"+QString::number(++acc_count)); 754 mailconf->setGroup("Account_"+QString::number(++acc_count));
755 mailconf->writeEntry("AccName",accountPtr->accountName ); 755 mailconf->writeEntry("AccName",accountPtr->accountName );
756 mailconf->writeEntry("UserName",accountPtr->name); 756 mailconf->writeEntry("UserName",accountPtr->name);
757 mailconf->writeEntry("Email",accountPtr->emailAddress); 757 mailconf->writeEntry("Email",accountPtr->emailAddress);
758 mailconf->writeEntry("POPUser",accountPtr->popUserName); 758 mailconf->writeEntry("POPUser",accountPtr->popUserName);
759 mailconf->writeEntryCrypt("POPPassword",accountPtr->popPasswd); 759 mailconf->writeEntryCrypt("POPPassword",accountPtr->popPasswd);
760 mailconf->writeEntry("POPServer",accountPtr->popServer); 760 mailconf->writeEntry("POPServer",accountPtr->popServer);
761 mailconf->writeEntry("SMTPServer",accountPtr->smtpServer); 761 mailconf->writeEntry("SMTPServer",accountPtr->smtpServer);
762 mailconf->writeEntry("AccountId",accountPtr->id); 762 mailconf->writeEntry("AccountId",accountPtr->id);
763 if (accountPtr->synchronize) 763 if (accountPtr->synchronize)
764 { 764 {
765 mailconf->writeEntry("Synchronize","Yes"); 765 mailconf->writeEntry("Synchronize","Yes");
766 mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit); 766 mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit);
767 mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount); 767 mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount);
768 } 768 }
769 else 769 else
770 { 770 {
771 mailconf->writeEntry("Synchronize", "No"); 771 mailconf->writeEntry("Synchronize", "No");
772 } 772 }
773 } 773 }
774 774
775 mailconf->setGroup("mailitglobal"); 775 mailconf->setGroup("mailitglobal");
776 mailconf->writeEntry("Accounts",acc_count); 776 mailconf->writeEntry("Accounts",acc_count);
777 mailconf->writeEntry("mailidcount", mailIdCount); 777 mailconf->writeEntry("mailidcount", mailIdCount);
778 mailconf->writeEntry("accountidcount", accountIdCount); 778 mailconf->writeEntry("accountidcount", accountIdCount);
779} 779}
780 780
781void EmailClient::selectAccount(int id) 781void EmailClient::selectAccount(int id)
782{ 782{
783 if (accountList.count() > 0) { 783 if (accountList.count() > 0) {
784 currentAccount = accountList.at(id); 784 currentAccount = accountList.at(id);
785 emit newCaption("Mailit - " + currentAccount->accountName); 785 emit newCaption("Mailit - " + currentAccount->accountName);
786 getNewMail(); 786 getNewMail();
787 } else { 787 } else {
788 emit newCaption("Mailit ! No account defined"); 788 emit newCaption("Mailit ! No account defined");
789 } 789 }
790} 790}
791 791
792void EmailClient::editAccount(int id) 792void EmailClient::editAccount(int id)
793{ 793{
794 MailAccount *newAccount; 794 MailAccount *newAccount;
795 795
796 editAccountView = new EditAccount(this, "account", TRUE); 796 editAccountView = new EditAccount(this, "account", TRUE);
797 if (id == newAccountId) { //new account 797 if (id == newAccountId) { //new account
798 newAccount = new MailAccount; 798 newAccount = new MailAccount;
799 editAccountView->setAccount(newAccount); 799 editAccountView->setAccount(newAccount);
800 } else { 800 } else {
801 newAccount = accountList.at(id); 801 newAccount = accountList.at(id);
802 editAccountView->setAccount(newAccount, FALSE); 802 editAccountView->setAccount(newAccount, FALSE);
803 } 803 }
804 804
805 editAccountView->showMaximized(); 805 editAccountView->showMaximized();
806 editAccountView->exec(); 806 editAccountView->exec();
807 807
808 if (editAccountView->result() == QDialog::Accepted) { 808 if (editAccountView->result() == QDialog::Accepted) {
809 if (id == newAccountId) { 809 if (id == newAccountId) {
810 newAccount->id = accountIdCount; 810 newAccount->id = accountIdCount;
811 accountIdCount++; 811 accountIdCount++;
812 accountList.append(newAccount); 812 accountList.append(newAccount);
813 updateAccounts(); 813 updateAccounts();
814 } else { 814 } else {
815 updateAccounts(); 815 updateAccounts();
816 } 816 }
817 } 817 }
818 818
819 delete editAccountView; 819 delete editAccountView;
820} 820}
821 821
822void EmailClient::deleteAccount(int id) 822void EmailClient::deleteAccount(int id)
823{ 823{
824 MailAccount *newAccount; 824 MailAccount *newAccount;
825 QString message; 825 QString message;
826 826
827 newAccount = accountList.at(id); 827 newAccount = accountList.at(id);
828 message = "Delete account:\n" + newAccount->accountName; 828 message = "Delete account:\n" + newAccount->accountName;
829 switch( QMessageBox::warning( this, "Mailit", message, 829 switch( QMessageBox::warning( this, "Mailit", message,
830 "Yes", "No", 0, 0, 1 ) ) { 830 "Yes", "No", 0, 0, 1 ) ) {
831 831
832 case 0: accountList.remove(id); 832 case 0: accountList.remove(id);
833 updateAccounts(); 833 updateAccounts();
834 break; 834 break;
835 case 1: 835 case 1:
836 break; 836 break;
837 } 837 }
838} 838}
839 839
840void EmailClient::updateAccounts() 840void EmailClient::updateAccounts()
841{ 841{
842 MailAccount *accountPtr; 842 MailAccount *accountPtr;
843 843
844 //rebuild menus, clear all first 844 //rebuild menus, clear all first
845 editAccountMenu->clear(); 845 editAccountMenu->clear();
846 selectAccountMenu->clear(); 846 selectAccountMenu->clear();
847 deleteAccountMenu->clear(); 847 deleteAccountMenu->clear();
848 848
849 newAccountId = editAccountMenu->insertItem("New", this, 849 newAccountId = editAccountMenu->insertItem("New", this,
850 SLOT(editAccount(int)) ); 850 SLOT(editAccount(int)) );
851 editAccountMenu->insertSeparator(); 851 editAccountMenu->insertSeparator();
852 852
853 idCount = 0; 853 idCount = 0;
854 for (accountPtr = accountList.first(); accountPtr != 0; 854 for (accountPtr = accountList.first(); accountPtr != 0;
855 accountPtr = accountList.next()) { 855 accountPtr = accountList.next()) {
856 856
857 editAccountMenu->insertItem(accountPtr->accountName, 857 editAccountMenu->insertItem(accountPtr->accountName,
858 this, SLOT(editAccount(int)), 0, idCount); 858 this, SLOT(editAccount(int)), 0, idCount);
859 selectAccountMenu->insertItem(accountPtr->accountName, 859 selectAccountMenu->insertItem(accountPtr->accountName,
860 this, SLOT(selectAccount(int)), 0, idCount); 860 this, SLOT(selectAccount(int)), 0, idCount);
861 deleteAccountMenu->insertItem(accountPtr->accountName, 861 deleteAccountMenu->insertItem(accountPtr->accountName,
862 this, SLOT(deleteAccount(int)), 0, idCount); 862 this, SLOT(deleteAccount(int)), 0, idCount);
863 idCount++; 863 idCount++;
864 } 864 }
865} 865}
866 866
867void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) 867void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox)
868{ 868{
869 Email *mPtr; 869 Email *mPtr;
870 Enclosure *ePtr; 870 Enclosure *ePtr;
871 871
872 if (inbox) 872 if (inbox)
873 { 873 {
874 mPtr = mailItem->getMail(); 874 mPtr = mailItem->getMail();
875 875
876 //if mail is in queue for download, remove it from 876 //if mail is in queue for download, remove it from
877 //queue if possible 877 //queue if possible
878 if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { 878 if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) {
879 if ( !mPtr->downloaded ) 879 if ( !mPtr->downloaded )
880 mailDownloadList.remove(mPtr->serverId, mPtr->size); 880 mailDownloadList.remove(mPtr->serverId, mPtr->size);
881 } 881 }
882 882
883 mailconf->setGroup(mPtr->id); 883 mailconf->setGroup(mPtr->id);
884 mailconf->clearGroup(); 884 mailconf->clearGroup();
885 885
886 //delete any temporary attatchemnts storing 886 //delete any temporary attatchemnts storing
887 for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { 887 for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) {
888 if (ePtr->saved) { 888 if (ePtr->saved) {
889 QFile::remove( (ePtr->path + ePtr->name) ); 889 QFile::remove( (ePtr->path + ePtr->name) );
890 } 890 }
891 } 891 }
892 inboxView->takeItem(mailItem); 892 inboxView->takeItem(mailItem);
893 } 893 }
894 else 894 else
895 { 895 {
896 outboxView->takeItem(mailItem); 896 outboxView->takeItem(mailItem);
897 } 897 }
898} 898}
899 899
900void EmailClient::setMailSize(int size) 900void EmailClient::setMailSize(int size)
901{ 901{
902 progressBar->reset(); 902 progressBar->reset();
903 progressBar->setTotalSteps(size); 903 progressBar->setTotalSteps(size);
904} 904}
905 905
906void EmailClient::setTotalSize(int /*size*/) 906void EmailClient::setTotalSize(int /*size*/)
907{ 907{
908 908
909} 909}
910 910
911void EmailClient::setDownloadedSize(int size) 911void EmailClient::setDownloadedSize(int size)
912{ 912{
913 int total = progressBar->totalSteps(); 913 int total = progressBar->totalSteps();
914 914
915 if (size < total) { 915 if (size < total) {
916 progressBar->setProgress(size); 916 progressBar->setProgress(size);
917 } else { 917 } else {
918 progressBar->setProgress(total); 918 progressBar->setProgress(total);
919 } 919 }
920} 920}
921 921
922void EmailClient::deleteItem() 922void EmailClient::deleteItem()
923{ 923{
924 bool inbox=mailboxView->currentTab()==0; 924 bool inbox=mailboxView->currentTab()==0;
925 QListView* box; 925 QListView* box;
926 926
927 EmailListItem* eli; 927 EmailListItem* eli;
928 // int pos; 928 // int pos;
929 929
930 inbox ? box=inboxView : box=outboxView; 930 inbox ? box=inboxView : box=outboxView;
931 931
932 eli=(EmailListItem*)box->selectedItem(); 932 eli=(EmailListItem*)box->selectedItem();
933 933
934 if (eli) 934 if (eli)
935 { 935 {
936 box->setSelected(eli->itemBelow(),true); //select the previous item 936 box->setSelected(eli->itemBelow(),true); //select the previous item
937 937
938 deleteMail(eli,(bool&)inbox); //remove mail entry 938 deleteMail(eli,(bool&)inbox); //remove mail entry
939 } 939 }
940} 940}
941 941
942void EmailClient::inboxItemPressed() 942void EmailClient::inboxItemPressed()
943{ 943{
944// timerID=startTimer(500); 944// timerID=startTimer(500);
945} 945}
946 946
947void EmailClient::inboxItemReleased() 947void EmailClient::inboxItemReleased()
948{ 948{
949 // killTimer(timerID); 949 // killTimer(timerID);
950} 950}
951 951
952/*void EmailClient::timerEvent(QTimerEvent *e) 952/*void EmailClient::timerEvent(QTimerEvent *e)
953{ 953{
954 //killTimer(timerID); 954 //killTimer(timerID);
955 955
956 956
957 QPopupMenu *action = new QPopupMenu(this); 957 QPopupMenu *action = new QPopupMenu(this);
958 958
959 int reply=0; 959 int reply=0;
960 960
961 action->insertItem(tr( "Reply To" ),this,SLOT(reply())); 961 action->insertItem(tr( "Reply To" ),this,SLOT(reply()));
962 action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); 962 action->insertItem( tr( "Reply All" ),this,SLOT(replyAll()));
963 action->insertItem( tr( "Forward" ), this,SLOT(forward())); 963 action->insertItem( tr( "Forward" ), this,SLOT(forward()));
964 action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); 964 action->insertItem( tr( "Remove Mail" ), this,SLOT(remove()));
965 965
966 action->exec(QCursor::pos()); 966 action->exec(QCursor::pos());
967 967
968 if (action) delete action; 968 if (action) delete action;
969 969
970}*/ 970}*/
971 971
972Email* EmailClient::getCurrentMail() 972Email* EmailClient::getCurrentMail()
973{ 973{
974 EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); 974 EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem());
975 if (eli!=NULL) 975 if (eli!=NULL)
976 return eli->getMail(); 976 return eli->getMail();
977 else 977 else
978 return NULL; 978 return NULL;
979} 979}
980 980
981void EmailClient::download(Email* mail) 981void EmailClient::download(Email* mail)
982{ 982{
983 MailAccount* acc=0; 983 MailAccount* acc=0;
984 984
985 tempMailDownloadList.clear(); 985 tempMailDownloadList.clear();
986 tempMailDownloadList.sizeInsert(mail->serverId, mail->size); 986 tempMailDownloadList.sizeInsert(mail->serverId, mail->size);
987 987
988 acc=accountList.at(mail->fromAccountId-1); 988 acc=accountList.at(mail->fromAccountId-1);
989 if (acc) 989 if (acc)
990 { 990 {
991 emailHandler->setAccount(*acc); 991 emailHandler->setAccount(*acc);
992 emailHandler->getMailByList(&tempMailDownloadList); 992 emailHandler->getMailByList(&tempMailDownloadList);
993 } 993 }
994 else 994 else
995 QMessageBox::warning(qApp->activeWindow(), 995 QMessageBox::warning(qApp->activeWindow(),
996 tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n"); 996 tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n");
997} 997}
998 998
999void EmailClient::receive(const QCString& /*msg*/, const QByteArray& /*data*/) 999void EmailClient::receive(const QCString& /*msg*/, const QByteArray& /*data*/)
1000{ 1000{
1001 /*if (msg=="getMail()") 1001 /*if (msg=="getMail()")
1002 { 1002 {
1003 //QDialog qd(qApp->activeWindow(),"Getting mail",true); 1003 //QDialog qd(qApp->activeWindow(),"Getting mail",true);
1004 QVBoxLayout *vbProg = new QVBoxLayout( &qd ); 1004 QVBoxLayout *vbProg = new QVBoxLayout( &qd );
1005 1005
1006 initStatusBar(&qd); 1006 initStatusBar(&qd);
1007 1007
1008 if (statusBar==0) 1008 if (statusBar==0)
1009 { 1009 {
1010 qDebug("No Bar ..."); 1010 qDebug("No Bar ...");
1011 //statusBar=new ProgressBar(&qd); 1011 //statusBar=new ProgressBar(&qd);
1012 } 1012 }
1013 statusBar->show(); 1013 statusBar->show();
1014 vbProg->addWidget(statusBar); 1014 vbProg->addWidget(statusBar);
1015 qd.showMaximized(); 1015 qd.showMaximized();
1016 qd.show(); 1016 qd.show();
1017 emit getAllNewMail(); 1017 emit getAllNewMail();
1018 //qd.exec(); 1018 //qd.exec();
1019 } 1019 }
1020 else if (msg=="compose()") 1020 else if (msg=="compose()")
1021 { 1021 {
1022 QDialog qd(qApp->activeWindow(),"Getting mail",true); 1022 QDialog qd(qApp->activeWindow(),"Getting mail",true);
1023 1023
1024 WriteMail wm(&qd,"write new mail"); 1024 WriteMail wm(&qd,"write new mail");
1025 QVBoxLayout vbProg( &qd ); 1025 QVBoxLayout vbProg( &qd );
1026 1026
1027 wm.showMaximized(); 1027 wm.showMaximized();
1028 vbProg.addWidget(&wm); 1028 vbProg.addWidget(&wm);
1029 1029
1030 qd.showMaximized(); 1030 qd.showMaximized();
1031 1031
1032 emit composeRequested(); 1032 emit composeRequested();
1033 qd.exec(); 1033 qd.exec();
1034 1034
1035 QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n"); 1035 QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n");
1036 } 1036 }
1037 1037
1038 else if (msg=="dialog()") 1038 else if (msg=="dialog()")
1039 { 1039 {
1040 QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n"); 1040 QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n");
1041 }*/ 1041 }*/
1042} 1042}
diff --git a/noncore/unsupported/mailit/emailhandler.cpp b/noncore/unsupported/mailit/emailhandler.cpp
index 5b8bda1..06e978d 100644
--- a/noncore/unsupported/mailit/emailhandler.cpp
+++ b/noncore/unsupported/mailit/emailhandler.cpp
@@ -1,625 +1,630 @@
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, const QString &)), this, 47 connect(smtpClient, SIGNAL(errorOccurred(int, const QString &)), this,
48 SIGNAL(smtpError(int, const QString &)) ); 48 SIGNAL(smtpError(int, const QString &)) );
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, const QString &)), this, 53 connect(popClient, SIGNAL(errorOccurred(int, const QString &)), this,
54 SIGNAL(popError(int, const QString &)) ); 54 SIGNAL(popError(int, const QString &)) );
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 = QString::null;
75 userName += " <" + mailAccount.emailAddress + ">"; 75 // not supported by ALL SMTP servers in the MAIL From field
76 // userName = "\""+mailAccount.name+"\"";
77 userName += "<" + mailAccount.emailAddress + ">";
76 78
77 for (currentMail = mailList->first(); currentMail != 0; 79 for (currentMail = mailList->first(); currentMail != 0;
78 currentMail = mailList->next()) { 80 currentMail = mailList->next()) {
79 81
80 if (encodeMime(currentMail) == 0) { 82 if (encodeMime(currentMail) == 0) {
81 smtpClient->addMail(userName, currentMail->subject, 83 smtpClient->addMail(userName, currentMail->subject,
82 currentMail->recipients, currentMail->rawMail); 84 currentMail->recipients, currentMail->rawMail);
83 } else { //error 85 } else { //error
84 temp = tr("Could not locate all files in \nmail with subject: ") + 86 temp = tr("Could not locate all files in \nmail with subject: ") +
85 currentMail->subject; 87 currentMail->subject;
86 temp += tr("\nMail has NOT been sent"); 88 temp += tr("\nMail has NOT been sent");
87 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); 89 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n"));
88 90
89 } 91 }
90 } 92 }
91 smtpClient->newConnection(mailAccount.smtpServer, 25); 93 smtpClient->newConnection(mailAccount.smtpServer, 25);
92} 94}
93 95
94void EmailHandler::setAccount(MailAccount account) 96void EmailHandler::setAccount(MailAccount account)
95{ 97{
96 mailAccount = account; 98 mailAccount = account;
97} 99}
98 100
99void EmailHandler::getMail() 101void EmailHandler::getMail()
100{ 102{
101 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); 103 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
102 if (mailAccount.synchronize) { 104 if (mailAccount.synchronize) {
103 popClient->setSynchronize(mailAccount.lastServerMailCount); 105 popClient->setSynchronize(mailAccount.lastServerMailCount);
104 } else { 106 } else {
105 popClient->removeSynchronize(); 107 popClient->removeSynchronize();
106 } 108 }
107 109
108 headers = FALSE; 110 headers = FALSE;
109 //popClient->headersOnly(headers, 0); 111 //popClient->headersOnly(headers, 0);
110 popClient->newConnection(mailAccount.popServer, 110); 112 popClient->newConnection(mailAccount.popServer, 110);
111} 113}
112 114
113void EmailHandler::getMailHeaders() 115void EmailHandler::getMailHeaders()
114{ 116{
115 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); 117 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
116 mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); 118 mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize();
117 119
118 headers = TRUE; 120 headers = TRUE;
119 popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all 121 popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all
120 qDebug("Initiating connection"); 122 qDebug("Initiating connection");
121 popClient->newConnection(mailAccount.popServer, 110); 123 popClient->newConnection(mailAccount.popServer, 110);
122} 124}
123 125
124void EmailHandler::getMailByList(MailList *mailList) 126void EmailHandler::getMailByList(MailList *mailList)
125{ 127{
126 if (mailList->count() == 0) { //should not occur though 128 if (mailList->count() == 0) { //should not occur though
127 emit mailTransfered(0); 129 emit mailTransfered(0);
128 return; 130 return;
129 } 131 }
130 132
131 headers = FALSE; 133 headers = FALSE;
132 popClient->headersOnly(FALSE, 0); 134 popClient->headersOnly(FALSE, 0);
133 135
134 popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd); 136 popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd);
135 popClient->setSelectedMails(mailList); 137 popClient->setSelectedMails(mailList);
136 popClient->newConnection(mailAccount.popServer, 110); 138 popClient->newConnection(mailAccount.popServer, 110);
137 } 139 }
138 140
139void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) 141void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete)
140{ 142{
141 Email mail; 143 Email mail;
142 144
143 mail.rawMail = message; 145 mail.rawMail = message;
144 mail.serverId = id; 146 mail.serverId = id;
145 mail.size = size; 147 mail.size = size;
146 mail.downloaded = complete; 148 mail.downloaded = complete;
147 149
148 emit mailArrived(mail, FALSE); 150 emit mailArrived(mail, FALSE);
149} 151}
150 152
151bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mail) 153bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mail)
152{ 154{
153 QString temp, boundary; 155 QString temp, boundary;
154 int pos; 156 int pos;
155 QString delimiter, header, body, mimeHeader, mimeBody; 157 QString delimiter, header, body, mimeHeader, mimeBody;
156 QString content, contentType, contentAttribute, id, encoding; 158 QString content, contentType, contentAttribute, id, encoding;
157 QString fileName, storedName; 159 QString fileName, storedName;
158 int enclosureId = 0; 160 int enclosureId = 0;
159 161
160 mail->rawMail = in; 162 mail->rawMail = in;
161 mail->received = TRUE; 163 mail->received = TRUE;
162 mail->files.setAutoDelete(TRUE); 164 mail->files.setAutoDelete(TRUE);
163 165
164 temp = lineShift + "." + lineShift; 166 temp = lineShift + "." + lineShift;
165 167
166 if (in.right(temp.length()) != temp) { 168 if (in.right(temp.length()) != temp) {
167 mail->rawMail += temp; 169 mail->rawMail += temp;
168 } 170 }
169 171
170 172
171 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" 173 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n"
172 pos = in.find(delimiter, 0, FALSE); 174 pos = in.find(delimiter, 0, FALSE);
173 header = in.left(pos); 175 header = in.left(pos);
174 body = in.right(in.length() - pos - delimiter.length()); 176 body = in.right(in.length() - pos - delimiter.length());
175 if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) 177 if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n'))
176 body.truncate(body.length()-2); 178 body.truncate(body.length()-2);
177 179
178 // TextParser p(header, lineShift); 180 // TextParser p(header, lineShift);
179 TextParser * lp = new TextParser(header, lineShift); 181 TextParser * lp = new TextParser(header, lineShift);
180#define p (*lp) 182#define p (*lp)
181 183
182 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { 184 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) {
183 pos++; 185 pos++;
184 if (p.separatorAt(pos) == ' ') { 186 if (p.separatorAt(pos) == ' ') {
185 mail->from = p.getString(&pos, '<', false); 187 mail->from = p.getString(&pos, '<', false);
186 mail->from = mail->from.stripWhiteSpace(); 188 mail->from = mail->from.stripWhiteSpace();
187 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { 189 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) {
188 mail->from = mail->from.left(mail->from.length() - 1); 190 mail->from = mail->from.left(mail->from.length() - 1);
189 mail->from = mail->from.right(mail->from.length() - 1); 191 mail->from = mail->from.right(mail->from.length() - 1);
190 } 192 }
191 pos++; 193 pos++;
192 mail->fromMail = p.getString(&pos, '>', false); 194 mail->fromMail = p.getString(&pos, '>', false);
193 } else { 195 } else {
194 if (p.separatorAt(pos) == '<') //No name.. nasty 196 if (p.separatorAt(pos) == '<') //No name.. nasty
195 pos++; 197 pos++;
196 //pos++; 198 //pos++;
197 mail->fromMail = p.getString(&pos, 'z', TRUE); 199 mail->fromMail = p.getString(&pos, 'z', TRUE);
198 if (mail->fromMail.at(mail->fromMail.length()-1) == '>') 200 if (mail->fromMail.at(mail->fromMail.length()-1) == '>')
199 mail->fromMail.truncate(mail->fromMail.length() - 1); 201 mail->fromMail.truncate(mail->fromMail.length() - 1);
200 mail->from=mail->fromMail; 202 mail->from=mail->fromMail;
201 } 203 }
202 } 204 }
203 205
204 pos=0; 206 pos=0;
205 207
206 //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: 208 //Search for To: after the FROM: attribute to prevent hitting the Delivered-To:
207 while((pos = p.find("TO",':', pos+1, TRUE))!=-1) 209 while((pos = p.find("TO",':', pos+1, TRUE))!=-1)
208 { 210 {
209 QString rec; 211 QString rec;
210 212
211 if (p.separatorAt(pos-1)!='-') //The - separator means that this is a Delivered-To: or Reply-To: 213 if (p.separatorAt(pos-1)!='-') //The - separator means that this is a Delivered-To: or Reply-To:
212 { 214 {
213 pos++; 215 pos++;
214 mail->recipients.append(p.getString(&pos, '\r', TRUE)); 216 mail->recipients.append(p.getString(&pos, '\r', TRUE));
215 } 217 }
216 } 218 }
217 // 219 //
218 //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); 220 //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") );
219 221
220 if ((pos = p.find("CC",':', 0, TRUE)) != -1) 222 if ((pos = p.find("CC",':', 0, TRUE)) != -1)
221 { 223 {
222 pos++; 224 pos++;
223 mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); 225 mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) );
224 } 226 }
225 227
226 if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { 228 if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) {
227 pos++; 229 pos++;
228 mail->subject = p.getString(&pos, 'z', TRUE); 230 mail->subject = p.getString(&pos, 'z', TRUE);
229 } 231 }
230 232
231 if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { 233 if ((pos = p.find("DATE",':', 0, TRUE)) != -1) {
232 pos++; 234 pos++;
233 mail->date = p.getString(&pos, 'z', TRUE); 235 mail->date = p.getString(&pos, 'z', TRUE);
234 } 236 }
235 237
236 238
237 239
238 if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { 240 if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) {
239 pos++; 241 pos++;
240 if ( (p.wordAt(pos).upper() == "ID") && 242 if ( (p.wordAt(pos).upper() == "ID") &&
241 (p.separatorAt(pos) == ':') ) { 243 (p.separatorAt(pos) == ':') ) {
242 244
243 id = p.getString(&pos, 'z', TRUE); 245 id = p.getString(&pos, 'z', TRUE);
244 mail->id = id; 246 mail->id = id;
245 } 247 }
246 } 248 }
247 249
248 pos = 0; 250 pos = 0;
249 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { 251 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) {
250 pos++; 252 pos++;
251 if ( (p.wordAt(pos).upper() == "VERSION") && 253 if ( (p.wordAt(pos).upper() == "VERSION") &&
252 (p.separatorAt(pos) == ':') ) { 254 (p.separatorAt(pos) == ':') ) {
253 pos++; 255 pos++;
254 if (p.getString(&pos, 'z', true) == "1.0") { 256 if (p.getString(&pos, 'z', true) == "1.0") {
255 mail->mimeType = 1; 257 mail->mimeType = 1;
256 } 258 }
257 } 259 }
258 } 260 }
259 261
260 if (mail->mimeType == 1) { 262 if (mail->mimeType == 1) {
261 boundary = ""; 263 boundary = "";
262 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { 264 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) {
263 pos++; 265 pos++;
264 boundary = p.getString(&pos, 'z', true); 266 boundary = p.getString(&pos, 'z', true);
265 if (boundary[0] == '"') { 267 if (boundary[0] == '"') {
266 boundary = boundary.left(boundary.length() - 1); //strip " 268 boundary = boundary.left(boundary.length() - 1); //strip "
267 boundary = boundary.right(boundary.length() - 1); //strip " 269 boundary = boundary.right(boundary.length() - 1); //strip "
268 } 270 }
269 boundary = "--" + boundary; //create boundary field 271 boundary = "--" + boundary; //create boundary field
270 } 272 }
271 273
272 if (boundary == "") { //fooled by Mime-Version 274 if (boundary == "") { //fooled by Mime-Version
273 mail->body = body; 275 mail->body = body;
274 mail->bodyPlain = body; 276 mail->bodyPlain = body;
275 delete lp; 277 delete lp;
276 return mail; 278 return mail;
277 } 279 }
278 280
279 while (body.length() > 0) { 281 while (body.length() > 0) {
280 pos = body.find(boundary, 0, FALSE); 282 pos = body.find(boundary, 0, FALSE);
281 pos = body.find(delimiter, pos, FALSE); 283 pos = body.find(delimiter, pos, FALSE);
282 mimeHeader = body.left(pos); 284 mimeHeader = body.left(pos);
283 mimeBody = body.right(body.length() - pos - delimiter.length()); 285 mimeBody = body.right(body.length() - pos - delimiter.length());
284 TextParser bp(mimeHeader, lineShift); 286 TextParser bp(mimeHeader, lineShift);
285 287
286 contentType = ""; 288 contentType = "";
287 contentAttribute = ""; 289 contentAttribute = "";
288 fileName = ""; 290 fileName = "";
289 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) { 291 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) {
290 pos++; 292 pos++;
291 if ( (bp.wordAt(pos).upper() == "TYPE") && 293 if ( (bp.wordAt(pos).upper() == "TYPE") &&
292 (bp.separatorAt(pos) == ':') ) { 294 (bp.separatorAt(pos) == ':') ) {
293 contentType = bp.nextWord().upper(); 295 contentType = bp.nextWord().upper();
294 if (bp.nextSeparator() == '/') 296 if (bp.nextSeparator() == '/')
295 contentAttribute = bp.nextWord().upper(); 297 contentAttribute = bp.nextWord().upper();
296 content = contentType + "/" + contentAttribute; 298 content = contentType + "/" + contentAttribute;
297 } 299 }
298 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) { 300 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) {
299 pos++; 301 pos++;
300 encoding = bp.getString(&pos, 'z', TRUE); 302 encoding = bp.getString(&pos, 'z', TRUE);
301 } 303 }
302 304
303 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) { 305 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) {
304 pos++; 306 pos++;
305 fileName = bp.getString(&pos, 'z', TRUE); 307 fileName = bp.getString(&pos, 'z', TRUE);
306 fileName = fileName.right(fileName.length() - 1); 308 fileName = fileName.right(fileName.length() - 1);
307 fileName = fileName.left(fileName.length() - 1); 309 fileName = fileName.left(fileName.length() - 1);
308 } 310 }
309 311
310 } 312 }
311 pos = mimeBody.find(boundary, 0, FALSE); 313 pos = mimeBody.find(boundary, 0, FALSE);
312 if (pos == -1) //should not occur, malformed mail 314 if (pos == -1) //should not occur, malformed mail
313 pos = mimeBody.length(); 315 pos = mimeBody.length();
314 body = mimeBody.right(mimeBody.length() - pos); 316 body = mimeBody.right(mimeBody.length() - pos);
315 mimeBody = mimeBody.left(pos); 317 mimeBody = mimeBody.left(pos);
316 318
317 if (fileName != "") { //attatchments of some type, audio, image etc. 319 if (fileName != "") { //attatchments of some type, audio, image etc.
318 320
319 Enclosure e; 321 Enclosure e;
320 e.id = enclosureId; 322 e.id = enclosureId;
321 e.originalName = fileName; 323 e.originalName = fileName;
322 e.contentType = contentType; 324 e.contentType = contentType;
323 e.contentAttribute = contentAttribute; 325 e.contentAttribute = contentAttribute;
324 e.encoding = encoding; 326 e.encoding = encoding;
325 e.body = mimeBody; 327 e.body = mimeBody;
326 e.saved = FALSE; 328 e.saved = FALSE;
327 mail->addEnclosure(&e); 329 mail->addEnclosure(&e);
328 enclosureId++; 330 enclosureId++;
329 331
330 } else if (contentType == "TEXT") { 332 } else if (contentType == "TEXT") {
331 if (contentAttribute == "PLAIN") { 333 if (contentAttribute == "PLAIN") {
332 mail->body = mimeBody; 334 mail->body = mimeBody;
333 mail->bodyPlain = mimeBody; 335 mail->bodyPlain = mimeBody;
334 } 336 }
335 if (contentAttribute == "HTML") { 337 if (contentAttribute == "HTML") {
336 mail->body = mimeBody; 338 mail->body = mimeBody;
337 } 339 }
338 } 340 }
339 } 341 }
340 } else { 342 } else {
341 mail->bodyPlain = body; 343 mail->bodyPlain = body;
342 mail->body = body; 344 mail->body = body;
343 } 345 }
344 delete lp; 346 delete lp;
345 return TRUE; 347 return TRUE;
346} 348}
347 349
348bool EmailHandler::getEnclosure(Enclosure *ePtr) 350bool EmailHandler::getEnclosure(Enclosure *ePtr)
349{ 351{
350 QFile f(ePtr->path + ePtr->name); 352 QFile f(ePtr->path + ePtr->name);
351 char src[4]; 353 char src[4];
352 char *destPtr; 354 char *destPtr;
353 QByteArray buffer; 355 QByteArray buffer;
354 uint bufCount, pos, decodedCount, size, x; 356 uint bufCount, pos, decodedCount, size, x;
355 357
356 if (! f.open(IO_WriteOnly) ) { 358 if (! f.open(IO_WriteOnly) ) {
357 qWarning("could not save: " + ePtr->path + ePtr->name); 359 qWarning("could not save: " + ePtr->path + ePtr->name);
358 return FALSE; 360 return FALSE;
359 } 361 }
360 362
361 if (ePtr->encoding.upper() == "BASE64") { 363 if (ePtr->encoding.upper() == "BASE64") {
362 size = (ePtr->body.length() * 3 / 4); //approximate size (always above) 364 size = (ePtr->body.length() * 3 / 4); //approximate size (always above)
363 buffer.resize(size); 365 buffer.resize(size);
364 bufCount = 0; 366 bufCount = 0;
365 pos = 0; 367 pos = 0;
366 destPtr = buffer.data(); 368 destPtr = buffer.data();
367 369
368 while (pos < ePtr->body.length()) { 370 while (pos < ePtr->body.length()) {
369 decodedCount = 4; 371 decodedCount = 4;
370 x = 0; 372 x = 0;
371 while ( (x < 4) && (pos < ePtr->body.length()) ) { 373 while ( (x < 4) && (pos < ePtr->body.length()) ) {
372 src[x] = ePtr->body[pos].latin1(); 374 src[x] = ePtr->body[pos].latin1();
373 pos++; 375 pos++;
374 if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ') 376 if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ')
375 x--; 377 x--;
376 x++; 378 x++;
377 } 379 }
378 if (x > 1) { 380 if (x > 1) {
379 decodedCount = parse64base(src, destPtr); 381 decodedCount = parse64base(src, destPtr);
380 destPtr += decodedCount; 382 destPtr += decodedCount;
381 bufCount += decodedCount; 383 bufCount += decodedCount;
382 } 384 }
383 } 385 }
384 386
385 buffer.resize(bufCount); //set correct length of file 387 buffer.resize(bufCount); //set correct length of file
386 f.writeBlock(buffer); 388 f.writeBlock(buffer);
387 } else { 389 } else {
388 QTextStream t(&f); 390 QTextStream t(&f);
389 t << ePtr->body; 391 t << ePtr->body;
390 } 392 }
391 return TRUE; 393 return TRUE;
392} 394}
393 395
394int EmailHandler::parse64base(char *src, char *bufOut) { 396int EmailHandler::parse64base(char *src, char *bufOut) {
395 397
396 char c, z; 398 char c, z;
397 char li[4]; 399 char li[4];
398 int processed; 400 int processed;
399 401
400 //conversion table withouth table... 402 //conversion table withouth table...
401 for (int x = 0; x < 4; x++) { 403 for (int x = 0; x < 4; x++) {
402 c = src[x]; 404 c = src[x];
403 405
404 if ( (int) c >= 'A' && (int) c <= 'Z') 406 if ( (int) c >= 'A' && (int) c <= 'Z')
405 li[x] = (int) c - (int) 'A'; 407 li[x] = (int) c - (int) 'A';
406 if ( (int) c >= 'a' && (int) c <= 'z') 408 if ( (int) c >= 'a' && (int) c <= 'z')
407 li[x] = (int) c - (int) 'a' + 26; 409 li[x] = (int) c - (int) 'a' + 26;
408 if ( (int) c >= '0' && (int) c <= '9') 410 if ( (int) c >= '0' && (int) c <= '9')
409 li[x] = (int) c - (int) '0' + 52; 411 li[x] = (int) c - (int) '0' + 52;
410 if (c == '+') 412 if (c == '+')
411 li[x] = 62; 413 li[x] = 62;
412 if (c == '/') 414 if (c == '/')
413 li[x] = 63; 415 li[x] = 63;
414 } 416 }
415 417
416 processed = 1; 418 processed = 1;
417 bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits 419 bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits
418 bufOut[0] <<= 2; 420 bufOut[0] <<= 2;
419 z = li[1] >> 4; 421 z = li[1] >> 4;
420 bufOut[0] = bufOut[0] | z; //first byte retrived 422 bufOut[0] = bufOut[0] | z; //first byte retrived
421 423
422 if (src[2] != '=') { 424 if (src[2] != '=') {
423 bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits 425 bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits
424 bufOut[1] <<= 4; 426 bufOut[1] <<= 4;
425 z = li[2] >> 2; 427 z = li[2] >> 2;
426 bufOut[1] = bufOut[1] | z; //second byte retrived 428 bufOut[1] = bufOut[1] | z; //second byte retrived
427 processed++; 429 processed++;
428 430
429 if (src[3] != '=') { 431 if (src[3] != '=') {
430 bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits 432 bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits
431 bufOut[2] <<= 6; 433 bufOut[2] <<= 6;
432 z = li[3]; 434 z = li[3];
433 bufOut[2] = bufOut[2] | z; //third byte retrieved 435 bufOut[2] = bufOut[2] | z; //third byte retrieved
434 processed++; 436 processed++;
435 } 437 }
436 } 438 }
437 return processed; 439 return processed;
438} 440}
439 441
440int EmailHandler::encodeMime(Email *mail) 442int EmailHandler::encodeMime(Email *mail)
441{ 443{
442 444
443 QString fileName, fileType, contentType, newBody, boundary; 445 QString fileName, fileType, contentType, newBody, boundary;
444 Enclosure *ePtr; 446 Enclosure *ePtr;
447 QString userName;
445 448
446 QString userName = mailAccount.name; 449 if ( ! mailAccount.name.isEmpty() ) {
447 if (userName.length()>0) //only embrace it if there is a user name 450 userName = "\"" + mailAccount.name + "\" <" + mailAccount.emailAddress + ">";
448 userName += " <" + mailAccount.emailAddress + ">"; 451 } else {
452 userName = "<" + mailAccount.emailAddress + ">";
453 }
449 454
450 //add standard headers 455 //add standard headers
451 newBody = "From: " + userName + "\r\nTo: "; 456 newBody = "From: " + userName + "\r\nTo: ";
452 for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) { 457 for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) {
453 newBody += *it + " "; 458 newBody += *it + " ";
454 } 459 }
455 460
456 newBody += "\r\nCC: "; 461 newBody += "\r\nCC: ";
457 462
458 for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) { 463 for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) {
459 newBody += *it + " "; 464 newBody += *it + " ";
460 } 465 }
461 466
462 newBody += "\r\nSubject: " + mail->subject + "\r\n"; 467 newBody += "\r\nSubject: " + mail->subject + "\r\n";
463 468
464 if (mail->files.count() == 0) { //just a simple mail 469 if (mail->files.count() == 0) { //just a simple mail
465 newBody += "\r\n" + mail->body; 470 newBody += "\r\n" + mail->body;
466 mail->rawMail = newBody; 471 mail->rawMail = newBody;
467 return 0; 472 return 0;
468 } 473 }
469 474
470 //Build mime encoded mail 475 //Build mime encoded mail
471 boundary = "-----4345=next_bound=0495----"; 476 boundary = "-----4345=next_bound=0495----";
472 477
473 newBody += "Mime-Version: 1.0\r\n"; 478 newBody += "Mime-Version: 1.0\r\n";
474 newBody += "Content-Type: multipart/mixed; boundary=\"" + 479 newBody += "Content-Type: multipart/mixed; boundary=\"" +
475 boundary + "\"\r\n\r\n"; 480 boundary + "\"\r\n\r\n";
476 481
477 newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n"; 482 newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n";
478 newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n"; 483 newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n";
479 newBody += mail->body; 484 newBody += mail->body;
480 485
481 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 486 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
482 fileName = ePtr->originalName; 487 fileName = ePtr->originalName;
483 fileType = ePtr->contentType; 488 fileType = ePtr->contentType;
484 QFileInfo fi(fileName); 489 QFileInfo fi(fileName);
485 490
486 // This specification of contentType is temporary 491 // This specification of contentType is temporary
487 contentType = ""; 492 contentType = "";
488 if (fileType == "Picture") { 493 if (fileType == "Picture") {
489 contentType = "image/x-image"; 494 contentType = "image/x-image";
490 } else if (fileType == "Document") { 495 } else if (fileType == "Document") {
491 contentType = "text/plain"; 496 contentType = "text/plain";
492 } else if (fileType == "Sound") { 497 } else if (fileType == "Sound") {
493 contentType = "audio/x-wav"; 498 contentType = "audio/x-wav";
494 } else if (fileType == "Movie") { 499 } else if (fileType == "Movie") {
495 contentType = "video/mpeg"; 500 contentType = "video/mpeg";
496 } else { 501 } else {
497 contentType = "application/octet-stream"; 502 contentType = "application/octet-stream";
498 } 503 }
499 504
500 newBody += "\r\n\r\n--" + boundary + "\r\n"; 505 newBody += "\r\n\r\n--" + boundary + "\r\n";
501 newBody += "Content-Type: " + contentType + "; name=\"" + 506 newBody += "Content-Type: " + contentType + "; name=\"" +
502 fi.fileName() + "\"\r\n"; 507 fi.fileName() + "\"\r\n";
503 newBody += "Content-Transfer-Encoding: base64\r\n"; 508 newBody += "Content-Transfer-Encoding: base64\r\n";
504 newBody += "Content-Disposition: inline; filename=\"" + 509 newBody += "Content-Disposition: inline; filename=\"" +
505 fi.fileName() + "\"\r\n\r\n"; 510 fi.fileName() + "\"\r\n\r\n";
506 511
507 if (encodeFile(fileName, &newBody) == -1) //file not found? 512 if (encodeFile(fileName, &newBody) == -1) //file not found?
508 return -1; 513 return -1;
509 } 514 }
510 515
511 newBody += "\r\n\r\n--" + boundary + "--"; 516 newBody += "\r\n\r\n--" + boundary + "--";
512 mail->rawMail = newBody; 517 mail->rawMail = newBody;
513 518
514 return 0; 519 return 0;
515} 520}
516 521
517int EmailHandler::encodeFile(const QString &fileName, QString *toBody) 522int EmailHandler::encodeFile(const QString &fileName, QString *toBody)
518{ 523{
519 char *fileData; 524 char *fileData;
520 char *dataPtr; 525 char *dataPtr;
521 QString temp; 526 QString temp;
522 uint dataSize, count; 527 uint dataSize, count;
523 QFile f(fileName); 528 QFile f(fileName);
524 529
525 if (! f.open(IO_ReadOnly) ) { 530 if (! f.open(IO_ReadOnly) ) {
526 qWarning("could not open file: " + fileName); 531 qWarning("could not open file: " + fileName);
527 return -1; 532 return -1;
528 } 533 }
529 QTextStream s(&f); 534 QTextStream s(&f);
530 dataSize = f.size(); 535 dataSize = f.size();
531 fileData = (char *) malloc(dataSize + 3); 536 fileData = (char *) malloc(dataSize + 3);
532 s.readRawBytes(fileData, dataSize); 537 s.readRawBytes(fileData, dataSize);
533 538
534 temp = ""; 539 temp = "";
535 dataPtr = fileData; 540 dataPtr = fileData;
536 count = 0; 541 count = 0;
537 while (dataSize > 0) { 542 while (dataSize > 0) {
538 if (dataSize < 3) { 543 if (dataSize < 3) {
539 encode64base(dataPtr, &temp, dataSize); 544 encode64base(dataPtr, &temp, dataSize);
540 dataSize = 0; 545 dataSize = 0;
541 } else { 546 } else {
542 encode64base(dataPtr, &temp, 3); 547 encode64base(dataPtr, &temp, 3);
543 dataSize -= 3; 548 dataSize -= 3;
544 dataPtr += 3; 549 dataPtr += 3;
545 count += 4; 550 count += 4;
546 } 551 }
547 if (count > 72) { 552 if (count > 72) {
548 count = 0; 553 count = 0;
549 temp += "\r\n"; 554 temp += "\r\n";
550 } 555 }
551 } 556 }
552 toBody->append(temp); 557 toBody->append(temp);
553 558
554 delete(fileData); 559 delete(fileData);
555 f.close(); 560 f.close();
556 return 0; 561 return 0;
557} 562}
558 563
559void EmailHandler::encode64base(char *src, QString *dest, int len) 564void EmailHandler::encode64base(char *src, QString *dest, int len)
560{ 565{
561 QString temp; 566 QString temp;
562 uchar c; 567 uchar c;
563 uchar bufOut[4]; 568 uchar bufOut[4];
564 569
565 bufOut[0] = src[0]; 570 bufOut[0] = src[0];
566 bufOut[0] >>= 2; //Done byte 0 571 bufOut[0] >>= 2; //Done byte 0
567 572
568 bufOut[1] = src[0]; 573 bufOut[1] = src[0];
569 bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits 574 bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits
570 bufOut[1] <<= 4; //copy up 4 places 575 bufOut[1] <<= 4; //copy up 4 places
571 if (len > 1) { 576 if (len > 1) {
572 c = src[1]; 577 c = src[1];
573 } else { 578 } else {
574 c = 0; 579 c = 0;
575 } 580 }
576 581
577 c = c & (16 + 32 + 64 + 128); 582 c = c & (16 + 32 + 64 + 128);
578 c >>= 4; 583 c >>= 4;
579 bufOut[1] = bufOut[1] | c; //Done byte 1 584 bufOut[1] = bufOut[1] | c; //Done byte 1
580 585
581 bufOut[2] = src[1]; 586 bufOut[2] = src[1];
582 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8); 587 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8);
583 bufOut[2] <<= 2; 588 bufOut[2] <<= 2;
584 if (len > 2) { 589 if (len > 2) {
585 c = src[2]; 590 c = src[2];
586 } else { 591 } else {
587 c = 0; 592 c = 0;
588 } 593 }
589 c >>= 6; 594 c >>= 6;
590 bufOut[2] = bufOut[2] | c; 595 bufOut[2] = bufOut[2] | c;
591 596
592 bufOut[3] = src[2]; 597 bufOut[3] = src[2];
593 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32); 598 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32);
594 599
595 if (len == 1) { 600 if (len == 1) {
596 bufOut[2] = 64; 601 bufOut[2] = 64;
597 bufOut[3] = 64; 602 bufOut[3] = 64;
598 } 603 }
599 if (len == 2) { 604 if (len == 2) {
600 bufOut[3] = 64; 605 bufOut[3] = 64;
601 } 606 }
602 for (int x = 0; x < 4; x++) { 607 for (int x = 0; x < 4; x++) {
603 if (bufOut[x] <= 25) 608 if (bufOut[x] <= 25)
604 bufOut[x] += (uint) 'A'; 609 bufOut[x] += (uint) 'A';
605 else if (bufOut[x] >= 26 && bufOut[x] <= 51) 610 else if (bufOut[x] >= 26 && bufOut[x] <= 51)
606 bufOut[x] += (uint) 'a' - 26; 611 bufOut[x] += (uint) 'a' - 26;
607 else if (bufOut[x] >= 52 && bufOut[x] <= 61) 612 else if (bufOut[x] >= 52 && bufOut[x] <= 61)
608 bufOut[x] += (uint) '0' - 52; 613 bufOut[x] += (uint) '0' - 52;
609 else if (bufOut[x] == 62) 614 else if (bufOut[x] == 62)
610 bufOut[x] = '+'; 615 bufOut[x] = '+';
611 else if (bufOut[x] == 63) 616 else if (bufOut[x] == 63)
612 bufOut[x] = '/'; 617 bufOut[x] = '/';
613 else if (bufOut[x] == 64) 618 else if (bufOut[x] == 64)
614 bufOut[x] = '='; 619 bufOut[x] = '=';
615 620
616 dest->append(bufOut[x]); 621 dest->append(bufOut[x]);
617 } 622 }
618} 623}
619 624
620void EmailHandler::cancel() 625void EmailHandler::cancel()
621{ 626{
622 popClient->errorHandling(ErrCancel); 627 popClient->errorHandling(ErrCancel);
623 smtpClient->errorHandling(ErrCancel); 628 smtpClient->errorHandling(ErrCancel);
624} 629}
625 630