summaryrefslogtreecommitdiff
authorgroucho <groucho>2003-04-29 08:04:34 (UTC)
committer groucho <groucho>2003-04-29 08:04:34 (UTC)
commitf09f685be0540e98cc33bc4f664a812aed756926 (patch) (unidiff)
tree10a2193eafd1dc0ae25cd458f3bfa9f0f23522e1
parente096c9d1f2be1ec74ede583fc4221871a56ef508 (diff)
downloadopie-f09f685be0540e98cc33bc4f664a812aed756926.zip
opie-f09f685be0540e98cc33bc4f664a812aed756926.tar.gz
opie-f09f685be0540e98cc33bc4f664a812aed756926.tar.bz2
- added ReplyAll for CC: addressing
- added a download button in mail view - smaller layout fixes - now it's getting to be real useful
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mailit/emailclient.cpp140
-rw-r--r--noncore/net/mailit/emailclient.h11
-rw-r--r--noncore/net/mailit/emailhandler.cpp4
-rw-r--r--noncore/net/mailit/emailhandler.h1
-rw-r--r--noncore/net/mailit/mailitwindow.cpp3
-rw-r--r--noncore/net/mailit/popclient.cpp14
-rw-r--r--noncore/net/mailit/readmail.cpp64
-rw-r--r--noncore/net/mailit/readmail.h8
-rw-r--r--noncore/net/mailit/writemail.cpp35
-rw-r--r--noncore/unsupported/mailit/emailclient.cpp140
-rw-r--r--noncore/unsupported/mailit/emailclient.h11
-rw-r--r--noncore/unsupported/mailit/emailhandler.cpp4
-rw-r--r--noncore/unsupported/mailit/emailhandler.h1
-rw-r--r--noncore/unsupported/mailit/mailitwindow.cpp3
-rw-r--r--noncore/unsupported/mailit/popclient.cpp14
-rw-r--r--noncore/unsupported/mailit/readmail.cpp64
-rw-r--r--noncore/unsupported/mailit/readmail.h8
-rw-r--r--noncore/unsupported/mailit/writemail.cpp35
18 files changed, 412 insertions, 148 deletions
diff --git a/noncore/net/mailit/emailclient.cpp b/noncore/net/mailit/emailclient.cpp
index dff1888..2cedc51 100644
--- a/noncore/net/mailit/emailclient.cpp
+++ b/noncore/net/mailit/emailclient.cpp
@@ -1,552 +1,573 @@
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 <qfile.h> 23#include <qfile.h>
23#include <qcheckbox.h> 24#include <qcheckbox.h>
24#include <qmenubar.h> 25#include <qmenubar.h>
25#include <qaction.h> 26#include <qaction.h>
26#include <qwhatsthis.h> 27#include <qwhatsthis.h>
27#include <qpe/resource.h> 28#include <qpe/resource.h>
28#include "emailclient.h" 29#include "emailclient.h"
30#include "writemail.h"
29 31
30QCollection::Item AccountList::newItem(QCollection::Item d) 32QCollection::Item AccountList::newItem(QCollection::Item d)
31{ 33{
32 return dupl( (MailAccount *) d); 34 return dupl( (MailAccount *) d);
33} 35}
34 36
35MailAccount* AccountList::dupl(MailAccount *in) 37MailAccount* AccountList::dupl(MailAccount *in)
36{ 38{
37 ac = new MailAccount(*in); 39 ac = new MailAccount(*in);
38 return ac; 40 return ac;
39} 41}
40 42
41EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl ) 43EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl )
42 : QMainWindow( parent, name, fl ) 44 : QMainWindow( parent, name, fl )
43{ 45{
44 emailHandler = new EmailHandler(); 46 emailHandler = new EmailHandler();
45 addressList = new AddressList(); 47 addressList = new AddressList();
46 48
47 sending = FALSE; 49 sending = FALSE;
48 receiving = FALSE; 50 receiving = FALSE;
49 previewingMail = FALSE; 51 previewingMail = FALSE;
50 mailIdCount = 1; 52 mailIdCount = 1;
51 accountIdCount = 1; 53 accountIdCount = 1;
52 allAccounts = FALSE; 54 allAccounts = FALSE;
53 55
54 init(); 56 init();
55 57
58
59
56 connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) ); 60 connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) );
57 61
58 connect(emailHandler, SIGNAL(smtpError(int)), this, 62 connect(emailHandler, SIGNAL(smtpError(int)), this,
59 SLOT(smtpError(int)) ); 63 SLOT(smtpError(int)) );
60 connect(emailHandler, SIGNAL(popError(int)), this, 64 connect(emailHandler, SIGNAL(popError(int)), this,
61 SLOT(popError(int)) ); 65 SLOT(popError(int)) );
62 66
63 connect(inboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(inboxItemSelected()) ); 67 connect(inboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(inboxItemSelected()) );
64 connect(outboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(outboxItemSelected()) ); 68 connect(outboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(outboxItemSelected()) );
65 69
66 connect(inboxView, SIGNAL(pressed(QListViewItem *)), this, SLOT(inboxItemPressed()) ); 70 connect(inboxView, SIGNAL(pressed(QListViewItem *)), this, SLOT(inboxItemPressed()) );
67 connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemReleased()) ); 71 connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemReleased()) );
68 72
69
70 connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this, 73 connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this,
71 SLOT(mailArrived(const Email &, bool)) ); 74 SLOT(mailArrived(const Email &, bool)) );
72 connect(emailHandler, SIGNAL(mailTransfered(int)), this, 75 connect(emailHandler, SIGNAL(mailTransfered(int)), this,
73 SLOT(allMailArrived(int)) ); 76 SLOT(allMailArrived(int)) );
74 77
75 mailconf = new Config("mailit"); 78 mailconf = new Config("mailit");
76 //In case Synchronize is not defined in settings.txt 79 //In case Synchronize is not defined in settings.txt
77 80
78 readSettings(); 81 readSettings();
79 82
80 updateAccounts(); 83 updateAccounts();
81 84
82 lineShift = "\n"; 85 lineShift = "\n";
83 readMail(); 86 readMail();
84 lineShift = "\r\n"; 87 lineShift = "\r\n";
85 88
86 mailboxView->setCurrentTab(0); //ensure that inbox has focus 89 mailboxView->setCurrentTab(0); //ensure that inbox has focus
90
91 /*channel = new QCopChannel( "QPE/Application/mailit", this );
92 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
93 this, SLOT(receive(const QCString&, const QByteArray&)) );*/
94
87} 95}
88 96
89 97
90EmailClient::~EmailClient() 98EmailClient::~EmailClient()
91{ 99{
92 //needs to be moved from destructor to closewindow event 100 //needs to be moved from destructor to closewindow event
93 saveMail(getPath(FALSE) + "inbox.txt", inboxView); 101 saveMail(getPath(FALSE) + "inbox.txt", inboxView);
94 //does not currently work. Defining outbox in the same 102 //does not currently work. Defining outbox in the same
95 //format as inbox is not a good solution as they have 103 //format as inbox is not a good solution as they have
96 //different properties 104 //different properties
97 saveMail(getPath(FALSE) + "outbox.txt", outboxView); 105 saveMail(getPath(FALSE) + "outbox.txt", outboxView);
98 saveSettings(); 106 saveSettings();
99 107
100 mailconf->write(); 108 mailconf->write();
101 delete mailconf; 109 delete mailconf;
102 110
103} 111}
104 112
105void EmailClient::init() 113void EmailClient::init()
106{ 114{
107 statusBar = new QStatusBar(this); 115 initStatusBar(this);
108 statusBar->setSizeGripEnabled(FALSE); 116
109
110 status1Label = new QLabel( tr("Idle"), statusBar);
111 status2Label = new QLabel("", statusBar);
112 connect(emailHandler, SIGNAL(updatePopStatus(const QString &)),
113 status2Label, SLOT(setText(const QString &)) );
114 connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)),
115 status2Label, SLOT(setText(const QString &)) );
116
117 progressBar = new QProgressBar(statusBar);
118
119 connect(emailHandler, SIGNAL(mailboxSize(int)),
120 this, SLOT(setTotalSize(int)) );
121 connect(emailHandler, SIGNAL(currentMailSize(int)),
122 this, SLOT(setMailSize(int)) );
123 connect(emailHandler, SIGNAL(downloadedSize(int)),
124 this, SLOT(setDownloadedSize(int)) );
125
126 statusBar->addWidget(status1Label);
127 statusBar->addWidget(progressBar);
128 statusBar->addWidget(status2Label);
129
130 setToolBarsMovable(FALSE); 117 setToolBarsMovable(FALSE);
131 118
132 bar = new QToolBar(this); 119 bar = new QToolBar(this);
133 QWhatsThis::add(bar,tr("Main operation toolbar")); 120 QWhatsThis::add(bar,tr("Main operation toolbar"));
134 bar->setHorizontalStretchable( TRUE ); 121 bar->setHorizontalStretchable( TRUE );
135 122
136 mb = new QMenuBar( bar ); 123 mb = new QMenuBar( bar );
137 124
138 QPopupMenu *mail = new QPopupMenu(mb); 125 QPopupMenu *mail = new QPopupMenu(mb);
139 mb->insertItem( tr( "&Mail" ), mail); 126 mb->insertItem( tr( "&Mail" ), mail);
140 127
141 QPopupMenu *configure = new QPopupMenu(mb); 128 QPopupMenu *configure = new QPopupMenu(mb);
142 mb->insertItem( tr( "Accounts" ), configure); 129 mb->insertItem( tr( "Accounts" ), configure);
143 130
144 selectAccountMenu = new QPopupMenu(mb); 131 selectAccountMenu = new QPopupMenu(mb);
145 editAccountMenu = new QPopupMenu(mb); 132 editAccountMenu = new QPopupMenu(mb);
146 deleteAccountMenu = new QPopupMenu(mb); 133 deleteAccountMenu = new QPopupMenu(mb);
147 134
148 mail->insertItem(tr("Get Mail in"), selectAccountMenu); 135 mail->insertItem(tr("Get Mail in"), selectAccountMenu);
149 configure->insertItem(tr("Edit account"), editAccountMenu); 136 configure->insertItem(tr("Edit account"), editAccountMenu);
150 configure->insertItem(tr("Delete account"), deleteAccountMenu); 137 configure->insertItem(tr("Delete account"), deleteAccountMenu);
151 138
152 bar = new QToolBar(this); 139 bar = new QToolBar(this);
153 140
154 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);
155 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."));
156 143
157 getMailButton->setPopup(selectAccountMenu); 144 getMailButton->setPopup(selectAccountMenu);
158 145
159 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);
160 connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) ); 147 connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) );
161 sendMailButton->addTo(bar); 148 sendMailButton->addTo(bar);
162 sendMailButton->addTo(mail); 149 sendMailButton->addTo(mail);
163 sendMailButton->setWhatsThis("Send mail queued in the outbox"); 150 sendMailButton->setWhatsThis("Send mail queued in the outbox");
164 151
165 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);
166 connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) ); 153 connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) );
167 composeButton->addTo(bar); 154 composeButton->addTo(bar);
168 composeButton->addTo(mail); 155 composeButton->addTo(mail);
169 composeButton->setWhatsThis("Compose a new mail"); 156 composeButton->setWhatsThis("Compose a new mail");
170 157
171 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);
172 connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) ); 159 connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) );
173 cancelButton->addTo(mail); 160 cancelButton->addTo(mail);
174 cancelButton->addTo(bar); 161 cancelButton->addTo(bar);
175 cancelButton->setEnabled(FALSE); 162 cancelButton->setEnabled(FALSE);
176 cancelButton->setWhatsThis("Stop the currently active mail transfer"); 163 cancelButton->setWhatsThis("Stop the currently active mail transfer");
177 164
178 165
179 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 );
180 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); 167 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) );
181 deleteButton->addTo(bar); 168 deleteButton->addTo(bar);
182 deleteButton->setWhatsThis("Remove the currently selected eMail(s)"); 169 deleteButton->setWhatsThis("Remove the currently selected eMail(s)");
183 170
184 mailboxView = new OTabWidget( this, "mailboxView" ); 171 mailboxView = new OTabWidget( this, "mailboxView" );
185 172
186 QWidget* widget = new QWidget( mailboxView, "widget" ); 173 QWidget* widget = new QWidget( mailboxView, "widget" );
187 grid_2 = new QGridLayout( widget ); 174 grid_2 = new QGridLayout( widget );
188// grid_2->setSpacing(6); 175// grid_2->setSpacing(6);
189// grid_2->setMargin( 11 ); 176// grid_2->setMargin( 11 );
190 177
191 inboxView = new QListView( widget, "inboxView" ); 178 inboxView = new QListView( widget, "inboxView" );
192 inboxView->addColumn( tr( "From" ) ); 179 inboxView->addColumn( tr( "From" ) );
193 inboxView->addColumn( tr( "Subject" ) ); 180 inboxView->addColumn( tr( "Subject" ) );
194 inboxView->addColumn( tr( "Date" ) ); 181 inboxView->addColumn( tr( "Date" ) );
195 inboxView->setMinimumSize( QSize( 0, 0 ) ); 182 inboxView->setMinimumSize( QSize( 0, 0 ) );
196 inboxView->setAllColumnsShowFocus(TRUE); 183 inboxView->setAllColumnsShowFocus(TRUE);
197 QWhatsThis::add(inboxView,QWidget::tr("This is the inbox view.\n It keeps the fetched mail which can be viewed by double clicking the entry.\n" 184 QWhatsThis::add(inboxView,QWidget::tr("This is the inbox view.\n"
198 " A blue attachment icon shows whether this mail has attachments.")); 185 "It keeps the fetched mail which can be \n"
186 "viewed by double clicking the entry.\n"
187 "blue attachment icon shows whether this \n"
188 "mailhas attachments.\n"));
199 189
200 grid_2->addWidget( inboxView, 2, 0 ); 190 grid_2->addWidget( inboxView, 2, 0 );
201 mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) ); 191 mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) );
202 192
203 QWidget* widget_2 = new QWidget( mailboxView, "widget_2" ); 193 QWidget* widget_2 = new QWidget( mailboxView, "widget_2" );
204 grid_3 = new QGridLayout( widget_2 ); 194 grid_3 = new QGridLayout( widget_2 );
205// grid_3->setSpacing(6); 195// grid_3->setSpacing(6);
206// grid_3->setMargin( 11 ); 196// grid_3->setMargin( 11 );
207 197
208 outboxView = new QListView( widget_2, "outboxView" ); 198 outboxView = new QListView( widget_2, "outboxView" );
209 outboxView->addColumn( tr( "To" ) ); 199 outboxView->addColumn( tr( "To" ) );
210 outboxView->addColumn( tr( "Subject" ) ); 200 outboxView->addColumn( tr( "Subject" ) );
211 outboxView->setAllColumnsShowFocus(TRUE); 201 outboxView->setAllColumnsShowFocus(TRUE);
212 202
213 QWhatsThis::add(outboxView,QWidget::tr("This is the oubox view.\n It keeps the queued mails to send which can be reviewed by double clicking the entry.")); 203 QWhatsThis::add(outboxView,QWidget::tr("This is the outbox view.\n"
204 "It keeps the queued mails to send which can be \n"
205 "reviewed by double clicking the entry."));
214 grid_3->addWidget( outboxView, 0, 0 ); 206 grid_3->addWidget( outboxView, 0, 0 );
215 mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) ); 207 mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) );
216 208
217 setCentralWidget(mailboxView); 209 setCentralWidget(mailboxView);
218 210
219} 211}
220 212
213void EmailClient::initStatusBar(QWidget* parent)
214{
215 statusBar = new QStatusBar(parent);
216 statusBar->setSizeGripEnabled(FALSE);
217
218 status1Label = new QLabel( tr("Idle"), statusBar);
219 status2Label = new QLabel("", statusBar);
220 connect(emailHandler, SIGNAL(updatePopStatus(const QString &)),
221 status2Label, SLOT(setText(const QString &)) );
222 connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)),
223 status2Label, SLOT(setText(const QString &)) );
224
225 progressBar = new QProgressBar(statusBar);
226
227 connect(emailHandler, SIGNAL(mailboxSize(int)),
228 this, SLOT(setTotalSize(int)) );
229 connect(emailHandler, SIGNAL(currentMailSize(int)),
230 this, SLOT(setMailSize(int)) );
231 connect(emailHandler, SIGNAL(downloadedSize(int)),
232 this, SLOT(setDownloadedSize(int)) );
233
234 statusBar->addWidget(status1Label);
235 statusBar->addWidget(progressBar);
236 statusBar->addWidget(status2Label);
237
238}
239
221void EmailClient::compose() 240void EmailClient::compose()
222{ 241{
223 emit composeRequested(); 242 emit composeRequested();
224} 243}
225 244
226void EmailClient::cancel() 245void EmailClient::cancel()
227{ 246{
228 emailHandler->cancel(); 247 emailHandler->cancel();
229} 248}
230 249
231AddressList* EmailClient::getAdrListRef() 250AddressList* EmailClient::getAdrListRef()
232{ 251{
233 return addressList; 252 return addressList;
234} 253}
235 254
236//this needs to be rewritten to syncronize with outboxView 255//this needs to be rewritten to syncronize with outboxView
237void EmailClient::enqueMail(const Email &mail) 256void EmailClient::enqueMail(const Email &mail)
238{ 257{
239 if (accountList.count() == 0) { 258 if (accountList.count() == 0) {
240 QMessageBox::warning(qApp->activeWindow(), 259 QMessageBox::warning(qApp->activeWindow(),
241 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");
242 return; 261 return;
243 } 262 }
244 263
245 if (accountList.count() > 0) { 264 if (accountList.count() > 0) {
246 currentAccount = accountList.first(); 265 currentAccount = accountList.first();
247 qWarning("using account " + currentAccount->name); 266 qWarning("using account " + currentAccount->name);
248 } 267 }
249 268
250 Email addMail = mail; 269 Email addMail = mail;
251 addMail.from = currentAccount->name; 270 addMail.from = currentAccount->name;
252 addMail.fromMail = currentAccount->emailAddress; 271 addMail.fromMail = currentAccount->emailAddress;
253 addMail.rawMail.prepend("From: " + addMail.from + "<" + addMail.fromMail + ">\n"); 272 addMail.rawMail.prepend("From: " + addMail.from + "<" + addMail.fromMail + ">\n");
254 item = new EmailListItem(outboxView, addMail, false); 273 item = new EmailListItem(outboxView, addMail, false);
255 274
256 mailboxView->setCurrentTab(1); 275 mailboxView->setCurrentTab(1);
257 276
258} 277}
259 278
260void EmailClient::sendQuedMail() 279void EmailClient::sendQuedMail()
261{ 280{
262 int count = 0; 281 int count = 0;
263 282
264 if (accountList.count() == 0) { 283 if (accountList.count() == 0) {
265 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");
266 return; 285 return;
267 } 286 }
268 //traverse listview, find messages to send 287 //traverse listview, find messages to send
269 if (! sending) { 288 if (! sending) {
270 item = (EmailListItem *) outboxView->firstChild(); 289 item = (EmailListItem *) outboxView->firstChild();
271 if (item != NULL) { 290 if (item != NULL) {
272 while (item != NULL) { 291 while (item != NULL) {
273 quedMessages.append(item->getMail()); 292 quedMessages.append(item->getMail());
274 item = (EmailListItem *) item->nextSibling(); 293 item = (EmailListItem *) item->nextSibling();
275 count++; 294 count++;
276 } 295 }
277 setMailAccount(); 296 setMailAccount();
278 emailHandler->sendMail(&quedMessages); 297 emailHandler->sendMail(&quedMessages);
279 sending = TRUE; 298 sending = TRUE;
280 sendMailButton->setEnabled(FALSE); 299 sendMailButton->setEnabled(FALSE);
281 cancelButton->setEnabled(TRUE); 300 cancelButton->setEnabled(TRUE);
282 } else { 301 } else {
283 qWarning("sendQuedMail(): no messages to send"); 302 qWarning("sendQuedMail(): no messages to send");
284 } 303 }
285 } 304 }
286} 305}
287 306
288void EmailClient::setMailAccount() 307void EmailClient::setMailAccount()
289{ 308{
290 emailHandler->setAccount(*currentAccount); 309 emailHandler->setAccount(*currentAccount);
291} 310}
292 311
293void EmailClient::mailSent() 312void EmailClient::mailSent()
294{ 313{
295 sending = FALSE; 314 sending = FALSE;
296 sendMailButton->setEnabled(TRUE); 315 sendMailButton->setEnabled(TRUE);
297 316
298 quedMessages.clear(); 317 quedMessages.clear();
299 outboxView->clear(); //should be moved to an sentBox 318 outboxView->clear(); //should be moved to an sentBox
300} 319}
301 320
302void EmailClient::getNewMail() { 321void EmailClient::getNewMail() {
303 322
304 if (accountList.count() == 0) { 323 if (accountList.count() == 0) {
305 QMessageBox::warning(qApp->activeWindow(),"No account selected", 324 QMessageBox::warning(qApp->activeWindow(),"No account selected",
306 "You must create an account", "OK\n"); 325 "You must create an account", "OK\n");
307 return; 326 return;
308 } 327 }
309 328
310 setMailAccount(); 329 setMailAccount();
311 330
312 receiving = TRUE; 331 receiving = TRUE;
313 previewingMail = TRUE; 332 previewingMail = TRUE;
314 getMailButton->setEnabled(FALSE); 333 getMailButton->setEnabled(FALSE);
315 cancelButton->setEnabled(TRUE); 334 cancelButton->setEnabled(TRUE);
316 selectAccountMenu->setEnabled(FALSE); 335 selectAccountMenu->setEnabled(FALSE);
317 336
318 status1Label->setText(currentAccount->accountName + " headers"); 337 status1Label->setText(currentAccount->accountName + " headers");
319 progressBar->reset(); 338 progressBar->reset();
320 339
321 //get any previous mails not downloaded and add to queue 340 //get any previous mails not downloaded and add to queue
322 mailDownloadList.clear(); 341 /*mailDownloadList.clear();
323 Email *mailPtr; 342 Email *mailPtr;
324 item = (EmailListItem *) inboxView->firstChild(); 343 item = (EmailListItem *) inboxView->firstChild();
325 while (item != NULL) { 344 while (item != NULL) {
326 mailPtr = item->getMail(); 345 mailPtr = item->getMail();
327 if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { 346 if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) {
328 mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); 347 mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size);
329 } 348 }
330 item = (EmailListItem *) item->nextSibling(); 349 item = (EmailListItem *) item->nextSibling();
331 } 350 }*/
332 351
333 emailHandler->getMailHeaders(); 352 emailHandler->getMailHeaders();
334 353
335} 354}
336 355
337void EmailClient::getAllNewMail() 356void EmailClient::getAllNewMail()
338{ 357{
339 allAccounts = TRUE; 358 allAccounts = TRUE;
340 currentAccount = accountList.first(); 359 currentAccount = accountList.first();
341 getNewMail(); 360 getNewMail();
342} 361}
343 362
344void EmailClient::mailArrived(const Email &mail, bool fromDisk) 363void EmailClient::mailArrived(const Email &mail, bool fromDisk)
345{ 364{
346 Enclosure *ePtr; 365 Enclosure *ePtr;
347 Email newMail; 366 Email newMail;
348 int thisMailId; 367 int thisMailId;
349 emailHandler->parse(mail.rawMail, lineShift, &newMail); 368 emailHandler->parse(mail.rawMail, lineShift, &newMail);
350 mailconf->setGroup(newMail.id); 369 mailconf->setGroup(newMail.id);
351 370
352 if (fromDisk) 371 if (fromDisk)
353 { 372 {
373
354 newMail.downloaded = mailconf->readBoolEntry("downloaded"); 374 newMail.downloaded = mailconf->readBoolEntry("downloaded");
355 newMail.size = mailconf->readNumEntry("size"); 375 newMail.size = mailconf->readNumEntry("size");
356 newMail.serverId = mailconf->readNumEntry("serverid"); 376 newMail.serverId = mailconf->readNumEntry("serverid");
357 newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); 377 newMail.fromAccountId = mailconf->readNumEntry("fromaccountid");
358 } 378 }
359 else 379 else
360 { //mail arrived from server 380 { //mail arrived from server
381
361 newMail.serverId = mail.serverId; 382 newMail.serverId = mail.serverId;
362 newMail.size = mail.size; 383 newMail.size = mail.size;
363 newMail.downloaded = mail.downloaded; 384 newMail.downloaded = mail.downloaded;
364 385
365 newMail.fromAccountId = emailHandler->getAccount()->id; 386 newMail.fromAccountId = emailHandler->getAccount()->id;
366 mailconf->writeEntry("fromaccountid", newMail.fromAccountId); 387 mailconf->writeEntry("fromaccountid", newMail.fromAccountId);
367 } 388 }
368 389
369 //add if read or not 390 //add if read or not
370 newMail.read = mailconf->readBoolEntry("mailread"); 391 newMail.read = mailconf->readBoolEntry("mailread");
371 392
372 //check if new mail 393 //check if new mail
373 if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { 394 if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) {
374 thisMailId = mailIdCount; 395 thisMailId = mailIdCount;
375 mailIdCount++; 396 mailIdCount++;
376 397
377 //set server count, so that if the user aborts, the new 398 //set server count, so that if the user aborts, the new
378 //header is not reloaded 399 //header is not reloaded
379 if ((currentAccount)&&(currentAccount->synchronize)) 400 if ((currentAccount)&&(currentAccount->synchronize))
380 currentAccount->lastServerMailCount++; 401 currentAccount->lastServerMailCount++;
381 402
382 mailconf->writeEntry("internalmailid", thisMailId); 403 mailconf->writeEntry("internalmailid", thisMailId);
383 mailconf->writeEntry("downloaded", newMail.downloaded); 404 mailconf->writeEntry("downloaded", newMail.downloaded);
384 mailconf->writeEntry("size", (int) newMail.size); 405 mailconf->writeEntry("size", (int) newMail.size);
385 mailconf->writeEntry("serverid", newMail.serverId); 406 mailconf->writeEntry("serverid", newMail.serverId);
386 407
387 //addressList->addContact(newMail.fromMail, newMail.from); 408 //addressList->addContact(newMail.fromMail, newMail.from);
388 } 409 }
389 410
390 mailconf->writeEntry("downloaded", newMail.downloaded); 411 mailconf->writeEntry("downloaded", newMail.downloaded);
391 412
392 QString stringMailId; 413 QString stringMailId;
393 stringMailId.setNum(thisMailId); 414 stringMailId.setNum(thisMailId);
394 //see if any attatchments needs to be stored 415 //see if any attatchments needs to be stored
395 416
396 for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { 417 for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) {
397 QString stringId; 418 QString stringId;
398 stringId.setNum(ePtr->id); 419 stringId.setNum(ePtr->id);
399 420
400 int id = mailconf->readNumEntry("enclosureid_" + stringId); 421 int id = mailconf->readNumEntry("enclosureid_" + stringId);
401 if (id != ePtr->id) { //new entry 422 if (id != ePtr->id) { //new entry
402 mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); 423 mailconf->writeEntry("enclosureid_" + stringId, ePtr->id);
403 mailconf->writeEntry("name_" + stringId, ePtr->originalName); 424 mailconf->writeEntry("name_" + stringId, ePtr->originalName);
404 mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); 425 mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType);
405 mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); 426 mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute);
406 mailconf->writeEntry("saved_" + stringId, ePtr->saved); 427 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
407 mailconf->writeEntry("installed_" + stringId, FALSE); 428 mailconf->writeEntry("installed_" + stringId, FALSE);
408 429
409 ePtr->name = stringMailId + "_" + stringId; 430 ePtr->name = stringMailId + "_" + stringId;
410 ePtr->path = getPath(TRUE); 431 ePtr->path = getPath(TRUE);
411 if (emailHandler->getEnclosure(ePtr)) { //file saved 432 if (emailHandler->getEnclosure(ePtr)) { //file saved
412 ePtr->saved = TRUE; 433 ePtr->saved = TRUE;
413 mailconf->writeEntry("saved_" + stringId, ePtr->saved); 434 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
414 mailconf->writeEntry("filename_" + stringId, ePtr->name); 435 mailconf->writeEntry("filename_" + stringId, ePtr->name);
415 mailconf->writeEntry("path_" + stringId, ePtr->path); 436 mailconf->writeEntry("path_" + stringId, ePtr->path);
416 } else { 437 } else {
417 ePtr->saved = FALSE; 438 ePtr->saved = FALSE;
418 mailconf->writeEntry("saved_" + stringId, ePtr->saved); 439 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
419 } 440 }
420 } else { 441 } else {
421 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); 442 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId);
422 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); 443 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId);
423 if (ePtr->saved) { 444 if (ePtr->saved) {
424 ePtr->name = mailconf->readEntry("filename_" + stringId); 445 ePtr->name = mailconf->readEntry("filename_" + stringId);
425 ePtr->path = mailconf->readEntry("path_" + stringId); 446 ePtr->path = mailconf->readEntry("path_" + stringId);
426 } 447 }
427 } 448 }
428 } 449 }
429 450
430 bool found=false; 451 bool found=false;
431 452
432 if (!fromDisk) 453 if (!fromDisk)
433 { 454 {
434 455
435 Email *mailPtr; 456 Email *mailPtr;
436 item = (EmailListItem *) inboxView->firstChild(); 457 item = (EmailListItem *) inboxView->firstChild();
437 while ((item != NULL)&&(!found)) 458 while ((item != NULL)&&(!found))
438 { 459 {
439 mailPtr = item->getMail(); 460 mailPtr = item->getMail();
440 if (mailPtr->id == newMail.id) { 461 if (mailPtr->id == newMail.id) {
441 item->setMail(newMail); 462 item->setMail(newMail);
442 emit mailUpdated(item->getMail()); 463 emit mailUpdated(item->getMail());
443 found = true; 464 found = true;
444 } 465 }
445 item = (EmailListItem *) item->nextSibling(); 466 item = (EmailListItem *) item->nextSibling();
446 } 467 }
447 } 468 }
448 if ((!found)||(fromDisk)) item = new EmailListItem(inboxView, newMail, TRUE); 469 if ((!found)||(fromDisk)) item = new EmailListItem(inboxView, newMail, TRUE);
449 470
450 /*if (!newMail.downloaded) 471 /*if (!newMail.downloaded)
451 mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ 472 mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/
452 473
453 mailboxView->setCurrentTab(0); 474 mailboxView->setCurrentTab(0);
454 475
455} 476}
456 477
457void EmailClient::allMailArrived(int count) 478void EmailClient::allMailArrived(int count)
458{ 479{
459 // not previewing means all mailtransfer has been done 480 // not previewing means all mailtransfer has been done
460 /*if (!previewingMail) {*/ 481 /*if (!previewingMail) {*/
461 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { 482 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) {
462 emit newCaption("Mailit - " + currentAccount->accountName); 483 emit newCaption("Mailit - " + currentAccount->accountName);
463 getNewMail(); 484 getNewMail();
464 return; 485 return;
465 } else { 486 } else {
466 allAccounts = FALSE; 487 allAccounts = FALSE;
467 receiving = FALSE; 488 receiving = FALSE;
468 getMailButton->setEnabled(TRUE); 489 getMailButton->setEnabled(TRUE);
469 cancelButton->setEnabled(FALSE); 490 cancelButton->setEnabled(FALSE);
470 selectAccountMenu->setEnabled(TRUE); 491 selectAccountMenu->setEnabled(TRUE);
471 status1Label->setText("Idle"); 492 status1Label->setText("Idle");
472 493
473 progressBar->reset(); 494 progressBar->reset();
474 return; 495 return;
475 } 496 }
476 //} 497 //}
477 498
478 // all headers downloaded from server, start downloading remaining mails 499 // all headers downloaded from server, start downloading remaining mails
479 previewingMail = FALSE; 500 previewingMail = FALSE;
480 status1Label->setText(currentAccount->accountName); 501 status1Label->setText(currentAccount->accountName);
481 progressBar->reset(); 502 progressBar->reset();
482 503
483 504
484 mailboxView->setCurrentTab(0); 505 mailboxView->setCurrentTab(0);
485} 506}
486 507
487 508
488void EmailClient::moveMailFront(Email *mailPtr) 509void EmailClient::moveMailFront(Email *mailPtr)
489{ 510{
490 if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { 511 if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) {
491 mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); 512 mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size);
492 } 513 }
493} 514}
494 515
495void EmailClient::smtpError(int code) 516void EmailClient::smtpError(int code)
496{ 517{
497 QString temp; 518 QString temp;
498 519
499 if (code == ErrUnknownResponse) 520 if (code == ErrUnknownResponse)
500 temp = "Unknown response from server"; 521 temp = "Unknown response from server";
501 522
502 if (code == QSocket::ErrHostNotFound) 523 if (code == QSocket::ErrHostNotFound)
503 temp = "host not found"; 524 temp = "host not found";
504 if (code == QSocket::ErrConnectionRefused) 525 if (code == QSocket::ErrConnectionRefused)
505 temp = "connection refused"; 526 temp = "connection refused";
506 if (code == QSocket::ErrSocketRead) 527 if (code == QSocket::ErrSocketRead)
507 temp = "socket packet error"; 528 temp = "socket packet error";
508 529
509 if (code != ErrCancel) { 530 if (code != ErrCancel) {
510 QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); 531 QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n");
511 } else { 532 } else {
512 status2Label->setText("Aborted by user"); 533 status2Label->setText("Aborted by user");
513 } 534 }
514 535
515 sending = FALSE; 536 sending = FALSE;
516 sendMailButton->setEnabled(TRUE); 537 sendMailButton->setEnabled(TRUE);
517 cancelButton->setEnabled(FALSE); 538 cancelButton->setEnabled(FALSE);
518 quedMessages.clear(); 539 quedMessages.clear();
519} 540}
520 541
521void EmailClient::popError(int code) 542void EmailClient::popError(int code)
522{ 543{
523 QString temp; 544 QString temp;
524 545
525 if (code == ErrUnknownResponse) 546 if (code == ErrUnknownResponse)
526 temp = "Unknown response from server"; 547 temp = "Unknown response from server";
527 if (code == ErrLoginFailed) 548 if (code == ErrLoginFailed)
528 temp = "Login failed\nCheck user name and password"; 549 temp = "Login failed\nCheck user name and password";
529 550
530 if (code == QSocket::ErrHostNotFound) 551 if (code == QSocket::ErrHostNotFound)
531 temp = "host not found"; 552 temp = "host not found";
532 if (code == QSocket::ErrConnectionRefused) 553 if (code == QSocket::ErrConnectionRefused)
533 temp = "connection refused"; 554 temp = "connection refused";
534 if (code == QSocket::ErrSocketRead) 555 if (code == QSocket::ErrSocketRead)
535 temp = "socket packet error"; 556 temp = "socket packet error";
536 557
537 if (code != ErrCancel) { 558 if (code != ErrCancel) {
538 QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n"); 559 QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n");
539 } else { 560 } else {
540 status2Label->setText("Aborted by user"); 561 status2Label->setText("Aborted by user");
541 } 562 }
542 563
543 receiving = FALSE; 564 receiving = FALSE;
544 getMailButton->setEnabled(TRUE); 565 getMailButton->setEnabled(TRUE);
545 cancelButton->setEnabled(FALSE); 566 cancelButton->setEnabled(FALSE);
546 selectAccountMenu->setEnabled(TRUE); 567 selectAccountMenu->setEnabled(TRUE);
547} 568}
548 569
549void EmailClient::inboxItemSelected() 570void EmailClient::inboxItemSelected()
550{ 571{
551 //killTimer(timerID); 572 //killTimer(timerID);
552 573
@@ -729,240 +750,283 @@ void EmailClient::saveSettings()
729 mailconf->writeEntry("POPServer",accountPtr->popServer); 750 mailconf->writeEntry("POPServer",accountPtr->popServer);
730 mailconf->writeEntry("SMTPServer",accountPtr->smtpServer); 751 mailconf->writeEntry("SMTPServer",accountPtr->smtpServer);
731 mailconf->writeEntry("AccountId",accountPtr->id); 752 mailconf->writeEntry("AccountId",accountPtr->id);
732 if (accountPtr->synchronize) 753 if (accountPtr->synchronize)
733 { 754 {
734 mailconf->writeEntry("Synchronize","Yes"); 755 mailconf->writeEntry("Synchronize","Yes");
735 mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit); 756 mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit);
736 mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount); 757 mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount);
737 } 758 }
738 else 759 else
739 { 760 {
740 mailconf->writeEntry("Synchronize", "No"); 761 mailconf->writeEntry("Synchronize", "No");
741 } 762 }
742 } 763 }
743 764
744 mailconf->setGroup("mailitglobal"); 765 mailconf->setGroup("mailitglobal");
745 mailconf->writeEntry("Accounts",acc_count); 766 mailconf->writeEntry("Accounts",acc_count);
746 mailconf->writeEntry("mailidcount", mailIdCount); 767 mailconf->writeEntry("mailidcount", mailIdCount);
747 mailconf->writeEntry("accountidcount", accountIdCount); 768 mailconf->writeEntry("accountidcount", accountIdCount);
748} 769}
749 770
750void EmailClient::selectAccount(int id) 771void EmailClient::selectAccount(int id)
751{ 772{
752 if (accountList.count() > 0) { 773 if (accountList.count() > 0) {
753 currentAccount = accountList.at(id); 774 currentAccount = accountList.at(id);
754 emit newCaption("Mailit - " + currentAccount->accountName); 775 emit newCaption("Mailit - " + currentAccount->accountName);
755 getNewMail(); 776 getNewMail();
756 } else { 777 } else {
757 emit newCaption("Mailit ! No account defined"); 778 emit newCaption("Mailit ! No account defined");
758 } 779 }
759} 780}
760 781
761void EmailClient::editAccount(int id) 782void EmailClient::editAccount(int id)
762{ 783{
763 MailAccount *newAccount; 784 MailAccount *newAccount;
764 785
765 editAccountView = new EditAccount(this, "account", TRUE); 786 editAccountView = new EditAccount(this, "account", TRUE);
766 if (id == newAccountId) { //new account 787 if (id == newAccountId) { //new account
767 newAccount = new MailAccount; 788 newAccount = new MailAccount;
768 editAccountView->setAccount(newAccount); 789 editAccountView->setAccount(newAccount);
769 } else { 790 } else {
770 newAccount = accountList.at(id); 791 newAccount = accountList.at(id);
771 editAccountView->setAccount(newAccount, FALSE); 792 editAccountView->setAccount(newAccount, FALSE);
772 } 793 }
773 794
774 editAccountView->showMaximized(); 795 editAccountView->showMaximized();
775 editAccountView->exec(); 796 editAccountView->exec();
776 797
777 if (editAccountView->result() == QDialog::Accepted) { 798 if (editAccountView->result() == QDialog::Accepted) {
778 if (id == newAccountId) { 799 if (id == newAccountId) {
779 newAccount->id = accountIdCount; 800 newAccount->id = accountIdCount;
780 accountIdCount++; 801 accountIdCount++;
781 accountList.append(newAccount); 802 accountList.append(newAccount);
782 updateAccounts(); 803 updateAccounts();
783 } else { 804 } else {
784 updateAccounts(); 805 updateAccounts();
785 } 806 }
786 } 807 }
787 808
788 delete editAccountView; 809 delete editAccountView;
789} 810}
790 811
791void EmailClient::deleteAccount(int id) 812void EmailClient::deleteAccount(int id)
792{ 813{
793 MailAccount *newAccount; 814 MailAccount *newAccount;
794 QString message; 815 QString message;
795 816
796 newAccount = accountList.at(id); 817 newAccount = accountList.at(id);
797 message = "Delete account:\n" + newAccount->accountName; 818 message = "Delete account:\n" + newAccount->accountName;
798 switch( QMessageBox::warning( this, "Mailit", message, 819 switch( QMessageBox::warning( this, "Mailit", message,
799 "Yes", "No", 0, 0, 1 ) ) { 820 "Yes", "No", 0, 0, 1 ) ) {
800 821
801 case 0: accountList.remove(id); 822 case 0: accountList.remove(id);
802 updateAccounts(); 823 updateAccounts();
803 break; 824 break;
804 case 1: 825 case 1:
805 break; 826 break;
806 } 827 }
807} 828}
808 829
809void EmailClient::updateAccounts() 830void EmailClient::updateAccounts()
810{ 831{
811 MailAccount *accountPtr; 832 MailAccount *accountPtr;
812 833
813 //rebuild menus, clear all first 834 //rebuild menus, clear all first
814 editAccountMenu->clear(); 835 editAccountMenu->clear();
815 selectAccountMenu->clear(); 836 selectAccountMenu->clear();
816 deleteAccountMenu->clear(); 837 deleteAccountMenu->clear();
817 838
818 newAccountId = editAccountMenu->insertItem("New", this, 839 newAccountId = editAccountMenu->insertItem("New", this,
819 SLOT(editAccount(int)) ); 840 SLOT(editAccount(int)) );
820 editAccountMenu->insertSeparator(); 841 editAccountMenu->insertSeparator();
821 842
822 idCount = 0; 843 idCount = 0;
823 for (accountPtr = accountList.first(); accountPtr != 0; 844 for (accountPtr = accountList.first(); accountPtr != 0;
824 accountPtr = accountList.next()) { 845 accountPtr = accountList.next()) {
825 846
826 editAccountMenu->insertItem(accountPtr->accountName, 847 editAccountMenu->insertItem(accountPtr->accountName,
827 this, SLOT(editAccount(int)), 0, idCount); 848 this, SLOT(editAccount(int)), 0, idCount);
828 selectAccountMenu->insertItem(accountPtr->accountName, 849 selectAccountMenu->insertItem(accountPtr->accountName,
829 this, SLOT(selectAccount(int)), 0, idCount); 850 this, SLOT(selectAccount(int)), 0, idCount);
830 deleteAccountMenu->insertItem(accountPtr->accountName, 851 deleteAccountMenu->insertItem(accountPtr->accountName,
831 this, SLOT(deleteAccount(int)), 0, idCount); 852 this, SLOT(deleteAccount(int)), 0, idCount);
832 idCount++; 853 idCount++;
833 } 854 }
834} 855}
835 856
836void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) 857void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox)
837{ 858{
838 Email *mPtr; 859 Email *mPtr;
839 Enclosure *ePtr; 860 Enclosure *ePtr;
840 861
841 if (inbox) 862 if (inbox)
842 { 863 {
843 mPtr = mailItem->getMail(); 864 mPtr = mailItem->getMail();
844 865
845 //if mail is in queue for download, remove it from 866 //if mail is in queue for download, remove it from
846 //queue if possible 867 //queue if possible
847 if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { 868 if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) {
848 if ( !mPtr->downloaded ) 869 if ( !mPtr->downloaded )
849 mailDownloadList.remove(mPtr->serverId, mPtr->size); 870 mailDownloadList.remove(mPtr->serverId, mPtr->size);
850 } 871 }
851 872
852 mailconf->setGroup(mPtr->id); 873 mailconf->setGroup(mPtr->id);
853 mailconf->clearGroup(); 874 mailconf->clearGroup();
854 875
855 //delete any temporary attatchemnts storing 876 //delete any temporary attatchemnts storing
856 for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { 877 for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) {
857 if (ePtr->saved) { 878 if (ePtr->saved) {
858 QFile::remove( (ePtr->path + ePtr->name) ); 879 QFile::remove( (ePtr->path + ePtr->name) );
859 } 880 }
860 } 881 }
861 inboxView->takeItem(mailItem); 882 inboxView->takeItem(mailItem);
862 } 883 }
863 else 884 else
864 { 885 {
865 outboxView->takeItem(mailItem); 886 outboxView->takeItem(mailItem);
866 } 887 }
867} 888}
868 889
869void EmailClient::setMailSize(int size) 890void EmailClient::setMailSize(int size)
870{ 891{
871 progressBar->reset(); 892 progressBar->reset();
872 progressBar->setTotalSteps(size); 893 progressBar->setTotalSteps(size);
873} 894}
874 895
875void EmailClient::setTotalSize(int size) 896void EmailClient::setTotalSize(int size)
876{ 897{
877 898
878} 899}
879 900
880void EmailClient::setDownloadedSize(int size) 901void EmailClient::setDownloadedSize(int size)
881{ 902{
882 int total = progressBar->totalSteps(); 903 int total = progressBar->totalSteps();
883 904
884 if (size < total) { 905 if (size < total) {
885 progressBar->setProgress(size); 906 progressBar->setProgress(size);
886 } else { 907 } else {
887 progressBar->setProgress(total); 908 progressBar->setProgress(total);
888 } 909 }
889} 910}
890 911
891void EmailClient::deleteItem() 912void EmailClient::deleteItem()
892{ 913{
893 bool inbox=mailboxView->currentTab()==0; 914 bool inbox=mailboxView->currentTab()==0;
894 QListView* box; 915 QListView* box;
895 916
896 EmailListItem* eli; 917 EmailListItem* eli;
897 int pos; 918 int pos;
898 919
899 inbox ? box=inboxView : box=outboxView; 920 inbox ? box=inboxView : box=outboxView;
900 921
901 eli=(EmailListItem*)box->selectedItem(); 922 eli=(EmailListItem*)box->selectedItem();
902 923
903 if (eli) 924 if (eli)
904 { 925 {
905 box->setSelected(eli->itemBelow(),true);//select the previous item 926 box->setSelected(eli->itemBelow(),true);//select the previous item
906 927
907 deleteMail(eli,(bool&)inbox); //remove mail entry 928 deleteMail(eli,(bool&)inbox); //remove mail entry
908 } 929 }
909} 930}
910 931
911void EmailClient::inboxItemPressed() 932void EmailClient::inboxItemPressed()
912{ 933{
913 //timerID=startTimer(500); 934 //timerID=startTimer(500);
914} 935}
915 936
916void EmailClient::inboxItemReleased() 937void EmailClient::inboxItemReleased()
917{ 938{
918 //killTimer(timerID); 939 //killTimer(timerID);
919} 940}
920 941
921void EmailClient::timerEvent(QTimerEvent *e) 942/*void EmailClient::timerEvent(QTimerEvent *e)
922{ 943{
923 /*killTimer(timerID); 944 /*killTimer(timerID);
924 945
925 946
926 QPopupMenu *action = new QPopupMenu(this); 947 QPopupMenu *action = new QPopupMenu(this);
927 948
928 int reply=0; 949 int reply=0;
929 950
930 action->insertItem(tr( "Reply To" ),this,SLOT(reply())); 951 action->insertItem(tr( "Reply To" ),this,SLOT(reply()));
931 action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); 952 action->insertItem( tr( "Reply All" ),this,SLOT(replyAll()));
932 action->insertItem( tr( "Forward" ), this,SLOT(forward())); 953 action->insertItem( tr( "Forward" ), this,SLOT(forward()));
933 action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); 954 action->insertItem( tr( "Remove Mail" ), this,SLOT(remove()));
934 955
935 action->exec(QCursor::pos()); 956 action->exec(QCursor::pos());
936 957
937 if (action) delete action; 958 if (action) delete action;
938 */ 959
939} 960}*/
940 961
941Email* EmailClient::getCurrentMail() 962Email* EmailClient::getCurrentMail()
942{ 963{
943 EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); 964 EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem());
944 if (eli!=NULL) 965 if (eli!=NULL)
945 return eli->getMail(); 966 return eli->getMail();
946 else 967 else
947 return NULL; 968 return NULL;
948} 969}
949 970
950void EmailClient::download(Email* mail) 971void EmailClient::download(Email* mail)
951{ 972{
952 MailAccount* acc=0; 973 MailAccount* acc=0;
953 974
954 tempMailDownloadList.clear(); 975 tempMailDownloadList.clear();
955 tempMailDownloadList.sizeInsert(mail->serverId, mail->size); 976 tempMailDownloadList.sizeInsert(mail->serverId, mail->size);
956 if (accountList.count()>0)
957 qDebug("Accounts present");
958 977
959 acc=accountList.at(mail->fromAccountId-1); 978 acc=accountList.at(mail->fromAccountId-1);
960 if (acc) 979 if (acc)
961 { 980 {
962 emailHandler->setAccount(*acc); 981 emailHandler->setAccount(*acc);
963 emailHandler->getMailByList(&tempMailDownloadList); 982 emailHandler->getMailByList(&tempMailDownloadList);
964 } 983 }
965 else 984 else
966 QMessageBox::warning(qApp->activeWindow(), 985 QMessageBox::warning(qApp->activeWindow(),
967 tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n"); 986 tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n");
968} 987}
988
989void EmailClient::receive(const QCString& msg, const QByteArray& data)
990{
991 /*if (msg=="getMail()")
992 {
993 /*QDialog qd(qApp->activeWindow(),"Getting mail",true);
994 QVBoxLayout *vbProg = new QVBoxLayout( &qd );
995
996 initStatusBar(&qd);
997
998 if (statusBar==0)
999 {
1000 qDebug("No Bar ...");
1001 //statusBar=new ProgressBar(&qd);
1002 }
1003 statusBar->show();
1004 vbProg->addWidget(statusBar);
1005 qd.showMaximized();
1006 qd.show();
1007 emit getAllNewMail();
1008 //qd.exec();
1009 }
1010 else if (msg=="compose()")
1011 {
1012 QDialog qd(qApp->activeWindow(),"Getting mail",true);
1013
1014 WriteMail wm(&qd,"write new mail");
1015 QVBoxLayout vbProg( &qd );
1016
1017 wm.showMaximized();
1018 vbProg.addWidget(&wm);
1019
1020 qd.showMaximized();
1021
1022 emit composeRequested();
1023 qd.exec();
1024
1025 QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n");
1026 }
1027
1028 else if (msg=="dialog()")
1029 {
1030 QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n");
1031 }*/
1032}
diff --git a/noncore/net/mailit/emailclient.h b/noncore/net/mailit/emailclient.h
index 549683b..994fec5 100644
--- a/noncore/net/mailit/emailclient.h
+++ b/noncore/net/mailit/emailclient.h
@@ -1,174 +1,181 @@
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#ifndef EMAILCLIENT_H 20#ifndef EMAILCLIENT_H
21#define EMAILCLIENT_H 21#define EMAILCLIENT_H
22 22
23#include <qlist.h> 23#include <qlist.h>
24#include <qcstring.h> 24#include <qcstring.h>
25#include <qmainwindow.h> 25#include <qmainwindow.h>
26 26
27#include <qtoolbar.h> 27#include <qtoolbar.h>
28#include <qcheckbox.h> 28#include <qcheckbox.h>
29#include <qlabel.h> 29#include <qlabel.h>
30#include <qlineedit.h> 30#include <qlineedit.h>
31#include <qlistview.h> 31#include <qlistview.h>
32#include <qaction.h> 32#include <qaction.h>
33#include <qlayout.h> 33#include <qlayout.h>
34#include <qtooltip.h> 34#include <qtooltip.h>
35#include <qtoolbutton.h> 35#include <qtoolbutton.h>
36#include <qimage.h> 36#include <qimage.h>
37#include <qpixmap.h> 37#include <qpixmap.h>
38#include <qstringlist.h> 38#include <qstringlist.h>
39#include <qprogressbar.h> 39#include <qprogressbar.h>
40#include <qstatusbar.h> 40#include <qstatusbar.h>
41#include <qdir.h> 41#include <qdir.h>
42#include <stdlib.h> 42#include <stdlib.h>
43#include <opie/otabwidget.h> 43#include <opie/otabwidget.h>
44#include <qpe/qcopenvelope_qws.h>
44#include <qtimer.h> 45#include <qtimer.h>
45 46
46#include "emailhandler.h" 47#include "emailhandler.h"
47#include "emaillistitem.h" 48#include "emaillistitem.h"
48#include "textparser.h" 49#include "textparser.h"
49#include "editaccount.h" 50#include "editaccount.h"
50#include "maillist.h" 51#include "maillist.h"
51#include "addresslist.h" 52#include "addresslist.h"
52 53
53#include <qpe/config.h> 54#include <qpe/config.h>
54 55
55class AccountList : public QList<MailAccount> 56class AccountList : public QList<MailAccount>
56{ 57{
57public: 58public:
58 Item newItem(Item d); 59 Item newItem(Item d);
59private: 60private:
60 MailAccount* dupl(MailAccount *in); 61 MailAccount* dupl(MailAccount *in);
61 MailAccount *ac; 62 MailAccount *ac;
62}; 63};
63 64
64//class EmailClient : public EmailClientBase 65//class EmailClient : public EmailClientBase
65class EmailClient : public QMainWindow 66class EmailClient : public QMainWindow
66{ 67{
67 Q_OBJECT 68 Q_OBJECT
68 69
69public: 70public:
70 EmailClient( QWidget* parent, const char* name, WFlags fl = 0 ); 71 EmailClient( QWidget* parent, const char* name, WFlags fl = 0 );
71 ~EmailClient(); 72 ~EmailClient();
72 AddressList* getAdrListRef(); 73 AddressList* getAdrListRef();
73 void download(Email*);
74 74
75protected: 75protected:
76 void timerEvent(QTimerEvent*); 76 //void timerEvent(QTimerEvent*);
77 77
78signals: 78signals:
79 void composeRequested(); 79 void composeRequested();
80 void viewEmail(QListView *, Email *); 80 void viewEmail(QListView *, Email *);
81 void mailUpdated(Email *); 81 void mailUpdated(Email *);
82 void newCaption(const QString &); 82 void newCaption(const QString &);
83 void replyRequested(Email&, bool&); 83 void replyRequested(Email&, bool&);
84 void forwardRequested(Email&); 84 void forwardRequested(Email&);
85 void removeItem(EmailListItem*, bool&); 85 void removeItem(EmailListItem*, bool&);
86 /*void reply(Email&); 86 /*void reply(Email&);
87 void replyAll(Email&); 87 void replyAll(Email&);
88 void remove(Email&); 88 void remove(Email&);
89 void forward(Email&);*/ 89 void forward(Email&);*/
90 90
91public slots: 91public slots:
92 void compose(); 92 void compose();
93 void cancel(); 93 void cancel();
94 void enqueMail(const Email &mail); 94 void enqueMail(const Email &mail);
95 void setMailAccount(); 95 void setMailAccount();
96 void sendQuedMail(); 96 void sendQuedMail();
97 void mailSent(); 97 void mailSent();
98 void deleteItem(); 98 void deleteItem();
99 void getNewMail(); 99 void getNewMail();
100 void getAllNewMail(); 100 void getAllNewMail();
101 void smtpError(int code); 101 void smtpError(int code);
102 void popError(int code); 102 void popError(int code);
103 void inboxItemSelected(); 103 void inboxItemSelected();
104 void outboxItemSelected(); 104 void outboxItemSelected();
105 void inboxItemPressed(); 105 void inboxItemPressed();
106 void inboxItemReleased(); 106 void inboxItemReleased();
107 void mailArrived(const Email &mail, bool fromDisk); 107 void mailArrived(const Email &mail, bool fromDisk);
108 void allMailArrived(int); 108 void allMailArrived(int);
109 void saveMail(QString fileName, QListView *view); 109 void saveMail(QString fileName, QListView *view);
110 void selectAccount(int); 110 void selectAccount(int);
111 void editAccount(int); 111 void editAccount(int);
112 void updateAccounts(); 112 void updateAccounts();
113 void deleteAccount(int); 113 void deleteAccount(int);
114 void deleteMail(EmailListItem *mailItem, bool &inbox); 114 void deleteMail(EmailListItem *mailItem, bool &inbox);
115 void setTotalSize(int); 115 void setTotalSize(int);
116 void setMailSize(int); 116 void setMailSize(int);
117 void setDownloadedSize(int); 117 void setDownloadedSize(int);
118 void moveMailFront(Email *mailPtr); 118 void moveMailFront(Email *mailPtr);
119 void download(Email*);
119/* void reply(); 120/* void reply();
120 void replyAll(); 121 void replyAll();
121 void forward(); 122 void forward();
122 void remove();*/ 123 void remove();*/
123 124
125private slots:
126 void receive(const QCString&, const QByteArray&);
127
124private: 128private:
125 void init(); 129 void init();
130 void initStatusBar(QWidget*);
126 void readMail(); 131 void readMail();
127 QString getPath(bool enclosurePath); 132 QString getPath(bool enclosurePath);
128 void readSettings(); 133 void readSettings();
129 void saveSettings(); 134 void saveSettings();
130 Email* getCurrentMail(); 135 Email* getCurrentMail();
131 int timerID; 136 int timerID;
132 Config *mailconf; 137 Config *mailconf;
133 int newAccountId, idCount, mailIdCount; 138 int newAccountId, idCount, mailIdCount;
134 int accountIdCount; 139 int accountIdCount;
135 AccountList accountList; 140 AccountList accountList;
136 AddressList *addressList; 141 AddressList *addressList;
137 142
138 EditAccount *editAccountView; 143 EditAccount *editAccountView;
139 EmailListItem *item; 144 EmailListItem *item;
140 EmailHandler *emailHandler; 145 EmailHandler *emailHandler;
141 QList<Email> quedMessages; 146 QList<Email> quedMessages;
142 MailList mailDownloadList; 147 MailList mailDownloadList;
143 MailList tempMailDownloadList; 148 MailList tempMailDownloadList;
144 149
145 bool sending, receiving, previewingMail, allAccounts; 150 bool sending, receiving, previewingMail, allAccounts;
146 QString lineShift; 151 QString lineShift;
147 MailAccount account, *currentAccount; 152 MailAccount account, *currentAccount;
148 153
154 QCopChannel* channel;
155
149 QToolBar *bar; 156 QToolBar *bar;
150 QProgressBar *progressBar; 157 QProgressBar *progressBar;
151 QStatusBar *statusBar; 158 QStatusBar *statusBar;
152 QLabel *status1Label, *status2Label; 159 QLabel *status1Label, *status2Label;
153 QToolButton *getMailButton; 160 QToolButton *getMailButton;
154 QAction *sendMailButton; 161 QAction *sendMailButton;
155 QAction *composeButton; 162 QAction *composeButton;
156 QAction *cancelButton; 163 QAction *cancelButton;
157 QAction *deleteButton; 164 QAction *deleteButton;
158 //QToolButton *setAccountButton; 165 //QToolButton *setAccountButton;
159 166
160 QMenuBar *mb; 167 QMenuBar *mb;
161 QPopupMenu *selectAccountMenu; 168 QPopupMenu *selectAccountMenu;
162 QPopupMenu *editAccountMenu; 169 QPopupMenu *editAccountMenu;
163 QPopupMenu *deleteAccountMenu; 170 QPopupMenu *deleteAccountMenu;
164 QPopupMenu *setAccountMenu; 171 QPopupMenu *setAccountMenu;
165 172
166 OTabWidget* mailboxView; 173 OTabWidget* mailboxView;
167 QListView* inboxView; 174 QListView* inboxView;
168 QListView* outboxView; 175 QListView* outboxView;
169 176
170 QGridLayout* grid_2; 177 QGridLayout* grid_2;
171 QGridLayout* grid_3; 178 QGridLayout* grid_3;
172}; 179};
173 180
174#endif // EMAILCLIENT_H 181#endif // EMAILCLIENT_H
diff --git a/noncore/net/mailit/emailhandler.cpp b/noncore/net/mailit/emailhandler.cpp
index fbbada7..c7b27a0 100644
--- a/noncore/net/mailit/emailhandler.cpp
+++ b/noncore/net/mailit/emailhandler.cpp
@@ -1,309 +1,312 @@
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");
43
42 smtpClient = new SmtpClient(); 44 smtpClient = new SmtpClient();
43 popClient = new PopClient(); 45 popClient = new PopClient();
44 46
45 connect(smtpClient, SIGNAL(errorOccurred(int)), this, 47 connect(smtpClient, SIGNAL(errorOccurred(int)), this,
46 SIGNAL(smtpError(int)) ); 48 SIGNAL(smtpError(int)) );
47 connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); 49 connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) );
48 connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, 50 connect(smtpClient, SIGNAL(updateStatus(const QString &)), this,
49 SIGNAL(updateSmtpStatus(const QString &)) ); 51 SIGNAL(updateSmtpStatus(const QString &)) );
50 52
51 connect(popClient, SIGNAL(errorOccurred(int)), this, 53 connect(popClient, SIGNAL(errorOccurred(int)), this,
52 SIGNAL(popError(int)) ); 54 SIGNAL(popError(int)) );
53 connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), 55 connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)),
54 this, SLOT(messageArrived(const QString &, int, uint, bool)) ); 56 this, SLOT(messageArrived(const QString &, int, uint, bool)) );
55 connect(popClient, SIGNAL(updateStatus(const QString &)), this, 57 connect(popClient, SIGNAL(updateStatus(const QString &)), this,
56 SIGNAL(updatePopStatus(const QString &)) ); 58 SIGNAL(updatePopStatus(const QString &)) );
57 connect(popClient, SIGNAL(mailTransfered(int)), this, 59 connect(popClient, SIGNAL(mailTransfered(int)), this,
58 SIGNAL(mailTransfered(int)) ); 60 SIGNAL(mailTransfered(int)) );
59 61
60 62
61 //relaying size information 63 //relaying size information
62 connect(popClient, SIGNAL(currentMailSize(int)), 64 connect(popClient, SIGNAL(currentMailSize(int)),
63 this, SIGNAL(currentMailSize(int)) ); 65 this, SIGNAL(currentMailSize(int)) );
64 connect(popClient, SIGNAL(downloadedSize(int)), 66 connect(popClient, SIGNAL(downloadedSize(int)),
65 this, SIGNAL(downloadedSize(int)) ); 67 this, SIGNAL(downloadedSize(int)) );
66} 68}
67 69
68void EmailHandler::sendMail(QList<Email> *mailList) 70void EmailHandler::sendMail(QList<Email> *mailList)
69{ 71{
70 Email *currentMail; 72 Email *currentMail;
71 QString temp; 73 QString temp;
72 QString userName = mailAccount.name; 74 QString userName = mailAccount.name;
73 userName += " <" + mailAccount.emailAddress + ">"; 75 userName += " <" + mailAccount.emailAddress + ">";
74 76
75 for (currentMail = mailList->first(); currentMail != 0; 77 for (currentMail = mailList->first(); currentMail != 0;
76 currentMail = mailList->next()) { 78 currentMail = mailList->next()) {
77 79
78 if (encodeMime(currentMail) == 0) { 80 if (encodeMime(currentMail) == 0) {
79 smtpClient->addMail(userName, currentMail->subject, 81 smtpClient->addMail(userName, currentMail->subject,
80 currentMail->recipients, currentMail->rawMail); 82 currentMail->recipients, currentMail->rawMail);
81 } else { //error 83 } else { //error
82 temp = tr("Could not locate all files in \nmail with subject: ") + 84 temp = tr("Could not locate all files in \nmail with subject: ") +
83 currentMail->subject; 85 currentMail->subject;
84 temp += tr("\nMail has NOT been sent"); 86 temp += tr("\nMail has NOT been sent");
85 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); 87 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n"));
86 88
87 } 89 }
88 } 90 }
89 smtpClient->newConnection(mailAccount.smtpServer, 25); 91 smtpClient->newConnection(mailAccount.smtpServer, 25);
90} 92}
91 93
92void EmailHandler::setAccount(MailAccount account) 94void EmailHandler::setAccount(MailAccount account)
93{ 95{
94 mailAccount = account; 96 mailAccount = account;
95} 97}
96 98
97void EmailHandler::getMail() 99void EmailHandler::getMail()
98{ 100{
99 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); 101 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
100 if (mailAccount.synchronize) { 102 if (mailAccount.synchronize) {
101 popClient->setSynchronize(mailAccount.lastServerMailCount); 103 popClient->setSynchronize(mailAccount.lastServerMailCount);
102 } else { 104 } else {
103 popClient->removeSynchronize(); 105 popClient->removeSynchronize();
104 } 106 }
105 107
106 headers = FALSE; 108 headers = FALSE;
107 //popClient->headersOnly(headers, 0); 109 //popClient->headersOnly(headers, 0);
108 popClient->newConnection(mailAccount.popServer, 110); 110 popClient->newConnection(mailAccount.popServer, 110);
109} 111}
110 112
111void EmailHandler::getMailHeaders() 113void EmailHandler::getMailHeaders()
112{ 114{
113 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); 115 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
114 mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); 116 mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize();
115 117
116 headers = TRUE; 118 headers = TRUE;
117 popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all 119 popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all
120 qDebug("Initiating connection");
118 popClient->newConnection(mailAccount.popServer, 110); 121 popClient->newConnection(mailAccount.popServer, 110);
119} 122}
120 123
121void EmailHandler::getMailByList(MailList *mailList) 124void EmailHandler::getMailByList(MailList *mailList)
122{ 125{
123 if (mailList->count() == 0) { //should not occur though 126 if (mailList->count() == 0) { //should not occur though
124 emit mailTransfered(0); 127 emit mailTransfered(0);
125 return; 128 return;
126 } 129 }
127 130
128 headers = FALSE; 131 headers = FALSE;
129 popClient->headersOnly(FALSE, 0); 132 popClient->headersOnly(FALSE, 0);
130 133
131 popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd); 134 popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd);
132 popClient->setSelectedMails(mailList); 135 popClient->setSelectedMails(mailList);
133 popClient->newConnection(mailAccount.popServer, 110); 136 popClient->newConnection(mailAccount.popServer, 110);
134 } 137 }
135 138
136void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) 139void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete)
137{ 140{
138 Email mail; 141 Email mail;
139 142
140 mail.rawMail = message; 143 mail.rawMail = message;
141 mail.serverId = id; 144 mail.serverId = id;
142 mail.size = size; 145 mail.size = size;
143 mail.downloaded = complete; 146 mail.downloaded = complete;
144 147
145 emit mailArrived(mail, FALSE); 148 emit mailArrived(mail, FALSE);
146} 149}
147 150
148bool EmailHandler::parse(QString in, QString lineShift, Email *mail) 151bool EmailHandler::parse(QString in, QString lineShift, Email *mail)
149{ 152{
150 QString temp, boundary; 153 QString temp, boundary;
151 int pos; 154 int pos;
152 QString delimiter, header, body, mimeHeader, mimeBody; 155 QString delimiter, header, body, mimeHeader, mimeBody;
153 QString content, contentType, contentAttribute, id, encoding; 156 QString content, contentType, contentAttribute, id, encoding;
154 QString fileName, storedName; 157 QString fileName, storedName;
155 int enclosureId = 0; 158 int enclosureId = 0;
156 159
157 mail->rawMail = in; 160 mail->rawMail = in;
158 mail->received = TRUE; 161 mail->received = TRUE;
159 mail->files.setAutoDelete(TRUE); 162 mail->files.setAutoDelete(TRUE);
160 163
161 temp = lineShift + "." + lineShift; 164 temp = lineShift + "." + lineShift;
162 165
163 if (in.right(temp.length()) != temp) { 166 if (in.right(temp.length()) != temp) {
164 mail->rawMail += temp; 167 mail->rawMail += temp;
165 } 168 }
166 169
167 170
168 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" 171 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n"
169 pos = in.find(delimiter, 0, FALSE); 172 pos = in.find(delimiter, 0, FALSE);
170 header = in.left(pos); 173 header = in.left(pos);
171 body = in.right(in.length() - pos - delimiter.length()); 174 body = in.right(in.length() - pos - delimiter.length());
172 if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) 175 if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n'))
173 body.truncate(body.length()-2); 176 body.truncate(body.length()-2);
174 177
175 TextParser p(header, lineShift); 178 TextParser p(header, lineShift);
176 179
177 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { 180 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) {
178 pos++; 181 pos++;
179 if (p.separatorAt(pos) == ' ') { 182 if (p.separatorAt(pos) == ' ') {
180 mail->from = p.getString(&pos, '<', false); 183 mail->from = p.getString(&pos, '<', false);
181 mail->from = mail->from.stripWhiteSpace(); 184 mail->from = mail->from.stripWhiteSpace();
182 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { 185 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) {
183 mail->from = mail->from.left(mail->from.length() - 1); 186 mail->from = mail->from.left(mail->from.length() - 1);
184 mail->from = mail->from.right(mail->from.length() - 1); 187 mail->from = mail->from.right(mail->from.length() - 1);
185 } 188 }
186 pos++; 189 pos++;
187 mail->fromMail = p.getString(&pos, '>', false); 190 mail->fromMail = p.getString(&pos, '>', false);
188 } else { 191 } else {
189 if (p.separatorAt(pos) == '<') //No name.. nasty 192 if (p.separatorAt(pos) == '<') //No name.. nasty
190 pos++; 193 pos++;
191 //pos++; 194 //pos++;
192 mail->fromMail = p.getString(&pos, 'z', TRUE); 195 mail->fromMail = p.getString(&pos, 'z', TRUE);
193 if (mail->fromMail.at(mail->fromMail.length()-1) == '>') 196 if (mail->fromMail.at(mail->fromMail.length()-1) == '>')
194 mail->fromMail.truncate(mail->fromMail.length() - 1); 197 mail->fromMail.truncate(mail->fromMail.length() - 1);
195 mail->from=mail->fromMail; 198 mail->from=mail->fromMail;
196 } 199 }
197 } 200 }
198 201
199 pos=0; 202 pos=0;
200 203
201 //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: 204 //Search for To: after the FROM: attribute to prevent hitting the Delivered-To:
202 while((pos = p.find("TO",':', pos+1, TRUE))!=-1) 205 while((pos = p.find("TO",':', pos+1, TRUE))!=-1)
203 { 206 {
204 QString rec; 207 QString rec;
205 208
206 if (p.separatorAt(pos-1)!='-') 209 if (p.separatorAt(pos-1)!='-')
207 { 210 {
208 pos++; 211 pos++;
209 mail->recipients.append(p.getString(&pos, '\r', TRUE)); 212 mail->recipients.append(p.getString(&pos, '\r', TRUE));
210 } 213 }
211 /*else { 214 /*else {
212 if ((p.separatorAt(pos) == '<')|| (p.separatorAt(pos) == ' ')) //No name.. nasty 215 if ((p.separatorAt(pos) == '<')|| (p.separatorAt(pos) == ' ')) //No name.. nasty
213 pos++; 216 pos++;
214 pos++; 217 pos++;
215 mail->fromMail = p.getString(&pos, 'z', TRUE); 218 mail->fromMail = p.getString(&pos, 'z', TRUE);
216 if (mail->fromMail.at(mail->fromMail.length()-1) == '>') 219 if (mail->fromMail.at(mail->fromMail.length()-1) == '>')
217 mail->fromMail.truncate(mail->fromMail.length() - 1); 220 mail->fromMail.truncate(mail->fromMail.length() - 1);
218 mail->from=mail->fromMail; 221 mail->from=mail->fromMail;
219 } 222 }
220 mail->recipients.append (p.getString(&pos, 'z', TRUE) ); 223 mail->recipients.append (p.getString(&pos, 'z', TRUE) );
221 }*/ 224 }*/
222 } 225 }
223 // 226 //
224 //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); 227 //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") );
225 228
226 if ((pos = p.find("CC",':', 0, TRUE)) != -1) 229 if ((pos = p.find("CC",':', 0, TRUE)) != -1)
227 { 230 {
228 pos++; 231 pos++;
229 mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); 232 mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) );
230 } 233 }
231 234
232 if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { 235 if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) {
233 pos++; 236 pos++;
234 mail->subject = p.getString(&pos, 'z', TRUE); 237 mail->subject = p.getString(&pos, 'z', TRUE);
235 } 238 }
236 239
237 if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { 240 if ((pos = p.find("DATE",':', 0, TRUE)) != -1) {
238 pos++; 241 pos++;
239 mail->date = p.getString(&pos, 'z', TRUE); 242 mail->date = p.getString(&pos, 'z', TRUE);
240 } 243 }
241 244
242 245
243 246
244 if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { 247 if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) {
245 pos++; 248 pos++;
246 if ( (p.wordAt(pos).upper() == "ID") && 249 if ( (p.wordAt(pos).upper() == "ID") &&
247 (p.separatorAt(pos) == ':') ) { 250 (p.separatorAt(pos) == ':') ) {
248 251
249 id = p.getString(&pos, 'z', TRUE); 252 id = p.getString(&pos, 'z', TRUE);
250 mail->id = id; 253 mail->id = id;
251 } 254 }
252 } 255 }
253 256
254 pos = 0; 257 pos = 0;
255 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { 258 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) {
256 pos++; 259 pos++;
257 if ( (p.wordAt(pos).upper() == "VERSION") && 260 if ( (p.wordAt(pos).upper() == "VERSION") &&
258 (p.separatorAt(pos) == ':') ) { 261 (p.separatorAt(pos) == ':') ) {
259 pos++; 262 pos++;
260 if (p.getString(&pos, 'z', true) == "1.0") { 263 if (p.getString(&pos, 'z', true) == "1.0") {
261 mail->mimeType = 1; 264 mail->mimeType = 1;
262 } 265 }
263 } 266 }
264 } 267 }
265 268
266 if (mail->mimeType == 1) { 269 if (mail->mimeType == 1) {
267 boundary = ""; 270 boundary = "";
268 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { 271 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) {
269 pos++; 272 pos++;
270 boundary = p.getString(&pos, 'z', true); 273 boundary = p.getString(&pos, 'z', true);
271 if (boundary[0] == '"') { 274 if (boundary[0] == '"') {
272 boundary = boundary.left(boundary.length() - 1); //strip " 275 boundary = boundary.left(boundary.length() - 1); //strip "
273 boundary = boundary.right(boundary.length() - 1); //strip " 276 boundary = boundary.right(boundary.length() - 1); //strip "
274 } 277 }
275 boundary = "--" + boundary; //create boundary field 278 boundary = "--" + boundary; //create boundary field
276 } 279 }
277 280
278 if (boundary == "") { //fooled by Mime-Version 281 if (boundary == "") { //fooled by Mime-Version
279 mail->body = body; 282 mail->body = body;
280 mail->bodyPlain = body; 283 mail->bodyPlain = body;
281 return mail; 284 return mail;
282 } 285 }
283 286
284 while (body.length() > 0) { 287 while (body.length() > 0) {
285 pos = body.find(boundary, 0, FALSE); 288 pos = body.find(boundary, 0, FALSE);
286 pos = body.find(delimiter, pos, FALSE); 289 pos = body.find(delimiter, pos, FALSE);
287 mimeHeader = body.left(pos); 290 mimeHeader = body.left(pos);
288 mimeBody = body.right(body.length() - pos - delimiter.length()); 291 mimeBody = body.right(body.length() - pos - delimiter.length());
289 TextParser bp(mimeHeader, lineShift); 292 TextParser bp(mimeHeader, lineShift);
290 293
291 contentType = ""; 294 contentType = "";
292 contentAttribute = ""; 295 contentAttribute = "";
293 fileName = ""; 296 fileName = "";
294 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) { 297 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) {
295 pos++; 298 pos++;
296 if ( (bp.wordAt(pos).upper() == "TYPE") && 299 if ( (bp.wordAt(pos).upper() == "TYPE") &&
297 (bp.separatorAt(pos) == ':') ) { 300 (bp.separatorAt(pos) == ':') ) {
298 contentType = bp.nextWord().upper(); 301 contentType = bp.nextWord().upper();
299 if (bp.nextSeparator() == '/') 302 if (bp.nextSeparator() == '/')
300 contentAttribute = bp.nextWord().upper(); 303 contentAttribute = bp.nextWord().upper();
301 content = contentType + "/" + contentAttribute; 304 content = contentType + "/" + contentAttribute;
302 } 305 }
303 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) { 306 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) {
304 pos++; 307 pos++;
305 encoding = bp.getString(&pos, 'z', TRUE); 308 encoding = bp.getString(&pos, 'z', TRUE);
306 } 309 }
307 310
308 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) { 311 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) {
309 pos++; 312 pos++;
@@ -437,192 +440,193 @@ int EmailHandler::parse64base(char *src, char *bufOut) {
437 bufOut[2] = bufOut[2] | z; //third byte retrieved 440 bufOut[2] = bufOut[2] | z; //third byte retrieved
438 processed++; 441 processed++;
439 } 442 }
440 } 443 }
441 return processed; 444 return processed;
442} 445}
443 446
444int EmailHandler::encodeMime(Email *mail) 447int EmailHandler::encodeMime(Email *mail)
445{ 448{
446 449
447 QString fileName, fileType, contentType, newBody, boundary; 450 QString fileName, fileType, contentType, newBody, boundary;
448 Enclosure *ePtr; 451 Enclosure *ePtr;
449 452
450 QString userName = mailAccount.name; 453 QString userName = mailAccount.name;
451 if (userName.length()>0)//only embrace it if there is a user name 454 if (userName.length()>0)//only embrace it if there is a user name
452 userName += " <" + mailAccount.emailAddress + ">"; 455 userName += " <" + mailAccount.emailAddress + ">";
453 456
454 //add standard headers 457 //add standard headers
455 newBody = "From: " + userName + "\r\nTo: "; 458 newBody = "From: " + userName + "\r\nTo: ";
456 for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) { 459 for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) {
457 newBody += *it + " "; 460 newBody += *it + " ";
458 } 461 }
459 462
460 newBody += "\r\nCC: "; 463 newBody += "\r\nCC: ";
461 464
462 for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) { 465 for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) {
463 newBody += *it + " "; 466 newBody += *it + " ";
464 } 467 }
465 468
466 newBody += "\r\nSubject: " + mail->subject + "\r\n"; 469 newBody += "\r\nSubject: " + mail->subject + "\r\n";
467 470
468 if (mail->files.count() == 0) { //just a simple mail 471 if (mail->files.count() == 0) { //just a simple mail
469 newBody += "\r\n" + mail->body; 472 newBody += "\r\n" + mail->body;
470 mail->rawMail = newBody; 473 mail->rawMail = newBody;
471 return 0; 474 return 0;
472 } 475 }
473 476
474 //Build mime encoded mail 477 //Build mime encoded mail
475 boundary = "-----4345=next_bound=0495----"; 478 boundary = "-----4345=next_bound=0495----";
476 479
477 newBody += "Mime-Version: 1.0\r\n"; 480 newBody += "Mime-Version: 1.0\r\n";
478 newBody += "Content-Type: multipart/mixed; boundary=\"" + 481 newBody += "Content-Type: multipart/mixed; boundary=\"" +
479 boundary + "\"\r\n\r\n"; 482 boundary + "\"\r\n\r\n";
480 483
481 newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n"; 484 newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n";
482 newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n"; 485 newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n";
483 newBody += mail->body; 486 newBody += mail->body;
484 487
485 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 488 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
486 fileName = ePtr->originalName; 489 fileName = ePtr->originalName;
487 fileType = ePtr->contentType; 490 fileType = ePtr->contentType;
488 QFileInfo fi(fileName); 491 QFileInfo fi(fileName);
489 492
490 // This specification of contentType is temporary 493 // This specification of contentType is temporary
491 contentType = ""; 494 contentType = "";
492 if (fileType == "Picture") { 495 if (fileType == "Picture") {
493 contentType = "image/x-image"; 496 contentType = "image/x-image";
494 } else if (fileType == "Document") { 497 } else if (fileType == "Document") {
495 contentType = "text/plain"; 498 contentType = "text/plain";
496 } else if (fileType == "Sound") { 499 } else if (fileType == "Sound") {
497 contentType = "audio/x-wav"; 500 contentType = "audio/x-wav";
498 } else if (fileType == "Movie") { 501 } else if (fileType == "Movie") {
499 contentType = "video/mpeg"; 502 contentType = "video/mpeg";
500 } else { 503 } else {
501 contentType = "application/octet-stream"; 504 contentType = "application/octet-stream";
502 } 505 }
503 506
504 newBody += "\r\n\r\n--" + boundary + "\r\n"; 507 newBody += "\r\n\r\n--" + boundary + "\r\n";
505 newBody += "Content-Type: " + contentType + "; name=\"" + 508 newBody += "Content-Type: " + contentType + "; name=\"" +
506 fi.fileName() + "\"\r\n"; 509 fi.fileName() + "\"\r\n";
507 newBody += "Content-Transfer-Encoding: base64\r\n"; 510 newBody += "Content-Transfer-Encoding: base64\r\n";
508 newBody += "Content-Disposition: inline; filename=\"" + 511 newBody += "Content-Disposition: inline; filename=\"" +
509 fi.fileName() + "\"\r\n\r\n"; 512 fi.fileName() + "\"\r\n\r\n";
510 513
511 if (encodeFile(fileName, &newBody) == -1) //file not found? 514 if (encodeFile(fileName, &newBody) == -1) //file not found?
512 return -1; 515 return -1;
513 } 516 }
514 517
515 newBody += "\r\n\r\n--" + boundary + "--"; 518 newBody += "\r\n\r\n--" + boundary + "--";
516 mail->rawMail = newBody; 519 mail->rawMail = newBody;
517 520
518 return 0; 521 return 0;
519} 522}
520 523
521int EmailHandler::encodeFile(QString fileName, QString *toBody) 524int EmailHandler::encodeFile(QString fileName, QString *toBody)
522{ 525{
523 char *fileData; 526 char *fileData;
524 char *dataPtr; 527 char *dataPtr;
525 QString temp; 528 QString temp;
526 uint dataSize, count; 529 uint dataSize, count;
527 QFile f(fileName); 530 QFile f(fileName);
528 531
529 if (! f.open(IO_ReadOnly) ) { 532 if (! f.open(IO_ReadOnly) ) {
530 qWarning("could not open file: " + fileName); 533 qWarning("could not open file: " + fileName);
531 return -1; 534 return -1;
532 } 535 }
533 QTextStream s(&f); 536 QTextStream s(&f);
534 dataSize = f.size(); 537 dataSize = f.size();
535 fileData = (char *) malloc(dataSize + 3); 538 fileData = (char *) malloc(dataSize + 3);
536 s.readRawBytes(fileData, dataSize); 539 s.readRawBytes(fileData, dataSize);
537 540
538 temp = ""; 541 temp = "";
539 dataPtr = fileData; 542 dataPtr = fileData;
540 count = 0; 543 count = 0;
541 while (dataSize > 0) { 544 while (dataSize > 0) {
542 if (dataSize < 3) { 545 if (dataSize < 3) {
543 encode64base(dataPtr, &temp, dataSize); 546 encode64base(dataPtr, &temp, dataSize);
544 dataSize = 0; 547 dataSize = 0;
545 } else { 548 } else {
546 encode64base(dataPtr, &temp, 3); 549 encode64base(dataPtr, &temp, 3);
547 dataSize -= 3; 550 dataSize -= 3;
548 dataPtr += 3; 551 dataPtr += 3;
549 count += 4; 552 count += 4;
550 } 553 }
551 if (count > 72) { 554 if (count > 72) {
552 count = 0; 555 count = 0;
553 temp += "\r\n"; 556 temp += "\r\n";
554 } 557 }
555 } 558 }
556 toBody->append(temp); 559 toBody->append(temp);
557 560
558 delete(fileData); 561 delete(fileData);
559 f.close(); 562 f.close();
560 return 0; 563 return 0;
561} 564}
562 565
563void EmailHandler::encode64base(char *src, QString *dest, int len) 566void EmailHandler::encode64base(char *src, QString *dest, int len)
564{ 567{
565 QString temp; 568 QString temp;
566 uchar c; 569 uchar c;
567 uchar bufOut[4]; 570 uchar bufOut[4];
568 571
569 bufOut[0] = src[0]; 572 bufOut[0] = src[0];
570 bufOut[0] >>= 2; //Done byte 0 573 bufOut[0] >>= 2; //Done byte 0
571 574
572 bufOut[1] = src[0]; 575 bufOut[1] = src[0];
573 bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits 576 bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits
574 bufOut[1] <<= 4; //copy up 4 places 577 bufOut[1] <<= 4; //copy up 4 places
575 if (len > 1) { 578 if (len > 1) {
576 c = src[1]; 579 c = src[1];
577 } else { 580 } else {
578 c = 0; 581 c = 0;
579 } 582 }
580 583
581 c = c & (16 + 32 + 64 + 128); 584 c = c & (16 + 32 + 64 + 128);
582 c >>= 4; 585 c >>= 4;
583 bufOut[1] = bufOut[1] | c; //Done byte 1 586 bufOut[1] = bufOut[1] | c; //Done byte 1
584 587
585 bufOut[2] = src[1]; 588 bufOut[2] = src[1];
586 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8); 589 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8);
587 bufOut[2] <<= 2; 590 bufOut[2] <<= 2;
588 if (len > 2) { 591 if (len > 2) {
589 c = src[2]; 592 c = src[2];
590 } else { 593 } else {
591 c = 0; 594 c = 0;
592 } 595 }
593 c >>= 6; 596 c >>= 6;
594 bufOut[2] = bufOut[2] | c; 597 bufOut[2] = bufOut[2] | c;
595 598
596 bufOut[3] = src[2]; 599 bufOut[3] = src[2];
597 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32); 600 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32);
598 601
599 if (len == 1) { 602 if (len == 1) {
600 bufOut[2] = 64; 603 bufOut[2] = 64;
601 bufOut[3] = 64; 604 bufOut[3] = 64;
602 } 605 }
603 if (len == 2) { 606 if (len == 2) {
604 bufOut[3] = 64; 607 bufOut[3] = 64;
605 } 608 }
606 for (int x = 0; x < 4; x++) { 609 for (int x = 0; x < 4; x++) {
607 if (bufOut[x] <= 25) 610 if (bufOut[x] <= 25)
608 bufOut[x] += (uint) 'A'; 611 bufOut[x] += (uint) 'A';
609 else if (bufOut[x] >= 26 && bufOut[x] <= 51) 612 else if (bufOut[x] >= 26 && bufOut[x] <= 51)
610 bufOut[x] += (uint) 'a' - 26; 613 bufOut[x] += (uint) 'a' - 26;
611 else if (bufOut[x] >= 52 && bufOut[x] <= 61) 614 else if (bufOut[x] >= 52 && bufOut[x] <= 61)
612 bufOut[x] += (uint) '0' - 52; 615 bufOut[x] += (uint) '0' - 52;
613 else if (bufOut[x] == 62) 616 else if (bufOut[x] == 62)
614 bufOut[x] = '+'; 617 bufOut[x] = '+';
615 else if (bufOut[x] == 63) 618 else if (bufOut[x] == 63)
616 bufOut[x] = '/'; 619 bufOut[x] = '/';
617 else if (bufOut[x] == 64) 620 else if (bufOut[x] == 64)
618 bufOut[x] = '='; 621 bufOut[x] = '=';
619 622
620 dest->append(bufOut[x]); 623 dest->append(bufOut[x]);
621 } 624 }
622} 625}
623 626
624void EmailHandler::cancel() 627void EmailHandler::cancel()
625{ 628{
626 popClient->errorHandling(ErrCancel); 629 popClient->errorHandling(ErrCancel);
627 smtpClient->errorHandling(ErrCancel); 630 smtpClient->errorHandling(ErrCancel);
628} 631}
632
diff --git a/noncore/net/mailit/emailhandler.h b/noncore/net/mailit/emailhandler.h
index b645868..5b59f65 100644
--- a/noncore/net/mailit/emailhandler.h
+++ b/noncore/net/mailit/emailhandler.h
@@ -1,149 +1,150 @@
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#ifndef EmailHandler_H 20#ifndef EmailHandler_H
21#define EmailHandler_H 21#define EmailHandler_H
22 22
23#include <qobject.h> 23#include <qobject.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qdatetime.h> 25#include <qdatetime.h>
26#include <qlist.h> 26#include <qlist.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qfile.h> 28#include <qfile.h>
29#include <qstringlist.h> 29#include <qstringlist.h>
30#include <qcollection.h> 30#include <qcollection.h>
31#include <qpe/qcopenvelope_qws.h>
31 32
32#include "smtpclient.h" 33#include "smtpclient.h"
33#include "popclient.h" 34#include "popclient.h"
34#include "textparser.h" 35#include "textparser.h"
35#include "maillist.h" 36#include "maillist.h"
36 37
37struct Enclosure 38struct Enclosure
38{ 39{
39 int id; 40 int id;
40 QString originalName; 41 QString originalName;
41 QString name; 42 QString name;
42 QString path; 43 QString path;
43 QString contentType; 44 QString contentType;
44 QString contentAttribute; 45 QString contentAttribute;
45 QString encoding; 46 QString encoding;
46 QString body; //might use to much mem. check!! 47 QString body; //might use to much mem. check!!
47 bool saved, installed; 48 bool saved, installed;
48}; 49};
49 50
50class EnclosureList : public QList<Enclosure> 51class EnclosureList : public QList<Enclosure>
51{ 52{
52public: 53public:
53 Item newItem(Item d); 54 Item newItem(Item d);
54private: 55private:
55 Enclosure* dupl(Enclosure *in); 56 Enclosure* dupl(Enclosure *in);
56 Enclosure *ac; 57 Enclosure *ac;
57}; 58};
58 59
59struct Email 60struct Email
60{ 61{
61 QString id; 62 QString id;
62 QString from; 63 QString from;
63 QString fromMail; 64 QString fromMail;
64 QStringList recipients; 65 QStringList recipients;
65 QStringList carbonCopies; 66 QStringList carbonCopies;
66 QString date; 67 QString date;
67 QString subject; 68 QString subject;
68 QString body; 69 QString body;
69 QString bodyPlain; 70 QString bodyPlain;
70 bool sent, received, read, downloaded; 71 bool sent, received, read, downloaded;
71 QString rawMail; 72 QString rawMail;
72 int mimeType; //1 = Mime 1.0 73 int mimeType; //1 = Mime 1.0
73 int serverId; 74 int serverId;
74 int internalId; 75 int internalId;
75 int fromAccountId; 76 int fromAccountId;
76 QString contentType; //0 = text 77 QString contentType; //0 = text
77 QString contentAttribute; //0 = plain, 1 = html 78 QString contentAttribute; //0 = plain, 1 = html
78 EnclosureList files; 79 EnclosureList files;
79 uint size; 80 uint size;
80 81
81 void addEnclosure(Enclosure *e) 82 void addEnclosure(Enclosure *e)
82 { 83 {
83 files.append(e); 84 files.append(e);
84 } 85 }
85}; 86};
86 87
87struct MailAccount 88struct MailAccount
88{ 89{
89 QString accountName; 90 QString accountName;
90 QString name; 91 QString name;
91 QString emailAddress; 92 QString emailAddress;
92 QString popUserName; 93 QString popUserName;
93 QString popPasswd; 94 QString popPasswd;
94 QString popServer; 95 QString popServer;
95 QString smtpServer; 96 QString smtpServer;
96 bool synchronize; 97 bool synchronize;
97 int syncLimit; 98 int syncLimit;
98 int lastServerMailCount; 99 int lastServerMailCount;
99 int id; 100 int id;
100}; 101};
101 102
102 const int ErrUnknownResponse = 1001; 103 const int ErrUnknownResponse = 1001;
103 const int ErrLoginFailed = 1002; 104 const int ErrLoginFailed = 1002;
104 const int ErrCancel = 1003; 105 const int ErrCancel = 1003;
105 106
106 107
107class EmailHandler : public QObject 108class EmailHandler : public QObject
108{ 109{
109 Q_OBJECT 110 Q_OBJECT
110 111
111public: 112public:
112 EmailHandler(); 113 EmailHandler();
113 void setAccount(MailAccount account); 114 void setAccount(MailAccount account);
114 MailAccount* getAccount(){return &mailAccount;} 115 MailAccount* getAccount(){return &mailAccount;}
115 void sendMail(QList<Email> *mailList); 116 void sendMail(QList<Email> *mailList);
116 void getMail(); 117 void getMail();
117 void getMailHeaders(); 118 void getMailHeaders();
118 void getMailByList(MailList *mailList); 119 void getMailByList(MailList *mailList);
119 bool parse(QString in, QString lineShift, Email *mail); 120 bool parse(QString in, QString lineShift, Email *mail);
120 bool getEnclosure(Enclosure *ePtr); 121 bool getEnclosure(Enclosure *ePtr);
121 int parse64base(char *src, char *dest); 122 int parse64base(char *src, char *dest);
122 int encodeMime(Email *mail); 123 int encodeMime(Email *mail);
123 int encodeFile(QString fileName, QString *toBody); 124 int encodeFile(QString fileName, QString *toBody);
124 void encode64base(char *src, QString *dest, int len); 125 void encode64base(char *src, QString *dest, int len);
125 void cancel(); 126 void cancel();
126 127
127signals: 128signals:
128 void mailSent(); 129 void mailSent();
129 void smtpError(int); 130 void smtpError(int);
130 void popError(int); 131 void popError(int);
131 void mailArrived(const Email &, bool); 132 void mailArrived(const Email &, bool);
132 void updatePopStatus(const QString &); 133 void updatePopStatus(const QString &);
133 void updateSmtpStatus(const QString &); 134 void updateSmtpStatus(const QString &);
134 void mailTransfered(int); 135 void mailTransfered(int);
135 void mailboxSize(int); 136 void mailboxSize(int);
136 void currentMailSize(int); 137 void currentMailSize(int);
137 void downloadedSize(int); 138 void downloadedSize(int);
138 139
139public slots: 140public slots:
140 void messageArrived(const QString &, int id, uint size, bool complete); 141 void messageArrived(const QString &, int id, uint size, bool complete);
141 142
142private: 143private:
143 MailAccount mailAccount; 144 MailAccount mailAccount;
144 SmtpClient *smtpClient; 145 SmtpClient *smtpClient;
145 PopClient *popClient; 146 PopClient *popClient;
146 bool headers; 147 bool headers;
147}; 148};
148 149
149#endif 150#endif
diff --git a/noncore/net/mailit/mailitwindow.cpp b/noncore/net/mailit/mailitwindow.cpp
index ffee67e..a111241 100644
--- a/noncore/net/mailit/mailitwindow.cpp
+++ b/noncore/net/mailit/mailitwindow.cpp
@@ -1,165 +1,168 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qwhatsthis.h> 20#include <qwhatsthis.h>
21#include <qmessagebox.h> 21#include <qmessagebox.h>
22#include "mailitwindow.h" 22#include "mailitwindow.h"
23 23
24MailItWindow::MailItWindow(QWidget *parent, const char *name, WFlags fl) 24MailItWindow::MailItWindow(QWidget *parent, const char *name, WFlags fl)
25 : QMainWindow(parent, name, WStyle_ContextHelp) 25 : QMainWindow(parent, name, WStyle_ContextHelp)
26{ 26{
27 currentCaption = "Mailit"; 27 currentCaption = "Mailit";
28 setCaption(tr(currentCaption)); 28 setCaption(tr(currentCaption));
29 views = new QWidgetStack(this); 29 views = new QWidgetStack(this);
30 setCentralWidget(views); 30 setCentralWidget(views);
31 QWhatsThis::add(views,tr("Central view area")); 31 QWhatsThis::add(views,tr("Central view area"));
32 emailClient = new EmailClient(views, "client"); 32 emailClient = new EmailClient(views, "client");
33 writeMail = new WriteMail(views, "writing"); 33 writeMail = new WriteMail(views, "writing");
34 readMail = new ReadMail(views, "reading"); 34 readMail = new ReadMail(views, "reading");
35 35
36 views->raiseWidget(emailClient); 36 views->raiseWidget(emailClient);
37 37
38 connect(emailClient, SIGNAL(composeRequested()), 38 connect(emailClient, SIGNAL(composeRequested()),
39 this, SLOT(compose()) ); 39 this, SLOT(compose()) );
40 connect(emailClient, SIGNAL(viewEmail(QListView *, Email *)), this, 40 connect(emailClient, SIGNAL(viewEmail(QListView *, Email *)), this,
41 SLOT(viewMail(QListView *, Email *)) ); 41 SLOT(viewMail(QListView *, Email *)) );
42 connect(emailClient, SIGNAL(mailUpdated(Email *)), this, 42 connect(emailClient, SIGNAL(mailUpdated(Email *)), this,
43 SLOT(updateMailView(Email *)) ); 43 SLOT(updateMailView(Email *)) );
44 44
45 connect(writeMail, SIGNAL(cancelMail()), this, SLOT(showEmailClient()) ); 45 connect(writeMail, SIGNAL(cancelMail()), this, SLOT(showEmailClient()) );
46 connect(writeMail, SIGNAL(sendMailRequested(const Email &)), this, 46 connect(writeMail, SIGNAL(sendMailRequested(const Email &)), this,
47 SLOT(showEmailClient()) ); 47 SLOT(showEmailClient()) );
48 connect(writeMail, SIGNAL(sendMailRequested(const Email &)), emailClient, 48 connect(writeMail, SIGNAL(sendMailRequested(const Email &)), emailClient,
49 SLOT(enqueMail(const Email &)) ); 49 SLOT(enqueMail(const Email &)) );
50 50
51 connect(readMail, SIGNAL(cancelView()), this, SLOT(showEmailClient()) ); 51 connect(readMail, SIGNAL(cancelView()), this, SLOT(showEmailClient()) );
52 connect(readMail, SIGNAL(replyRequested(Email &, bool&)), this, 52 connect(readMail, SIGNAL(replyRequested(Email &, bool&)), this,
53 SLOT(composeReply(Email &, bool&)) ); 53 SLOT(composeReply(Email &, bool&)) );
54 connect(readMail, SIGNAL(forwardRequested(Email &)), this, 54 connect(readMail, SIGNAL(forwardRequested(Email &)), this,
55 SLOT(composeForward(Email &)) ); 55 SLOT(composeForward(Email &)) );
56 56
57 connect(readMail, SIGNAL(removeItem(EmailListItem *, bool &)), emailClient, 57 connect(readMail, SIGNAL(removeItem(EmailListItem *, bool &)), emailClient,
58 SLOT(deleteMail(EmailListItem *, bool &)) ); 58 SLOT(deleteMail(EmailListItem *, bool &)) );
59 connect(readMail, SIGNAL(viewingMail(Email *)), emailClient, 59 connect(readMail, SIGNAL(viewingMail(Email *)), emailClient,
60 SLOT(moveMailFront(Email *)) ); 60 SLOT(moveMailFront(Email *)) );
61 61
62 connect(emailClient, SIGNAL(newCaption(const QString &)), 62 connect(emailClient, SIGNAL(newCaption(const QString &)),
63 this, SLOT(updateCaption(const QString &)) ); 63 this, SLOT(updateCaption(const QString &)) );
64
65 connect(readMail, SIGNAL(download(Email *)), emailClient, SLOT(download(Email*)) );
66
64 viewingMail = FALSE; 67 viewingMail = FALSE;
65} 68}
66 69
67MailItWindow::~MailItWindow() 70MailItWindow::~MailItWindow()
68{ 71{
69} 72}
70 73
71void MailItWindow::closeEvent(QCloseEvent *e) 74void MailItWindow::closeEvent(QCloseEvent *e)
72{ 75{
73 if (views->visibleWidget() == emailClient) { 76 if (views->visibleWidget() == emailClient) {
74 e->accept(); 77 e->accept();
75 } else { 78 } else {
76 showEmailClient(); 79 showEmailClient();
77 } 80 }
78} 81}
79 82
80void MailItWindow::compose() 83void MailItWindow::compose()
81{ 84{
82 viewingMail = FALSE; 85 viewingMail = FALSE;
83 emailClient->hide(); 86 emailClient->hide();
84 readMail->hide(); 87 readMail->hide();
85 views->raiseWidget(writeMail); 88 views->raiseWidget(writeMail);
86 writeMail->setAddressList(emailClient->getAdrListRef()); 89 writeMail->setAddressList(emailClient->getAdrListRef());
87 writeMail->newMail(); 90 writeMail->newMail();
88 setCaption( tr( "Write mail" ) ); 91 setCaption( tr( "Write mail" ) );
89} 92}
90 93
91void MailItWindow::composeReply(Email &mail, bool& replyAll) 94void MailItWindow::composeReply(Email &mail, bool& replyAll)
92{ 95{
93 compose(); 96 compose();
94 writeMail->reply(mail,replyAll) ; 97 writeMail->reply(mail,replyAll) ;
95} 98}
96 99
97void MailItWindow::composeForward(Email &mail) 100void MailItWindow::composeForward(Email &mail)
98{ 101{
99 compose(); 102 compose();
100 writeMail->forward(mail) ; 103 writeMail->forward(mail) ;
101} 104}
102 105
103 106
104void MailItWindow::showEmailClient() 107void MailItWindow::showEmailClient()
105{ 108{
106 viewingMail = FALSE; 109 viewingMail = FALSE;
107 writeMail->hide(); 110 writeMail->hide();
108 readMail->hide(); 111 readMail->hide();
109 views->raiseWidget(emailClient); 112 views->raiseWidget(emailClient);
110 setCaption( tr(currentCaption) ); 113 setCaption( tr(currentCaption) );
111} 114}
112 115
113void MailItWindow::viewMail(QListView *view, Email *mail) 116void MailItWindow::viewMail(QListView *view, Email *mail)
114{ 117{
115 viewingMail = TRUE; 118 viewingMail = TRUE;
116 emailClient->hide(); 119 emailClient->hide();
117 120
118 int result=0; 121 int result=0;
119 122
120 if ((mail->received)&&(!mail->downloaded)) 123 if ((mail->received)&&(!mail->downloaded))
121 { 124 {
122 QMessageBox mb( tr("Mail not downloaded"), 125 QMessageBox mb( tr("Mail not downloaded"),
123 tr("The mail you have clicked \n" 126 tr("The mail you have clicked \n"
124 "has not been downloaded yet.\n " 127 "has not been downloaded yet.\n "
125 "Would you like to do it now ?"), 128 "Would you like to do it now ?"),
126 QMessageBox::Information, 129 QMessageBox::Information,
127 QMessageBox::Yes | QMessageBox::Default, 130 QMessageBox::Yes | QMessageBox::Default,
128 QMessageBox::No | QMessageBox::Escape,0 ); 131 QMessageBox::No | QMessageBox::Escape,0 );
129 132
130 result=mb.exec(); 133 result=mb.exec();
131 134
132 if (result==QMessageBox::Yes) 135 if (result==QMessageBox::Yes)
133 { 136 {
134 emailClient->download(mail); 137 emailClient->download(mail);
135 } 138 }
136 } 139 }
137 140
138 readMail->update(view, mail); 141 readMail->update(view, mail);
139 views->raiseWidget(readMail); 142 views->raiseWidget(readMail);
140 setCaption( tr( "Examine mail" ) ); 143 setCaption( tr( "Examine mail" ) );
141} 144}
142 145
143void MailItWindow::updateMailView(Email *mail) 146void MailItWindow::updateMailView(Email *mail)
144{ 147{
145 if (viewingMail) { 148 if (viewingMail) {
146 readMail->mailUpdated(mail); 149 readMail->mailUpdated(mail);
147 } 150 }
148} 151}
149 152
150void MailItWindow::updateCaption(const QString &newCaption) 153void MailItWindow::updateCaption(const QString &newCaption)
151{ 154{
152 currentCaption = newCaption; 155 currentCaption = newCaption;
153 setCaption(tr(currentCaption)); 156 setCaption(tr(currentCaption));
154} 157}
155 158
156void MailItWindow::setDocument(const QString &_address) 159void MailItWindow::setDocument(const QString &_address)
157{ 160{
158 // strip leading 'mailto:' 161 // strip leading 'mailto:'
159 QString address = _address; 162 QString address = _address;
160 if (address.startsWith("mailto:")) 163 if (address.startsWith("mailto:"))
161 address = address.mid(6); 164 address = address.mid(6);
162 165
163 compose(); 166 compose();
164 writeMail->setRecipient(address); 167 writeMail->setRecipient(address);
165} 168}
diff --git a/noncore/net/mailit/popclient.cpp b/noncore/net/mailit/popclient.cpp
index 6105d09..fedc4e2 100644
--- a/noncore/net/mailit/popclient.cpp
+++ b/noncore/net/mailit/popclient.cpp
@@ -1,325 +1,327 @@
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 "popclient.h" 20#include "popclient.h"
21#include "emailhandler.h" 21#include "emailhandler.h"
22//#define APOP_TEST 22//#define APOP_TEST
23 23
24extern "C" { 24extern "C" {
25#include "md5.h" 25#include "md5.h"
26} 26}
27 27
28#include <qcstring.h> 28#include <qcstring.h>
29 29
30PopClient::PopClient() 30PopClient::PopClient()
31{ 31{
32
32 socket = new QSocket(this, "popClient"); 33 socket = new QSocket(this, "popClient");
33 connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); 34 connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int)));
34 connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); 35 connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished()));
35 connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); 36 connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData()));
36 37
37 stream = new QTextStream(socket); 38 stream = new QTextStream(socket);
38 39
39 receiving = FALSE; 40 receiving = FALSE;
40 synchronize = FALSE; 41 synchronize = FALSE;
41 lastSync = 0; 42 lastSync = 0;
42 headerLimit = 0; 43 headerLimit = 0;
43 preview = FALSE; 44 preview = FALSE;
44} 45}
45 46
46PopClient::~PopClient() 47PopClient::~PopClient()
47{ 48{
48 delete socket; 49 delete socket;
49 delete stream; 50 delete stream;
50} 51}
51 52
52void PopClient::newConnection(QString target, int port) 53void PopClient::newConnection(QString target, int port)
53{ 54{
54 if (receiving) { 55 if (receiving) {
55 qWarning("socket in use, connection refused"); 56 qWarning("socket in use, connection refused");
56 return; 57 return;
57 } 58 }
58 59
59 status = Init; 60 status = Init;
60 61
61 socket->connectToHost(target, port); 62 socket->connectToHost(target, port);
62 receiving = TRUE; 63 receiving = TRUE;
63 //selected = FALSE; 64 //selected = FALSE;
64 65
65 emit updateStatus("DNS lookup"); 66 emit updateStatus("DNS lookup");
66} 67}
67 68
68void PopClient::setAccount(QString popUser, QString popPasswd) 69void PopClient::setAccount(QString popUser, QString popPasswd)
69{ 70{
70 popUserName = popUser; 71 popUserName = popUser;
71 popPassword = popPasswd; 72 popPassword = popPasswd;
72} 73}
73 74
74void PopClient::setSynchronize(int lastCount) 75void PopClient::setSynchronize(int lastCount)
75{ 76{
76 synchronize = TRUE; 77 synchronize = TRUE;
77 lastSync = lastCount; 78 lastSync = lastCount;
78} 79}
79 80
80void PopClient::removeSynchronize() 81void PopClient::removeSynchronize()
81{ 82{
82 synchronize = FALSE; 83 synchronize = FALSE;
83 lastSync = 0; 84 lastSync = 0;
84} 85}
85 86
86void PopClient::headersOnly(bool headers, int limit) 87void PopClient::headersOnly(bool headers, int limit)
87{ 88{
88 preview = headers; 89 preview = headers;
89 headerLimit = limit; 90 headerLimit = limit;
90} 91}
91 92
92void PopClient::setSelectedMails(MailList *list) 93void PopClient::setSelectedMails(MailList *list)
93{ 94{
94 selected = TRUE; 95 selected = TRUE;
95 mailList = list; 96 mailList = list;
96} 97}
97 98
98void PopClient::connectionEstablished() 99void PopClient::connectionEstablished()
99{ 100{
100 emit updateStatus(tr("Connection established")); 101 emit updateStatus(tr("Connection established"));
101} 102}
102 103
103void PopClient::errorHandling(int status) 104void PopClient::errorHandling(int status)
104{ 105{
105 emit updateStatus(tr("Error Occured")); 106 emit updateStatus(tr("Error Occured"));
106 emit errorOccurred(status); 107 emit errorOccurred(status);
107 socket->close(); 108 socket->close();
108 receiving = FALSE; 109 receiving = FALSE;
109} 110}
110 111
111void PopClient::incomingData() 112void PopClient::incomingData()
112{ 113{
113 QString response, temp, temp2, timeStamp; 114 QString response, temp, temp2, timeStamp;
114 QString md5Source; 115 QString md5Source;
115 int start, end; 116 int start, end;
116// char *md5Digest; 117// char *md5Digest;
117 char md5Digest[16]; 118 char md5Digest[16];
118// if ( !socket->canReadLine() ) 119// if ( !socket->canReadLine() )
119// return; 120// return;
121
120 122
121 response = socket->readLine(); 123 response = socket->readLine();
122 124
123 switch(status) { 125 switch(status) {
124 //logging in 126 //logging in
125 case Init: { 127 case Init: {
126#ifdef APOP_TEST 128#ifdef APOP_TEST
127 start = response.find('<',0); 129 start = response.find('<',0);
128 end = response.find('>', start); 130 end = response.find('>', start);
129 if( start >= 0 && end > start ) 131 if( start >= 0 && end > start )
130 { 132 {
131 timeStamp = response.mid( start , end - start + 1); 133 timeStamp = response.mid( start , end - start + 1);
132 md5Source = timeStamp + popPassword; 134 md5Source = timeStamp + popPassword;
133 135
134 md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); 136 md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]);
135 137
136 for(int j =0;j < MD5_DIGEST_LENGTH ;j++) 138 for(int j =0;j < MD5_DIGEST_LENGTH ;j++)
137 { 139 {
138 printf("%x", md5Digest[j]); 140 printf("%x", md5Digest[j]);
139 } 141 }
140 printf("\n"); 142 printf("\n");
141// qDebug(md5Digest); 143// qDebug(md5Digest);
142 *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; 144 *stream << "APOP " << popUserName << " " << md5Digest << "\r\n";
143 // qDebug("%s", stream); 145 // qDebug("%s", stream);
144 status = Stat; 146 status = Stat;
145 } 147 }
146 else 148 else
147#endif 149#endif
148 { 150 {
149 timeStamp = ""; 151 timeStamp = "";
150 *stream << "USER " << popUserName << "\r\n"; 152 *stream << "USER " << popUserName << "\r\n";
151 status = Pass; 153 status = Pass;
152 } 154 }
153 155
154 break; 156 break;
155 } 157 }
156 158
157 case Pass: { 159 case Pass: {
158 *stream << "PASS " << popPassword << "\r\n"; 160 *stream << "PASS " << popPassword << "\r\n";
159 status = Stat; 161 status = Stat;
162
160 break; 163 break;
161 } 164 }
162 //ask for number of messages 165 //ask for number of messages
163 case Stat: { 166 case Stat: {
164 if (response[0] == '+') { 167 if (response[0] == '+') {
165 *stream << "STAT" << "\r\n"; 168 *stream << "STAT" << "\r\n";
166 status = Mcnt; 169 status = Mcnt;
167 } else errorHandling(ErrLoginFailed); 170 } else errorHandling(ErrLoginFailed);
168 break; 171 break;
169 } 172 }
170 //get count of messages, eg "+OK 4 900.." -> int 4 173 //get count of messages, eg "+OK 4 900.." -> int 4
171 case Mcnt: { 174 case Mcnt: {
172 if (response[0] == '+') { 175 if (response[0] == '+') {
173 temp = response.replace(0, 4, ""); 176 temp = response.replace(0, 4, "");
174 int x = temp.find(" ", 0); 177 int x = temp.find(" ", 0);
175 temp.truncate((uint) x); 178 temp.truncate((uint) x);
176 newMessages = temp.toInt(); 179 newMessages = temp.toInt();
177 messageCount = 1; 180 messageCount = 1;
178 status = List; 181 status = List;
179 182
180 if (synchronize) { 183 if (synchronize) {
181 //messages deleted from server, reload all 184 //messages deleted from server, reload all
182 if (newMessages < lastSync) 185 if (newMessages < lastSync)
183 lastSync = 0; 186 lastSync = 0;
184 messageCount = 1; 187 messageCount = 1;
185 } 188 }
186 189
187 if (selected) { 190 if (selected) {
188 int *ptr = mailList->first(); 191 int *ptr = mailList->first();
189 if (ptr != 0) { 192 if (ptr != 0) {
190 newMessages++; //to ensure no early jumpout 193 newMessages++; //to ensure no early jumpout
191 messageCount = *ptr; 194 messageCount = *ptr;
192 } else newMessages = 0; 195 } else newMessages = 0;
193 } 196 }
194 197
195 } else errorHandling(ErrUnknownResponse); 198 } else errorHandling(ErrUnknownResponse);
196 } 199 }
197 //Read message number x, count upwards to messageCount 200 //Read message number x, count upwards to messageCount
198 case List: { 201 case List: {
199 if (messageCount <= newMessages) { 202 if (messageCount <= newMessages) {
200 *stream << "LIST " << messageCount << "\r\n"; 203 *stream << "LIST " << messageCount << "\r\n";
201 status = Size; 204 status = Size;
202 temp2.setNum(newMessages - lastSync); 205 temp2.setNum(newMessages - lastSync);
203 temp.setNum(messageCount - lastSync); 206 temp.setNum(messageCount - lastSync);
204 if (!selected) { 207 if (!selected) {
205 emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); 208 emit updateStatus(tr("Retrieving ") + temp + "/" + temp2);
206 } else { 209 } else {
207 //completing a previously closed transfer 210 //completing a previously closed transfer
208 /* if ( (messageCount - lastSync) <= 0) { 211 /* if ( (messageCount - lastSync) <= 0) {
209 temp.setNum(messageCount); 212 temp.setNum(messageCount);
210 emit updateStatus(tr("Previous message ") + temp); 213 emit updateStatus(tr("Previous message ") + temp);
211 } else {*/ 214 } else {*/
212 emit updateStatus(tr("Completing message ") + temp); 215 emit updateStatus(tr("Completing message ") + temp);
213 //} 216 //}
214 } 217 }
215 break; 218 break;
216 } else { 219 } else {
217 emit updateStatus(tr("No new Messages")); 220 emit updateStatus(tr("No new Messages"));
218 status = Quit; 221 status = Quit;
219 } 222 }
220 } 223 }
221 //get size of message, eg "500 characters in message.." -> int 500 224 //get size of message, eg "500 characters in message.." -> int 500
222 case Size: { 225 case Size: {
223 if (status != Quit) { //because of idiotic switch 226 if (status != Quit) { //because of idiotic switch
224 if (response[0] == '+') { 227 if (response[0] == '+') {
225 temp = response.replace(0, 4, ""); 228 temp = response.replace(0, 4, "");
226 int x = temp.find(" ", 0); 229 int x = temp.find(" ", 0);
227 temp = temp.right(temp.length() - ((uint) x + 1) ); 230 temp = temp.right(temp.length() - ((uint) x + 1) );
228 mailSize = temp.toInt(); 231 mailSize = temp.toInt();
229 emit currentMailSize(mailSize); 232 emit currentMailSize(mailSize);
230 233
231 status = Retr; 234 status = Retr;
232 } else { 235 } else {
233 //qWarning(response); 236 //qWarning(response);
234 errorHandling(ErrUnknownResponse); 237 errorHandling(ErrUnknownResponse);
235 } 238 }
236 } 239 }
237 } 240 }
238 //Read message number x, count upwards to messageCount 241 //Read message number x, count upwards to messageCount
239 case Retr: { 242 case Retr: {
240 if (status != Quit) { 243 if (status != Quit) {
241 if ((selected)||(mailSize <= headerLimit)) 244 if ((selected)||(mailSize <= headerLimit))
242 { 245 {
243 *stream << "RETR " << messageCount << "\r\n"; 246 *stream << "RETR " << messageCount << "\r\n";
244 } else { //only header 247 } else { //only header
245 *stream << "TOP " << messageCount << " 0\r\n"; 248 *stream << "TOP " << messageCount << " 0\r\n";
246 } 249 }
247 messageCount++; 250 messageCount++;
248 status = Ignore; 251 status = Ignore;
249 break; 252 break;
250 } } 253 } }
251 case Ignore: { 254 case Ignore: {
252 if (status != Quit) { //because of idiotic switch 255 if (status != Quit) { //because of idiotic switch
253 if (response[0] == '+') { 256 if (response[0] == '+') {
254 message = ""; 257 message = "";
255 status = Read; 258 status = Read;
256 if (!socket->canReadLine()) //sync. problems 259 if (!socket->canReadLine()) //sync. problems
257 break; 260 break;
258 response = socket->readLine(); 261 response = socket->readLine();
259 } else errorHandling(ErrUnknownResponse); 262 } else errorHandling(ErrUnknownResponse);
260 } 263 }
261 } 264 }
262 //add all incoming lines to body. When size is reached, send 265 //add all incoming lines to body. When size is reached, send
263 //message, and go back to read new message 266 //message, and go back to read new message
264 case Read: { 267 case Read: {
265 if (status != Quit) { //because of idiotic switch 268 if (status != Quit) { //because of idiotic switch
266 message += response; 269 message += response;
267 while ( socket->canReadLine() ) { 270 while ( socket->canReadLine() ) {
268 response = socket->readLine(); 271 response = socket->readLine();
269 message += response; 272 message += response;
270 } 273 }
271 emit downloadedSize(message.length()); 274 emit downloadedSize(message.length());
272 int x = message.find("\r\n.\r\n",-5); 275 int x = message.find("\r\n.\r\n",-5);
273 if (x == -1) { 276 if (x == -1) {
274 break; 277 break;
275 } else { //message reach entire size 278 } else { //message reach entire size
276
277 if ( (selected)||(mailSize <= headerLimit)) //mail size limit is not used if late download is active 279 if ( (selected)||(mailSize <= headerLimit)) //mail size limit is not used if late download is active
278 { 280 {
279 emit newMessage(message, messageCount-1, mailSize, TRUE); 281 emit newMessage(message, messageCount-1, mailSize, TRUE);
280 } else { //incomplete mail downloaded 282 } else { //incomplete mail downloaded
281 emit newMessage(message, messageCount-1, mailSize, FALSE); 283 emit newMessage(message, messageCount-1, mailSize, FALSE);
282 } 284 }
283 285
284 if ((messageCount > newMessages)||(selected)) //last message ? 286 if ((messageCount > newMessages)||(selected)) //last message ?
285 { 287 {
286 status = Quit; 288 status = Quit;
287 if (selected) { //grab next from queue 289 if (selected) { //grab next from queue
288 newMessages--; 290 newMessages--;
289 status = Quit; 291 status = Quit;
290 } 292 }
291 } 293 }
292 else 294 else
293 { 295 {
294 *stream << "LIST " << messageCount << "\r\n"; 296 *stream << "LIST " << messageCount << "\r\n";
295 status = Size; 297 status = Size;
296 temp2.setNum(newMessages - lastSync); 298 temp2.setNum(newMessages - lastSync);
297 temp.setNum(messageCount - lastSync); 299 temp.setNum(messageCount - lastSync);
298 emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); 300 emit updateStatus(tr("Retrieving ") + temp + "/" + temp2);
299 301
300 break; 302 break;
301 } 303 }
302 } 304 }
303 } 305 }
304 if (status != Quit) 306 if (status != Quit)
305 break; 307 break;
306 } 308 }
307 case Quit: { 309 case Quit: {
308 *stream << "Quit\r\n"; 310 *stream << "Quit\r\n";
309 status = Done; 311 status = Done;
310 int newM = newMessages - lastSync; 312 int newM = newMessages - lastSync;
311 if (newM > 0) { 313 if (newM > 0) {
312 temp.setNum(newM); 314 temp.setNum(newM);
313 emit updateStatus(temp + tr(" new messages")); 315 emit updateStatus(temp + tr(" new messages"));
314 } else { 316 } else {
315 emit updateStatus(tr("No new messages")); 317 emit updateStatus(tr("No new messages"));
316 } 318 }
317 319
318 socket->close(); 320 socket->close();
319 receiving = FALSE; 321 receiving = FALSE;
320 emit mailTransfered(newM); 322 emit mailTransfered(newM);
321 break; 323 break;
322 } 324 }
323 } 325 }
324 326
325} 327}
diff --git a/noncore/net/mailit/readmail.cpp b/noncore/net/mailit/readmail.cpp
index 4eae7f6..1682675 100644
--- a/noncore/net/mailit/readmail.cpp
+++ b/noncore/net/mailit/readmail.cpp
@@ -1,367 +1,399 @@
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 "readmail.h" 20#include "readmail.h"
21#include <qimage.h> 21#include <qimage.h>
22#include <qwhatsthis.h>
22#include <qmime.h> 23#include <qmime.h>
23#include <qaction.h> 24#include <qaction.h>
25#include <qpopupmenu.h>
24#include <qpe/resource.h> 26#include <qpe/resource.h>
25 27
26ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl ) 28ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl )
27 : QMainWindow(parent, name, fl) 29 : QMainWindow(parent, name, fl)
28{ 30{
29 plainTxt = FALSE; 31 plainTxt = FALSE;
30 32
31 init(); 33 init();
32 viewAtt = new ViewAtt(0, "View Attatchments"); 34 viewAtt = new ViewAtt(0, "View Attatchments");
33} 35}
34 36
35ReadMail::~ReadMail() 37ReadMail::~ReadMail()
36{ 38{
37 delete emailView->mimeSourceFactory(); 39 delete emailView->mimeSourceFactory();
38 delete viewAtt; 40 delete viewAtt;
39} 41}
40 42
41void ReadMail::init() 43void ReadMail::init()
42{ 44{
43 setToolBarsMovable(FALSE); 45 setToolBarsMovable(FALSE);
44 46
47 QPopupMenu* mailaction=new QPopupMenu(this);
48
45 bar = new QToolBar(this); 49 bar = new QToolBar(this);
46 bar->setHorizontalStretchable( TRUE ); 50 bar->setHorizontalStretchable( TRUE );
47 51
48 menu = new QMenuBar( bar ); 52 menu = new QMenuBar( bar );
49 53
50 viewMenu = new QPopupMenu(menu); 54 viewMenu = new QPopupMenu(menu);
51 menu->insertItem( tr( "&View" ), viewMenu); 55 menu->insertItem( tr( "&View" ), viewMenu);
52 56
53 mailMenu = new QPopupMenu(menu); 57 mailMenu = new QPopupMenu(menu);
54 menu->insertItem( tr( "&Mail" ), mailMenu); 58 menu->insertItem( tr( "&Mail" ), mailMenu);
55 59
56 bar = new QToolBar(this); 60 bar = new QToolBar(this);
57 61
58 //reply dependant on viewing inbox 62 downloadButton = new QAction( tr( "Download" ), Resource::loadPixmap( "mailit/download" ),QString::null, 0, this, 0 );
59 replyButton = new QAction( tr( "Reply" ), Resource::loadPixmap( "mailit/reply" ), 63 connect(downloadButton, SIGNAL(activated()), this, SLOT(download()) );
60 QString::null, 0, this, 0 ); 64 downloadButton->setWhatsThis(tr("Click here to download the selected mail"));
61 connect(replyButton, SIGNAL(activated()), this, SLOT(reply()) );
62 replyButton->setWhatsThis(tr("Click here to reply to the selected mail"));
63
64 forwardButton = new QAction( tr( "Forward" ), Resource::loadPixmap( "mailit/forward" ),
65 QString::null, 0, this, 0 );
66 connect(forwardButton, SIGNAL(activated()), this, SLOT(forward()) );
67 forwardButton->setWhatsThis(tr("Click here to forward the selected mail"));
68 65
66
69 previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); 67 previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 );
70 connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) ); 68 connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) );
71 previousButton->addTo(bar); 69 previousButton->addTo(bar);
72 previousButton->addTo(viewMenu); 70 previousButton->addTo(viewMenu);
73 previousButton->setWhatsThis(tr("Read the previous mail in the list")); 71 previousButton->setWhatsThis(tr("Read the previous mail in the list"));
74 72
75 nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 ); 73 nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 );
76 connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) ); 74 connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) );
77 nextButton->addTo(bar); 75 nextButton->addTo(bar);
78 nextButton->addTo(viewMenu); 76 nextButton->addTo(viewMenu);
79 previousButton->setWhatsThis(tr("Read the next mail in the list")); 77 previousButton->setWhatsThis(tr("Read the next mail in the list"));
80 78
81 attachmentButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "mailit/attach" ), QString::null, 0, this, 0 ); 79 attachmentButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "mailit/attach" ), QString::null, 0, this, 0 );
82 connect( attachmentButton, SIGNAL( activated() ), this, 80 connect( attachmentButton, SIGNAL( activated() ), this,
83 SLOT( viewAttachments() ) ); 81 SLOT( viewAttachments() ) );
84 attachmentButton->addTo(bar); 82 attachmentButton->addTo(bar);
85 attachmentButton->addTo(viewMenu); 83 attachmentButton->addTo(viewMenu);
86 attachmentButton->setWhatsThis(tr("Click here to add attachments to your mail")); 84 attachmentButton->setWhatsThis(tr("Click here to add attachments to your mail"));
87 85
88 plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "DocsIcon" ), QString::null, 0, this, 0, TRUE); 86 plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "DocsIcon" ), QString::null, 0, this, 0, TRUE);
89 connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) ); 87 connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) );
90 plainTextButton->addTo(bar); 88 plainTextButton->addTo(bar);
91 plainTextButton->addTo(viewMenu); 89 plainTextButton->addTo(viewMenu);
92 plainTextButton->setWhatsThis(tr("The mail view has 2 modes:\n" 90 plainTextButton->setWhatsThis(tr("The mail view has 2 modes:\n"
93 "<LI><B>RichText</B> shows the mail as HTML with reach features (no standard line breaks)</LI>" 91 "<LI><B>RichText</B> shows the mail as HTML with reach features (no standard line breaks)</LI>"
94 "<LI><B>Plain</B> shows the mail as standard plain text</LI>" 92 "<LI><B>Plain</B> shows the mail as standard plain text</LI>"
95 "Click here to switch between those view modes" )); 93 "Click here to switch between those view modes" ));
96 94
95 //reply dependant on viewing inbox
96 replyButton = new QToolButton(Resource::loadPixmap("mailit/reply"),tr("reply"),tr("reply to mail"), this,SLOT(reply()),bar);
97 QWhatsThis::add(replyButton,tr("Click here to reply to the selected mail\nPress and hold for more options."));
98 replyButton->setPopup(mailaction);
99
100 replyAllButton = new QAction( tr( "Reply all" ), Resource::loadPixmap( "mailit/reply" ),QString::null, 0, this, 0 );
101 connect(replyAllButton, SIGNAL(activated()), this, SLOT(replyAll()));
102 replyAllButton->setWhatsThis(tr("Click here to reply to the selected mail to CC: addresses also"));
103 replyAllButton->addTo(mailaction);
104
105 forwardButton = new QAction( tr( "Forward" ), Resource::loadPixmap( "mailit/forward" ),
106 QString::null, 0, this, 0 );
107 connect(forwardButton, SIGNAL(activated()), this, SLOT(forward()));
108 forwardButton->setWhatsThis(tr("Click here to forward the selected mail"));
109 forwardButton->addTo(mailaction);
110
111
97 deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); 112 deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 );
98 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); 113 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) );
99 deleteButton->addTo(bar); 114 deleteButton->addTo(bar);
100 deleteButton->addTo(mailMenu); 115 deleteButton->addTo(mailMenu);
101 deleteButton->setWhatsThis(tr("Click here to remove the selected mail")); 116 deleteButton->setWhatsThis(tr("Click here to remove the selected mail"));
102 117
103 viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close())); 118 viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close()));
104 119
105 emailView = new QTextView( this, "emailView" ); 120 emailView = new QTextView( this, "emailView" );
106 121
107 setCentralWidget(emailView); 122 setCentralWidget(emailView);
108 123
109 mime = new QMimeSourceFactory(); 124 mime = new QMimeSourceFactory();
110 emailView->setMimeSourceFactory(mime); 125 emailView->setMimeSourceFactory(mime);
111} 126}
112 127
113void ReadMail::updateView() 128void ReadMail::updateView()
114{ 129{
115 Enclosure *ePtr; 130 Enclosure *ePtr;
116 QString mailStringSize; 131 QString mailStringSize;
117 QString text, temp; 132 QString text, temp;
118 133
119 mail->read = TRUE; //mark as read 134 mail->read = TRUE; //mark as read
120 inbox = mail->received; 135 inbox = mail->received;
121 136
122 replyButton->removeFrom(mailMenu); 137 replyButton->setEnabled(false);
123 replyButton->removeFrom(bar); 138 /*replyButton->removeFrom(bar);
124 forwardButton->removeFrom(mailMenu); 139 forwardButton->removeFrom(mailMenu);
125 forwardButton->removeFrom(bar); 140 forwardButton->removeFrom(bar);*/
141 downloadButton->removeFrom(bar);
142
143 //downloadButton->setEnabled(!mail->downloaded);
126 144
145
127 if (inbox == TRUE) { 146 if (inbox == TRUE) {
128 replyButton->addTo(bar); 147 replyButton->setEnabled(true);
129 replyButton->addTo(mailMenu); 148 /*replyButton->addTo(mailMenu);
130 forwardButton->addTo(bar); 149 forwardButton->addTo(bar);
131 forwardButton->addTo(mailMenu); 150 forwardButton->addTo(mailMenu);*/
132 151
133 152
134 if (!mail->downloaded) { 153 if (!mail->downloaded) {
154
155 downloadButton->addTo(bar);
156
135 //report currently viewed mail so that it will be 157 //report currently viewed mail so that it will be
136 //placed first in the queue of new mails to download 158 //placed first in the queue of new mails to download
137 emit viewingMail(mail); 159 emit viewingMail(mail);
138 160
139 double mailSize = (double) mail->size; 161 double mailSize = (double) mail->size;
140 if (mailSize < 1024) { 162 if (mailSize < 1024) {
141 mailStringSize.setNum(mailSize); 163 mailStringSize.setNum(mailSize);
142 mailStringSize += " Bytes"; 164 mailStringSize += " Bytes";
143 } else if (mailSize < 1024*1024) { 165 } else if (mailSize < 1024*1024) {
144 mailStringSize.setNum( (mailSize / 1024), 'g', 2 ); 166 mailStringSize.setNum( (mailSize / 1024), 'g', 2 );
145 mailStringSize += " Kb"; 167 mailStringSize += " Kb";
146 } else { 168 } else {
147 mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3); 169 mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3);
148 mailStringSize += " Mb"; 170 mailStringSize += " Mb";
149 } 171 }
150 } 172 }
151 } 173 }
152 174
153 QMimeSourceFactory *mime = emailView->mimeSourceFactory(); 175 QMimeSourceFactory *mime = emailView->mimeSourceFactory();
154 176
155 if (! plainTxt) { //use RichText, inline pics etc. 177 if (! plainTxt) { //use RichText, inline pics etc.
156 emailView->setTextFormat(QTextView::RichText); 178 emailView->setTextFormat(QTextView::RichText);
157 text = "<b><big><center><font color=\"blue\">" + mail->subject 179 text = "<b><big><center><font color=\"blue\">" + mail->subject
158 +"</font></center></big></b><br>"; 180 +"</font></center></big></b><br>";
159 text += "<b>From: </b>" + mail->from + " <i>" + 181 text += "<b>From: </b>" + mail->from + " <i>" +
160 mail->fromMail + "</i><br>"; 182 mail->fromMail + "</i><br>";
161 183
162 text +="<b>To: </b>"; 184 text +="<b>To: </b>";
163 for (QStringList::Iterator it = mail->recipients.begin(); 185 for (QStringList::Iterator it = mail->recipients.begin();
164 it != mail->recipients.end(); ++it ) { 186 it != mail->recipients.end(); ++it ) {
165 text += *it + " "; 187 text += *it + " ";
166 } 188 }
167 189
168 text +="<br><b>CC: </b>"; 190 text +="<br><b>CC: </b>";
169 for (QStringList::Iterator it = mail->carbonCopies.begin(); 191 for (QStringList::Iterator it = mail->carbonCopies.begin();
170 it != mail->carbonCopies.end(); ++it ) { 192 it != mail->carbonCopies.end(); ++it ) {
171 text += *it + " "; 193 text += *it + " ";
172 } 194 }
173 195
174 text += "<br>" + mail->date; 196 text += "<br>" + mail->date;
175 197
176 if (mail->files.count() > 0) { 198 if (mail->files.count() > 0) {
177 text += "<br><b>Attatchments: </b>"; 199 text += "<br><b>Attatchments: </b>";
178 200
179 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 201 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
180 text += ePtr->originalName + " "; 202 text += ePtr->originalName + " ";
181 } 203 }
182 text += "<hr><br>" + mail->body; 204 text += "<hr><br>" + mail->body;
183 205
184 if (inbox) { 206 if (inbox) {
185 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 207 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
186 208
187 text += "<br><hr><b>Attatchment: </b>" + 209 text += "<br><hr><b>Attatchment: </b>" +
188 ePtr->originalName + "<hr>"; 210 ePtr->originalName + "<hr>";
189 211
190 if (ePtr->contentType == "TEXT") { 212 if (ePtr->contentType == "TEXT") {
191 QFile f(ePtr->path + ePtr->name); 213 QFile f(ePtr->path + ePtr->name);
192 214
193 if (f.open(IO_ReadOnly) ) { 215 if (f.open(IO_ReadOnly) ) {
194 QTextStream t(&f); 216 QTextStream t(&f);
195 temp = t.read(); 217 temp = t.read();
196 text += temp + "<br>"; 218 text += temp + "<br>";
197 f.close(); 219 f.close();
198 } else { 220 } else {
199 text += "<b>Could not locate file</b><br>"; 221 text += "<b>Could not locate file</b><br>";
200 } 222 }
201 223
202 } 224 }
203 if (ePtr->contentType == "IMAGE") { 225 if (ePtr->contentType == "IMAGE") {
204 // temp.setNum(emailView->width());//get display width 226 // temp.setNum(emailView->width());//get display width
205 // text += "<img width=" + temp +" src =""" + 227 // text += "<img width=" + temp +" src =""" +
206 // ePtr->originalName + """> </img>"; 228 // ePtr->originalName + """> </img>";
207 text += "<img src =""" + 229 text += "<img src =""" +
208 ePtr->originalName + """> </img>"; 230 ePtr->originalName + """> </img>";
209 mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) )); 231 mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) ));
210 } 232 }
211 } 233 }
212 } 234 }
213 } else { 235 } else {
214 if (mail->downloaded || !inbox) { 236 if (mail->downloaded || !inbox) {
215 text += "<hr><br>" + mail->body; 237 text += "<hr><br>" + mail->body;
216 } else { 238 } else {
217 text += "<hr><br><b> Awaiting download </b><br>"; 239 text += "<hr><br><b> Awaiting download </b><br>";
218 text += "Size of mail: " + mailStringSize; 240 text += "Size of mail: " + mailStringSize;
219 } 241 }
220 } 242 }
221 emailView->setText(text); 243 emailView->setText(text);
222 } else { // show plain txt mail 244 } else { // show plain txt mail
223 emailView->setTextFormat(QTextView::PlainText); 245 emailView->setTextFormat(QTextView::PlainText);
224 text = "Subject: " + mail->subject + "\n"; 246 text = "Subject: " + mail->subject + "\n";
225 text += "From: " + mail->from + " " + mail->fromMail + "\n"; 247 text += "From: " + mail->from + " " + mail->fromMail + "\n";
226 text += "To: "; 248 text += "To: ";
227 for (QStringList::Iterator it = mail->recipients.begin(); 249 for (QStringList::Iterator it = mail->recipients.begin();
228 it != mail->recipients.end(); ++it ) { 250 it != mail->recipients.end(); ++it ) {
229 text += *it + " "; 251 text += *it + " ";
230 } 252 }
231 253
232 text += "\nCC: "; 254 text += "\nCC: ";
233 for (QStringList::Iterator it = mail->carbonCopies.begin(); 255 for (QStringList::Iterator it = mail->carbonCopies.begin();
234 it != mail->carbonCopies.end(); ++it ) { 256 it != mail->carbonCopies.end(); ++it ) {
235 text += *it + " "; 257 text += *it + " ";
236 } 258 }
237 259
238 260
239 text += "\nDate: " + mail->date + "\n"; 261 text += "\nDate: " + mail->date + "\n";
240 if (mail->files.count() > 0) { 262 if (mail->files.count() > 0) {
241 text += "Attatchments: "; 263 text += "Attatchments: ";
242 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 264 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
243 text += ePtr->originalName + " "; 265 text += ePtr->originalName + " ";
244 } 266 }
245 text += "\n\n"; 267 text += "\n\n";
246 } else text += "\n"; 268 } else text += "\n";
247 269
248 if (!inbox) { 270 if (!inbox) {
249 text += mail->body; 271 text += mail->body;
250 } else if (mail->downloaded) { 272 } else if (mail->downloaded) {
251 text += mail->bodyPlain; 273 text += mail->bodyPlain;
252 } else { 274 } else {
253 text += "\nAwaiting download\n"; 275 text += "\nAwaiting download\n";
254 text += "Size of mail: " + mailStringSize; 276 text += "Size of mail: " + mailStringSize;
255 } 277 }
256 278
257 emailView->setText(text); 279 emailView->setText(text);
258 } 280 }
259 281
260 if (mail->files.count() == 0) 282 if (mail->files.count() == 0)
261 attachmentButton->setEnabled(FALSE); 283 attachmentButton->setEnabled(FALSE);
262 else attachmentButton->setEnabled(TRUE); 284 else attachmentButton->setEnabled(TRUE);
263 285
264 setCaption("Examining mail: " + mail->subject); 286 setCaption("Examining mail: " + mail->subject);
265} 287}
266 288
267//update view with current EmailListItem (item) 289//update view with current EmailListItem (item)
268void ReadMail::update(QListView *thisView, Email *mailIn) 290void ReadMail::update(QListView *thisView, Email *mailIn)
269{ 291{
270 view = thisView; 292 view = thisView;
271 item = (EmailListItem *) view->selectedItem(); 293 item = (EmailListItem *) view->selectedItem();
272 mail = mailIn; 294 mail = mailIn;
273 updateView(); 295 updateView();
274 updateButtons(); 296 updateButtons();
275} 297}
276 298
277void ReadMail::mailUpdated(Email *mailIn) 299void ReadMail::mailUpdated(Email *mailIn)
278{ 300{
279 if (mailIn == mail) { 301 if (mailIn == mail) {
280 updateView(); 302 updateView();
281 } else { 303 } else {
282 updateButtons(); 304 updateButtons();
283 } 305 }
284} 306}
285 307
286void ReadMail::close() 308void ReadMail::close()
287{ 309{
288 emit cancelView(); 310 emit cancelView();
289} 311}
290 312
291//gets next item in listview, exits if there is no next 313//gets next item in listview, exits if there is no next
292void ReadMail::next() 314void ReadMail::next()
293{ 315{
294 item = (EmailListItem *) item->nextSibling(); 316 item = (EmailListItem *) item->nextSibling();
295 if (item != NULL) { 317 if (item != NULL) {
296 mail = item->getMail(); 318 mail = item->getMail();
297 updateView(); 319 updateView();
298 } 320 }
299 updateButtons(); 321 updateButtons();
300} 322}
301 323
302//gets previous item in listview, exits if there is no previous 324//gets previous item in listview, exits if there is no previous
303void ReadMail::previous() 325void ReadMail::previous()
304{ 326{
305 item = (EmailListItem *) item->itemAbove(); 327 item = (EmailListItem *) item->itemAbove();
306 if (item != NULL) { 328 if (item != NULL) {
307 mail = item->getMail(); 329 mail = item->getMail();
308 updateView(); 330 updateView();
309 } 331 }
310 updateButtons(); 332 updateButtons();
311} 333}
312 334
313//deletes item, tries bringing up next or previous, exits if unsucessful 335//deletes item, tries bringing up next or previous, exits if unsucessful
314void ReadMail::deleteItem() 336void ReadMail::deleteItem()
315{ 337{
316 EmailListItem *temp = item; 338 EmailListItem *temp = item;
317 temp = (EmailListItem *) item->nextSibling();//trybelow 339 temp = (EmailListItem *) item->nextSibling();//trybelow
318 if (temp == NULL) 340 if (temp == NULL)
319 temp = (EmailListItem *) item->itemAbove(); //try above 341 temp = (EmailListItem *) item->itemAbove(); //try above
320 342
321 emit removeItem(item, inbox); 343 emit removeItem(item, inbox);
322 344
323 item = temp; 345 item = temp;
324 if (item != NULL) { //more items in list 346 if (item != NULL) { //more items in list
325 mail = item->getMail(); 347 mail = item->getMail();
326 updateView(); 348 updateView();
327 updateButtons(); 349 updateButtons();
328 } else close(); //no more items to see 350 } else close(); //no more items to see
329} 351}
330 352
331void ReadMail::updateButtons() 353void ReadMail::updateButtons()
332{ 354{
333 EmailListItem *temp; 355 EmailListItem *temp;
334 356
335 temp = item; 357 temp = item;
336 if ((EmailListItem *) temp->nextSibling() == NULL) 358 if ((EmailListItem *) temp->nextSibling() == NULL)
337 nextButton->setEnabled(FALSE); 359 nextButton->setEnabled(FALSE);
338 else nextButton->setEnabled(TRUE); 360 else nextButton->setEnabled(TRUE);
339 361
340 temp = item; 362 temp = item;
341 if ((EmailListItem *) temp->itemAbove() == NULL) 363 if ((EmailListItem *) temp->itemAbove() == NULL)
342 previousButton->setEnabled(FALSE); 364 previousButton->setEnabled(FALSE);
343 else previousButton->setEnabled(TRUE); 365 else previousButton->setEnabled(TRUE);
344} 366}
345 367
346void ReadMail::shiftText() 368void ReadMail::shiftText()
347{ 369{
348 plainTxt = ! plainTxt; 370 plainTxt = ! plainTxt;
349 updateView(); 371 updateView();
350} 372}
351 373
352void ReadMail::viewAttachments() 374void ReadMail::viewAttachments()
353{ 375{
354 viewAtt->update(mail, inbox); 376 viewAtt->update(mail, inbox);
355 viewAtt->showMaximized(); 377 viewAtt->showMaximized();
356} 378}
357 379
358void ReadMail::reply() 380void ReadMail::reply()
359{ 381{
382 emit replyRequested(*mail, (bool&)FALSE);
383}
384
385void ReadMail::replyAll()
386{
360 emit replyRequested(*mail, (bool&)TRUE); 387 emit replyRequested(*mail, (bool&)TRUE);
361} 388}
362 389
363void ReadMail::forward() 390void ReadMail::forward()
364{ 391{
365 emit forwardRequested(*mail); 392 emit forwardRequested(*mail);
366} 393}
367 394
395void ReadMail::download()
396{
397 emit download(mail);
398}
399
diff --git a/noncore/net/mailit/readmail.h b/noncore/net/mailit/readmail.h
index df32c34..6700595 100644
--- a/noncore/net/mailit/readmail.h
+++ b/noncore/net/mailit/readmail.h
@@ -1,89 +1,95 @@
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#ifndef READMAIL_H 20#ifndef READMAIL_H
21#define READMAIL_H 21#define READMAIL_H
22 22
23#include <qaction.h> 23#include <qaction.h>
24#include <qmainwindow.h> 24#include <qmainwindow.h>
25#include <qmenubar.h> 25#include <qmenubar.h>
26#include <qpopupmenu.h> 26#include <qpopupmenu.h>
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qlistview.h> 28#include <qlistview.h>
29#include <qlayout.h> 29#include <qlayout.h>
30#include <qtextview.h> 30#include <qtextview.h>
31#include <qtoolbutton.h>
31 32
32#include "emailhandler.h" 33#include "emailhandler.h"
33#include "emaillistitem.h" 34#include "emaillistitem.h"
34#include "viewatt.h" 35#include "viewatt.h"
35 36
36class ReadMail : public QMainWindow 37class ReadMail : public QMainWindow
37{ 38{
38 Q_OBJECT 39 Q_OBJECT
39 40
40public: 41public:
41 ReadMail( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 42 ReadMail( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
42 ~ReadMail(); 43 ~ReadMail();
43 void update(QListView *thisView, Email *mailIn); 44 void update(QListView *thisView, Email *mailIn);
44 void updateView(); 45 void updateView();
45 void mailUpdated(Email *mailIn); 46 void mailUpdated(Email *mailIn);
46 47
47signals: 48signals:
48 void cancelView(); 49 void cancelView();
49 void replyRequested(Email &, bool &); 50 void replyRequested(Email &, bool &);
50 void forwardRequested(Email&); 51 void forwardRequested(Email&);
51 void removeItem(EmailListItem *, bool &); 52 void removeItem(EmailListItem *, bool &);
52 void viewingMail(Email *); 53 void viewingMail(Email *);
54 void download (Email*);
53 55
54public slots: 56public slots:
55 void close(); 57 void close();
56 void next(); 58 void next();
57 void previous(); 59 void previous();
58 void deleteItem(); 60 void deleteItem();
59 void shiftText(); 61 void shiftText();
60 void viewAttachments(); 62 void viewAttachments();
61 void reply(); 63 void reply();
64 void replyAll();
62 void forward(); 65 void forward();
66 void download();
63 67
64private: 68private:
65 void init(); 69 void init();
66 void updateButtons(); 70 void updateButtons();
67 71
68private: 72private:
69 QListView *view; 73 QListView *view;
70 EmailListItem *item; 74 EmailListItem *item;
71 bool plainTxt, inbox; 75 bool plainTxt, inbox;
72 Email *mail; 76 Email *mail;
73 ViewAtt *viewAtt; 77 ViewAtt *viewAtt;
74 78
75 QToolBar *bar; 79 QToolBar *bar;
76 QMenuBar *menu; 80 QMenuBar *menu;
77 QPopupMenu *viewMenu, *mailMenu; 81 QPopupMenu *viewMenu, *mailMenu;
78 QAction *deleteButton; 82 QAction *deleteButton;
79 QMimeSourceFactory *mime; 83 QMimeSourceFactory *mime;
80 QAction *plainTextButton; 84 QAction *plainTextButton;
81 QAction *nextButton; 85 QAction *nextButton;
82 QTextView *emailView; 86 QTextView *emailView;
83 QAction *attachmentButton; 87 QAction *attachmentButton;
84 QAction *previousButton; 88 QAction *previousButton;
85 QAction *replyButton; 89 QToolButton *replyButton;
86 QAction *forwardButton; 90 QAction *forwardButton;
91 QAction *replyAllButton;
92 QAction *downloadButton;
87}; 93};
88 94
89#endif // READMAIL_H 95#endif // READMAIL_H
diff --git a/noncore/net/mailit/writemail.cpp b/noncore/net/mailit/writemail.cpp
index dcf0c6e..c75494e 100644
--- a/noncore/net/mailit/writemail.cpp
+++ b/noncore/net/mailit/writemail.cpp
@@ -1,389 +1,402 @@
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 <qmessagebox.h> 20#include <qmessagebox.h>
21#include <qwhatsthis.h> 21#include <qwhatsthis.h>
22#include "writemail.h" 22#include "writemail.h"
23#include <qpe/resource.h> 23#include <qpe/resource.h>
24 24
25WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl ) 25WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl ):QMainWindow( parent, name, fl )
26 : QMainWindow( parent, name, fl )
27{ 26{
28 showingAddressList = FALSE; 27 showingAddressList = FALSE;
29 init(); 28 init();
30 29
31 addAtt = new AddAtt(0, "Add Attachments"); 30 addAtt = new AddAtt(0, "Add Attachments");
32} 31}
33 32
34WriteMail::~WriteMail() 33WriteMail::~WriteMail()
35{ 34{
36 delete addAtt; 35 delete addAtt;
37} 36}
38 37
39void WriteMail::setAddressList(AddressList *list) 38void WriteMail::setAddressList(AddressList *list)
40{ 39{
41 Contact *cPtr; 40 Contact *cPtr;
42 41
43 addressList = list; 42 addressList = list;
44 43
45 addressView->clear(); 44 addressView->clear();
46 QList<Contact> *cListPtr = addressList->getContactList(); 45 QList<Contact> *cListPtr = addressList->getContactList();
47 QListViewItem *item; 46 QListViewItem *item;
48 for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) { 47 for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) {
49 item = new QListViewItem(addressView, cPtr->name, cPtr->email); 48 item = new QListViewItem(addressView, cPtr->name, cPtr->email);
50 } 49 }
51} 50}
52 51
53void WriteMail::init() 52void WriteMail::init()
54{ 53{
55 setToolBarsMovable(FALSE); 54 setToolBarsMovable(FALSE);
56 55
57 bar = new QToolBar(this); 56 bar = new QToolBar(this);
58 bar->setHorizontalStretchable( TRUE ); 57 bar->setHorizontalStretchable( TRUE );
59 58
60 menu = new QMenuBar( bar ); 59 menu = new QMenuBar( bar );
61 60
62 mailMenu = new QPopupMenu(menu); 61 mailMenu = new QPopupMenu(menu);
63 menu->insertItem( tr( "&Mail" ), mailMenu); 62 menu->insertItem( tr( "&Mail" ), mailMenu);
64 addMenu = new QPopupMenu(menu); 63 addMenu = new QPopupMenu(menu);
65 menu->insertItem( tr( "&Add" ), addMenu); 64 menu->insertItem( tr( "&Add" ), addMenu);
66 65
67 bar = new QToolBar(this); 66 bar = new QToolBar(this);
68 attachButton = new QAction(tr("Attachment"), Resource::loadPixmap("mailit/attach"), QString::null, 0, this, 0); 67 attachButton = new QAction(tr("Attachment"), Resource::loadPixmap("mailit/attach"), QString::null, 0, this, 0);
69 attachButton->addTo(bar); 68 attachButton->addTo(bar);
70 attachButton->addTo(addMenu); 69 attachButton->addTo(addMenu);
71 connect( attachButton, SIGNAL( activated() ), this, SLOT( attachFile() ) ); 70 connect( attachButton, SIGNAL( activated() ), this, SLOT( attachFile() ) );
72 attachButton->setWhatsThis(tr("Click here to attach files to your mail")); 71 attachButton->setWhatsThis(tr("Click here to attach files to your mail"));
73 72
74 confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0); 73 confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0);
75 confirmButton->addTo(bar); 74 confirmButton->addTo(bar);
76 confirmButton->addTo(mailMenu); 75 confirmButton->addTo(mailMenu);
77 connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) ); 76 connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) );
78 confirmButton->setWhatsThis(tr("This button puts your mail in the send queue")); 77 confirmButton->setWhatsThis(tr("This button puts your mail in the send queue"));
79 78
80 newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0); 79 newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0);
81 newButton->addTo(mailMenu); 80 newButton->addTo(mailMenu);
82 connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) ); 81 connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) );
83 newButton->setWhatsThis(tr("Click here to create a new mail")); 82 newButton->setWhatsThis(tr("Click here to create a new mail"));
84 83
85 widget = new QWidget(this, "widget"); 84 widget = new QWidget(this, "widget");
86 grid = new QGridLayout( widget ); 85 grid = new QGridLayout( widget );
87 86
88 recipientsBox = new QComboBox( FALSE, widget, "toLabel" ); 87 recipientsBox = new QComboBox( FALSE, widget, "toLabel" );
89 recipientsBox->insertItem( tr( "To:" ) ); 88 recipientsBox->insertItem( tr( "To:" ) );
90 recipientsBox->insertItem( tr( "CC:" ) ); 89 recipientsBox->insertItem( tr( "CC:" ) );
91 recipientsBox->setCurrentItem(0); 90 recipientsBox->setCurrentItem(0);
92 grid->addWidget( recipientsBox, 0, 0 ); 91 grid->addWidget( recipientsBox, 0, 0 );
93 connect(recipientsBox,SIGNAL(activated(int)),this, SLOT(changeRecipients(int))); 92 connect(recipientsBox,SIGNAL(activated(int)),this, SLOT(changeRecipients(int)));
94 93
95 subjetLabel = new QLabel( widget, "subjetLabel" ); 94 subjetLabel = new QLabel( widget, "subjetLabel" );
96 subjetLabel->setText( tr( "Subject:" ) ); 95 subjetLabel->setText( tr( "Subject:" ) );
97 96
98 grid->addWidget( subjetLabel, 1, 0 ); 97 grid->addWidget( subjetLabel, 1, 0 );
99 98
100 ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" ); 99 ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" );
101 ToolButton13_2->setText( tr( "..." ) ); 100 ToolButton13_2->setText( tr( "..." ) );
102 grid->addWidget( ToolButton13_2, 1, 2 ); 101 grid->addWidget( ToolButton13_2, 1, 2 );
103 102
104 subjectInput = new QLineEdit( widget, "subjectInput" ); 103 subjectInput = new QLineEdit( widget, "subjectInput" );
105 grid->addWidget( subjectInput, 1, 1 ); 104 grid->addWidget( subjectInput, 1, 1 );
106 QWhatsThis::add(subjectInput,QWidget::tr("The mail subject should be entered here")); 105 QWhatsThis::add(subjectInput,QWidget::tr("The mail subject should be entered here"));
107 106
108 toInput = new QLineEdit( widget, "toInput" ); 107 toInput = new QLineEdit( widget, "toInput" );
109 grid->addWidget( toInput, 0, 1 ); 108 grid->addWidget( toInput, 0, 1 );
110 QWhatsThis::add(recipientsBox,QWidget::tr("Recipients can be entered here")); 109 QWhatsThis::add(recipientsBox,QWidget::tr("Recipients can be entered here"));
111 110
112 ccInput = new QLineEdit( widget, "ccInput" ); 111 ccInput = new QLineEdit( widget, "ccInput" );
113 ccInput->hide(); 112 ccInput->hide();
114 grid->addWidget( ccInput, 0, 1 ); 113 grid->addWidget( ccInput, 0, 1 );
115 QWhatsThis::add(ccInput,QWidget::tr("If you would like to send copies of your mail they can be entered here")); 114 QWhatsThis::add(ccInput,QWidget::tr("If you would like to send copies of your mail they can be entered here"));
116 115
117 addressButton = new QToolButton( widget, "addressButton" ); 116 addressButton = new QToolButton( widget, "addressButton" );
118 addressButton->setPixmap( Resource::loadPixmap("AddressBook") ); 117 addressButton->setPixmap( Resource::loadPixmap("AddressBook") );
119 addressButton->setToggleButton(TRUE); 118 addressButton->setToggleButton(TRUE);
120 grid->addWidget( addressButton, 0, 2 ); 119 grid->addWidget( addressButton, 0, 2 );
121 connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) ); 120 connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) );
122 QWhatsThis::add(addressButton,QWidget::tr("This button opens the address selector with all mail adresses from your OPIE addressbook")); 121 QWhatsThis::add(addressButton,QWidget::tr("This button opens the address selector with all mail adresses from your OPIE addressbook"));
123 122
124 emailInput = new QMultiLineEdit( widget, "emailInput" ); 123 emailInput = new QMultiLineEdit( widget, "emailInput" );
125 grid->addMultiCellWidget( emailInput, 2, 2, 0, 2); 124 grid->addMultiCellWidget( emailInput, 2, 2, 0, 2);
126 QWhatsThis::add(emailInput,QWidget::tr("Enter your mail text here")); 125 QWhatsThis::add(emailInput,QWidget::tr("Enter your mail text here"));
127 126
128 addressView = new QListView( widget, "addressView"); 127 addressView = new QListView( widget, "addressView");
129 addressView->addColumn("Name"); 128 addressView->addColumn("Name");
130 addressView->addColumn("EMail"); 129 addressView->addColumn("EMail");
131 addressView->setAllColumnsShowFocus(TRUE); 130 addressView->setAllColumnsShowFocus(TRUE);
132 addressView->setMultiSelection(TRUE); 131 addressView->setMultiSelection(TRUE);
133 addressView->hide(); 132 addressView->hide();
134 grid->addMultiCellWidget( addressView, 3, 3, 0, 2); 133 grid->addMultiCellWidget( addressView, 3, 3, 0, 2);
135 QWhatsThis::add(recipientsBox,QWidget::tr("Choose the recipients from this list")); 134 QWhatsThis::add(recipientsBox,QWidget::tr("Choose the recipients from this list"));
136 135
137 okButton = new QToolButton(bar, "ok"); 136 okButton = new QToolButton(bar, "ok");
138 okButton->setPixmap( Resource::loadPixmap("enter") ); 137 okButton->setPixmap( Resource::loadPixmap("enter") );
139 okButton->hide(); 138 okButton->hide();
140 connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) ); 139 connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) );
141 QWhatsThis::add(okButton,QWidget::tr("Queue your mail by clicking here")); 140 QWhatsThis::add(okButton,QWidget::tr("Queue your mail by clicking here"));
142 141
143 setCentralWidget(widget); 142 setCentralWidget(widget);
144} 143}
145 144
146void WriteMail::reject() 145void WriteMail::reject()
147{ 146{
148 emit cancelMail(); 147 emit cancelMail();
149} 148}
150 149
151void WriteMail::accept() 150void WriteMail::accept()
152{ 151{
153 QStringList attachedFiles, attachmentsType; 152 QStringList attachedFiles, attachmentsType;
154 int idCount = 0; 153 int idCount = 0;
155 154
156 if (toInput->text() == "") 155 if (toInput->text() == "")
157 { 156 {
158 QMessageBox::warning(this,tr("No recipient"), tr("Send mail to whom?"), tr("OK\n")); 157 QMessageBox::warning(this,tr("No recipient"), tr("Send mail to whom?"), tr("OK\n"));
159 return; 158 return;
160 } 159 }
161 160
162 if (! getRecipients(false) ) 161 if (! getRecipients(false) )
163 { 162 {
164 QMessageBox::warning(this,tr("Incorrect recipient separator"), 163 QMessageBox::warning(this,tr("Incorrect recipient separator"),
165 tr("Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n")); 164 tr("Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n"));
166 return; 165 return;
167 } 166 }
168 167
169 if ((ccInput->text()!="") && (! getRecipients(true) )) 168 if ((ccInput->text()!="") && (! getRecipients(true) ))
170 { 169 {
171 QMessageBox::warning(this,tr("Incorrect carbon copy separator"), 170 QMessageBox::warning(this,tr("Incorrect carbon copy separator"),
172 tr("CC Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n")); 171 tr("CC Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n"));
173 return; 172 return;
174 } 173 }
175 174
176 mail.subject = subjectInput->text(); 175 mail.subject = subjectInput->text();
177 mail.body = emailInput->text(); 176 mail.body = emailInput->text();
178 mail.sent = false; 177 mail.sent = false;
179 mail.received = false; 178 mail.received = false;
180 179
181 mail.rawMail = "To: "; 180 mail.rawMail = "To: ";
182 181
183 for (QStringList::Iterator it = mail.recipients.begin(); 182 for (QStringList::Iterator it = mail.recipients.begin();
184 it != mail.recipients.end(); ++it) { 183 it != mail.recipients.end(); ++it) {
185 184
186 mail.rawMail += (*it); 185 mail.rawMail += (*it);
187 mail.rawMail += ",\n"; 186 mail.rawMail += ",\n";
188 } 187 }
189 188
190 mail.rawMail.truncate(mail.rawMail.length()-2); 189 mail.rawMail.truncate(mail.rawMail.length()-2);
191 190
192 mail.rawMail += "\nCC: "; 191 mail.rawMail += "\nCC: ";
193 192
194 for (QStringList::Iterator it = mail.carbonCopies.begin(); 193 for (QStringList::Iterator it = mail.carbonCopies.begin();
195 it != mail.carbonCopies.end(); ++it) { 194 it != mail.carbonCopies.end(); ++it) {
196 195
197 mail.rawMail += (*it); 196 mail.rawMail += (*it);
198 mail.rawMail += ",\n"; 197 mail.rawMail += ",\n";
199 } 198 }
200 199
201 mail.rawMail += mail.from; 200 mail.rawMail += mail.from;
202 mail.rawMail += "\nSubject: "; 201 mail.rawMail += "\nSubject: ";
203 mail.rawMail += mail.subject; 202 mail.rawMail += mail.subject;
204 mail.rawMail += "\n\n"; 203 mail.rawMail += "\n\n";
205 204
206 attachedFiles = addAtt->returnattachedFiles(); 205 attachedFiles = addAtt->returnattachedFiles();
207 attachmentsType = addAtt->returnFileTypes(); 206 attachmentsType = addAtt->returnFileTypes();
208 207
209 QStringList::Iterator itType = attachmentsType.begin(); 208 QStringList::Iterator itType = attachmentsType.begin();
210 209
211 Enclosure e; 210 Enclosure e;
212 for ( QStringList::Iterator it = attachedFiles.begin(); it != attachedFiles.end(); ++it ) { 211 for ( QStringList::Iterator it = attachedFiles.begin(); it != attachedFiles.end(); ++it ) {
213 e.id = idCount; 212 e.id = idCount;
214 e.originalName = (*it).latin1(); 213 e.originalName = (*it).latin1();
215 e.contentType = (*itType).latin1(); 214 e.contentType = (*itType).latin1();
216 e.contentAttribute = (*itType).latin1(); 215 e.contentAttribute = (*itType).latin1();
217 e.saved = TRUE; 216 e.saved = TRUE;
218 mail.addEnclosure(&e); 217 mail.addEnclosure(&e);
219 218
220 itType++; 219 itType++;
221 idCount++; 220 idCount++;
222 } 221 }
223 mail.rawMail += mail.body; 222 mail.rawMail += mail.body;
224 mail.rawMail += "\n"; 223 mail.rawMail += "\n";
225 mail.rawMail += ".\n"; 224 mail.rawMail += ".\n";
226 emit sendMailRequested(mail); 225 emit sendMailRequested(mail);
227 addAtt->clear(); 226 addAtt->clear();
228} 227}
229 228
230void WriteMail::getAddress() 229void WriteMail::getAddress()
231{ 230{
232 showingAddressList = !showingAddressList; 231 showingAddressList = !showingAddressList;
233 232
234 if (showingAddressList) { 233 if (showingAddressList) {
235 emailInput->hide(); 234 emailInput->hide();
236 addressView->show(); 235 addressView->show();
237 okButton->show(); 236 okButton->show();
238 237
239 } else { 238 } else {
240 addressView->hide(); 239 addressView->hide();
241 okButton->hide(); 240 okButton->hide();
242 emailInput->show(); 241 emailInput->show();
243 } 242 }
244} 243}
245 244
246void WriteMail::attachFile() 245void WriteMail::attachFile()
247{ 246{
248 addAtt->showMaximized(); 247 addAtt->showMaximized();
249} 248}
250 249
251void WriteMail::reply(Email replyMail, bool replyAll) 250void WriteMail::reply(Email replyMail, bool replyAll)
252{ 251{
253 int pos; 252 int pos;
254 QString ccRecipients; 253 QString ccRecipients;
255 254
256 mail = replyMail; 255 mail = replyMail;
257 mail.files.clear(); 256 mail.files.clear();
258 257
259 toInput->setText(mail.fromMail); 258 toInput->setText(mail.fromMail);
260 259
261 if (replyAll) 260 if (replyAll)
262 { 261 {
263 for (QStringList::Iterator it = mail.carbonCopies.begin();it != mail.carbonCopies.end(); ++it) 262 for (QStringList::Iterator it = mail.carbonCopies.begin();it != mail.carbonCopies.end(); ++it)
264 { 263 {
265 ccRecipients.append(*it); 264 ccRecipients.append(*it);
266 ccRecipients.append(";"); 265 ccRecipients.append(";");
267 } 266 }
268 ccRecipients.truncate(ccRecipients.length()-1); //no ; at the end 267 ccRecipients.truncate(ccRecipients.length()-1); //no ; at the end
269 ccInput->setText(ccRecipients); 268 ccInput->setText(ccRecipients);
270 } 269 }
271 270 else ccInput->clear();
272 addRecipients(replyAll);
273 271
274 subjectInput->setText(tr("Re: ") + mail.subject); 272 subjectInput->setText(tr("Re: ") + mail.subject);
275 273
274 QString citation=mail.fromMail;
275 citation.append(tr(" wrote on "));
276 citation.append(mail.date);
277 citation.append(":\n");
278
279
280 //mail.body.insert(0,tr("On"));
276 pos = 0; 281 pos = 0;
277 mail.body.insert(pos, ">"); 282 mail.body.insert(pos, ">");
278 while (pos != -1) { 283 while (pos != -1) {
279 pos = mail.body.find('\n', pos); 284 pos = mail.body.find('\n', pos);
280 if (pos != -1) 285 if (pos != -1)
281 mail.body.insert(++pos, ">>"); 286 mail.body.insert(++pos, ">>");
282 } 287 }
283 288 mail.body.insert(0,citation);
284 emailInput->setText(mail.body); 289 emailInput->setText(mail.body);
285} 290}
286 291
287void WriteMail::forward(Email forwMail) 292void WriteMail::forward(Email forwMail)
288{ 293{
289 int pos=0; 294 int pos=0;
290 295
291 QString fwdBody=tr("======forwarded message from "); 296 QString fwdBody=tr("======forwarded message from ");
292 fwdBody.append(forwMail.fromMail); 297 fwdBody.append(forwMail.fromMail);
293 fwdBody.append(tr(" starts======\n\n")); 298 fwdBody.append(tr(" starts======\n\n"));
294 299
295 mail=forwMail; 300 mail=forwMail;
296 toInput->setText(""); 301 toInput->setText("");
297 ccInput->setText(""); 302 ccInput->setText("");
298 subjectInput->setText(tr("FWD: ") + mail.subject); 303 subjectInput->setText(tr("FWD: ") + mail.subject);
299 304
300 fwdBody+=mail.body; 305 fwdBody+=mail.body;
301 fwdBody+=QString(tr("======end of forwarded message======\n\n")); 306 fwdBody+=QString(tr("======end of forwarded message======\n\n"));
302 307
303 emailInput->setText(fwdBody); 308 emailInput->setText(fwdBody);
304} 309}
305 310
306bool WriteMail::getRecipients(bool ccField) 311bool WriteMail::getRecipients(bool ccField)
307{ 312{
308 QString str, temp; 313 QString str, temp;
309 int pos = 0; 314 int pos = 0;
310 315
311 mail.recipients.clear(); 316 if (ccField)
312 317 {
313 ccField ? temp = ccInput->text() : temp=toInput->text() ; 318 mail.carbonCopies.clear();
319 temp = ccInput->text();
320 }
321 else
322 {
323 mail.recipients.clear();
324 temp=toInput->text() ;
325 }
314 326
315 while ( (pos = temp.find(';')) != -1) { 327 while ( (pos = temp.find(';')) != -1) {
316 str = temp.left(pos).stripWhiteSpace(); 328 str = temp.left(pos).stripWhiteSpace();
317 temp = temp.right(temp.length() - (pos + 1)); 329 temp = temp.right(temp.length() - (pos + 1));
318 if ( str.find('@') == -1) 330 if ( str.find('@') == -1)
319 return false; 331 return false;
320 ccField ? mail.carbonCopies.append(str) : mail.recipients.append(str); 332 ccField ? mail.carbonCopies.append(str) : mail.recipients.append(str);
321 addressList->addContact(str, ""); 333 //addressList->addContact(str, "");
322 } 334 }
323 temp = temp.stripWhiteSpace(); 335 temp = temp.stripWhiteSpace();
324 if ( temp.find('@') == -1) 336 if ( temp.find('@') == -1)
325 return false; 337 return false;
326 ccField ? mail.carbonCopies.append(temp) : mail.recipients.append(temp); 338 ccField ? mail.carbonCopies.append(temp) : mail.recipients.append(temp);
327 addressList->addContact(temp, ""); 339 //addressList->addContact(temp, "");
328 340
329 return TRUE; 341 return TRUE;
330} 342}
331 343
332void WriteMail::addRecipients() 344void WriteMail::addRecipients()
333{ 345{
334 toInput->isVisible() ? addRecipients(false) : addRecipients(true); 346 toInput->isVisible() ? addRecipients(false) : addRecipients(true);
335 } 347 }
336 348
337void WriteMail::addRecipients(bool ccField) 349void WriteMail::addRecipients(bool ccField)
338{ 350{
339 QString recipients = ""; 351 QString recipients = "";
340 352
341 mail.recipients.clear(); 353 mail.recipients.clear();
342 354
343 QListViewItem *item = addressView->firstChild(); 355 QListViewItem *item = addressView->firstChild();
344 while (item != NULL) { 356 while (item != NULL) {
345 if ( item->isSelected() ) { 357 if ( item->isSelected() ) {
346 if (recipients == "") { 358 if (recipients == "") {
347 recipients = item->text(1); 359 recipients = item->text(1);
348 } else { 360 } else {
349 recipients += "; " + item->text(1); 361 recipients += "; " + item->text(1);
350 } 362 }
351 } 363 }
352 item = item->nextSibling(); 364 item = item->nextSibling();
353 } 365 }
354 366
355 ccField ? ccInput->setText(recipients):toInput->setText(recipients); 367 ccField ? ccInput->setText(recipients):toInput->setText(recipients);
356 368
357 addressView->hide(); 369 addressView->hide();
358 okButton->hide(); 370 okButton->hide();
359 emailInput->show(); 371 emailInput->show();
360 addressButton->setOn(FALSE); 372 addressButton->setOn(FALSE);
361 showingAddressList = !showingAddressList; 373 showingAddressList = !showingAddressList;
362} 374}
363 375
364void WriteMail::changeRecipients(int selection) 376void WriteMail::changeRecipients(int selection)
365{ 377{
366 if (selection==0) 378 if (selection==0)
367 { 379 {
368 toInput->show(); 380 toInput->show();
369 ccInput->hide(); 381 ccInput->hide();
370 } 382 }
371 else if (selection==1) 383 else if (selection==1)
372 { 384 {
373 toInput->hide(); 385 toInput->hide();
374 ccInput->show(); 386 ccInput->show();
375 } 387 }
376} 388}
377 389
378void WriteMail::setRecipient(const QString &recipient) 390void WriteMail::setRecipient(const QString &recipient)
379{ 391{
380 toInput->setText(recipient); 392 toInput->setText(recipient);
381} 393}
382 394
383void WriteMail::newMail() 395void WriteMail::newMail()
384{ 396{
385 toInput->clear(); 397 toInput->clear();
398 ccInput->clear();
386 subjectInput->clear(); 399 subjectInput->clear();
387 emailInput->clear(); 400 emailInput->clear();
388 setAddressList(addressList); 401 setAddressList(addressList);
389} 402}
diff --git a/noncore/unsupported/mailit/emailclient.cpp b/noncore/unsupported/mailit/emailclient.cpp
index dff1888..2cedc51 100644
--- a/noncore/unsupported/mailit/emailclient.cpp
+++ b/noncore/unsupported/mailit/emailclient.cpp
@@ -1,552 +1,573 @@
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 <qfile.h> 23#include <qfile.h>
23#include <qcheckbox.h> 24#include <qcheckbox.h>
24#include <qmenubar.h> 25#include <qmenubar.h>
25#include <qaction.h> 26#include <qaction.h>
26#include <qwhatsthis.h> 27#include <qwhatsthis.h>
27#include <qpe/resource.h> 28#include <qpe/resource.h>
28#include "emailclient.h" 29#include "emailclient.h"
30#include "writemail.h"
29 31
30QCollection::Item AccountList::newItem(QCollection::Item d) 32QCollection::Item AccountList::newItem(QCollection::Item d)
31{ 33{
32 return dupl( (MailAccount *) d); 34 return dupl( (MailAccount *) d);
33} 35}
34 36
35MailAccount* AccountList::dupl(MailAccount *in) 37MailAccount* AccountList::dupl(MailAccount *in)
36{ 38{
37 ac = new MailAccount(*in); 39 ac = new MailAccount(*in);
38 return ac; 40 return ac;
39} 41}
40 42
41EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl ) 43EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl )
42 : QMainWindow( parent, name, fl ) 44 : QMainWindow( parent, name, fl )
43{ 45{
44 emailHandler = new EmailHandler(); 46 emailHandler = new EmailHandler();
45 addressList = new AddressList(); 47 addressList = new AddressList();
46 48
47 sending = FALSE; 49 sending = FALSE;
48 receiving = FALSE; 50 receiving = FALSE;
49 previewingMail = FALSE; 51 previewingMail = FALSE;
50 mailIdCount = 1; 52 mailIdCount = 1;
51 accountIdCount = 1; 53 accountIdCount = 1;
52 allAccounts = FALSE; 54 allAccounts = FALSE;
53 55
54 init(); 56 init();
55 57
58
59
56 connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) ); 60 connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) );
57 61
58 connect(emailHandler, SIGNAL(smtpError(int)), this, 62 connect(emailHandler, SIGNAL(smtpError(int)), this,
59 SLOT(smtpError(int)) ); 63 SLOT(smtpError(int)) );
60 connect(emailHandler, SIGNAL(popError(int)), this, 64 connect(emailHandler, SIGNAL(popError(int)), this,
61 SLOT(popError(int)) ); 65 SLOT(popError(int)) );
62 66
63 connect(inboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(inboxItemSelected()) ); 67 connect(inboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(inboxItemSelected()) );
64 connect(outboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(outboxItemSelected()) ); 68 connect(outboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(outboxItemSelected()) );
65 69
66 connect(inboxView, SIGNAL(pressed(QListViewItem *)), this, SLOT(inboxItemPressed()) ); 70 connect(inboxView, SIGNAL(pressed(QListViewItem *)), this, SLOT(inboxItemPressed()) );
67 connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemReleased()) ); 71 connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemReleased()) );
68 72
69
70 connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this, 73 connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this,
71 SLOT(mailArrived(const Email &, bool)) ); 74 SLOT(mailArrived(const Email &, bool)) );
72 connect(emailHandler, SIGNAL(mailTransfered(int)), this, 75 connect(emailHandler, SIGNAL(mailTransfered(int)), this,
73 SLOT(allMailArrived(int)) ); 76 SLOT(allMailArrived(int)) );
74 77
75 mailconf = new Config("mailit"); 78 mailconf = new Config("mailit");
76 //In case Synchronize is not defined in settings.txt 79 //In case Synchronize is not defined in settings.txt
77 80
78 readSettings(); 81 readSettings();
79 82
80 updateAccounts(); 83 updateAccounts();
81 84
82 lineShift = "\n"; 85 lineShift = "\n";
83 readMail(); 86 readMail();
84 lineShift = "\r\n"; 87 lineShift = "\r\n";
85 88
86 mailboxView->setCurrentTab(0); //ensure that inbox has focus 89 mailboxView->setCurrentTab(0); //ensure that inbox has focus
90
91 /*channel = new QCopChannel( "QPE/Application/mailit", this );
92 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
93 this, SLOT(receive(const QCString&, const QByteArray&)) );*/
94
87} 95}
88 96
89 97
90EmailClient::~EmailClient() 98EmailClient::~EmailClient()
91{ 99{
92 //needs to be moved from destructor to closewindow event 100 //needs to be moved from destructor to closewindow event
93 saveMail(getPath(FALSE) + "inbox.txt", inboxView); 101 saveMail(getPath(FALSE) + "inbox.txt", inboxView);
94 //does not currently work. Defining outbox in the same 102 //does not currently work. Defining outbox in the same
95 //format as inbox is not a good solution as they have 103 //format as inbox is not a good solution as they have
96 //different properties 104 //different properties
97 saveMail(getPath(FALSE) + "outbox.txt", outboxView); 105 saveMail(getPath(FALSE) + "outbox.txt", outboxView);
98 saveSettings(); 106 saveSettings();
99 107
100 mailconf->write(); 108 mailconf->write();
101 delete mailconf; 109 delete mailconf;
102 110
103} 111}
104 112
105void EmailClient::init() 113void EmailClient::init()
106{ 114{
107 statusBar = new QStatusBar(this); 115 initStatusBar(this);
108 statusBar->setSizeGripEnabled(FALSE); 116
109
110 status1Label = new QLabel( tr("Idle"), statusBar);
111 status2Label = new QLabel("", statusBar);
112 connect(emailHandler, SIGNAL(updatePopStatus(const QString &)),
113 status2Label, SLOT(setText(const QString &)) );
114 connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)),
115 status2Label, SLOT(setText(const QString &)) );
116
117 progressBar = new QProgressBar(statusBar);
118
119 connect(emailHandler, SIGNAL(mailboxSize(int)),
120 this, SLOT(setTotalSize(int)) );
121 connect(emailHandler, SIGNAL(currentMailSize(int)),
122 this, SLOT(setMailSize(int)) );
123 connect(emailHandler, SIGNAL(downloadedSize(int)),
124 this, SLOT(setDownloadedSize(int)) );
125
126 statusBar->addWidget(status1Label);
127 statusBar->addWidget(progressBar);
128 statusBar->addWidget(status2Label);
129
130 setToolBarsMovable(FALSE); 117 setToolBarsMovable(FALSE);
131 118
132 bar = new QToolBar(this); 119 bar = new QToolBar(this);
133 QWhatsThis::add(bar,tr("Main operation toolbar")); 120 QWhatsThis::add(bar,tr("Main operation toolbar"));
134 bar->setHorizontalStretchable( TRUE ); 121 bar->setHorizontalStretchable( TRUE );
135 122
136 mb = new QMenuBar( bar ); 123 mb = new QMenuBar( bar );
137 124
138 QPopupMenu *mail = new QPopupMenu(mb); 125 QPopupMenu *mail = new QPopupMenu(mb);
139 mb->insertItem( tr( "&Mail" ), mail); 126 mb->insertItem( tr( "&Mail" ), mail);
140 127
141 QPopupMenu *configure = new QPopupMenu(mb); 128 QPopupMenu *configure = new QPopupMenu(mb);
142 mb->insertItem( tr( "Accounts" ), configure); 129 mb->insertItem( tr( "Accounts" ), configure);
143 130
144 selectAccountMenu = new QPopupMenu(mb); 131 selectAccountMenu = new QPopupMenu(mb);
145 editAccountMenu = new QPopupMenu(mb); 132 editAccountMenu = new QPopupMenu(mb);
146 deleteAccountMenu = new QPopupMenu(mb); 133 deleteAccountMenu = new QPopupMenu(mb);
147 134
148 mail->insertItem(tr("Get Mail in"), selectAccountMenu); 135 mail->insertItem(tr("Get Mail in"), selectAccountMenu);
149 configure->insertItem(tr("Edit account"), editAccountMenu); 136 configure->insertItem(tr("Edit account"), editAccountMenu);
150 configure->insertItem(tr("Delete account"), deleteAccountMenu); 137 configure->insertItem(tr("Delete account"), deleteAccountMenu);
151 138
152 bar = new QToolBar(this); 139 bar = new QToolBar(this);
153 140
154 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);
155 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."));
156 143
157 getMailButton->setPopup(selectAccountMenu); 144 getMailButton->setPopup(selectAccountMenu);
158 145
159 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);
160 connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) ); 147 connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) );
161 sendMailButton->addTo(bar); 148 sendMailButton->addTo(bar);
162 sendMailButton->addTo(mail); 149 sendMailButton->addTo(mail);
163 sendMailButton->setWhatsThis("Send mail queued in the outbox"); 150 sendMailButton->setWhatsThis("Send mail queued in the outbox");
164 151
165 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);
166 connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) ); 153 connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) );
167 composeButton->addTo(bar); 154 composeButton->addTo(bar);
168 composeButton->addTo(mail); 155 composeButton->addTo(mail);
169 composeButton->setWhatsThis("Compose a new mail"); 156 composeButton->setWhatsThis("Compose a new mail");
170 157
171 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);
172 connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) ); 159 connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) );
173 cancelButton->addTo(mail); 160 cancelButton->addTo(mail);
174 cancelButton->addTo(bar); 161 cancelButton->addTo(bar);
175 cancelButton->setEnabled(FALSE); 162 cancelButton->setEnabled(FALSE);
176 cancelButton->setWhatsThis("Stop the currently active mail transfer"); 163 cancelButton->setWhatsThis("Stop the currently active mail transfer");
177 164
178 165
179 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 );
180 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); 167 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) );
181 deleteButton->addTo(bar); 168 deleteButton->addTo(bar);
182 deleteButton->setWhatsThis("Remove the currently selected eMail(s)"); 169 deleteButton->setWhatsThis("Remove the currently selected eMail(s)");
183 170
184 mailboxView = new OTabWidget( this, "mailboxView" ); 171 mailboxView = new OTabWidget( this, "mailboxView" );
185 172
186 QWidget* widget = new QWidget( mailboxView, "widget" ); 173 QWidget* widget = new QWidget( mailboxView, "widget" );
187 grid_2 = new QGridLayout( widget ); 174 grid_2 = new QGridLayout( widget );
188// grid_2->setSpacing(6); 175// grid_2->setSpacing(6);
189// grid_2->setMargin( 11 ); 176// grid_2->setMargin( 11 );
190 177
191 inboxView = new QListView( widget, "inboxView" ); 178 inboxView = new QListView( widget, "inboxView" );
192 inboxView->addColumn( tr( "From" ) ); 179 inboxView->addColumn( tr( "From" ) );
193 inboxView->addColumn( tr( "Subject" ) ); 180 inboxView->addColumn( tr( "Subject" ) );
194 inboxView->addColumn( tr( "Date" ) ); 181 inboxView->addColumn( tr( "Date" ) );
195 inboxView->setMinimumSize( QSize( 0, 0 ) ); 182 inboxView->setMinimumSize( QSize( 0, 0 ) );
196 inboxView->setAllColumnsShowFocus(TRUE); 183 inboxView->setAllColumnsShowFocus(TRUE);
197 QWhatsThis::add(inboxView,QWidget::tr("This is the inbox view.\n It keeps the fetched mail which can be viewed by double clicking the entry.\n" 184 QWhatsThis::add(inboxView,QWidget::tr("This is the inbox view.\n"
198 " A blue attachment icon shows whether this mail has attachments.")); 185 "It keeps the fetched mail which can be \n"
186 "viewed by double clicking the entry.\n"
187 "blue attachment icon shows whether this \n"
188 "mailhas attachments.\n"));
199 189
200 grid_2->addWidget( inboxView, 2, 0 ); 190 grid_2->addWidget( inboxView, 2, 0 );
201 mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) ); 191 mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) );
202 192
203 QWidget* widget_2 = new QWidget( mailboxView, "widget_2" ); 193 QWidget* widget_2 = new QWidget( mailboxView, "widget_2" );
204 grid_3 = new QGridLayout( widget_2 ); 194 grid_3 = new QGridLayout( widget_2 );
205// grid_3->setSpacing(6); 195// grid_3->setSpacing(6);
206// grid_3->setMargin( 11 ); 196// grid_3->setMargin( 11 );
207 197
208 outboxView = new QListView( widget_2, "outboxView" ); 198 outboxView = new QListView( widget_2, "outboxView" );
209 outboxView->addColumn( tr( "To" ) ); 199 outboxView->addColumn( tr( "To" ) );
210 outboxView->addColumn( tr( "Subject" ) ); 200 outboxView->addColumn( tr( "Subject" ) );
211 outboxView->setAllColumnsShowFocus(TRUE); 201 outboxView->setAllColumnsShowFocus(TRUE);
212 202
213 QWhatsThis::add(outboxView,QWidget::tr("This is the oubox view.\n It keeps the queued mails to send which can be reviewed by double clicking the entry.")); 203 QWhatsThis::add(outboxView,QWidget::tr("This is the outbox view.\n"
204 "It keeps the queued mails to send which can be \n"
205 "reviewed by double clicking the entry."));
214 grid_3->addWidget( outboxView, 0, 0 ); 206 grid_3->addWidget( outboxView, 0, 0 );
215 mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) ); 207 mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) );
216 208
217 setCentralWidget(mailboxView); 209 setCentralWidget(mailboxView);
218 210
219} 211}
220 212
213void EmailClient::initStatusBar(QWidget* parent)
214{
215 statusBar = new QStatusBar(parent);
216 statusBar->setSizeGripEnabled(FALSE);
217
218 status1Label = new QLabel( tr("Idle"), statusBar);
219 status2Label = new QLabel("", statusBar);
220 connect(emailHandler, SIGNAL(updatePopStatus(const QString &)),
221 status2Label, SLOT(setText(const QString &)) );
222 connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)),
223 status2Label, SLOT(setText(const QString &)) );
224
225 progressBar = new QProgressBar(statusBar);
226
227 connect(emailHandler, SIGNAL(mailboxSize(int)),
228 this, SLOT(setTotalSize(int)) );
229 connect(emailHandler, SIGNAL(currentMailSize(int)),
230 this, SLOT(setMailSize(int)) );
231 connect(emailHandler, SIGNAL(downloadedSize(int)),
232 this, SLOT(setDownloadedSize(int)) );
233
234 statusBar->addWidget(status1Label);
235 statusBar->addWidget(progressBar);
236 statusBar->addWidget(status2Label);
237
238}
239
221void EmailClient::compose() 240void EmailClient::compose()
222{ 241{
223 emit composeRequested(); 242 emit composeRequested();
224} 243}
225 244
226void EmailClient::cancel() 245void EmailClient::cancel()
227{ 246{
228 emailHandler->cancel(); 247 emailHandler->cancel();
229} 248}
230 249
231AddressList* EmailClient::getAdrListRef() 250AddressList* EmailClient::getAdrListRef()
232{ 251{
233 return addressList; 252 return addressList;
234} 253}
235 254
236//this needs to be rewritten to syncronize with outboxView 255//this needs to be rewritten to syncronize with outboxView
237void EmailClient::enqueMail(const Email &mail) 256void EmailClient::enqueMail(const Email &mail)
238{ 257{
239 if (accountList.count() == 0) { 258 if (accountList.count() == 0) {
240 QMessageBox::warning(qApp->activeWindow(), 259 QMessageBox::warning(qApp->activeWindow(),
241 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");
242 return; 261 return;
243 } 262 }
244 263
245 if (accountList.count() > 0) { 264 if (accountList.count() > 0) {
246 currentAccount = accountList.first(); 265 currentAccount = accountList.first();
247 qWarning("using account " + currentAccount->name); 266 qWarning("using account " + currentAccount->name);
248 } 267 }
249 268
250 Email addMail = mail; 269 Email addMail = mail;
251 addMail.from = currentAccount->name; 270 addMail.from = currentAccount->name;
252 addMail.fromMail = currentAccount->emailAddress; 271 addMail.fromMail = currentAccount->emailAddress;
253 addMail.rawMail.prepend("From: " + addMail.from + "<" + addMail.fromMail + ">\n"); 272 addMail.rawMail.prepend("From: " + addMail.from + "<" + addMail.fromMail + ">\n");
254 item = new EmailListItem(outboxView, addMail, false); 273 item = new EmailListItem(outboxView, addMail, false);
255 274
256 mailboxView->setCurrentTab(1); 275 mailboxView->setCurrentTab(1);
257 276
258} 277}
259 278
260void EmailClient::sendQuedMail() 279void EmailClient::sendQuedMail()
261{ 280{
262 int count = 0; 281 int count = 0;
263 282
264 if (accountList.count() == 0) { 283 if (accountList.count() == 0) {
265 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");
266 return; 285 return;
267 } 286 }
268 //traverse listview, find messages to send 287 //traverse listview, find messages to send
269 if (! sending) { 288 if (! sending) {
270 item = (EmailListItem *) outboxView->firstChild(); 289 item = (EmailListItem *) outboxView->firstChild();
271 if (item != NULL) { 290 if (item != NULL) {
272 while (item != NULL) { 291 while (item != NULL) {
273 quedMessages.append(item->getMail()); 292 quedMessages.append(item->getMail());
274 item = (EmailListItem *) item->nextSibling(); 293 item = (EmailListItem *) item->nextSibling();
275 count++; 294 count++;
276 } 295 }
277 setMailAccount(); 296 setMailAccount();
278 emailHandler->sendMail(&quedMessages); 297 emailHandler->sendMail(&quedMessages);
279 sending = TRUE; 298 sending = TRUE;
280 sendMailButton->setEnabled(FALSE); 299 sendMailButton->setEnabled(FALSE);
281 cancelButton->setEnabled(TRUE); 300 cancelButton->setEnabled(TRUE);
282 } else { 301 } else {
283 qWarning("sendQuedMail(): no messages to send"); 302 qWarning("sendQuedMail(): no messages to send");
284 } 303 }
285 } 304 }
286} 305}
287 306
288void EmailClient::setMailAccount() 307void EmailClient::setMailAccount()
289{ 308{
290 emailHandler->setAccount(*currentAccount); 309 emailHandler->setAccount(*currentAccount);
291} 310}
292 311
293void EmailClient::mailSent() 312void EmailClient::mailSent()
294{ 313{
295 sending = FALSE; 314 sending = FALSE;
296 sendMailButton->setEnabled(TRUE); 315 sendMailButton->setEnabled(TRUE);
297 316
298 quedMessages.clear(); 317 quedMessages.clear();
299 outboxView->clear(); //should be moved to an sentBox 318 outboxView->clear(); //should be moved to an sentBox
300} 319}
301 320
302void EmailClient::getNewMail() { 321void EmailClient::getNewMail() {
303 322
304 if (accountList.count() == 0) { 323 if (accountList.count() == 0) {
305 QMessageBox::warning(qApp->activeWindow(),"No account selected", 324 QMessageBox::warning(qApp->activeWindow(),"No account selected",
306 "You must create an account", "OK\n"); 325 "You must create an account", "OK\n");
307 return; 326 return;
308 } 327 }
309 328
310 setMailAccount(); 329 setMailAccount();
311 330
312 receiving = TRUE; 331 receiving = TRUE;
313 previewingMail = TRUE; 332 previewingMail = TRUE;
314 getMailButton->setEnabled(FALSE); 333 getMailButton->setEnabled(FALSE);
315 cancelButton->setEnabled(TRUE); 334 cancelButton->setEnabled(TRUE);
316 selectAccountMenu->setEnabled(FALSE); 335 selectAccountMenu->setEnabled(FALSE);
317 336
318 status1Label->setText(currentAccount->accountName + " headers"); 337 status1Label->setText(currentAccount->accountName + " headers");
319 progressBar->reset(); 338 progressBar->reset();
320 339
321 //get any previous mails not downloaded and add to queue 340 //get any previous mails not downloaded and add to queue
322 mailDownloadList.clear(); 341 /*mailDownloadList.clear();
323 Email *mailPtr; 342 Email *mailPtr;
324 item = (EmailListItem *) inboxView->firstChild(); 343 item = (EmailListItem *) inboxView->firstChild();
325 while (item != NULL) { 344 while (item != NULL) {
326 mailPtr = item->getMail(); 345 mailPtr = item->getMail();
327 if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { 346 if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) {
328 mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); 347 mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size);
329 } 348 }
330 item = (EmailListItem *) item->nextSibling(); 349 item = (EmailListItem *) item->nextSibling();
331 } 350 }*/
332 351
333 emailHandler->getMailHeaders(); 352 emailHandler->getMailHeaders();
334 353
335} 354}
336 355
337void EmailClient::getAllNewMail() 356void EmailClient::getAllNewMail()
338{ 357{
339 allAccounts = TRUE; 358 allAccounts = TRUE;
340 currentAccount = accountList.first(); 359 currentAccount = accountList.first();
341 getNewMail(); 360 getNewMail();
342} 361}
343 362
344void EmailClient::mailArrived(const Email &mail, bool fromDisk) 363void EmailClient::mailArrived(const Email &mail, bool fromDisk)
345{ 364{
346 Enclosure *ePtr; 365 Enclosure *ePtr;
347 Email newMail; 366 Email newMail;
348 int thisMailId; 367 int thisMailId;
349 emailHandler->parse(mail.rawMail, lineShift, &newMail); 368 emailHandler->parse(mail.rawMail, lineShift, &newMail);
350 mailconf->setGroup(newMail.id); 369 mailconf->setGroup(newMail.id);
351 370
352 if (fromDisk) 371 if (fromDisk)
353 { 372 {
373
354 newMail.downloaded = mailconf->readBoolEntry("downloaded"); 374 newMail.downloaded = mailconf->readBoolEntry("downloaded");
355 newMail.size = mailconf->readNumEntry("size"); 375 newMail.size = mailconf->readNumEntry("size");
356 newMail.serverId = mailconf->readNumEntry("serverid"); 376 newMail.serverId = mailconf->readNumEntry("serverid");
357 newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); 377 newMail.fromAccountId = mailconf->readNumEntry("fromaccountid");
358 } 378 }
359 else 379 else
360 { //mail arrived from server 380 { //mail arrived from server
381
361 newMail.serverId = mail.serverId; 382 newMail.serverId = mail.serverId;
362 newMail.size = mail.size; 383 newMail.size = mail.size;
363 newMail.downloaded = mail.downloaded; 384 newMail.downloaded = mail.downloaded;
364 385
365 newMail.fromAccountId = emailHandler->getAccount()->id; 386 newMail.fromAccountId = emailHandler->getAccount()->id;
366 mailconf->writeEntry("fromaccountid", newMail.fromAccountId); 387 mailconf->writeEntry("fromaccountid", newMail.fromAccountId);
367 } 388 }
368 389
369 //add if read or not 390 //add if read or not
370 newMail.read = mailconf->readBoolEntry("mailread"); 391 newMail.read = mailconf->readBoolEntry("mailread");
371 392
372 //check if new mail 393 //check if new mail
373 if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { 394 if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) {
374 thisMailId = mailIdCount; 395 thisMailId = mailIdCount;
375 mailIdCount++; 396 mailIdCount++;
376 397
377 //set server count, so that if the user aborts, the new 398 //set server count, so that if the user aborts, the new
378 //header is not reloaded 399 //header is not reloaded
379 if ((currentAccount)&&(currentAccount->synchronize)) 400 if ((currentAccount)&&(currentAccount->synchronize))
380 currentAccount->lastServerMailCount++; 401 currentAccount->lastServerMailCount++;
381 402
382 mailconf->writeEntry("internalmailid", thisMailId); 403 mailconf->writeEntry("internalmailid", thisMailId);
383 mailconf->writeEntry("downloaded", newMail.downloaded); 404 mailconf->writeEntry("downloaded", newMail.downloaded);
384 mailconf->writeEntry("size", (int) newMail.size); 405 mailconf->writeEntry("size", (int) newMail.size);
385 mailconf->writeEntry("serverid", newMail.serverId); 406 mailconf->writeEntry("serverid", newMail.serverId);
386 407
387 //addressList->addContact(newMail.fromMail, newMail.from); 408 //addressList->addContact(newMail.fromMail, newMail.from);
388 } 409 }
389 410
390 mailconf->writeEntry("downloaded", newMail.downloaded); 411 mailconf->writeEntry("downloaded", newMail.downloaded);
391 412
392 QString stringMailId; 413 QString stringMailId;
393 stringMailId.setNum(thisMailId); 414 stringMailId.setNum(thisMailId);
394 //see if any attatchments needs to be stored 415 //see if any attatchments needs to be stored
395 416
396 for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { 417 for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) {
397 QString stringId; 418 QString stringId;
398 stringId.setNum(ePtr->id); 419 stringId.setNum(ePtr->id);
399 420
400 int id = mailconf->readNumEntry("enclosureid_" + stringId); 421 int id = mailconf->readNumEntry("enclosureid_" + stringId);
401 if (id != ePtr->id) { //new entry 422 if (id != ePtr->id) { //new entry
402 mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); 423 mailconf->writeEntry("enclosureid_" + stringId, ePtr->id);
403 mailconf->writeEntry("name_" + stringId, ePtr->originalName); 424 mailconf->writeEntry("name_" + stringId, ePtr->originalName);
404 mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); 425 mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType);
405 mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); 426 mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute);
406 mailconf->writeEntry("saved_" + stringId, ePtr->saved); 427 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
407 mailconf->writeEntry("installed_" + stringId, FALSE); 428 mailconf->writeEntry("installed_" + stringId, FALSE);
408 429
409 ePtr->name = stringMailId + "_" + stringId; 430 ePtr->name = stringMailId + "_" + stringId;
410 ePtr->path = getPath(TRUE); 431 ePtr->path = getPath(TRUE);
411 if (emailHandler->getEnclosure(ePtr)) { //file saved 432 if (emailHandler->getEnclosure(ePtr)) { //file saved
412 ePtr->saved = TRUE; 433 ePtr->saved = TRUE;
413 mailconf->writeEntry("saved_" + stringId, ePtr->saved); 434 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
414 mailconf->writeEntry("filename_" + stringId, ePtr->name); 435 mailconf->writeEntry("filename_" + stringId, ePtr->name);
415 mailconf->writeEntry("path_" + stringId, ePtr->path); 436 mailconf->writeEntry("path_" + stringId, ePtr->path);
416 } else { 437 } else {
417 ePtr->saved = FALSE; 438 ePtr->saved = FALSE;
418 mailconf->writeEntry("saved_" + stringId, ePtr->saved); 439 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
419 } 440 }
420 } else { 441 } else {
421 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); 442 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId);
422 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); 443 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId);
423 if (ePtr->saved) { 444 if (ePtr->saved) {
424 ePtr->name = mailconf->readEntry("filename_" + stringId); 445 ePtr->name = mailconf->readEntry("filename_" + stringId);
425 ePtr->path = mailconf->readEntry("path_" + stringId); 446 ePtr->path = mailconf->readEntry("path_" + stringId);
426 } 447 }
427 } 448 }
428 } 449 }
429 450
430 bool found=false; 451 bool found=false;
431 452
432 if (!fromDisk) 453 if (!fromDisk)
433 { 454 {
434 455
435 Email *mailPtr; 456 Email *mailPtr;
436 item = (EmailListItem *) inboxView->firstChild(); 457 item = (EmailListItem *) inboxView->firstChild();
437 while ((item != NULL)&&(!found)) 458 while ((item != NULL)&&(!found))
438 { 459 {
439 mailPtr = item->getMail(); 460 mailPtr = item->getMail();
440 if (mailPtr->id == newMail.id) { 461 if (mailPtr->id == newMail.id) {
441 item->setMail(newMail); 462 item->setMail(newMail);
442 emit mailUpdated(item->getMail()); 463 emit mailUpdated(item->getMail());
443 found = true; 464 found = true;
444 } 465 }
445 item = (EmailListItem *) item->nextSibling(); 466 item = (EmailListItem *) item->nextSibling();
446 } 467 }
447 } 468 }
448 if ((!found)||(fromDisk)) item = new EmailListItem(inboxView, newMail, TRUE); 469 if ((!found)||(fromDisk)) item = new EmailListItem(inboxView, newMail, TRUE);
449 470
450 /*if (!newMail.downloaded) 471 /*if (!newMail.downloaded)
451 mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ 472 mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/
452 473
453 mailboxView->setCurrentTab(0); 474 mailboxView->setCurrentTab(0);
454 475
455} 476}
456 477
457void EmailClient::allMailArrived(int count) 478void EmailClient::allMailArrived(int count)
458{ 479{
459 // not previewing means all mailtransfer has been done 480 // not previewing means all mailtransfer has been done
460 /*if (!previewingMail) {*/ 481 /*if (!previewingMail) {*/
461 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { 482 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) {
462 emit newCaption("Mailit - " + currentAccount->accountName); 483 emit newCaption("Mailit - " + currentAccount->accountName);
463 getNewMail(); 484 getNewMail();
464 return; 485 return;
465 } else { 486 } else {
466 allAccounts = FALSE; 487 allAccounts = FALSE;
467 receiving = FALSE; 488 receiving = FALSE;
468 getMailButton->setEnabled(TRUE); 489 getMailButton->setEnabled(TRUE);
469 cancelButton->setEnabled(FALSE); 490 cancelButton->setEnabled(FALSE);
470 selectAccountMenu->setEnabled(TRUE); 491 selectAccountMenu->setEnabled(TRUE);
471 status1Label->setText("Idle"); 492 status1Label->setText("Idle");
472 493
473 progressBar->reset(); 494 progressBar->reset();
474 return; 495 return;
475 } 496 }
476 //} 497 //}
477 498
478 // all headers downloaded from server, start downloading remaining mails 499 // all headers downloaded from server, start downloading remaining mails
479 previewingMail = FALSE; 500 previewingMail = FALSE;
480 status1Label->setText(currentAccount->accountName); 501 status1Label->setText(currentAccount->accountName);
481 progressBar->reset(); 502 progressBar->reset();
482 503
483 504
484 mailboxView->setCurrentTab(0); 505 mailboxView->setCurrentTab(0);
485} 506}
486 507
487 508
488void EmailClient::moveMailFront(Email *mailPtr) 509void EmailClient::moveMailFront(Email *mailPtr)
489{ 510{
490 if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { 511 if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) {
491 mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); 512 mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size);
492 } 513 }
493} 514}
494 515
495void EmailClient::smtpError(int code) 516void EmailClient::smtpError(int code)
496{ 517{
497 QString temp; 518 QString temp;
498 519
499 if (code == ErrUnknownResponse) 520 if (code == ErrUnknownResponse)
500 temp = "Unknown response from server"; 521 temp = "Unknown response from server";
501 522
502 if (code == QSocket::ErrHostNotFound) 523 if (code == QSocket::ErrHostNotFound)
503 temp = "host not found"; 524 temp = "host not found";
504 if (code == QSocket::ErrConnectionRefused) 525 if (code == QSocket::ErrConnectionRefused)
505 temp = "connection refused"; 526 temp = "connection refused";
506 if (code == QSocket::ErrSocketRead) 527 if (code == QSocket::ErrSocketRead)
507 temp = "socket packet error"; 528 temp = "socket packet error";
508 529
509 if (code != ErrCancel) { 530 if (code != ErrCancel) {
510 QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); 531 QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n");
511 } else { 532 } else {
512 status2Label->setText("Aborted by user"); 533 status2Label->setText("Aborted by user");
513 } 534 }
514 535
515 sending = FALSE; 536 sending = FALSE;
516 sendMailButton->setEnabled(TRUE); 537 sendMailButton->setEnabled(TRUE);
517 cancelButton->setEnabled(FALSE); 538 cancelButton->setEnabled(FALSE);
518 quedMessages.clear(); 539 quedMessages.clear();
519} 540}
520 541
521void EmailClient::popError(int code) 542void EmailClient::popError(int code)
522{ 543{
523 QString temp; 544 QString temp;
524 545
525 if (code == ErrUnknownResponse) 546 if (code == ErrUnknownResponse)
526 temp = "Unknown response from server"; 547 temp = "Unknown response from server";
527 if (code == ErrLoginFailed) 548 if (code == ErrLoginFailed)
528 temp = "Login failed\nCheck user name and password"; 549 temp = "Login failed\nCheck user name and password";
529 550
530 if (code == QSocket::ErrHostNotFound) 551 if (code == QSocket::ErrHostNotFound)
531 temp = "host not found"; 552 temp = "host not found";
532 if (code == QSocket::ErrConnectionRefused) 553 if (code == QSocket::ErrConnectionRefused)
533 temp = "connection refused"; 554 temp = "connection refused";
534 if (code == QSocket::ErrSocketRead) 555 if (code == QSocket::ErrSocketRead)
535 temp = "socket packet error"; 556 temp = "socket packet error";
536 557
537 if (code != ErrCancel) { 558 if (code != ErrCancel) {
538 QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n"); 559 QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n");
539 } else { 560 } else {
540 status2Label->setText("Aborted by user"); 561 status2Label->setText("Aborted by user");
541 } 562 }
542 563
543 receiving = FALSE; 564 receiving = FALSE;
544 getMailButton->setEnabled(TRUE); 565 getMailButton->setEnabled(TRUE);
545 cancelButton->setEnabled(FALSE); 566 cancelButton->setEnabled(FALSE);
546 selectAccountMenu->setEnabled(TRUE); 567 selectAccountMenu->setEnabled(TRUE);
547} 568}
548 569
549void EmailClient::inboxItemSelected() 570void EmailClient::inboxItemSelected()
550{ 571{
551 //killTimer(timerID); 572 //killTimer(timerID);
552 573
@@ -729,240 +750,283 @@ void EmailClient::saveSettings()
729 mailconf->writeEntry("POPServer",accountPtr->popServer); 750 mailconf->writeEntry("POPServer",accountPtr->popServer);
730 mailconf->writeEntry("SMTPServer",accountPtr->smtpServer); 751 mailconf->writeEntry("SMTPServer",accountPtr->smtpServer);
731 mailconf->writeEntry("AccountId",accountPtr->id); 752 mailconf->writeEntry("AccountId",accountPtr->id);
732 if (accountPtr->synchronize) 753 if (accountPtr->synchronize)
733 { 754 {
734 mailconf->writeEntry("Synchronize","Yes"); 755 mailconf->writeEntry("Synchronize","Yes");
735 mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit); 756 mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit);
736 mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount); 757 mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount);
737 } 758 }
738 else 759 else
739 { 760 {
740 mailconf->writeEntry("Synchronize", "No"); 761 mailconf->writeEntry("Synchronize", "No");
741 } 762 }
742 } 763 }
743 764
744 mailconf->setGroup("mailitglobal"); 765 mailconf->setGroup("mailitglobal");
745 mailconf->writeEntry("Accounts",acc_count); 766 mailconf->writeEntry("Accounts",acc_count);
746 mailconf->writeEntry("mailidcount", mailIdCount); 767 mailconf->writeEntry("mailidcount", mailIdCount);
747 mailconf->writeEntry("accountidcount", accountIdCount); 768 mailconf->writeEntry("accountidcount", accountIdCount);
748} 769}
749 770
750void EmailClient::selectAccount(int id) 771void EmailClient::selectAccount(int id)
751{ 772{
752 if (accountList.count() > 0) { 773 if (accountList.count() > 0) {
753 currentAccount = accountList.at(id); 774 currentAccount = accountList.at(id);
754 emit newCaption("Mailit - " + currentAccount->accountName); 775 emit newCaption("Mailit - " + currentAccount->accountName);
755 getNewMail(); 776 getNewMail();
756 } else { 777 } else {
757 emit newCaption("Mailit ! No account defined"); 778 emit newCaption("Mailit ! No account defined");
758 } 779 }
759} 780}
760 781
761void EmailClient::editAccount(int id) 782void EmailClient::editAccount(int id)
762{ 783{
763 MailAccount *newAccount; 784 MailAccount *newAccount;
764 785
765 editAccountView = new EditAccount(this, "account", TRUE); 786 editAccountView = new EditAccount(this, "account", TRUE);
766 if (id == newAccountId) { //new account 787 if (id == newAccountId) { //new account
767 newAccount = new MailAccount; 788 newAccount = new MailAccount;
768 editAccountView->setAccount(newAccount); 789 editAccountView->setAccount(newAccount);
769 } else { 790 } else {
770 newAccount = accountList.at(id); 791 newAccount = accountList.at(id);
771 editAccountView->setAccount(newAccount, FALSE); 792 editAccountView->setAccount(newAccount, FALSE);
772 } 793 }
773 794
774 editAccountView->showMaximized(); 795 editAccountView->showMaximized();
775 editAccountView->exec(); 796 editAccountView->exec();
776 797
777 if (editAccountView->result() == QDialog::Accepted) { 798 if (editAccountView->result() == QDialog::Accepted) {
778 if (id == newAccountId) { 799 if (id == newAccountId) {
779 newAccount->id = accountIdCount; 800 newAccount->id = accountIdCount;
780 accountIdCount++; 801 accountIdCount++;
781 accountList.append(newAccount); 802 accountList.append(newAccount);
782 updateAccounts(); 803 updateAccounts();
783 } else { 804 } else {
784 updateAccounts(); 805 updateAccounts();
785 } 806 }
786 } 807 }
787 808
788 delete editAccountView; 809 delete editAccountView;
789} 810}
790 811
791void EmailClient::deleteAccount(int id) 812void EmailClient::deleteAccount(int id)
792{ 813{
793 MailAccount *newAccount; 814 MailAccount *newAccount;
794 QString message; 815 QString message;
795 816
796 newAccount = accountList.at(id); 817 newAccount = accountList.at(id);
797 message = "Delete account:\n" + newAccount->accountName; 818 message = "Delete account:\n" + newAccount->accountName;
798 switch( QMessageBox::warning( this, "Mailit", message, 819 switch( QMessageBox::warning( this, "Mailit", message,
799 "Yes", "No", 0, 0, 1 ) ) { 820 "Yes", "No", 0, 0, 1 ) ) {
800 821
801 case 0: accountList.remove(id); 822 case 0: accountList.remove(id);
802 updateAccounts(); 823 updateAccounts();
803 break; 824 break;
804 case 1: 825 case 1:
805 break; 826 break;
806 } 827 }
807} 828}
808 829
809void EmailClient::updateAccounts() 830void EmailClient::updateAccounts()
810{ 831{
811 MailAccount *accountPtr; 832 MailAccount *accountPtr;
812 833
813 //rebuild menus, clear all first 834 //rebuild menus, clear all first
814 editAccountMenu->clear(); 835 editAccountMenu->clear();
815 selectAccountMenu->clear(); 836 selectAccountMenu->clear();
816 deleteAccountMenu->clear(); 837 deleteAccountMenu->clear();
817 838
818 newAccountId = editAccountMenu->insertItem("New", this, 839 newAccountId = editAccountMenu->insertItem("New", this,
819 SLOT(editAccount(int)) ); 840 SLOT(editAccount(int)) );
820 editAccountMenu->insertSeparator(); 841 editAccountMenu->insertSeparator();
821 842
822 idCount = 0; 843 idCount = 0;
823 for (accountPtr = accountList.first(); accountPtr != 0; 844 for (accountPtr = accountList.first(); accountPtr != 0;
824 accountPtr = accountList.next()) { 845 accountPtr = accountList.next()) {
825 846
826 editAccountMenu->insertItem(accountPtr->accountName, 847 editAccountMenu->insertItem(accountPtr->accountName,
827 this, SLOT(editAccount(int)), 0, idCount); 848 this, SLOT(editAccount(int)), 0, idCount);
828 selectAccountMenu->insertItem(accountPtr->accountName, 849 selectAccountMenu->insertItem(accountPtr->accountName,
829 this, SLOT(selectAccount(int)), 0, idCount); 850 this, SLOT(selectAccount(int)), 0, idCount);
830 deleteAccountMenu->insertItem(accountPtr->accountName, 851 deleteAccountMenu->insertItem(accountPtr->accountName,
831 this, SLOT(deleteAccount(int)), 0, idCount); 852 this, SLOT(deleteAccount(int)), 0, idCount);
832 idCount++; 853 idCount++;
833 } 854 }
834} 855}
835 856
836void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) 857void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox)
837{ 858{
838 Email *mPtr; 859 Email *mPtr;
839 Enclosure *ePtr; 860 Enclosure *ePtr;
840 861
841 if (inbox) 862 if (inbox)
842 { 863 {
843 mPtr = mailItem->getMail(); 864 mPtr = mailItem->getMail();
844 865
845 //if mail is in queue for download, remove it from 866 //if mail is in queue for download, remove it from
846 //queue if possible 867 //queue if possible
847 if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { 868 if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) {
848 if ( !mPtr->downloaded ) 869 if ( !mPtr->downloaded )
849 mailDownloadList.remove(mPtr->serverId, mPtr->size); 870 mailDownloadList.remove(mPtr->serverId, mPtr->size);
850 } 871 }
851 872
852 mailconf->setGroup(mPtr->id); 873 mailconf->setGroup(mPtr->id);
853 mailconf->clearGroup(); 874 mailconf->clearGroup();
854 875
855 //delete any temporary attatchemnts storing 876 //delete any temporary attatchemnts storing
856 for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { 877 for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) {
857 if (ePtr->saved) { 878 if (ePtr->saved) {
858 QFile::remove( (ePtr->path + ePtr->name) ); 879 QFile::remove( (ePtr->path + ePtr->name) );
859 } 880 }
860 } 881 }
861 inboxView->takeItem(mailItem); 882 inboxView->takeItem(mailItem);
862 } 883 }
863 else 884 else
864 { 885 {
865 outboxView->takeItem(mailItem); 886 outboxView->takeItem(mailItem);
866 } 887 }
867} 888}
868 889
869void EmailClient::setMailSize(int size) 890void EmailClient::setMailSize(int size)
870{ 891{
871 progressBar->reset(); 892 progressBar->reset();
872 progressBar->setTotalSteps(size); 893 progressBar->setTotalSteps(size);
873} 894}
874 895
875void EmailClient::setTotalSize(int size) 896void EmailClient::setTotalSize(int size)
876{ 897{
877 898
878} 899}
879 900
880void EmailClient::setDownloadedSize(int size) 901void EmailClient::setDownloadedSize(int size)
881{ 902{
882 int total = progressBar->totalSteps(); 903 int total = progressBar->totalSteps();
883 904
884 if (size < total) { 905 if (size < total) {
885 progressBar->setProgress(size); 906 progressBar->setProgress(size);
886 } else { 907 } else {
887 progressBar->setProgress(total); 908 progressBar->setProgress(total);
888 } 909 }
889} 910}
890 911
891void EmailClient::deleteItem() 912void EmailClient::deleteItem()
892{ 913{
893 bool inbox=mailboxView->currentTab()==0; 914 bool inbox=mailboxView->currentTab()==0;
894 QListView* box; 915 QListView* box;
895 916
896 EmailListItem* eli; 917 EmailListItem* eli;
897 int pos; 918 int pos;
898 919
899 inbox ? box=inboxView : box=outboxView; 920 inbox ? box=inboxView : box=outboxView;
900 921
901 eli=(EmailListItem*)box->selectedItem(); 922 eli=(EmailListItem*)box->selectedItem();
902 923
903 if (eli) 924 if (eli)
904 { 925 {
905 box->setSelected(eli->itemBelow(),true);//select the previous item 926 box->setSelected(eli->itemBelow(),true);//select the previous item
906 927
907 deleteMail(eli,(bool&)inbox); //remove mail entry 928 deleteMail(eli,(bool&)inbox); //remove mail entry
908 } 929 }
909} 930}
910 931
911void EmailClient::inboxItemPressed() 932void EmailClient::inboxItemPressed()
912{ 933{
913 //timerID=startTimer(500); 934 //timerID=startTimer(500);
914} 935}
915 936
916void EmailClient::inboxItemReleased() 937void EmailClient::inboxItemReleased()
917{ 938{
918 //killTimer(timerID); 939 //killTimer(timerID);
919} 940}
920 941
921void EmailClient::timerEvent(QTimerEvent *e) 942/*void EmailClient::timerEvent(QTimerEvent *e)
922{ 943{
923 /*killTimer(timerID); 944 /*killTimer(timerID);
924 945
925 946
926 QPopupMenu *action = new QPopupMenu(this); 947 QPopupMenu *action = new QPopupMenu(this);
927 948
928 int reply=0; 949 int reply=0;
929 950
930 action->insertItem(tr( "Reply To" ),this,SLOT(reply())); 951 action->insertItem(tr( "Reply To" ),this,SLOT(reply()));
931 action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); 952 action->insertItem( tr( "Reply All" ),this,SLOT(replyAll()));
932 action->insertItem( tr( "Forward" ), this,SLOT(forward())); 953 action->insertItem( tr( "Forward" ), this,SLOT(forward()));
933 action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); 954 action->insertItem( tr( "Remove Mail" ), this,SLOT(remove()));
934 955
935 action->exec(QCursor::pos()); 956 action->exec(QCursor::pos());
936 957
937 if (action) delete action; 958 if (action) delete action;
938 */ 959
939} 960}*/
940 961
941Email* EmailClient::getCurrentMail() 962Email* EmailClient::getCurrentMail()
942{ 963{
943 EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); 964 EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem());
944 if (eli!=NULL) 965 if (eli!=NULL)
945 return eli->getMail(); 966 return eli->getMail();
946 else 967 else
947 return NULL; 968 return NULL;
948} 969}
949 970
950void EmailClient::download(Email* mail) 971void EmailClient::download(Email* mail)
951{ 972{
952 MailAccount* acc=0; 973 MailAccount* acc=0;
953 974
954 tempMailDownloadList.clear(); 975 tempMailDownloadList.clear();
955 tempMailDownloadList.sizeInsert(mail->serverId, mail->size); 976 tempMailDownloadList.sizeInsert(mail->serverId, mail->size);
956 if (accountList.count()>0)
957 qDebug("Accounts present");
958 977
959 acc=accountList.at(mail->fromAccountId-1); 978 acc=accountList.at(mail->fromAccountId-1);
960 if (acc) 979 if (acc)
961 { 980 {
962 emailHandler->setAccount(*acc); 981 emailHandler->setAccount(*acc);
963 emailHandler->getMailByList(&tempMailDownloadList); 982 emailHandler->getMailByList(&tempMailDownloadList);
964 } 983 }
965 else 984 else
966 QMessageBox::warning(qApp->activeWindow(), 985 QMessageBox::warning(qApp->activeWindow(),
967 tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n"); 986 tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n");
968} 987}
988
989void EmailClient::receive(const QCString& msg, const QByteArray& data)
990{
991 /*if (msg=="getMail()")
992 {
993 /*QDialog qd(qApp->activeWindow(),"Getting mail",true);
994 QVBoxLayout *vbProg = new QVBoxLayout( &qd );
995
996 initStatusBar(&qd);
997
998 if (statusBar==0)
999 {
1000 qDebug("No Bar ...");
1001 //statusBar=new ProgressBar(&qd);
1002 }
1003 statusBar->show();
1004 vbProg->addWidget(statusBar);
1005 qd.showMaximized();
1006 qd.show();
1007 emit getAllNewMail();
1008 //qd.exec();
1009 }
1010 else if (msg=="compose()")
1011 {
1012 QDialog qd(qApp->activeWindow(),"Getting mail",true);
1013
1014 WriteMail wm(&qd,"write new mail");
1015 QVBoxLayout vbProg( &qd );
1016
1017 wm.showMaximized();
1018 vbProg.addWidget(&wm);
1019
1020 qd.showMaximized();
1021
1022 emit composeRequested();
1023 qd.exec();
1024
1025 QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n");
1026 }
1027
1028 else if (msg=="dialog()")
1029 {
1030 QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n");
1031 }*/
1032}
diff --git a/noncore/unsupported/mailit/emailclient.h b/noncore/unsupported/mailit/emailclient.h
index 549683b..994fec5 100644
--- a/noncore/unsupported/mailit/emailclient.h
+++ b/noncore/unsupported/mailit/emailclient.h
@@ -1,174 +1,181 @@
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#ifndef EMAILCLIENT_H 20#ifndef EMAILCLIENT_H
21#define EMAILCLIENT_H 21#define EMAILCLIENT_H
22 22
23#include <qlist.h> 23#include <qlist.h>
24#include <qcstring.h> 24#include <qcstring.h>
25#include <qmainwindow.h> 25#include <qmainwindow.h>
26 26
27#include <qtoolbar.h> 27#include <qtoolbar.h>
28#include <qcheckbox.h> 28#include <qcheckbox.h>
29#include <qlabel.h> 29#include <qlabel.h>
30#include <qlineedit.h> 30#include <qlineedit.h>
31#include <qlistview.h> 31#include <qlistview.h>
32#include <qaction.h> 32#include <qaction.h>
33#include <qlayout.h> 33#include <qlayout.h>
34#include <qtooltip.h> 34#include <qtooltip.h>
35#include <qtoolbutton.h> 35#include <qtoolbutton.h>
36#include <qimage.h> 36#include <qimage.h>
37#include <qpixmap.h> 37#include <qpixmap.h>
38#include <qstringlist.h> 38#include <qstringlist.h>
39#include <qprogressbar.h> 39#include <qprogressbar.h>
40#include <qstatusbar.h> 40#include <qstatusbar.h>
41#include <qdir.h> 41#include <qdir.h>
42#include <stdlib.h> 42#include <stdlib.h>
43#include <opie/otabwidget.h> 43#include <opie/otabwidget.h>
44#include <qpe/qcopenvelope_qws.h>
44#include <qtimer.h> 45#include <qtimer.h>
45 46
46#include "emailhandler.h" 47#include "emailhandler.h"
47#include "emaillistitem.h" 48#include "emaillistitem.h"
48#include "textparser.h" 49#include "textparser.h"
49#include "editaccount.h" 50#include "editaccount.h"
50#include "maillist.h" 51#include "maillist.h"
51#include "addresslist.h" 52#include "addresslist.h"
52 53
53#include <qpe/config.h> 54#include <qpe/config.h>
54 55
55class AccountList : public QList<MailAccount> 56class AccountList : public QList<MailAccount>
56{ 57{
57public: 58public:
58 Item newItem(Item d); 59 Item newItem(Item d);
59private: 60private:
60 MailAccount* dupl(MailAccount *in); 61 MailAccount* dupl(MailAccount *in);
61 MailAccount *ac; 62 MailAccount *ac;
62}; 63};
63 64
64//class EmailClient : public EmailClientBase 65//class EmailClient : public EmailClientBase
65class EmailClient : public QMainWindow 66class EmailClient : public QMainWindow
66{ 67{
67 Q_OBJECT 68 Q_OBJECT
68 69
69public: 70public:
70 EmailClient( QWidget* parent, const char* name, WFlags fl = 0 ); 71 EmailClient( QWidget* parent, const char* name, WFlags fl = 0 );
71 ~EmailClient(); 72 ~EmailClient();
72 AddressList* getAdrListRef(); 73 AddressList* getAdrListRef();
73 void download(Email*);
74 74
75protected: 75protected:
76 void timerEvent(QTimerEvent*); 76 //void timerEvent(QTimerEvent*);
77 77
78signals: 78signals:
79 void composeRequested(); 79 void composeRequested();
80 void viewEmail(QListView *, Email *); 80 void viewEmail(QListView *, Email *);
81 void mailUpdated(Email *); 81 void mailUpdated(Email *);
82 void newCaption(const QString &); 82 void newCaption(const QString &);
83 void replyRequested(Email&, bool&); 83 void replyRequested(Email&, bool&);
84 void forwardRequested(Email&); 84 void forwardRequested(Email&);
85 void removeItem(EmailListItem*, bool&); 85 void removeItem(EmailListItem*, bool&);
86 /*void reply(Email&); 86 /*void reply(Email&);
87 void replyAll(Email&); 87 void replyAll(Email&);
88 void remove(Email&); 88 void remove(Email&);
89 void forward(Email&);*/ 89 void forward(Email&);*/
90 90
91public slots: 91public slots:
92 void compose(); 92 void compose();
93 void cancel(); 93 void cancel();
94 void enqueMail(const Email &mail); 94 void enqueMail(const Email &mail);
95 void setMailAccount(); 95 void setMailAccount();
96 void sendQuedMail(); 96 void sendQuedMail();
97 void mailSent(); 97 void mailSent();
98 void deleteItem(); 98 void deleteItem();
99 void getNewMail(); 99 void getNewMail();
100 void getAllNewMail(); 100 void getAllNewMail();
101 void smtpError(int code); 101 void smtpError(int code);
102 void popError(int code); 102 void popError(int code);
103 void inboxItemSelected(); 103 void inboxItemSelected();
104 void outboxItemSelected(); 104 void outboxItemSelected();
105 void inboxItemPressed(); 105 void inboxItemPressed();
106 void inboxItemReleased(); 106 void inboxItemReleased();
107 void mailArrived(const Email &mail, bool fromDisk); 107 void mailArrived(const Email &mail, bool fromDisk);
108 void allMailArrived(int); 108 void allMailArrived(int);
109 void saveMail(QString fileName, QListView *view); 109 void saveMail(QString fileName, QListView *view);
110 void selectAccount(int); 110 void selectAccount(int);
111 void editAccount(int); 111 void editAccount(int);
112 void updateAccounts(); 112 void updateAccounts();
113 void deleteAccount(int); 113 void deleteAccount(int);
114 void deleteMail(EmailListItem *mailItem, bool &inbox); 114 void deleteMail(EmailListItem *mailItem, bool &inbox);
115 void setTotalSize(int); 115 void setTotalSize(int);
116 void setMailSize(int); 116 void setMailSize(int);
117 void setDownloadedSize(int); 117 void setDownloadedSize(int);
118 void moveMailFront(Email *mailPtr); 118 void moveMailFront(Email *mailPtr);
119 void download(Email*);
119/* void reply(); 120/* void reply();
120 void replyAll(); 121 void replyAll();
121 void forward(); 122 void forward();
122 void remove();*/ 123 void remove();*/
123 124
125private slots:
126 void receive(const QCString&, const QByteArray&);
127
124private: 128private:
125 void init(); 129 void init();
130 void initStatusBar(QWidget*);
126 void readMail(); 131 void readMail();
127 QString getPath(bool enclosurePath); 132 QString getPath(bool enclosurePath);
128 void readSettings(); 133 void readSettings();
129 void saveSettings(); 134 void saveSettings();
130 Email* getCurrentMail(); 135 Email* getCurrentMail();
131 int timerID; 136 int timerID;
132 Config *mailconf; 137 Config *mailconf;
133 int newAccountId, idCount, mailIdCount; 138 int newAccountId, idCount, mailIdCount;
134 int accountIdCount; 139 int accountIdCount;
135 AccountList accountList; 140 AccountList accountList;
136 AddressList *addressList; 141 AddressList *addressList;
137 142
138 EditAccount *editAccountView; 143 EditAccount *editAccountView;
139 EmailListItem *item; 144 EmailListItem *item;
140 EmailHandler *emailHandler; 145 EmailHandler *emailHandler;
141 QList<Email> quedMessages; 146 QList<Email> quedMessages;
142 MailList mailDownloadList; 147 MailList mailDownloadList;
143 MailList tempMailDownloadList; 148 MailList tempMailDownloadList;
144 149
145 bool sending, receiving, previewingMail, allAccounts; 150 bool sending, receiving, previewingMail, allAccounts;
146 QString lineShift; 151 QString lineShift;
147 MailAccount account, *currentAccount; 152 MailAccount account, *currentAccount;
148 153
154 QCopChannel* channel;
155
149 QToolBar *bar; 156 QToolBar *bar;
150 QProgressBar *progressBar; 157 QProgressBar *progressBar;
151 QStatusBar *statusBar; 158 QStatusBar *statusBar;
152 QLabel *status1Label, *status2Label; 159 QLabel *status1Label, *status2Label;
153 QToolButton *getMailButton; 160 QToolButton *getMailButton;
154 QAction *sendMailButton; 161 QAction *sendMailButton;
155 QAction *composeButton; 162 QAction *composeButton;
156 QAction *cancelButton; 163 QAction *cancelButton;
157 QAction *deleteButton; 164 QAction *deleteButton;
158 //QToolButton *setAccountButton; 165 //QToolButton *setAccountButton;
159 166
160 QMenuBar *mb; 167 QMenuBar *mb;
161 QPopupMenu *selectAccountMenu; 168 QPopupMenu *selectAccountMenu;
162 QPopupMenu *editAccountMenu; 169 QPopupMenu *editAccountMenu;
163 QPopupMenu *deleteAccountMenu; 170 QPopupMenu *deleteAccountMenu;
164 QPopupMenu *setAccountMenu; 171 QPopupMenu *setAccountMenu;
165 172
166 OTabWidget* mailboxView; 173 OTabWidget* mailboxView;
167 QListView* inboxView; 174 QListView* inboxView;
168 QListView* outboxView; 175 QListView* outboxView;
169 176
170 QGridLayout* grid_2; 177 QGridLayout* grid_2;
171 QGridLayout* grid_3; 178 QGridLayout* grid_3;
172}; 179};
173 180
174#endif // EMAILCLIENT_H 181#endif // EMAILCLIENT_H
diff --git a/noncore/unsupported/mailit/emailhandler.cpp b/noncore/unsupported/mailit/emailhandler.cpp
index fbbada7..c7b27a0 100644
--- a/noncore/unsupported/mailit/emailhandler.cpp
+++ b/noncore/unsupported/mailit/emailhandler.cpp
@@ -1,309 +1,312 @@
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");
43
42 smtpClient = new SmtpClient(); 44 smtpClient = new SmtpClient();
43 popClient = new PopClient(); 45 popClient = new PopClient();
44 46
45 connect(smtpClient, SIGNAL(errorOccurred(int)), this, 47 connect(smtpClient, SIGNAL(errorOccurred(int)), this,
46 SIGNAL(smtpError(int)) ); 48 SIGNAL(smtpError(int)) );
47 connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); 49 connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) );
48 connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, 50 connect(smtpClient, SIGNAL(updateStatus(const QString &)), this,
49 SIGNAL(updateSmtpStatus(const QString &)) ); 51 SIGNAL(updateSmtpStatus(const QString &)) );
50 52
51 connect(popClient, SIGNAL(errorOccurred(int)), this, 53 connect(popClient, SIGNAL(errorOccurred(int)), this,
52 SIGNAL(popError(int)) ); 54 SIGNAL(popError(int)) );
53 connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), 55 connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)),
54 this, SLOT(messageArrived(const QString &, int, uint, bool)) ); 56 this, SLOT(messageArrived(const QString &, int, uint, bool)) );
55 connect(popClient, SIGNAL(updateStatus(const QString &)), this, 57 connect(popClient, SIGNAL(updateStatus(const QString &)), this,
56 SIGNAL(updatePopStatus(const QString &)) ); 58 SIGNAL(updatePopStatus(const QString &)) );
57 connect(popClient, SIGNAL(mailTransfered(int)), this, 59 connect(popClient, SIGNAL(mailTransfered(int)), this,
58 SIGNAL(mailTransfered(int)) ); 60 SIGNAL(mailTransfered(int)) );
59 61
60 62
61 //relaying size information 63 //relaying size information
62 connect(popClient, SIGNAL(currentMailSize(int)), 64 connect(popClient, SIGNAL(currentMailSize(int)),
63 this, SIGNAL(currentMailSize(int)) ); 65 this, SIGNAL(currentMailSize(int)) );
64 connect(popClient, SIGNAL(downloadedSize(int)), 66 connect(popClient, SIGNAL(downloadedSize(int)),
65 this, SIGNAL(downloadedSize(int)) ); 67 this, SIGNAL(downloadedSize(int)) );
66} 68}
67 69
68void EmailHandler::sendMail(QList<Email> *mailList) 70void EmailHandler::sendMail(QList<Email> *mailList)
69{ 71{
70 Email *currentMail; 72 Email *currentMail;
71 QString temp; 73 QString temp;
72 QString userName = mailAccount.name; 74 QString userName = mailAccount.name;
73 userName += " <" + mailAccount.emailAddress + ">"; 75 userName += " <" + mailAccount.emailAddress + ">";
74 76
75 for (currentMail = mailList->first(); currentMail != 0; 77 for (currentMail = mailList->first(); currentMail != 0;
76 currentMail = mailList->next()) { 78 currentMail = mailList->next()) {
77 79
78 if (encodeMime(currentMail) == 0) { 80 if (encodeMime(currentMail) == 0) {
79 smtpClient->addMail(userName, currentMail->subject, 81 smtpClient->addMail(userName, currentMail->subject,
80 currentMail->recipients, currentMail->rawMail); 82 currentMail->recipients, currentMail->rawMail);
81 } else { //error 83 } else { //error
82 temp = tr("Could not locate all files in \nmail with subject: ") + 84 temp = tr("Could not locate all files in \nmail with subject: ") +
83 currentMail->subject; 85 currentMail->subject;
84 temp += tr("\nMail has NOT been sent"); 86 temp += tr("\nMail has NOT been sent");
85 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); 87 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n"));
86 88
87 } 89 }
88 } 90 }
89 smtpClient->newConnection(mailAccount.smtpServer, 25); 91 smtpClient->newConnection(mailAccount.smtpServer, 25);
90} 92}
91 93
92void EmailHandler::setAccount(MailAccount account) 94void EmailHandler::setAccount(MailAccount account)
93{ 95{
94 mailAccount = account; 96 mailAccount = account;
95} 97}
96 98
97void EmailHandler::getMail() 99void EmailHandler::getMail()
98{ 100{
99 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); 101 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
100 if (mailAccount.synchronize) { 102 if (mailAccount.synchronize) {
101 popClient->setSynchronize(mailAccount.lastServerMailCount); 103 popClient->setSynchronize(mailAccount.lastServerMailCount);
102 } else { 104 } else {
103 popClient->removeSynchronize(); 105 popClient->removeSynchronize();
104 } 106 }
105 107
106 headers = FALSE; 108 headers = FALSE;
107 //popClient->headersOnly(headers, 0); 109 //popClient->headersOnly(headers, 0);
108 popClient->newConnection(mailAccount.popServer, 110); 110 popClient->newConnection(mailAccount.popServer, 110);
109} 111}
110 112
111void EmailHandler::getMailHeaders() 113void EmailHandler::getMailHeaders()
112{ 114{
113 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); 115 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
114 mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); 116 mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize();
115 117
116 headers = TRUE; 118 headers = TRUE;
117 popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all 119 popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all
120 qDebug("Initiating connection");
118 popClient->newConnection(mailAccount.popServer, 110); 121 popClient->newConnection(mailAccount.popServer, 110);
119} 122}
120 123
121void EmailHandler::getMailByList(MailList *mailList) 124void EmailHandler::getMailByList(MailList *mailList)
122{ 125{
123 if (mailList->count() == 0) { //should not occur though 126 if (mailList->count() == 0) { //should not occur though
124 emit mailTransfered(0); 127 emit mailTransfered(0);
125 return; 128 return;
126 } 129 }
127 130
128 headers = FALSE; 131 headers = FALSE;
129 popClient->headersOnly(FALSE, 0); 132 popClient->headersOnly(FALSE, 0);
130 133
131 popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd); 134 popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd);
132 popClient->setSelectedMails(mailList); 135 popClient->setSelectedMails(mailList);
133 popClient->newConnection(mailAccount.popServer, 110); 136 popClient->newConnection(mailAccount.popServer, 110);
134 } 137 }
135 138
136void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) 139void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete)
137{ 140{
138 Email mail; 141 Email mail;
139 142
140 mail.rawMail = message; 143 mail.rawMail = message;
141 mail.serverId = id; 144 mail.serverId = id;
142 mail.size = size; 145 mail.size = size;
143 mail.downloaded = complete; 146 mail.downloaded = complete;
144 147
145 emit mailArrived(mail, FALSE); 148 emit mailArrived(mail, FALSE);
146} 149}
147 150
148bool EmailHandler::parse(QString in, QString lineShift, Email *mail) 151bool EmailHandler::parse(QString in, QString lineShift, Email *mail)
149{ 152{
150 QString temp, boundary; 153 QString temp, boundary;
151 int pos; 154 int pos;
152 QString delimiter, header, body, mimeHeader, mimeBody; 155 QString delimiter, header, body, mimeHeader, mimeBody;
153 QString content, contentType, contentAttribute, id, encoding; 156 QString content, contentType, contentAttribute, id, encoding;
154 QString fileName, storedName; 157 QString fileName, storedName;
155 int enclosureId = 0; 158 int enclosureId = 0;
156 159
157 mail->rawMail = in; 160 mail->rawMail = in;
158 mail->received = TRUE; 161 mail->received = TRUE;
159 mail->files.setAutoDelete(TRUE); 162 mail->files.setAutoDelete(TRUE);
160 163
161 temp = lineShift + "." + lineShift; 164 temp = lineShift + "." + lineShift;
162 165
163 if (in.right(temp.length()) != temp) { 166 if (in.right(temp.length()) != temp) {
164 mail->rawMail += temp; 167 mail->rawMail += temp;
165 } 168 }
166 169
167 170
168 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" 171 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n"
169 pos = in.find(delimiter, 0, FALSE); 172 pos = in.find(delimiter, 0, FALSE);
170 header = in.left(pos); 173 header = in.left(pos);
171 body = in.right(in.length() - pos - delimiter.length()); 174 body = in.right(in.length() - pos - delimiter.length());
172 if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) 175 if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n'))
173 body.truncate(body.length()-2); 176 body.truncate(body.length()-2);
174 177
175 TextParser p(header, lineShift); 178 TextParser p(header, lineShift);
176 179
177 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { 180 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) {
178 pos++; 181 pos++;
179 if (p.separatorAt(pos) == ' ') { 182 if (p.separatorAt(pos) == ' ') {
180 mail->from = p.getString(&pos, '<', false); 183 mail->from = p.getString(&pos, '<', false);
181 mail->from = mail->from.stripWhiteSpace(); 184 mail->from = mail->from.stripWhiteSpace();
182 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { 185 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) {
183 mail->from = mail->from.left(mail->from.length() - 1); 186 mail->from = mail->from.left(mail->from.length() - 1);
184 mail->from = mail->from.right(mail->from.length() - 1); 187 mail->from = mail->from.right(mail->from.length() - 1);
185 } 188 }
186 pos++; 189 pos++;
187 mail->fromMail = p.getString(&pos, '>', false); 190 mail->fromMail = p.getString(&pos, '>', false);
188 } else { 191 } else {
189 if (p.separatorAt(pos) == '<') //No name.. nasty 192 if (p.separatorAt(pos) == '<') //No name.. nasty
190 pos++; 193 pos++;
191 //pos++; 194 //pos++;
192 mail->fromMail = p.getString(&pos, 'z', TRUE); 195 mail->fromMail = p.getString(&pos, 'z', TRUE);
193 if (mail->fromMail.at(mail->fromMail.length()-1) == '>') 196 if (mail->fromMail.at(mail->fromMail.length()-1) == '>')
194 mail->fromMail.truncate(mail->fromMail.length() - 1); 197 mail->fromMail.truncate(mail->fromMail.length() - 1);
195 mail->from=mail->fromMail; 198 mail->from=mail->fromMail;
196 } 199 }
197 } 200 }
198 201
199 pos=0; 202 pos=0;
200 203
201 //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: 204 //Search for To: after the FROM: attribute to prevent hitting the Delivered-To:
202 while((pos = p.find("TO",':', pos+1, TRUE))!=-1) 205 while((pos = p.find("TO",':', pos+1, TRUE))!=-1)
203 { 206 {
204 QString rec; 207 QString rec;
205 208
206 if (p.separatorAt(pos-1)!='-') 209 if (p.separatorAt(pos-1)!='-')
207 { 210 {
208 pos++; 211 pos++;
209 mail->recipients.append(p.getString(&pos, '\r', TRUE)); 212 mail->recipients.append(p.getString(&pos, '\r', TRUE));
210 } 213 }
211 /*else { 214 /*else {
212 if ((p.separatorAt(pos) == '<')|| (p.separatorAt(pos) == ' ')) //No name.. nasty 215 if ((p.separatorAt(pos) == '<')|| (p.separatorAt(pos) == ' ')) //No name.. nasty
213 pos++; 216 pos++;
214 pos++; 217 pos++;
215 mail->fromMail = p.getString(&pos, 'z', TRUE); 218 mail->fromMail = p.getString(&pos, 'z', TRUE);
216 if (mail->fromMail.at(mail->fromMail.length()-1) == '>') 219 if (mail->fromMail.at(mail->fromMail.length()-1) == '>')
217 mail->fromMail.truncate(mail->fromMail.length() - 1); 220 mail->fromMail.truncate(mail->fromMail.length() - 1);
218 mail->from=mail->fromMail; 221 mail->from=mail->fromMail;
219 } 222 }
220 mail->recipients.append (p.getString(&pos, 'z', TRUE) ); 223 mail->recipients.append (p.getString(&pos, 'z', TRUE) );
221 }*/ 224 }*/
222 } 225 }
223 // 226 //
224 //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); 227 //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") );
225 228
226 if ((pos = p.find("CC",':', 0, TRUE)) != -1) 229 if ((pos = p.find("CC",':', 0, TRUE)) != -1)
227 { 230 {
228 pos++; 231 pos++;
229 mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); 232 mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) );
230 } 233 }
231 234
232 if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { 235 if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) {
233 pos++; 236 pos++;
234 mail->subject = p.getString(&pos, 'z', TRUE); 237 mail->subject = p.getString(&pos, 'z', TRUE);
235 } 238 }
236 239
237 if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { 240 if ((pos = p.find("DATE",':', 0, TRUE)) != -1) {
238 pos++; 241 pos++;
239 mail->date = p.getString(&pos, 'z', TRUE); 242 mail->date = p.getString(&pos, 'z', TRUE);
240 } 243 }
241 244
242 245
243 246
244 if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { 247 if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) {
245 pos++; 248 pos++;
246 if ( (p.wordAt(pos).upper() == "ID") && 249 if ( (p.wordAt(pos).upper() == "ID") &&
247 (p.separatorAt(pos) == ':') ) { 250 (p.separatorAt(pos) == ':') ) {
248 251
249 id = p.getString(&pos, 'z', TRUE); 252 id = p.getString(&pos, 'z', TRUE);
250 mail->id = id; 253 mail->id = id;
251 } 254 }
252 } 255 }
253 256
254 pos = 0; 257 pos = 0;
255 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { 258 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) {
256 pos++; 259 pos++;
257 if ( (p.wordAt(pos).upper() == "VERSION") && 260 if ( (p.wordAt(pos).upper() == "VERSION") &&
258 (p.separatorAt(pos) == ':') ) { 261 (p.separatorAt(pos) == ':') ) {
259 pos++; 262 pos++;
260 if (p.getString(&pos, 'z', true) == "1.0") { 263 if (p.getString(&pos, 'z', true) == "1.0") {
261 mail->mimeType = 1; 264 mail->mimeType = 1;
262 } 265 }
263 } 266 }
264 } 267 }
265 268
266 if (mail->mimeType == 1) { 269 if (mail->mimeType == 1) {
267 boundary = ""; 270 boundary = "";
268 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { 271 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) {
269 pos++; 272 pos++;
270 boundary = p.getString(&pos, 'z', true); 273 boundary = p.getString(&pos, 'z', true);
271 if (boundary[0] == '"') { 274 if (boundary[0] == '"') {
272 boundary = boundary.left(boundary.length() - 1); //strip " 275 boundary = boundary.left(boundary.length() - 1); //strip "
273 boundary = boundary.right(boundary.length() - 1); //strip " 276 boundary = boundary.right(boundary.length() - 1); //strip "
274 } 277 }
275 boundary = "--" + boundary; //create boundary field 278 boundary = "--" + boundary; //create boundary field
276 } 279 }
277 280
278 if (boundary == "") { //fooled by Mime-Version 281 if (boundary == "") { //fooled by Mime-Version
279 mail->body = body; 282 mail->body = body;
280 mail->bodyPlain = body; 283 mail->bodyPlain = body;
281 return mail; 284 return mail;
282 } 285 }
283 286
284 while (body.length() > 0) { 287 while (body.length() > 0) {
285 pos = body.find(boundary, 0, FALSE); 288 pos = body.find(boundary, 0, FALSE);
286 pos = body.find(delimiter, pos, FALSE); 289 pos = body.find(delimiter, pos, FALSE);
287 mimeHeader = body.left(pos); 290 mimeHeader = body.left(pos);
288 mimeBody = body.right(body.length() - pos - delimiter.length()); 291 mimeBody = body.right(body.length() - pos - delimiter.length());
289 TextParser bp(mimeHeader, lineShift); 292 TextParser bp(mimeHeader, lineShift);
290 293
291 contentType = ""; 294 contentType = "";
292 contentAttribute = ""; 295 contentAttribute = "";
293 fileName = ""; 296 fileName = "";
294 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) { 297 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) {
295 pos++; 298 pos++;
296 if ( (bp.wordAt(pos).upper() == "TYPE") && 299 if ( (bp.wordAt(pos).upper() == "TYPE") &&
297 (bp.separatorAt(pos) == ':') ) { 300 (bp.separatorAt(pos) == ':') ) {
298 contentType = bp.nextWord().upper(); 301 contentType = bp.nextWord().upper();
299 if (bp.nextSeparator() == '/') 302 if (bp.nextSeparator() == '/')
300 contentAttribute = bp.nextWord().upper(); 303 contentAttribute = bp.nextWord().upper();
301 content = contentType + "/" + contentAttribute; 304 content = contentType + "/" + contentAttribute;
302 } 305 }
303 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) { 306 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) {
304 pos++; 307 pos++;
305 encoding = bp.getString(&pos, 'z', TRUE); 308 encoding = bp.getString(&pos, 'z', TRUE);
306 } 309 }
307 310
308 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) { 311 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) {
309 pos++; 312 pos++;
@@ -437,192 +440,193 @@ int EmailHandler::parse64base(char *src, char *bufOut) {
437 bufOut[2] = bufOut[2] | z; //third byte retrieved 440 bufOut[2] = bufOut[2] | z; //third byte retrieved
438 processed++; 441 processed++;
439 } 442 }
440 } 443 }
441 return processed; 444 return processed;
442} 445}
443 446
444int EmailHandler::encodeMime(Email *mail) 447int EmailHandler::encodeMime(Email *mail)
445{ 448{
446 449
447 QString fileName, fileType, contentType, newBody, boundary; 450 QString fileName, fileType, contentType, newBody, boundary;
448 Enclosure *ePtr; 451 Enclosure *ePtr;
449 452
450 QString userName = mailAccount.name; 453 QString userName = mailAccount.name;
451 if (userName.length()>0)//only embrace it if there is a user name 454 if (userName.length()>0)//only embrace it if there is a user name
452 userName += " <" + mailAccount.emailAddress + ">"; 455 userName += " <" + mailAccount.emailAddress + ">";
453 456
454 //add standard headers 457 //add standard headers
455 newBody = "From: " + userName + "\r\nTo: "; 458 newBody = "From: " + userName + "\r\nTo: ";
456 for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) { 459 for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) {
457 newBody += *it + " "; 460 newBody += *it + " ";
458 } 461 }
459 462
460 newBody += "\r\nCC: "; 463 newBody += "\r\nCC: ";
461 464
462 for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) { 465 for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) {
463 newBody += *it + " "; 466 newBody += *it + " ";
464 } 467 }
465 468
466 newBody += "\r\nSubject: " + mail->subject + "\r\n"; 469 newBody += "\r\nSubject: " + mail->subject + "\r\n";
467 470
468 if (mail->files.count() == 0) { //just a simple mail 471 if (mail->files.count() == 0) { //just a simple mail
469 newBody += "\r\n" + mail->body; 472 newBody += "\r\n" + mail->body;
470 mail->rawMail = newBody; 473 mail->rawMail = newBody;
471 return 0; 474 return 0;
472 } 475 }
473 476
474 //Build mime encoded mail 477 //Build mime encoded mail
475 boundary = "-----4345=next_bound=0495----"; 478 boundary = "-----4345=next_bound=0495----";
476 479
477 newBody += "Mime-Version: 1.0\r\n"; 480 newBody += "Mime-Version: 1.0\r\n";
478 newBody += "Content-Type: multipart/mixed; boundary=\"" + 481 newBody += "Content-Type: multipart/mixed; boundary=\"" +
479 boundary + "\"\r\n\r\n"; 482 boundary + "\"\r\n\r\n";
480 483
481 newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n"; 484 newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n";
482 newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n"; 485 newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n";
483 newBody += mail->body; 486 newBody += mail->body;
484 487
485 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 488 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
486 fileName = ePtr->originalName; 489 fileName = ePtr->originalName;
487 fileType = ePtr->contentType; 490 fileType = ePtr->contentType;
488 QFileInfo fi(fileName); 491 QFileInfo fi(fileName);
489 492
490 // This specification of contentType is temporary 493 // This specification of contentType is temporary
491 contentType = ""; 494 contentType = "";
492 if (fileType == "Picture") { 495 if (fileType == "Picture") {
493 contentType = "image/x-image"; 496 contentType = "image/x-image";
494 } else if (fileType == "Document") { 497 } else if (fileType == "Document") {
495 contentType = "text/plain"; 498 contentType = "text/plain";
496 } else if (fileType == "Sound") { 499 } else if (fileType == "Sound") {
497 contentType = "audio/x-wav"; 500 contentType = "audio/x-wav";
498 } else if (fileType == "Movie") { 501 } else if (fileType == "Movie") {
499 contentType = "video/mpeg"; 502 contentType = "video/mpeg";
500 } else { 503 } else {
501 contentType = "application/octet-stream"; 504 contentType = "application/octet-stream";
502 } 505 }
503 506
504 newBody += "\r\n\r\n--" + boundary + "\r\n"; 507 newBody += "\r\n\r\n--" + boundary + "\r\n";
505 newBody += "Content-Type: " + contentType + "; name=\"" + 508 newBody += "Content-Type: " + contentType + "; name=\"" +
506 fi.fileName() + "\"\r\n"; 509 fi.fileName() + "\"\r\n";
507 newBody += "Content-Transfer-Encoding: base64\r\n"; 510 newBody += "Content-Transfer-Encoding: base64\r\n";
508 newBody += "Content-Disposition: inline; filename=\"" + 511 newBody += "Content-Disposition: inline; filename=\"" +
509 fi.fileName() + "\"\r\n\r\n"; 512 fi.fileName() + "\"\r\n\r\n";
510 513
511 if (encodeFile(fileName, &newBody) == -1) //file not found? 514 if (encodeFile(fileName, &newBody) == -1) //file not found?
512 return -1; 515 return -1;
513 } 516 }
514 517
515 newBody += "\r\n\r\n--" + boundary + "--"; 518 newBody += "\r\n\r\n--" + boundary + "--";
516 mail->rawMail = newBody; 519 mail->rawMail = newBody;
517 520
518 return 0; 521 return 0;
519} 522}
520 523
521int EmailHandler::encodeFile(QString fileName, QString *toBody) 524int EmailHandler::encodeFile(QString fileName, QString *toBody)
522{ 525{
523 char *fileData; 526 char *fileData;
524 char *dataPtr; 527 char *dataPtr;
525 QString temp; 528 QString temp;
526 uint dataSize, count; 529 uint dataSize, count;
527 QFile f(fileName); 530 QFile f(fileName);
528 531
529 if (! f.open(IO_ReadOnly) ) { 532 if (! f.open(IO_ReadOnly) ) {
530 qWarning("could not open file: " + fileName); 533 qWarning("could not open file: " + fileName);
531 return -1; 534 return -1;
532 } 535 }
533 QTextStream s(&f); 536 QTextStream s(&f);
534 dataSize = f.size(); 537 dataSize = f.size();
535 fileData = (char *) malloc(dataSize + 3); 538 fileData = (char *) malloc(dataSize + 3);
536 s.readRawBytes(fileData, dataSize); 539 s.readRawBytes(fileData, dataSize);
537 540
538 temp = ""; 541 temp = "";
539 dataPtr = fileData; 542 dataPtr = fileData;
540 count = 0; 543 count = 0;
541 while (dataSize > 0) { 544 while (dataSize > 0) {
542 if (dataSize < 3) { 545 if (dataSize < 3) {
543 encode64base(dataPtr, &temp, dataSize); 546 encode64base(dataPtr, &temp, dataSize);
544 dataSize = 0; 547 dataSize = 0;
545 } else { 548 } else {
546 encode64base(dataPtr, &temp, 3); 549 encode64base(dataPtr, &temp, 3);
547 dataSize -= 3; 550 dataSize -= 3;
548 dataPtr += 3; 551 dataPtr += 3;
549 count += 4; 552 count += 4;
550 } 553 }
551 if (count > 72) { 554 if (count > 72) {
552 count = 0; 555 count = 0;
553 temp += "\r\n"; 556 temp += "\r\n";
554 } 557 }
555 } 558 }
556 toBody->append(temp); 559 toBody->append(temp);
557 560
558 delete(fileData); 561 delete(fileData);
559 f.close(); 562 f.close();
560 return 0; 563 return 0;
561} 564}
562 565
563void EmailHandler::encode64base(char *src, QString *dest, int len) 566void EmailHandler::encode64base(char *src, QString *dest, int len)
564{ 567{
565 QString temp; 568 QString temp;
566 uchar c; 569 uchar c;
567 uchar bufOut[4]; 570 uchar bufOut[4];
568 571
569 bufOut[0] = src[0]; 572 bufOut[0] = src[0];
570 bufOut[0] >>= 2; //Done byte 0 573 bufOut[0] >>= 2; //Done byte 0
571 574
572 bufOut[1] = src[0]; 575 bufOut[1] = src[0];
573 bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits 576 bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits
574 bufOut[1] <<= 4; //copy up 4 places 577 bufOut[1] <<= 4; //copy up 4 places
575 if (len > 1) { 578 if (len > 1) {
576 c = src[1]; 579 c = src[1];
577 } else { 580 } else {
578 c = 0; 581 c = 0;
579 } 582 }
580 583
581 c = c & (16 + 32 + 64 + 128); 584 c = c & (16 + 32 + 64 + 128);
582 c >>= 4; 585 c >>= 4;
583 bufOut[1] = bufOut[1] | c; //Done byte 1 586 bufOut[1] = bufOut[1] | c; //Done byte 1
584 587
585 bufOut[2] = src[1]; 588 bufOut[2] = src[1];
586 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8); 589 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8);
587 bufOut[2] <<= 2; 590 bufOut[2] <<= 2;
588 if (len > 2) { 591 if (len > 2) {
589 c = src[2]; 592 c = src[2];
590 } else { 593 } else {
591 c = 0; 594 c = 0;
592 } 595 }
593 c >>= 6; 596 c >>= 6;
594 bufOut[2] = bufOut[2] | c; 597 bufOut[2] = bufOut[2] | c;
595 598
596 bufOut[3] = src[2]; 599 bufOut[3] = src[2];
597 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32); 600 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32);
598 601
599 if (len == 1) { 602 if (len == 1) {
600 bufOut[2] = 64; 603 bufOut[2] = 64;
601 bufOut[3] = 64; 604 bufOut[3] = 64;
602 } 605 }
603 if (len == 2) { 606 if (len == 2) {
604 bufOut[3] = 64; 607 bufOut[3] = 64;
605 } 608 }
606 for (int x = 0; x < 4; x++) { 609 for (int x = 0; x < 4; x++) {
607 if (bufOut[x] <= 25) 610 if (bufOut[x] <= 25)
608 bufOut[x] += (uint) 'A'; 611 bufOut[x] += (uint) 'A';
609 else if (bufOut[x] >= 26 && bufOut[x] <= 51) 612 else if (bufOut[x] >= 26 && bufOut[x] <= 51)
610 bufOut[x] += (uint) 'a' - 26; 613 bufOut[x] += (uint) 'a' - 26;
611 else if (bufOut[x] >= 52 && bufOut[x] <= 61) 614 else if (bufOut[x] >= 52 && bufOut[x] <= 61)
612 bufOut[x] += (uint) '0' - 52; 615 bufOut[x] += (uint) '0' - 52;
613 else if (bufOut[x] == 62) 616 else if (bufOut[x] == 62)
614 bufOut[x] = '+'; 617 bufOut[x] = '+';
615 else if (bufOut[x] == 63) 618 else if (bufOut[x] == 63)
616 bufOut[x] = '/'; 619 bufOut[x] = '/';
617 else if (bufOut[x] == 64) 620 else if (bufOut[x] == 64)
618 bufOut[x] = '='; 621 bufOut[x] = '=';
619 622
620 dest->append(bufOut[x]); 623 dest->append(bufOut[x]);
621 } 624 }
622} 625}
623 626
624void EmailHandler::cancel() 627void EmailHandler::cancel()
625{ 628{
626 popClient->errorHandling(ErrCancel); 629 popClient->errorHandling(ErrCancel);
627 smtpClient->errorHandling(ErrCancel); 630 smtpClient->errorHandling(ErrCancel);
628} 631}
632
diff --git a/noncore/unsupported/mailit/emailhandler.h b/noncore/unsupported/mailit/emailhandler.h
index b645868..5b59f65 100644
--- a/noncore/unsupported/mailit/emailhandler.h
+++ b/noncore/unsupported/mailit/emailhandler.h
@@ -1,149 +1,150 @@
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#ifndef EmailHandler_H 20#ifndef EmailHandler_H
21#define EmailHandler_H 21#define EmailHandler_H
22 22
23#include <qobject.h> 23#include <qobject.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qdatetime.h> 25#include <qdatetime.h>
26#include <qlist.h> 26#include <qlist.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qfile.h> 28#include <qfile.h>
29#include <qstringlist.h> 29#include <qstringlist.h>
30#include <qcollection.h> 30#include <qcollection.h>
31#include <qpe/qcopenvelope_qws.h>
31 32
32#include "smtpclient.h" 33#include "smtpclient.h"
33#include "popclient.h" 34#include "popclient.h"
34#include "textparser.h" 35#include "textparser.h"
35#include "maillist.h" 36#include "maillist.h"
36 37
37struct Enclosure 38struct Enclosure
38{ 39{
39 int id; 40 int id;
40 QString originalName; 41 QString originalName;
41 QString name; 42 QString name;
42 QString path; 43 QString path;
43 QString contentType; 44 QString contentType;
44 QString contentAttribute; 45 QString contentAttribute;
45 QString encoding; 46 QString encoding;
46 QString body; //might use to much mem. check!! 47 QString body; //might use to much mem. check!!
47 bool saved, installed; 48 bool saved, installed;
48}; 49};
49 50
50class EnclosureList : public QList<Enclosure> 51class EnclosureList : public QList<Enclosure>
51{ 52{
52public: 53public:
53 Item newItem(Item d); 54 Item newItem(Item d);
54private: 55private:
55 Enclosure* dupl(Enclosure *in); 56 Enclosure* dupl(Enclosure *in);
56 Enclosure *ac; 57 Enclosure *ac;
57}; 58};
58 59
59struct Email 60struct Email
60{ 61{
61 QString id; 62 QString id;
62 QString from; 63 QString from;
63 QString fromMail; 64 QString fromMail;
64 QStringList recipients; 65 QStringList recipients;
65 QStringList carbonCopies; 66 QStringList carbonCopies;
66 QString date; 67 QString date;
67 QString subject; 68 QString subject;
68 QString body; 69 QString body;
69 QString bodyPlain; 70 QString bodyPlain;
70 bool sent, received, read, downloaded; 71 bool sent, received, read, downloaded;
71 QString rawMail; 72 QString rawMail;
72 int mimeType; //1 = Mime 1.0 73 int mimeType; //1 = Mime 1.0
73 int serverId; 74 int serverId;
74 int internalId; 75 int internalId;
75 int fromAccountId; 76 int fromAccountId;
76 QString contentType; //0 = text 77 QString contentType; //0 = text
77 QString contentAttribute; //0 = plain, 1 = html 78 QString contentAttribute; //0 = plain, 1 = html
78 EnclosureList files; 79 EnclosureList files;
79 uint size; 80 uint size;
80 81
81 void addEnclosure(Enclosure *e) 82 void addEnclosure(Enclosure *e)
82 { 83 {
83 files.append(e); 84 files.append(e);
84 } 85 }
85}; 86};
86 87
87struct MailAccount 88struct MailAccount
88{ 89{
89 QString accountName; 90 QString accountName;
90 QString name; 91 QString name;
91 QString emailAddress; 92 QString emailAddress;
92 QString popUserName; 93 QString popUserName;
93 QString popPasswd; 94 QString popPasswd;
94 QString popServer; 95 QString popServer;
95 QString smtpServer; 96 QString smtpServer;
96 bool synchronize; 97 bool synchronize;
97 int syncLimit; 98 int syncLimit;
98 int lastServerMailCount; 99 int lastServerMailCount;
99 int id; 100 int id;
100}; 101};
101 102
102 const int ErrUnknownResponse = 1001; 103 const int ErrUnknownResponse = 1001;
103 const int ErrLoginFailed = 1002; 104 const int ErrLoginFailed = 1002;
104 const int ErrCancel = 1003; 105 const int ErrCancel = 1003;
105 106
106 107
107class EmailHandler : public QObject 108class EmailHandler : public QObject
108{ 109{
109 Q_OBJECT 110 Q_OBJECT
110 111
111public: 112public:
112 EmailHandler(); 113 EmailHandler();
113 void setAccount(MailAccount account); 114 void setAccount(MailAccount account);
114 MailAccount* getAccount(){return &mailAccount;} 115 MailAccount* getAccount(){return &mailAccount;}
115 void sendMail(QList<Email> *mailList); 116 void sendMail(QList<Email> *mailList);
116 void getMail(); 117 void getMail();
117 void getMailHeaders(); 118 void getMailHeaders();
118 void getMailByList(MailList *mailList); 119 void getMailByList(MailList *mailList);
119 bool parse(QString in, QString lineShift, Email *mail); 120 bool parse(QString in, QString lineShift, Email *mail);
120 bool getEnclosure(Enclosure *ePtr); 121 bool getEnclosure(Enclosure *ePtr);
121 int parse64base(char *src, char *dest); 122 int parse64base(char *src, char *dest);
122 int encodeMime(Email *mail); 123 int encodeMime(Email *mail);
123 int encodeFile(QString fileName, QString *toBody); 124 int encodeFile(QString fileName, QString *toBody);
124 void encode64base(char *src, QString *dest, int len); 125 void encode64base(char *src, QString *dest, int len);
125 void cancel(); 126 void cancel();
126 127
127signals: 128signals:
128 void mailSent(); 129 void mailSent();
129 void smtpError(int); 130 void smtpError(int);
130 void popError(int); 131 void popError(int);
131 void mailArrived(const Email &, bool); 132 void mailArrived(const Email &, bool);
132 void updatePopStatus(const QString &); 133 void updatePopStatus(const QString &);
133 void updateSmtpStatus(const QString &); 134 void updateSmtpStatus(const QString &);
134 void mailTransfered(int); 135 void mailTransfered(int);
135 void mailboxSize(int); 136 void mailboxSize(int);
136 void currentMailSize(int); 137 void currentMailSize(int);
137 void downloadedSize(int); 138 void downloadedSize(int);
138 139
139public slots: 140public slots:
140 void messageArrived(const QString &, int id, uint size, bool complete); 141 void messageArrived(const QString &, int id, uint size, bool complete);
141 142
142private: 143private:
143 MailAccount mailAccount; 144 MailAccount mailAccount;
144 SmtpClient *smtpClient; 145 SmtpClient *smtpClient;
145 PopClient *popClient; 146 PopClient *popClient;
146 bool headers; 147 bool headers;
147}; 148};
148 149
149#endif 150#endif
diff --git a/noncore/unsupported/mailit/mailitwindow.cpp b/noncore/unsupported/mailit/mailitwindow.cpp
index ffee67e..a111241 100644
--- a/noncore/unsupported/mailit/mailitwindow.cpp
+++ b/noncore/unsupported/mailit/mailitwindow.cpp
@@ -1,165 +1,168 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qwhatsthis.h> 20#include <qwhatsthis.h>
21#include <qmessagebox.h> 21#include <qmessagebox.h>
22#include "mailitwindow.h" 22#include "mailitwindow.h"
23 23
24MailItWindow::MailItWindow(QWidget *parent, const char *name, WFlags fl) 24MailItWindow::MailItWindow(QWidget *parent, const char *name, WFlags fl)
25 : QMainWindow(parent, name, WStyle_ContextHelp) 25 : QMainWindow(parent, name, WStyle_ContextHelp)
26{ 26{
27 currentCaption = "Mailit"; 27 currentCaption = "Mailit";
28 setCaption(tr(currentCaption)); 28 setCaption(tr(currentCaption));
29 views = new QWidgetStack(this); 29 views = new QWidgetStack(this);
30 setCentralWidget(views); 30 setCentralWidget(views);
31 QWhatsThis::add(views,tr("Central view area")); 31 QWhatsThis::add(views,tr("Central view area"));
32 emailClient = new EmailClient(views, "client"); 32 emailClient = new EmailClient(views, "client");
33 writeMail = new WriteMail(views, "writing"); 33 writeMail = new WriteMail(views, "writing");
34 readMail = new ReadMail(views, "reading"); 34 readMail = new ReadMail(views, "reading");
35 35
36 views->raiseWidget(emailClient); 36 views->raiseWidget(emailClient);
37 37
38 connect(emailClient, SIGNAL(composeRequested()), 38 connect(emailClient, SIGNAL(composeRequested()),
39 this, SLOT(compose()) ); 39 this, SLOT(compose()) );
40 connect(emailClient, SIGNAL(viewEmail(QListView *, Email *)), this, 40 connect(emailClient, SIGNAL(viewEmail(QListView *, Email *)), this,
41 SLOT(viewMail(QListView *, Email *)) ); 41 SLOT(viewMail(QListView *, Email *)) );
42 connect(emailClient, SIGNAL(mailUpdated(Email *)), this, 42 connect(emailClient, SIGNAL(mailUpdated(Email *)), this,
43 SLOT(updateMailView(Email *)) ); 43 SLOT(updateMailView(Email *)) );
44 44
45 connect(writeMail, SIGNAL(cancelMail()), this, SLOT(showEmailClient()) ); 45 connect(writeMail, SIGNAL(cancelMail()), this, SLOT(showEmailClient()) );
46 connect(writeMail, SIGNAL(sendMailRequested(const Email &)), this, 46 connect(writeMail, SIGNAL(sendMailRequested(const Email &)), this,
47 SLOT(showEmailClient()) ); 47 SLOT(showEmailClient()) );
48 connect(writeMail, SIGNAL(sendMailRequested(const Email &)), emailClient, 48 connect(writeMail, SIGNAL(sendMailRequested(const Email &)), emailClient,
49 SLOT(enqueMail(const Email &)) ); 49 SLOT(enqueMail(const Email &)) );
50 50
51 connect(readMail, SIGNAL(cancelView()), this, SLOT(showEmailClient()) ); 51 connect(readMail, SIGNAL(cancelView()), this, SLOT(showEmailClient()) );
52 connect(readMail, SIGNAL(replyRequested(Email &, bool&)), this, 52 connect(readMail, SIGNAL(replyRequested(Email &, bool&)), this,
53 SLOT(composeReply(Email &, bool&)) ); 53 SLOT(composeReply(Email &, bool&)) );
54 connect(readMail, SIGNAL(forwardRequested(Email &)), this, 54 connect(readMail, SIGNAL(forwardRequested(Email &)), this,
55 SLOT(composeForward(Email &)) ); 55 SLOT(composeForward(Email &)) );
56 56
57 connect(readMail, SIGNAL(removeItem(EmailListItem *, bool &)), emailClient, 57 connect(readMail, SIGNAL(removeItem(EmailListItem *, bool &)), emailClient,
58 SLOT(deleteMail(EmailListItem *, bool &)) ); 58 SLOT(deleteMail(EmailListItem *, bool &)) );
59 connect(readMail, SIGNAL(viewingMail(Email *)), emailClient, 59 connect(readMail, SIGNAL(viewingMail(Email *)), emailClient,
60 SLOT(moveMailFront(Email *)) ); 60 SLOT(moveMailFront(Email *)) );
61 61
62 connect(emailClient, SIGNAL(newCaption(const QString &)), 62 connect(emailClient, SIGNAL(newCaption(const QString &)),
63 this, SLOT(updateCaption(const QString &)) ); 63 this, SLOT(updateCaption(const QString &)) );
64
65 connect(readMail, SIGNAL(download(Email *)), emailClient, SLOT(download(Email*)) );
66
64 viewingMail = FALSE; 67 viewingMail = FALSE;
65} 68}
66 69
67MailItWindow::~MailItWindow() 70MailItWindow::~MailItWindow()
68{ 71{
69} 72}
70 73
71void MailItWindow::closeEvent(QCloseEvent *e) 74void MailItWindow::closeEvent(QCloseEvent *e)
72{ 75{
73 if (views->visibleWidget() == emailClient) { 76 if (views->visibleWidget() == emailClient) {
74 e->accept(); 77 e->accept();
75 } else { 78 } else {
76 showEmailClient(); 79 showEmailClient();
77 } 80 }
78} 81}
79 82
80void MailItWindow::compose() 83void MailItWindow::compose()
81{ 84{
82 viewingMail = FALSE; 85 viewingMail = FALSE;
83 emailClient->hide(); 86 emailClient->hide();
84 readMail->hide(); 87 readMail->hide();
85 views->raiseWidget(writeMail); 88 views->raiseWidget(writeMail);
86 writeMail->setAddressList(emailClient->getAdrListRef()); 89 writeMail->setAddressList(emailClient->getAdrListRef());
87 writeMail->newMail(); 90 writeMail->newMail();
88 setCaption( tr( "Write mail" ) ); 91 setCaption( tr( "Write mail" ) );
89} 92}
90 93
91void MailItWindow::composeReply(Email &mail, bool& replyAll) 94void MailItWindow::composeReply(Email &mail, bool& replyAll)
92{ 95{
93 compose(); 96 compose();
94 writeMail->reply(mail,replyAll) ; 97 writeMail->reply(mail,replyAll) ;
95} 98}
96 99
97void MailItWindow::composeForward(Email &mail) 100void MailItWindow::composeForward(Email &mail)
98{ 101{
99 compose(); 102 compose();
100 writeMail->forward(mail) ; 103 writeMail->forward(mail) ;
101} 104}
102 105
103 106
104void MailItWindow::showEmailClient() 107void MailItWindow::showEmailClient()
105{ 108{
106 viewingMail = FALSE; 109 viewingMail = FALSE;
107 writeMail->hide(); 110 writeMail->hide();
108 readMail->hide(); 111 readMail->hide();
109 views->raiseWidget(emailClient); 112 views->raiseWidget(emailClient);
110 setCaption( tr(currentCaption) ); 113 setCaption( tr(currentCaption) );
111} 114}
112 115
113void MailItWindow::viewMail(QListView *view, Email *mail) 116void MailItWindow::viewMail(QListView *view, Email *mail)
114{ 117{
115 viewingMail = TRUE; 118 viewingMail = TRUE;
116 emailClient->hide(); 119 emailClient->hide();
117 120
118 int result=0; 121 int result=0;
119 122
120 if ((mail->received)&&(!mail->downloaded)) 123 if ((mail->received)&&(!mail->downloaded))
121 { 124 {
122 QMessageBox mb( tr("Mail not downloaded"), 125 QMessageBox mb( tr("Mail not downloaded"),
123 tr("The mail you have clicked \n" 126 tr("The mail you have clicked \n"
124 "has not been downloaded yet.\n " 127 "has not been downloaded yet.\n "
125 "Would you like to do it now ?"), 128 "Would you like to do it now ?"),
126 QMessageBox::Information, 129 QMessageBox::Information,
127 QMessageBox::Yes | QMessageBox::Default, 130 QMessageBox::Yes | QMessageBox::Default,
128 QMessageBox::No | QMessageBox::Escape,0 ); 131 QMessageBox::No | QMessageBox::Escape,0 );
129 132
130 result=mb.exec(); 133 result=mb.exec();
131 134
132 if (result==QMessageBox::Yes) 135 if (result==QMessageBox::Yes)
133 { 136 {
134 emailClient->download(mail); 137 emailClient->download(mail);
135 } 138 }
136 } 139 }
137 140
138 readMail->update(view, mail); 141 readMail->update(view, mail);
139 views->raiseWidget(readMail); 142 views->raiseWidget(readMail);
140 setCaption( tr( "Examine mail" ) ); 143 setCaption( tr( "Examine mail" ) );
141} 144}
142 145
143void MailItWindow::updateMailView(Email *mail) 146void MailItWindow::updateMailView(Email *mail)
144{ 147{
145 if (viewingMail) { 148 if (viewingMail) {
146 readMail->mailUpdated(mail); 149 readMail->mailUpdated(mail);
147 } 150 }
148} 151}
149 152
150void MailItWindow::updateCaption(const QString &newCaption) 153void MailItWindow::updateCaption(const QString &newCaption)
151{ 154{
152 currentCaption = newCaption; 155 currentCaption = newCaption;
153 setCaption(tr(currentCaption)); 156 setCaption(tr(currentCaption));
154} 157}
155 158
156void MailItWindow::setDocument(const QString &_address) 159void MailItWindow::setDocument(const QString &_address)
157{ 160{
158 // strip leading 'mailto:' 161 // strip leading 'mailto:'
159 QString address = _address; 162 QString address = _address;
160 if (address.startsWith("mailto:")) 163 if (address.startsWith("mailto:"))
161 address = address.mid(6); 164 address = address.mid(6);
162 165
163 compose(); 166 compose();
164 writeMail->setRecipient(address); 167 writeMail->setRecipient(address);
165} 168}
diff --git a/noncore/unsupported/mailit/popclient.cpp b/noncore/unsupported/mailit/popclient.cpp
index 6105d09..fedc4e2 100644
--- a/noncore/unsupported/mailit/popclient.cpp
+++ b/noncore/unsupported/mailit/popclient.cpp
@@ -1,325 +1,327 @@
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 "popclient.h" 20#include "popclient.h"
21#include "emailhandler.h" 21#include "emailhandler.h"
22//#define APOP_TEST 22//#define APOP_TEST
23 23
24extern "C" { 24extern "C" {
25#include "md5.h" 25#include "md5.h"
26} 26}
27 27
28#include <qcstring.h> 28#include <qcstring.h>
29 29
30PopClient::PopClient() 30PopClient::PopClient()
31{ 31{
32
32 socket = new QSocket(this, "popClient"); 33 socket = new QSocket(this, "popClient");
33 connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); 34 connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int)));
34 connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); 35 connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished()));
35 connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); 36 connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData()));
36 37
37 stream = new QTextStream(socket); 38 stream = new QTextStream(socket);
38 39
39 receiving = FALSE; 40 receiving = FALSE;
40 synchronize = FALSE; 41 synchronize = FALSE;
41 lastSync = 0; 42 lastSync = 0;
42 headerLimit = 0; 43 headerLimit = 0;
43 preview = FALSE; 44 preview = FALSE;
44} 45}
45 46
46PopClient::~PopClient() 47PopClient::~PopClient()
47{ 48{
48 delete socket; 49 delete socket;
49 delete stream; 50 delete stream;
50} 51}
51 52
52void PopClient::newConnection(QString target, int port) 53void PopClient::newConnection(QString target, int port)
53{ 54{
54 if (receiving) { 55 if (receiving) {
55 qWarning("socket in use, connection refused"); 56 qWarning("socket in use, connection refused");
56 return; 57 return;
57 } 58 }
58 59
59 status = Init; 60 status = Init;
60 61
61 socket->connectToHost(target, port); 62 socket->connectToHost(target, port);
62 receiving = TRUE; 63 receiving = TRUE;
63 //selected = FALSE; 64 //selected = FALSE;
64 65
65 emit updateStatus("DNS lookup"); 66 emit updateStatus("DNS lookup");
66} 67}
67 68
68void PopClient::setAccount(QString popUser, QString popPasswd) 69void PopClient::setAccount(QString popUser, QString popPasswd)
69{ 70{
70 popUserName = popUser; 71 popUserName = popUser;
71 popPassword = popPasswd; 72 popPassword = popPasswd;
72} 73}
73 74
74void PopClient::setSynchronize(int lastCount) 75void PopClient::setSynchronize(int lastCount)
75{ 76{
76 synchronize = TRUE; 77 synchronize = TRUE;
77 lastSync = lastCount; 78 lastSync = lastCount;
78} 79}
79 80
80void PopClient::removeSynchronize() 81void PopClient::removeSynchronize()
81{ 82{
82 synchronize = FALSE; 83 synchronize = FALSE;
83 lastSync = 0; 84 lastSync = 0;
84} 85}
85 86
86void PopClient::headersOnly(bool headers, int limit) 87void PopClient::headersOnly(bool headers, int limit)
87{ 88{
88 preview = headers; 89 preview = headers;
89 headerLimit = limit; 90 headerLimit = limit;
90} 91}
91 92
92void PopClient::setSelectedMails(MailList *list) 93void PopClient::setSelectedMails(MailList *list)
93{ 94{
94 selected = TRUE; 95 selected = TRUE;
95 mailList = list; 96 mailList = list;
96} 97}
97 98
98void PopClient::connectionEstablished() 99void PopClient::connectionEstablished()
99{ 100{
100 emit updateStatus(tr("Connection established")); 101 emit updateStatus(tr("Connection established"));
101} 102}
102 103
103void PopClient::errorHandling(int status) 104void PopClient::errorHandling(int status)
104{ 105{
105 emit updateStatus(tr("Error Occured")); 106 emit updateStatus(tr("Error Occured"));
106 emit errorOccurred(status); 107 emit errorOccurred(status);
107 socket->close(); 108 socket->close();
108 receiving = FALSE; 109 receiving = FALSE;
109} 110}
110 111
111void PopClient::incomingData() 112void PopClient::incomingData()
112{ 113{
113 QString response, temp, temp2, timeStamp; 114 QString response, temp, temp2, timeStamp;
114 QString md5Source; 115 QString md5Source;
115 int start, end; 116 int start, end;
116// char *md5Digest; 117// char *md5Digest;
117 char md5Digest[16]; 118 char md5Digest[16];
118// if ( !socket->canReadLine() ) 119// if ( !socket->canReadLine() )
119// return; 120// return;
121
120 122
121 response = socket->readLine(); 123 response = socket->readLine();
122 124
123 switch(status) { 125 switch(status) {
124 //logging in 126 //logging in
125 case Init: { 127 case Init: {
126#ifdef APOP_TEST 128#ifdef APOP_TEST
127 start = response.find('<',0); 129 start = response.find('<',0);
128 end = response.find('>', start); 130 end = response.find('>', start);
129 if( start >= 0 && end > start ) 131 if( start >= 0 && end > start )
130 { 132 {
131 timeStamp = response.mid( start , end - start + 1); 133 timeStamp = response.mid( start , end - start + 1);
132 md5Source = timeStamp + popPassword; 134 md5Source = timeStamp + popPassword;
133 135
134 md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); 136 md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]);
135 137
136 for(int j =0;j < MD5_DIGEST_LENGTH ;j++) 138 for(int j =0;j < MD5_DIGEST_LENGTH ;j++)
137 { 139 {
138 printf("%x", md5Digest[j]); 140 printf("%x", md5Digest[j]);
139 } 141 }
140 printf("\n"); 142 printf("\n");
141// qDebug(md5Digest); 143// qDebug(md5Digest);
142 *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; 144 *stream << "APOP " << popUserName << " " << md5Digest << "\r\n";
143 // qDebug("%s", stream); 145 // qDebug("%s", stream);
144 status = Stat; 146 status = Stat;
145 } 147 }
146 else 148 else
147#endif 149#endif
148 { 150 {
149 timeStamp = ""; 151 timeStamp = "";
150 *stream << "USER " << popUserName << "\r\n"; 152 *stream << "USER " << popUserName << "\r\n";
151 status = Pass; 153 status = Pass;
152 } 154 }
153 155
154 break; 156 break;
155 } 157 }
156 158
157 case Pass: { 159 case Pass: {
158 *stream << "PASS " << popPassword << "\r\n"; 160 *stream << "PASS " << popPassword << "\r\n";
159 status = Stat; 161 status = Stat;
162
160 break; 163 break;
161 } 164 }
162 //ask for number of messages 165 //ask for number of messages
163 case Stat: { 166 case Stat: {
164 if (response[0] == '+') { 167 if (response[0] == '+') {
165 *stream << "STAT" << "\r\n"; 168 *stream << "STAT" << "\r\n";
166 status = Mcnt; 169 status = Mcnt;
167 } else errorHandling(ErrLoginFailed); 170 } else errorHandling(ErrLoginFailed);
168 break; 171 break;
169 } 172 }
170 //get count of messages, eg "+OK 4 900.." -> int 4 173 //get count of messages, eg "+OK 4 900.." -> int 4
171 case Mcnt: { 174 case Mcnt: {
172 if (response[0] == '+') { 175 if (response[0] == '+') {
173 temp = response.replace(0, 4, ""); 176 temp = response.replace(0, 4, "");
174 int x = temp.find(" ", 0); 177 int x = temp.find(" ", 0);
175 temp.truncate((uint) x); 178 temp.truncate((uint) x);
176 newMessages = temp.toInt(); 179 newMessages = temp.toInt();
177 messageCount = 1; 180 messageCount = 1;
178 status = List; 181 status = List;
179 182
180 if (synchronize) { 183 if (synchronize) {
181 //messages deleted from server, reload all 184 //messages deleted from server, reload all
182 if (newMessages < lastSync) 185 if (newMessages < lastSync)
183 lastSync = 0; 186 lastSync = 0;
184 messageCount = 1; 187 messageCount = 1;
185 } 188 }
186 189
187 if (selected) { 190 if (selected) {
188 int *ptr = mailList->first(); 191 int *ptr = mailList->first();
189 if (ptr != 0) { 192 if (ptr != 0) {
190 newMessages++; //to ensure no early jumpout 193 newMessages++; //to ensure no early jumpout
191 messageCount = *ptr; 194 messageCount = *ptr;
192 } else newMessages = 0; 195 } else newMessages = 0;
193 } 196 }
194 197
195 } else errorHandling(ErrUnknownResponse); 198 } else errorHandling(ErrUnknownResponse);
196 } 199 }
197 //Read message number x, count upwards to messageCount 200 //Read message number x, count upwards to messageCount
198 case List: { 201 case List: {
199 if (messageCount <= newMessages) { 202 if (messageCount <= newMessages) {
200 *stream << "LIST " << messageCount << "\r\n"; 203 *stream << "LIST " << messageCount << "\r\n";
201 status = Size; 204 status = Size;
202 temp2.setNum(newMessages - lastSync); 205 temp2.setNum(newMessages - lastSync);
203 temp.setNum(messageCount - lastSync); 206 temp.setNum(messageCount - lastSync);
204 if (!selected) { 207 if (!selected) {
205 emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); 208 emit updateStatus(tr("Retrieving ") + temp + "/" + temp2);
206 } else { 209 } else {
207 //completing a previously closed transfer 210 //completing a previously closed transfer
208 /* if ( (messageCount - lastSync) <= 0) { 211 /* if ( (messageCount - lastSync) <= 0) {
209 temp.setNum(messageCount); 212 temp.setNum(messageCount);
210 emit updateStatus(tr("Previous message ") + temp); 213 emit updateStatus(tr("Previous message ") + temp);
211 } else {*/ 214 } else {*/
212 emit updateStatus(tr("Completing message ") + temp); 215 emit updateStatus(tr("Completing message ") + temp);
213 //} 216 //}
214 } 217 }
215 break; 218 break;
216 } else { 219 } else {
217 emit updateStatus(tr("No new Messages")); 220 emit updateStatus(tr("No new Messages"));
218 status = Quit; 221 status = Quit;
219 } 222 }
220 } 223 }
221 //get size of message, eg "500 characters in message.." -> int 500 224 //get size of message, eg "500 characters in message.." -> int 500
222 case Size: { 225 case Size: {
223 if (status != Quit) { //because of idiotic switch 226 if (status != Quit) { //because of idiotic switch
224 if (response[0] == '+') { 227 if (response[0] == '+') {
225 temp = response.replace(0, 4, ""); 228 temp = response.replace(0, 4, "");
226 int x = temp.find(" ", 0); 229 int x = temp.find(" ", 0);
227 temp = temp.right(temp.length() - ((uint) x + 1) ); 230 temp = temp.right(temp.length() - ((uint) x + 1) );
228 mailSize = temp.toInt(); 231 mailSize = temp.toInt();
229 emit currentMailSize(mailSize); 232 emit currentMailSize(mailSize);
230 233
231 status = Retr; 234 status = Retr;
232 } else { 235 } else {
233 //qWarning(response); 236 //qWarning(response);
234 errorHandling(ErrUnknownResponse); 237 errorHandling(ErrUnknownResponse);
235 } 238 }
236 } 239 }
237 } 240 }
238 //Read message number x, count upwards to messageCount 241 //Read message number x, count upwards to messageCount
239 case Retr: { 242 case Retr: {
240 if (status != Quit) { 243 if (status != Quit) {
241 if ((selected)||(mailSize <= headerLimit)) 244 if ((selected)||(mailSize <= headerLimit))
242 { 245 {
243 *stream << "RETR " << messageCount << "\r\n"; 246 *stream << "RETR " << messageCount << "\r\n";
244 } else { //only header 247 } else { //only header
245 *stream << "TOP " << messageCount << " 0\r\n"; 248 *stream << "TOP " << messageCount << " 0\r\n";
246 } 249 }
247 messageCount++; 250 messageCount++;
248 status = Ignore; 251 status = Ignore;
249 break; 252 break;
250 } } 253 } }
251 case Ignore: { 254 case Ignore: {
252 if (status != Quit) { //because of idiotic switch 255 if (status != Quit) { //because of idiotic switch
253 if (response[0] == '+') { 256 if (response[0] == '+') {
254 message = ""; 257 message = "";
255 status = Read; 258 status = Read;
256 if (!socket->canReadLine()) //sync. problems 259 if (!socket->canReadLine()) //sync. problems
257 break; 260 break;
258 response = socket->readLine(); 261 response = socket->readLine();
259 } else errorHandling(ErrUnknownResponse); 262 } else errorHandling(ErrUnknownResponse);
260 } 263 }
261 } 264 }
262 //add all incoming lines to body. When size is reached, send 265 //add all incoming lines to body. When size is reached, send
263 //message, and go back to read new message 266 //message, and go back to read new message
264 case Read: { 267 case Read: {
265 if (status != Quit) { //because of idiotic switch 268 if (status != Quit) { //because of idiotic switch
266 message += response; 269 message += response;
267 while ( socket->canReadLine() ) { 270 while ( socket->canReadLine() ) {
268 response = socket->readLine(); 271 response = socket->readLine();
269 message += response; 272 message += response;
270 } 273 }
271 emit downloadedSize(message.length()); 274 emit downloadedSize(message.length());
272 int x = message.find("\r\n.\r\n",-5); 275 int x = message.find("\r\n.\r\n",-5);
273 if (x == -1) { 276 if (x == -1) {
274 break; 277 break;
275 } else { //message reach entire size 278 } else { //message reach entire size
276
277 if ( (selected)||(mailSize <= headerLimit)) //mail size limit is not used if late download is active 279 if ( (selected)||(mailSize <= headerLimit)) //mail size limit is not used if late download is active
278 { 280 {
279 emit newMessage(message, messageCount-1, mailSize, TRUE); 281 emit newMessage(message, messageCount-1, mailSize, TRUE);
280 } else { //incomplete mail downloaded 282 } else { //incomplete mail downloaded
281 emit newMessage(message, messageCount-1, mailSize, FALSE); 283 emit newMessage(message, messageCount-1, mailSize, FALSE);
282 } 284 }
283 285
284 if ((messageCount > newMessages)||(selected)) //last message ? 286 if ((messageCount > newMessages)||(selected)) //last message ?
285 { 287 {
286 status = Quit; 288 status = Quit;
287 if (selected) { //grab next from queue 289 if (selected) { //grab next from queue
288 newMessages--; 290 newMessages--;
289 status = Quit; 291 status = Quit;
290 } 292 }
291 } 293 }
292 else 294 else
293 { 295 {
294 *stream << "LIST " << messageCount << "\r\n"; 296 *stream << "LIST " << messageCount << "\r\n";
295 status = Size; 297 status = Size;
296 temp2.setNum(newMessages - lastSync); 298 temp2.setNum(newMessages - lastSync);
297 temp.setNum(messageCount - lastSync); 299 temp.setNum(messageCount - lastSync);
298 emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); 300 emit updateStatus(tr("Retrieving ") + temp + "/" + temp2);
299 301
300 break; 302 break;
301 } 303 }
302 } 304 }
303 } 305 }
304 if (status != Quit) 306 if (status != Quit)
305 break; 307 break;
306 } 308 }
307 case Quit: { 309 case Quit: {
308 *stream << "Quit\r\n"; 310 *stream << "Quit\r\n";
309 status = Done; 311 status = Done;
310 int newM = newMessages - lastSync; 312 int newM = newMessages - lastSync;
311 if (newM > 0) { 313 if (newM > 0) {
312 temp.setNum(newM); 314 temp.setNum(newM);
313 emit updateStatus(temp + tr(" new messages")); 315 emit updateStatus(temp + tr(" new messages"));
314 } else { 316 } else {
315 emit updateStatus(tr("No new messages")); 317 emit updateStatus(tr("No new messages"));
316 } 318 }
317 319
318 socket->close(); 320 socket->close();
319 receiving = FALSE; 321 receiving = FALSE;
320 emit mailTransfered(newM); 322 emit mailTransfered(newM);
321 break; 323 break;
322 } 324 }
323 } 325 }
324 326
325} 327}
diff --git a/noncore/unsupported/mailit/readmail.cpp b/noncore/unsupported/mailit/readmail.cpp
index 4eae7f6..1682675 100644
--- a/noncore/unsupported/mailit/readmail.cpp
+++ b/noncore/unsupported/mailit/readmail.cpp
@@ -1,367 +1,399 @@
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 "readmail.h" 20#include "readmail.h"
21#include <qimage.h> 21#include <qimage.h>
22#include <qwhatsthis.h>
22#include <qmime.h> 23#include <qmime.h>
23#include <qaction.h> 24#include <qaction.h>
25#include <qpopupmenu.h>
24#include <qpe/resource.h> 26#include <qpe/resource.h>
25 27
26ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl ) 28ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl )
27 : QMainWindow(parent, name, fl) 29 : QMainWindow(parent, name, fl)
28{ 30{
29 plainTxt = FALSE; 31 plainTxt = FALSE;
30 32
31 init(); 33 init();
32 viewAtt = new ViewAtt(0, "View Attatchments"); 34 viewAtt = new ViewAtt(0, "View Attatchments");
33} 35}
34 36
35ReadMail::~ReadMail() 37ReadMail::~ReadMail()
36{ 38{
37 delete emailView->mimeSourceFactory(); 39 delete emailView->mimeSourceFactory();
38 delete viewAtt; 40 delete viewAtt;
39} 41}
40 42
41void ReadMail::init() 43void ReadMail::init()
42{ 44{
43 setToolBarsMovable(FALSE); 45 setToolBarsMovable(FALSE);
44 46
47 QPopupMenu* mailaction=new QPopupMenu(this);
48
45 bar = new QToolBar(this); 49 bar = new QToolBar(this);
46 bar->setHorizontalStretchable( TRUE ); 50 bar->setHorizontalStretchable( TRUE );
47 51
48 menu = new QMenuBar( bar ); 52 menu = new QMenuBar( bar );
49 53
50 viewMenu = new QPopupMenu(menu); 54 viewMenu = new QPopupMenu(menu);
51 menu->insertItem( tr( "&View" ), viewMenu); 55 menu->insertItem( tr( "&View" ), viewMenu);
52 56
53 mailMenu = new QPopupMenu(menu); 57 mailMenu = new QPopupMenu(menu);
54 menu->insertItem( tr( "&Mail" ), mailMenu); 58 menu->insertItem( tr( "&Mail" ), mailMenu);
55 59
56 bar = new QToolBar(this); 60 bar = new QToolBar(this);
57 61
58 //reply dependant on viewing inbox 62 downloadButton = new QAction( tr( "Download" ), Resource::loadPixmap( "mailit/download" ),QString::null, 0, this, 0 );
59 replyButton = new QAction( tr( "Reply" ), Resource::loadPixmap( "mailit/reply" ), 63 connect(downloadButton, SIGNAL(activated()), this, SLOT(download()) );
60 QString::null, 0, this, 0 ); 64 downloadButton->setWhatsThis(tr("Click here to download the selected mail"));
61 connect(replyButton, SIGNAL(activated()), this, SLOT(reply()) );
62 replyButton->setWhatsThis(tr("Click here to reply to the selected mail"));
63
64 forwardButton = new QAction( tr( "Forward" ), Resource::loadPixmap( "mailit/forward" ),
65 QString::null, 0, this, 0 );
66 connect(forwardButton, SIGNAL(activated()), this, SLOT(forward()) );
67 forwardButton->setWhatsThis(tr("Click here to forward the selected mail"));
68 65
66
69 previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); 67 previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 );
70 connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) ); 68 connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) );
71 previousButton->addTo(bar); 69 previousButton->addTo(bar);
72 previousButton->addTo(viewMenu); 70 previousButton->addTo(viewMenu);
73 previousButton->setWhatsThis(tr("Read the previous mail in the list")); 71 previousButton->setWhatsThis(tr("Read the previous mail in the list"));
74 72
75 nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 ); 73 nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 );
76 connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) ); 74 connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) );
77 nextButton->addTo(bar); 75 nextButton->addTo(bar);
78 nextButton->addTo(viewMenu); 76 nextButton->addTo(viewMenu);
79 previousButton->setWhatsThis(tr("Read the next mail in the list")); 77 previousButton->setWhatsThis(tr("Read the next mail in the list"));
80 78
81 attachmentButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "mailit/attach" ), QString::null, 0, this, 0 ); 79 attachmentButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "mailit/attach" ), QString::null, 0, this, 0 );
82 connect( attachmentButton, SIGNAL( activated() ), this, 80 connect( attachmentButton, SIGNAL( activated() ), this,
83 SLOT( viewAttachments() ) ); 81 SLOT( viewAttachments() ) );
84 attachmentButton->addTo(bar); 82 attachmentButton->addTo(bar);
85 attachmentButton->addTo(viewMenu); 83 attachmentButton->addTo(viewMenu);
86 attachmentButton->setWhatsThis(tr("Click here to add attachments to your mail")); 84 attachmentButton->setWhatsThis(tr("Click here to add attachments to your mail"));
87 85
88 plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "DocsIcon" ), QString::null, 0, this, 0, TRUE); 86 plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "DocsIcon" ), QString::null, 0, this, 0, TRUE);
89 connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) ); 87 connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) );
90 plainTextButton->addTo(bar); 88 plainTextButton->addTo(bar);
91 plainTextButton->addTo(viewMenu); 89 plainTextButton->addTo(viewMenu);
92 plainTextButton->setWhatsThis(tr("The mail view has 2 modes:\n" 90 plainTextButton->setWhatsThis(tr("The mail view has 2 modes:\n"
93 "<LI><B>RichText</B> shows the mail as HTML with reach features (no standard line breaks)</LI>" 91 "<LI><B>RichText</B> shows the mail as HTML with reach features (no standard line breaks)</LI>"
94 "<LI><B>Plain</B> shows the mail as standard plain text</LI>" 92 "<LI><B>Plain</B> shows the mail as standard plain text</LI>"
95 "Click here to switch between those view modes" )); 93 "Click here to switch between those view modes" ));
96 94
95 //reply dependant on viewing inbox
96 replyButton = new QToolButton(Resource::loadPixmap("mailit/reply"),tr("reply"),tr("reply to mail"), this,SLOT(reply()),bar);
97 QWhatsThis::add(replyButton,tr("Click here to reply to the selected mail\nPress and hold for more options."));
98 replyButton->setPopup(mailaction);
99
100 replyAllButton = new QAction( tr( "Reply all" ), Resource::loadPixmap( "mailit/reply" ),QString::null, 0, this, 0 );
101 connect(replyAllButton, SIGNAL(activated()), this, SLOT(replyAll()));
102 replyAllButton->setWhatsThis(tr("Click here to reply to the selected mail to CC: addresses also"));
103 replyAllButton->addTo(mailaction);
104
105 forwardButton = new QAction( tr( "Forward" ), Resource::loadPixmap( "mailit/forward" ),
106 QString::null, 0, this, 0 );
107 connect(forwardButton, SIGNAL(activated()), this, SLOT(forward()));
108 forwardButton->setWhatsThis(tr("Click here to forward the selected mail"));
109 forwardButton->addTo(mailaction);
110
111
97 deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); 112 deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 );
98 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); 113 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) );
99 deleteButton->addTo(bar); 114 deleteButton->addTo(bar);
100 deleteButton->addTo(mailMenu); 115 deleteButton->addTo(mailMenu);
101 deleteButton->setWhatsThis(tr("Click here to remove the selected mail")); 116 deleteButton->setWhatsThis(tr("Click here to remove the selected mail"));
102 117
103 viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close())); 118 viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close()));
104 119
105 emailView = new QTextView( this, "emailView" ); 120 emailView = new QTextView( this, "emailView" );
106 121
107 setCentralWidget(emailView); 122 setCentralWidget(emailView);
108 123
109 mime = new QMimeSourceFactory(); 124 mime = new QMimeSourceFactory();
110 emailView->setMimeSourceFactory(mime); 125 emailView->setMimeSourceFactory(mime);
111} 126}
112 127
113void ReadMail::updateView() 128void ReadMail::updateView()
114{ 129{
115 Enclosure *ePtr; 130 Enclosure *ePtr;
116 QString mailStringSize; 131 QString mailStringSize;
117 QString text, temp; 132 QString text, temp;
118 133
119 mail->read = TRUE; //mark as read 134 mail->read = TRUE; //mark as read
120 inbox = mail->received; 135 inbox = mail->received;
121 136
122 replyButton->removeFrom(mailMenu); 137 replyButton->setEnabled(false);
123 replyButton->removeFrom(bar); 138 /*replyButton->removeFrom(bar);
124 forwardButton->removeFrom(mailMenu); 139 forwardButton->removeFrom(mailMenu);
125 forwardButton->removeFrom(bar); 140 forwardButton->removeFrom(bar);*/
141 downloadButton->removeFrom(bar);
142
143 //downloadButton->setEnabled(!mail->downloaded);
126 144
145
127 if (inbox == TRUE) { 146 if (inbox == TRUE) {
128 replyButton->addTo(bar); 147 replyButton->setEnabled(true);
129 replyButton->addTo(mailMenu); 148 /*replyButton->addTo(mailMenu);
130 forwardButton->addTo(bar); 149 forwardButton->addTo(bar);
131 forwardButton->addTo(mailMenu); 150 forwardButton->addTo(mailMenu);*/
132 151
133 152
134 if (!mail->downloaded) { 153 if (!mail->downloaded) {
154
155 downloadButton->addTo(bar);
156
135 //report currently viewed mail so that it will be 157 //report currently viewed mail so that it will be
136 //placed first in the queue of new mails to download 158 //placed first in the queue of new mails to download
137 emit viewingMail(mail); 159 emit viewingMail(mail);
138 160
139 double mailSize = (double) mail->size; 161 double mailSize = (double) mail->size;
140 if (mailSize < 1024) { 162 if (mailSize < 1024) {
141 mailStringSize.setNum(mailSize); 163 mailStringSize.setNum(mailSize);
142 mailStringSize += " Bytes"; 164 mailStringSize += " Bytes";
143 } else if (mailSize < 1024*1024) { 165 } else if (mailSize < 1024*1024) {
144 mailStringSize.setNum( (mailSize / 1024), 'g', 2 ); 166 mailStringSize.setNum( (mailSize / 1024), 'g', 2 );
145 mailStringSize += " Kb"; 167 mailStringSize += " Kb";
146 } else { 168 } else {
147 mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3); 169 mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3);
148 mailStringSize += " Mb"; 170 mailStringSize += " Mb";
149 } 171 }
150 } 172 }
151 } 173 }
152 174
153 QMimeSourceFactory *mime = emailView->mimeSourceFactory(); 175 QMimeSourceFactory *mime = emailView->mimeSourceFactory();
154 176
155 if (! plainTxt) { //use RichText, inline pics etc. 177 if (! plainTxt) { //use RichText, inline pics etc.
156 emailView->setTextFormat(QTextView::RichText); 178 emailView->setTextFormat(QTextView::RichText);
157 text = "<b><big><center><font color=\"blue\">" + mail->subject 179 text = "<b><big><center><font color=\"blue\">" + mail->subject
158 +"</font></center></big></b><br>"; 180 +"</font></center></big></b><br>";
159 text += "<b>From: </b>" + mail->from + " <i>" + 181 text += "<b>From: </b>" + mail->from + " <i>" +
160 mail->fromMail + "</i><br>"; 182 mail->fromMail + "</i><br>";
161 183
162 text +="<b>To: </b>"; 184 text +="<b>To: </b>";
163 for (QStringList::Iterator it = mail->recipients.begin(); 185 for (QStringList::Iterator it = mail->recipients.begin();
164 it != mail->recipients.end(); ++it ) { 186 it != mail->recipients.end(); ++it ) {
165 text += *it + " "; 187 text += *it + " ";
166 } 188 }
167 189
168 text +="<br><b>CC: </b>"; 190 text +="<br><b>CC: </b>";
169 for (QStringList::Iterator it = mail->carbonCopies.begin(); 191 for (QStringList::Iterator it = mail->carbonCopies.begin();
170 it != mail->carbonCopies.end(); ++it ) { 192 it != mail->carbonCopies.end(); ++it ) {
171 text += *it + " "; 193 text += *it + " ";
172 } 194 }
173 195
174 text += "<br>" + mail->date; 196 text += "<br>" + mail->date;
175 197
176 if (mail->files.count() > 0) { 198 if (mail->files.count() > 0) {
177 text += "<br><b>Attatchments: </b>"; 199 text += "<br><b>Attatchments: </b>";
178 200
179 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 201 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
180 text += ePtr->originalName + " "; 202 text += ePtr->originalName + " ";
181 } 203 }
182 text += "<hr><br>" + mail->body; 204 text += "<hr><br>" + mail->body;
183 205
184 if (inbox) { 206 if (inbox) {
185 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 207 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
186 208
187 text += "<br><hr><b>Attatchment: </b>" + 209 text += "<br><hr><b>Attatchment: </b>" +
188 ePtr->originalName + "<hr>"; 210 ePtr->originalName + "<hr>";
189 211
190 if (ePtr->contentType == "TEXT") { 212 if (ePtr->contentType == "TEXT") {
191 QFile f(ePtr->path + ePtr->name); 213 QFile f(ePtr->path + ePtr->name);
192 214
193 if (f.open(IO_ReadOnly) ) { 215 if (f.open(IO_ReadOnly) ) {
194 QTextStream t(&f); 216 QTextStream t(&f);
195 temp = t.read(); 217 temp = t.read();
196 text += temp + "<br>"; 218 text += temp + "<br>";
197 f.close(); 219 f.close();
198 } else { 220 } else {
199 text += "<b>Could not locate file</b><br>"; 221 text += "<b>Could not locate file</b><br>";
200 } 222 }
201 223
202 } 224 }
203 if (ePtr->contentType == "IMAGE") { 225 if (ePtr->contentType == "IMAGE") {
204 // temp.setNum(emailView->width());//get display width 226 // temp.setNum(emailView->width());//get display width
205 // text += "<img width=" + temp +" src =""" + 227 // text += "<img width=" + temp +" src =""" +
206 // ePtr->originalName + """> </img>"; 228 // ePtr->originalName + """> </img>";
207 text += "<img src =""" + 229 text += "<img src =""" +
208 ePtr->originalName + """> </img>"; 230 ePtr->originalName + """> </img>";
209 mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) )); 231 mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) ));
210 } 232 }
211 } 233 }
212 } 234 }
213 } else { 235 } else {
214 if (mail->downloaded || !inbox) { 236 if (mail->downloaded || !inbox) {
215 text += "<hr><br>" + mail->body; 237 text += "<hr><br>" + mail->body;
216 } else { 238 } else {
217 text += "<hr><br><b> Awaiting download </b><br>"; 239 text += "<hr><br><b> Awaiting download </b><br>";
218 text += "Size of mail: " + mailStringSize; 240 text += "Size of mail: " + mailStringSize;
219 } 241 }
220 } 242 }
221 emailView->setText(text); 243 emailView->setText(text);
222 } else { // show plain txt mail 244 } else { // show plain txt mail
223 emailView->setTextFormat(QTextView::PlainText); 245 emailView->setTextFormat(QTextView::PlainText);
224 text = "Subject: " + mail->subject + "\n"; 246 text = "Subject: " + mail->subject + "\n";
225 text += "From: " + mail->from + " " + mail->fromMail + "\n"; 247 text += "From: " + mail->from + " " + mail->fromMail + "\n";
226 text += "To: "; 248 text += "To: ";
227 for (QStringList::Iterator it = mail->recipients.begin(); 249 for (QStringList::Iterator it = mail->recipients.begin();
228 it != mail->recipients.end(); ++it ) { 250 it != mail->recipients.end(); ++it ) {
229 text += *it + " "; 251 text += *it + " ";
230 } 252 }
231 253
232 text += "\nCC: "; 254 text += "\nCC: ";
233 for (QStringList::Iterator it = mail->carbonCopies.begin(); 255 for (QStringList::Iterator it = mail->carbonCopies.begin();
234 it != mail->carbonCopies.end(); ++it ) { 256 it != mail->carbonCopies.end(); ++it ) {
235 text += *it + " "; 257 text += *it + " ";
236 } 258 }
237 259
238 260
239 text += "\nDate: " + mail->date + "\n"; 261 text += "\nDate: " + mail->date + "\n";
240 if (mail->files.count() > 0) { 262 if (mail->files.count() > 0) {
241 text += "Attatchments: "; 263 text += "Attatchments: ";
242 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 264 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
243 text += ePtr->originalName + " "; 265 text += ePtr->originalName + " ";
244 } 266 }
245 text += "\n\n"; 267 text += "\n\n";
246 } else text += "\n"; 268 } else text += "\n";
247 269
248 if (!inbox) { 270 if (!inbox) {
249 text += mail->body; 271 text += mail->body;
250 } else if (mail->downloaded) { 272 } else if (mail->downloaded) {
251 text += mail->bodyPlain; 273 text += mail->bodyPlain;
252 } else { 274 } else {
253 text += "\nAwaiting download\n"; 275 text += "\nAwaiting download\n";
254 text += "Size of mail: " + mailStringSize; 276 text += "Size of mail: " + mailStringSize;
255 } 277 }
256 278
257 emailView->setText(text); 279 emailView->setText(text);
258 } 280 }
259 281
260 if (mail->files.count() == 0) 282 if (mail->files.count() == 0)
261 attachmentButton->setEnabled(FALSE); 283 attachmentButton->setEnabled(FALSE);
262 else attachmentButton->setEnabled(TRUE); 284 else attachmentButton->setEnabled(TRUE);
263 285
264 setCaption("Examining mail: " + mail->subject); 286 setCaption("Examining mail: " + mail->subject);
265} 287}
266 288
267//update view with current EmailListItem (item) 289//update view with current EmailListItem (item)
268void ReadMail::update(QListView *thisView, Email *mailIn) 290void ReadMail::update(QListView *thisView, Email *mailIn)
269{ 291{
270 view = thisView; 292 view = thisView;
271 item = (EmailListItem *) view->selectedItem(); 293 item = (EmailListItem *) view->selectedItem();
272 mail = mailIn; 294 mail = mailIn;
273 updateView(); 295 updateView();
274 updateButtons(); 296 updateButtons();
275} 297}
276 298
277void ReadMail::mailUpdated(Email *mailIn) 299void ReadMail::mailUpdated(Email *mailIn)
278{ 300{
279 if (mailIn == mail) { 301 if (mailIn == mail) {
280 updateView(); 302 updateView();
281 } else { 303 } else {
282 updateButtons(); 304 updateButtons();
283 } 305 }
284} 306}
285 307
286void ReadMail::close() 308void ReadMail::close()
287{ 309{
288 emit cancelView(); 310 emit cancelView();
289} 311}
290 312
291//gets next item in listview, exits if there is no next 313//gets next item in listview, exits if there is no next
292void ReadMail::next() 314void ReadMail::next()
293{ 315{
294 item = (EmailListItem *) item->nextSibling(); 316 item = (EmailListItem *) item->nextSibling();
295 if (item != NULL) { 317 if (item != NULL) {
296 mail = item->getMail(); 318 mail = item->getMail();
297 updateView(); 319 updateView();
298 } 320 }
299 updateButtons(); 321 updateButtons();
300} 322}
301 323
302//gets previous item in listview, exits if there is no previous 324//gets previous item in listview, exits if there is no previous
303void ReadMail::previous() 325void ReadMail::previous()
304{ 326{
305 item = (EmailListItem *) item->itemAbove(); 327 item = (EmailListItem *) item->itemAbove();
306 if (item != NULL) { 328 if (item != NULL) {
307 mail = item->getMail(); 329 mail = item->getMail();
308 updateView(); 330 updateView();
309 } 331 }
310 updateButtons(); 332 updateButtons();
311} 333}
312 334
313//deletes item, tries bringing up next or previous, exits if unsucessful 335//deletes item, tries bringing up next or previous, exits if unsucessful
314void ReadMail::deleteItem() 336void ReadMail::deleteItem()
315{ 337{
316 EmailListItem *temp = item; 338 EmailListItem *temp = item;
317 temp = (EmailListItem *) item->nextSibling();//trybelow 339 temp = (EmailListItem *) item->nextSibling();//trybelow
318 if (temp == NULL) 340 if (temp == NULL)
319 temp = (EmailListItem *) item->itemAbove(); //try above 341 temp = (EmailListItem *) item->itemAbove(); //try above
320 342
321 emit removeItem(item, inbox); 343 emit removeItem(item, inbox);
322 344
323 item = temp; 345 item = temp;
324 if (item != NULL) { //more items in list 346 if (item != NULL) { //more items in list
325 mail = item->getMail(); 347 mail = item->getMail();
326 updateView(); 348 updateView();
327 updateButtons(); 349 updateButtons();
328 } else close(); //no more items to see 350 } else close(); //no more items to see
329} 351}
330 352
331void ReadMail::updateButtons() 353void ReadMail::updateButtons()
332{ 354{
333 EmailListItem *temp; 355 EmailListItem *temp;
334 356
335 temp = item; 357 temp = item;
336 if ((EmailListItem *) temp->nextSibling() == NULL) 358 if ((EmailListItem *) temp->nextSibling() == NULL)
337 nextButton->setEnabled(FALSE); 359 nextButton->setEnabled(FALSE);
338 else nextButton->setEnabled(TRUE); 360 else nextButton->setEnabled(TRUE);
339 361
340 temp = item; 362 temp = item;
341 if ((EmailListItem *) temp->itemAbove() == NULL) 363 if ((EmailListItem *) temp->itemAbove() == NULL)
342 previousButton->setEnabled(FALSE); 364 previousButton->setEnabled(FALSE);
343 else previousButton->setEnabled(TRUE); 365 else previousButton->setEnabled(TRUE);
344} 366}
345 367
346void ReadMail::shiftText() 368void ReadMail::shiftText()
347{ 369{
348 plainTxt = ! plainTxt; 370 plainTxt = ! plainTxt;
349 updateView(); 371 updateView();
350} 372}
351 373
352void ReadMail::viewAttachments() 374void ReadMail::viewAttachments()
353{ 375{
354 viewAtt->update(mail, inbox); 376 viewAtt->update(mail, inbox);
355 viewAtt->showMaximized(); 377 viewAtt->showMaximized();
356} 378}
357 379
358void ReadMail::reply() 380void ReadMail::reply()
359{ 381{
382 emit replyRequested(*mail, (bool&)FALSE);
383}
384
385void ReadMail::replyAll()
386{
360 emit replyRequested(*mail, (bool&)TRUE); 387 emit replyRequested(*mail, (bool&)TRUE);
361} 388}
362 389
363void ReadMail::forward() 390void ReadMail::forward()
364{ 391{
365 emit forwardRequested(*mail); 392 emit forwardRequested(*mail);
366} 393}
367 394
395void ReadMail::download()
396{
397 emit download(mail);
398}
399
diff --git a/noncore/unsupported/mailit/readmail.h b/noncore/unsupported/mailit/readmail.h
index df32c34..6700595 100644
--- a/noncore/unsupported/mailit/readmail.h
+++ b/noncore/unsupported/mailit/readmail.h
@@ -1,89 +1,95 @@
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#ifndef READMAIL_H 20#ifndef READMAIL_H
21#define READMAIL_H 21#define READMAIL_H
22 22
23#include <qaction.h> 23#include <qaction.h>
24#include <qmainwindow.h> 24#include <qmainwindow.h>
25#include <qmenubar.h> 25#include <qmenubar.h>
26#include <qpopupmenu.h> 26#include <qpopupmenu.h>
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qlistview.h> 28#include <qlistview.h>
29#include <qlayout.h> 29#include <qlayout.h>
30#include <qtextview.h> 30#include <qtextview.h>
31#include <qtoolbutton.h>
31 32
32#include "emailhandler.h" 33#include "emailhandler.h"
33#include "emaillistitem.h" 34#include "emaillistitem.h"
34#include "viewatt.h" 35#include "viewatt.h"
35 36
36class ReadMail : public QMainWindow 37class ReadMail : public QMainWindow
37{ 38{
38 Q_OBJECT 39 Q_OBJECT
39 40
40public: 41public:
41 ReadMail( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 42 ReadMail( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
42 ~ReadMail(); 43 ~ReadMail();
43 void update(QListView *thisView, Email *mailIn); 44 void update(QListView *thisView, Email *mailIn);
44 void updateView(); 45 void updateView();
45 void mailUpdated(Email *mailIn); 46 void mailUpdated(Email *mailIn);
46 47
47signals: 48signals:
48 void cancelView(); 49 void cancelView();
49 void replyRequested(Email &, bool &); 50 void replyRequested(Email &, bool &);
50 void forwardRequested(Email&); 51 void forwardRequested(Email&);
51 void removeItem(EmailListItem *, bool &); 52 void removeItem(EmailListItem *, bool &);
52 void viewingMail(Email *); 53 void viewingMail(Email *);
54 void download (Email*);
53 55
54public slots: 56public slots:
55 void close(); 57 void close();
56 void next(); 58 void next();
57 void previous(); 59 void previous();
58 void deleteItem(); 60 void deleteItem();
59 void shiftText(); 61 void shiftText();
60 void viewAttachments(); 62 void viewAttachments();
61 void reply(); 63 void reply();
64 void replyAll();
62 void forward(); 65 void forward();
66 void download();
63 67
64private: 68private:
65 void init(); 69 void init();
66 void updateButtons(); 70 void updateButtons();
67 71
68private: 72private:
69 QListView *view; 73 QListView *view;
70 EmailListItem *item; 74 EmailListItem *item;
71 bool plainTxt, inbox; 75 bool plainTxt, inbox;
72 Email *mail; 76 Email *mail;
73 ViewAtt *viewAtt; 77 ViewAtt *viewAtt;
74 78
75 QToolBar *bar; 79 QToolBar *bar;
76 QMenuBar *menu; 80 QMenuBar *menu;
77 QPopupMenu *viewMenu, *mailMenu; 81 QPopupMenu *viewMenu, *mailMenu;
78 QAction *deleteButton; 82 QAction *deleteButton;
79 QMimeSourceFactory *mime; 83 QMimeSourceFactory *mime;
80 QAction *plainTextButton; 84 QAction *plainTextButton;
81 QAction *nextButton; 85 QAction *nextButton;
82 QTextView *emailView; 86 QTextView *emailView;
83 QAction *attachmentButton; 87 QAction *attachmentButton;
84 QAction *previousButton; 88 QAction *previousButton;
85 QAction *replyButton; 89 QToolButton *replyButton;
86 QAction *forwardButton; 90 QAction *forwardButton;
91 QAction *replyAllButton;
92 QAction *downloadButton;
87}; 93};
88 94
89#endif // READMAIL_H 95#endif // READMAIL_H
diff --git a/noncore/unsupported/mailit/writemail.cpp b/noncore/unsupported/mailit/writemail.cpp
index dcf0c6e..c75494e 100644
--- a/noncore/unsupported/mailit/writemail.cpp
+++ b/noncore/unsupported/mailit/writemail.cpp
@@ -1,389 +1,402 @@
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 <qmessagebox.h> 20#include <qmessagebox.h>
21#include <qwhatsthis.h> 21#include <qwhatsthis.h>
22#include "writemail.h" 22#include "writemail.h"
23#include <qpe/resource.h> 23#include <qpe/resource.h>
24 24
25WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl ) 25WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl ):QMainWindow( parent, name, fl )
26 : QMainWindow( parent, name, fl )
27{ 26{
28 showingAddressList = FALSE; 27 showingAddressList = FALSE;
29 init(); 28 init();
30 29
31 addAtt = new AddAtt(0, "Add Attachments"); 30 addAtt = new AddAtt(0, "Add Attachments");
32} 31}
33 32
34WriteMail::~WriteMail() 33WriteMail::~WriteMail()
35{ 34{
36 delete addAtt; 35 delete addAtt;
37} 36}
38 37
39void WriteMail::setAddressList(AddressList *list) 38void WriteMail::setAddressList(AddressList *list)
40{ 39{
41 Contact *cPtr; 40 Contact *cPtr;
42 41
43 addressList = list; 42 addressList = list;
44 43
45 addressView->clear(); 44 addressView->clear();
46 QList<Contact> *cListPtr = addressList->getContactList(); 45 QList<Contact> *cListPtr = addressList->getContactList();
47 QListViewItem *item; 46 QListViewItem *item;
48 for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) { 47 for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) {
49 item = new QListViewItem(addressView, cPtr->name, cPtr->email); 48 item = new QListViewItem(addressView, cPtr->name, cPtr->email);
50 } 49 }
51} 50}
52 51
53void WriteMail::init() 52void WriteMail::init()
54{ 53{
55 setToolBarsMovable(FALSE); 54 setToolBarsMovable(FALSE);
56 55
57 bar = new QToolBar(this); 56 bar = new QToolBar(this);
58 bar->setHorizontalStretchable( TRUE ); 57 bar->setHorizontalStretchable( TRUE );
59 58
60 menu = new QMenuBar( bar ); 59 menu = new QMenuBar( bar );
61 60
62 mailMenu = new QPopupMenu(menu); 61 mailMenu = new QPopupMenu(menu);
63 menu->insertItem( tr( "&Mail" ), mailMenu); 62 menu->insertItem( tr( "&Mail" ), mailMenu);
64 addMenu = new QPopupMenu(menu); 63 addMenu = new QPopupMenu(menu);
65 menu->insertItem( tr( "&Add" ), addMenu); 64 menu->insertItem( tr( "&Add" ), addMenu);
66 65
67 bar = new QToolBar(this); 66 bar = new QToolBar(this);
68 attachButton = new QAction(tr("Attachment"), Resource::loadPixmap("mailit/attach"), QString::null, 0, this, 0); 67 attachButton = new QAction(tr("Attachment"), Resource::loadPixmap("mailit/attach"), QString::null, 0, this, 0);
69 attachButton->addTo(bar); 68 attachButton->addTo(bar);
70 attachButton->addTo(addMenu); 69 attachButton->addTo(addMenu);
71 connect( attachButton, SIGNAL( activated() ), this, SLOT( attachFile() ) ); 70 connect( attachButton, SIGNAL( activated() ), this, SLOT( attachFile() ) );
72 attachButton->setWhatsThis(tr("Click here to attach files to your mail")); 71 attachButton->setWhatsThis(tr("Click here to attach files to your mail"));
73 72
74 confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0); 73 confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0);
75 confirmButton->addTo(bar); 74 confirmButton->addTo(bar);
76 confirmButton->addTo(mailMenu); 75 confirmButton->addTo(mailMenu);
77 connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) ); 76 connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) );
78 confirmButton->setWhatsThis(tr("This button puts your mail in the send queue")); 77 confirmButton->setWhatsThis(tr("This button puts your mail in the send queue"));
79 78
80 newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0); 79 newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0);
81 newButton->addTo(mailMenu); 80 newButton->addTo(mailMenu);
82 connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) ); 81 connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) );
83 newButton->setWhatsThis(tr("Click here to create a new mail")); 82 newButton->setWhatsThis(tr("Click here to create a new mail"));
84 83
85 widget = new QWidget(this, "widget"); 84 widget = new QWidget(this, "widget");
86 grid = new QGridLayout( widget ); 85 grid = new QGridLayout( widget );
87 86
88 recipientsBox = new QComboBox( FALSE, widget, "toLabel" ); 87 recipientsBox = new QComboBox( FALSE, widget, "toLabel" );
89 recipientsBox->insertItem( tr( "To:" ) ); 88 recipientsBox->insertItem( tr( "To:" ) );
90 recipientsBox->insertItem( tr( "CC:" ) ); 89 recipientsBox->insertItem( tr( "CC:" ) );
91 recipientsBox->setCurrentItem(0); 90 recipientsBox->setCurrentItem(0);
92 grid->addWidget( recipientsBox, 0, 0 ); 91 grid->addWidget( recipientsBox, 0, 0 );
93 connect(recipientsBox,SIGNAL(activated(int)),this, SLOT(changeRecipients(int))); 92 connect(recipientsBox,SIGNAL(activated(int)),this, SLOT(changeRecipients(int)));
94 93
95 subjetLabel = new QLabel( widget, "subjetLabel" ); 94 subjetLabel = new QLabel( widget, "subjetLabel" );
96 subjetLabel->setText( tr( "Subject:" ) ); 95 subjetLabel->setText( tr( "Subject:" ) );
97 96
98 grid->addWidget( subjetLabel, 1, 0 ); 97 grid->addWidget( subjetLabel, 1, 0 );
99 98
100 ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" ); 99 ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" );
101 ToolButton13_2->setText( tr( "..." ) ); 100 ToolButton13_2->setText( tr( "..." ) );
102 grid->addWidget( ToolButton13_2, 1, 2 ); 101 grid->addWidget( ToolButton13_2, 1, 2 );
103 102
104 subjectInput = new QLineEdit( widget, "subjectInput" ); 103 subjectInput = new QLineEdit( widget, "subjectInput" );
105 grid->addWidget( subjectInput, 1, 1 ); 104 grid->addWidget( subjectInput, 1, 1 );
106 QWhatsThis::add(subjectInput,QWidget::tr("The mail subject should be entered here")); 105 QWhatsThis::add(subjectInput,QWidget::tr("The mail subject should be entered here"));
107 106
108 toInput = new QLineEdit( widget, "toInput" ); 107 toInput = new QLineEdit( widget, "toInput" );
109 grid->addWidget( toInput, 0, 1 ); 108 grid->addWidget( toInput, 0, 1 );
110 QWhatsThis::add(recipientsBox,QWidget::tr("Recipients can be entered here")); 109 QWhatsThis::add(recipientsBox,QWidget::tr("Recipients can be entered here"));
111 110
112 ccInput = new QLineEdit( widget, "ccInput" ); 111 ccInput = new QLineEdit( widget, "ccInput" );
113 ccInput->hide(); 112 ccInput->hide();
114 grid->addWidget( ccInput, 0, 1 ); 113 grid->addWidget( ccInput, 0, 1 );
115 QWhatsThis::add(ccInput,QWidget::tr("If you would like to send copies of your mail they can be entered here")); 114 QWhatsThis::add(ccInput,QWidget::tr("If you would like to send copies of your mail they can be entered here"));
116 115
117 addressButton = new QToolButton( widget, "addressButton" ); 116 addressButton = new QToolButton( widget, "addressButton" );
118 addressButton->setPixmap( Resource::loadPixmap("AddressBook") ); 117 addressButton->setPixmap( Resource::loadPixmap("AddressBook") );
119 addressButton->setToggleButton(TRUE); 118 addressButton->setToggleButton(TRUE);
120 grid->addWidget( addressButton, 0, 2 ); 119 grid->addWidget( addressButton, 0, 2 );
121 connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) ); 120 connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) );
122 QWhatsThis::add(addressButton,QWidget::tr("This button opens the address selector with all mail adresses from your OPIE addressbook")); 121 QWhatsThis::add(addressButton,QWidget::tr("This button opens the address selector with all mail adresses from your OPIE addressbook"));
123 122
124 emailInput = new QMultiLineEdit( widget, "emailInput" ); 123 emailInput = new QMultiLineEdit( widget, "emailInput" );
125 grid->addMultiCellWidget( emailInput, 2, 2, 0, 2); 124 grid->addMultiCellWidget( emailInput, 2, 2, 0, 2);
126 QWhatsThis::add(emailInput,QWidget::tr("Enter your mail text here")); 125 QWhatsThis::add(emailInput,QWidget::tr("Enter your mail text here"));
127 126
128 addressView = new QListView( widget, "addressView"); 127 addressView = new QListView( widget, "addressView");
129 addressView->addColumn("Name"); 128 addressView->addColumn("Name");
130 addressView->addColumn("EMail"); 129 addressView->addColumn("EMail");
131 addressView->setAllColumnsShowFocus(TRUE); 130 addressView->setAllColumnsShowFocus(TRUE);
132 addressView->setMultiSelection(TRUE); 131 addressView->setMultiSelection(TRUE);
133 addressView->hide(); 132 addressView->hide();
134 grid->addMultiCellWidget( addressView, 3, 3, 0, 2); 133 grid->addMultiCellWidget( addressView, 3, 3, 0, 2);
135 QWhatsThis::add(recipientsBox,QWidget::tr("Choose the recipients from this list")); 134 QWhatsThis::add(recipientsBox,QWidget::tr("Choose the recipients from this list"));
136 135
137 okButton = new QToolButton(bar, "ok"); 136 okButton = new QToolButton(bar, "ok");
138 okButton->setPixmap( Resource::loadPixmap("enter") ); 137 okButton->setPixmap( Resource::loadPixmap("enter") );
139 okButton->hide(); 138 okButton->hide();
140 connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) ); 139 connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) );
141 QWhatsThis::add(okButton,QWidget::tr("Queue your mail by clicking here")); 140 QWhatsThis::add(okButton,QWidget::tr("Queue your mail by clicking here"));
142 141
143 setCentralWidget(widget); 142 setCentralWidget(widget);
144} 143}
145 144
146void WriteMail::reject() 145void WriteMail::reject()
147{ 146{
148 emit cancelMail(); 147 emit cancelMail();
149} 148}
150 149
151void WriteMail::accept() 150void WriteMail::accept()
152{ 151{
153 QStringList attachedFiles, attachmentsType; 152 QStringList attachedFiles, attachmentsType;
154 int idCount = 0; 153 int idCount = 0;
155 154
156 if (toInput->text() == "") 155 if (toInput->text() == "")
157 { 156 {
158 QMessageBox::warning(this,tr("No recipient"), tr("Send mail to whom?"), tr("OK\n")); 157 QMessageBox::warning(this,tr("No recipient"), tr("Send mail to whom?"), tr("OK\n"));
159 return; 158 return;
160 } 159 }
161 160
162 if (! getRecipients(false) ) 161 if (! getRecipients(false) )
163 { 162 {
164 QMessageBox::warning(this,tr("Incorrect recipient separator"), 163 QMessageBox::warning(this,tr("Incorrect recipient separator"),
165 tr("Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n")); 164 tr("Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n"));
166 return; 165 return;
167 } 166 }
168 167
169 if ((ccInput->text()!="") && (! getRecipients(true) )) 168 if ((ccInput->text()!="") && (! getRecipients(true) ))
170 { 169 {
171 QMessageBox::warning(this,tr("Incorrect carbon copy separator"), 170 QMessageBox::warning(this,tr("Incorrect carbon copy separator"),
172 tr("CC Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n")); 171 tr("CC Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n"));
173 return; 172 return;
174 } 173 }
175 174
176 mail.subject = subjectInput->text(); 175 mail.subject = subjectInput->text();
177 mail.body = emailInput->text(); 176 mail.body = emailInput->text();
178 mail.sent = false; 177 mail.sent = false;
179 mail.received = false; 178 mail.received = false;
180 179
181 mail.rawMail = "To: "; 180 mail.rawMail = "To: ";
182 181
183 for (QStringList::Iterator it = mail.recipients.begin(); 182 for (QStringList::Iterator it = mail.recipients.begin();
184 it != mail.recipients.end(); ++it) { 183 it != mail.recipients.end(); ++it) {
185 184
186 mail.rawMail += (*it); 185 mail.rawMail += (*it);
187 mail.rawMail += ",\n"; 186 mail.rawMail += ",\n";
188 } 187 }
189 188
190 mail.rawMail.truncate(mail.rawMail.length()-2); 189 mail.rawMail.truncate(mail.rawMail.length()-2);
191 190
192 mail.rawMail += "\nCC: "; 191 mail.rawMail += "\nCC: ";
193 192
194 for (QStringList::Iterator it = mail.carbonCopies.begin(); 193 for (QStringList::Iterator it = mail.carbonCopies.begin();
195 it != mail.carbonCopies.end(); ++it) { 194 it != mail.carbonCopies.end(); ++it) {
196 195
197 mail.rawMail += (*it); 196 mail.rawMail += (*it);
198 mail.rawMail += ",\n"; 197 mail.rawMail += ",\n";
199 } 198 }
200 199
201 mail.rawMail += mail.from; 200 mail.rawMail += mail.from;
202 mail.rawMail += "\nSubject: "; 201 mail.rawMail += "\nSubject: ";
203 mail.rawMail += mail.subject; 202 mail.rawMail += mail.subject;
204 mail.rawMail += "\n\n"; 203 mail.rawMail += "\n\n";
205 204
206 attachedFiles = addAtt->returnattachedFiles(); 205 attachedFiles = addAtt->returnattachedFiles();
207 attachmentsType = addAtt->returnFileTypes(); 206 attachmentsType = addAtt->returnFileTypes();
208 207
209 QStringList::Iterator itType = attachmentsType.begin(); 208 QStringList::Iterator itType = attachmentsType.begin();
210 209
211 Enclosure e; 210 Enclosure e;
212 for ( QStringList::Iterator it = attachedFiles.begin(); it != attachedFiles.end(); ++it ) { 211 for ( QStringList::Iterator it = attachedFiles.begin(); it != attachedFiles.end(); ++it ) {
213 e.id = idCount; 212 e.id = idCount;
214 e.originalName = (*it).latin1(); 213 e.originalName = (*it).latin1();
215 e.contentType = (*itType).latin1(); 214 e.contentType = (*itType).latin1();
216 e.contentAttribute = (*itType).latin1(); 215 e.contentAttribute = (*itType).latin1();
217 e.saved = TRUE; 216 e.saved = TRUE;
218 mail.addEnclosure(&e); 217 mail.addEnclosure(&e);
219 218
220 itType++; 219 itType++;
221 idCount++; 220 idCount++;
222 } 221 }
223 mail.rawMail += mail.body; 222 mail.rawMail += mail.body;
224 mail.rawMail += "\n"; 223 mail.rawMail += "\n";
225 mail.rawMail += ".\n"; 224 mail.rawMail += ".\n";
226 emit sendMailRequested(mail); 225 emit sendMailRequested(mail);
227 addAtt->clear(); 226 addAtt->clear();
228} 227}
229 228
230void WriteMail::getAddress() 229void WriteMail::getAddress()
231{ 230{
232 showingAddressList = !showingAddressList; 231 showingAddressList = !showingAddressList;
233 232
234 if (showingAddressList) { 233 if (showingAddressList) {
235 emailInput->hide(); 234 emailInput->hide();
236 addressView->show(); 235 addressView->show();
237 okButton->show(); 236 okButton->show();
238 237
239 } else { 238 } else {
240 addressView->hide(); 239 addressView->hide();
241 okButton->hide(); 240 okButton->hide();
242 emailInput->show(); 241 emailInput->show();
243 } 242 }
244} 243}
245 244
246void WriteMail::attachFile() 245void WriteMail::attachFile()
247{ 246{
248 addAtt->showMaximized(); 247 addAtt->showMaximized();
249} 248}
250 249
251void WriteMail::reply(Email replyMail, bool replyAll) 250void WriteMail::reply(Email replyMail, bool replyAll)
252{ 251{
253 int pos; 252 int pos;
254 QString ccRecipients; 253 QString ccRecipients;
255 254
256 mail = replyMail; 255 mail = replyMail;
257 mail.files.clear(); 256 mail.files.clear();
258 257
259 toInput->setText(mail.fromMail); 258 toInput->setText(mail.fromMail);
260 259
261 if (replyAll) 260 if (replyAll)
262 { 261 {
263 for (QStringList::Iterator it = mail.carbonCopies.begin();it != mail.carbonCopies.end(); ++it) 262 for (QStringList::Iterator it = mail.carbonCopies.begin();it != mail.carbonCopies.end(); ++it)
264 { 263 {
265 ccRecipients.append(*it); 264 ccRecipients.append(*it);
266 ccRecipients.append(";"); 265 ccRecipients.append(";");
267 } 266 }
268 ccRecipients.truncate(ccRecipients.length()-1); //no ; at the end 267 ccRecipients.truncate(ccRecipients.length()-1); //no ; at the end
269 ccInput->setText(ccRecipients); 268 ccInput->setText(ccRecipients);
270 } 269 }
271 270 else ccInput->clear();
272 addRecipients(replyAll);
273 271
274 subjectInput->setText(tr("Re: ") + mail.subject); 272 subjectInput->setText(tr("Re: ") + mail.subject);
275 273
274 QString citation=mail.fromMail;
275 citation.append(tr(" wrote on "));
276 citation.append(mail.date);
277 citation.append(":\n");
278
279
280 //mail.body.insert(0,tr("On"));
276 pos = 0; 281 pos = 0;
277 mail.body.insert(pos, ">"); 282 mail.body.insert(pos, ">");
278 while (pos != -1) { 283 while (pos != -1) {
279 pos = mail.body.find('\n', pos); 284 pos = mail.body.find('\n', pos);
280 if (pos != -1) 285 if (pos != -1)
281 mail.body.insert(++pos, ">>"); 286 mail.body.insert(++pos, ">>");
282 } 287 }
283 288 mail.body.insert(0,citation);
284 emailInput->setText(mail.body); 289 emailInput->setText(mail.body);
285} 290}
286 291
287void WriteMail::forward(Email forwMail) 292void WriteMail::forward(Email forwMail)
288{ 293{
289 int pos=0; 294 int pos=0;
290 295
291 QString fwdBody=tr("======forwarded message from "); 296 QString fwdBody=tr("======forwarded message from ");
292 fwdBody.append(forwMail.fromMail); 297 fwdBody.append(forwMail.fromMail);
293 fwdBody.append(tr(" starts======\n\n")); 298 fwdBody.append(tr(" starts======\n\n"));
294 299
295 mail=forwMail; 300 mail=forwMail;
296 toInput->setText(""); 301 toInput->setText("");
297 ccInput->setText(""); 302 ccInput->setText("");
298 subjectInput->setText(tr("FWD: ") + mail.subject); 303 subjectInput->setText(tr("FWD: ") + mail.subject);
299 304
300 fwdBody+=mail.body; 305 fwdBody+=mail.body;
301 fwdBody+=QString(tr("======end of forwarded message======\n\n")); 306 fwdBody+=QString(tr("======end of forwarded message======\n\n"));
302 307
303 emailInput->setText(fwdBody); 308 emailInput->setText(fwdBody);
304} 309}
305 310
306bool WriteMail::getRecipients(bool ccField) 311bool WriteMail::getRecipients(bool ccField)
307{ 312{
308 QString str, temp; 313 QString str, temp;
309 int pos = 0; 314 int pos = 0;
310 315
311 mail.recipients.clear(); 316 if (ccField)
312 317 {
313 ccField ? temp = ccInput->text() : temp=toInput->text() ; 318 mail.carbonCopies.clear();
319 temp = ccInput->text();
320 }
321 else
322 {
323 mail.recipients.clear();
324 temp=toInput->text() ;
325 }
314 326
315 while ( (pos = temp.find(';')) != -1) { 327 while ( (pos = temp.find(';')) != -1) {
316 str = temp.left(pos).stripWhiteSpace(); 328 str = temp.left(pos).stripWhiteSpace();
317 temp = temp.right(temp.length() - (pos + 1)); 329 temp = temp.right(temp.length() - (pos + 1));
318 if ( str.find('@') == -1) 330 if ( str.find('@') == -1)
319 return false; 331 return false;
320 ccField ? mail.carbonCopies.append(str) : mail.recipients.append(str); 332 ccField ? mail.carbonCopies.append(str) : mail.recipients.append(str);
321 addressList->addContact(str, ""); 333 //addressList->addContact(str, "");
322 } 334 }
323 temp = temp.stripWhiteSpace(); 335 temp = temp.stripWhiteSpace();
324 if ( temp.find('@') == -1) 336 if ( temp.find('@') == -1)
325 return false; 337 return false;
326 ccField ? mail.carbonCopies.append(temp) : mail.recipients.append(temp); 338 ccField ? mail.carbonCopies.append(temp) : mail.recipients.append(temp);
327 addressList->addContact(temp, ""); 339 //addressList->addContact(temp, "");
328 340
329 return TRUE; 341 return TRUE;
330} 342}
331 343
332void WriteMail::addRecipients() 344void WriteMail::addRecipients()
333{ 345{
334 toInput->isVisible() ? addRecipients(false) : addRecipients(true); 346 toInput->isVisible() ? addRecipients(false) : addRecipients(true);
335 } 347 }
336 348
337void WriteMail::addRecipients(bool ccField) 349void WriteMail::addRecipients(bool ccField)
338{ 350{
339 QString recipients = ""; 351 QString recipients = "";
340 352
341 mail.recipients.clear(); 353 mail.recipients.clear();
342 354
343 QListViewItem *item = addressView->firstChild(); 355 QListViewItem *item = addressView->firstChild();
344 while (item != NULL) { 356 while (item != NULL) {
345 if ( item->isSelected() ) { 357 if ( item->isSelected() ) {
346 if (recipients == "") { 358 if (recipients == "") {
347 recipients = item->text(1); 359 recipients = item->text(1);
348 } else { 360 } else {
349 recipients += "; " + item->text(1); 361 recipients += "; " + item->text(1);
350 } 362 }
351 } 363 }
352 item = item->nextSibling(); 364 item = item->nextSibling();
353 } 365 }
354 366
355 ccField ? ccInput->setText(recipients):toInput->setText(recipients); 367 ccField ? ccInput->setText(recipients):toInput->setText(recipients);
356 368
357 addressView->hide(); 369 addressView->hide();
358 okButton->hide(); 370 okButton->hide();
359 emailInput->show(); 371 emailInput->show();
360 addressButton->setOn(FALSE); 372 addressButton->setOn(FALSE);
361 showingAddressList = !showingAddressList; 373 showingAddressList = !showingAddressList;
362} 374}
363 375
364void WriteMail::changeRecipients(int selection) 376void WriteMail::changeRecipients(int selection)
365{ 377{
366 if (selection==0) 378 if (selection==0)
367 { 379 {
368 toInput->show(); 380 toInput->show();
369 ccInput->hide(); 381 ccInput->hide();
370 } 382 }
371 else if (selection==1) 383 else if (selection==1)
372 { 384 {
373 toInput->hide(); 385 toInput->hide();
374 ccInput->show(); 386 ccInput->show();
375 } 387 }
376} 388}
377 389
378void WriteMail::setRecipient(const QString &recipient) 390void WriteMail::setRecipient(const QString &recipient)
379{ 391{
380 toInput->setText(recipient); 392 toInput->setText(recipient);
381} 393}
382 394
383void WriteMail::newMail() 395void WriteMail::newMail()
384{ 396{
385 toInput->clear(); 397 toInput->clear();
398 ccInput->clear();
386 subjectInput->clear(); 399 subjectInput->clear();
387 emailInput->clear(); 400 emailInput->clear();
388 setAddressList(addressList); 401 setAddressList(addressList);
389} 402}