author | groucho <groucho> | 2003-04-24 11:19:11 (UTC) |
---|---|---|
committer | groucho <groucho> | 2003-04-24 11:19:11 (UTC) |
commit | 9671975e21266e3bfa6f3c793a3278b67cea34b7 (patch) (unidiff) | |
tree | 876c77939cfd0e00fc844b1b5af09b2978564a6d /noncore/unsupported/mailit/emailclient.cpp | |
parent | 51e782b9658de61dc02579e115a9c62f396609a3 (diff) | |
download | opie-9671975e21266e3bfa6f3c793a3278b67cea34b7.zip opie-9671975e21266e3bfa6f3c793a3278b67cea34b7.tar.gz opie-9671975e21266e3bfa6f3c793a3278b67cea34b7.tar.bz2 |
- reworked size filtering
- started reworking offline download
- better tab focus switching
- Hello "Whats this" capability
- Fixed parsing of To: header files (no more Delivered-To: and Reply-To: matches)
- Good bye Settings.txt, hello Config Objects and encrypted passwords
- Translation improvements (added trs)
- Parser optimizations
Diffstat (limited to 'noncore/unsupported/mailit/emailclient.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/unsupported/mailit/emailclient.cpp | 219 |
1 files changed, 98 insertions, 121 deletions
diff --git a/noncore/unsupported/mailit/emailclient.cpp b/noncore/unsupported/mailit/emailclient.cpp index ad1e0b4..23059cf 100644 --- a/noncore/unsupported/mailit/emailclient.cpp +++ b/noncore/unsupported/mailit/emailclient.cpp | |||
@@ -2,48 +2,49 @@ | |||
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 <qfile.h> | 22 | #include <qfile.h> |
23 | #include <qcheckbox.h> | 23 | #include <qcheckbox.h> |
24 | #include <qmenubar.h> | 24 | #include <qmenubar.h> |
25 | #include <qaction.h> | 25 | #include <qaction.h> |
26 | #include <qwhatsthis.h> | ||
26 | #include <qpe/resource.h> | 27 | #include <qpe/resource.h> |
27 | #include "emailclient.h" | 28 | #include "emailclient.h" |
28 | 29 | ||
29 | QCollection::Item AccountList::newItem(QCollection::Item d) | 30 | QCollection::Item AccountList::newItem(QCollection::Item d) |
30 | { | 31 | { |
31 | return dupl( (MailAccount *) d); | 32 | return dupl( (MailAccount *) d); |
32 | } | 33 | } |
33 | 34 | ||
34 | MailAccount* AccountList::dupl(MailAccount *in) | 35 | MailAccount* AccountList::dupl(MailAccount *in) |
35 | { | 36 | { |
36 | ac = new MailAccount(*in); | 37 | ac = new MailAccount(*in); |
37 | return ac; | 38 | return ac; |
38 | } | 39 | } |
39 | 40 | ||
40 | EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl ) | 41 | EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl ) |
41 | : QMainWindow( parent, name, fl ) | 42 | : QMainWindow( parent, name, fl ) |
42 | { | 43 | { |
43 | emailHandler = new EmailHandler(); | 44 | emailHandler = new EmailHandler(); |
44 | addressList = new AddressList(); | 45 | addressList = new AddressList(); |
45 | 46 | ||
46 | sending = FALSE; | 47 | sending = FALSE; |
47 | receiving = FALSE; | 48 | receiving = FALSE; |
48 | previewingMail = FALSE; | 49 | previewingMail = FALSE; |
49 | mailIdCount = 1; | 50 | mailIdCount = 1; |
@@ -61,187 +62,181 @@ EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl ) | |||
61 | 62 | ||
62 | connect(inboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(inboxItemSelected()) ); | 63 | connect(inboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(inboxItemSelected()) ); |
63 | connect(outboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(outboxItemSelected()) ); | 64 | connect(outboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(outboxItemSelected()) ); |
64 | 65 | ||
65 | connect(inboxView, SIGNAL(pressed(QListViewItem *)), this, SLOT(inboxItemPressed()) ); | 66 | connect(inboxView, SIGNAL(pressed(QListViewItem *)), this, SLOT(inboxItemPressed()) ); |
66 | connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemReleased()) ); | 67 | connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemReleased()) ); |
67 | 68 | ||
68 | 69 | ||
69 | connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this, | 70 | connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this, |
70 | SLOT(mailArrived(const Email &, bool)) ); | 71 | SLOT(mailArrived(const Email &, bool)) ); |
71 | connect(emailHandler, SIGNAL(mailTransfered(int)), this, | 72 | connect(emailHandler, SIGNAL(mailTransfered(int)), this, |
72 | SLOT(allMailArrived(int)) ); | 73 | SLOT(allMailArrived(int)) ); |
73 | 74 | ||
74 | mailconf = new Config("mailit"); | 75 | mailconf = new Config("mailit"); |
75 | //In case Synchronize is not defined in settings.txt | 76 | //In case Synchronize is not defined in settings.txt |
76 | 77 | ||
77 | readSettings(); | 78 | readSettings(); |
78 | 79 | ||
79 | updateAccounts(); | 80 | updateAccounts(); |
80 | 81 | ||
81 | lineShift = "\n"; | 82 | lineShift = "\n"; |
82 | readMail(); | 83 | readMail(); |
83 | lineShift = "\r\n"; | 84 | lineShift = "\r\n"; |
84 | 85 | ||
86 | mailboxView->setCurrentTab(0); //ensure that inbox has focus | ||
85 | } | 87 | } |
86 | 88 | ||
87 | 89 | ||
88 | EmailClient::~EmailClient() | 90 | EmailClient::~EmailClient() |
89 | { | 91 | { |
90 | //needs to be moved from destructor to closewindow event | 92 | //needs to be moved from destructor to closewindow event |
91 | saveMail(getPath(FALSE) + "inbox.txt", inboxView); | 93 | saveMail(getPath(FALSE) + "inbox.txt", inboxView); |
92 | //does not currently work. Defining outbox in the same | 94 | //does not currently work. Defining outbox in the same |
93 | //format as inbox is not a good solution as they have | 95 | //format as inbox is not a good solution as they have |
94 | //different properties | 96 | //different properties |
95 | saveMail(getPath(FALSE) + "outbox.txt", outboxView); | 97 | saveMail(getPath(FALSE) + "outbox.txt", outboxView); |
96 | saveSettings(); | 98 | saveSettings(); |
97 | 99 | ||
98 | mailconf->write(); | 100 | mailconf->write(); |
99 | delete mailconf; | 101 | delete mailconf; |
100 | 102 | ||
101 | } | 103 | } |
102 | 104 | ||
103 | void EmailClient::init() | 105 | void EmailClient::init() |
104 | { | 106 | { |
105 | statusBar = new QStatusBar(this); | 107 | statusBar = new QStatusBar(this); |
106 | statusBar->setSizeGripEnabled(FALSE); | 108 | statusBar->setSizeGripEnabled(FALSE); |
107 | 109 | ||
108 | status1Label = new QLabel( tr("Idle"), statusBar); | 110 | status1Label = new QLabel( tr("Idle"), statusBar); |
109 | status2Label = new QLabel("", statusBar); | 111 | status2Label = new QLabel("", statusBar); |
110 | connect(emailHandler, SIGNAL(updatePopStatus(const QString &)), | 112 | connect(emailHandler, SIGNAL(updatePopStatus(const QString &)), |
111 | status2Label, SLOT(setText(const QString &)) ); | 113 | status2Label, SLOT(setText(const QString &)) ); |
112 | connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)), | 114 | connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)), |
113 | status2Label, SLOT(setText(const QString &)) ); | 115 | status2Label, SLOT(setText(const QString &)) ); |
114 | 116 | ||
115 | progressBar = new QProgressBar(statusBar); | 117 | progressBar = new QProgressBar(statusBar); |
118 | |||
116 | connect(emailHandler, SIGNAL(mailboxSize(int)), | 119 | connect(emailHandler, SIGNAL(mailboxSize(int)), |
117 | this, SLOT(setTotalSize(int)) ); | 120 | this, SLOT(setTotalSize(int)) ); |
118 | connect(emailHandler, SIGNAL(currentMailSize(int)), | 121 | connect(emailHandler, SIGNAL(currentMailSize(int)), |
119 | this, SLOT(setMailSize(int)) ); | 122 | this, SLOT(setMailSize(int)) ); |
120 | connect(emailHandler, SIGNAL(downloadedSize(int)), | 123 | connect(emailHandler, SIGNAL(downloadedSize(int)), |
121 | this, SLOT(setDownloadedSize(int)) ); | 124 | this, SLOT(setDownloadedSize(int)) ); |
122 | 125 | ||
123 | statusBar->addWidget(status1Label); | 126 | statusBar->addWidget(status1Label); |
124 | statusBar->addWidget(progressBar); | 127 | statusBar->addWidget(progressBar); |
125 | statusBar->addWidget(status2Label); | 128 | statusBar->addWidget(status2Label); |
126 | 129 | ||
127 | setToolBarsMovable(FALSE); | 130 | setToolBarsMovable(FALSE); |
128 | 131 | ||
129 | bar = new QToolBar(this); | 132 | bar = new QToolBar(this); |
133 | QWhatsThis::add(bar,tr("Main operation toolbar")); | ||
130 | bar->setHorizontalStretchable( TRUE ); | 134 | bar->setHorizontalStretchable( TRUE ); |
131 | 135 | ||
132 | mb = new QMenuBar( bar ); | 136 | mb = new QMenuBar( bar ); |
133 | 137 | ||
134 | QPopupMenu *mail = new QPopupMenu(mb); | 138 | QPopupMenu *mail = new QPopupMenu(mb); |
135 | mb->insertItem( tr( "&Mail" ), mail); | 139 | mb->insertItem( tr( "&Mail" ), mail); |
136 | 140 | ||
137 | QPopupMenu *configure = new QPopupMenu(mb); | 141 | QPopupMenu *configure = new QPopupMenu(mb); |
138 | mb->insertItem( tr( "Accounts" ), configure); | 142 | mb->insertItem( tr( "Accounts" ), configure); |
139 | 143 | ||
140 | selectAccountMenu = new QPopupMenu(mb); | 144 | selectAccountMenu = new QPopupMenu(mb); |
141 | editAccountMenu = new QPopupMenu(mb); | 145 | editAccountMenu = new QPopupMenu(mb); |
142 | deleteAccountMenu = new QPopupMenu(mb); | 146 | deleteAccountMenu = new QPopupMenu(mb); |
143 | 147 | ||
144 | mail->insertItem(tr("Get Mail in"), selectAccountMenu); | 148 | mail->insertItem(tr("Get Mail in"), selectAccountMenu); |
145 | configure->insertItem(tr("Edit account"), editAccountMenu); | 149 | configure->insertItem(tr("Edit account"), editAccountMenu); |
146 | configure->insertItem(tr("Delete account"), deleteAccountMenu); | 150 | configure->insertItem(tr("Delete account"), deleteAccountMenu); |
147 | 151 | ||
148 | bar = new QToolBar(this); | 152 | bar = new QToolBar(this); |
149 | 153 | ||
150 | getMailButton = new QToolButton(Resource::loadPixmap("mailit/getmail"),tr("getMail"),tr("select account"), this,SLOT(getAllNewMail()),bar); | 154 | getMailButton = new QToolButton(Resource::loadPixmap("mailit/getmail"),tr("getMail"),tr("select account"), this,SLOT(getAllNewMail()),bar); |
151 | //connect(setAccountlButton, SIGNAL(activated()), this, SLOT(setCurrentAccount()) ); | 155 | QWhatsThis::add(getMailButton,tr("Click to download mail via all available accounts.\n Press and hold to select the desired account.")); |
152 | // setAccountButton->addTo(bar); | ||
153 | //setAccountButton->addTo(mail); | ||
154 | |||
155 | /*idCount = 0; | ||
156 | |||
157 | for (MailAccount* accountPtr = accountList.first(); accountPtr != 0; | ||
158 | accountPtr = accountList.next()) { | ||
159 | 156 | ||
160 | selectAccountMenu->insertItem(accountPtr->accountName,this, SLOT(selectAccount(int)), 0, idCount); | ||
161 | idCount++; | ||
162 | }*/ | ||
163 | getMailButton->setPopup(selectAccountMenu); | 157 | getMailButton->setPopup(selectAccountMenu); |
164 | 158 | ||
165 | |||
166 | /*getMailButton = new QAction(tr("Get all mail"), Resource::loadPixmap("mailit/getmail"), QString::null, 0, this, 0); | ||
167 | connect(getMailButton, SIGNAL(activated()), this, SLOT(getAllNewMail()) ); | ||
168 | getMailButton->addTo(bar);*/ | ||
169 | //getMailButton->addTo(mail); | ||
170 | |||
171 | sendMailButton = new QAction(tr("Send mail"), Resource::loadPixmap("mailit/sendqueue"), QString::null, 0, this, 0); | 159 | sendMailButton = new QAction(tr("Send mail"), Resource::loadPixmap("mailit/sendqueue"), QString::null, 0, this, 0); |
172 | connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) ); | 160 | connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) ); |
173 | sendMailButton->addTo(bar); | 161 | sendMailButton->addTo(bar); |
174 | sendMailButton->addTo(mail); | 162 | sendMailButton->addTo(mail); |
163 | sendMailButton->setWhatsThis("Send mail queued in the outbox"); | ||
175 | 164 | ||
176 | composeButton = new QAction(tr("Compose"), Resource::loadPixmap("new"), QString::null, 0, this, 0); | 165 | composeButton = new QAction(tr("Compose"), Resource::loadPixmap("new"), QString::null, 0, this, 0); |
177 | connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) ); | 166 | connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) ); |
178 | composeButton->addTo(bar); | 167 | composeButton->addTo(bar); |
179 | composeButton->addTo(mail); | 168 | composeButton->addTo(mail); |
169 | composeButton->setWhatsThis("Compose a new mail"); | ||
180 | 170 | ||
181 | cancelButton = new QAction(tr("Cancel transfer"), Resource::loadPixmap("close"), QString::null, 0, this, 0); | 171 | cancelButton = new QAction(tr("Cancel transfer"), Resource::loadPixmap("close"), QString::null, 0, this, 0); |
182 | connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) ); | 172 | connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) ); |
183 | cancelButton->addTo(mail); | 173 | cancelButton->addTo(mail); |
184 | cancelButton->addTo(bar); | 174 | cancelButton->addTo(bar); |
185 | cancelButton->setEnabled(FALSE); | 175 | cancelButton->setEnabled(FALSE); |
176 | cancelButton->setWhatsThis("Stop the currently active mail transfer"); | ||
177 | |||
186 | 178 | ||
187 | deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); | 179 | deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); |
188 | connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); | 180 | connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); |
189 | deleteButton->addTo(bar); | 181 | deleteButton->addTo(bar); |
182 | deleteButton->setWhatsThis("Remove the currently selected eMail(s)"); | ||
190 | 183 | ||
191 | mailboxView = new OTabWidget( this, "mailboxView" ); | 184 | mailboxView = new OTabWidget( this, "mailboxView" ); |
192 | 185 | ||
193 | QWidget* widget = new QWidget( mailboxView, "widget" ); | 186 | QWidget* widget = new QWidget( mailboxView, "widget" ); |
194 | grid_2 = new QGridLayout( widget ); | 187 | grid_2 = new QGridLayout( widget ); |
195 | // grid_2->setSpacing(6); | 188 | // grid_2->setSpacing(6); |
196 | // grid_2->setMargin( 11 ); | 189 | // grid_2->setMargin( 11 ); |
197 | 190 | ||
198 | inboxView = new QListView( widget, "inboxView" ); | 191 | inboxView = new QListView( widget, "inboxView" ); |
199 | inboxView->addColumn( tr( "From" ) ); | 192 | inboxView->addColumn( tr( "From" ) ); |
200 | inboxView->addColumn( tr( "Subject" ) ); | 193 | inboxView->addColumn( tr( "Subject" ) ); |
201 | inboxView->addColumn( tr( "Date" ) ); | 194 | inboxView->addColumn( tr( "Date" ) ); |
202 | inboxView->setMinimumSize( QSize( 0, 0 ) ); | 195 | inboxView->setMinimumSize( QSize( 0, 0 ) ); |
203 | inboxView->setAllColumnsShowFocus(TRUE); | 196 | 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" | ||
198 | " A blue attachment icon shows whether this mail has attachments.")); | ||
204 | 199 | ||
205 | grid_2->addWidget( inboxView, 2, 0 ); | 200 | grid_2->addWidget( inboxView, 2, 0 ); |
206 | mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) ); | 201 | mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) ); |
207 | 202 | ||
208 | QWidget* widget_2 = new QWidget( mailboxView, "widget_2" ); | 203 | QWidget* widget_2 = new QWidget( mailboxView, "widget_2" ); |
209 | grid_3 = new QGridLayout( widget_2 ); | 204 | grid_3 = new QGridLayout( widget_2 ); |
210 | // grid_3->setSpacing(6); | 205 | // grid_3->setSpacing(6); |
211 | // grid_3->setMargin( 11 ); | 206 | // grid_3->setMargin( 11 ); |
212 | 207 | ||
213 | outboxView = new QListView( widget_2, "outboxView" ); | 208 | outboxView = new QListView( widget_2, "outboxView" ); |
214 | outboxView->addColumn( tr( "To" ) ); | 209 | outboxView->addColumn( tr( "To" ) ); |
215 | outboxView->addColumn( tr( "Subject" ) ); | 210 | outboxView->addColumn( tr( "Subject" ) ); |
216 | outboxView->setAllColumnsShowFocus(TRUE); | 211 | outboxView->setAllColumnsShowFocus(TRUE); |
217 | 212 | ||
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.")); | ||
218 | grid_3->addWidget( outboxView, 0, 0 ); | 214 | grid_3->addWidget( outboxView, 0, 0 ); |
219 | mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) ); | 215 | mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) ); |
220 | 216 | ||
221 | setCentralWidget(mailboxView); | 217 | setCentralWidget(mailboxView); |
222 | 218 | ||
223 | mailboxView->setCurrentTab(0); | ||
224 | } | 219 | } |
225 | 220 | ||
226 | void EmailClient::compose() | 221 | void EmailClient::compose() |
227 | { | 222 | { |
228 | emit composeRequested(); | 223 | emit composeRequested(); |
229 | } | 224 | } |
230 | 225 | ||
231 | void EmailClient::cancel() | 226 | void EmailClient::cancel() |
232 | { | 227 | { |
233 | emailHandler->cancel(); | 228 | emailHandler->cancel(); |
234 | } | 229 | } |
235 | 230 | ||
236 | AddressList* EmailClient::getAdrListRef() | 231 | AddressList* EmailClient::getAdrListRef() |
237 | { | 232 | { |
238 | return addressList; | 233 | return addressList; |
239 | } | 234 | } |
240 | 235 | ||
241 | //this needs to be rewritten to syncronize with outboxView | 236 | //this needs to be rewritten to syncronize with outboxView |
242 | void EmailClient::enqueMail(const Email &mail) | 237 | void EmailClient::enqueMail(const Email &mail) |
243 | { | 238 | { |
244 | if (accountList.count() == 0) { | 239 | if (accountList.count() == 0) { |
245 | QMessageBox::warning(qApp->activeWindow(), | 240 | QMessageBox::warning(qApp->activeWindow(), |
246 | tr("No account selected"), tr("You must create an account"), "OK\n"); | 241 | tr("No account selected"), tr("You must create an account"), "OK\n"); |
247 | return; | 242 | return; |
@@ -303,198 +298,210 @@ void EmailClient::mailSent() | |||
303 | quedMessages.clear(); | 298 | quedMessages.clear(); |
304 | outboxView->clear(); //should be moved to an sentBox | 299 | outboxView->clear(); //should be moved to an sentBox |
305 | } | 300 | } |
306 | 301 | ||
307 | void EmailClient::getNewMail() { | 302 | void EmailClient::getNewMail() { |
308 | 303 | ||
309 | if (accountList.count() == 0) { | 304 | if (accountList.count() == 0) { |
310 | QMessageBox::warning(qApp->activeWindow(),"No account selected", | 305 | QMessageBox::warning(qApp->activeWindow(),"No account selected", |
311 | "You must create an account", "OK\n"); | 306 | "You must create an account", "OK\n"); |
312 | return; | 307 | return; |
313 | } | 308 | } |
314 | 309 | ||
315 | setMailAccount(); | 310 | setMailAccount(); |
316 | 311 | ||
317 | receiving = TRUE; | 312 | receiving = TRUE; |
318 | previewingMail = TRUE; | 313 | previewingMail = TRUE; |
319 | getMailButton->setEnabled(FALSE); | 314 | getMailButton->setEnabled(FALSE); |
320 | cancelButton->setEnabled(TRUE); | 315 | cancelButton->setEnabled(TRUE); |
321 | selectAccountMenu->setEnabled(FALSE); | 316 | selectAccountMenu->setEnabled(FALSE); |
322 | 317 | ||
323 | status1Label->setText(currentAccount->accountName + " headers"); | 318 | status1Label->setText(currentAccount->accountName + " headers"); |
324 | progressBar->reset(); | 319 | progressBar->reset(); |
325 | 320 | ||
326 | //get any previous mails not downloaded and add to queue | 321 | //get any previous mails not downloaded and add to queue |
327 | /* mailDownloadList.clear(); | 322 | mailDownloadList.clear(); |
328 | Email *mailPtr; | 323 | Email *mailPtr; |
329 | item = (EmailListItem *) inboxView->firstChild(); | 324 | item = (EmailListItem *) inboxView->firstChild(); |
330 | while (item != NULL) { | 325 | while (item != NULL) { |
331 | mailPtr = item->getMail(); | 326 | mailPtr = item->getMail(); |
332 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { | 327 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { |
333 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); | 328 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); |
334 | } | 329 | } |
335 | item = (EmailListItem *) item->nextSibling(); | 330 | item = (EmailListItem *) item->nextSibling(); |
336 | }*/ | 331 | } |
337 | 332 | ||
338 | emailHandler->getMailHeaders(); | 333 | emailHandler->getMailHeaders(); |
334 | |||
339 | } | 335 | } |
340 | 336 | ||
341 | void EmailClient::getAllNewMail() | 337 | void EmailClient::getAllNewMail() |
342 | { | 338 | { |
343 | allAccounts = TRUE; | 339 | allAccounts = TRUE; |
344 | currentAccount = accountList.first(); | 340 | currentAccount = accountList.first(); |
345 | getNewMail(); | 341 | getNewMail(); |
346 | } | 342 | } |
347 | 343 | ||
348 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) | 344 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) |
349 | { | 345 | { |
350 | Enclosure *ePtr; | 346 | Enclosure *ePtr; |
351 | Email newMail; | 347 | Email newMail; |
352 | int thisMailId; | 348 | int thisMailId; |
353 | emailHandler->parse(mail.rawMail, lineShift, &newMail); | 349 | emailHandler->parse(mail.rawMail, lineShift, &newMail); |
354 | |||
355 | mailconf->setGroup(newMail.id); | 350 | mailconf->setGroup(newMail.id); |
356 | 351 | ||
357 | if (fromDisk) { | 352 | if (fromDisk) |
353 | { | ||
358 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); | 354 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); |
359 | newMail.size = mailconf->readNumEntry("size"); | 355 | newMail.size = mailconf->readNumEntry("size"); |
360 | newMail.serverId = mailconf->readNumEntry("serverid"); | 356 | newMail.serverId = mailconf->readNumEntry("serverid"); |
361 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); | 357 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); |
362 | } else { //mail arrived from server | 358 | } |
359 | else | ||
360 | { //mail arrived from server | ||
363 | newMail.serverId = mail.serverId; | 361 | newMail.serverId = mail.serverId; |
364 | newMail.size = mail.size; | 362 | newMail.size = mail.size; |
365 | newMail.downloaded = mail.downloaded; | 363 | newMail.downloaded = mail.downloaded; |
366 | 364 | ||
367 | newMail.fromAccountId = currentAccount->id; | 365 | newMail.fromAccountId = currentAccount->id; |
368 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); | 366 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); |
369 | } | 367 | } |
370 | 368 | ||
371 | //add if read or not | 369 | //add if read or not |
372 | newMail.read = mailconf->readBoolEntry("mailread"); | 370 | newMail.read = mailconf->readBoolEntry("mailread"); |
373 | 371 | ||
374 | //check if new mail | 372 | //check if new mail |
375 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { | 373 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { |
376 | thisMailId = mailIdCount; | 374 | thisMailId = mailIdCount; |
377 | mailIdCount++; | 375 | mailIdCount++; |
378 | 376 | ||
379 | //set server count, so that if the user aborts, the new | 377 | //set server count, so that if the user aborts, the new |
380 | //header is not reloaded | 378 | //header is not reloaded |
381 | if (currentAccount->synchronize) | 379 | if ((currentAccount)&&(currentAccount->synchronize)) |
382 | currentAccount->lastServerMailCount++; | 380 | currentAccount->lastServerMailCount++; |
383 | 381 | ||
384 | mailconf->writeEntry("internalmailid", thisMailId); | 382 | mailconf->writeEntry("internalmailid", thisMailId); |
385 | mailconf->writeEntry("downloaded", newMail.downloaded); | 383 | mailconf->writeEntry("downloaded", newMail.downloaded); |
386 | mailconf->writeEntry("size", (int) newMail.size); | 384 | mailconf->writeEntry("size", (int) newMail.size); |
387 | mailconf->writeEntry("serverid", newMail.serverId); | 385 | mailconf->writeEntry("serverid", newMail.serverId); |
388 | 386 | ||
389 | addressList->addContact(newMail.fromMail, newMail.from); | 387 | //addressList->addContact(newMail.fromMail, newMail.from); |
390 | } else if (!fromDisk) { //body to header arrived | ||
391 | mailconf->writeEntry("downloaded", TRUE); | ||
392 | } | 388 | } |
389 | |||
390 | mailconf->writeEntry("downloaded", newMail.downloaded); | ||
391 | |||
393 | QString stringMailId; | 392 | QString stringMailId; |
394 | stringMailId.setNum(thisMailId); | 393 | stringMailId.setNum(thisMailId); |
395 | //se if any attatchments needs to be stored | 394 | //see if any attatchments needs to be stored |
395 | |||
396 | for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { | 396 | for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { |
397 | QString stringId; | 397 | QString stringId; |
398 | stringId.setNum(ePtr->id); | 398 | stringId.setNum(ePtr->id); |
399 | 399 | ||
400 | int id = mailconf->readNumEntry("enclosureid_" + stringId); | 400 | int id = mailconf->readNumEntry("enclosureid_" + stringId); |
401 | if (id != ePtr->id) { //new entry | 401 | if (id != ePtr->id) { //new entry |
402 | mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); | 402 | mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); |
403 | mailconf->writeEntry("name_" + stringId, ePtr->originalName); | 403 | mailconf->writeEntry("name_" + stringId, ePtr->originalName); |
404 | mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); | 404 | mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); |
405 | mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); | 405 | mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); |
406 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 406 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
407 | mailconf->writeEntry("installed_" + stringId, FALSE); | 407 | mailconf->writeEntry("installed_" + stringId, FALSE); |
408 | 408 | ||
409 | ePtr->name = stringMailId + "_" + stringId; | 409 | ePtr->name = stringMailId + "_" + stringId; |
410 | ePtr->path = getPath(TRUE); | 410 | ePtr->path = getPath(TRUE); |
411 | if (emailHandler->getEnclosure(ePtr)) { //file saved | 411 | if (emailHandler->getEnclosure(ePtr)) { //file saved |
412 | ePtr->saved = TRUE; | 412 | ePtr->saved = TRUE; |
413 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 413 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
414 | mailconf->writeEntry("filename_" + stringId, ePtr->name); | 414 | mailconf->writeEntry("filename_" + stringId, ePtr->name); |
415 | mailconf->writeEntry("path_" + stringId, ePtr->path); | 415 | mailconf->writeEntry("path_" + stringId, ePtr->path); |
416 | } else { | 416 | } else { |
417 | ePtr->saved = FALSE; | 417 | ePtr->saved = FALSE; |
418 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 418 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
419 | } | 419 | } |
420 | } else { | 420 | } else { |
421 | ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); | 421 | ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); |
422 | ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); | 422 | ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); |
423 | if (ePtr->saved) { | 423 | if (ePtr->saved) { |
424 | ePtr->name = mailconf->readEntry("filename_" + stringId); | 424 | ePtr->name = mailconf->readEntry("filename_" + stringId); |
425 | ePtr->path = mailconf->readEntry("path_" + stringId); | 425 | ePtr->path = mailconf->readEntry("path_" + stringId); |
426 | } | 426 | } |
427 | } | 427 | } |
428 | } | 428 | } |
429 | if (!previewingMail && !fromDisk) { | 429 | |
430 | bool found=false; | ||
431 | |||
432 | if (!fromDisk) | ||
433 | { | ||
434 | |||
430 | Email *mailPtr; | 435 | Email *mailPtr; |
431 | item = (EmailListItem *) inboxView->firstChild(); | 436 | item = (EmailListItem *) inboxView->firstChild(); |
432 | while (item != NULL) { | 437 | while ((item != NULL)&&(!found)) |
438 | { | ||
433 | mailPtr = item->getMail(); | 439 | mailPtr = item->getMail(); |
434 | if (mailPtr->id == newMail.id) { | 440 | if (mailPtr->id == newMail.id) { |
435 | item->setMail(newMail); | 441 | item->setMail(newMail); |
436 | emit mailUpdated(item->getMail()); | 442 | emit mailUpdated(item->getMail()); |
443 | found = true; | ||
437 | } | 444 | } |
438 | item = (EmailListItem *) item->nextSibling(); | 445 | item = (EmailListItem *) item->nextSibling(); |
439 | } | 446 | } |
440 | } else { | ||
441 | item = new EmailListItem(inboxView, newMail, TRUE); | ||
442 | if (!newMail.downloaded) | ||
443 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size); | ||
444 | } | 447 | } |
448 | if ((!found)||(fromDisk)) item = new EmailListItem(inboxView, newMail, TRUE); | ||
449 | |||
450 | /*if (!newMail.downloaded) | ||
451 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ | ||
445 | 452 | ||
446 | mailboxView->setCurrentTab(0); | 453 | mailboxView->setCurrentTab(0); |
447 | 454 | ||
448 | } | 455 | } |
449 | 456 | ||
450 | void EmailClient::allMailArrived(int count) | 457 | void EmailClient::allMailArrived(int count) |
451 | { | 458 | { |
452 | // not previewing means all mailtransfer has been done | 459 | // not previewing means all mailtransfer has been done |
453 | if (!previewingMail) { | 460 | /*if (!previewingMail) {*/ |
454 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { | 461 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { |
455 | emit newCaption("Mailit - " + currentAccount->accountName); | 462 | emit newCaption("Mailit - " + currentAccount->accountName); |
456 | getNewMail(); | 463 | getNewMail(); |
457 | return; | 464 | return; |
458 | } else { | 465 | } else { |
459 | allAccounts = FALSE; | 466 | allAccounts = FALSE; |
460 | receiving = FALSE; | 467 | receiving = FALSE; |
461 | getMailButton->setEnabled(TRUE); | 468 | getMailButton->setEnabled(TRUE); |
462 | cancelButton->setEnabled(FALSE); | 469 | cancelButton->setEnabled(FALSE); |
463 | selectAccountMenu->setEnabled(TRUE); | 470 | selectAccountMenu->setEnabled(TRUE); |
464 | status1Label->setText("Idle"); | 471 | status1Label->setText("Idle"); |
465 | 472 | ||
466 | progressBar->reset(); | 473 | progressBar->reset(); |
467 | return; | 474 | return; |
468 | } | 475 | } |
469 | } | 476 | //} |
470 | 477 | ||
471 | // all headers downloaded from server, start downloading remaining mails | 478 | // all headers downloaded from server, start downloading remaining mails |
472 | previewingMail = FALSE; | 479 | previewingMail = FALSE; |
473 | status1Label->setText(currentAccount->accountName); | 480 | status1Label->setText(currentAccount->accountName); |
474 | progressBar->reset(); | 481 | progressBar->reset(); |
475 | 482 | ||
476 | emailHandler->getMailByList(&mailDownloadList); | 483 | //emailHandler->getMailByList(&mailDownloadList); |
477 | 484 | ||
478 | mailboxView->setCurrentTab(0); | 485 | mailboxView->setCurrentTab(0); |
479 | } | 486 | } |
480 | 487 | ||
481 | void EmailClient::moveMailFront(Email *mailPtr) | 488 | void EmailClient::moveMailFront(Email *mailPtr) |
482 | { | 489 | { |
483 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { | 490 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { |
484 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); | 491 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); |
485 | } | 492 | } |
486 | } | 493 | } |
487 | 494 | ||
488 | void EmailClient::smtpError(int code) | 495 | void EmailClient::smtpError(int code) |
489 | { | 496 | { |
490 | QString temp; | 497 | QString temp; |
491 | 498 | ||
492 | if (code == ErrUnknownResponse) | 499 | if (code == ErrUnknownResponse) |
493 | temp = "Unknown response from server"; | 500 | temp = "Unknown response from server"; |
494 | 501 | ||
495 | if (code == QSocket::ErrHostNotFound) | 502 | if (code == QSocket::ErrHostNotFound) |
496 | temp = "host not found"; | 503 | temp = "host not found"; |
497 | if (code == QSocket::ErrConnectionRefused) | 504 | if (code == QSocket::ErrConnectionRefused) |
498 | temp = "connection refused"; | 505 | temp = "connection refused"; |
499 | if (code == QSocket::ErrSocketRead) | 506 | if (code == QSocket::ErrSocketRead) |
500 | temp = "socket packet error"; | 507 | temp = "socket packet error"; |
@@ -520,76 +527,74 @@ void EmailClient::popError(int code) | |||
520 | if (code == ErrLoginFailed) | 527 | if (code == ErrLoginFailed) |
521 | temp = "Login failed\nCheck user name and password"; | 528 | temp = "Login failed\nCheck user name and password"; |
522 | 529 | ||
523 | if (code == QSocket::ErrHostNotFound) | 530 | if (code == QSocket::ErrHostNotFound) |
524 | temp = "host not found"; | 531 | temp = "host not found"; |
525 | if (code == QSocket::ErrConnectionRefused) | 532 | if (code == QSocket::ErrConnectionRefused) |
526 | temp = "connection refused"; | 533 | temp = "connection refused"; |
527 | if (code == QSocket::ErrSocketRead) | 534 | if (code == QSocket::ErrSocketRead) |
528 | temp = "socket packet error"; | 535 | temp = "socket packet error"; |
529 | 536 | ||
530 | if (code != ErrCancel) { | 537 | if (code != ErrCancel) { |
531 | QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n"); | 538 | QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n"); |
532 | } else { | 539 | } else { |
533 | status2Label->setText("Aborted by user"); | 540 | status2Label->setText("Aborted by user"); |
534 | } | 541 | } |
535 | 542 | ||
536 | receiving = FALSE; | 543 | receiving = FALSE; |
537 | getMailButton->setEnabled(TRUE); | 544 | getMailButton->setEnabled(TRUE); |
538 | cancelButton->setEnabled(FALSE); | 545 | cancelButton->setEnabled(FALSE); |
539 | selectAccountMenu->setEnabled(TRUE); | 546 | selectAccountMenu->setEnabled(TRUE); |
540 | } | 547 | } |
541 | 548 | ||
542 | void EmailClient::inboxItemSelected() | 549 | void EmailClient::inboxItemSelected() |
543 | { | 550 | { |
544 | killTimer(timerID); | 551 | //killTimer(timerID); |
545 | 552 | ||
546 | item = (EmailListItem*) inboxView->selectedItem(); | 553 | item = (EmailListItem*) inboxView->selectedItem(); |
547 | if (item != NULL) { | 554 | if (item != NULL) { |
548 | emit viewEmail(inboxView, item->getMail()); | 555 | emit viewEmail(inboxView, item->getMail()); |
549 | } | 556 | } |
550 | } | 557 | } |
551 | 558 | ||
552 | void EmailClient::outboxItemSelected() | 559 | void EmailClient::outboxItemSelected() |
553 | { | 560 | { |
554 | killTimer(timerID); | 561 | //killTimer(timerID); |
555 | 562 | ||
556 | item = (EmailListItem*) outboxView->selectedItem(); | 563 | item = (EmailListItem*) outboxView->selectedItem(); |
557 | if (item != NULL) { | 564 | if (item != NULL) { |
558 | emit viewEmail(outboxView, item->getMail()); | 565 | emit viewEmail(outboxView, item->getMail()); |
559 | } | 566 | } |
560 | 567 | ||
561 | } | 568 | } |
562 | 569 | ||
563 | void EmailClient::readMail() | 570 | void EmailClient::readMail() |
564 | { | 571 | { |
565 | Email mail; | 572 | Email mail; |
566 | int start, stop; | 573 | int start, stop; |
567 | QString s, del; | 574 | QString s, del; |
568 | 575 | ||
569 | QFile f(getPath(FALSE) + "inbox.txt"); | 576 | QFile f(getPath(FALSE) + "inbox.txt"); |
570 | // QFileInfo fi(f); | ||
571 | //qDebug( f.name()); | ||
572 | 577 | ||
573 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 578 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
574 | QTextStream t( &f ); // use a text stream | 579 | QTextStream t( &f ); // use a text stream |
575 | s = t.read(); | 580 | s = t.read(); |
576 | f.close(); | 581 | f.close(); |
577 | 582 | ||
578 | start = 0; | 583 | start = 0; |
579 | del = "\n.\n"; | 584 | del = "\n.\n"; |
580 | while ((uint) start < s.length()) { | 585 | while ((uint) start < s.length()) { |
581 | stop = s.find(del, start); | 586 | stop = s.find(del, start); |
582 | if (stop == -1) | 587 | if (stop == -1) |
583 | stop = s.length() - del.length(); | 588 | stop = s.length() - del.length(); |
584 | 589 | ||
585 | mail.rawMail = s.mid(start, stop + del.length() - start ); | 590 | mail.rawMail = s.mid(start, stop + del.length() - start ); |
586 | start = stop + del.length(); | 591 | start = stop + del.length(); |
587 | mailArrived(mail, TRUE); | 592 | mailArrived(mail, TRUE); |
588 | } | 593 | } |
589 | } | 594 | } |
590 | 595 | ||
591 | QFile fo(getPath(FALSE) + "outbox.txt"); | 596 | QFile fo(getPath(FALSE) + "outbox.txt"); |
592 | if ( fo.open(IO_ReadOnly) ) { // file opened successfully | 597 | if ( fo.open(IO_ReadOnly) ) { // file opened successfully |
593 | QTextStream t( &fo ); // use a text stream | 598 | QTextStream t( &fo ); // use a text stream |
594 | s = t.read(); | 599 | s = t.read(); |
595 | fo.close(); | 600 | fo.close(); |
@@ -601,192 +606,164 @@ void EmailClient::readMail() | |||
601 | if (stop == -1) | 606 | if (stop == -1) |
602 | stop = s.length() - del.length(); | 607 | stop = s.length() - del.length(); |
603 | 608 | ||
604 | mail.rawMail = s.mid(start, stop + del.length() - start ); | 609 | mail.rawMail = s.mid(start, stop + del.length() - start ); |
605 | start = stop + del.length(); | 610 | start = stop + del.length(); |
606 | emailHandler->parse(mail.rawMail, lineShift, &mail); | 611 | emailHandler->parse(mail.rawMail, lineShift, &mail); |
607 | mail.sent = false; | 612 | mail.sent = false; |
608 | mail.received = false; | 613 | mail.received = false; |
609 | enqueMail(mail); | 614 | enqueMail(mail); |
610 | 615 | ||
611 | } | 616 | } |
612 | } | 617 | } |
613 | } | 618 | } |
614 | 619 | ||
615 | void EmailClient::saveMail(QString fileName, QListView *view) | 620 | void EmailClient::saveMail(QString fileName, QListView *view) |
616 | { | 621 | { |
617 | QFile f(fileName); | 622 | QFile f(fileName); |
618 | Email *mail; | 623 | Email *mail; |
619 | 624 | ||
620 | if (! f.open(IO_WriteOnly) ) { | 625 | if (! f.open(IO_WriteOnly) ) { |
621 | qWarning("could not open file"); | 626 | qWarning("could not open file"); |
622 | return; | 627 | return; |
623 | } | 628 | } |
624 | item = (EmailListItem *) view->firstChild(); | 629 | item = (EmailListItem *) view->firstChild(); |
625 | //qDebug (QString("Write : ") ); | ||
626 | QTextStream t(&f); | 630 | QTextStream t(&f); |
627 | while (item != NULL) { | 631 | while (item != NULL) { |
628 | mail = item->getMail(); | 632 | mail = item->getMail(); |
629 | //qDebug(mail->rawMail); | ||
630 | //qDebug(mail->recipients.first()); | ||
631 | t << mail->rawMail; | 633 | t << mail->rawMail; |
632 | 634 | ||
633 | mailconf->setGroup(mail->id); | 635 | mailconf->setGroup(mail->id); |
634 | mailconf->writeEntry("mailread", mail->read); | 636 | mailconf->writeEntry("mailread", mail->read); |
635 | 637 | ||
636 | item = (EmailListItem *) item->nextSibling(); | 638 | item = (EmailListItem *) item->nextSibling(); |
637 | } | 639 | } |
638 | f.close(); | 640 | f.close(); |
639 | } | 641 | } |
640 | 642 | ||
641 | //paths for mailit, is settings, inbox, enclosures | 643 | //paths for mailit, is settings, inbox, enclosures |
642 | QString EmailClient::getPath(bool enclosurePath) | 644 | QString EmailClient::getPath(bool enclosurePath) |
643 | { | 645 | { |
644 | QString basePath = "qtmail"; | 646 | QString basePath = "qtmail"; |
645 | QString enclosures = "enclosures"; | 647 | QString enclosures = "enclosures"; |
646 | 648 | ||
647 | QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); | 649 | QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); |
648 | if ( !dir.exists() ) | 650 | if ( !dir.exists() ) |
649 | dir.mkdir( dir.path() ); | 651 | dir.mkdir( dir.path() ); |
650 | 652 | ||
651 | if (enclosurePath) { | 653 | if (enclosurePath) { |
652 | dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); | 654 | dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); |
653 | 655 | ||
654 | if ( !dir.exists() ) | 656 | if ( !dir.exists() ) |
655 | dir.mkdir( dir.path() ); | 657 | dir.mkdir( dir.path() ); |
656 | 658 | ||
657 | return (dir.path() + "/"); | 659 | return (dir.path() + "/"); |
658 | 660 | ||
659 | } | 661 | } |
660 | return (dir.path() + "/"); | 662 | return (dir.path() + "/"); |
661 | } | 663 | } |
662 | 664 | ||
663 | void EmailClient::readSettings() | 665 | void EmailClient::readSettings() |
664 | { | 666 | { |
665 | TextParser *p; | 667 | int y,acc_count, accountPos=0; |
666 | QString s; | ||
667 | int pos, accountPos, y; | ||
668 | QFile f( getPath(FALSE) + "settings.txt"); | ||
669 | |||
670 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | ||
671 | QTextStream t( &f ); // use a text stream | ||
672 | s = t.read(); | ||
673 | f.close(); | ||
674 | |||
675 | p = new TextParser(s, "\n"); | ||
676 | |||
677 | accountPos = 0; | ||
678 | while ( (accountPos = p->find("ACCOUNTSTART",';', accountPos, TRUE)) != -1 ) { | ||
679 | accountPos++; | ||
680 | if ( (pos = p->find("ACCOUNTNAME",':', accountPos, TRUE)) != -1 ) | ||
681 | account.accountName = p->getString(& ++pos, 'z', TRUE); | ||
682 | if ( (pos = p->find("NAME",':', accountPos, TRUE)) != -1) | ||
683 | account.name = p->getString(& ++pos, 'z', TRUE); | ||
684 | if ( (pos = p->find("EMAIL",':', accountPos, TRUE)) != -1) | ||
685 | account.emailAddress = p->getString(& ++pos, 'z', TRUE); | ||
686 | if ( (pos = p->find("POPUSER",':', accountPos, TRUE)) != -1) | ||
687 | account.popUserName = p->getString(& ++pos, 'z', TRUE); | ||
688 | if ( (pos = p->find("POPPASSWORD",':', accountPos, TRUE)) != -1) | ||
689 | account.popPasswd = p->getString(& ++pos, 'z', TRUE); | ||
690 | if ( (pos = p->find("POPSERVER",':', accountPos, TRUE)) != -1) | ||
691 | account.popServer = p->getString(& ++pos, 'z', TRUE); | ||
692 | if ( (pos = p->find("SMTPSERVER",':', accountPos, TRUE)) != -1) | ||
693 | account.smtpServer = p->getString(& ++pos, 'z', TRUE); | ||
694 | if ( (pos = p->find("ACCOUNTID",':', accountPos, TRUE)) != -1) { | ||
695 | s = p->getString(& ++pos, 'z', TRUE); | ||
696 | account.id = s.toInt(); | ||
697 | } | ||
698 | 668 | ||
669 | mailconf->setGroup("mailitglobal"); | ||
670 | acc_count=mailconf->readNumEntry("Accounts",0); | ||
671 | |||
672 | for (int accountPos = 0;accountPos<acc_count ; accountPos++) | ||
673 | { | ||
674 | mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ... | ||
675 | account.accountName = mailconf->readEntry("AccName",""); | ||
676 | account.name = mailconf->readEntry("UserName",""); | ||
677 | account.emailAddress = mailconf->readEntry("Email",""); | ||
678 | account.popUserName = mailconf->readEntry("POPUser",""); | ||
679 | account.popPasswd = mailconf->readEntryCrypt("POPPassword",""); | ||
680 | account.popServer = mailconf->readEntry("POPServer",""); | ||
681 | account.smtpServer = mailconf->readEntry("SMTPServer",""); | ||
682 | account.id = mailconf->readNumEntry("AccountId",0); | ||
683 | account.syncLimit = mailconf->readNumEntry("HeaderLimit",0); | ||
699 | account.lastServerMailCount = 0; | 684 | account.lastServerMailCount = 0; |
700 | account.synchronize = FALSE; | 685 | account.synchronize = FALSE; |
701 | if ( (pos = p->find("SYNCHRONIZE",':', accountPos, TRUE)) != -1) { | ||
702 | if (p->getString(& ++pos, 'z', TRUE).upper() == "YES") { | ||
703 | account.synchronize = TRUE; | ||
704 | if ( (pos = p->find("LASTSERVERMAILCOUNT",':', accountPos, TRUE)) != -1) { | ||
705 | s = p->getString(& ++pos, 'z', TRUE); | ||
706 | account.lastServerMailCount = s.toInt(); | ||
707 | } | ||
708 | } | ||
709 | } | ||
710 | 686 | ||
711 | if ( (pos = p->find("SYNCLIMIT",':', accountPos, TRUE)) != -1) { | 687 | account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes"); |
712 | account.syncLimit = p->getString(& ++pos, 'z', TRUE).toInt(); | 688 | if (account.synchronize) |
689 | { | ||
690 | mailconf->readNumEntry("LASTSERVERMAILCOUNT",0); | ||
713 | } | 691 | } |
714 | 692 | ||
715 | |||
716 | accountList.append(&account); | 693 | accountList.append(&account); |
717 | } | 694 | } |
718 | delete p; | 695 | |
719 | } | ||
720 | mailconf->setGroup("mailitglobal"); | 696 | mailconf->setGroup("mailitglobal"); |
721 | if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) { | 697 | |
698 | if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) | ||
699 | { | ||
722 | mailIdCount = y; | 700 | mailIdCount = y; |
723 | } | 701 | } |
724 | if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) { | 702 | if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) |
703 | { | ||
725 | accountIdCount = y; | 704 | accountIdCount = y; |
726 | } | 705 | } |
727 | } | 706 | } |
728 | 707 | ||
729 | void EmailClient::saveSettings() | 708 | void EmailClient::saveSettings() |
730 | { | 709 | { |
731 | 710 | int acc_count=0; | |
732 | QString temp; | ||
733 | QFile f( getPath(FALSE) + "settings.txt"); | ||
734 | MailAccount *accountPtr; | 711 | MailAccount *accountPtr; |
735 | 712 | ||
736 | if (! f.open(IO_WriteOnly) ) { | 713 | |
737 | qWarning("could not save settings file"); | 714 | if (!mailconf) |
715 | { | ||
716 | qWarning("could not save settings"); | ||
738 | return; | 717 | return; |
739 | } | 718 | } |
740 | QTextStream t(&f); | ||
741 | t << "#Settings for OPIE Mailit program\n"; | ||
742 | 719 | ||
743 | for (accountPtr = accountList.first(); accountPtr != 0; | 720 | for (accountPtr = accountList.first(); accountPtr != 0; |
744 | accountPtr = accountList.next()) { | 721 | accountPtr = accountList.next()) |
745 | 722 | { | |
746 | t << "accountStart;\n"; | 723 | mailconf->setGroup("Account_"+QString::number(++acc_count)); |
747 | t << "AccountName: " + accountPtr->accountName + "\n"; | 724 | mailconf->writeEntry("AccName",accountPtr->accountName ); |
748 | t << "Name: " + accountPtr->name + "\n"; | 725 | mailconf->writeEntry("UserName",accountPtr->name); |
749 | t << "Email: " + accountPtr->emailAddress + "\n"; | 726 | mailconf->writeEntry("Email",accountPtr->emailAddress); |
750 | t << "POPUser: " + accountPtr->popUserName + "\n"; | 727 | mailconf->writeEntry("POPUser",accountPtr->popUserName); |
751 | t << "POPPAssword: " + accountPtr->popPasswd + "\n"; | 728 | mailconf->writeEntryCrypt("POPPassword",accountPtr->popPasswd); |
752 | t << "POPServer: " + accountPtr->popServer + "\n"; | 729 | mailconf->writeEntry("POPServer",accountPtr->popServer); |
753 | t << "SMTPServer: " + accountPtr->smtpServer + "\n"; | 730 | mailconf->writeEntry("SMTPServer",accountPtr->smtpServer); |
754 | t << "AccountId: " << accountPtr->id << "\n"; | 731 | mailconf->writeEntry("AccountId",accountPtr->id); |
755 | if (accountPtr->synchronize) { | 732 | if (accountPtr->synchronize) |
756 | t << "Synchronize: Yes\n"; | 733 | { |
757 | t << "LastServerMailCount: "; | 734 | mailconf->writeEntry("Synchronize","Yes"); |
758 | t << accountPtr->lastServerMailCount << "\n"; | 735 | mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit); |
759 | } else { | 736 | mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount); |
760 | t << "Synchronize: No\n"; | 737 | } |
738 | else | ||
739 | { | ||
740 | mailconf->writeEntry("Synchronize", "No"); | ||
761 | } | 741 | } |
762 | t << "SyncLimit: "; | ||
763 | t << accountPtr->syncLimit << "\n"; | ||
764 | t << "accountEnd;\n"; | ||
765 | } | 742 | } |
766 | f.close(); | ||
767 | 743 | ||
768 | mailconf->setGroup("mailitglobal"); | 744 | mailconf->setGroup("mailitglobal"); |
745 | mailconf->writeEntry("Accounts",acc_count); | ||
769 | mailconf->writeEntry("mailidcount", mailIdCount); | 746 | mailconf->writeEntry("mailidcount", mailIdCount); |
770 | mailconf->writeEntry("accountidcount", accountIdCount); | 747 | mailconf->writeEntry("accountidcount", accountIdCount); |
771 | } | 748 | } |
772 | 749 | ||
773 | void EmailClient::selectAccount(int id) | 750 | void EmailClient::selectAccount(int id) |
774 | { | 751 | { |
775 | if (accountList.count() > 0) { | 752 | if (accountList.count() > 0) { |
776 | currentAccount = accountList.at(id); | 753 | currentAccount = accountList.at(id); |
777 | emit newCaption("Mailit - " + currentAccount->accountName); | 754 | emit newCaption("Mailit - " + currentAccount->accountName); |
778 | getNewMail(); | 755 | getNewMail(); |
779 | } else { | 756 | } else { |
780 | emit newCaption("Mailit ! No account defined"); | 757 | emit newCaption("Mailit ! No account defined"); |
781 | } | 758 | } |
782 | } | 759 | } |
783 | 760 | ||
784 | void EmailClient::editAccount(int id) | 761 | void EmailClient::editAccount(int id) |
785 | { | 762 | { |
786 | MailAccount *newAccount; | 763 | MailAccount *newAccount; |
787 | 764 | ||
788 | editAccountView = new EditAccount(this, "account", TRUE); | 765 | editAccountView = new EditAccount(this, "account", TRUE); |
789 | if (id == newAccountId) { //new account | 766 | if (id == newAccountId) { //new account |
790 | newAccount = new MailAccount; | 767 | newAccount = new MailAccount; |
791 | editAccountView->setAccount(newAccount); | 768 | editAccountView->setAccount(newAccount); |
792 | } else { | 769 | } else { |