-rw-r--r-- | noncore/net/mailit/emailclient.cpp | 75 | ||||
-rw-r--r-- | noncore/net/mailit/emailclient.h | 3 | ||||
-rw-r--r-- | noncore/net/mailit/emailhandler.cpp | 16 | ||||
-rw-r--r-- | noncore/net/mailit/emailhandler.h | 1 | ||||
-rw-r--r-- | noncore/net/mailit/mailitwindow.cpp | 26 | ||||
-rw-r--r-- | noncore/net/mailit/popclient.cpp | 80 | ||||
-rw-r--r-- | noncore/net/mailit/writemail.cpp | 28 | ||||
-rw-r--r-- | noncore/unsupported/mailit/emailclient.cpp | 75 | ||||
-rw-r--r-- | noncore/unsupported/mailit/emailclient.h | 3 | ||||
-rw-r--r-- | noncore/unsupported/mailit/emailhandler.cpp | 16 | ||||
-rw-r--r-- | noncore/unsupported/mailit/emailhandler.h | 1 | ||||
-rw-r--r-- | noncore/unsupported/mailit/mailitwindow.cpp | 26 | ||||
-rw-r--r-- | noncore/unsupported/mailit/popclient.cpp | 80 | ||||
-rw-r--r-- | noncore/unsupported/mailit/writemail.cpp | 28 |
14 files changed, 208 insertions, 250 deletions
diff --git a/noncore/net/mailit/emailclient.cpp b/noncore/net/mailit/emailclient.cpp index 23059cf..dff1888 100644 --- a/noncore/net/mailit/emailclient.cpp +++ b/noncore/net/mailit/emailclient.cpp | |||
@@ -1,981 +1,968 @@ | |||
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 <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 <qwhatsthis.h> |
27 | #include <qpe/resource.h> | 27 | #include <qpe/resource.h> |
28 | #include "emailclient.h" | 28 | #include "emailclient.h" |
29 | 29 | ||
30 | QCollection::Item AccountList::newItem(QCollection::Item d) | 30 | QCollection::Item AccountList::newItem(QCollection::Item d) |
31 | { | 31 | { |
32 | return dupl( (MailAccount *) d); | 32 | return dupl( (MailAccount *) d); |
33 | } | 33 | } |
34 | 34 | ||
35 | MailAccount* AccountList::dupl(MailAccount *in) | 35 | MailAccount* AccountList::dupl(MailAccount *in) |
36 | { | 36 | { |
37 | ac = new MailAccount(*in); | 37 | ac = new MailAccount(*in); |
38 | return ac; | 38 | return ac; |
39 | } | 39 | } |
40 | 40 | ||
41 | EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl ) | 41 | EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl ) |
42 | : QMainWindow( parent, name, fl ) | 42 | : QMainWindow( parent, name, fl ) |
43 | { | 43 | { |
44 | emailHandler = new EmailHandler(); | 44 | emailHandler = new EmailHandler(); |
45 | addressList = new AddressList(); | 45 | addressList = new AddressList(); |
46 | 46 | ||
47 | sending = FALSE; | 47 | sending = FALSE; |
48 | receiving = FALSE; | 48 | receiving = FALSE; |
49 | previewingMail = FALSE; | 49 | previewingMail = FALSE; |
50 | mailIdCount = 1; | 50 | mailIdCount = 1; |
51 | accountIdCount = 1; | 51 | accountIdCount = 1; |
52 | allAccounts = FALSE; | 52 | allAccounts = FALSE; |
53 | 53 | ||
54 | init(); | 54 | init(); |
55 | 55 | ||
56 | connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) ); | 56 | connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) ); |
57 | 57 | ||
58 | connect(emailHandler, SIGNAL(smtpError(int)), this, | 58 | connect(emailHandler, SIGNAL(smtpError(int)), this, |
59 | SLOT(smtpError(int)) ); | 59 | SLOT(smtpError(int)) ); |
60 | connect(emailHandler, SIGNAL(popError(int)), this, | 60 | connect(emailHandler, SIGNAL(popError(int)), this, |
61 | SLOT(popError(int)) ); | 61 | SLOT(popError(int)) ); |
62 | 62 | ||
63 | connect(inboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(inboxItemSelected()) ); | 63 | connect(inboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(inboxItemSelected()) ); |
64 | connect(outboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(outboxItemSelected()) ); | 64 | connect(outboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(outboxItemSelected()) ); |
65 | 65 | ||
66 | connect(inboxView, SIGNAL(pressed(QListViewItem *)), this, SLOT(inboxItemPressed()) ); | 66 | connect(inboxView, SIGNAL(pressed(QListViewItem *)), this, SLOT(inboxItemPressed()) ); |
67 | connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemReleased()) ); | 67 | connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemReleased()) ); |
68 | 68 | ||
69 | 69 | ||
70 | connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this, | 70 | connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this, |
71 | SLOT(mailArrived(const Email &, bool)) ); | 71 | SLOT(mailArrived(const Email &, bool)) ); |
72 | connect(emailHandler, SIGNAL(mailTransfered(int)), this, | 72 | connect(emailHandler, SIGNAL(mailTransfered(int)), this, |
73 | SLOT(allMailArrived(int)) ); | 73 | SLOT(allMailArrived(int)) ); |
74 | 74 | ||
75 | mailconf = new Config("mailit"); | 75 | mailconf = new Config("mailit"); |
76 | //In case Synchronize is not defined in settings.txt | 76 | //In case Synchronize is not defined in settings.txt |
77 | 77 | ||
78 | readSettings(); | 78 | readSettings(); |
79 | 79 | ||
80 | updateAccounts(); | 80 | updateAccounts(); |
81 | 81 | ||
82 | lineShift = "\n"; | 82 | lineShift = "\n"; |
83 | readMail(); | 83 | readMail(); |
84 | lineShift = "\r\n"; | 84 | lineShift = "\r\n"; |
85 | 85 | ||
86 | mailboxView->setCurrentTab(0); //ensure that inbox has focus | 86 | mailboxView->setCurrentTab(0); //ensure that inbox has focus |
87 | } | 87 | } |
88 | 88 | ||
89 | 89 | ||
90 | EmailClient::~EmailClient() | 90 | EmailClient::~EmailClient() |
91 | { | 91 | { |
92 | //needs to be moved from destructor to closewindow event | 92 | //needs to be moved from destructor to closewindow event |
93 | saveMail(getPath(FALSE) + "inbox.txt", inboxView); | 93 | saveMail(getPath(FALSE) + "inbox.txt", inboxView); |
94 | //does not currently work. Defining outbox in the same | 94 | //does not currently work. Defining outbox in the same |
95 | //format as inbox is not a good solution as they have | 95 | //format as inbox is not a good solution as they have |
96 | //different properties | 96 | //different properties |
97 | saveMail(getPath(FALSE) + "outbox.txt", outboxView); | 97 | saveMail(getPath(FALSE) + "outbox.txt", outboxView); |
98 | saveSettings(); | 98 | saveSettings(); |
99 | 99 | ||
100 | mailconf->write(); | 100 | mailconf->write(); |
101 | delete mailconf; | 101 | delete mailconf; |
102 | 102 | ||
103 | } | 103 | } |
104 | 104 | ||
105 | void EmailClient::init() | 105 | void EmailClient::init() |
106 | { | 106 | { |
107 | statusBar = new QStatusBar(this); | 107 | statusBar = new QStatusBar(this); |
108 | statusBar->setSizeGripEnabled(FALSE); | 108 | statusBar->setSizeGripEnabled(FALSE); |
109 | 109 | ||
110 | status1Label = new QLabel( tr("Idle"), statusBar); | 110 | status1Label = new QLabel( tr("Idle"), statusBar); |
111 | status2Label = new QLabel("", statusBar); | 111 | status2Label = new QLabel("", statusBar); |
112 | connect(emailHandler, SIGNAL(updatePopStatus(const QString &)), | 112 | connect(emailHandler, SIGNAL(updatePopStatus(const QString &)), |
113 | status2Label, SLOT(setText(const QString &)) ); | 113 | status2Label, SLOT(setText(const QString &)) ); |
114 | connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)), | 114 | connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)), |
115 | status2Label, SLOT(setText(const QString &)) ); | 115 | status2Label, SLOT(setText(const QString &)) ); |
116 | 116 | ||
117 | progressBar = new QProgressBar(statusBar); | 117 | progressBar = new QProgressBar(statusBar); |
118 | 118 | ||
119 | connect(emailHandler, SIGNAL(mailboxSize(int)), | 119 | connect(emailHandler, SIGNAL(mailboxSize(int)), |
120 | this, SLOT(setTotalSize(int)) ); | 120 | this, SLOT(setTotalSize(int)) ); |
121 | connect(emailHandler, SIGNAL(currentMailSize(int)), | 121 | connect(emailHandler, SIGNAL(currentMailSize(int)), |
122 | this, SLOT(setMailSize(int)) ); | 122 | this, SLOT(setMailSize(int)) ); |
123 | connect(emailHandler, SIGNAL(downloadedSize(int)), | 123 | connect(emailHandler, SIGNAL(downloadedSize(int)), |
124 | this, SLOT(setDownloadedSize(int)) ); | 124 | this, SLOT(setDownloadedSize(int)) ); |
125 | 125 | ||
126 | statusBar->addWidget(status1Label); | 126 | statusBar->addWidget(status1Label); |
127 | statusBar->addWidget(progressBar); | 127 | statusBar->addWidget(progressBar); |
128 | statusBar->addWidget(status2Label); | 128 | statusBar->addWidget(status2Label); |
129 | 129 | ||
130 | setToolBarsMovable(FALSE); | 130 | setToolBarsMovable(FALSE); |
131 | 131 | ||
132 | bar = new QToolBar(this); | 132 | bar = new QToolBar(this); |
133 | QWhatsThis::add(bar,tr("Main operation toolbar")); | 133 | QWhatsThis::add(bar,tr("Main operation toolbar")); |
134 | bar->setHorizontalStretchable( TRUE ); | 134 | bar->setHorizontalStretchable( TRUE ); |
135 | 135 | ||
136 | mb = new QMenuBar( bar ); | 136 | mb = new QMenuBar( bar ); |
137 | 137 | ||
138 | QPopupMenu *mail = new QPopupMenu(mb); | 138 | QPopupMenu *mail = new QPopupMenu(mb); |
139 | mb->insertItem( tr( "&Mail" ), mail); | 139 | mb->insertItem( tr( "&Mail" ), mail); |
140 | 140 | ||
141 | QPopupMenu *configure = new QPopupMenu(mb); | 141 | QPopupMenu *configure = new QPopupMenu(mb); |
142 | mb->insertItem( tr( "Accounts" ), configure); | 142 | mb->insertItem( tr( "Accounts" ), configure); |
143 | 143 | ||
144 | selectAccountMenu = new QPopupMenu(mb); | 144 | selectAccountMenu = new QPopupMenu(mb); |
145 | editAccountMenu = new QPopupMenu(mb); | 145 | editAccountMenu = new QPopupMenu(mb); |
146 | deleteAccountMenu = new QPopupMenu(mb); | 146 | deleteAccountMenu = new QPopupMenu(mb); |
147 | 147 | ||
148 | mail->insertItem(tr("Get Mail in"), selectAccountMenu); | 148 | mail->insertItem(tr("Get Mail in"), selectAccountMenu); |
149 | configure->insertItem(tr("Edit account"), editAccountMenu); | 149 | configure->insertItem(tr("Edit account"), editAccountMenu); |
150 | configure->insertItem(tr("Delete account"), deleteAccountMenu); | 150 | configure->insertItem(tr("Delete account"), deleteAccountMenu); |
151 | 151 | ||
152 | bar = new QToolBar(this); | 152 | bar = new QToolBar(this); |
153 | 153 | ||
154 | 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); |
155 | QWhatsThis::add(getMailButton,tr("Click to download mail via all available accounts.\n Press and hold to select the desired account.")); | 155 | QWhatsThis::add(getMailButton,tr("Click to download mail via all available accounts.\n Press and hold to select the desired account.")); |
156 | 156 | ||
157 | getMailButton->setPopup(selectAccountMenu); | 157 | getMailButton->setPopup(selectAccountMenu); |
158 | 158 | ||
159 | 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); |
160 | connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) ); | 160 | connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) ); |
161 | sendMailButton->addTo(bar); | 161 | sendMailButton->addTo(bar); |
162 | sendMailButton->addTo(mail); | 162 | sendMailButton->addTo(mail); |
163 | sendMailButton->setWhatsThis("Send mail queued in the outbox"); | 163 | sendMailButton->setWhatsThis("Send mail queued in the outbox"); |
164 | 164 | ||
165 | 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); |
166 | connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) ); | 166 | connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) ); |
167 | composeButton->addTo(bar); | 167 | composeButton->addTo(bar); |
168 | composeButton->addTo(mail); | 168 | composeButton->addTo(mail); |
169 | composeButton->setWhatsThis("Compose a new mail"); | 169 | composeButton->setWhatsThis("Compose a new mail"); |
170 | 170 | ||
171 | 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); |
172 | connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) ); | 172 | connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) ); |
173 | cancelButton->addTo(mail); | 173 | cancelButton->addTo(mail); |
174 | cancelButton->addTo(bar); | 174 | cancelButton->addTo(bar); |
175 | cancelButton->setEnabled(FALSE); | 175 | cancelButton->setEnabled(FALSE); |
176 | cancelButton->setWhatsThis("Stop the currently active mail transfer"); | 176 | cancelButton->setWhatsThis("Stop the currently active mail transfer"); |
177 | 177 | ||
178 | 178 | ||
179 | 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 ); |
180 | connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); | 180 | connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); |
181 | deleteButton->addTo(bar); | 181 | deleteButton->addTo(bar); |
182 | deleteButton->setWhatsThis("Remove the currently selected eMail(s)"); | 182 | deleteButton->setWhatsThis("Remove the currently selected eMail(s)"); |
183 | 183 | ||
184 | mailboxView = new OTabWidget( this, "mailboxView" ); | 184 | mailboxView = new OTabWidget( this, "mailboxView" ); |
185 | 185 | ||
186 | QWidget* widget = new QWidget( mailboxView, "widget" ); | 186 | QWidget* widget = new QWidget( mailboxView, "widget" ); |
187 | grid_2 = new QGridLayout( widget ); | 187 | grid_2 = new QGridLayout( widget ); |
188 | // grid_2->setSpacing(6); | 188 | // grid_2->setSpacing(6); |
189 | // grid_2->setMargin( 11 ); | 189 | // grid_2->setMargin( 11 ); |
190 | 190 | ||
191 | inboxView = new QListView( widget, "inboxView" ); | 191 | inboxView = new QListView( widget, "inboxView" ); |
192 | inboxView->addColumn( tr( "From" ) ); | 192 | inboxView->addColumn( tr( "From" ) ); |
193 | inboxView->addColumn( tr( "Subject" ) ); | 193 | inboxView->addColumn( tr( "Subject" ) ); |
194 | inboxView->addColumn( tr( "Date" ) ); | 194 | inboxView->addColumn( tr( "Date" ) ); |
195 | inboxView->setMinimumSize( QSize( 0, 0 ) ); | 195 | inboxView->setMinimumSize( QSize( 0, 0 ) ); |
196 | 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" | 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.")); | 198 | " A blue attachment icon shows whether this mail has attachments.")); |
199 | 199 | ||
200 | grid_2->addWidget( inboxView, 2, 0 ); | 200 | grid_2->addWidget( inboxView, 2, 0 ); |
201 | mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) ); | 201 | mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) ); |
202 | 202 | ||
203 | QWidget* widget_2 = new QWidget( mailboxView, "widget_2" ); | 203 | QWidget* widget_2 = new QWidget( mailboxView, "widget_2" ); |
204 | grid_3 = new QGridLayout( widget_2 ); | 204 | grid_3 = new QGridLayout( widget_2 ); |
205 | // grid_3->setSpacing(6); | 205 | // grid_3->setSpacing(6); |
206 | // grid_3->setMargin( 11 ); | 206 | // grid_3->setMargin( 11 ); |
207 | 207 | ||
208 | outboxView = new QListView( widget_2, "outboxView" ); | 208 | outboxView = new QListView( widget_2, "outboxView" ); |
209 | outboxView->addColumn( tr( "To" ) ); | 209 | outboxView->addColumn( tr( "To" ) ); |
210 | outboxView->addColumn( tr( "Subject" ) ); | 210 | outboxView->addColumn( tr( "Subject" ) ); |
211 | outboxView->setAllColumnsShowFocus(TRUE); | 211 | outboxView->setAllColumnsShowFocus(TRUE); |
212 | 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.")); | 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.")); |
214 | grid_3->addWidget( outboxView, 0, 0 ); | 214 | grid_3->addWidget( outboxView, 0, 0 ); |
215 | mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) ); | 215 | mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) ); |
216 | 216 | ||
217 | setCentralWidget(mailboxView); | 217 | setCentralWidget(mailboxView); |
218 | 218 | ||
219 | } | 219 | } |
220 | 220 | ||
221 | void EmailClient::compose() | 221 | void EmailClient::compose() |
222 | { | 222 | { |
223 | emit composeRequested(); | 223 | emit composeRequested(); |
224 | } | 224 | } |
225 | 225 | ||
226 | void EmailClient::cancel() | 226 | void EmailClient::cancel() |
227 | { | 227 | { |
228 | emailHandler->cancel(); | 228 | emailHandler->cancel(); |
229 | } | 229 | } |
230 | 230 | ||
231 | AddressList* EmailClient::getAdrListRef() | 231 | AddressList* EmailClient::getAdrListRef() |
232 | { | 232 | { |
233 | return addressList; | 233 | return addressList; |
234 | } | 234 | } |
235 | 235 | ||
236 | //this needs to be rewritten to syncronize with outboxView | 236 | //this needs to be rewritten to syncronize with outboxView |
237 | void EmailClient::enqueMail(const Email &mail) | 237 | void EmailClient::enqueMail(const Email &mail) |
238 | { | 238 | { |
239 | if (accountList.count() == 0) { | 239 | if (accountList.count() == 0) { |
240 | QMessageBox::warning(qApp->activeWindow(), | 240 | QMessageBox::warning(qApp->activeWindow(), |
241 | 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"); |
242 | return; | 242 | return; |
243 | } | 243 | } |
244 | 244 | ||
245 | if (accountList.count() > 0) { | 245 | if (accountList.count() > 0) { |
246 | currentAccount = accountList.first(); | 246 | currentAccount = accountList.first(); |
247 | qWarning("using account " + currentAccount->name); | 247 | qWarning("using account " + currentAccount->name); |
248 | } | 248 | } |
249 | 249 | ||
250 | Email addMail = mail; | 250 | Email addMail = mail; |
251 | addMail.from = currentAccount->name; | 251 | addMail.from = currentAccount->name; |
252 | addMail.fromMail = currentAccount->emailAddress; | 252 | addMail.fromMail = currentAccount->emailAddress; |
253 | addMail.rawMail.prepend("From: " + addMail.from + "<" + addMail.fromMail + ">\n"); | 253 | addMail.rawMail.prepend("From: " + addMail.from + "<" + addMail.fromMail + ">\n"); |
254 | item = new EmailListItem(outboxView, addMail, false); | 254 | item = new EmailListItem(outboxView, addMail, false); |
255 | 255 | ||
256 | mailboxView->setCurrentTab(1); | 256 | mailboxView->setCurrentTab(1); |
257 | 257 | ||
258 | } | 258 | } |
259 | 259 | ||
260 | void EmailClient::sendQuedMail() | 260 | void EmailClient::sendQuedMail() |
261 | { | 261 | { |
262 | int count = 0; | 262 | int count = 0; |
263 | 263 | ||
264 | if (accountList.count() == 0) { | 264 | if (accountList.count() == 0) { |
265 | QMessageBox::warning(qApp->activeWindow(), "No account selected", "You must create an account", "OK\n"); | 265 | QMessageBox::warning(qApp->activeWindow(), "No account selected", "You must create an account", "OK\n"); |
266 | return; | 266 | return; |
267 | } | 267 | } |
268 | //traverse listview, find messages to send | 268 | //traverse listview, find messages to send |
269 | if (! sending) { | 269 | if (! sending) { |
270 | item = (EmailListItem *) outboxView->firstChild(); | 270 | item = (EmailListItem *) outboxView->firstChild(); |
271 | if (item != NULL) { | 271 | if (item != NULL) { |
272 | while (item != NULL) { | 272 | while (item != NULL) { |
273 | quedMessages.append(item->getMail()); | 273 | quedMessages.append(item->getMail()); |
274 | item = (EmailListItem *) item->nextSibling(); | 274 | item = (EmailListItem *) item->nextSibling(); |
275 | count++; | 275 | count++; |
276 | } | 276 | } |
277 | setMailAccount(); | 277 | setMailAccount(); |
278 | emailHandler->sendMail(&quedMessages); | 278 | emailHandler->sendMail(&quedMessages); |
279 | sending = TRUE; | 279 | sending = TRUE; |
280 | sendMailButton->setEnabled(FALSE); | 280 | sendMailButton->setEnabled(FALSE); |
281 | cancelButton->setEnabled(TRUE); | 281 | cancelButton->setEnabled(TRUE); |
282 | } else { | 282 | } else { |
283 | qWarning("sendQuedMail(): no messages to send"); | 283 | qWarning("sendQuedMail(): no messages to send"); |
284 | } | 284 | } |
285 | } | 285 | } |
286 | } | 286 | } |
287 | 287 | ||
288 | void EmailClient::setMailAccount() | 288 | void EmailClient::setMailAccount() |
289 | { | 289 | { |
290 | emailHandler->setAccount(*currentAccount); | 290 | emailHandler->setAccount(*currentAccount); |
291 | } | 291 | } |
292 | 292 | ||
293 | void EmailClient::mailSent() | 293 | void EmailClient::mailSent() |
294 | { | 294 | { |
295 | sending = FALSE; | 295 | sending = FALSE; |
296 | sendMailButton->setEnabled(TRUE); | 296 | sendMailButton->setEnabled(TRUE); |
297 | 297 | ||
298 | quedMessages.clear(); | 298 | quedMessages.clear(); |
299 | outboxView->clear(); //should be moved to an sentBox | 299 | outboxView->clear(); //should be moved to an sentBox |
300 | } | 300 | } |
301 | 301 | ||
302 | void EmailClient::getNewMail() { | 302 | void EmailClient::getNewMail() { |
303 | 303 | ||
304 | if (accountList.count() == 0) { | 304 | if (accountList.count() == 0) { |
305 | QMessageBox::warning(qApp->activeWindow(),"No account selected", | 305 | QMessageBox::warning(qApp->activeWindow(),"No account selected", |
306 | "You must create an account", "OK\n"); | 306 | "You must create an account", "OK\n"); |
307 | return; | 307 | return; |
308 | } | 308 | } |
309 | 309 | ||
310 | setMailAccount(); | 310 | setMailAccount(); |
311 | 311 | ||
312 | receiving = TRUE; | 312 | receiving = TRUE; |
313 | previewingMail = TRUE; | 313 | previewingMail = TRUE; |
314 | getMailButton->setEnabled(FALSE); | 314 | getMailButton->setEnabled(FALSE); |
315 | cancelButton->setEnabled(TRUE); | 315 | cancelButton->setEnabled(TRUE); |
316 | selectAccountMenu->setEnabled(FALSE); | 316 | selectAccountMenu->setEnabled(FALSE); |
317 | 317 | ||
318 | status1Label->setText(currentAccount->accountName + " headers"); | 318 | status1Label->setText(currentAccount->accountName + " headers"); |
319 | progressBar->reset(); | 319 | progressBar->reset(); |
320 | 320 | ||
321 | //get any previous mails not downloaded and add to queue | 321 | //get any previous mails not downloaded and add to queue |
322 | mailDownloadList.clear(); | 322 | mailDownloadList.clear(); |
323 | Email *mailPtr; | 323 | Email *mailPtr; |
324 | item = (EmailListItem *) inboxView->firstChild(); | 324 | item = (EmailListItem *) inboxView->firstChild(); |
325 | while (item != NULL) { | 325 | while (item != NULL) { |
326 | mailPtr = item->getMail(); | 326 | mailPtr = item->getMail(); |
327 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { | 327 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { |
328 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); | 328 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); |
329 | } | 329 | } |
330 | item = (EmailListItem *) item->nextSibling(); | 330 | item = (EmailListItem *) item->nextSibling(); |
331 | } | 331 | } |
332 | 332 | ||
333 | emailHandler->getMailHeaders(); | 333 | emailHandler->getMailHeaders(); |
334 | 334 | ||
335 | } | 335 | } |
336 | 336 | ||
337 | void EmailClient::getAllNewMail() | 337 | void EmailClient::getAllNewMail() |
338 | { | 338 | { |
339 | allAccounts = TRUE; | 339 | allAccounts = TRUE; |
340 | currentAccount = accountList.first(); | 340 | currentAccount = accountList.first(); |
341 | getNewMail(); | 341 | getNewMail(); |
342 | } | 342 | } |
343 | 343 | ||
344 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) | 344 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) |
345 | { | 345 | { |
346 | Enclosure *ePtr; | 346 | Enclosure *ePtr; |
347 | Email newMail; | 347 | Email newMail; |
348 | int thisMailId; | 348 | int thisMailId; |
349 | emailHandler->parse(mail.rawMail, lineShift, &newMail); | 349 | emailHandler->parse(mail.rawMail, lineShift, &newMail); |
350 | mailconf->setGroup(newMail.id); | 350 | mailconf->setGroup(newMail.id); |
351 | 351 | ||
352 | if (fromDisk) | 352 | if (fromDisk) |
353 | { | 353 | { |
354 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); | 354 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); |
355 | newMail.size = mailconf->readNumEntry("size"); | 355 | newMail.size = mailconf->readNumEntry("size"); |
356 | newMail.serverId = mailconf->readNumEntry("serverid"); | 356 | newMail.serverId = mailconf->readNumEntry("serverid"); |
357 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); | 357 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); |
358 | } | 358 | } |
359 | else | 359 | else |
360 | { //mail arrived from server | 360 | { //mail arrived from server |
361 | newMail.serverId = mail.serverId; | 361 | newMail.serverId = mail.serverId; |
362 | newMail.size = mail.size; | 362 | newMail.size = mail.size; |
363 | newMail.downloaded = mail.downloaded; | 363 | newMail.downloaded = mail.downloaded; |
364 | 364 | ||
365 | newMail.fromAccountId = currentAccount->id; | 365 | newMail.fromAccountId = emailHandler->getAccount()->id; |
366 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); | 366 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); |
367 | } | 367 | } |
368 | 368 | ||
369 | //add if read or not | 369 | //add if read or not |
370 | newMail.read = mailconf->readBoolEntry("mailread"); | 370 | newMail.read = mailconf->readBoolEntry("mailread"); |
371 | 371 | ||
372 | //check if new mail | 372 | //check if new mail |
373 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { | 373 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { |
374 | thisMailId = mailIdCount; | 374 | thisMailId = mailIdCount; |
375 | mailIdCount++; | 375 | mailIdCount++; |
376 | 376 | ||
377 | //set server count, so that if the user aborts, the new | 377 | //set server count, so that if the user aborts, the new |
378 | //header is not reloaded | 378 | //header is not reloaded |
379 | if ((currentAccount)&&(currentAccount->synchronize)) | 379 | if ((currentAccount)&&(currentAccount->synchronize)) |
380 | currentAccount->lastServerMailCount++; | 380 | currentAccount->lastServerMailCount++; |
381 | 381 | ||
382 | mailconf->writeEntry("internalmailid", thisMailId); | 382 | mailconf->writeEntry("internalmailid", thisMailId); |
383 | mailconf->writeEntry("downloaded", newMail.downloaded); | 383 | mailconf->writeEntry("downloaded", newMail.downloaded); |
384 | mailconf->writeEntry("size", (int) newMail.size); | 384 | mailconf->writeEntry("size", (int) newMail.size); |
385 | mailconf->writeEntry("serverid", newMail.serverId); | 385 | mailconf->writeEntry("serverid", newMail.serverId); |
386 | 386 | ||
387 | //addressList->addContact(newMail.fromMail, newMail.from); | 387 | //addressList->addContact(newMail.fromMail, newMail.from); |
388 | } | 388 | } |
389 | 389 | ||
390 | mailconf->writeEntry("downloaded", newMail.downloaded); | 390 | mailconf->writeEntry("downloaded", newMail.downloaded); |
391 | 391 | ||
392 | QString stringMailId; | 392 | QString stringMailId; |
393 | stringMailId.setNum(thisMailId); | 393 | stringMailId.setNum(thisMailId); |
394 | //see if any attatchments needs to be stored | 394 | //see if any attatchments needs to be stored |
395 | 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 | 429 | ||
430 | bool found=false; | 430 | bool found=false; |
431 | 431 | ||
432 | if (!fromDisk) | 432 | if (!fromDisk) |
433 | { | 433 | { |
434 | 434 | ||
435 | Email *mailPtr; | 435 | Email *mailPtr; |
436 | item = (EmailListItem *) inboxView->firstChild(); | 436 | item = (EmailListItem *) inboxView->firstChild(); |
437 | while ((item != NULL)&&(!found)) | 437 | while ((item != NULL)&&(!found)) |
438 | { | 438 | { |
439 | mailPtr = item->getMail(); | 439 | mailPtr = item->getMail(); |
440 | if (mailPtr->id == newMail.id) { | 440 | if (mailPtr->id == newMail.id) { |
441 | item->setMail(newMail); | 441 | item->setMail(newMail); |
442 | emit mailUpdated(item->getMail()); | 442 | emit mailUpdated(item->getMail()); |
443 | found = true; | 443 | found = true; |
444 | } | 444 | } |
445 | item = (EmailListItem *) item->nextSibling(); | 445 | item = (EmailListItem *) item->nextSibling(); |
446 | } | 446 | } |
447 | } | 447 | } |
448 | if ((!found)||(fromDisk)) item = new EmailListItem(inboxView, newMail, TRUE); | 448 | if ((!found)||(fromDisk)) item = new EmailListItem(inboxView, newMail, TRUE); |
449 | 449 | ||
450 | /*if (!newMail.downloaded) | 450 | /*if (!newMail.downloaded) |
451 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ | 451 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ |
452 | 452 | ||
453 | mailboxView->setCurrentTab(0); | 453 | mailboxView->setCurrentTab(0); |
454 | 454 | ||
455 | } | 455 | } |
456 | 456 | ||
457 | void EmailClient::allMailArrived(int count) | 457 | void EmailClient::allMailArrived(int count) |
458 | { | 458 | { |
459 | // not previewing means all mailtransfer has been done | 459 | // not previewing means all mailtransfer has been done |
460 | /*if (!previewingMail) {*/ | 460 | /*if (!previewingMail) {*/ |
461 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { | 461 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { |
462 | emit newCaption("Mailit - " + currentAccount->accountName); | 462 | emit newCaption("Mailit - " + currentAccount->accountName); |
463 | getNewMail(); | 463 | getNewMail(); |
464 | return; | 464 | return; |
465 | } else { | 465 | } else { |
466 | allAccounts = FALSE; | 466 | allAccounts = FALSE; |
467 | receiving = FALSE; | 467 | receiving = FALSE; |
468 | getMailButton->setEnabled(TRUE); | 468 | getMailButton->setEnabled(TRUE); |
469 | cancelButton->setEnabled(FALSE); | 469 | cancelButton->setEnabled(FALSE); |
470 | selectAccountMenu->setEnabled(TRUE); | 470 | selectAccountMenu->setEnabled(TRUE); |
471 | status1Label->setText("Idle"); | 471 | status1Label->setText("Idle"); |
472 | 472 | ||
473 | progressBar->reset(); | 473 | progressBar->reset(); |
474 | return; | 474 | return; |
475 | } | 475 | } |
476 | //} | 476 | //} |
477 | 477 | ||
478 | // all headers downloaded from server, start downloading remaining mails | 478 | // all headers downloaded from server, start downloading remaining mails |
479 | previewingMail = FALSE; | 479 | previewingMail = FALSE; |
480 | status1Label->setText(currentAccount->accountName); | 480 | status1Label->setText(currentAccount->accountName); |
481 | progressBar->reset(); | 481 | progressBar->reset(); |
482 | 482 | ||
483 | //emailHandler->getMailByList(&mailDownloadList); | 483 | |
484 | |||
485 | mailboxView->setCurrentTab(0); | 484 | mailboxView->setCurrentTab(0); |
486 | } | 485 | } |
487 | 486 | ||
487 | |||
488 | void EmailClient::moveMailFront(Email *mailPtr) | 488 | void EmailClient::moveMailFront(Email *mailPtr) |
489 | { | 489 | { |
490 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { | 490 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { |
491 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); | 491 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); |
492 | } | 492 | } |
493 | } | 493 | } |
494 | 494 | ||
495 | void EmailClient::smtpError(int code) | 495 | void EmailClient::smtpError(int code) |
496 | { | 496 | { |
497 | QString temp; | 497 | QString temp; |
498 | 498 | ||
499 | if (code == ErrUnknownResponse) | 499 | if (code == ErrUnknownResponse) |
500 | temp = "Unknown response from server"; | 500 | temp = "Unknown response from server"; |
501 | 501 | ||
502 | if (code == QSocket::ErrHostNotFound) | 502 | if (code == QSocket::ErrHostNotFound) |
503 | temp = "host not found"; | 503 | temp = "host not found"; |
504 | if (code == QSocket::ErrConnectionRefused) | 504 | if (code == QSocket::ErrConnectionRefused) |
505 | temp = "connection refused"; | 505 | temp = "connection refused"; |
506 | if (code == QSocket::ErrSocketRead) | 506 | if (code == QSocket::ErrSocketRead) |
507 | temp = "socket packet error"; | 507 | temp = "socket packet error"; |
508 | 508 | ||
509 | if (code != ErrCancel) { | 509 | if (code != ErrCancel) { |
510 | QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); | 510 | QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); |
511 | } else { | 511 | } else { |
512 | status2Label->setText("Aborted by user"); | 512 | status2Label->setText("Aborted by user"); |
513 | } | 513 | } |
514 | 514 | ||
515 | sending = FALSE; | 515 | sending = FALSE; |
516 | sendMailButton->setEnabled(TRUE); | 516 | sendMailButton->setEnabled(TRUE); |
517 | cancelButton->setEnabled(FALSE); | 517 | cancelButton->setEnabled(FALSE); |
518 | quedMessages.clear(); | 518 | quedMessages.clear(); |
519 | } | 519 | } |
520 | 520 | ||
521 | void EmailClient::popError(int code) | 521 | void EmailClient::popError(int code) |
522 | { | 522 | { |
523 | QString temp; | 523 | QString temp; |
524 | 524 | ||
525 | if (code == ErrUnknownResponse) | 525 | if (code == ErrUnknownResponse) |
526 | temp = "Unknown response from server"; | 526 | temp = "Unknown response from server"; |
527 | if (code == ErrLoginFailed) | 527 | if (code == ErrLoginFailed) |
528 | temp = "Login failed\nCheck user name and password"; | 528 | temp = "Login failed\nCheck user name and password"; |
529 | 529 | ||
530 | if (code == QSocket::ErrHostNotFound) | 530 | if (code == QSocket::ErrHostNotFound) |
531 | temp = "host not found"; | 531 | temp = "host not found"; |
532 | if (code == QSocket::ErrConnectionRefused) | 532 | if (code == QSocket::ErrConnectionRefused) |
533 | temp = "connection refused"; | 533 | temp = "connection refused"; |
534 | if (code == QSocket::ErrSocketRead) | 534 | if (code == QSocket::ErrSocketRead) |
535 | temp = "socket packet error"; | 535 | temp = "socket packet error"; |
536 | 536 | ||
537 | if (code != ErrCancel) { | 537 | if (code != ErrCancel) { |
538 | QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n"); | 538 | QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n"); |
539 | } else { | 539 | } else { |
540 | status2Label->setText("Aborted by user"); | 540 | status2Label->setText("Aborted by user"); |
541 | } | 541 | } |
542 | 542 | ||
543 | receiving = FALSE; | 543 | receiving = FALSE; |
544 | getMailButton->setEnabled(TRUE); | 544 | getMailButton->setEnabled(TRUE); |
545 | cancelButton->setEnabled(FALSE); | 545 | cancelButton->setEnabled(FALSE); |
546 | selectAccountMenu->setEnabled(TRUE); | 546 | selectAccountMenu->setEnabled(TRUE); |
547 | } | 547 | } |
548 | 548 | ||
549 | void EmailClient::inboxItemSelected() | 549 | void EmailClient::inboxItemSelected() |
550 | { | 550 | { |
551 | //killTimer(timerID); | 551 | //killTimer(timerID); |
552 | 552 | ||
553 | item = (EmailListItem*) inboxView->selectedItem(); | 553 | item = (EmailListItem*) inboxView->selectedItem(); |
554 | if (item != NULL) { | 554 | if (item != NULL) { |
555 | emit viewEmail(inboxView, item->getMail()); | 555 | emit viewEmail(inboxView, item->getMail()); |
556 | } | 556 | } |
557 | } | 557 | } |
558 | 558 | ||
559 | void EmailClient::outboxItemSelected() | 559 | void EmailClient::outboxItemSelected() |
560 | { | 560 | { |
561 | //killTimer(timerID); | 561 | //killTimer(timerID); |
562 | 562 | ||
563 | item = (EmailListItem*) outboxView->selectedItem(); | 563 | item = (EmailListItem*) outboxView->selectedItem(); |
564 | if (item != NULL) { | 564 | if (item != NULL) { |
565 | emit viewEmail(outboxView, item->getMail()); | 565 | emit viewEmail(outboxView, item->getMail()); |
566 | } | 566 | } |
567 | 567 | ||
568 | } | 568 | } |
569 | 569 | ||
570 | void EmailClient::readMail() | 570 | void EmailClient::readMail() |
571 | { | 571 | { |
572 | Email mail; | 572 | Email mail; |
573 | int start, stop; | 573 | int start, stop; |
574 | QString s, del; | 574 | QString s, del; |
575 | 575 | ||
576 | QFile f(getPath(FALSE) + "inbox.txt"); | 576 | QFile f(getPath(FALSE) + "inbox.txt"); |
577 | 577 | ||
578 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 578 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
579 | QTextStream t( &f ); // use a text stream | 579 | QTextStream t( &f ); // use a text stream |
580 | s = t.read(); | 580 | s = t.read(); |
581 | f.close(); | 581 | f.close(); |
582 | 582 | ||
583 | start = 0; | 583 | start = 0; |
584 | del = "\n.\n"; | 584 | del = "\n.\n"; |
585 | while ((uint) start < s.length()) { | 585 | while ((uint) start < s.length()) { |
586 | stop = s.find(del, start); | 586 | stop = s.find(del, start); |
587 | if (stop == -1) | 587 | if (stop == -1) |
588 | stop = s.length() - del.length(); | 588 | stop = s.length() - del.length(); |
589 | 589 | ||
590 | mail.rawMail = s.mid(start, stop + del.length() - start ); | 590 | mail.rawMail = s.mid(start, stop + del.length() - start ); |
591 | start = stop + del.length(); | 591 | start = stop + del.length(); |
592 | mailArrived(mail, TRUE); | 592 | mailArrived(mail, TRUE); |
593 | } | 593 | } |
594 | } | 594 | } |
595 | 595 | ||
596 | QFile fo(getPath(FALSE) + "outbox.txt"); | 596 | QFile fo(getPath(FALSE) + "outbox.txt"); |
597 | if ( fo.open(IO_ReadOnly) ) { // file opened successfully | 597 | if ( fo.open(IO_ReadOnly) ) { // file opened successfully |
598 | QTextStream t( &fo ); // use a text stream | 598 | QTextStream t( &fo ); // use a text stream |
599 | s = t.read(); | 599 | s = t.read(); |
600 | fo.close(); | 600 | fo.close(); |
601 | 601 | ||
602 | start = 0; | 602 | start = 0; |
603 | del = "\n.\n"; | 603 | del = "\n.\n"; |
604 | while ((uint) start < s.length()) { | 604 | while ((uint) start < s.length()) { |
605 | stop = s.find(del, start); | 605 | stop = s.find(del, start); |
606 | if (stop == -1) | 606 | if (stop == -1) |
607 | stop = s.length() - del.length(); | 607 | stop = s.length() - del.length(); |
608 | 608 | ||
609 | mail.rawMail = s.mid(start, stop + del.length() - start ); | 609 | mail.rawMail = s.mid(start, stop + del.length() - start ); |
610 | start = stop + del.length(); | 610 | start = stop + del.length(); |
611 | emailHandler->parse(mail.rawMail, lineShift, &mail); | 611 | emailHandler->parse(mail.rawMail, lineShift, &mail); |
612 | mail.sent = false; | 612 | mail.sent = false; |
613 | mail.received = false; | 613 | mail.received = false; |
614 | enqueMail(mail); | 614 | enqueMail(mail); |
615 | 615 | ||
616 | } | 616 | } |
617 | } | 617 | } |
618 | } | 618 | } |
619 | 619 | ||
620 | void EmailClient::saveMail(QString fileName, QListView *view) | 620 | void EmailClient::saveMail(QString fileName, QListView *view) |
621 | { | 621 | { |
622 | QFile f(fileName); | 622 | QFile f(fileName); |
623 | Email *mail; | 623 | Email *mail; |
624 | 624 | ||
625 | if (! f.open(IO_WriteOnly) ) { | 625 | if (! f.open(IO_WriteOnly) ) { |
626 | qWarning("could not open file"); | 626 | qWarning("could not open file"); |
627 | return; | 627 | return; |
628 | } | 628 | } |
629 | item = (EmailListItem *) view->firstChild(); | 629 | item = (EmailListItem *) view->firstChild(); |
630 | QTextStream t(&f); | 630 | QTextStream t(&f); |
631 | while (item != NULL) { | 631 | while (item != NULL) { |
632 | mail = item->getMail(); | 632 | mail = item->getMail(); |
633 | t << mail->rawMail; | 633 | t << mail->rawMail; |
634 | 634 | ||
635 | mailconf->setGroup(mail->id); | 635 | mailconf->setGroup(mail->id); |
636 | mailconf->writeEntry("mailread", mail->read); | 636 | mailconf->writeEntry("mailread", mail->read); |
637 | 637 | ||
638 | item = (EmailListItem *) item->nextSibling(); | 638 | item = (EmailListItem *) item->nextSibling(); |
639 | } | 639 | } |
640 | f.close(); | 640 | f.close(); |
641 | } | 641 | } |
642 | 642 | ||
643 | //paths for mailit, is settings, inbox, enclosures | 643 | //paths for mailit, is settings, inbox, enclosures |
644 | QString EmailClient::getPath(bool enclosurePath) | 644 | QString EmailClient::getPath(bool enclosurePath) |
645 | { | 645 | { |
646 | QString basePath = "qtmail"; | 646 | QString basePath = "qtmail"; |
647 | QString enclosures = "enclosures"; | 647 | QString enclosures = "enclosures"; |
648 | 648 | ||
649 | QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); | 649 | QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); |
650 | if ( !dir.exists() ) | 650 | if ( !dir.exists() ) |
651 | dir.mkdir( dir.path() ); | 651 | dir.mkdir( dir.path() ); |
652 | 652 | ||
653 | if (enclosurePath) { | 653 | if (enclosurePath) { |
654 | dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); | 654 | dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); |
655 | 655 | ||
656 | if ( !dir.exists() ) | 656 | if ( !dir.exists() ) |
657 | dir.mkdir( dir.path() ); | 657 | dir.mkdir( dir.path() ); |
658 | 658 | ||
659 | return (dir.path() + "/"); | 659 | return (dir.path() + "/"); |
660 | 660 | ||
661 | } | 661 | } |
662 | return (dir.path() + "/"); | 662 | return (dir.path() + "/"); |
663 | } | 663 | } |
664 | 664 | ||
665 | void EmailClient::readSettings() | 665 | void EmailClient::readSettings() |
666 | { | 666 | { |
667 | int y,acc_count, accountPos=0; | 667 | int y,acc_count; |
668 | 668 | ||
669 | mailconf->setGroup("mailitglobal"); | 669 | mailconf->setGroup("mailitglobal"); |
670 | acc_count=mailconf->readNumEntry("Accounts",0); | 670 | acc_count=mailconf->readNumEntry("Accounts",0); |
671 | 671 | ||
672 | for (int accountPos = 0;accountPos<acc_count ; accountPos++) | 672 | for (int accountPos = 0;accountPos<acc_count ; accountPos++) |
673 | { | 673 | { |
674 | mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ... | 674 | mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ... |
675 | account.accountName = mailconf->readEntry("AccName",""); | 675 | account.accountName = mailconf->readEntry("AccName",""); |
676 | account.name = mailconf->readEntry("UserName",""); | 676 | account.name = mailconf->readEntry("UserName",""); |
677 | account.emailAddress = mailconf->readEntry("Email",""); | 677 | account.emailAddress = mailconf->readEntry("Email",""); |
678 | account.popUserName = mailconf->readEntry("POPUser",""); | 678 | account.popUserName = mailconf->readEntry("POPUser",""); |
679 | account.popPasswd = mailconf->readEntryCrypt("POPPassword",""); | 679 | account.popPasswd = mailconf->readEntryCrypt("POPPassword",""); |
680 | account.popServer = mailconf->readEntry("POPServer",""); | 680 | account.popServer = mailconf->readEntry("POPServer",""); |
681 | account.smtpServer = mailconf->readEntry("SMTPServer",""); | 681 | account.smtpServer = mailconf->readEntry("SMTPServer",""); |
682 | account.id = mailconf->readNumEntry("AccountId",0); | 682 | account.id = mailconf->readNumEntry("AccountId",0); |
683 | account.syncLimit = mailconf->readNumEntry("HeaderLimit",0); | 683 | account.syncLimit = mailconf->readNumEntry("HeaderLimit",0); |
684 | account.lastServerMailCount = 0; | 684 | account.lastServerMailCount = 0; |
685 | account.synchronize = FALSE; | 685 | account.synchronize = FALSE; |
686 | 686 | ||
687 | account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes"); | 687 | account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes"); |
688 | if (account.synchronize) | 688 | if (account.synchronize) |
689 | { | 689 | { |
690 | mailconf->readNumEntry("LASTSERVERMAILCOUNT",0); | 690 | mailconf->readNumEntry("LASTSERVERMAILCOUNT",0); |
691 | } | 691 | } |
692 | 692 | ||
693 | accountList.append(&account); | 693 | accountList.append(&account); |
694 | } | 694 | } |
695 | 695 | ||
696 | mailconf->setGroup("mailitglobal"); | 696 | mailconf->setGroup("mailitglobal"); |
697 | 697 | ||
698 | if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) | 698 | if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) |
699 | { | 699 | { |
700 | mailIdCount = y; | 700 | mailIdCount = y; |
701 | } | 701 | } |
702 | if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) | 702 | if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) |
703 | { | 703 | { |
704 | accountIdCount = y; | 704 | accountIdCount = y; |
705 | } | 705 | } |
706 | } | 706 | } |
707 | 707 | ||
708 | void EmailClient::saveSettings() | 708 | void EmailClient::saveSettings() |
709 | { | 709 | { |
710 | int acc_count=0; | 710 | int acc_count=0; |
711 | MailAccount *accountPtr; | 711 | MailAccount *accountPtr; |
712 | 712 | ||
713 | 713 | ||
714 | if (!mailconf) | 714 | if (!mailconf) |
715 | { | 715 | { |
716 | qWarning("could not save settings"); | 716 | qWarning("could not save settings"); |
717 | return; | 717 | return; |
718 | } | 718 | } |
719 | 719 | ||
720 | for (accountPtr = accountList.first(); accountPtr != 0; | 720 | for (accountPtr = accountList.first(); accountPtr != 0; |
721 | accountPtr = accountList.next()) | 721 | accountPtr = accountList.next()) |
722 | { | 722 | { |
723 | mailconf->setGroup("Account_"+QString::number(++acc_count)); | 723 | mailconf->setGroup("Account_"+QString::number(++acc_count)); |
724 | mailconf->writeEntry("AccName",accountPtr->accountName ); | 724 | mailconf->writeEntry("AccName",accountPtr->accountName ); |
725 | mailconf->writeEntry("UserName",accountPtr->name); | 725 | mailconf->writeEntry("UserName",accountPtr->name); |
726 | mailconf->writeEntry("Email",accountPtr->emailAddress); | 726 | mailconf->writeEntry("Email",accountPtr->emailAddress); |
727 | mailconf->writeEntry("POPUser",accountPtr->popUserName); | 727 | mailconf->writeEntry("POPUser",accountPtr->popUserName); |
728 | mailconf->writeEntryCrypt("POPPassword",accountPtr->popPasswd); | 728 | mailconf->writeEntryCrypt("POPPassword",accountPtr->popPasswd); |
729 | mailconf->writeEntry("POPServer",accountPtr->popServer); | 729 | mailconf->writeEntry("POPServer",accountPtr->popServer); |
730 | mailconf->writeEntry("SMTPServer",accountPtr->smtpServer); | 730 | mailconf->writeEntry("SMTPServer",accountPtr->smtpServer); |
731 | mailconf->writeEntry("AccountId",accountPtr->id); | 731 | mailconf->writeEntry("AccountId",accountPtr->id); |
732 | if (accountPtr->synchronize) | 732 | if (accountPtr->synchronize) |
733 | { | 733 | { |
734 | mailconf->writeEntry("Synchronize","Yes"); | 734 | mailconf->writeEntry("Synchronize","Yes"); |
735 | mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit); | 735 | mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit); |
736 | mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount); | 736 | mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount); |
737 | } | 737 | } |
738 | else | 738 | else |
739 | { | 739 | { |
740 | mailconf->writeEntry("Synchronize", "No"); | 740 | mailconf->writeEntry("Synchronize", "No"); |
741 | } | 741 | } |
742 | } | 742 | } |
743 | 743 | ||
744 | mailconf->setGroup("mailitglobal"); | 744 | mailconf->setGroup("mailitglobal"); |
745 | mailconf->writeEntry("Accounts",acc_count); | 745 | mailconf->writeEntry("Accounts",acc_count); |
746 | mailconf->writeEntry("mailidcount", mailIdCount); | 746 | mailconf->writeEntry("mailidcount", mailIdCount); |
747 | mailconf->writeEntry("accountidcount", accountIdCount); | 747 | mailconf->writeEntry("accountidcount", accountIdCount); |
748 | } | 748 | } |
749 | 749 | ||
750 | void EmailClient::selectAccount(int id) | 750 | void EmailClient::selectAccount(int id) |
751 | { | 751 | { |
752 | if (accountList.count() > 0) { | 752 | if (accountList.count() > 0) { |
753 | currentAccount = accountList.at(id); | 753 | currentAccount = accountList.at(id); |
754 | emit newCaption("Mailit - " + currentAccount->accountName); | 754 | emit newCaption("Mailit - " + currentAccount->accountName); |
755 | getNewMail(); | 755 | getNewMail(); |
756 | } else { | 756 | } else { |
757 | emit newCaption("Mailit ! No account defined"); | 757 | emit newCaption("Mailit ! No account defined"); |
758 | } | 758 | } |
759 | } | 759 | } |
760 | 760 | ||
761 | void EmailClient::editAccount(int id) | 761 | void EmailClient::editAccount(int id) |
762 | { | 762 | { |
763 | MailAccount *newAccount; | 763 | MailAccount *newAccount; |
764 | 764 | ||
765 | editAccountView = new EditAccount(this, "account", TRUE); | 765 | editAccountView = new EditAccount(this, "account", TRUE); |
766 | if (id == newAccountId) { //new account | 766 | if (id == newAccountId) { //new account |
767 | newAccount = new MailAccount; | 767 | newAccount = new MailAccount; |
768 | editAccountView->setAccount(newAccount); | 768 | editAccountView->setAccount(newAccount); |
769 | } else { | 769 | } else { |
770 | newAccount = accountList.at(id); | 770 | newAccount = accountList.at(id); |
771 | editAccountView->setAccount(newAccount, FALSE); | 771 | editAccountView->setAccount(newAccount, FALSE); |
772 | } | 772 | } |
773 | 773 | ||
774 | editAccountView->showMaximized(); | 774 | editAccountView->showMaximized(); |
775 | editAccountView->exec(); | 775 | editAccountView->exec(); |
776 | 776 | ||
777 | if (editAccountView->result() == QDialog::Accepted) { | 777 | if (editAccountView->result() == QDialog::Accepted) { |
778 | if (id == newAccountId) { | 778 | if (id == newAccountId) { |
779 | newAccount->id = accountIdCount; | 779 | newAccount->id = accountIdCount; |
780 | accountIdCount++; | 780 | accountIdCount++; |
781 | accountList.append(newAccount); | 781 | accountList.append(newAccount); |
782 | updateAccounts(); | 782 | updateAccounts(); |
783 | } else { | 783 | } else { |
784 | updateAccounts(); | 784 | updateAccounts(); |
785 | } | 785 | } |
786 | } | 786 | } |
787 | 787 | ||
788 | delete editAccountView; | 788 | delete editAccountView; |
789 | } | 789 | } |
790 | 790 | ||
791 | void EmailClient::deleteAccount(int id) | 791 | void EmailClient::deleteAccount(int id) |
792 | { | 792 | { |
793 | MailAccount *newAccount; | 793 | MailAccount *newAccount; |
794 | QString message; | 794 | QString message; |
795 | 795 | ||
796 | newAccount = accountList.at(id); | 796 | newAccount = accountList.at(id); |
797 | message = "Delete account:\n" + newAccount->accountName; | 797 | message = "Delete account:\n" + newAccount->accountName; |
798 | switch( QMessageBox::warning( this, "Mailit", message, | 798 | switch( QMessageBox::warning( this, "Mailit", message, |
799 | "Yes", "No", 0, 0, 1 ) ) { | 799 | "Yes", "No", 0, 0, 1 ) ) { |
800 | 800 | ||
801 | case 0: accountList.remove(id); | 801 | case 0: accountList.remove(id); |
802 | updateAccounts(); | 802 | updateAccounts(); |
803 | break; | 803 | break; |
804 | case 1: | 804 | case 1: |
805 | break; | 805 | break; |
806 | } | 806 | } |
807 | } | 807 | } |
808 | 808 | ||
809 | void EmailClient::updateAccounts() | 809 | void EmailClient::updateAccounts() |
810 | { | 810 | { |
811 | MailAccount *accountPtr; | 811 | MailAccount *accountPtr; |
812 | 812 | ||
813 | //rebuild menus, clear all first | 813 | //rebuild menus, clear all first |
814 | editAccountMenu->clear(); | 814 | editAccountMenu->clear(); |
815 | selectAccountMenu->clear(); | 815 | selectAccountMenu->clear(); |
816 | deleteAccountMenu->clear(); | 816 | deleteAccountMenu->clear(); |
817 | 817 | ||
818 | newAccountId = editAccountMenu->insertItem("New", this, | 818 | newAccountId = editAccountMenu->insertItem("New", this, |
819 | SLOT(editAccount(int)) ); | 819 | SLOT(editAccount(int)) ); |
820 | editAccountMenu->insertSeparator(); | 820 | editAccountMenu->insertSeparator(); |
821 | 821 | ||
822 | idCount = 0; | 822 | idCount = 0; |
823 | for (accountPtr = accountList.first(); accountPtr != 0; | 823 | for (accountPtr = accountList.first(); accountPtr != 0; |
824 | accountPtr = accountList.next()) { | 824 | accountPtr = accountList.next()) { |
825 | 825 | ||
826 | editAccountMenu->insertItem(accountPtr->accountName, | 826 | editAccountMenu->insertItem(accountPtr->accountName, |
827 | this, SLOT(editAccount(int)), 0, idCount); | 827 | this, SLOT(editAccount(int)), 0, idCount); |
828 | selectAccountMenu->insertItem(accountPtr->accountName, | 828 | selectAccountMenu->insertItem(accountPtr->accountName, |
829 | this, SLOT(selectAccount(int)), 0, idCount); | 829 | this, SLOT(selectAccount(int)), 0, idCount); |
830 | deleteAccountMenu->insertItem(accountPtr->accountName, | 830 | deleteAccountMenu->insertItem(accountPtr->accountName, |
831 | this, SLOT(deleteAccount(int)), 0, idCount); | 831 | this, SLOT(deleteAccount(int)), 0, idCount); |
832 | idCount++; | 832 | idCount++; |
833 | } | 833 | } |
834 | } | 834 | } |
835 | 835 | ||
836 | void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) | 836 | void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) |
837 | { | 837 | { |
838 | Email *mPtr; | 838 | Email *mPtr; |
839 | Enclosure *ePtr; | 839 | Enclosure *ePtr; |
840 | 840 | ||
841 | if (inbox) | 841 | if (inbox) |
842 | { | 842 | { |
843 | mPtr = mailItem->getMail(); | 843 | mPtr = mailItem->getMail(); |
844 | 844 | ||
845 | //if mail is in queue for download, remove it from | 845 | //if mail is in queue for download, remove it from |
846 | //queue if possible | 846 | //queue if possible |
847 | if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { | 847 | if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { |
848 | if ( !mPtr->downloaded ) | 848 | if ( !mPtr->downloaded ) |
849 | mailDownloadList.remove(mPtr->serverId, mPtr->size); | 849 | mailDownloadList.remove(mPtr->serverId, mPtr->size); |
850 | } | 850 | } |
851 | 851 | ||
852 | mailconf->setGroup(mPtr->id); | 852 | mailconf->setGroup(mPtr->id); |
853 | mailconf->clearGroup(); | 853 | mailconf->clearGroup(); |
854 | 854 | ||
855 | //delete any temporary attatchemnts storing | 855 | //delete any temporary attatchemnts storing |
856 | for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { | 856 | for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { |
857 | if (ePtr->saved) { | 857 | if (ePtr->saved) { |
858 | QFile::remove( (ePtr->path + ePtr->name) ); | 858 | QFile::remove( (ePtr->path + ePtr->name) ); |
859 | } | 859 | } |
860 | } | 860 | } |
861 | inboxView->takeItem(mailItem); | 861 | inboxView->takeItem(mailItem); |
862 | } | 862 | } |
863 | else | 863 | else |
864 | { | 864 | { |
865 | outboxView->takeItem(mailItem); | 865 | outboxView->takeItem(mailItem); |
866 | } | 866 | } |
867 | } | 867 | } |
868 | 868 | ||
869 | void EmailClient::setMailSize(int size) | 869 | void EmailClient::setMailSize(int size) |
870 | { | 870 | { |
871 | progressBar->reset(); | 871 | progressBar->reset(); |
872 | progressBar->setTotalSteps(size); | 872 | progressBar->setTotalSteps(size); |
873 | } | 873 | } |
874 | 874 | ||
875 | void EmailClient::setTotalSize(int size) | 875 | void EmailClient::setTotalSize(int size) |
876 | { | 876 | { |
877 | 877 | ||
878 | } | 878 | } |
879 | 879 | ||
880 | void EmailClient::setDownloadedSize(int size) | 880 | void EmailClient::setDownloadedSize(int size) |
881 | { | 881 | { |
882 | int total = progressBar->totalSteps(); | 882 | int total = progressBar->totalSteps(); |
883 | 883 | ||
884 | if (size < total) { | 884 | if (size < total) { |
885 | progressBar->setProgress(size); | 885 | progressBar->setProgress(size); |
886 | } else { | 886 | } else { |
887 | progressBar->setProgress(total); | 887 | progressBar->setProgress(total); |
888 | } | 888 | } |
889 | } | 889 | } |
890 | 890 | ||
891 | void EmailClient::deleteItem() | 891 | void EmailClient::deleteItem() |
892 | { | 892 | { |
893 | bool inbox=mailboxView->currentTab()==0; | 893 | bool inbox=mailboxView->currentTab()==0; |
894 | QListView* box; | ||
894 | 895 | ||
895 | EmailListItem* eli; | 896 | EmailListItem* eli; |
897 | int pos; | ||
898 | |||
899 | inbox ? box=inboxView : box=outboxView; | ||
896 | 900 | ||
897 | inbox ? eli=(EmailListItem*)inboxView->selectedItem():eli=(EmailListItem*)outboxView->selectedItem(); | 901 | eli=(EmailListItem*)box->selectedItem(); |
898 | 902 | ||
899 | if (eli) | 903 | if (eli) |
900 | deleteMail(eli,(bool&)inbox); | 904 | { |
905 | box->setSelected(eli->itemBelow(),true);//select the previous item | ||
906 | |||
907 | deleteMail(eli,(bool&)inbox); //remove mail entry | ||
908 | } | ||
901 | } | 909 | } |
902 | 910 | ||
903 | void EmailClient::inboxItemPressed() | 911 | void EmailClient::inboxItemPressed() |
904 | { | 912 | { |
905 | //timerID=startTimer(500); | 913 | //timerID=startTimer(500); |
906 | } | 914 | } |
907 | 915 | ||
908 | void EmailClient::inboxItemReleased() | 916 | void EmailClient::inboxItemReleased() |
909 | { | 917 | { |
910 | //killTimer(timerID); | 918 | //killTimer(timerID); |
911 | } | 919 | } |
912 | 920 | ||
913 | void EmailClient::timerEvent(QTimerEvent *e) | 921 | void EmailClient::timerEvent(QTimerEvent *e) |
914 | { | 922 | { |
915 | /*killTimer(timerID); | 923 | /*killTimer(timerID); |
916 | 924 | ||
917 | 925 | ||
918 | QPopupMenu *action = new QPopupMenu(this); | 926 | QPopupMenu *action = new QPopupMenu(this); |
919 | 927 | ||
920 | int reply=0; | 928 | int reply=0; |
921 | 929 | ||
922 | action->insertItem(tr( "Reply To" ),this,SLOT(reply())); | 930 | action->insertItem(tr( "Reply To" ),this,SLOT(reply())); |
923 | action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); | 931 | action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); |
924 | action->insertItem( tr( "Forward" ), this,SLOT(forward())); | 932 | action->insertItem( tr( "Forward" ), this,SLOT(forward())); |
925 | action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); | 933 | action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); |
926 | 934 | ||
927 | action->exec(QCursor::pos()); | 935 | action->exec(QCursor::pos()); |
928 | 936 | ||
929 | if (action) delete action; | 937 | if (action) delete action; |
930 | */ | 938 | */ |
931 | } | 939 | } |
932 | 940 | ||
933 | Email* EmailClient::getCurrentMail() | 941 | Email* EmailClient::getCurrentMail() |
934 | { | 942 | { |
935 | EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); | 943 | EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); |
936 | if (eli!=NULL) | 944 | if (eli!=NULL) |
937 | return eli->getMail(); | 945 | return eli->getMail(); |
938 | else | 946 | else |
939 | return NULL; | 947 | return NULL; |
940 | } | 948 | } |
941 | 949 | ||
942 | /* | 950 | void EmailClient::download(Email* mail) |
943 | void EmailClient::reply() | ||
944 | { | ||
945 | Email* mail=getCurrentMail(); | ||
946 | |||
947 | if (mail!=NULL) | ||
948 | { | ||
949 | emit reply(*mail); | ||
950 | } | ||
951 | } | ||
952 | |||
953 | void EmailClient::replyAll() | ||
954 | { | ||
955 | Email* mail=getCurrentMail(); | ||
956 | |||
957 | if (mail!=NULL) | ||
958 | { | ||
959 | emit replyAll(*mail); | ||
960 | } | ||
961 | } | ||
962 | |||
963 | void EmailClient::forward() | ||
964 | { | 951 | { |
965 | Email* mail=getCurrentMail(); | 952 | MailAccount* acc=0; |
966 | 953 | ||
967 | if (mail!=NULL) | 954 | tempMailDownloadList.clear(); |
968 | { | 955 | tempMailDownloadList.sizeInsert(mail->serverId, mail->size); |
969 | emit reply(*mail); | 956 | if (accountList.count()>0) |
970 | } | 957 | qDebug("Accounts present"); |
958 | |||
959 | acc=accountList.at(mail->fromAccountId-1); | ||
960 | if (acc) | ||
961 | { | ||
962 | emailHandler->setAccount(*acc); | ||
963 | emailHandler->getMailByList(&tempMailDownloadList); | ||
964 | } | ||
965 | else | ||
966 | 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"); | ||
971 | } | 968 | } |
972 | |||
973 | void EmailClient::remove() | ||
974 | { | ||
975 | Email* mail=getCurrentMail(); | ||
976 | |||
977 | if (mail!=NULL) | ||
978 | { | ||
979 | emit remove(*mail); | ||
980 | } | ||
981 | }*/ | ||
diff --git a/noncore/net/mailit/emailclient.h b/noncore/net/mailit/emailclient.h index 0890dcf..549683b 100644 --- a/noncore/net/mailit/emailclient.h +++ b/noncore/net/mailit/emailclient.h | |||
@@ -1,171 +1,174 @@ | |||
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 <qtimer.h> | 44 | #include <qtimer.h> |
45 | 45 | ||
46 | #include "emailhandler.h" | 46 | #include "emailhandler.h" |
47 | #include "emaillistitem.h" | 47 | #include "emaillistitem.h" |
48 | #include "textparser.h" | 48 | #include "textparser.h" |
49 | #include "editaccount.h" | 49 | #include "editaccount.h" |
50 | #include "maillist.h" | 50 | #include "maillist.h" |
51 | #include "addresslist.h" | 51 | #include "addresslist.h" |
52 | 52 | ||
53 | #include <qpe/config.h> | 53 | #include <qpe/config.h> |
54 | 54 | ||
55 | class AccountList : public QList<MailAccount> | 55 | class AccountList : public QList<MailAccount> |
56 | { | 56 | { |
57 | public: | 57 | public: |
58 | Item newItem(Item d); | 58 | Item newItem(Item d); |
59 | private: | 59 | private: |
60 | MailAccount* dupl(MailAccount *in); | 60 | MailAccount* dupl(MailAccount *in); |
61 | MailAccount *ac; | 61 | MailAccount *ac; |
62 | }; | 62 | }; |
63 | 63 | ||
64 | //class EmailClient : public EmailClientBase | 64 | //class EmailClient : public EmailClientBase |
65 | class EmailClient : public QMainWindow | 65 | class EmailClient : public QMainWindow |
66 | { | 66 | { |
67 | Q_OBJECT | 67 | Q_OBJECT |
68 | 68 | ||
69 | public: | 69 | public: |
70 | EmailClient( QWidget* parent, const char* name, WFlags fl = 0 ); | 70 | EmailClient( QWidget* parent, const char* name, WFlags fl = 0 ); |
71 | ~EmailClient(); | 71 | ~EmailClient(); |
72 | AddressList* getAdrListRef(); | 72 | AddressList* getAdrListRef(); |
73 | void download(Email*); | ||
73 | 74 | ||
74 | protected: | 75 | protected: |
75 | void timerEvent(QTimerEvent*); | 76 | void timerEvent(QTimerEvent*); |
76 | 77 | ||
77 | signals: | 78 | signals: |
78 | void composeRequested(); | 79 | void composeRequested(); |
79 | void viewEmail(QListView *, Email *); | 80 | void viewEmail(QListView *, Email *); |
80 | void mailUpdated(Email *); | 81 | void mailUpdated(Email *); |
81 | void newCaption(const QString &); | 82 | void newCaption(const QString &); |
82 | void replyRequested(Email&, bool&); | 83 | void replyRequested(Email&, bool&); |
83 | void forwardRequested(Email&); | 84 | void forwardRequested(Email&); |
84 | void removeItem(EmailListItem*, bool&); | 85 | void removeItem(EmailListItem*, bool&); |
85 | /*void reply(Email&); | 86 | /*void reply(Email&); |
86 | void replyAll(Email&); | 87 | void replyAll(Email&); |
87 | void remove(Email&); | 88 | void remove(Email&); |
88 | void forward(Email&);*/ | 89 | void forward(Email&);*/ |
89 | 90 | ||
90 | public slots: | 91 | public slots: |
91 | void compose(); | 92 | void compose(); |
92 | void cancel(); | 93 | void cancel(); |
93 | void enqueMail(const Email &mail); | 94 | void enqueMail(const Email &mail); |
94 | void setMailAccount(); | 95 | void setMailAccount(); |
95 | void sendQuedMail(); | 96 | void sendQuedMail(); |
96 | void mailSent(); | 97 | void mailSent(); |
97 | void deleteItem(); | 98 | void deleteItem(); |
98 | void getNewMail(); | 99 | void getNewMail(); |
99 | void getAllNewMail(); | 100 | void getAllNewMail(); |
100 | void smtpError(int code); | 101 | void smtpError(int code); |
101 | void popError(int code); | 102 | void popError(int code); |
102 | void inboxItemSelected(); | 103 | void inboxItemSelected(); |
103 | void outboxItemSelected(); | 104 | void outboxItemSelected(); |
104 | void inboxItemPressed(); | 105 | void inboxItemPressed(); |
105 | void inboxItemReleased(); | 106 | void inboxItemReleased(); |
106 | void mailArrived(const Email &mail, bool fromDisk); | 107 | void mailArrived(const Email &mail, bool fromDisk); |
107 | void allMailArrived(int); | 108 | void allMailArrived(int); |
108 | void saveMail(QString fileName, QListView *view); | 109 | void saveMail(QString fileName, QListView *view); |
109 | void selectAccount(int); | 110 | void selectAccount(int); |
110 | void editAccount(int); | 111 | void editAccount(int); |
111 | void updateAccounts(); | 112 | void updateAccounts(); |
112 | void deleteAccount(int); | 113 | void deleteAccount(int); |
113 | void deleteMail(EmailListItem *mailItem, bool &inbox); | 114 | void deleteMail(EmailListItem *mailItem, bool &inbox); |
114 | void setTotalSize(int); | 115 | void setTotalSize(int); |
115 | void setMailSize(int); | 116 | void setMailSize(int); |
116 | void setDownloadedSize(int); | 117 | void setDownloadedSize(int); |
117 | void moveMailFront(Email *mailPtr); | 118 | void moveMailFront(Email *mailPtr); |
118 | /* void reply(); | 119 | /* void reply(); |
119 | void replyAll(); | 120 | void replyAll(); |
120 | void forward(); | 121 | void forward(); |
121 | void remove();*/ | 122 | void remove();*/ |
122 | 123 | ||
123 | private: | 124 | private: |
124 | void init(); | 125 | void init(); |
125 | void readMail(); | 126 | void readMail(); |
126 | QString getPath(bool enclosurePath); | 127 | QString getPath(bool enclosurePath); |
127 | void readSettings(); | 128 | void readSettings(); |
128 | void saveSettings(); | 129 | void saveSettings(); |
129 | Email* getCurrentMail(); | 130 | Email* getCurrentMail(); |
130 | int timerID; | 131 | int timerID; |
131 | Config *mailconf; | 132 | Config *mailconf; |
132 | int newAccountId, idCount, mailIdCount; | 133 | int newAccountId, idCount, mailIdCount; |
133 | int accountIdCount; | 134 | int accountIdCount; |
134 | AccountList accountList; | 135 | AccountList accountList; |
135 | AddressList *addressList; | 136 | AddressList *addressList; |
136 | 137 | ||
137 | EditAccount *editAccountView; | 138 | EditAccount *editAccountView; |
138 | EmailListItem *item; | 139 | EmailListItem *item; |
139 | EmailHandler *emailHandler; | 140 | EmailHandler *emailHandler; |
140 | QList<Email> quedMessages; | 141 | QList<Email> quedMessages; |
141 | MailList mailDownloadList; | 142 | MailList mailDownloadList; |
143 | MailList tempMailDownloadList; | ||
144 | |||
142 | bool sending, receiving, previewingMail, allAccounts; | 145 | bool sending, receiving, previewingMail, allAccounts; |
143 | QString lineShift; | 146 | QString lineShift; |
144 | MailAccount account, *currentAccount; | 147 | MailAccount account, *currentAccount; |
145 | 148 | ||
146 | QToolBar *bar; | 149 | QToolBar *bar; |
147 | QProgressBar *progressBar; | 150 | QProgressBar *progressBar; |
148 | QStatusBar *statusBar; | 151 | QStatusBar *statusBar; |
149 | QLabel *status1Label, *status2Label; | 152 | QLabel *status1Label, *status2Label; |
150 | QToolButton *getMailButton; | 153 | QToolButton *getMailButton; |
151 | QAction *sendMailButton; | 154 | QAction *sendMailButton; |
152 | QAction *composeButton; | 155 | QAction *composeButton; |
153 | QAction *cancelButton; | 156 | QAction *cancelButton; |
154 | QAction *deleteButton; | 157 | QAction *deleteButton; |
155 | //QToolButton *setAccountButton; | 158 | //QToolButton *setAccountButton; |
156 | 159 | ||
157 | QMenuBar *mb; | 160 | QMenuBar *mb; |
158 | QPopupMenu *selectAccountMenu; | 161 | QPopupMenu *selectAccountMenu; |
159 | QPopupMenu *editAccountMenu; | 162 | QPopupMenu *editAccountMenu; |
160 | QPopupMenu *deleteAccountMenu; | 163 | QPopupMenu *deleteAccountMenu; |
161 | QPopupMenu *setAccountMenu; | 164 | QPopupMenu *setAccountMenu; |
162 | 165 | ||
163 | OTabWidget* mailboxView; | 166 | OTabWidget* mailboxView; |
164 | QListView* inboxView; | 167 | QListView* inboxView; |
165 | QListView* outboxView; | 168 | QListView* outboxView; |
166 | 169 | ||
167 | QGridLayout* grid_2; | 170 | QGridLayout* grid_2; |
168 | QGridLayout* grid_3; | 171 | QGridLayout* grid_3; |
169 | }; | 172 | }; |
170 | 173 | ||
171 | #endif // EMAILCLIENT_H | 174 | #endif // EMAILCLIENT_H |
diff --git a/noncore/net/mailit/emailhandler.cpp b/noncore/net/mailit/emailhandler.cpp index b180051..fbbada7 100644 --- a/noncore/net/mailit/emailhandler.cpp +++ b/noncore/net/mailit/emailhandler.cpp | |||
@@ -1,628 +1,628 @@ | |||
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 | ||
29 | QCollection::Item EnclosureList::newItem(QCollection::Item d) | 29 | QCollection::Item EnclosureList::newItem(QCollection::Item d) |
30 | { | 30 | { |
31 | return dupl( (Enclosure *) d); | 31 | return dupl( (Enclosure *) d); |
32 | } | 32 | } |
33 | 33 | ||
34 | Enclosure* EnclosureList::dupl(Enclosure *in) | 34 | Enclosure* 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 | ||
40 | EmailHandler::EmailHandler() | 40 | EmailHandler::EmailHandler() |
41 | { | 41 | { |
42 | smtpClient = new SmtpClient(); | 42 | smtpClient = new SmtpClient(); |
43 | popClient = new PopClient(); | 43 | popClient = new PopClient(); |
44 | 44 | ||
45 | connect(smtpClient, SIGNAL(errorOccurred(int)), this, | 45 | connect(smtpClient, SIGNAL(errorOccurred(int)), this, |
46 | SIGNAL(smtpError(int)) ); | 46 | SIGNAL(smtpError(int)) ); |
47 | connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); | 47 | connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); |
48 | connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, | 48 | connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, |
49 | SIGNAL(updateSmtpStatus(const QString &)) ); | 49 | SIGNAL(updateSmtpStatus(const QString &)) ); |
50 | 50 | ||
51 | connect(popClient, SIGNAL(errorOccurred(int)), this, | 51 | connect(popClient, SIGNAL(errorOccurred(int)), this, |
52 | SIGNAL(popError(int)) ); | 52 | SIGNAL(popError(int)) ); |
53 | connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), | 53 | connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), |
54 | this, SLOT(messageArrived(const QString &, int, uint, bool)) ); | 54 | this, SLOT(messageArrived(const QString &, int, uint, bool)) ); |
55 | connect(popClient, SIGNAL(updateStatus(const QString &)), this, | 55 | connect(popClient, SIGNAL(updateStatus(const QString &)), this, |
56 | SIGNAL(updatePopStatus(const QString &)) ); | 56 | SIGNAL(updatePopStatus(const QString &)) ); |
57 | connect(popClient, SIGNAL(mailTransfered(int)), this, | 57 | connect(popClient, SIGNAL(mailTransfered(int)), this, |
58 | SIGNAL(mailTransfered(int)) ); | 58 | SIGNAL(mailTransfered(int)) ); |
59 | 59 | ||
60 | 60 | ||
61 | //relaying size information | 61 | //relaying size information |
62 | connect(popClient, SIGNAL(currentMailSize(int)), | 62 | connect(popClient, SIGNAL(currentMailSize(int)), |
63 | this, SIGNAL(currentMailSize(int)) ); | 63 | this, SIGNAL(currentMailSize(int)) ); |
64 | connect(popClient, SIGNAL(downloadedSize(int)), | 64 | connect(popClient, SIGNAL(downloadedSize(int)), |
65 | this, SIGNAL(downloadedSize(int)) ); | 65 | this, SIGNAL(downloadedSize(int)) ); |
66 | } | 66 | } |
67 | 67 | ||
68 | void EmailHandler::sendMail(QList<Email> *mailList) | 68 | void EmailHandler::sendMail(QList<Email> *mailList) |
69 | { | 69 | { |
70 | Email *currentMail; | 70 | Email *currentMail; |
71 | QString temp; | 71 | QString temp; |
72 | QString userName = mailAccount.name; | 72 | QString userName = mailAccount.name; |
73 | userName += " <" + mailAccount.emailAddress + ">"; | 73 | userName += " <" + mailAccount.emailAddress + ">"; |
74 | 74 | ||
75 | for (currentMail = mailList->first(); currentMail != 0; | 75 | for (currentMail = mailList->first(); currentMail != 0; |
76 | currentMail = mailList->next()) { | 76 | currentMail = mailList->next()) { |
77 | 77 | ||
78 | if (encodeMime(currentMail) == 0) { | 78 | if (encodeMime(currentMail) == 0) { |
79 | smtpClient->addMail(userName, currentMail->subject, | 79 | smtpClient->addMail(userName, currentMail->subject, |
80 | currentMail->recipients, currentMail->rawMail); | 80 | currentMail->recipients, currentMail->rawMail); |
81 | } else { //error | 81 | } else { //error |
82 | temp = tr("Could not locate all files in \nmail with subject: ") + | 82 | temp = tr("Could not locate all files in \nmail with subject: ") + |
83 | currentMail->subject; | 83 | currentMail->subject; |
84 | temp += tr("\nMail has NOT been sent"); | 84 | temp += tr("\nMail has NOT been sent"); |
85 | QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); | 85 | QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); |
86 | 86 | ||
87 | } | 87 | } |
88 | } | 88 | } |
89 | smtpClient->newConnection(mailAccount.smtpServer, 25); | 89 | smtpClient->newConnection(mailAccount.smtpServer, 25); |
90 | } | 90 | } |
91 | 91 | ||
92 | void EmailHandler::setAccount(MailAccount account) | 92 | void EmailHandler::setAccount(MailAccount account) |
93 | { | 93 | { |
94 | mailAccount = account; | 94 | mailAccount = account; |
95 | } | 95 | } |
96 | 96 | ||
97 | void EmailHandler::getMail() | 97 | void EmailHandler::getMail() |
98 | { | 98 | { |
99 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); | 99 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); |
100 | if (mailAccount.synchronize) { | 100 | if (mailAccount.synchronize) { |
101 | popClient->setSynchronize(mailAccount.lastServerMailCount); | 101 | popClient->setSynchronize(mailAccount.lastServerMailCount); |
102 | } else { | 102 | } else { |
103 | popClient->removeSynchronize(); | 103 | popClient->removeSynchronize(); |
104 | } | 104 | } |
105 | 105 | ||
106 | headers = FALSE; | 106 | headers = FALSE; |
107 | //popClient->headersOnly(headers, 0); | 107 | //popClient->headersOnly(headers, 0); |
108 | popClient->newConnection(mailAccount.popServer, 110); | 108 | popClient->newConnection(mailAccount.popServer, 110); |
109 | } | 109 | } |
110 | 110 | ||
111 | void EmailHandler::getMailHeaders() | 111 | void EmailHandler::getMailHeaders() |
112 | { | 112 | { |
113 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); | 113 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); |
114 | mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); | 114 | mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); |
115 | 115 | ||
116 | headers = TRUE; | 116 | headers = TRUE; |
117 | popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all | 117 | popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all |
118 | popClient->newConnection(mailAccount.popServer, 110); | 118 | popClient->newConnection(mailAccount.popServer, 110); |
119 | } | 119 | } |
120 | 120 | ||
121 | void EmailHandler::getMailByList(MailList *mailList) | 121 | void EmailHandler::getMailByList(MailList *mailList) |
122 | { | 122 | { |
123 | if (mailList->count() == 0) { //should not occur though | 123 | if (mailList->count() == 0) { //should not occur though |
124 | emit mailTransfered(0); | 124 | emit mailTransfered(0); |
125 | return; | 125 | return; |
126 | } | 126 | } |
127 | 127 | ||
128 | headers = FALSE; | 128 | headers = FALSE; |
129 | popClient->headersOnly(FALSE, 0); | 129 | popClient->headersOnly(FALSE, 0); |
130 | popClient->newConnection(mailAccount.popServer, 110); | 130 | |
131 | popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd); | ||
131 | popClient->setSelectedMails(mailList); | 132 | popClient->setSelectedMails(mailList); |
132 | } | 133 | popClient->newConnection(mailAccount.popServer, 110); |
134 | } | ||
133 | 135 | ||
134 | void EmailHandler::messageArrived(const QString &message, int id, uint size, bool incomplete) | 136 | void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) |
135 | { | 137 | { |
136 | Email mail; | 138 | Email mail; |
137 | 139 | ||
138 | mail.rawMail = message; | 140 | mail.rawMail = message; |
139 | mail.serverId = id; | 141 | mail.serverId = id; |
140 | mail.size = size; | 142 | mail.size = size; |
141 | mail.downloaded = incomplete; | 143 | mail.downloaded = complete; |
142 | 144 | ||
143 | emit mailArrived(mail, FALSE); | 145 | emit mailArrived(mail, FALSE); |
144 | } | 146 | } |
145 | 147 | ||
146 | bool EmailHandler::parse(QString in, QString lineShift, Email *mail) | 148 | bool EmailHandler::parse(QString in, QString lineShift, Email *mail) |
147 | { | 149 | { |
148 | QString temp, boundary; | 150 | QString temp, boundary; |
149 | int pos; | 151 | int pos; |
150 | QString delimiter, header, body, mimeHeader, mimeBody; | 152 | QString delimiter, header, body, mimeHeader, mimeBody; |
151 | QString content, contentType, contentAttribute, id, encoding; | 153 | QString content, contentType, contentAttribute, id, encoding; |
152 | QString fileName, storedName; | 154 | QString fileName, storedName; |
153 | int enclosureId = 0; | 155 | int enclosureId = 0; |
154 | 156 | ||
155 | mail->rawMail = in; | 157 | mail->rawMail = in; |
156 | mail->received = TRUE; | 158 | mail->received = TRUE; |
157 | mail->files.setAutoDelete(TRUE); | 159 | mail->files.setAutoDelete(TRUE); |
158 | 160 | ||
159 | temp = lineShift + "." + lineShift; | 161 | temp = lineShift + "." + lineShift; |
160 | 162 | ||
161 | if (in.right(temp.length()) != temp) { | 163 | if (in.right(temp.length()) != temp) { |
162 | mail->rawMail += temp; | 164 | mail->rawMail += temp; |
163 | } | 165 | } |
164 | 166 | ||
165 | 167 | ||
166 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" | 168 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" |
167 | pos = in.find(delimiter, 0, FALSE); | 169 | pos = in.find(delimiter, 0, FALSE); |
168 | header = in.left(pos); | 170 | header = in.left(pos); |
169 | body = in.right(in.length() - pos - delimiter.length()); | 171 | body = in.right(in.length() - pos - delimiter.length()); |
170 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) | 172 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) |
171 | body.truncate(body.length()-2); | 173 | body.truncate(body.length()-2); |
172 | 174 | ||
173 | TextParser p(header, lineShift); | 175 | TextParser p(header, lineShift); |
174 | 176 | ||
175 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { | 177 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { |
176 | pos++; | 178 | pos++; |
177 | if (p.separatorAt(pos) == ' ') { | 179 | if (p.separatorAt(pos) == ' ') { |
178 | mail->from = p.getString(&pos, '<', false); | 180 | mail->from = p.getString(&pos, '<', false); |
179 | mail->from = mail->from.stripWhiteSpace(); | 181 | mail->from = mail->from.stripWhiteSpace(); |
180 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { | 182 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { |
181 | mail->from = mail->from.left(mail->from.length() - 1); | 183 | mail->from = mail->from.left(mail->from.length() - 1); |
182 | mail->from = mail->from.right(mail->from.length() - 1); | 184 | mail->from = mail->from.right(mail->from.length() - 1); |
183 | } | 185 | } |
184 | pos++; | 186 | pos++; |
185 | |||
186 | mail->fromMail = p.getString(&pos, '>', false); | 187 | mail->fromMail = p.getString(&pos, '>', false); |
187 | } else { | 188 | } else { |
188 | if ((p.separatorAt(pos) == '<') | 189 | if (p.separatorAt(pos) == '<') //No name.. nasty |
189 | || (p.separatorAt(pos) == ' ')) //No name.. nasty | ||
190 | pos++; | ||
191 | pos++; | 190 | pos++; |
191 | //pos++; | ||
192 | mail->fromMail = p.getString(&pos, 'z', TRUE); | 192 | mail->fromMail = p.getString(&pos, 'z', TRUE); |
193 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') | 193 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') |
194 | mail->fromMail.truncate(mail->fromMail.length() - 1); | 194 | mail->fromMail.truncate(mail->fromMail.length() - 1); |
195 | mail->from=mail->fromMail; | 195 | mail->from=mail->fromMail; |
196 | } | 196 | } |
197 | } | 197 | } |
198 | 198 | ||
199 | pos=0; | 199 | pos=0; |
200 | 200 | ||
201 | //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: | 201 | //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: |
202 | while((pos = p.find("TO",':', pos+1, TRUE))!=-1) | 202 | while((pos = p.find("TO",':', pos+1, TRUE))!=-1) |
203 | { | 203 | { |
204 | QString rec; | 204 | QString rec; |
205 | 205 | ||
206 | if (p.separatorAt(pos-1)!='-') | 206 | if (p.separatorAt(pos-1)!='-') |
207 | { | 207 | { |
208 | pos++; | 208 | pos++; |
209 | mail->recipients.append(p.getString(&pos, '\r', TRUE)); | 209 | mail->recipients.append(p.getString(&pos, '\r', TRUE)); |
210 | } | 210 | } |
211 | /*else { | 211 | /*else { |
212 | if ((p.separatorAt(pos) == '<')|| (p.separatorAt(pos) == ' ')) //No name.. nasty | 212 | if ((p.separatorAt(pos) == '<')|| (p.separatorAt(pos) == ' ')) //No name.. nasty |
213 | pos++; | 213 | pos++; |
214 | pos++; | 214 | pos++; |
215 | mail->fromMail = p.getString(&pos, 'z', TRUE); | 215 | mail->fromMail = p.getString(&pos, 'z', TRUE); |
216 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') | 216 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') |
217 | mail->fromMail.truncate(mail->fromMail.length() - 1); | 217 | mail->fromMail.truncate(mail->fromMail.length() - 1); |
218 | mail->from=mail->fromMail; | 218 | mail->from=mail->fromMail; |
219 | } | 219 | } |
220 | mail->recipients.append (p.getString(&pos, 'z', TRUE) ); | 220 | mail->recipients.append (p.getString(&pos, 'z', TRUE) ); |
221 | }*/ | 221 | }*/ |
222 | } | 222 | } |
223 | // | 223 | // |
224 | //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); | 224 | //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); |
225 | 225 | ||
226 | if ((pos = p.find("CC",':', 0, TRUE)) != -1) | 226 | if ((pos = p.find("CC",':', 0, TRUE)) != -1) |
227 | { | 227 | { |
228 | pos++; | 228 | pos++; |
229 | mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); | 229 | mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); |
230 | } | 230 | } |
231 | 231 | ||
232 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { | 232 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { |
233 | pos++; | 233 | pos++; |
234 | mail->subject = p.getString(&pos, 'z', TRUE); | 234 | mail->subject = p.getString(&pos, 'z', TRUE); |
235 | } | 235 | } |
236 | 236 | ||
237 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { | 237 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { |
238 | pos++; | 238 | pos++; |
239 | mail->date = p.getString(&pos, 'z', TRUE); | 239 | mail->date = p.getString(&pos, 'z', TRUE); |
240 | } | 240 | } |
241 | 241 | ||
242 | 242 | ||
243 | 243 | ||
244 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { | 244 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { |
245 | pos++; | 245 | pos++; |
246 | if ( (p.wordAt(pos).upper() == "ID") && | 246 | if ( (p.wordAt(pos).upper() == "ID") && |
247 | (p.separatorAt(pos) == ':') ) { | 247 | (p.separatorAt(pos) == ':') ) { |
248 | 248 | ||
249 | id = p.getString(&pos, 'z', TRUE); | 249 | id = p.getString(&pos, 'z', TRUE); |
250 | mail->id = id; | 250 | mail->id = id; |
251 | } | 251 | } |
252 | } | 252 | } |
253 | 253 | ||
254 | pos = 0; | 254 | pos = 0; |
255 | while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { | 255 | while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { |
256 | pos++; | 256 | pos++; |
257 | if ( (p.wordAt(pos).upper() == "VERSION") && | 257 | if ( (p.wordAt(pos).upper() == "VERSION") && |
258 | (p.separatorAt(pos) == ':') ) { | 258 | (p.separatorAt(pos) == ':') ) { |
259 | pos++; | 259 | pos++; |
260 | if (p.getString(&pos, 'z', true) == "1.0") { | 260 | if (p.getString(&pos, 'z', true) == "1.0") { |
261 | mail->mimeType = 1; | 261 | mail->mimeType = 1; |
262 | } | 262 | } |
263 | } | 263 | } |
264 | } | 264 | } |
265 | 265 | ||
266 | if (mail->mimeType == 1) { | 266 | if (mail->mimeType == 1) { |
267 | boundary = ""; | 267 | boundary = ""; |
268 | if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { | 268 | if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { |
269 | pos++; | 269 | pos++; |
270 | boundary = p.getString(&pos, 'z', true); | 270 | boundary = p.getString(&pos, 'z', true); |
271 | if (boundary[0] == '"') { | 271 | if (boundary[0] == '"') { |
272 | boundary = boundary.left(boundary.length() - 1); //strip " | 272 | boundary = boundary.left(boundary.length() - 1); //strip " |
273 | boundary = boundary.right(boundary.length() - 1); //strip " | 273 | boundary = boundary.right(boundary.length() - 1); //strip " |
274 | } | 274 | } |
275 | boundary = "--" + boundary; //create boundary field | 275 | boundary = "--" + boundary; //create boundary field |
276 | } | 276 | } |
277 | 277 | ||
278 | if (boundary == "") { //fooled by Mime-Version | 278 | if (boundary == "") { //fooled by Mime-Version |
279 | mail->body = body; | 279 | mail->body = body; |
280 | mail->bodyPlain = body; | 280 | mail->bodyPlain = body; |
281 | return mail; | 281 | return mail; |
282 | } | 282 | } |
283 | 283 | ||
284 | while (body.length() > 0) { | 284 | while (body.length() > 0) { |
285 | pos = body.find(boundary, 0, FALSE); | 285 | pos = body.find(boundary, 0, FALSE); |
286 | pos = body.find(delimiter, pos, FALSE); | 286 | pos = body.find(delimiter, pos, FALSE); |
287 | mimeHeader = body.left(pos); | 287 | mimeHeader = body.left(pos); |
288 | mimeBody = body.right(body.length() - pos - delimiter.length()); | 288 | mimeBody = body.right(body.length() - pos - delimiter.length()); |
289 | TextParser bp(mimeHeader, lineShift); | 289 | TextParser bp(mimeHeader, lineShift); |
290 | 290 | ||
291 | contentType = ""; | 291 | contentType = ""; |
292 | contentAttribute = ""; | 292 | contentAttribute = ""; |
293 | fileName = ""; | 293 | fileName = ""; |
294 | if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) { | 294 | if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) { |
295 | pos++; | 295 | pos++; |
296 | if ( (bp.wordAt(pos).upper() == "TYPE") && | 296 | if ( (bp.wordAt(pos).upper() == "TYPE") && |
297 | (bp.separatorAt(pos) == ':') ) { | 297 | (bp.separatorAt(pos) == ':') ) { |
298 | contentType = bp.nextWord().upper(); | 298 | contentType = bp.nextWord().upper(); |
299 | if (bp.nextSeparator() == '/') | 299 | if (bp.nextSeparator() == '/') |
300 | contentAttribute = bp.nextWord().upper(); | 300 | contentAttribute = bp.nextWord().upper(); |
301 | content = contentType + "/" + contentAttribute; | 301 | content = contentType + "/" + contentAttribute; |
302 | } | 302 | } |
303 | if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) { | 303 | if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) { |
304 | pos++; | 304 | pos++; |
305 | encoding = bp.getString(&pos, 'z', TRUE); | 305 | encoding = bp.getString(&pos, 'z', TRUE); |
306 | } | 306 | } |
307 | 307 | ||
308 | if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) { | 308 | if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) { |
309 | pos++; | 309 | pos++; |
310 | fileName = bp.getString(&pos, 'z', TRUE); | 310 | fileName = bp.getString(&pos, 'z', TRUE); |
311 | fileName = fileName.right(fileName.length() - 1); | 311 | fileName = fileName.right(fileName.length() - 1); |
312 | fileName = fileName.left(fileName.length() - 1); | 312 | fileName = fileName.left(fileName.length() - 1); |
313 | } | 313 | } |
314 | 314 | ||
315 | } | 315 | } |
316 | pos = mimeBody.find(boundary, 0, FALSE); | 316 | pos = mimeBody.find(boundary, 0, FALSE); |
317 | if (pos == -1) //should not occur, malformed mail | 317 | if (pos == -1) //should not occur, malformed mail |
318 | pos = mimeBody.length(); | 318 | pos = mimeBody.length(); |
319 | body = mimeBody.right(mimeBody.length() - pos); | 319 | body = mimeBody.right(mimeBody.length() - pos); |
320 | mimeBody = mimeBody.left(pos); | 320 | mimeBody = mimeBody.left(pos); |
321 | 321 | ||
322 | if (fileName != "") { //attatchments of some type, audio, image etc. | 322 | if (fileName != "") { //attatchments of some type, audio, image etc. |
323 | 323 | ||
324 | Enclosure e; | 324 | Enclosure e; |
325 | e.id = enclosureId; | 325 | e.id = enclosureId; |
326 | e.originalName = fileName; | 326 | e.originalName = fileName; |
327 | e.contentType = contentType; | 327 | e.contentType = contentType; |
328 | e.contentAttribute = contentAttribute; | 328 | e.contentAttribute = contentAttribute; |
329 | e.encoding = encoding; | 329 | e.encoding = encoding; |
330 | e.body = mimeBody; | 330 | e.body = mimeBody; |
331 | e.saved = FALSE; | 331 | e.saved = FALSE; |
332 | mail->addEnclosure(&e); | 332 | mail->addEnclosure(&e); |
333 | enclosureId++; | 333 | enclosureId++; |
334 | 334 | ||
335 | } else if (contentType == "TEXT") { | 335 | } else if (contentType == "TEXT") { |
336 | if (contentAttribute == "PLAIN") { | 336 | if (contentAttribute == "PLAIN") { |
337 | mail->body = mimeBody; | 337 | mail->body = mimeBody; |
338 | mail->bodyPlain = mimeBody; | 338 | mail->bodyPlain = mimeBody; |
339 | } | 339 | } |
340 | if (contentAttribute == "HTML") { | 340 | if (contentAttribute == "HTML") { |
341 | mail->body = mimeBody; | 341 | mail->body = mimeBody; |
342 | } | 342 | } |
343 | } | 343 | } |
344 | } | 344 | } |
345 | } else { | 345 | } else { |
346 | mail->bodyPlain = body; | 346 | mail->bodyPlain = body; |
347 | mail->body = body; | 347 | mail->body = body; |
348 | } | 348 | } |
349 | return TRUE; | 349 | return TRUE; |
350 | } | 350 | } |
351 | 351 | ||
352 | bool EmailHandler::getEnclosure(Enclosure *ePtr) | 352 | bool EmailHandler::getEnclosure(Enclosure *ePtr) |
353 | { | 353 | { |
354 | QFile f(ePtr->path + ePtr->name); | 354 | QFile f(ePtr->path + ePtr->name); |
355 | char src[4]; | 355 | char src[4]; |
356 | char *destPtr; | 356 | char *destPtr; |
357 | QByteArray buffer; | 357 | QByteArray buffer; |
358 | uint bufCount, pos, decodedCount, size, x; | 358 | uint bufCount, pos, decodedCount, size, x; |
359 | 359 | ||
360 | if (! f.open(IO_WriteOnly) ) { | 360 | if (! f.open(IO_WriteOnly) ) { |
361 | qWarning("could not save: " + ePtr->path + ePtr->name); | 361 | qWarning("could not save: " + ePtr->path + ePtr->name); |
362 | return FALSE; | 362 | return FALSE; |
363 | } | 363 | } |
364 | 364 | ||
365 | if (ePtr->encoding.upper() == "BASE64") { | 365 | if (ePtr->encoding.upper() == "BASE64") { |
366 | size = (ePtr->body.length() * 3 / 4); //approximate size (always above) | 366 | size = (ePtr->body.length() * 3 / 4); //approximate size (always above) |
367 | buffer.resize(size); | 367 | buffer.resize(size); |
368 | bufCount = 0; | 368 | bufCount = 0; |
369 | pos = 0; | 369 | pos = 0; |
370 | destPtr = buffer.data(); | 370 | destPtr = buffer.data(); |
371 | 371 | ||
372 | while (pos < ePtr->body.length()) { | 372 | while (pos < ePtr->body.length()) { |
373 | decodedCount = 4; | 373 | decodedCount = 4; |
374 | x = 0; | 374 | x = 0; |
375 | while ( (x < 4) && (pos < ePtr->body.length()) ) { | 375 | while ( (x < 4) && (pos < ePtr->body.length()) ) { |
376 | src[x] = ePtr->body[pos].latin1(); | 376 | src[x] = ePtr->body[pos].latin1(); |
377 | pos++; | 377 | pos++; |
378 | if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ') | 378 | if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ') |
379 | x--; | 379 | x--; |
380 | x++; | 380 | x++; |
381 | } | 381 | } |
382 | if (x > 1) { | 382 | if (x > 1) { |
383 | decodedCount = parse64base(src, destPtr); | 383 | decodedCount = parse64base(src, destPtr); |
384 | destPtr += decodedCount; | 384 | destPtr += decodedCount; |
385 | bufCount += decodedCount; | 385 | bufCount += decodedCount; |
386 | } | 386 | } |
387 | } | 387 | } |
388 | 388 | ||
389 | buffer.resize(bufCount); //set correct length of file | 389 | buffer.resize(bufCount); //set correct length of file |
390 | f.writeBlock(buffer); | 390 | f.writeBlock(buffer); |
391 | } else { | 391 | } else { |
392 | QTextStream t(&f); | 392 | QTextStream t(&f); |
393 | t << ePtr->body; | 393 | t << ePtr->body; |
394 | } | 394 | } |
395 | return TRUE; | 395 | return TRUE; |
396 | } | 396 | } |
397 | 397 | ||
398 | int EmailHandler::parse64base(char *src, char *bufOut) { | 398 | int EmailHandler::parse64base(char *src, char *bufOut) { |
399 | 399 | ||
400 | char c, z; | 400 | char c, z; |
401 | char li[4]; | 401 | char li[4]; |
402 | int processed; | 402 | int processed; |
403 | 403 | ||
404 | //conversion table withouth table... | 404 | //conversion table withouth table... |
405 | for (int x = 0; x < 4; x++) { | 405 | for (int x = 0; x < 4; x++) { |
406 | c = src[x]; | 406 | c = src[x]; |
407 | 407 | ||
408 | if ( (int) c >= 'A' && (int) c <= 'Z') | 408 | if ( (int) c >= 'A' && (int) c <= 'Z') |
409 | li[x] = (int) c - (int) 'A'; | 409 | li[x] = (int) c - (int) 'A'; |
410 | if ( (int) c >= 'a' && (int) c <= 'z') | 410 | if ( (int) c >= 'a' && (int) c <= 'z') |
411 | li[x] = (int) c - (int) 'a' + 26; | 411 | li[x] = (int) c - (int) 'a' + 26; |
412 | if ( (int) c >= '0' && (int) c <= '9') | 412 | if ( (int) c >= '0' && (int) c <= '9') |
413 | li[x] = (int) c - (int) '0' + 52; | 413 | li[x] = (int) c - (int) '0' + 52; |
414 | if (c == '+') | 414 | if (c == '+') |
415 | li[x] = 62; | 415 | li[x] = 62; |
416 | if (c == '/') | 416 | if (c == '/') |
417 | li[x] = 63; | 417 | li[x] = 63; |
418 | } | 418 | } |
419 | 419 | ||
420 | processed = 1; | 420 | processed = 1; |
421 | bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits | 421 | bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits |
422 | bufOut[0] <<= 2; | 422 | bufOut[0] <<= 2; |
423 | z = li[1] >> 4; | 423 | z = li[1] >> 4; |
424 | bufOut[0] = bufOut[0] | z; //first byte retrived | 424 | bufOut[0] = bufOut[0] | z; //first byte retrived |
425 | 425 | ||
426 | if (src[2] != '=') { | 426 | if (src[2] != '=') { |
427 | bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits | 427 | bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits |
428 | bufOut[1] <<= 4; | 428 | bufOut[1] <<= 4; |
429 | z = li[2] >> 2; | 429 | z = li[2] >> 2; |
430 | bufOut[1] = bufOut[1] | z; //second byte retrived | 430 | bufOut[1] = bufOut[1] | z; //second byte retrived |
431 | processed++; | 431 | processed++; |
432 | 432 | ||
433 | if (src[3] != '=') { | 433 | if (src[3] != '=') { |
434 | bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits | 434 | bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits |
435 | bufOut[2] <<= 6; | 435 | bufOut[2] <<= 6; |
436 | z = li[3]; | 436 | z = li[3]; |
437 | bufOut[2] = bufOut[2] | z; //third byte retrieved | 437 | bufOut[2] = bufOut[2] | z; //third byte retrieved |
438 | processed++; | 438 | processed++; |
439 | } | 439 | } |
440 | } | 440 | } |
441 | return processed; | 441 | return processed; |
442 | } | 442 | } |
443 | 443 | ||
444 | int EmailHandler::encodeMime(Email *mail) | 444 | int EmailHandler::encodeMime(Email *mail) |
445 | { | 445 | { |
446 | 446 | ||
447 | QString fileName, fileType, contentType, newBody, boundary; | 447 | QString fileName, fileType, contentType, newBody, boundary; |
448 | Enclosure *ePtr; | 448 | Enclosure *ePtr; |
449 | 449 | ||
450 | QString userName = mailAccount.name; | 450 | QString userName = mailAccount.name; |
451 | if (userName.length()>0)//only embrace it if there is a user name | 451 | if (userName.length()>0)//only embrace it if there is a user name |
452 | userName += " <" + mailAccount.emailAddress + ">"; | 452 | userName += " <" + mailAccount.emailAddress + ">"; |
453 | 453 | ||
454 | //add standard headers | 454 | //add standard headers |
455 | newBody = "From: " + userName + "\r\nTo: "; | 455 | newBody = "From: " + userName + "\r\nTo: "; |
456 | for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) { | 456 | for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) { |
457 | newBody += *it + " "; | 457 | newBody += *it + " "; |
458 | } | 458 | } |
459 | 459 | ||
460 | newBody += "\r\nCC: "; | 460 | newBody += "\r\nCC: "; |
461 | 461 | ||
462 | for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) { | 462 | for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) { |
463 | newBody += *it + " "; | 463 | newBody += *it + " "; |
464 | } | 464 | } |
465 | 465 | ||
466 | newBody += "\r\nSubject: " + mail->subject + "\r\n"; | 466 | newBody += "\r\nSubject: " + mail->subject + "\r\n"; |
467 | 467 | ||
468 | if (mail->files.count() == 0) { //just a simple mail | 468 | if (mail->files.count() == 0) { //just a simple mail |
469 | newBody += "\r\n" + mail->body; | 469 | newBody += "\r\n" + mail->body; |
470 | mail->rawMail = newBody; | 470 | mail->rawMail = newBody; |
471 | return 0; | 471 | return 0; |
472 | } | 472 | } |
473 | 473 | ||
474 | //Build mime encoded mail | 474 | //Build mime encoded mail |
475 | boundary = "-----4345=next_bound=0495----"; | 475 | boundary = "-----4345=next_bound=0495----"; |
476 | 476 | ||
477 | newBody += "Mime-Version: 1.0\r\n"; | 477 | newBody += "Mime-Version: 1.0\r\n"; |
478 | newBody += "Content-Type: multipart/mixed; boundary=\"" + | 478 | newBody += "Content-Type: multipart/mixed; boundary=\"" + |
479 | boundary + "\"\r\n\r\n"; | 479 | boundary + "\"\r\n\r\n"; |
480 | 480 | ||
481 | newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n"; | 481 | 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"; | 482 | newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n"; |
483 | newBody += mail->body; | 483 | newBody += mail->body; |
484 | 484 | ||
485 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { | 485 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { |
486 | fileName = ePtr->originalName; | 486 | fileName = ePtr->originalName; |
487 | fileType = ePtr->contentType; | 487 | fileType = ePtr->contentType; |
488 | QFileInfo fi(fileName); | 488 | QFileInfo fi(fileName); |
489 | 489 | ||
490 | // This specification of contentType is temporary | 490 | // This specification of contentType is temporary |
491 | contentType = ""; | 491 | contentType = ""; |
492 | if (fileType == "Picture") { | 492 | if (fileType == "Picture") { |
493 | contentType = "image/x-image"; | 493 | contentType = "image/x-image"; |
494 | } else if (fileType == "Document") { | 494 | } else if (fileType == "Document") { |
495 | contentType = "text/plain"; | 495 | contentType = "text/plain"; |
496 | } else if (fileType == "Sound") { | 496 | } else if (fileType == "Sound") { |
497 | contentType = "audio/x-wav"; | 497 | contentType = "audio/x-wav"; |
498 | } else if (fileType == "Movie") { | 498 | } else if (fileType == "Movie") { |
499 | contentType = "video/mpeg"; | 499 | contentType = "video/mpeg"; |
500 | } else { | 500 | } else { |
501 | contentType = "application/octet-stream"; | 501 | contentType = "application/octet-stream"; |
502 | } | 502 | } |
503 | 503 | ||
504 | newBody += "\r\n\r\n--" + boundary + "\r\n"; | 504 | newBody += "\r\n\r\n--" + boundary + "\r\n"; |
505 | newBody += "Content-Type: " + contentType + "; name=\"" + | 505 | newBody += "Content-Type: " + contentType + "; name=\"" + |
506 | fi.fileName() + "\"\r\n"; | 506 | fi.fileName() + "\"\r\n"; |
507 | newBody += "Content-Transfer-Encoding: base64\r\n"; | 507 | newBody += "Content-Transfer-Encoding: base64\r\n"; |
508 | newBody += "Content-Disposition: inline; filename=\"" + | 508 | newBody += "Content-Disposition: inline; filename=\"" + |
509 | fi.fileName() + "\"\r\n\r\n"; | 509 | fi.fileName() + "\"\r\n\r\n"; |
510 | 510 | ||
511 | if (encodeFile(fileName, &newBody) == -1) //file not found? | 511 | if (encodeFile(fileName, &newBody) == -1) //file not found? |
512 | return -1; | 512 | return -1; |
513 | } | 513 | } |
514 | 514 | ||
515 | newBody += "\r\n\r\n--" + boundary + "--"; | 515 | newBody += "\r\n\r\n--" + boundary + "--"; |
516 | mail->rawMail = newBody; | 516 | mail->rawMail = newBody; |
517 | 517 | ||
518 | return 0; | 518 | return 0; |
519 | } | 519 | } |
520 | 520 | ||
521 | int EmailHandler::encodeFile(QString fileName, QString *toBody) | 521 | int EmailHandler::encodeFile(QString fileName, QString *toBody) |
522 | { | 522 | { |
523 | char *fileData; | 523 | char *fileData; |
524 | char *dataPtr; | 524 | char *dataPtr; |
525 | QString temp; | 525 | QString temp; |
526 | uint dataSize, count; | 526 | uint dataSize, count; |
527 | QFile f(fileName); | 527 | QFile f(fileName); |
528 | 528 | ||
529 | if (! f.open(IO_ReadOnly) ) { | 529 | if (! f.open(IO_ReadOnly) ) { |
530 | qWarning("could not open file: " + fileName); | 530 | qWarning("could not open file: " + fileName); |
531 | return -1; | 531 | return -1; |
532 | } | 532 | } |
533 | QTextStream s(&f); | 533 | QTextStream s(&f); |
534 | dataSize = f.size(); | 534 | dataSize = f.size(); |
535 | fileData = (char *) malloc(dataSize + 3); | 535 | fileData = (char *) malloc(dataSize + 3); |
536 | s.readRawBytes(fileData, dataSize); | 536 | s.readRawBytes(fileData, dataSize); |
537 | 537 | ||
538 | temp = ""; | 538 | temp = ""; |
539 | dataPtr = fileData; | 539 | dataPtr = fileData; |
540 | count = 0; | 540 | count = 0; |
541 | while (dataSize > 0) { | 541 | while (dataSize > 0) { |
542 | if (dataSize < 3) { | 542 | if (dataSize < 3) { |
543 | encode64base(dataPtr, &temp, dataSize); | 543 | encode64base(dataPtr, &temp, dataSize); |
544 | dataSize = 0; | 544 | dataSize = 0; |
545 | } else { | 545 | } else { |
546 | encode64base(dataPtr, &temp, 3); | 546 | encode64base(dataPtr, &temp, 3); |
547 | dataSize -= 3; | 547 | dataSize -= 3; |
548 | dataPtr += 3; | 548 | dataPtr += 3; |
549 | count += 4; | 549 | count += 4; |
550 | } | 550 | } |
551 | if (count > 72) { | 551 | if (count > 72) { |
552 | count = 0; | 552 | count = 0; |
553 | temp += "\r\n"; | 553 | temp += "\r\n"; |
554 | } | 554 | } |
555 | } | 555 | } |
556 | toBody->append(temp); | 556 | toBody->append(temp); |
557 | 557 | ||
558 | delete(fileData); | 558 | delete(fileData); |
559 | f.close(); | 559 | f.close(); |
560 | return 0; | 560 | return 0; |
561 | } | 561 | } |
562 | 562 | ||
563 | void EmailHandler::encode64base(char *src, QString *dest, int len) | 563 | void EmailHandler::encode64base(char *src, QString *dest, int len) |
564 | { | 564 | { |
565 | QString temp; | 565 | QString temp; |
566 | uchar c; | 566 | uchar c; |
567 | uchar bufOut[4]; | 567 | uchar bufOut[4]; |
568 | 568 | ||
569 | bufOut[0] = src[0]; | 569 | bufOut[0] = src[0]; |
570 | bufOut[0] >>= 2; //Done byte 0 | 570 | bufOut[0] >>= 2; //Done byte 0 |
571 | 571 | ||
572 | bufOut[1] = src[0]; | 572 | bufOut[1] = src[0]; |
573 | bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits | 573 | bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits |
574 | bufOut[1] <<= 4; //copy up 4 places | 574 | bufOut[1] <<= 4; //copy up 4 places |
575 | if (len > 1) { | 575 | if (len > 1) { |
576 | c = src[1]; | 576 | c = src[1]; |
577 | } else { | 577 | } else { |
578 | c = 0; | 578 | c = 0; |
579 | } | 579 | } |
580 | 580 | ||
581 | c = c & (16 + 32 + 64 + 128); | 581 | c = c & (16 + 32 + 64 + 128); |
582 | c >>= 4; | 582 | c >>= 4; |
583 | bufOut[1] = bufOut[1] | c; //Done byte 1 | 583 | bufOut[1] = bufOut[1] | c; //Done byte 1 |
584 | 584 | ||
585 | bufOut[2] = src[1]; | 585 | bufOut[2] = src[1]; |
586 | bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8); | 586 | bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8); |
587 | bufOut[2] <<= 2; | 587 | bufOut[2] <<= 2; |
588 | if (len > 2) { | 588 | if (len > 2) { |
589 | c = src[2]; | 589 | c = src[2]; |
590 | } else { | 590 | } else { |
591 | c = 0; | 591 | c = 0; |
592 | } | 592 | } |
593 | c >>= 6; | 593 | c >>= 6; |
594 | bufOut[2] = bufOut[2] | c; | 594 | bufOut[2] = bufOut[2] | c; |
595 | 595 | ||
596 | bufOut[3] = src[2]; | 596 | bufOut[3] = src[2]; |
597 | bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32); | 597 | bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32); |
598 | 598 | ||
599 | if (len == 1) { | 599 | if (len == 1) { |
600 | bufOut[2] = 64; | 600 | bufOut[2] = 64; |
601 | bufOut[3] = 64; | 601 | bufOut[3] = 64; |
602 | } | 602 | } |
603 | if (len == 2) { | 603 | if (len == 2) { |
604 | bufOut[3] = 64; | 604 | bufOut[3] = 64; |
605 | } | 605 | } |
606 | for (int x = 0; x < 4; x++) { | 606 | for (int x = 0; x < 4; x++) { |
607 | if (bufOut[x] <= 25) | 607 | if (bufOut[x] <= 25) |
608 | bufOut[x] += (uint) 'A'; | 608 | bufOut[x] += (uint) 'A'; |
609 | else if (bufOut[x] >= 26 && bufOut[x] <= 51) | 609 | else if (bufOut[x] >= 26 && bufOut[x] <= 51) |
610 | bufOut[x] += (uint) 'a' - 26; | 610 | bufOut[x] += (uint) 'a' - 26; |
611 | else if (bufOut[x] >= 52 && bufOut[x] <= 61) | 611 | else if (bufOut[x] >= 52 && bufOut[x] <= 61) |
612 | bufOut[x] += (uint) '0' - 52; | 612 | bufOut[x] += (uint) '0' - 52; |
613 | else if (bufOut[x] == 62) | 613 | else if (bufOut[x] == 62) |
614 | bufOut[x] = '+'; | 614 | bufOut[x] = '+'; |
615 | else if (bufOut[x] == 63) | 615 | else if (bufOut[x] == 63) |
616 | bufOut[x] = '/'; | 616 | bufOut[x] = '/'; |
617 | else if (bufOut[x] == 64) | 617 | else if (bufOut[x] == 64) |
618 | bufOut[x] = '='; | 618 | bufOut[x] = '='; |
619 | 619 | ||
620 | dest->append(bufOut[x]); | 620 | dest->append(bufOut[x]); |
621 | } | 621 | } |
622 | } | 622 | } |
623 | 623 | ||
624 | void EmailHandler::cancel() | 624 | void EmailHandler::cancel() |
625 | { | 625 | { |
626 | popClient->errorHandling(ErrCancel); | 626 | popClient->errorHandling(ErrCancel); |
627 | smtpClient->errorHandling(ErrCancel); | 627 | smtpClient->errorHandling(ErrCancel); |
628 | } | 628 | } |
diff --git a/noncore/net/mailit/emailhandler.h b/noncore/net/mailit/emailhandler.h index e47fd9a..b645868 100644 --- a/noncore/net/mailit/emailhandler.h +++ b/noncore/net/mailit/emailhandler.h | |||
@@ -1,148 +1,149 @@ | |||
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 | 31 | ||
32 | #include "smtpclient.h" | 32 | #include "smtpclient.h" |
33 | #include "popclient.h" | 33 | #include "popclient.h" |
34 | #include "textparser.h" | 34 | #include "textparser.h" |
35 | #include "maillist.h" | 35 | #include "maillist.h" |
36 | 36 | ||
37 | struct Enclosure | 37 | struct Enclosure |
38 | { | 38 | { |
39 | int id; | 39 | int id; |
40 | QString originalName; | 40 | QString originalName; |
41 | QString name; | 41 | QString name; |
42 | QString path; | 42 | QString path; |
43 | QString contentType; | 43 | QString contentType; |
44 | QString contentAttribute; | 44 | QString contentAttribute; |
45 | QString encoding; | 45 | QString encoding; |
46 | QString body; //might use to much mem. check!! | 46 | QString body; //might use to much mem. check!! |
47 | bool saved, installed; | 47 | bool saved, installed; |
48 | }; | 48 | }; |
49 | 49 | ||
50 | class EnclosureList : public QList<Enclosure> | 50 | class EnclosureList : public QList<Enclosure> |
51 | { | 51 | { |
52 | public: | 52 | public: |
53 | Item newItem(Item d); | 53 | Item newItem(Item d); |
54 | private: | 54 | private: |
55 | Enclosure* dupl(Enclosure *in); | 55 | Enclosure* dupl(Enclosure *in); |
56 | Enclosure *ac; | 56 | Enclosure *ac; |
57 | }; | 57 | }; |
58 | 58 | ||
59 | struct Email | 59 | struct Email |
60 | { | 60 | { |
61 | QString id; | 61 | QString id; |
62 | QString from; | 62 | QString from; |
63 | QString fromMail; | 63 | QString fromMail; |
64 | QStringList recipients; | 64 | QStringList recipients; |
65 | QStringList carbonCopies; | 65 | QStringList carbonCopies; |
66 | QString date; | 66 | QString date; |
67 | QString subject; | 67 | QString subject; |
68 | QString body; | 68 | QString body; |
69 | QString bodyPlain; | 69 | QString bodyPlain; |
70 | bool sent, received, read, downloaded; | 70 | bool sent, received, read, downloaded; |
71 | QString rawMail; | 71 | QString rawMail; |
72 | int mimeType; //1 = Mime 1.0 | 72 | int mimeType; //1 = Mime 1.0 |
73 | int serverId; | 73 | int serverId; |
74 | int internalId; | 74 | int internalId; |
75 | int fromAccountId; | 75 | int fromAccountId; |
76 | QString contentType; //0 = text | 76 | QString contentType; //0 = text |
77 | QString contentAttribute; //0 = plain, 1 = html | 77 | QString contentAttribute; //0 = plain, 1 = html |
78 | EnclosureList files; | 78 | EnclosureList files; |
79 | uint size; | 79 | uint size; |
80 | 80 | ||
81 | void addEnclosure(Enclosure *e) | 81 | void addEnclosure(Enclosure *e) |
82 | { | 82 | { |
83 | files.append(e); | 83 | files.append(e); |
84 | } | 84 | } |
85 | }; | 85 | }; |
86 | 86 | ||
87 | struct MailAccount | 87 | struct MailAccount |
88 | { | 88 | { |
89 | QString accountName; | 89 | QString accountName; |
90 | QString name; | 90 | QString name; |
91 | QString emailAddress; | 91 | QString emailAddress; |
92 | QString popUserName; | 92 | QString popUserName; |
93 | QString popPasswd; | 93 | QString popPasswd; |
94 | QString popServer; | 94 | QString popServer; |
95 | QString smtpServer; | 95 | QString smtpServer; |
96 | bool synchronize; | 96 | bool synchronize; |
97 | int syncLimit; | 97 | int syncLimit; |
98 | int lastServerMailCount; | 98 | int lastServerMailCount; |
99 | int id; | 99 | int id; |
100 | }; | 100 | }; |
101 | 101 | ||
102 | const int ErrUnknownResponse = 1001; | 102 | const int ErrUnknownResponse = 1001; |
103 | const int ErrLoginFailed = 1002; | 103 | const int ErrLoginFailed = 1002; |
104 | const int ErrCancel = 1003; | 104 | const int ErrCancel = 1003; |
105 | 105 | ||
106 | 106 | ||
107 | class EmailHandler : public QObject | 107 | class EmailHandler : public QObject |
108 | { | 108 | { |
109 | Q_OBJECT | 109 | Q_OBJECT |
110 | 110 | ||
111 | public: | 111 | public: |
112 | EmailHandler(); | 112 | EmailHandler(); |
113 | void setAccount(MailAccount account); | 113 | void setAccount(MailAccount account); |
114 | MailAccount* getAccount(){return &mailAccount;} | ||
114 | void sendMail(QList<Email> *mailList); | 115 | void sendMail(QList<Email> *mailList); |
115 | void getMail(); | 116 | void getMail(); |
116 | void getMailHeaders(); | 117 | void getMailHeaders(); |
117 | void getMailByList(MailList *mailList); | 118 | void getMailByList(MailList *mailList); |
118 | bool parse(QString in, QString lineShift, Email *mail); | 119 | bool parse(QString in, QString lineShift, Email *mail); |
119 | bool getEnclosure(Enclosure *ePtr); | 120 | bool getEnclosure(Enclosure *ePtr); |
120 | int parse64base(char *src, char *dest); | 121 | int parse64base(char *src, char *dest); |
121 | int encodeMime(Email *mail); | 122 | int encodeMime(Email *mail); |
122 | int encodeFile(QString fileName, QString *toBody); | 123 | int encodeFile(QString fileName, QString *toBody); |
123 | void encode64base(char *src, QString *dest, int len); | 124 | void encode64base(char *src, QString *dest, int len); |
124 | void cancel(); | 125 | void cancel(); |
125 | 126 | ||
126 | signals: | 127 | signals: |
127 | void mailSent(); | 128 | void mailSent(); |
128 | void smtpError(int); | 129 | void smtpError(int); |
129 | void popError(int); | 130 | void popError(int); |
130 | void mailArrived(const Email &, bool); | 131 | void mailArrived(const Email &, bool); |
131 | void updatePopStatus(const QString &); | 132 | void updatePopStatus(const QString &); |
132 | void updateSmtpStatus(const QString &); | 133 | void updateSmtpStatus(const QString &); |
133 | void mailTransfered(int); | 134 | void mailTransfered(int); |
134 | void mailboxSize(int); | 135 | void mailboxSize(int); |
135 | void currentMailSize(int); | 136 | void currentMailSize(int); |
136 | void downloadedSize(int); | 137 | void downloadedSize(int); |
137 | 138 | ||
138 | public slots: | 139 | public slots: |
139 | void messageArrived(const QString &, int id, uint size, bool complete); | 140 | void messageArrived(const QString &, int id, uint size, bool complete); |
140 | 141 | ||
141 | private: | 142 | private: |
142 | MailAccount mailAccount; | 143 | MailAccount mailAccount; |
143 | SmtpClient *smtpClient; | 144 | SmtpClient *smtpClient; |
144 | PopClient *popClient; | 145 | PopClient *popClient; |
145 | bool headers; | 146 | bool headers; |
146 | }; | 147 | }; |
147 | 148 | ||
148 | #endif | 149 | #endif |
diff --git a/noncore/net/mailit/mailitwindow.cpp b/noncore/net/mailit/mailitwindow.cpp index 7181adf..ffee67e 100644 --- a/noncore/net/mailit/mailitwindow.cpp +++ b/noncore/net/mailit/mailitwindow.cpp | |||
@@ -1,143 +1,165 @@ | |||
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 "mailitwindow.h" | 22 | #include "mailitwindow.h" |
22 | 23 | ||
23 | MailItWindow::MailItWindow(QWidget *parent, const char *name, WFlags fl) | 24 | MailItWindow::MailItWindow(QWidget *parent, const char *name, WFlags fl) |
24 | : QMainWindow(parent, name, WStyle_ContextHelp) | 25 | : QMainWindow(parent, name, WStyle_ContextHelp) |
25 | { | 26 | { |
26 | currentCaption = "Mailit"; | 27 | currentCaption = "Mailit"; |
27 | setCaption(tr(currentCaption)); | 28 | setCaption(tr(currentCaption)); |
28 | views = new QWidgetStack(this); | 29 | views = new QWidgetStack(this); |
29 | setCentralWidget(views); | 30 | setCentralWidget(views); |
30 | QWhatsThis::add(views,tr("Central view area")); | 31 | QWhatsThis::add(views,tr("Central view area")); |
31 | emailClient = new EmailClient(views, "client"); | 32 | emailClient = new EmailClient(views, "client"); |
32 | writeMail = new WriteMail(views, "writing"); | 33 | writeMail = new WriteMail(views, "writing"); |
33 | readMail = new ReadMail(views, "reading"); | 34 | readMail = new ReadMail(views, "reading"); |
34 | 35 | ||
35 | views->raiseWidget(emailClient); | 36 | views->raiseWidget(emailClient); |
36 | 37 | ||
37 | connect(emailClient, SIGNAL(composeRequested()), | 38 | connect(emailClient, SIGNAL(composeRequested()), |
38 | this, SLOT(compose()) ); | 39 | this, SLOT(compose()) ); |
39 | connect(emailClient, SIGNAL(viewEmail(QListView *, Email *)), this, | 40 | connect(emailClient, SIGNAL(viewEmail(QListView *, Email *)), this, |
40 | SLOT(viewMail(QListView *, Email *)) ); | 41 | SLOT(viewMail(QListView *, Email *)) ); |
41 | connect(emailClient, SIGNAL(mailUpdated(Email *)), this, | 42 | connect(emailClient, SIGNAL(mailUpdated(Email *)), this, |
42 | SLOT(updateMailView(Email *)) ); | 43 | SLOT(updateMailView(Email *)) ); |
43 | 44 | ||
44 | connect(writeMail, SIGNAL(cancelMail()), this, SLOT(showEmailClient()) ); | 45 | connect(writeMail, SIGNAL(cancelMail()), this, SLOT(showEmailClient()) ); |
45 | connect(writeMail, SIGNAL(sendMailRequested(const Email &)), this, | 46 | connect(writeMail, SIGNAL(sendMailRequested(const Email &)), this, |
46 | SLOT(showEmailClient()) ); | 47 | SLOT(showEmailClient()) ); |
47 | connect(writeMail, SIGNAL(sendMailRequested(const Email &)), emailClient, | 48 | connect(writeMail, SIGNAL(sendMailRequested(const Email &)), emailClient, |
48 | SLOT(enqueMail(const Email &)) ); | 49 | SLOT(enqueMail(const Email &)) ); |
49 | 50 | ||
50 | connect(readMail, SIGNAL(cancelView()), this, SLOT(showEmailClient()) ); | 51 | connect(readMail, SIGNAL(cancelView()), this, SLOT(showEmailClient()) ); |
51 | connect(readMail, SIGNAL(replyRequested(Email &, bool&)), this, | 52 | connect(readMail, SIGNAL(replyRequested(Email &, bool&)), this, |
52 | SLOT(composeReply(Email &, bool&)) ); | 53 | SLOT(composeReply(Email &, bool&)) ); |
53 | connect(readMail, SIGNAL(forwardRequested(Email &)), this, | 54 | connect(readMail, SIGNAL(forwardRequested(Email &)), this, |
54 | SLOT(composeForward(Email &)) ); | 55 | SLOT(composeForward(Email &)) ); |
55 | 56 | ||
56 | connect(readMail, SIGNAL(removeItem(EmailListItem *, bool &)), emailClient, | 57 | connect(readMail, SIGNAL(removeItem(EmailListItem *, bool &)), emailClient, |
57 | SLOT(deleteMail(EmailListItem *, bool &)) ); | 58 | SLOT(deleteMail(EmailListItem *, bool &)) ); |
58 | connect(readMail, SIGNAL(viewingMail(Email *)), emailClient, | 59 | connect(readMail, SIGNAL(viewingMail(Email *)), emailClient, |
59 | SLOT(moveMailFront(Email *)) ); | 60 | SLOT(moveMailFront(Email *)) ); |
60 | 61 | ||
61 | connect(emailClient, SIGNAL(newCaption(const QString &)), | 62 | connect(emailClient, SIGNAL(newCaption(const QString &)), |
62 | this, SLOT(updateCaption(const QString &)) ); | 63 | this, SLOT(updateCaption(const QString &)) ); |
63 | viewingMail = FALSE; | 64 | viewingMail = FALSE; |
64 | |||
65 | } | 65 | } |
66 | 66 | ||
67 | MailItWindow::~MailItWindow() | 67 | MailItWindow::~MailItWindow() |
68 | { | 68 | { |
69 | } | 69 | } |
70 | 70 | ||
71 | void MailItWindow::closeEvent(QCloseEvent *e) | 71 | void MailItWindow::closeEvent(QCloseEvent *e) |
72 | { | 72 | { |
73 | if (views->visibleWidget() == emailClient) { | 73 | if (views->visibleWidget() == emailClient) { |
74 | e->accept(); | 74 | e->accept(); |
75 | } else { | 75 | } else { |
76 | showEmailClient(); | 76 | showEmailClient(); |
77 | } | 77 | } |
78 | } | 78 | } |
79 | 79 | ||
80 | void MailItWindow::compose() | 80 | void MailItWindow::compose() |
81 | { | 81 | { |
82 | viewingMail = FALSE; | 82 | viewingMail = FALSE; |
83 | emailClient->hide(); | 83 | emailClient->hide(); |
84 | readMail->hide(); | 84 | readMail->hide(); |
85 | views->raiseWidget(writeMail); | 85 | views->raiseWidget(writeMail); |
86 | writeMail->setAddressList(emailClient->getAdrListRef()); | 86 | writeMail->setAddressList(emailClient->getAdrListRef()); |
87 | writeMail->newMail(); | ||
87 | setCaption( tr( "Write mail" ) ); | 88 | setCaption( tr( "Write mail" ) ); |
88 | } | 89 | } |
89 | 90 | ||
90 | void MailItWindow::composeReply(Email &mail, bool& replyAll) | 91 | void MailItWindow::composeReply(Email &mail, bool& replyAll) |
91 | { | 92 | { |
92 | compose(); | 93 | compose(); |
93 | writeMail->reply(mail,replyAll) ; | 94 | writeMail->reply(mail,replyAll) ; |
94 | } | 95 | } |
95 | 96 | ||
96 | void MailItWindow::composeForward(Email &mail) | 97 | void MailItWindow::composeForward(Email &mail) |
97 | { | 98 | { |
98 | compose(); | 99 | compose(); |
99 | writeMail->forward(mail) ; | 100 | writeMail->forward(mail) ; |
100 | } | 101 | } |
101 | 102 | ||
102 | 103 | ||
103 | void MailItWindow::showEmailClient() | 104 | void MailItWindow::showEmailClient() |
104 | { | 105 | { |
105 | viewingMail = FALSE; | 106 | viewingMail = FALSE; |
106 | writeMail->hide(); | 107 | writeMail->hide(); |
107 | readMail->hide(); | 108 | readMail->hide(); |
108 | views->raiseWidget(emailClient); | 109 | views->raiseWidget(emailClient); |
109 | setCaption( tr(currentCaption) ); | 110 | setCaption( tr(currentCaption) ); |
110 | } | 111 | } |
111 | 112 | ||
112 | void MailItWindow::viewMail(QListView *view, Email *mail) | 113 | void MailItWindow::viewMail(QListView *view, Email *mail) |
113 | { | 114 | { |
114 | viewingMail = TRUE; | 115 | viewingMail = TRUE; |
115 | emailClient->hide(); | 116 | emailClient->hide(); |
117 | |||
118 | int result=0; | ||
119 | |||
120 | if ((mail->received)&&(!mail->downloaded)) | ||
121 | { | ||
122 | QMessageBox mb( tr("Mail not downloaded"), | ||
123 | tr("The mail you have clicked \n" | ||
124 | "has not been downloaded yet.\n " | ||
125 | "Would you like to do it now ?"), | ||
126 | QMessageBox::Information, | ||
127 | QMessageBox::Yes | QMessageBox::Default, | ||
128 | QMessageBox::No | QMessageBox::Escape,0 ); | ||
129 | |||
130 | result=mb.exec(); | ||
131 | |||
132 | if (result==QMessageBox::Yes) | ||
133 | { | ||
134 | emailClient->download(mail); | ||
135 | } | ||
136 | } | ||
137 | |||
116 | readMail->update(view, mail); | 138 | readMail->update(view, mail); |
117 | views->raiseWidget(readMail); | 139 | views->raiseWidget(readMail); |
118 | setCaption( tr( "Examine mail" ) ); | 140 | setCaption( tr( "Examine mail" ) ); |
119 | } | 141 | } |
120 | 142 | ||
121 | void MailItWindow::updateMailView(Email *mail) | 143 | void MailItWindow::updateMailView(Email *mail) |
122 | { | 144 | { |
123 | if (viewingMail) { | 145 | if (viewingMail) { |
124 | readMail->mailUpdated(mail); | 146 | readMail->mailUpdated(mail); |
125 | } | 147 | } |
126 | } | 148 | } |
127 | 149 | ||
128 | void MailItWindow::updateCaption(const QString &newCaption) | 150 | void MailItWindow::updateCaption(const QString &newCaption) |
129 | { | 151 | { |
130 | currentCaption = newCaption; | 152 | currentCaption = newCaption; |
131 | setCaption(tr(currentCaption)); | 153 | setCaption(tr(currentCaption)); |
132 | } | 154 | } |
133 | 155 | ||
134 | void MailItWindow::setDocument(const QString &_address) | 156 | void MailItWindow::setDocument(const QString &_address) |
135 | { | 157 | { |
136 | // strip leading 'mailto:' | 158 | // strip leading 'mailto:' |
137 | QString address = _address; | 159 | QString address = _address; |
138 | if (address.startsWith("mailto:")) | 160 | if (address.startsWith("mailto:")) |
139 | address = address.mid(6); | 161 | address = address.mid(6); |
140 | 162 | ||
141 | compose(); | 163 | compose(); |
142 | writeMail->setRecipient(address); | 164 | writeMail->setRecipient(address); |
143 | } | 165 | } |
diff --git a/noncore/net/mailit/popclient.cpp b/noncore/net/mailit/popclient.cpp index 67306be..6105d09 100644 --- a/noncore/net/mailit/popclient.cpp +++ b/noncore/net/mailit/popclient.cpp | |||
@@ -1,367 +1,325 @@ | |||
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 | ||
24 | extern "C" { | 24 | extern "C" { |
25 | #include "md5.h" | 25 | #include "md5.h" |
26 | } | 26 | } |
27 | 27 | ||
28 | #include <qcstring.h> | 28 | #include <qcstring.h> |
29 | 29 | ||
30 | PopClient::PopClient() | 30 | PopClient::PopClient() |
31 | { | 31 | { |
32 | socket = new QSocket(this, "popClient"); | 32 | socket = new QSocket(this, "popClient"); |
33 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); | 33 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); |
34 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); | 34 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); |
35 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); | 35 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); |
36 | 36 | ||
37 | stream = new QTextStream(socket); | 37 | stream = new QTextStream(socket); |
38 | 38 | ||
39 | receiving = FALSE; | 39 | receiving = FALSE; |
40 | synchronize = FALSE; | 40 | synchronize = FALSE; |
41 | lastSync = 0; | 41 | lastSync = 0; |
42 | headerLimit = 0; | 42 | headerLimit = 0; |
43 | preview = FALSE; | 43 | preview = FALSE; |
44 | } | 44 | } |
45 | 45 | ||
46 | PopClient::~PopClient() | 46 | PopClient::~PopClient() |
47 | { | 47 | { |
48 | delete socket; | 48 | delete socket; |
49 | delete stream; | 49 | delete stream; |
50 | } | 50 | } |
51 | 51 | ||
52 | void PopClient::newConnection(QString target, int port) | 52 | void PopClient::newConnection(QString target, int port) |
53 | { | 53 | { |
54 | if (receiving) { | 54 | if (receiving) { |
55 | qWarning("socket in use, connection refused"); | 55 | qWarning("socket in use, connection refused"); |
56 | return; | 56 | return; |
57 | } | 57 | } |
58 | 58 | ||
59 | status = Init; | 59 | status = Init; |
60 | 60 | ||
61 | socket->connectToHost(target, port); | 61 | socket->connectToHost(target, port); |
62 | receiving = TRUE; | 62 | receiving = TRUE; |
63 | selected = FALSE; | 63 | //selected = FALSE; |
64 | 64 | ||
65 | emit updateStatus("DNS lookup"); | 65 | emit updateStatus("DNS lookup"); |
66 | } | 66 | } |
67 | 67 | ||
68 | void PopClient::setAccount(QString popUser, QString popPasswd) | 68 | void PopClient::setAccount(QString popUser, QString popPasswd) |
69 | { | 69 | { |
70 | popUserName = popUser; | 70 | popUserName = popUser; |
71 | popPassword = popPasswd; | 71 | popPassword = popPasswd; |
72 | } | 72 | } |
73 | 73 | ||
74 | void PopClient::setSynchronize(int lastCount) | 74 | void PopClient::setSynchronize(int lastCount) |
75 | { | 75 | { |
76 | synchronize = TRUE; | 76 | synchronize = TRUE; |
77 | lastSync = lastCount; | 77 | lastSync = lastCount; |
78 | } | 78 | } |
79 | 79 | ||
80 | void PopClient::removeSynchronize() | 80 | void PopClient::removeSynchronize() |
81 | { | 81 | { |
82 | synchronize = FALSE; | 82 | synchronize = FALSE; |
83 | lastSync = 0; | 83 | lastSync = 0; |
84 | } | 84 | } |
85 | 85 | ||
86 | void PopClient::headersOnly(bool headers, int limit) | 86 | void PopClient::headersOnly(bool headers, int limit) |
87 | { | 87 | { |
88 | preview = headers; | 88 | preview = headers; |
89 | headerLimit = limit; | 89 | headerLimit = limit; |
90 | } | 90 | } |
91 | 91 | ||
92 | void PopClient::setSelectedMails(MailList *list) | 92 | void PopClient::setSelectedMails(MailList *list) |
93 | { | 93 | { |
94 | selected = TRUE; | 94 | selected = TRUE; |
95 | mailList = list; | 95 | mailList = list; |
96 | } | 96 | } |
97 | 97 | ||
98 | void PopClient::connectionEstablished() | 98 | void PopClient::connectionEstablished() |
99 | { | 99 | { |
100 | emit updateStatus(tr("Connection established")); | 100 | emit updateStatus(tr("Connection established")); |
101 | } | 101 | } |
102 | 102 | ||
103 | void PopClient::errorHandling(int status) | 103 | void PopClient::errorHandling(int status) |
104 | { | 104 | { |
105 | emit updateStatus(tr("Error Occured")); | 105 | emit updateStatus(tr("Error Occured")); |
106 | emit errorOccurred(status); | 106 | emit errorOccurred(status); |
107 | socket->close(); | 107 | socket->close(); |
108 | receiving = FALSE; | 108 | receiving = FALSE; |
109 | } | 109 | } |
110 | 110 | ||
111 | void PopClient::incomingData() | 111 | void PopClient::incomingData() |
112 | { | 112 | { |
113 | QString response, temp, temp2, timeStamp; | 113 | QString response, temp, temp2, timeStamp; |
114 | QString md5Source; | 114 | QString md5Source; |
115 | int start, end; | 115 | int start, end; |
116 | // char *md5Digest; | 116 | // char *md5Digest; |
117 | char md5Digest[16]; | 117 | char md5Digest[16]; |
118 | // if ( !socket->canReadLine() ) | 118 | // if ( !socket->canReadLine() ) |
119 | // return; | 119 | // return; |
120 | 120 | ||
121 | response = socket->readLine(); | 121 | response = socket->readLine(); |
122 | 122 | ||
123 | switch(status) { | 123 | switch(status) { |
124 | //logging in | 124 | //logging in |
125 | case Init: { | 125 | case Init: { |
126 | #ifdef APOP_TEST | 126 | #ifdef APOP_TEST |
127 | start = response.find('<',0); | 127 | start = response.find('<',0); |
128 | end = response.find('>', start); | 128 | end = response.find('>', start); |
129 | if( start >= 0 && end > start ) | 129 | if( start >= 0 && end > start ) |
130 | { | 130 | { |
131 | timeStamp = response.mid( start , end - start + 1); | 131 | timeStamp = response.mid( start , end - start + 1); |
132 | md5Source = timeStamp + popPassword; | 132 | md5Source = timeStamp + popPassword; |
133 | 133 | ||
134 | md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); | 134 | md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); |
135 | 135 | ||
136 | for(int j =0;j < MD5_DIGEST_LENGTH ;j++) | 136 | for(int j =0;j < MD5_DIGEST_LENGTH ;j++) |
137 | { | 137 | { |
138 | printf("%x", md5Digest[j]); | 138 | printf("%x", md5Digest[j]); |
139 | } | 139 | } |
140 | printf("\n"); | 140 | printf("\n"); |
141 | // qDebug(md5Digest); | 141 | // qDebug(md5Digest); |
142 | *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; | 142 | *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; |
143 | // qDebug("%s", stream); | 143 | // qDebug("%s", stream); |
144 | status = Stat; | 144 | status = Stat; |
145 | } | 145 | } |
146 | else | 146 | else |
147 | #endif | 147 | #endif |
148 | { | 148 | { |
149 | timeStamp = ""; | 149 | timeStamp = ""; |
150 | *stream << "USER " << popUserName << "\r\n"; | 150 | *stream << "USER " << popUserName << "\r\n"; |
151 | status = Pass; | 151 | status = Pass; |
152 | } | 152 | } |
153 | 153 | ||
154 | break; | 154 | break; |
155 | } | 155 | } |
156 | 156 | ||
157 | case Pass: { | 157 | case Pass: { |
158 | *stream << "PASS " << popPassword << "\r\n"; | 158 | *stream << "PASS " << popPassword << "\r\n"; |
159 | status = Stat; | 159 | status = Stat; |
160 | break; | 160 | break; |
161 | } | 161 | } |
162 | //ask for number of messages | 162 | //ask for number of messages |
163 | case Stat: { | 163 | case Stat: { |
164 | if (response[0] == '+') { | 164 | if (response[0] == '+') { |
165 | *stream << "STAT" << "\r\n"; | 165 | *stream << "STAT" << "\r\n"; |
166 | status = Mcnt; | 166 | status = Mcnt; |
167 | } else errorHandling(ErrLoginFailed); | 167 | } else errorHandling(ErrLoginFailed); |
168 | break; | 168 | break; |
169 | } | 169 | } |
170 | //get count of messages, eg "+OK 4 900.." -> int 4 | 170 | //get count of messages, eg "+OK 4 900.." -> int 4 |
171 | case Mcnt: { | 171 | case Mcnt: { |
172 | if (response[0] == '+') { | 172 | if (response[0] == '+') { |
173 | temp = response.replace(0, 4, ""); | 173 | temp = response.replace(0, 4, ""); |
174 | int x = temp.find(" ", 0); | 174 | int x = temp.find(" ", 0); |
175 | temp.truncate((uint) x); | 175 | temp.truncate((uint) x); |
176 | newMessages = temp.toInt(); | 176 | newMessages = temp.toInt(); |
177 | messageCount = 1; | 177 | messageCount = 1; |
178 | status = List; | 178 | status = List; |
179 | 179 | ||
180 | if (synchronize) { | 180 | if (synchronize) { |
181 | //messages deleted from server, reload all | 181 | //messages deleted from server, reload all |
182 | if (newMessages < lastSync) | 182 | if (newMessages < lastSync) |
183 | lastSync = 0; | 183 | lastSync = 0; |
184 | messageCount = 1; | 184 | messageCount = 1; |
185 | } | 185 | } |
186 | 186 | ||
187 | if (selected) { | 187 | if (selected) { |
188 | int *ptr = mailList->first(); | 188 | int *ptr = mailList->first(); |
189 | if (ptr != 0) { | 189 | if (ptr != 0) { |
190 | newMessages++; //to ensure no early jumpout | 190 | newMessages++; //to ensure no early jumpout |
191 | messageCount = *(mailList->first()); | 191 | messageCount = *ptr; |
192 | } else newMessages = 0; | 192 | } else newMessages = 0; |
193 | } | 193 | } |
194 | |||
194 | } else errorHandling(ErrUnknownResponse); | 195 | } else errorHandling(ErrUnknownResponse); |
195 | } | 196 | } |
196 | //Read message number x, count upwards to messageCount | 197 | //Read message number x, count upwards to messageCount |
197 | case List: { | 198 | case List: { |
198 | if (messageCount <= newMessages) { | 199 | if (messageCount <= newMessages) { |
199 | *stream << "LIST " << messageCount << "\r\n"; | 200 | *stream << "LIST " << messageCount << "\r\n"; |
200 | status = Size; | 201 | status = Size; |
201 | temp2.setNum(newMessages - lastSync); | 202 | temp2.setNum(newMessages - lastSync); |
202 | temp.setNum(messageCount - lastSync); | 203 | temp.setNum(messageCount - lastSync); |
203 | if (!selected) { | 204 | if (!selected) { |
204 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); | 205 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); |
205 | } else { | 206 | } else { |
206 | //completing a previously closed transfer | 207 | //completing a previously closed transfer |
207 | if ( (messageCount - lastSync) <= 0) { | 208 | /* if ( (messageCount - lastSync) <= 0) { |
208 | temp.setNum(messageCount); | 209 | temp.setNum(messageCount); |
209 | emit updateStatus(tr("Previous message ") + temp); | 210 | emit updateStatus(tr("Previous message ") + temp); |
210 | } else { | 211 | } else {*/ |
211 | emit updateStatus(tr("Completing message ") + temp); | 212 | emit updateStatus(tr("Completing message ") + temp); |
212 | } | 213 | //} |
213 | } | 214 | } |
214 | break; | 215 | break; |
215 | } else { | 216 | } else { |
216 | emit updateStatus(tr("No new Messages")); | 217 | emit updateStatus(tr("No new Messages")); |
217 | status = Quit; | 218 | status = Quit; |
218 | } | 219 | } |
219 | } | 220 | } |
220 | //get size of message, eg "500 characters in message.." -> int 500 | 221 | //get size of message, eg "500 characters in message.." -> int 500 |
221 | case Size: { | 222 | case Size: { |
222 | if (status != Quit) { //because of idiotic switch | 223 | if (status != Quit) { //because of idiotic switch |
223 | if (response[0] == '+') { | 224 | if (response[0] == '+') { |
224 | temp = response.replace(0, 4, ""); | 225 | temp = response.replace(0, 4, ""); |
225 | int x = temp.find(" ", 0); | 226 | int x = temp.find(" ", 0); |
226 | temp = temp.right(temp.length() - ((uint) x + 1) ); | 227 | temp = temp.right(temp.length() - ((uint) x + 1) ); |
227 | mailSize = temp.toInt(); | 228 | mailSize = temp.toInt(); |
228 | emit currentMailSize(mailSize); | 229 | emit currentMailSize(mailSize); |
229 | 230 | ||
230 | status = Retr; | 231 | status = Retr; |
231 | } else { | 232 | } else { |
232 | //qWarning(response); | 233 | //qWarning(response); |
233 | errorHandling(ErrUnknownResponse); | 234 | errorHandling(ErrUnknownResponse); |
234 | } | 235 | } |
235 | } | 236 | } |
236 | } | 237 | } |
237 | //Read message number x, count upwards to messageCount | 238 | //Read message number x, count upwards to messageCount |
238 | case Retr: { | 239 | case Retr: { |
239 | if (status != Quit) { | 240 | if (status != Quit) { |
240 | if (mailSize <= headerLimit) | 241 | if ((selected)||(mailSize <= headerLimit)) |
241 | { | 242 | { |
242 | *stream << "RETR " << messageCount << "\r\n"; | 243 | *stream << "RETR " << messageCount << "\r\n"; |
243 | } else { //only header | 244 | } else { //only header |
244 | *stream << "TOP " << messageCount << " 0\r\n"; | 245 | *stream << "TOP " << messageCount << " 0\r\n"; |
245 | } | 246 | } |
246 | messageCount++; | 247 | messageCount++; |
247 | status = Ignore; | 248 | status = Ignore; |
248 | break; | 249 | break; |
249 | } } | 250 | } } |
250 | case Ignore: { | 251 | case Ignore: { |
251 | if (status != Quit) { //because of idiotic switch | 252 | if (status != Quit) { //because of idiotic switch |
252 | if (response[0] == '+') { | 253 | if (response[0] == '+') { |
253 | message = ""; | 254 | message = ""; |
254 | status = Read; | 255 | status = Read; |
255 | if (!socket->canReadLine()) //sync. problems | 256 | if (!socket->canReadLine()) //sync. problems |
256 | break; | 257 | break; |
257 | response = socket->readLine(); | 258 | response = socket->readLine(); |
258 | } else errorHandling(ErrUnknownResponse); | 259 | } else errorHandling(ErrUnknownResponse); |
259 | } | 260 | } |
260 | } | 261 | } |
261 | //add all incoming lines to body. When size is reached, send | 262 | //add all incoming lines to body. When size is reached, send |
262 | //message, and go back to read new message | 263 | //message, and go back to read new message |
263 | case Read: { | 264 | case Read: { |
264 | if (status != Quit) { //because of idiotic switch | 265 | if (status != Quit) { //because of idiotic switch |
265 | message += response; | 266 | message += response; |
266 | while ( socket->canReadLine() ) { | 267 | while ( socket->canReadLine() ) { |
267 | response = socket->readLine(); | 268 | response = socket->readLine(); |
268 | message += response; | 269 | message += response; |
269 | } | 270 | } |
270 | emit downloadedSize(message.length()); | 271 | emit downloadedSize(message.length()); |
271 | int x = message.find("\r\n.\r\n",-5); | 272 | int x = message.find("\r\n.\r\n",-5); |
272 | if (x == -1) { | 273 | if (x == -1) { |
273 | break; | 274 | break; |
274 | } else { //message reach entire size | 275 | } else { //message reach entire size |
275 | //complete mail downloaded | 276 | |
276 | //if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){ | 277 | if ( (selected)||(mailSize <= headerLimit)) //mail size limit is not used if late download is active |
277 | if ( mailSize <= headerLimit) | ||
278 | { | 278 | { |
279 | emit newMessage(message, messageCount-1, mailSize, TRUE); | 279 | emit newMessage(message, messageCount-1, mailSize, TRUE); |
280 | } else { //incomplete mail downloaded | 280 | } else { //incomplete mail downloaded |
281 | emit newMessage(message, messageCount-1, mailSize, FALSE); | 281 | emit newMessage(message, messageCount-1, mailSize, FALSE); |
282 | } | 282 | } |
283 | if (messageCount > newMessages) //that was the last message | 283 | |
284 | if ((messageCount > newMessages)||(selected)) //last message ? | ||
285 | { | ||
284 | status = Quit; | 286 | status = Quit; |
285 | else { //ask for new message | ||
286 | if (selected) { //grab next from queue | 287 | if (selected) { //grab next from queue |
287 | int *ptr = mailList->next(); | ||
288 | if (ptr != 0) { | ||
289 | messageCount = *ptr; | ||
290 | *stream << "LIST " << messageCount << "\r\n"; | ||
291 | status = Size; | ||
292 | //completing a previously closed transfer | ||
293 | if ( (messageCount - lastSync) <= 0) { | ||
294 | temp.setNum(messageCount); | ||
295 | emit updateStatus(tr("Previous message ") + temp); | ||
296 | } else { | ||
297 | temp.setNum(messageCount - lastSync); | ||
298 | emit updateStatus(tr("Completing message ") + temp); | ||
299 | } | ||
300 | break; | ||
301 | } else { | ||
302 | newMessages--; | 288 | newMessages--; |
303 | status = Quit; | 289 | status = Quit; |
304 | } | 290 | } |
305 | } else { | 291 | } |
292 | else | ||
293 | { | ||
306 | *stream << "LIST " << messageCount << "\r\n"; | 294 | *stream << "LIST " << messageCount << "\r\n"; |
307 | status = Size; | 295 | status = Size; |
308 | temp2.setNum(newMessages - lastSync); | 296 | temp2.setNum(newMessages - lastSync); |
309 | temp.setNum(messageCount - lastSync); | 297 | temp.setNum(messageCount - lastSync); |
310 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); | 298 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); |
311 | 299 | ||
312 | break; | 300 | break; |
313 | } | 301 | } |
314 | } | 302 | } |
315 | } | 303 | } |
316 | if (status != Quit) | 304 | if (status != Quit) |
317 | break; | 305 | break; |
318 | } | ||
319 | } | 306 | } |
320 | case Quit: { | 307 | case Quit: { |
321 | *stream << "Quit\r\n"; | 308 | *stream << "Quit\r\n"; |
322 | status = Done; | 309 | status = Done; |
323 | int newM = newMessages - lastSync; | 310 | int newM = newMessages - lastSync; |
324 | if (newM > 0) { | 311 | if (newM > 0) { |
325 | temp.setNum(newM); | 312 | temp.setNum(newM); |
326 | emit updateStatus(temp + tr(" new messages")); | 313 | emit updateStatus(temp + tr(" new messages")); |
327 | } else { | 314 | } else { |
328 | emit updateStatus(tr("No new messages")); | 315 | emit updateStatus(tr("No new messages")); |
329 | } | 316 | } |
330 | 317 | ||
331 | socket->close(); | 318 | socket->close(); |
332 | receiving = FALSE; | 319 | receiving = FALSE; |
333 | emit mailTransfered(newM); | 320 | emit mailTransfered(newM); |
334 | break; | 321 | break; |
335 | } | 322 | } |
336 | } | 323 | } |
337 | 324 | ||
338 | } | 325 | } |
339 | |||
340 | // if( bAPOPAuthentication ) | ||
341 | // { | ||
342 | // if( m_strTimeStamp.IsEmpty() ) | ||
343 | // { | ||
344 | // SetLastError("Apop error!"); | ||
345 | // return false; | ||
346 | // } | ||
347 | // strMD5Source = m_strTimeStamp+pszPassword; | ||
348 | // strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() ); | ||
349 | // sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst); | ||
350 | // ret = send(m_sPop3Socket , msg , strlen(msg) , NULL); | ||
351 | // if(ret == SOCKET_ERROR) | ||
352 | // { | ||
353 | // SetLastError("Socket error!"); | ||
354 | // m_bSocketOK = false; | ||
355 | // m_bConnected = false; | ||
356 | // return false; | ||
357 | // } | ||
358 | // if( !GetSocketResult(&strResult , COMMAND_END_FLAG) ) | ||
359 | // return false; | ||
360 | // if( 0 == strResult.Find('-' , 0) ) | ||
361 | // { | ||
362 | // SetLastError("Username or Password error!"); | ||
363 | // return false; | ||
364 | // } | ||
365 | // m_bConnected = true; | ||
366 | |||
367 | // } | ||
diff --git a/noncore/net/mailit/writemail.cpp b/noncore/net/mailit/writemail.cpp index 0336c83..dcf0c6e 100644 --- a/noncore/net/mailit/writemail.cpp +++ b/noncore/net/mailit/writemail.cpp | |||
@@ -1,381 +1,389 @@ | |||
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 | ||
25 | WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl ) | 25 | WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl ) |
26 | : QMainWindow( parent, name, fl ) | 26 | : QMainWindow( parent, name, fl ) |
27 | { | 27 | { |
28 | showingAddressList = FALSE; | 28 | showingAddressList = FALSE; |
29 | init(); | 29 | init(); |
30 | 30 | ||
31 | addAtt = new AddAtt(0, "Add Attachments"); | 31 | addAtt = new AddAtt(0, "Add Attachments"); |
32 | } | 32 | } |
33 | 33 | ||
34 | WriteMail::~WriteMail() | 34 | WriteMail::~WriteMail() |
35 | { | 35 | { |
36 | delete addAtt; | 36 | delete addAtt; |
37 | } | 37 | } |
38 | 38 | ||
39 | void WriteMail::setAddressList(AddressList *list) | 39 | void WriteMail::setAddressList(AddressList *list) |
40 | { | 40 | { |
41 | Contact *cPtr; | 41 | Contact *cPtr; |
42 | 42 | ||
43 | addressList = list; | 43 | addressList = list; |
44 | 44 | ||
45 | addressView->clear(); | 45 | addressView->clear(); |
46 | QList<Contact> *cListPtr = addressList->getContactList(); | 46 | QList<Contact> *cListPtr = addressList->getContactList(); |
47 | QListViewItem *item; | 47 | QListViewItem *item; |
48 | for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) { | 48 | for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) { |
49 | item = new QListViewItem(addressView, cPtr->name, cPtr->email); | 49 | item = new QListViewItem(addressView, cPtr->name, cPtr->email); |
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
53 | void WriteMail::init() | 53 | void WriteMail::init() |
54 | { | 54 | { |
55 | setToolBarsMovable(FALSE); | 55 | setToolBarsMovable(FALSE); |
56 | 56 | ||
57 | bar = new QToolBar(this); | 57 | bar = new QToolBar(this); |
58 | bar->setHorizontalStretchable( TRUE ); | 58 | bar->setHorizontalStretchable( TRUE ); |
59 | 59 | ||
60 | menu = new QMenuBar( bar ); | 60 | menu = new QMenuBar( bar ); |
61 | 61 | ||
62 | mailMenu = new QPopupMenu(menu); | 62 | mailMenu = new QPopupMenu(menu); |
63 | menu->insertItem( tr( "&Mail" ), mailMenu); | 63 | menu->insertItem( tr( "&Mail" ), mailMenu); |
64 | addMenu = new QPopupMenu(menu); | 64 | addMenu = new QPopupMenu(menu); |
65 | menu->insertItem( tr( "&Add" ), addMenu); | 65 | menu->insertItem( tr( "&Add" ), addMenu); |
66 | 66 | ||
67 | bar = new QToolBar(this); | 67 | bar = new QToolBar(this); |
68 | attachButton = new QAction(tr("Attachment"), Resource::loadPixmap("mailit/attach"), QString::null, 0, this, 0); | 68 | attachButton = new QAction(tr("Attachment"), Resource::loadPixmap("mailit/attach"), QString::null, 0, this, 0); |
69 | attachButton->addTo(bar); | 69 | attachButton->addTo(bar); |
70 | attachButton->addTo(addMenu); | 70 | attachButton->addTo(addMenu); |
71 | connect( attachButton, SIGNAL( activated() ), this, SLOT( attachFile() ) ); | 71 | connect( attachButton, SIGNAL( activated() ), this, SLOT( attachFile() ) ); |
72 | attachButton->setWhatsThis(tr("Click here to attach files to your mail")); | 72 | attachButton->setWhatsThis(tr("Click here to attach files to your mail")); |
73 | 73 | ||
74 | confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0); | 74 | confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0); |
75 | confirmButton->addTo(bar); | 75 | confirmButton->addTo(bar); |
76 | confirmButton->addTo(mailMenu); | 76 | confirmButton->addTo(mailMenu); |
77 | connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) ); | 77 | connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) ); |
78 | confirmButton->setWhatsThis(tr("This button puts your mail in the send queue")); | 78 | confirmButton->setWhatsThis(tr("This button puts your mail in the send queue")); |
79 | 79 | ||
80 | newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0); | 80 | newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0); |
81 | newButton->addTo(mailMenu); | 81 | newButton->addTo(mailMenu); |
82 | connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) ); | 82 | connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) ); |
83 | newButton->setWhatsThis(tr("Click here to create a new mail")); | 83 | newButton->setWhatsThis(tr("Click here to create a new mail")); |
84 | 84 | ||
85 | widget = new QWidget(this, "widget"); | 85 | widget = new QWidget(this, "widget"); |
86 | grid = new QGridLayout( widget ); | 86 | grid = new QGridLayout( widget ); |
87 | 87 | ||
88 | recipientsBox = new QComboBox( FALSE, widget, "toLabel" ); | 88 | recipientsBox = new QComboBox( FALSE, widget, "toLabel" ); |
89 | recipientsBox->insertItem( tr( "To:" ) ); | 89 | recipientsBox->insertItem( tr( "To:" ) ); |
90 | recipientsBox->insertItem( tr( "CC:" ) ); | 90 | recipientsBox->insertItem( tr( "CC:" ) ); |
91 | recipientsBox->setCurrentItem(0); | 91 | recipientsBox->setCurrentItem(0); |
92 | grid->addWidget( recipientsBox, 0, 0 ); | 92 | grid->addWidget( recipientsBox, 0, 0 ); |
93 | connect(recipientsBox,SIGNAL(activated(int)),this, SLOT(changeRecipients(int))); | 93 | connect(recipientsBox,SIGNAL(activated(int)),this, SLOT(changeRecipients(int))); |
94 | 94 | ||
95 | subjetLabel = new QLabel( widget, "subjetLabel" ); | 95 | subjetLabel = new QLabel( widget, "subjetLabel" ); |
96 | subjetLabel->setText( tr( "Subject:" ) ); | 96 | subjetLabel->setText( tr( "Subject:" ) ); |
97 | 97 | ||
98 | grid->addWidget( subjetLabel, 1, 0 ); | 98 | grid->addWidget( subjetLabel, 1, 0 ); |
99 | 99 | ||
100 | ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" ); | 100 | ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" ); |
101 | ToolButton13_2->setText( tr( "..." ) ); | 101 | ToolButton13_2->setText( tr( "..." ) ); |
102 | grid->addWidget( ToolButton13_2, 1, 2 ); | 102 | grid->addWidget( ToolButton13_2, 1, 2 ); |
103 | 103 | ||
104 | subjectInput = new QLineEdit( widget, "subjectInput" ); | 104 | subjectInput = new QLineEdit( widget, "subjectInput" ); |
105 | grid->addWidget( subjectInput, 1, 1 ); | 105 | grid->addWidget( subjectInput, 1, 1 ); |
106 | QWhatsThis::add(subjectInput,QWidget::tr("The mail subject should be entered here")); | 106 | QWhatsThis::add(subjectInput,QWidget::tr("The mail subject should be entered here")); |
107 | 107 | ||
108 | toInput = new QLineEdit( widget, "toInput" ); | 108 | toInput = new QLineEdit( widget, "toInput" ); |
109 | grid->addWidget( toInput, 0, 1 ); | 109 | grid->addWidget( toInput, 0, 1 ); |
110 | QWhatsThis::add(recipientsBox,QWidget::tr("Recipients can be entered here")); | 110 | QWhatsThis::add(recipientsBox,QWidget::tr("Recipients can be entered here")); |
111 | 111 | ||
112 | ccInput = new QLineEdit( widget, "ccInput" ); | 112 | ccInput = new QLineEdit( widget, "ccInput" ); |
113 | ccInput->hide(); | 113 | ccInput->hide(); |
114 | grid->addWidget( ccInput, 0, 1 ); | 114 | 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")); | 115 | QWhatsThis::add(ccInput,QWidget::tr("If you would like to send copies of your mail they can be entered here")); |
116 | 116 | ||
117 | addressButton = new QToolButton( widget, "addressButton" ); | 117 | addressButton = new QToolButton( widget, "addressButton" ); |
118 | addressButton->setPixmap( Resource::loadPixmap("AddressBook") ); | 118 | addressButton->setPixmap( Resource::loadPixmap("AddressBook") ); |
119 | addressButton->setToggleButton(TRUE); | 119 | addressButton->setToggleButton(TRUE); |
120 | grid->addWidget( addressButton, 0, 2 ); | 120 | grid->addWidget( addressButton, 0, 2 ); |
121 | connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) ); | 121 | 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")); | 122 | QWhatsThis::add(addressButton,QWidget::tr("This button opens the address selector with all mail adresses from your OPIE addressbook")); |
123 | 123 | ||
124 | emailInput = new QMultiLineEdit( widget, "emailInput" ); | 124 | emailInput = new QMultiLineEdit( widget, "emailInput" ); |
125 | grid->addMultiCellWidget( emailInput, 2, 2, 0, 2); | 125 | grid->addMultiCellWidget( emailInput, 2, 2, 0, 2); |
126 | QWhatsThis::add(recipientsBox,QWidget::tr("Enter your mail text here")); | 126 | QWhatsThis::add(emailInput,QWidget::tr("Enter your mail text here")); |
127 | 127 | ||
128 | addressView = new QListView( widget, "addressView"); | 128 | addressView = new QListView( widget, "addressView"); |
129 | addressView->addColumn("Name"); | 129 | addressView->addColumn("Name"); |
130 | addressView->addColumn("EMail"); | 130 | addressView->addColumn("EMail"); |
131 | addressView->setAllColumnsShowFocus(TRUE); | 131 | addressView->setAllColumnsShowFocus(TRUE); |
132 | addressView->setMultiSelection(TRUE); | 132 | addressView->setMultiSelection(TRUE); |
133 | addressView->hide(); | 133 | addressView->hide(); |
134 | grid->addMultiCellWidget( addressView, 3, 3, 0, 2); | 134 | grid->addMultiCellWidget( addressView, 3, 3, 0, 2); |
135 | QWhatsThis::add(recipientsBox,QWidget::tr("Chose the recipients from this list")); | 135 | QWhatsThis::add(recipientsBox,QWidget::tr("Choose the recipients from this list")); |
136 | 136 | ||
137 | okButton = new QToolButton(bar, "ok"); | 137 | okButton = new QToolButton(bar, "ok"); |
138 | okButton->setPixmap( Resource::loadPixmap("enter") ); | 138 | okButton->setPixmap( Resource::loadPixmap("enter") ); |
139 | okButton->hide(); | 139 | okButton->hide(); |
140 | connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) ); | 140 | connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) ); |
141 | QWhatsThis::add(okButton,QWidget::tr("Queue your mail by clicking here")); | 141 | QWhatsThis::add(okButton,QWidget::tr("Queue your mail by clicking here")); |
142 | 142 | ||
143 | setCentralWidget(widget); | 143 | setCentralWidget(widget); |
144 | } | 144 | } |
145 | 145 | ||
146 | void WriteMail::reject() | 146 | void WriteMail::reject() |
147 | { | 147 | { |
148 | emit cancelMail(); | 148 | emit cancelMail(); |
149 | } | 149 | } |
150 | 150 | ||
151 | // need to insert date | ||
152 | void WriteMail::accept() | 151 | void WriteMail::accept() |
153 | { | 152 | { |
154 | QStringList attachedFiles, attachmentsType; | 153 | QStringList attachedFiles, attachmentsType; |
155 | int idCount = 0; | 154 | int idCount = 0; |
156 | 155 | ||
157 | if (toInput->text() == "") | 156 | if (toInput->text() == "") |
158 | { | 157 | { |
159 | QMessageBox::warning(this,tr("No recipient"), tr("Send mail to whom?"), tr("OK\n")); | 158 | QMessageBox::warning(this,tr("No recipient"), tr("Send mail to whom?"), tr("OK\n")); |
160 | return; | 159 | return; |
161 | } | 160 | } |
162 | 161 | ||
163 | if (! getRecipients(false) ) | 162 | if (! getRecipients(false) ) |
164 | { | 163 | { |
165 | QMessageBox::warning(this,tr("Incorrect recipient separator"), | 164 | QMessageBox::warning(this,tr("Incorrect recipient separator"), |
166 | tr("Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n")); | 165 | tr("Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n")); |
167 | return; | 166 | return; |
168 | } | 167 | } |
169 | 168 | ||
170 | if ((ccInput->text()!="") && (! getRecipients(true) )) | 169 | if ((ccInput->text()!="") && (! getRecipients(true) )) |
171 | { | 170 | { |
172 | QMessageBox::warning(this,tr("Incorrect carbon copy separator"), | 171 | QMessageBox::warning(this,tr("Incorrect carbon copy separator"), |
173 | tr("CC Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n")); | 172 | tr("CC Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n")); |
174 | return; | 173 | return; |
175 | } | 174 | } |
176 | 175 | ||
177 | mail.subject = subjectInput->text(); | 176 | mail.subject = subjectInput->text(); |
178 | mail.body = emailInput->text(); | 177 | mail.body = emailInput->text(); |
179 | mail.sent = false; | 178 | mail.sent = false; |
180 | mail.received = false; | 179 | mail.received = false; |
181 | 180 | ||
182 | mail.rawMail = "To: "; | 181 | mail.rawMail = "To: "; |
183 | 182 | ||
184 | for (QStringList::Iterator it = mail.recipients.begin(); | 183 | for (QStringList::Iterator it = mail.recipients.begin(); |
185 | it != mail.recipients.end(); ++it) { | 184 | it != mail.recipients.end(); ++it) { |
186 | 185 | ||
187 | mail.rawMail += (*it); | 186 | mail.rawMail += (*it); |
188 | mail.rawMail += ",\n"; | 187 | mail.rawMail += ",\n"; |
189 | } | 188 | } |
190 | 189 | ||
191 | mail.rawMail.truncate(mail.rawMail.length()-2); | 190 | mail.rawMail.truncate(mail.rawMail.length()-2); |
192 | 191 | ||
193 | mail.rawMail += "\nCC: "; | 192 | mail.rawMail += "\nCC: "; |
194 | 193 | ||
195 | for (QStringList::Iterator it = mail.carbonCopies.begin(); | 194 | for (QStringList::Iterator it = mail.carbonCopies.begin(); |
196 | it != mail.carbonCopies.end(); ++it) { | 195 | it != mail.carbonCopies.end(); ++it) { |
197 | 196 | ||
198 | mail.rawMail += (*it); | 197 | mail.rawMail += (*it); |
199 | mail.rawMail += ",\n"; | 198 | mail.rawMail += ",\n"; |
200 | } | 199 | } |
201 | 200 | ||
202 | mail.rawMail += mail.from; | 201 | mail.rawMail += mail.from; |
203 | mail.rawMail += "\nSubject: "; | 202 | mail.rawMail += "\nSubject: "; |
204 | mail.rawMail += mail.subject; | 203 | mail.rawMail += mail.subject; |
205 | mail.rawMail += "\n\n"; | 204 | mail.rawMail += "\n\n"; |
206 | 205 | ||
207 | attachedFiles = addAtt->returnattachedFiles(); | 206 | attachedFiles = addAtt->returnattachedFiles(); |
208 | attachmentsType = addAtt->returnFileTypes(); | 207 | attachmentsType = addAtt->returnFileTypes(); |
209 | 208 | ||
210 | QStringList::Iterator itType = attachmentsType.begin(); | 209 | QStringList::Iterator itType = attachmentsType.begin(); |
211 | 210 | ||
212 | Enclosure e; | 211 | Enclosure e; |
213 | for ( QStringList::Iterator it = attachedFiles.begin(); it != attachedFiles.end(); ++it ) { | 212 | for ( QStringList::Iterator it = attachedFiles.begin(); it != attachedFiles.end(); ++it ) { |
214 | e.id = idCount; | 213 | e.id = idCount; |
215 | e.originalName = (*it).latin1(); | 214 | e.originalName = (*it).latin1(); |
216 | e.contentType = (*itType).latin1(); | 215 | e.contentType = (*itType).latin1(); |
217 | e.contentAttribute = (*itType).latin1(); | 216 | e.contentAttribute = (*itType).latin1(); |
218 | e.saved = TRUE; | 217 | e.saved = TRUE; |
219 | mail.addEnclosure(&e); | 218 | mail.addEnclosure(&e); |
220 | 219 | ||
221 | itType++; | 220 | itType++; |
222 | idCount++; | 221 | idCount++; |
223 | } | 222 | } |
224 | mail.rawMail += mail.body; | 223 | mail.rawMail += mail.body; |
225 | mail.rawMail += "\n"; | 224 | mail.rawMail += "\n"; |
226 | mail.rawMail += ".\n"; | 225 | mail.rawMail += ".\n"; |
227 | emit sendMailRequested(mail); | 226 | emit sendMailRequested(mail); |
228 | addAtt->clear(); | 227 | addAtt->clear(); |
229 | } | 228 | } |
230 | 229 | ||
231 | void WriteMail::getAddress() | 230 | void WriteMail::getAddress() |
232 | { | 231 | { |
233 | showingAddressList = !showingAddressList; | 232 | showingAddressList = !showingAddressList; |
234 | 233 | ||
235 | if (showingAddressList) { | 234 | if (showingAddressList) { |
236 | emailInput->hide(); | 235 | emailInput->hide(); |
237 | addressView->show(); | 236 | addressView->show(); |
238 | okButton->show(); | 237 | okButton->show(); |
239 | 238 | ||
240 | } else { | 239 | } else { |
241 | addressView->hide(); | 240 | addressView->hide(); |
242 | okButton->hide(); | 241 | okButton->hide(); |
243 | emailInput->show(); | 242 | emailInput->show(); |
244 | } | 243 | } |
245 | } | 244 | } |
246 | 245 | ||
247 | void WriteMail::attachFile() | 246 | void WriteMail::attachFile() |
248 | { | 247 | { |
249 | addAtt->showMaximized(); | 248 | addAtt->showMaximized(); |
250 | } | 249 | } |
251 | 250 | ||
252 | void WriteMail::reply(Email replyMail, bool replyAll) | 251 | void WriteMail::reply(Email replyMail, bool replyAll) |
253 | { | 252 | { |
254 | int pos; | 253 | int pos; |
254 | QString ccRecipients; | ||
255 | 255 | ||
256 | mail = replyMail; | 256 | mail = replyMail; |
257 | mail.files.clear(); | 257 | mail.files.clear(); |
258 | 258 | ||
259 | toInput->setText(mail.fromMail); | 259 | toInput->setText(mail.fromMail); |
260 | //replyAll ? ccInput->setText(mail.c) | ||
261 | 260 | ||
261 | if (replyAll) | ||
262 | { | ||
263 | for (QStringList::Iterator it = mail.carbonCopies.begin();it != mail.carbonCopies.end(); ++it) | ||
264 | { | ||
265 | ccRecipients.append(*it); | ||
266 | ccRecipients.append(";"); | ||
267 | } | ||
268 | ccRecipients.truncate(ccRecipients.length()-1); //no ; at the end | ||
269 | ccInput->setText(ccRecipients); | ||
270 | } | ||
271 | |||
262 | addRecipients(replyAll); | 272 | addRecipients(replyAll); |
263 | 273 | ||
264 | subjectInput->setText(tr("Re: ") + mail.subject); | 274 | subjectInput->setText(tr("Re: ") + mail.subject); |
265 | 275 | ||
266 | pos = 0; | 276 | pos = 0; |
267 | mail.body.insert(pos, ">"); | 277 | mail.body.insert(pos, ">"); |
268 | while (pos != -1) { | 278 | while (pos != -1) { |
269 | pos = mail.body.find('\n', pos); | 279 | pos = mail.body.find('\n', pos); |
270 | if (pos != -1) | 280 | if (pos != -1) |
271 | mail.body.insert(++pos, ">>"); | 281 | mail.body.insert(++pos, ">>"); |
272 | } | 282 | } |
273 | 283 | ||
274 | emailInput->setText(mail.body); | 284 | emailInput->setText(mail.body); |
275 | } | 285 | } |
276 | 286 | ||
277 | void WriteMail::forward(Email forwMail) | 287 | void WriteMail::forward(Email forwMail) |
278 | { | 288 | { |
279 | int pos=0; | 289 | int pos=0; |
280 | 290 | ||
281 | QString fwdBody=tr("======forwarded message from "); | 291 | QString fwdBody=tr("======forwarded message from "); |
282 | fwdBody.append(forwMail.fromMail); | 292 | fwdBody.append(forwMail.fromMail); |
283 | fwdBody.append(tr(" starts======\n\n")); | 293 | fwdBody.append(tr(" starts======\n\n")); |
284 | 294 | ||
285 | mail=forwMail; | 295 | mail=forwMail; |
286 | toInput->setText(""); | 296 | toInput->setText(""); |
287 | ccInput->setText(""); | 297 | ccInput->setText(""); |
288 | subjectInput->setText(tr("FWD: ") + mail.subject); | 298 | subjectInput->setText(tr("FWD: ") + mail.subject); |
289 | 299 | ||
290 | fwdBody+=mail.body; | 300 | fwdBody+=mail.body; |
291 | fwdBody+=QString(tr("======end of forwarded message======\n\n")); | 301 | fwdBody+=QString(tr("======end of forwarded message======\n\n")); |
292 | 302 | ||
293 | emailInput->setText(fwdBody); | 303 | emailInput->setText(fwdBody); |
294 | } | 304 | } |
295 | 305 | ||
296 | bool WriteMail::getRecipients(bool ccField) | 306 | bool WriteMail::getRecipients(bool ccField) |
297 | { | 307 | { |
298 | QString str, temp; | 308 | QString str, temp; |
299 | int pos = 0; | 309 | int pos = 0; |
300 | 310 | ||
301 | mail.recipients.clear(); | 311 | mail.recipients.clear(); |
302 | 312 | ||
303 | ccField ? temp = ccInput->text() : temp=toInput->text() ; | 313 | ccField ? temp = ccInput->text() : temp=toInput->text() ; |
304 | 314 | ||
305 | while ( (pos = temp.find(';')) != -1) { | 315 | while ( (pos = temp.find(';')) != -1) { |
306 | str = temp.left(pos).stripWhiteSpace(); | 316 | str = temp.left(pos).stripWhiteSpace(); |
307 | temp = temp.right(temp.length() - (pos + 1)); | 317 | temp = temp.right(temp.length() - (pos + 1)); |
308 | if ( str.find('@') == -1) | 318 | if ( str.find('@') == -1) |
309 | return false; | 319 | return false; |
310 | ccField ? mail.carbonCopies.append(str) : mail.recipients.append(str); | 320 | ccField ? mail.carbonCopies.append(str) : mail.recipients.append(str); |
311 | addressList->addContact(str, ""); | 321 | addressList->addContact(str, ""); |
312 | } | 322 | } |
313 | temp = temp.stripWhiteSpace(); | 323 | temp = temp.stripWhiteSpace(); |
314 | if ( temp.find('@') == -1) | 324 | if ( temp.find('@') == -1) |
315 | return false; | 325 | return false; |
316 | ccField ? mail.carbonCopies.append(temp) : mail.recipients.append(temp); | 326 | ccField ? mail.carbonCopies.append(temp) : mail.recipients.append(temp); |
317 | addressList->addContact(temp, ""); | 327 | addressList->addContact(temp, ""); |
318 | 328 | ||
319 | return TRUE; | 329 | return TRUE; |
320 | } | 330 | } |
321 | 331 | ||
322 | void WriteMail::addRecipients() | 332 | void WriteMail::addRecipients() |
323 | { | 333 | { |
324 | 334 | toInput->isVisible() ? addRecipients(false) : addRecipients(true); | |
325 | addRecipients(false); | ||
326 | } | 335 | } |
327 | 336 | ||
328 | void WriteMail::addRecipients(bool ccField) | 337 | void WriteMail::addRecipients(bool ccField) |
329 | { | 338 | { |
330 | QString recipients = ""; | 339 | QString recipients = ""; |
331 | 340 | ||
332 | mail.recipients.clear(); | 341 | mail.recipients.clear(); |
333 | 342 | ||
334 | QListViewItem *item = addressView->firstChild(); | 343 | QListViewItem *item = addressView->firstChild(); |
335 | while (item != NULL) { | 344 | while (item != NULL) { |
336 | if ( item->isSelected() ) { | 345 | if ( item->isSelected() ) { |
337 | if (recipients == "") { | 346 | if (recipients == "") { |
338 | recipients = item->text(0); | 347 | recipients = item->text(1); |
339 | } else { | 348 | } else { |
340 | recipients += "; " + item->text(0); | 349 | recipients += "; " + item->text(1); |
341 | } | 350 | } |
342 | } | 351 | } |
343 | item = item->nextSibling(); | 352 | item = item->nextSibling(); |
344 | } | 353 | } |
345 | 354 | ||
346 | ccField ? ccInput->setText(recipients):toInput->setText(recipients); | 355 | ccField ? ccInput->setText(recipients):toInput->setText(recipients); |
347 | 356 | ||
348 | addressView->hide(); | 357 | addressView->hide(); |
349 | okButton->hide(); | 358 | okButton->hide(); |
350 | emailInput->show(); | 359 | emailInput->show(); |
351 | addressButton->setOn(FALSE); | 360 | addressButton->setOn(FALSE); |
352 | showingAddressList = !showingAddressList; | 361 | showingAddressList = !showingAddressList; |
353 | } | 362 | } |
354 | 363 | ||
355 | void WriteMail::changeRecipients(int selection) | 364 | void WriteMail::changeRecipients(int selection) |
356 | { | 365 | { |
357 | if (selection==0) | 366 | if (selection==0) |
358 | { | 367 | { |
359 | toInput->show(); | 368 | toInput->show(); |
360 | ccInput->hide(); | 369 | ccInput->hide(); |
361 | } | 370 | } |
362 | else if (selection==1) | 371 | else if (selection==1) |
363 | { | 372 | { |
364 | toInput->hide(); | 373 | toInput->hide(); |
365 | ccInput->show(); | 374 | ccInput->show(); |
366 | } | 375 | } |
367 | } | 376 | } |
368 | 377 | ||
369 | void WriteMail::setRecipient(const QString &recipient) | 378 | void WriteMail::setRecipient(const QString &recipient) |
370 | { | 379 | { |
371 | toInput->setText(recipient); | 380 | toInput->setText(recipient); |
372 | } | 381 | } |
373 | 382 | ||
374 | void WriteMail::newMail() | 383 | void WriteMail::newMail() |
375 | { | 384 | { |
376 | toInput->clear(); | 385 | toInput->clear(); |
377 | subjectInput->clear(); | 386 | subjectInput->clear(); |
378 | emailInput->clear(); | 387 | emailInput->clear(); |
379 | //to clear selected | ||
380 | setAddressList(addressList); | 388 | setAddressList(addressList); |
381 | } | 389 | } |
diff --git a/noncore/unsupported/mailit/emailclient.cpp b/noncore/unsupported/mailit/emailclient.cpp index 23059cf..dff1888 100644 --- a/noncore/unsupported/mailit/emailclient.cpp +++ b/noncore/unsupported/mailit/emailclient.cpp | |||
@@ -1,981 +1,968 @@ | |||
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 <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 <qwhatsthis.h> |
27 | #include <qpe/resource.h> | 27 | #include <qpe/resource.h> |
28 | #include "emailclient.h" | 28 | #include "emailclient.h" |
29 | 29 | ||
30 | QCollection::Item AccountList::newItem(QCollection::Item d) | 30 | QCollection::Item AccountList::newItem(QCollection::Item d) |
31 | { | 31 | { |
32 | return dupl( (MailAccount *) d); | 32 | return dupl( (MailAccount *) d); |
33 | } | 33 | } |
34 | 34 | ||
35 | MailAccount* AccountList::dupl(MailAccount *in) | 35 | MailAccount* AccountList::dupl(MailAccount *in) |
36 | { | 36 | { |
37 | ac = new MailAccount(*in); | 37 | ac = new MailAccount(*in); |
38 | return ac; | 38 | return ac; |
39 | } | 39 | } |
40 | 40 | ||
41 | EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl ) | 41 | EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl ) |
42 | : QMainWindow( parent, name, fl ) | 42 | : QMainWindow( parent, name, fl ) |
43 | { | 43 | { |
44 | emailHandler = new EmailHandler(); | 44 | emailHandler = new EmailHandler(); |
45 | addressList = new AddressList(); | 45 | addressList = new AddressList(); |
46 | 46 | ||
47 | sending = FALSE; | 47 | sending = FALSE; |
48 | receiving = FALSE; | 48 | receiving = FALSE; |
49 | previewingMail = FALSE; | 49 | previewingMail = FALSE; |
50 | mailIdCount = 1; | 50 | mailIdCount = 1; |
51 | accountIdCount = 1; | 51 | accountIdCount = 1; |
52 | allAccounts = FALSE; | 52 | allAccounts = FALSE; |
53 | 53 | ||
54 | init(); | 54 | init(); |
55 | 55 | ||
56 | connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) ); | 56 | connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) ); |
57 | 57 | ||
58 | connect(emailHandler, SIGNAL(smtpError(int)), this, | 58 | connect(emailHandler, SIGNAL(smtpError(int)), this, |
59 | SLOT(smtpError(int)) ); | 59 | SLOT(smtpError(int)) ); |
60 | connect(emailHandler, SIGNAL(popError(int)), this, | 60 | connect(emailHandler, SIGNAL(popError(int)), this, |
61 | SLOT(popError(int)) ); | 61 | SLOT(popError(int)) ); |
62 | 62 | ||
63 | connect(inboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(inboxItemSelected()) ); | 63 | connect(inboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(inboxItemSelected()) ); |
64 | connect(outboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(outboxItemSelected()) ); | 64 | connect(outboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(outboxItemSelected()) ); |
65 | 65 | ||
66 | connect(inboxView, SIGNAL(pressed(QListViewItem *)), this, SLOT(inboxItemPressed()) ); | 66 | connect(inboxView, SIGNAL(pressed(QListViewItem *)), this, SLOT(inboxItemPressed()) ); |
67 | connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemReleased()) ); | 67 | connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemReleased()) ); |
68 | 68 | ||
69 | 69 | ||
70 | connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this, | 70 | connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this, |
71 | SLOT(mailArrived(const Email &, bool)) ); | 71 | SLOT(mailArrived(const Email &, bool)) ); |
72 | connect(emailHandler, SIGNAL(mailTransfered(int)), this, | 72 | connect(emailHandler, SIGNAL(mailTransfered(int)), this, |
73 | SLOT(allMailArrived(int)) ); | 73 | SLOT(allMailArrived(int)) ); |
74 | 74 | ||
75 | mailconf = new Config("mailit"); | 75 | mailconf = new Config("mailit"); |
76 | //In case Synchronize is not defined in settings.txt | 76 | //In case Synchronize is not defined in settings.txt |
77 | 77 | ||
78 | readSettings(); | 78 | readSettings(); |
79 | 79 | ||
80 | updateAccounts(); | 80 | updateAccounts(); |
81 | 81 | ||
82 | lineShift = "\n"; | 82 | lineShift = "\n"; |
83 | readMail(); | 83 | readMail(); |
84 | lineShift = "\r\n"; | 84 | lineShift = "\r\n"; |
85 | 85 | ||
86 | mailboxView->setCurrentTab(0); //ensure that inbox has focus | 86 | mailboxView->setCurrentTab(0); //ensure that inbox has focus |
87 | } | 87 | } |
88 | 88 | ||
89 | 89 | ||
90 | EmailClient::~EmailClient() | 90 | EmailClient::~EmailClient() |
91 | { | 91 | { |
92 | //needs to be moved from destructor to closewindow event | 92 | //needs to be moved from destructor to closewindow event |
93 | saveMail(getPath(FALSE) + "inbox.txt", inboxView); | 93 | saveMail(getPath(FALSE) + "inbox.txt", inboxView); |
94 | //does not currently work. Defining outbox in the same | 94 | //does not currently work. Defining outbox in the same |
95 | //format as inbox is not a good solution as they have | 95 | //format as inbox is not a good solution as they have |
96 | //different properties | 96 | //different properties |
97 | saveMail(getPath(FALSE) + "outbox.txt", outboxView); | 97 | saveMail(getPath(FALSE) + "outbox.txt", outboxView); |
98 | saveSettings(); | 98 | saveSettings(); |
99 | 99 | ||
100 | mailconf->write(); | 100 | mailconf->write(); |
101 | delete mailconf; | 101 | delete mailconf; |
102 | 102 | ||
103 | } | 103 | } |
104 | 104 | ||
105 | void EmailClient::init() | 105 | void EmailClient::init() |
106 | { | 106 | { |
107 | statusBar = new QStatusBar(this); | 107 | statusBar = new QStatusBar(this); |
108 | statusBar->setSizeGripEnabled(FALSE); | 108 | statusBar->setSizeGripEnabled(FALSE); |
109 | 109 | ||
110 | status1Label = new QLabel( tr("Idle"), statusBar); | 110 | status1Label = new QLabel( tr("Idle"), statusBar); |
111 | status2Label = new QLabel("", statusBar); | 111 | status2Label = new QLabel("", statusBar); |
112 | connect(emailHandler, SIGNAL(updatePopStatus(const QString &)), | 112 | connect(emailHandler, SIGNAL(updatePopStatus(const QString &)), |
113 | status2Label, SLOT(setText(const QString &)) ); | 113 | status2Label, SLOT(setText(const QString &)) ); |
114 | connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)), | 114 | connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)), |
115 | status2Label, SLOT(setText(const QString &)) ); | 115 | status2Label, SLOT(setText(const QString &)) ); |
116 | 116 | ||
117 | progressBar = new QProgressBar(statusBar); | 117 | progressBar = new QProgressBar(statusBar); |
118 | 118 | ||
119 | connect(emailHandler, SIGNAL(mailboxSize(int)), | 119 | connect(emailHandler, SIGNAL(mailboxSize(int)), |
120 | this, SLOT(setTotalSize(int)) ); | 120 | this, SLOT(setTotalSize(int)) ); |
121 | connect(emailHandler, SIGNAL(currentMailSize(int)), | 121 | connect(emailHandler, SIGNAL(currentMailSize(int)), |
122 | this, SLOT(setMailSize(int)) ); | 122 | this, SLOT(setMailSize(int)) ); |
123 | connect(emailHandler, SIGNAL(downloadedSize(int)), | 123 | connect(emailHandler, SIGNAL(downloadedSize(int)), |
124 | this, SLOT(setDownloadedSize(int)) ); | 124 | this, SLOT(setDownloadedSize(int)) ); |
125 | 125 | ||
126 | statusBar->addWidget(status1Label); | 126 | statusBar->addWidget(status1Label); |
127 | statusBar->addWidget(progressBar); | 127 | statusBar->addWidget(progressBar); |
128 | statusBar->addWidget(status2Label); | 128 | statusBar->addWidget(status2Label); |
129 | 129 | ||
130 | setToolBarsMovable(FALSE); | 130 | setToolBarsMovable(FALSE); |
131 | 131 | ||
132 | bar = new QToolBar(this); | 132 | bar = new QToolBar(this); |
133 | QWhatsThis::add(bar,tr("Main operation toolbar")); | 133 | QWhatsThis::add(bar,tr("Main operation toolbar")); |
134 | bar->setHorizontalStretchable( TRUE ); | 134 | bar->setHorizontalStretchable( TRUE ); |
135 | 135 | ||
136 | mb = new QMenuBar( bar ); | 136 | mb = new QMenuBar( bar ); |
137 | 137 | ||
138 | QPopupMenu *mail = new QPopupMenu(mb); | 138 | QPopupMenu *mail = new QPopupMenu(mb); |
139 | mb->insertItem( tr( "&Mail" ), mail); | 139 | mb->insertItem( tr( "&Mail" ), mail); |
140 | 140 | ||
141 | QPopupMenu *configure = new QPopupMenu(mb); | 141 | QPopupMenu *configure = new QPopupMenu(mb); |
142 | mb->insertItem( tr( "Accounts" ), configure); | 142 | mb->insertItem( tr( "Accounts" ), configure); |
143 | 143 | ||
144 | selectAccountMenu = new QPopupMenu(mb); | 144 | selectAccountMenu = new QPopupMenu(mb); |
145 | editAccountMenu = new QPopupMenu(mb); | 145 | editAccountMenu = new QPopupMenu(mb); |
146 | deleteAccountMenu = new QPopupMenu(mb); | 146 | deleteAccountMenu = new QPopupMenu(mb); |
147 | 147 | ||
148 | mail->insertItem(tr("Get Mail in"), selectAccountMenu); | 148 | mail->insertItem(tr("Get Mail in"), selectAccountMenu); |
149 | configure->insertItem(tr("Edit account"), editAccountMenu); | 149 | configure->insertItem(tr("Edit account"), editAccountMenu); |
150 | configure->insertItem(tr("Delete account"), deleteAccountMenu); | 150 | configure->insertItem(tr("Delete account"), deleteAccountMenu); |
151 | 151 | ||
152 | bar = new QToolBar(this); | 152 | bar = new QToolBar(this); |
153 | 153 | ||
154 | 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); |
155 | QWhatsThis::add(getMailButton,tr("Click to download mail via all available accounts.\n Press and hold to select the desired account.")); | 155 | QWhatsThis::add(getMailButton,tr("Click to download mail via all available accounts.\n Press and hold to select the desired account.")); |
156 | 156 | ||
157 | getMailButton->setPopup(selectAccountMenu); | 157 | getMailButton->setPopup(selectAccountMenu); |
158 | 158 | ||
159 | 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); |
160 | connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) ); | 160 | connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) ); |
161 | sendMailButton->addTo(bar); | 161 | sendMailButton->addTo(bar); |
162 | sendMailButton->addTo(mail); | 162 | sendMailButton->addTo(mail); |
163 | sendMailButton->setWhatsThis("Send mail queued in the outbox"); | 163 | sendMailButton->setWhatsThis("Send mail queued in the outbox"); |
164 | 164 | ||
165 | 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); |
166 | connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) ); | 166 | connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) ); |
167 | composeButton->addTo(bar); | 167 | composeButton->addTo(bar); |
168 | composeButton->addTo(mail); | 168 | composeButton->addTo(mail); |
169 | composeButton->setWhatsThis("Compose a new mail"); | 169 | composeButton->setWhatsThis("Compose a new mail"); |
170 | 170 | ||
171 | 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); |
172 | connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) ); | 172 | connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) ); |
173 | cancelButton->addTo(mail); | 173 | cancelButton->addTo(mail); |
174 | cancelButton->addTo(bar); | 174 | cancelButton->addTo(bar); |
175 | cancelButton->setEnabled(FALSE); | 175 | cancelButton->setEnabled(FALSE); |
176 | cancelButton->setWhatsThis("Stop the currently active mail transfer"); | 176 | cancelButton->setWhatsThis("Stop the currently active mail transfer"); |
177 | 177 | ||
178 | 178 | ||
179 | 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 ); |
180 | connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); | 180 | connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); |
181 | deleteButton->addTo(bar); | 181 | deleteButton->addTo(bar); |
182 | deleteButton->setWhatsThis("Remove the currently selected eMail(s)"); | 182 | deleteButton->setWhatsThis("Remove the currently selected eMail(s)"); |
183 | 183 | ||
184 | mailboxView = new OTabWidget( this, "mailboxView" ); | 184 | mailboxView = new OTabWidget( this, "mailboxView" ); |
185 | 185 | ||
186 | QWidget* widget = new QWidget( mailboxView, "widget" ); | 186 | QWidget* widget = new QWidget( mailboxView, "widget" ); |
187 | grid_2 = new QGridLayout( widget ); | 187 | grid_2 = new QGridLayout( widget ); |
188 | // grid_2->setSpacing(6); | 188 | // grid_2->setSpacing(6); |
189 | // grid_2->setMargin( 11 ); | 189 | // grid_2->setMargin( 11 ); |
190 | 190 | ||
191 | inboxView = new QListView( widget, "inboxView" ); | 191 | inboxView = new QListView( widget, "inboxView" ); |
192 | inboxView->addColumn( tr( "From" ) ); | 192 | inboxView->addColumn( tr( "From" ) ); |
193 | inboxView->addColumn( tr( "Subject" ) ); | 193 | inboxView->addColumn( tr( "Subject" ) ); |
194 | inboxView->addColumn( tr( "Date" ) ); | 194 | inboxView->addColumn( tr( "Date" ) ); |
195 | inboxView->setMinimumSize( QSize( 0, 0 ) ); | 195 | inboxView->setMinimumSize( QSize( 0, 0 ) ); |
196 | 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" | 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.")); | 198 | " A blue attachment icon shows whether this mail has attachments.")); |
199 | 199 | ||
200 | grid_2->addWidget( inboxView, 2, 0 ); | 200 | grid_2->addWidget( inboxView, 2, 0 ); |
201 | mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) ); | 201 | mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) ); |
202 | 202 | ||
203 | QWidget* widget_2 = new QWidget( mailboxView, "widget_2" ); | 203 | QWidget* widget_2 = new QWidget( mailboxView, "widget_2" ); |
204 | grid_3 = new QGridLayout( widget_2 ); | 204 | grid_3 = new QGridLayout( widget_2 ); |
205 | // grid_3->setSpacing(6); | 205 | // grid_3->setSpacing(6); |
206 | // grid_3->setMargin( 11 ); | 206 | // grid_3->setMargin( 11 ); |
207 | 207 | ||
208 | outboxView = new QListView( widget_2, "outboxView" ); | 208 | outboxView = new QListView( widget_2, "outboxView" ); |
209 | outboxView->addColumn( tr( "To" ) ); | 209 | outboxView->addColumn( tr( "To" ) ); |
210 | outboxView->addColumn( tr( "Subject" ) ); | 210 | outboxView->addColumn( tr( "Subject" ) ); |
211 | outboxView->setAllColumnsShowFocus(TRUE); | 211 | outboxView->setAllColumnsShowFocus(TRUE); |
212 | 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.")); | 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.")); |
214 | grid_3->addWidget( outboxView, 0, 0 ); | 214 | grid_3->addWidget( outboxView, 0, 0 ); |
215 | mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) ); | 215 | mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) ); |
216 | 216 | ||
217 | setCentralWidget(mailboxView); | 217 | setCentralWidget(mailboxView); |
218 | 218 | ||
219 | } | 219 | } |
220 | 220 | ||
221 | void EmailClient::compose() | 221 | void EmailClient::compose() |
222 | { | 222 | { |
223 | emit composeRequested(); | 223 | emit composeRequested(); |
224 | } | 224 | } |
225 | 225 | ||
226 | void EmailClient::cancel() | 226 | void EmailClient::cancel() |
227 | { | 227 | { |
228 | emailHandler->cancel(); | 228 | emailHandler->cancel(); |
229 | } | 229 | } |
230 | 230 | ||
231 | AddressList* EmailClient::getAdrListRef() | 231 | AddressList* EmailClient::getAdrListRef() |
232 | { | 232 | { |
233 | return addressList; | 233 | return addressList; |
234 | } | 234 | } |
235 | 235 | ||
236 | //this needs to be rewritten to syncronize with outboxView | 236 | //this needs to be rewritten to syncronize with outboxView |
237 | void EmailClient::enqueMail(const Email &mail) | 237 | void EmailClient::enqueMail(const Email &mail) |
238 | { | 238 | { |
239 | if (accountList.count() == 0) { | 239 | if (accountList.count() == 0) { |
240 | QMessageBox::warning(qApp->activeWindow(), | 240 | QMessageBox::warning(qApp->activeWindow(), |
241 | 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"); |
242 | return; | 242 | return; |
243 | } | 243 | } |
244 | 244 | ||
245 | if (accountList.count() > 0) { | 245 | if (accountList.count() > 0) { |
246 | currentAccount = accountList.first(); | 246 | currentAccount = accountList.first(); |
247 | qWarning("using account " + currentAccount->name); | 247 | qWarning("using account " + currentAccount->name); |
248 | } | 248 | } |
249 | 249 | ||
250 | Email addMail = mail; | 250 | Email addMail = mail; |
251 | addMail.from = currentAccount->name; | 251 | addMail.from = currentAccount->name; |
252 | addMail.fromMail = currentAccount->emailAddress; | 252 | addMail.fromMail = currentAccount->emailAddress; |
253 | addMail.rawMail.prepend("From: " + addMail.from + "<" + addMail.fromMail + ">\n"); | 253 | addMail.rawMail.prepend("From: " + addMail.from + "<" + addMail.fromMail + ">\n"); |
254 | item = new EmailListItem(outboxView, addMail, false); | 254 | item = new EmailListItem(outboxView, addMail, false); |
255 | 255 | ||
256 | mailboxView->setCurrentTab(1); | 256 | mailboxView->setCurrentTab(1); |
257 | 257 | ||
258 | } | 258 | } |
259 | 259 | ||
260 | void EmailClient::sendQuedMail() | 260 | void EmailClient::sendQuedMail() |
261 | { | 261 | { |
262 | int count = 0; | 262 | int count = 0; |
263 | 263 | ||
264 | if (accountList.count() == 0) { | 264 | if (accountList.count() == 0) { |
265 | QMessageBox::warning(qApp->activeWindow(), "No account selected", "You must create an account", "OK\n"); | 265 | QMessageBox::warning(qApp->activeWindow(), "No account selected", "You must create an account", "OK\n"); |
266 | return; | 266 | return; |
267 | } | 267 | } |
268 | //traverse listview, find messages to send | 268 | //traverse listview, find messages to send |
269 | if (! sending) { | 269 | if (! sending) { |
270 | item = (EmailListItem *) outboxView->firstChild(); | 270 | item = (EmailListItem *) outboxView->firstChild(); |
271 | if (item != NULL) { | 271 | if (item != NULL) { |
272 | while (item != NULL) { | 272 | while (item != NULL) { |
273 | quedMessages.append(item->getMail()); | 273 | quedMessages.append(item->getMail()); |
274 | item = (EmailListItem *) item->nextSibling(); | 274 | item = (EmailListItem *) item->nextSibling(); |
275 | count++; | 275 | count++; |
276 | } | 276 | } |
277 | setMailAccount(); | 277 | setMailAccount(); |
278 | emailHandler->sendMail(&quedMessages); | 278 | emailHandler->sendMail(&quedMessages); |
279 | sending = TRUE; | 279 | sending = TRUE; |
280 | sendMailButton->setEnabled(FALSE); | 280 | sendMailButton->setEnabled(FALSE); |
281 | cancelButton->setEnabled(TRUE); | 281 | cancelButton->setEnabled(TRUE); |
282 | } else { | 282 | } else { |
283 | qWarning("sendQuedMail(): no messages to send"); | 283 | qWarning("sendQuedMail(): no messages to send"); |
284 | } | 284 | } |
285 | } | 285 | } |
286 | } | 286 | } |
287 | 287 | ||
288 | void EmailClient::setMailAccount() | 288 | void EmailClient::setMailAccount() |
289 | { | 289 | { |
290 | emailHandler->setAccount(*currentAccount); | 290 | emailHandler->setAccount(*currentAccount); |
291 | } | 291 | } |
292 | 292 | ||
293 | void EmailClient::mailSent() | 293 | void EmailClient::mailSent() |
294 | { | 294 | { |
295 | sending = FALSE; | 295 | sending = FALSE; |
296 | sendMailButton->setEnabled(TRUE); | 296 | sendMailButton->setEnabled(TRUE); |
297 | 297 | ||
298 | quedMessages.clear(); | 298 | quedMessages.clear(); |
299 | outboxView->clear(); //should be moved to an sentBox | 299 | outboxView->clear(); //should be moved to an sentBox |
300 | } | 300 | } |
301 | 301 | ||
302 | void EmailClient::getNewMail() { | 302 | void EmailClient::getNewMail() { |
303 | 303 | ||
304 | if (accountList.count() == 0) { | 304 | if (accountList.count() == 0) { |
305 | QMessageBox::warning(qApp->activeWindow(),"No account selected", | 305 | QMessageBox::warning(qApp->activeWindow(),"No account selected", |
306 | "You must create an account", "OK\n"); | 306 | "You must create an account", "OK\n"); |
307 | return; | 307 | return; |
308 | } | 308 | } |
309 | 309 | ||
310 | setMailAccount(); | 310 | setMailAccount(); |
311 | 311 | ||
312 | receiving = TRUE; | 312 | receiving = TRUE; |
313 | previewingMail = TRUE; | 313 | previewingMail = TRUE; |
314 | getMailButton->setEnabled(FALSE); | 314 | getMailButton->setEnabled(FALSE); |
315 | cancelButton->setEnabled(TRUE); | 315 | cancelButton->setEnabled(TRUE); |
316 | selectAccountMenu->setEnabled(FALSE); | 316 | selectAccountMenu->setEnabled(FALSE); |
317 | 317 | ||
318 | status1Label->setText(currentAccount->accountName + " headers"); | 318 | status1Label->setText(currentAccount->accountName + " headers"); |
319 | progressBar->reset(); | 319 | progressBar->reset(); |
320 | 320 | ||
321 | //get any previous mails not downloaded and add to queue | 321 | //get any previous mails not downloaded and add to queue |
322 | mailDownloadList.clear(); | 322 | mailDownloadList.clear(); |
323 | Email *mailPtr; | 323 | Email *mailPtr; |
324 | item = (EmailListItem *) inboxView->firstChild(); | 324 | item = (EmailListItem *) inboxView->firstChild(); |
325 | while (item != NULL) { | 325 | while (item != NULL) { |
326 | mailPtr = item->getMail(); | 326 | mailPtr = item->getMail(); |
327 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { | 327 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { |
328 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); | 328 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); |
329 | } | 329 | } |
330 | item = (EmailListItem *) item->nextSibling(); | 330 | item = (EmailListItem *) item->nextSibling(); |
331 | } | 331 | } |
332 | 332 | ||
333 | emailHandler->getMailHeaders(); | 333 | emailHandler->getMailHeaders(); |
334 | 334 | ||
335 | } | 335 | } |
336 | 336 | ||
337 | void EmailClient::getAllNewMail() | 337 | void EmailClient::getAllNewMail() |
338 | { | 338 | { |
339 | allAccounts = TRUE; | 339 | allAccounts = TRUE; |
340 | currentAccount = accountList.first(); | 340 | currentAccount = accountList.first(); |
341 | getNewMail(); | 341 | getNewMail(); |
342 | } | 342 | } |
343 | 343 | ||
344 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) | 344 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) |
345 | { | 345 | { |
346 | Enclosure *ePtr; | 346 | Enclosure *ePtr; |
347 | Email newMail; | 347 | Email newMail; |
348 | int thisMailId; | 348 | int thisMailId; |
349 | emailHandler->parse(mail.rawMail, lineShift, &newMail); | 349 | emailHandler->parse(mail.rawMail, lineShift, &newMail); |
350 | mailconf->setGroup(newMail.id); | 350 | mailconf->setGroup(newMail.id); |
351 | 351 | ||
352 | if (fromDisk) | 352 | if (fromDisk) |
353 | { | 353 | { |
354 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); | 354 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); |
355 | newMail.size = mailconf->readNumEntry("size"); | 355 | newMail.size = mailconf->readNumEntry("size"); |
356 | newMail.serverId = mailconf->readNumEntry("serverid"); | 356 | newMail.serverId = mailconf->readNumEntry("serverid"); |
357 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); | 357 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); |
358 | } | 358 | } |
359 | else | 359 | else |
360 | { //mail arrived from server | 360 | { //mail arrived from server |
361 | newMail.serverId = mail.serverId; | 361 | newMail.serverId = mail.serverId; |
362 | newMail.size = mail.size; | 362 | newMail.size = mail.size; |
363 | newMail.downloaded = mail.downloaded; | 363 | newMail.downloaded = mail.downloaded; |
364 | 364 | ||
365 | newMail.fromAccountId = currentAccount->id; | 365 | newMail.fromAccountId = emailHandler->getAccount()->id; |
366 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); | 366 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); |
367 | } | 367 | } |
368 | 368 | ||
369 | //add if read or not | 369 | //add if read or not |
370 | newMail.read = mailconf->readBoolEntry("mailread"); | 370 | newMail.read = mailconf->readBoolEntry("mailread"); |
371 | 371 | ||
372 | //check if new mail | 372 | //check if new mail |
373 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { | 373 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { |
374 | thisMailId = mailIdCount; | 374 | thisMailId = mailIdCount; |
375 | mailIdCount++; | 375 | mailIdCount++; |
376 | 376 | ||
377 | //set server count, so that if the user aborts, the new | 377 | //set server count, so that if the user aborts, the new |
378 | //header is not reloaded | 378 | //header is not reloaded |
379 | if ((currentAccount)&&(currentAccount->synchronize)) | 379 | if ((currentAccount)&&(currentAccount->synchronize)) |
380 | currentAccount->lastServerMailCount++; | 380 | currentAccount->lastServerMailCount++; |
381 | 381 | ||
382 | mailconf->writeEntry("internalmailid", thisMailId); | 382 | mailconf->writeEntry("internalmailid", thisMailId); |
383 | mailconf->writeEntry("downloaded", newMail.downloaded); | 383 | mailconf->writeEntry("downloaded", newMail.downloaded); |
384 | mailconf->writeEntry("size", (int) newMail.size); | 384 | mailconf->writeEntry("size", (int) newMail.size); |
385 | mailconf->writeEntry("serverid", newMail.serverId); | 385 | mailconf->writeEntry("serverid", newMail.serverId); |
386 | 386 | ||
387 | //addressList->addContact(newMail.fromMail, newMail.from); | 387 | //addressList->addContact(newMail.fromMail, newMail.from); |
388 | } | 388 | } |
389 | 389 | ||
390 | mailconf->writeEntry("downloaded", newMail.downloaded); | 390 | mailconf->writeEntry("downloaded", newMail.downloaded); |
391 | 391 | ||
392 | QString stringMailId; | 392 | QString stringMailId; |
393 | stringMailId.setNum(thisMailId); | 393 | stringMailId.setNum(thisMailId); |
394 | //see if any attatchments needs to be stored | 394 | //see if any attatchments needs to be stored |
395 | 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 | 429 | ||
430 | bool found=false; | 430 | bool found=false; |
431 | 431 | ||
432 | if (!fromDisk) | 432 | if (!fromDisk) |
433 | { | 433 | { |
434 | 434 | ||
435 | Email *mailPtr; | 435 | Email *mailPtr; |
436 | item = (EmailListItem *) inboxView->firstChild(); | 436 | item = (EmailListItem *) inboxView->firstChild(); |
437 | while ((item != NULL)&&(!found)) | 437 | while ((item != NULL)&&(!found)) |
438 | { | 438 | { |
439 | mailPtr = item->getMail(); | 439 | mailPtr = item->getMail(); |
440 | if (mailPtr->id == newMail.id) { | 440 | if (mailPtr->id == newMail.id) { |
441 | item->setMail(newMail); | 441 | item->setMail(newMail); |
442 | emit mailUpdated(item->getMail()); | 442 | emit mailUpdated(item->getMail()); |
443 | found = true; | 443 | found = true; |
444 | } | 444 | } |
445 | item = (EmailListItem *) item->nextSibling(); | 445 | item = (EmailListItem *) item->nextSibling(); |
446 | } | 446 | } |
447 | } | 447 | } |
448 | if ((!found)||(fromDisk)) item = new EmailListItem(inboxView, newMail, TRUE); | 448 | if ((!found)||(fromDisk)) item = new EmailListItem(inboxView, newMail, TRUE); |
449 | 449 | ||
450 | /*if (!newMail.downloaded) | 450 | /*if (!newMail.downloaded) |
451 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ | 451 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ |
452 | 452 | ||
453 | mailboxView->setCurrentTab(0); | 453 | mailboxView->setCurrentTab(0); |
454 | 454 | ||
455 | } | 455 | } |
456 | 456 | ||
457 | void EmailClient::allMailArrived(int count) | 457 | void EmailClient::allMailArrived(int count) |
458 | { | 458 | { |
459 | // not previewing means all mailtransfer has been done | 459 | // not previewing means all mailtransfer has been done |
460 | /*if (!previewingMail) {*/ | 460 | /*if (!previewingMail) {*/ |
461 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { | 461 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { |
462 | emit newCaption("Mailit - " + currentAccount->accountName); | 462 | emit newCaption("Mailit - " + currentAccount->accountName); |
463 | getNewMail(); | 463 | getNewMail(); |
464 | return; | 464 | return; |
465 | } else { | 465 | } else { |
466 | allAccounts = FALSE; | 466 | allAccounts = FALSE; |
467 | receiving = FALSE; | 467 | receiving = FALSE; |
468 | getMailButton->setEnabled(TRUE); | 468 | getMailButton->setEnabled(TRUE); |
469 | cancelButton->setEnabled(FALSE); | 469 | cancelButton->setEnabled(FALSE); |
470 | selectAccountMenu->setEnabled(TRUE); | 470 | selectAccountMenu->setEnabled(TRUE); |
471 | status1Label->setText("Idle"); | 471 | status1Label->setText("Idle"); |
472 | 472 | ||
473 | progressBar->reset(); | 473 | progressBar->reset(); |
474 | return; | 474 | return; |
475 | } | 475 | } |
476 | //} | 476 | //} |
477 | 477 | ||
478 | // all headers downloaded from server, start downloading remaining mails | 478 | // all headers downloaded from server, start downloading remaining mails |
479 | previewingMail = FALSE; | 479 | previewingMail = FALSE; |
480 | status1Label->setText(currentAccount->accountName); | 480 | status1Label->setText(currentAccount->accountName); |
481 | progressBar->reset(); | 481 | progressBar->reset(); |
482 | 482 | ||
483 | //emailHandler->getMailByList(&mailDownloadList); | 483 | |
484 | |||
485 | mailboxView->setCurrentTab(0); | 484 | mailboxView->setCurrentTab(0); |
486 | } | 485 | } |
487 | 486 | ||
487 | |||
488 | void EmailClient::moveMailFront(Email *mailPtr) | 488 | void EmailClient::moveMailFront(Email *mailPtr) |
489 | { | 489 | { |
490 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { | 490 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { |
491 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); | 491 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); |
492 | } | 492 | } |
493 | } | 493 | } |
494 | 494 | ||
495 | void EmailClient::smtpError(int code) | 495 | void EmailClient::smtpError(int code) |
496 | { | 496 | { |
497 | QString temp; | 497 | QString temp; |
498 | 498 | ||
499 | if (code == ErrUnknownResponse) | 499 | if (code == ErrUnknownResponse) |
500 | temp = "Unknown response from server"; | 500 | temp = "Unknown response from server"; |
501 | 501 | ||
502 | if (code == QSocket::ErrHostNotFound) | 502 | if (code == QSocket::ErrHostNotFound) |
503 | temp = "host not found"; | 503 | temp = "host not found"; |
504 | if (code == QSocket::ErrConnectionRefused) | 504 | if (code == QSocket::ErrConnectionRefused) |
505 | temp = "connection refused"; | 505 | temp = "connection refused"; |
506 | if (code == QSocket::ErrSocketRead) | 506 | if (code == QSocket::ErrSocketRead) |
507 | temp = "socket packet error"; | 507 | temp = "socket packet error"; |
508 | 508 | ||
509 | if (code != ErrCancel) { | 509 | if (code != ErrCancel) { |
510 | QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); | 510 | QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); |
511 | } else { | 511 | } else { |
512 | status2Label->setText("Aborted by user"); | 512 | status2Label->setText("Aborted by user"); |
513 | } | 513 | } |
514 | 514 | ||
515 | sending = FALSE; | 515 | sending = FALSE; |
516 | sendMailButton->setEnabled(TRUE); | 516 | sendMailButton->setEnabled(TRUE); |
517 | cancelButton->setEnabled(FALSE); | 517 | cancelButton->setEnabled(FALSE); |
518 | quedMessages.clear(); | 518 | quedMessages.clear(); |
519 | } | 519 | } |
520 | 520 | ||
521 | void EmailClient::popError(int code) | 521 | void EmailClient::popError(int code) |
522 | { | 522 | { |
523 | QString temp; | 523 | QString temp; |
524 | 524 | ||
525 | if (code == ErrUnknownResponse) | 525 | if (code == ErrUnknownResponse) |
526 | temp = "Unknown response from server"; | 526 | temp = "Unknown response from server"; |
527 | if (code == ErrLoginFailed) | 527 | if (code == ErrLoginFailed) |
528 | temp = "Login failed\nCheck user name and password"; | 528 | temp = "Login failed\nCheck user name and password"; |
529 | 529 | ||
530 | if (code == QSocket::ErrHostNotFound) | 530 | if (code == QSocket::ErrHostNotFound) |
531 | temp = "host not found"; | 531 | temp = "host not found"; |
532 | if (code == QSocket::ErrConnectionRefused) | 532 | if (code == QSocket::ErrConnectionRefused) |
533 | temp = "connection refused"; | 533 | temp = "connection refused"; |
534 | if (code == QSocket::ErrSocketRead) | 534 | if (code == QSocket::ErrSocketRead) |
535 | temp = "socket packet error"; | 535 | temp = "socket packet error"; |
536 | 536 | ||
537 | if (code != ErrCancel) { | 537 | if (code != ErrCancel) { |
538 | QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n"); | 538 | QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n"); |
539 | } else { | 539 | } else { |
540 | status2Label->setText("Aborted by user"); | 540 | status2Label->setText("Aborted by user"); |
541 | } | 541 | } |
542 | 542 | ||
543 | receiving = FALSE; | 543 | receiving = FALSE; |
544 | getMailButton->setEnabled(TRUE); | 544 | getMailButton->setEnabled(TRUE); |
545 | cancelButton->setEnabled(FALSE); | 545 | cancelButton->setEnabled(FALSE); |
546 | selectAccountMenu->setEnabled(TRUE); | 546 | selectAccountMenu->setEnabled(TRUE); |
547 | } | 547 | } |
548 | 548 | ||
549 | void EmailClient::inboxItemSelected() | 549 | void EmailClient::inboxItemSelected() |
550 | { | 550 | { |
551 | //killTimer(timerID); | 551 | //killTimer(timerID); |
552 | 552 | ||
553 | item = (EmailListItem*) inboxView->selectedItem(); | 553 | item = (EmailListItem*) inboxView->selectedItem(); |
554 | if (item != NULL) { | 554 | if (item != NULL) { |
555 | emit viewEmail(inboxView, item->getMail()); | 555 | emit viewEmail(inboxView, item->getMail()); |
556 | } | 556 | } |
557 | } | 557 | } |
558 | 558 | ||
559 | void EmailClient::outboxItemSelected() | 559 | void EmailClient::outboxItemSelected() |
560 | { | 560 | { |
561 | //killTimer(timerID); | 561 | //killTimer(timerID); |
562 | 562 | ||
563 | item = (EmailListItem*) outboxView->selectedItem(); | 563 | item = (EmailListItem*) outboxView->selectedItem(); |
564 | if (item != NULL) { | 564 | if (item != NULL) { |
565 | emit viewEmail(outboxView, item->getMail()); | 565 | emit viewEmail(outboxView, item->getMail()); |
566 | } | 566 | } |
567 | 567 | ||
568 | } | 568 | } |
569 | 569 | ||
570 | void EmailClient::readMail() | 570 | void EmailClient::readMail() |
571 | { | 571 | { |
572 | Email mail; | 572 | Email mail; |
573 | int start, stop; | 573 | int start, stop; |
574 | QString s, del; | 574 | QString s, del; |
575 | 575 | ||
576 | QFile f(getPath(FALSE) + "inbox.txt"); | 576 | QFile f(getPath(FALSE) + "inbox.txt"); |
577 | 577 | ||
578 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 578 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
579 | QTextStream t( &f ); // use a text stream | 579 | QTextStream t( &f ); // use a text stream |
580 | s = t.read(); | 580 | s = t.read(); |
581 | f.close(); | 581 | f.close(); |
582 | 582 | ||
583 | start = 0; | 583 | start = 0; |
584 | del = "\n.\n"; | 584 | del = "\n.\n"; |
585 | while ((uint) start < s.length()) { | 585 | while ((uint) start < s.length()) { |
586 | stop = s.find(del, start); | 586 | stop = s.find(del, start); |
587 | if (stop == -1) | 587 | if (stop == -1) |
588 | stop = s.length() - del.length(); | 588 | stop = s.length() - del.length(); |
589 | 589 | ||
590 | mail.rawMail = s.mid(start, stop + del.length() - start ); | 590 | mail.rawMail = s.mid(start, stop + del.length() - start ); |
591 | start = stop + del.length(); | 591 | start = stop + del.length(); |
592 | mailArrived(mail, TRUE); | 592 | mailArrived(mail, TRUE); |
593 | } | 593 | } |
594 | } | 594 | } |
595 | 595 | ||
596 | QFile fo(getPath(FALSE) + "outbox.txt"); | 596 | QFile fo(getPath(FALSE) + "outbox.txt"); |
597 | if ( fo.open(IO_ReadOnly) ) { // file opened successfully | 597 | if ( fo.open(IO_ReadOnly) ) { // file opened successfully |
598 | QTextStream t( &fo ); // use a text stream | 598 | QTextStream t( &fo ); // use a text stream |
599 | s = t.read(); | 599 | s = t.read(); |
600 | fo.close(); | 600 | fo.close(); |
601 | 601 | ||
602 | start = 0; | 602 | start = 0; |
603 | del = "\n.\n"; | 603 | del = "\n.\n"; |
604 | while ((uint) start < s.length()) { | 604 | while ((uint) start < s.length()) { |
605 | stop = s.find(del, start); | 605 | stop = s.find(del, start); |
606 | if (stop == -1) | 606 | if (stop == -1) |
607 | stop = s.length() - del.length(); | 607 | stop = s.length() - del.length(); |
608 | 608 | ||
609 | mail.rawMail = s.mid(start, stop + del.length() - start ); | 609 | mail.rawMail = s.mid(start, stop + del.length() - start ); |
610 | start = stop + del.length(); | 610 | start = stop + del.length(); |
611 | emailHandler->parse(mail.rawMail, lineShift, &mail); | 611 | emailHandler->parse(mail.rawMail, lineShift, &mail); |
612 | mail.sent = false; | 612 | mail.sent = false; |
613 | mail.received = false; | 613 | mail.received = false; |
614 | enqueMail(mail); | 614 | enqueMail(mail); |
615 | 615 | ||
616 | } | 616 | } |
617 | } | 617 | } |
618 | } | 618 | } |
619 | 619 | ||
620 | void EmailClient::saveMail(QString fileName, QListView *view) | 620 | void EmailClient::saveMail(QString fileName, QListView *view) |
621 | { | 621 | { |
622 | QFile f(fileName); | 622 | QFile f(fileName); |
623 | Email *mail; | 623 | Email *mail; |
624 | 624 | ||
625 | if (! f.open(IO_WriteOnly) ) { | 625 | if (! f.open(IO_WriteOnly) ) { |
626 | qWarning("could not open file"); | 626 | qWarning("could not open file"); |
627 | return; | 627 | return; |
628 | } | 628 | } |
629 | item = (EmailListItem *) view->firstChild(); | 629 | item = (EmailListItem *) view->firstChild(); |
630 | QTextStream t(&f); | 630 | QTextStream t(&f); |
631 | while (item != NULL) { | 631 | while (item != NULL) { |
632 | mail = item->getMail(); | 632 | mail = item->getMail(); |
633 | t << mail->rawMail; | 633 | t << mail->rawMail; |
634 | 634 | ||
635 | mailconf->setGroup(mail->id); | 635 | mailconf->setGroup(mail->id); |
636 | mailconf->writeEntry("mailread", mail->read); | 636 | mailconf->writeEntry("mailread", mail->read); |
637 | 637 | ||
638 | item = (EmailListItem *) item->nextSibling(); | 638 | item = (EmailListItem *) item->nextSibling(); |
639 | } | 639 | } |
640 | f.close(); | 640 | f.close(); |
641 | } | 641 | } |
642 | 642 | ||
643 | //paths for mailit, is settings, inbox, enclosures | 643 | //paths for mailit, is settings, inbox, enclosures |
644 | QString EmailClient::getPath(bool enclosurePath) | 644 | QString EmailClient::getPath(bool enclosurePath) |
645 | { | 645 | { |
646 | QString basePath = "qtmail"; | 646 | QString basePath = "qtmail"; |
647 | QString enclosures = "enclosures"; | 647 | QString enclosures = "enclosures"; |
648 | 648 | ||
649 | QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); | 649 | QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); |
650 | if ( !dir.exists() ) | 650 | if ( !dir.exists() ) |
651 | dir.mkdir( dir.path() ); | 651 | dir.mkdir( dir.path() ); |
652 | 652 | ||
653 | if (enclosurePath) { | 653 | if (enclosurePath) { |
654 | dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); | 654 | dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); |
655 | 655 | ||
656 | if ( !dir.exists() ) | 656 | if ( !dir.exists() ) |
657 | dir.mkdir( dir.path() ); | 657 | dir.mkdir( dir.path() ); |
658 | 658 | ||
659 | return (dir.path() + "/"); | 659 | return (dir.path() + "/"); |
660 | 660 | ||
661 | } | 661 | } |
662 | return (dir.path() + "/"); | 662 | return (dir.path() + "/"); |
663 | } | 663 | } |
664 | 664 | ||
665 | void EmailClient::readSettings() | 665 | void EmailClient::readSettings() |
666 | { | 666 | { |
667 | int y,acc_count, accountPos=0; | 667 | int y,acc_count; |
668 | 668 | ||
669 | mailconf->setGroup("mailitglobal"); | 669 | mailconf->setGroup("mailitglobal"); |
670 | acc_count=mailconf->readNumEntry("Accounts",0); | 670 | acc_count=mailconf->readNumEntry("Accounts",0); |
671 | 671 | ||
672 | for (int accountPos = 0;accountPos<acc_count ; accountPos++) | 672 | for (int accountPos = 0;accountPos<acc_count ; accountPos++) |
673 | { | 673 | { |
674 | mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ... | 674 | mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ... |
675 | account.accountName = mailconf->readEntry("AccName",""); | 675 | account.accountName = mailconf->readEntry("AccName",""); |
676 | account.name = mailconf->readEntry("UserName",""); | 676 | account.name = mailconf->readEntry("UserName",""); |
677 | account.emailAddress = mailconf->readEntry("Email",""); | 677 | account.emailAddress = mailconf->readEntry("Email",""); |
678 | account.popUserName = mailconf->readEntry("POPUser",""); | 678 | account.popUserName = mailconf->readEntry("POPUser",""); |
679 | account.popPasswd = mailconf->readEntryCrypt("POPPassword",""); | 679 | account.popPasswd = mailconf->readEntryCrypt("POPPassword",""); |
680 | account.popServer = mailconf->readEntry("POPServer",""); | 680 | account.popServer = mailconf->readEntry("POPServer",""); |
681 | account.smtpServer = mailconf->readEntry("SMTPServer",""); | 681 | account.smtpServer = mailconf->readEntry("SMTPServer",""); |
682 | account.id = mailconf->readNumEntry("AccountId",0); | 682 | account.id = mailconf->readNumEntry("AccountId",0); |
683 | account.syncLimit = mailconf->readNumEntry("HeaderLimit",0); | 683 | account.syncLimit = mailconf->readNumEntry("HeaderLimit",0); |
684 | account.lastServerMailCount = 0; | 684 | account.lastServerMailCount = 0; |
685 | account.synchronize = FALSE; | 685 | account.synchronize = FALSE; |
686 | 686 | ||
687 | account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes"); | 687 | account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes"); |
688 | if (account.synchronize) | 688 | if (account.synchronize) |
689 | { | 689 | { |
690 | mailconf->readNumEntry("LASTSERVERMAILCOUNT",0); | 690 | mailconf->readNumEntry("LASTSERVERMAILCOUNT",0); |
691 | } | 691 | } |
692 | 692 | ||
693 | accountList.append(&account); | 693 | accountList.append(&account); |
694 | } | 694 | } |
695 | 695 | ||
696 | mailconf->setGroup("mailitglobal"); | 696 | mailconf->setGroup("mailitglobal"); |
697 | 697 | ||
698 | if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) | 698 | if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) |
699 | { | 699 | { |
700 | mailIdCount = y; | 700 | mailIdCount = y; |
701 | } | 701 | } |
702 | if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) | 702 | if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) |
703 | { | 703 | { |
704 | accountIdCount = y; | 704 | accountIdCount = y; |
705 | } | 705 | } |
706 | } | 706 | } |
707 | 707 | ||
708 | void EmailClient::saveSettings() | 708 | void EmailClient::saveSettings() |
709 | { | 709 | { |
710 | int acc_count=0; | 710 | int acc_count=0; |
711 | MailAccount *accountPtr; | 711 | MailAccount *accountPtr; |
712 | 712 | ||
713 | 713 | ||
714 | if (!mailconf) | 714 | if (!mailconf) |
715 | { | 715 | { |
716 | qWarning("could not save settings"); | 716 | qWarning("could not save settings"); |
717 | return; | 717 | return; |
718 | } | 718 | } |
719 | 719 | ||
720 | for (accountPtr = accountList.first(); accountPtr != 0; | 720 | for (accountPtr = accountList.first(); accountPtr != 0; |
721 | accountPtr = accountList.next()) | 721 | accountPtr = accountList.next()) |
722 | { | 722 | { |
723 | mailconf->setGroup("Account_"+QString::number(++acc_count)); | 723 | mailconf->setGroup("Account_"+QString::number(++acc_count)); |
724 | mailconf->writeEntry("AccName",accountPtr->accountName ); | 724 | mailconf->writeEntry("AccName",accountPtr->accountName ); |
725 | mailconf->writeEntry("UserName",accountPtr->name); | 725 | mailconf->writeEntry("UserName",accountPtr->name); |
726 | mailconf->writeEntry("Email",accountPtr->emailAddress); | 726 | mailconf->writeEntry("Email",accountPtr->emailAddress); |
727 | mailconf->writeEntry("POPUser",accountPtr->popUserName); | 727 | mailconf->writeEntry("POPUser",accountPtr->popUserName); |
728 | mailconf->writeEntryCrypt("POPPassword",accountPtr->popPasswd); | 728 | mailconf->writeEntryCrypt("POPPassword",accountPtr->popPasswd); |
729 | mailconf->writeEntry("POPServer",accountPtr->popServer); | 729 | mailconf->writeEntry("POPServer",accountPtr->popServer); |
730 | mailconf->writeEntry("SMTPServer",accountPtr->smtpServer); | 730 | mailconf->writeEntry("SMTPServer",accountPtr->smtpServer); |
731 | mailconf->writeEntry("AccountId",accountPtr->id); | 731 | mailconf->writeEntry("AccountId",accountPtr->id); |
732 | if (accountPtr->synchronize) | 732 | if (accountPtr->synchronize) |
733 | { | 733 | { |
734 | mailconf->writeEntry("Synchronize","Yes"); | 734 | mailconf->writeEntry("Synchronize","Yes"); |
735 | mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit); | 735 | mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit); |
736 | mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount); | 736 | mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount); |
737 | } | 737 | } |
738 | else | 738 | else |
739 | { | 739 | { |
740 | mailconf->writeEntry("Synchronize", "No"); | 740 | mailconf->writeEntry("Synchronize", "No"); |
741 | } | 741 | } |
742 | } | 742 | } |
743 | 743 | ||
744 | mailconf->setGroup("mailitglobal"); | 744 | mailconf->setGroup("mailitglobal"); |
745 | mailconf->writeEntry("Accounts",acc_count); | 745 | mailconf->writeEntry("Accounts",acc_count); |
746 | mailconf->writeEntry("mailidcount", mailIdCount); | 746 | mailconf->writeEntry("mailidcount", mailIdCount); |
747 | mailconf->writeEntry("accountidcount", accountIdCount); | 747 | mailconf->writeEntry("accountidcount", accountIdCount); |
748 | } | 748 | } |
749 | 749 | ||
750 | void EmailClient::selectAccount(int id) | 750 | void EmailClient::selectAccount(int id) |
751 | { | 751 | { |
752 | if (accountList.count() > 0) { | 752 | if (accountList.count() > 0) { |
753 | currentAccount = accountList.at(id); | 753 | currentAccount = accountList.at(id); |
754 | emit newCaption("Mailit - " + currentAccount->accountName); | 754 | emit newCaption("Mailit - " + currentAccount->accountName); |
755 | getNewMail(); | 755 | getNewMail(); |
756 | } else { | 756 | } else { |
757 | emit newCaption("Mailit ! No account defined"); | 757 | emit newCaption("Mailit ! No account defined"); |
758 | } | 758 | } |
759 | } | 759 | } |
760 | 760 | ||
761 | void EmailClient::editAccount(int id) | 761 | void EmailClient::editAccount(int id) |
762 | { | 762 | { |
763 | MailAccount *newAccount; | 763 | MailAccount *newAccount; |
764 | 764 | ||
765 | editAccountView = new EditAccount(this, "account", TRUE); | 765 | editAccountView = new EditAccount(this, "account", TRUE); |
766 | if (id == newAccountId) { //new account | 766 | if (id == newAccountId) { //new account |
767 | newAccount = new MailAccount; | 767 | newAccount = new MailAccount; |
768 | editAccountView->setAccount(newAccount); | 768 | editAccountView->setAccount(newAccount); |
769 | } else { | 769 | } else { |
770 | newAccount = accountList.at(id); | 770 | newAccount = accountList.at(id); |
771 | editAccountView->setAccount(newAccount, FALSE); | 771 | editAccountView->setAccount(newAccount, FALSE); |
772 | } | 772 | } |
773 | 773 | ||
774 | editAccountView->showMaximized(); | 774 | editAccountView->showMaximized(); |
775 | editAccountView->exec(); | 775 | editAccountView->exec(); |
776 | 776 | ||
777 | if (editAccountView->result() == QDialog::Accepted) { | 777 | if (editAccountView->result() == QDialog::Accepted) { |
778 | if (id == newAccountId) { | 778 | if (id == newAccountId) { |
779 | newAccount->id = accountIdCount; | 779 | newAccount->id = accountIdCount; |
780 | accountIdCount++; | 780 | accountIdCount++; |
781 | accountList.append(newAccount); | 781 | accountList.append(newAccount); |
782 | updateAccounts(); | 782 | updateAccounts(); |
783 | } else { | 783 | } else { |
784 | updateAccounts(); | 784 | updateAccounts(); |
785 | } | 785 | } |
786 | } | 786 | } |
787 | 787 | ||
788 | delete editAccountView; | 788 | delete editAccountView; |
789 | } | 789 | } |
790 | 790 | ||
791 | void EmailClient::deleteAccount(int id) | 791 | void EmailClient::deleteAccount(int id) |
792 | { | 792 | { |
793 | MailAccount *newAccount; | 793 | MailAccount *newAccount; |
794 | QString message; | 794 | QString message; |
795 | 795 | ||
796 | newAccount = accountList.at(id); | 796 | newAccount = accountList.at(id); |
797 | message = "Delete account:\n" + newAccount->accountName; | 797 | message = "Delete account:\n" + newAccount->accountName; |
798 | switch( QMessageBox::warning( this, "Mailit", message, | 798 | switch( QMessageBox::warning( this, "Mailit", message, |
799 | "Yes", "No", 0, 0, 1 ) ) { | 799 | "Yes", "No", 0, 0, 1 ) ) { |
800 | 800 | ||
801 | case 0: accountList.remove(id); | 801 | case 0: accountList.remove(id); |
802 | updateAccounts(); | 802 | updateAccounts(); |
803 | break; | 803 | break; |
804 | case 1: | 804 | case 1: |
805 | break; | 805 | break; |
806 | } | 806 | } |
807 | } | 807 | } |
808 | 808 | ||
809 | void EmailClient::updateAccounts() | 809 | void EmailClient::updateAccounts() |
810 | { | 810 | { |
811 | MailAccount *accountPtr; | 811 | MailAccount *accountPtr; |
812 | 812 | ||
813 | //rebuild menus, clear all first | 813 | //rebuild menus, clear all first |
814 | editAccountMenu->clear(); | 814 | editAccountMenu->clear(); |
815 | selectAccountMenu->clear(); | 815 | selectAccountMenu->clear(); |
816 | deleteAccountMenu->clear(); | 816 | deleteAccountMenu->clear(); |
817 | 817 | ||
818 | newAccountId = editAccountMenu->insertItem("New", this, | 818 | newAccountId = editAccountMenu->insertItem("New", this, |
819 | SLOT(editAccount(int)) ); | 819 | SLOT(editAccount(int)) ); |
820 | editAccountMenu->insertSeparator(); | 820 | editAccountMenu->insertSeparator(); |
821 | 821 | ||
822 | idCount = 0; | 822 | idCount = 0; |
823 | for (accountPtr = accountList.first(); accountPtr != 0; | 823 | for (accountPtr = accountList.first(); accountPtr != 0; |
824 | accountPtr = accountList.next()) { | 824 | accountPtr = accountList.next()) { |
825 | 825 | ||
826 | editAccountMenu->insertItem(accountPtr->accountName, | 826 | editAccountMenu->insertItem(accountPtr->accountName, |
827 | this, SLOT(editAccount(int)), 0, idCount); | 827 | this, SLOT(editAccount(int)), 0, idCount); |
828 | selectAccountMenu->insertItem(accountPtr->accountName, | 828 | selectAccountMenu->insertItem(accountPtr->accountName, |
829 | this, SLOT(selectAccount(int)), 0, idCount); | 829 | this, SLOT(selectAccount(int)), 0, idCount); |
830 | deleteAccountMenu->insertItem(accountPtr->accountName, | 830 | deleteAccountMenu->insertItem(accountPtr->accountName, |
831 | this, SLOT(deleteAccount(int)), 0, idCount); | 831 | this, SLOT(deleteAccount(int)), 0, idCount); |
832 | idCount++; | 832 | idCount++; |
833 | } | 833 | } |
834 | } | 834 | } |
835 | 835 | ||
836 | void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) | 836 | void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) |
837 | { | 837 | { |
838 | Email *mPtr; | 838 | Email *mPtr; |
839 | Enclosure *ePtr; | 839 | Enclosure *ePtr; |
840 | 840 | ||
841 | if (inbox) | 841 | if (inbox) |
842 | { | 842 | { |
843 | mPtr = mailItem->getMail(); | 843 | mPtr = mailItem->getMail(); |
844 | 844 | ||
845 | //if mail is in queue for download, remove it from | 845 | //if mail is in queue for download, remove it from |
846 | //queue if possible | 846 | //queue if possible |
847 | if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { | 847 | if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { |
848 | if ( !mPtr->downloaded ) | 848 | if ( !mPtr->downloaded ) |
849 | mailDownloadList.remove(mPtr->serverId, mPtr->size); | 849 | mailDownloadList.remove(mPtr->serverId, mPtr->size); |
850 | } | 850 | } |
851 | 851 | ||
852 | mailconf->setGroup(mPtr->id); | 852 | mailconf->setGroup(mPtr->id); |
853 | mailconf->clearGroup(); | 853 | mailconf->clearGroup(); |
854 | 854 | ||
855 | //delete any temporary attatchemnts storing | 855 | //delete any temporary attatchemnts storing |
856 | for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { | 856 | for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { |
857 | if (ePtr->saved) { | 857 | if (ePtr->saved) { |
858 | QFile::remove( (ePtr->path + ePtr->name) ); | 858 | QFile::remove( (ePtr->path + ePtr->name) ); |
859 | } | 859 | } |
860 | } | 860 | } |
861 | inboxView->takeItem(mailItem); | 861 | inboxView->takeItem(mailItem); |
862 | } | 862 | } |
863 | else | 863 | else |
864 | { | 864 | { |
865 | outboxView->takeItem(mailItem); | 865 | outboxView->takeItem(mailItem); |
866 | } | 866 | } |
867 | } | 867 | } |
868 | 868 | ||
869 | void EmailClient::setMailSize(int size) | 869 | void EmailClient::setMailSize(int size) |
870 | { | 870 | { |
871 | progressBar->reset(); | 871 | progressBar->reset(); |
872 | progressBar->setTotalSteps(size); | 872 | progressBar->setTotalSteps(size); |
873 | } | 873 | } |
874 | 874 | ||
875 | void EmailClient::setTotalSize(int size) | 875 | void EmailClient::setTotalSize(int size) |
876 | { | 876 | { |
877 | 877 | ||
878 | } | 878 | } |
879 | 879 | ||
880 | void EmailClient::setDownloadedSize(int size) | 880 | void EmailClient::setDownloadedSize(int size) |
881 | { | 881 | { |
882 | int total = progressBar->totalSteps(); | 882 | int total = progressBar->totalSteps(); |
883 | 883 | ||
884 | if (size < total) { | 884 | if (size < total) { |
885 | progressBar->setProgress(size); | 885 | progressBar->setProgress(size); |
886 | } else { | 886 | } else { |
887 | progressBar->setProgress(total); | 887 | progressBar->setProgress(total); |
888 | } | 888 | } |
889 | } | 889 | } |
890 | 890 | ||
891 | void EmailClient::deleteItem() | 891 | void EmailClient::deleteItem() |
892 | { | 892 | { |
893 | bool inbox=mailboxView->currentTab()==0; | 893 | bool inbox=mailboxView->currentTab()==0; |
894 | QListView* box; | ||
894 | 895 | ||
895 | EmailListItem* eli; | 896 | EmailListItem* eli; |
897 | int pos; | ||
898 | |||
899 | inbox ? box=inboxView : box=outboxView; | ||
896 | 900 | ||
897 | inbox ? eli=(EmailListItem*)inboxView->selectedItem():eli=(EmailListItem*)outboxView->selectedItem(); | 901 | eli=(EmailListItem*)box->selectedItem(); |
898 | 902 | ||
899 | if (eli) | 903 | if (eli) |
900 | deleteMail(eli,(bool&)inbox); | 904 | { |
905 | box->setSelected(eli->itemBelow(),true);//select the previous item | ||
906 | |||
907 | deleteMail(eli,(bool&)inbox); //remove mail entry | ||
908 | } | ||
901 | } | 909 | } |
902 | 910 | ||
903 | void EmailClient::inboxItemPressed() | 911 | void EmailClient::inboxItemPressed() |
904 | { | 912 | { |
905 | //timerID=startTimer(500); | 913 | //timerID=startTimer(500); |
906 | } | 914 | } |
907 | 915 | ||
908 | void EmailClient::inboxItemReleased() | 916 | void EmailClient::inboxItemReleased() |
909 | { | 917 | { |
910 | //killTimer(timerID); | 918 | //killTimer(timerID); |
911 | } | 919 | } |
912 | 920 | ||
913 | void EmailClient::timerEvent(QTimerEvent *e) | 921 | void EmailClient::timerEvent(QTimerEvent *e) |
914 | { | 922 | { |
915 | /*killTimer(timerID); | 923 | /*killTimer(timerID); |
916 | 924 | ||
917 | 925 | ||
918 | QPopupMenu *action = new QPopupMenu(this); | 926 | QPopupMenu *action = new QPopupMenu(this); |
919 | 927 | ||
920 | int reply=0; | 928 | int reply=0; |
921 | 929 | ||
922 | action->insertItem(tr( "Reply To" ),this,SLOT(reply())); | 930 | action->insertItem(tr( "Reply To" ),this,SLOT(reply())); |
923 | action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); | 931 | action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); |
924 | action->insertItem( tr( "Forward" ), this,SLOT(forward())); | 932 | action->insertItem( tr( "Forward" ), this,SLOT(forward())); |
925 | action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); | 933 | action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); |
926 | 934 | ||
927 | action->exec(QCursor::pos()); | 935 | action->exec(QCursor::pos()); |
928 | 936 | ||
929 | if (action) delete action; | 937 | if (action) delete action; |
930 | */ | 938 | */ |
931 | } | 939 | } |
932 | 940 | ||
933 | Email* EmailClient::getCurrentMail() | 941 | Email* EmailClient::getCurrentMail() |
934 | { | 942 | { |
935 | EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); | 943 | EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); |
936 | if (eli!=NULL) | 944 | if (eli!=NULL) |
937 | return eli->getMail(); | 945 | return eli->getMail(); |
938 | else | 946 | else |
939 | return NULL; | 947 | return NULL; |
940 | } | 948 | } |
941 | 949 | ||
942 | /* | 950 | void EmailClient::download(Email* mail) |
943 | void EmailClient::reply() | ||
944 | { | ||
945 | Email* mail=getCurrentMail(); | ||
946 | |||
947 | if (mail!=NULL) | ||
948 | { | ||
949 | emit reply(*mail); | ||
950 | } | ||
951 | } | ||
952 | |||
953 | void EmailClient::replyAll() | ||
954 | { | ||
955 | Email* mail=getCurrentMail(); | ||
956 | |||
957 | if (mail!=NULL) | ||
958 | { | ||
959 | emit replyAll(*mail); | ||
960 | } | ||
961 | } | ||
962 | |||
963 | void EmailClient::forward() | ||
964 | { | 951 | { |
965 | Email* mail=getCurrentMail(); | 952 | MailAccount* acc=0; |
966 | 953 | ||
967 | if (mail!=NULL) | 954 | tempMailDownloadList.clear(); |
968 | { | 955 | tempMailDownloadList.sizeInsert(mail->serverId, mail->size); |
969 | emit reply(*mail); | 956 | if (accountList.count()>0) |
970 | } | 957 | qDebug("Accounts present"); |
958 | |||
959 | acc=accountList.at(mail->fromAccountId-1); | ||
960 | if (acc) | ||
961 | { | ||
962 | emailHandler->setAccount(*acc); | ||
963 | emailHandler->getMailByList(&tempMailDownloadList); | ||
964 | } | ||
965 | else | ||
966 | 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"); | ||
971 | } | 968 | } |
972 | |||
973 | void EmailClient::remove() | ||
974 | { | ||
975 | Email* mail=getCurrentMail(); | ||
976 | |||
977 | if (mail!=NULL) | ||
978 | { | ||
979 | emit remove(*mail); | ||
980 | } | ||
981 | }*/ | ||
diff --git a/noncore/unsupported/mailit/emailclient.h b/noncore/unsupported/mailit/emailclient.h index 0890dcf..549683b 100644 --- a/noncore/unsupported/mailit/emailclient.h +++ b/noncore/unsupported/mailit/emailclient.h | |||
@@ -1,171 +1,174 @@ | |||
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 <qtimer.h> | 44 | #include <qtimer.h> |
45 | 45 | ||
46 | #include "emailhandler.h" | 46 | #include "emailhandler.h" |
47 | #include "emaillistitem.h" | 47 | #include "emaillistitem.h" |
48 | #include "textparser.h" | 48 | #include "textparser.h" |
49 | #include "editaccount.h" | 49 | #include "editaccount.h" |
50 | #include "maillist.h" | 50 | #include "maillist.h" |
51 | #include "addresslist.h" | 51 | #include "addresslist.h" |
52 | 52 | ||
53 | #include <qpe/config.h> | 53 | #include <qpe/config.h> |
54 | 54 | ||
55 | class AccountList : public QList<MailAccount> | 55 | class AccountList : public QList<MailAccount> |
56 | { | 56 | { |
57 | public: | 57 | public: |
58 | Item newItem(Item d); | 58 | Item newItem(Item d); |
59 | private: | 59 | private: |
60 | MailAccount* dupl(MailAccount *in); | 60 | MailAccount* dupl(MailAccount *in); |
61 | MailAccount *ac; | 61 | MailAccount *ac; |
62 | }; | 62 | }; |
63 | 63 | ||
64 | //class EmailClient : public EmailClientBase | 64 | //class EmailClient : public EmailClientBase |
65 | class EmailClient : public QMainWindow | 65 | class EmailClient : public QMainWindow |
66 | { | 66 | { |
67 | Q_OBJECT | 67 | Q_OBJECT |
68 | 68 | ||
69 | public: | 69 | public: |
70 | EmailClient( QWidget* parent, const char* name, WFlags fl = 0 ); | 70 | EmailClient( QWidget* parent, const char* name, WFlags fl = 0 ); |
71 | ~EmailClient(); | 71 | ~EmailClient(); |
72 | AddressList* getAdrListRef(); | 72 | AddressList* getAdrListRef(); |
73 | void download(Email*); | ||
73 | 74 | ||
74 | protected: | 75 | protected: |
75 | void timerEvent(QTimerEvent*); | 76 | void timerEvent(QTimerEvent*); |
76 | 77 | ||
77 | signals: | 78 | signals: |
78 | void composeRequested(); | 79 | void composeRequested(); |
79 | void viewEmail(QListView *, Email *); | 80 | void viewEmail(QListView *, Email *); |
80 | void mailUpdated(Email *); | 81 | void mailUpdated(Email *); |
81 | void newCaption(const QString &); | 82 | void newCaption(const QString &); |
82 | void replyRequested(Email&, bool&); | 83 | void replyRequested(Email&, bool&); |
83 | void forwardRequested(Email&); | 84 | void forwardRequested(Email&); |
84 | void removeItem(EmailListItem*, bool&); | 85 | void removeItem(EmailListItem*, bool&); |
85 | /*void reply(Email&); | 86 | /*void reply(Email&); |
86 | void replyAll(Email&); | 87 | void replyAll(Email&); |
87 | void remove(Email&); | 88 | void remove(Email&); |
88 | void forward(Email&);*/ | 89 | void forward(Email&);*/ |
89 | 90 | ||
90 | public slots: | 91 | public slots: |
91 | void compose(); | 92 | void compose(); |
92 | void cancel(); | 93 | void cancel(); |
93 | void enqueMail(const Email &mail); | 94 | void enqueMail(const Email &mail); |
94 | void setMailAccount(); | 95 | void setMailAccount(); |
95 | void sendQuedMail(); | 96 | void sendQuedMail(); |
96 | void mailSent(); | 97 | void mailSent(); |
97 | void deleteItem(); | 98 | void deleteItem(); |
98 | void getNewMail(); | 99 | void getNewMail(); |
99 | void getAllNewMail(); | 100 | void getAllNewMail(); |
100 | void smtpError(int code); | 101 | void smtpError(int code); |
101 | void popError(int code); | 102 | void popError(int code); |
102 | void inboxItemSelected(); | 103 | void inboxItemSelected(); |
103 | void outboxItemSelected(); | 104 | void outboxItemSelected(); |
104 | void inboxItemPressed(); | 105 | void inboxItemPressed(); |
105 | void inboxItemReleased(); | 106 | void inboxItemReleased(); |
106 | void mailArrived(const Email &mail, bool fromDisk); | 107 | void mailArrived(const Email &mail, bool fromDisk); |
107 | void allMailArrived(int); | 108 | void allMailArrived(int); |
108 | void saveMail(QString fileName, QListView *view); | 109 | void saveMail(QString fileName, QListView *view); |
109 | void selectAccount(int); | 110 | void selectAccount(int); |
110 | void editAccount(int); | 111 | void editAccount(int); |
111 | void updateAccounts(); | 112 | void updateAccounts(); |
112 | void deleteAccount(int); | 113 | void deleteAccount(int); |
113 | void deleteMail(EmailListItem *mailItem, bool &inbox); | 114 | void deleteMail(EmailListItem *mailItem, bool &inbox); |
114 | void setTotalSize(int); | 115 | void setTotalSize(int); |
115 | void setMailSize(int); | 116 | void setMailSize(int); |
116 | void setDownloadedSize(int); | 117 | void setDownloadedSize(int); |
117 | void moveMailFront(Email *mailPtr); | 118 | void moveMailFront(Email *mailPtr); |
118 | /* void reply(); | 119 | /* void reply(); |
119 | void replyAll(); | 120 | void replyAll(); |
120 | void forward(); | 121 | void forward(); |
121 | void remove();*/ | 122 | void remove();*/ |
122 | 123 | ||
123 | private: | 124 | private: |
124 | void init(); | 125 | void init(); |
125 | void readMail(); | 126 | void readMail(); |
126 | QString getPath(bool enclosurePath); | 127 | QString getPath(bool enclosurePath); |
127 | void readSettings(); | 128 | void readSettings(); |
128 | void saveSettings(); | 129 | void saveSettings(); |
129 | Email* getCurrentMail(); | 130 | Email* getCurrentMail(); |
130 | int timerID; | 131 | int timerID; |
131 | Config *mailconf; | 132 | Config *mailconf; |
132 | int newAccountId, idCount, mailIdCount; | 133 | int newAccountId, idCount, mailIdCount; |
133 | int accountIdCount; | 134 | int accountIdCount; |
134 | AccountList accountList; | 135 | AccountList accountList; |
135 | AddressList *addressList; | 136 | AddressList *addressList; |
136 | 137 | ||
137 | EditAccount *editAccountView; | 138 | EditAccount *editAccountView; |
138 | EmailListItem *item; | 139 | EmailListItem *item; |
139 | EmailHandler *emailHandler; | 140 | EmailHandler *emailHandler; |
140 | QList<Email> quedMessages; | 141 | QList<Email> quedMessages; |
141 | MailList mailDownloadList; | 142 | MailList mailDownloadList; |
143 | MailList tempMailDownloadList; | ||
144 | |||
142 | bool sending, receiving, previewingMail, allAccounts; | 145 | bool sending, receiving, previewingMail, allAccounts; |
143 | QString lineShift; | 146 | QString lineShift; |
144 | MailAccount account, *currentAccount; | 147 | MailAccount account, *currentAccount; |
145 | 148 | ||
146 | QToolBar *bar; | 149 | QToolBar *bar; |
147 | QProgressBar *progressBar; | 150 | QProgressBar *progressBar; |
148 | QStatusBar *statusBar; | 151 | QStatusBar *statusBar; |
149 | QLabel *status1Label, *status2Label; | 152 | QLabel *status1Label, *status2Label; |
150 | QToolButton *getMailButton; | 153 | QToolButton *getMailButton; |
151 | QAction *sendMailButton; | 154 | QAction *sendMailButton; |
152 | QAction *composeButton; | 155 | QAction *composeButton; |
153 | QAction *cancelButton; | 156 | QAction *cancelButton; |
154 | QAction *deleteButton; | 157 | QAction *deleteButton; |
155 | //QToolButton *setAccountButton; | 158 | //QToolButton *setAccountButton; |
156 | 159 | ||
157 | QMenuBar *mb; | 160 | QMenuBar *mb; |
158 | QPopupMenu *selectAccountMenu; | 161 | QPopupMenu *selectAccountMenu; |
159 | QPopupMenu *editAccountMenu; | 162 | QPopupMenu *editAccountMenu; |
160 | QPopupMenu *deleteAccountMenu; | 163 | QPopupMenu *deleteAccountMenu; |
161 | QPopupMenu *setAccountMenu; | 164 | QPopupMenu *setAccountMenu; |
162 | 165 | ||
163 | OTabWidget* mailboxView; | 166 | OTabWidget* mailboxView; |
164 | QListView* inboxView; | 167 | QListView* inboxView; |
165 | QListView* outboxView; | 168 | QListView* outboxView; |
166 | 169 | ||
167 | QGridLayout* grid_2; | 170 | QGridLayout* grid_2; |
168 | QGridLayout* grid_3; | 171 | QGridLayout* grid_3; |
169 | }; | 172 | }; |
170 | 173 | ||
171 | #endif // EMAILCLIENT_H | 174 | #endif // EMAILCLIENT_H |
diff --git a/noncore/unsupported/mailit/emailhandler.cpp b/noncore/unsupported/mailit/emailhandler.cpp index b180051..fbbada7 100644 --- a/noncore/unsupported/mailit/emailhandler.cpp +++ b/noncore/unsupported/mailit/emailhandler.cpp | |||
@@ -1,628 +1,628 @@ | |||
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 | ||
29 | QCollection::Item EnclosureList::newItem(QCollection::Item d) | 29 | QCollection::Item EnclosureList::newItem(QCollection::Item d) |
30 | { | 30 | { |
31 | return dupl( (Enclosure *) d); | 31 | return dupl( (Enclosure *) d); |
32 | } | 32 | } |
33 | 33 | ||
34 | Enclosure* EnclosureList::dupl(Enclosure *in) | 34 | Enclosure* 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 | ||
40 | EmailHandler::EmailHandler() | 40 | EmailHandler::EmailHandler() |
41 | { | 41 | { |
42 | smtpClient = new SmtpClient(); | 42 | smtpClient = new SmtpClient(); |
43 | popClient = new PopClient(); | 43 | popClient = new PopClient(); |
44 | 44 | ||
45 | connect(smtpClient, SIGNAL(errorOccurred(int)), this, | 45 | connect(smtpClient, SIGNAL(errorOccurred(int)), this, |
46 | SIGNAL(smtpError(int)) ); | 46 | SIGNAL(smtpError(int)) ); |
47 | connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); | 47 | connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); |
48 | connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, | 48 | connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, |
49 | SIGNAL(updateSmtpStatus(const QString &)) ); | 49 | SIGNAL(updateSmtpStatus(const QString &)) ); |
50 | 50 | ||
51 | connect(popClient, SIGNAL(errorOccurred(int)), this, | 51 | connect(popClient, SIGNAL(errorOccurred(int)), this, |
52 | SIGNAL(popError(int)) ); | 52 | SIGNAL(popError(int)) ); |
53 | connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), | 53 | connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), |
54 | this, SLOT(messageArrived(const QString &, int, uint, bool)) ); | 54 | this, SLOT(messageArrived(const QString &, int, uint, bool)) ); |
55 | connect(popClient, SIGNAL(updateStatus(const QString &)), this, | 55 | connect(popClient, SIGNAL(updateStatus(const QString &)), this, |
56 | SIGNAL(updatePopStatus(const QString &)) ); | 56 | SIGNAL(updatePopStatus(const QString &)) ); |
57 | connect(popClient, SIGNAL(mailTransfered(int)), this, | 57 | connect(popClient, SIGNAL(mailTransfered(int)), this, |
58 | SIGNAL(mailTransfered(int)) ); | 58 | SIGNAL(mailTransfered(int)) ); |
59 | 59 | ||
60 | 60 | ||
61 | //relaying size information | 61 | //relaying size information |
62 | connect(popClient, SIGNAL(currentMailSize(int)), | 62 | connect(popClient, SIGNAL(currentMailSize(int)), |
63 | this, SIGNAL(currentMailSize(int)) ); | 63 | this, SIGNAL(currentMailSize(int)) ); |
64 | connect(popClient, SIGNAL(downloadedSize(int)), | 64 | connect(popClient, SIGNAL(downloadedSize(int)), |
65 | this, SIGNAL(downloadedSize(int)) ); | 65 | this, SIGNAL(downloadedSize(int)) ); |
66 | } | 66 | } |
67 | 67 | ||
68 | void EmailHandler::sendMail(QList<Email> *mailList) | 68 | void EmailHandler::sendMail(QList<Email> *mailList) |
69 | { | 69 | { |
70 | Email *currentMail; | 70 | Email *currentMail; |
71 | QString temp; | 71 | QString temp; |
72 | QString userName = mailAccount.name; | 72 | QString userName = mailAccount.name; |
73 | userName += " <" + mailAccount.emailAddress + ">"; | 73 | userName += " <" + mailAccount.emailAddress + ">"; |
74 | 74 | ||
75 | for (currentMail = mailList->first(); currentMail != 0; | 75 | for (currentMail = mailList->first(); currentMail != 0; |
76 | currentMail = mailList->next()) { | 76 | currentMail = mailList->next()) { |
77 | 77 | ||
78 | if (encodeMime(currentMail) == 0) { | 78 | if (encodeMime(currentMail) == 0) { |
79 | smtpClient->addMail(userName, currentMail->subject, | 79 | smtpClient->addMail(userName, currentMail->subject, |
80 | currentMail->recipients, currentMail->rawMail); | 80 | currentMail->recipients, currentMail->rawMail); |
81 | } else { //error | 81 | } else { //error |
82 | temp = tr("Could not locate all files in \nmail with subject: ") + | 82 | temp = tr("Could not locate all files in \nmail with subject: ") + |
83 | currentMail->subject; | 83 | currentMail->subject; |
84 | temp += tr("\nMail has NOT been sent"); | 84 | temp += tr("\nMail has NOT been sent"); |
85 | QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); | 85 | QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); |
86 | 86 | ||
87 | } | 87 | } |
88 | } | 88 | } |
89 | smtpClient->newConnection(mailAccount.smtpServer, 25); | 89 | smtpClient->newConnection(mailAccount.smtpServer, 25); |
90 | } | 90 | } |
91 | 91 | ||
92 | void EmailHandler::setAccount(MailAccount account) | 92 | void EmailHandler::setAccount(MailAccount account) |
93 | { | 93 | { |
94 | mailAccount = account; | 94 | mailAccount = account; |
95 | } | 95 | } |
96 | 96 | ||
97 | void EmailHandler::getMail() | 97 | void EmailHandler::getMail() |
98 | { | 98 | { |
99 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); | 99 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); |
100 | if (mailAccount.synchronize) { | 100 | if (mailAccount.synchronize) { |
101 | popClient->setSynchronize(mailAccount.lastServerMailCount); | 101 | popClient->setSynchronize(mailAccount.lastServerMailCount); |
102 | } else { | 102 | } else { |
103 | popClient->removeSynchronize(); | 103 | popClient->removeSynchronize(); |
104 | } | 104 | } |
105 | 105 | ||
106 | headers = FALSE; | 106 | headers = FALSE; |
107 | //popClient->headersOnly(headers, 0); | 107 | //popClient->headersOnly(headers, 0); |
108 | popClient->newConnection(mailAccount.popServer, 110); | 108 | popClient->newConnection(mailAccount.popServer, 110); |
109 | } | 109 | } |
110 | 110 | ||
111 | void EmailHandler::getMailHeaders() | 111 | void EmailHandler::getMailHeaders() |
112 | { | 112 | { |
113 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); | 113 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); |
114 | mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); | 114 | mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); |
115 | 115 | ||
116 | headers = TRUE; | 116 | headers = TRUE; |
117 | popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all | 117 | popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all |
118 | popClient->newConnection(mailAccount.popServer, 110); | 118 | popClient->newConnection(mailAccount.popServer, 110); |
119 | } | 119 | } |
120 | 120 | ||
121 | void EmailHandler::getMailByList(MailList *mailList) | 121 | void EmailHandler::getMailByList(MailList *mailList) |
122 | { | 122 | { |
123 | if (mailList->count() == 0) { //should not occur though | 123 | if (mailList->count() == 0) { //should not occur though |
124 | emit mailTransfered(0); | 124 | emit mailTransfered(0); |
125 | return; | 125 | return; |
126 | } | 126 | } |
127 | 127 | ||
128 | headers = FALSE; | 128 | headers = FALSE; |
129 | popClient->headersOnly(FALSE, 0); | 129 | popClient->headersOnly(FALSE, 0); |
130 | popClient->newConnection(mailAccount.popServer, 110); | 130 | |
131 | popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd); | ||
131 | popClient->setSelectedMails(mailList); | 132 | popClient->setSelectedMails(mailList); |
132 | } | 133 | popClient->newConnection(mailAccount.popServer, 110); |
134 | } | ||
133 | 135 | ||
134 | void EmailHandler::messageArrived(const QString &message, int id, uint size, bool incomplete) | 136 | void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) |
135 | { | 137 | { |
136 | Email mail; | 138 | Email mail; |
137 | 139 | ||
138 | mail.rawMail = message; | 140 | mail.rawMail = message; |
139 | mail.serverId = id; | 141 | mail.serverId = id; |
140 | mail.size = size; | 142 | mail.size = size; |
141 | mail.downloaded = incomplete; | 143 | mail.downloaded = complete; |
142 | 144 | ||
143 | emit mailArrived(mail, FALSE); | 145 | emit mailArrived(mail, FALSE); |
144 | } | 146 | } |
145 | 147 | ||
146 | bool EmailHandler::parse(QString in, QString lineShift, Email *mail) | 148 | bool EmailHandler::parse(QString in, QString lineShift, Email *mail) |
147 | { | 149 | { |
148 | QString temp, boundary; | 150 | QString temp, boundary; |
149 | int pos; | 151 | int pos; |
150 | QString delimiter, header, body, mimeHeader, mimeBody; | 152 | QString delimiter, header, body, mimeHeader, mimeBody; |
151 | QString content, contentType, contentAttribute, id, encoding; | 153 | QString content, contentType, contentAttribute, id, encoding; |
152 | QString fileName, storedName; | 154 | QString fileName, storedName; |
153 | int enclosureId = 0; | 155 | int enclosureId = 0; |
154 | 156 | ||
155 | mail->rawMail = in; | 157 | mail->rawMail = in; |
156 | mail->received = TRUE; | 158 | mail->received = TRUE; |
157 | mail->files.setAutoDelete(TRUE); | 159 | mail->files.setAutoDelete(TRUE); |
158 | 160 | ||
159 | temp = lineShift + "." + lineShift; | 161 | temp = lineShift + "." + lineShift; |
160 | 162 | ||
161 | if (in.right(temp.length()) != temp) { | 163 | if (in.right(temp.length()) != temp) { |
162 | mail->rawMail += temp; | 164 | mail->rawMail += temp; |
163 | } | 165 | } |
164 | 166 | ||
165 | 167 | ||
166 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" | 168 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" |
167 | pos = in.find(delimiter, 0, FALSE); | 169 | pos = in.find(delimiter, 0, FALSE); |
168 | header = in.left(pos); | 170 | header = in.left(pos); |
169 | body = in.right(in.length() - pos - delimiter.length()); | 171 | body = in.right(in.length() - pos - delimiter.length()); |
170 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) | 172 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) |
171 | body.truncate(body.length()-2); | 173 | body.truncate(body.length()-2); |
172 | 174 | ||
173 | TextParser p(header, lineShift); | 175 | TextParser p(header, lineShift); |
174 | 176 | ||
175 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { | 177 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { |
176 | pos++; | 178 | pos++; |
177 | if (p.separatorAt(pos) == ' ') { | 179 | if (p.separatorAt(pos) == ' ') { |
178 | mail->from = p.getString(&pos, '<', false); | 180 | mail->from = p.getString(&pos, '<', false); |
179 | mail->from = mail->from.stripWhiteSpace(); | 181 | mail->from = mail->from.stripWhiteSpace(); |
180 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { | 182 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { |
181 | mail->from = mail->from.left(mail->from.length() - 1); | 183 | mail->from = mail->from.left(mail->from.length() - 1); |
182 | mail->from = mail->from.right(mail->from.length() - 1); | 184 | mail->from = mail->from.right(mail->from.length() - 1); |
183 | } | 185 | } |
184 | pos++; | 186 | pos++; |
185 | |||
186 | mail->fromMail = p.getString(&pos, '>', false); | 187 | mail->fromMail = p.getString(&pos, '>', false); |
187 | } else { | 188 | } else { |
188 | if ((p.separatorAt(pos) == '<') | 189 | if (p.separatorAt(pos) == '<') //No name.. nasty |
189 | || (p.separatorAt(pos) == ' ')) //No name.. nasty | ||
190 | pos++; | ||
191 | pos++; | 190 | pos++; |
191 | //pos++; | ||
192 | mail->fromMail = p.getString(&pos, 'z', TRUE); | 192 | mail->fromMail = p.getString(&pos, 'z', TRUE); |
193 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') | 193 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') |
194 | mail->fromMail.truncate(mail->fromMail.length() - 1); | 194 | mail->fromMail.truncate(mail->fromMail.length() - 1); |
195 | mail->from=mail->fromMail; | 195 | mail->from=mail->fromMail; |
196 | } | 196 | } |
197 | } | 197 | } |
198 | 198 | ||
199 | pos=0; | 199 | pos=0; |
200 | 200 | ||
201 | //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: | 201 | //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: |
202 | while((pos = p.find("TO",':', pos+1, TRUE))!=-1) | 202 | while((pos = p.find("TO",':', pos+1, TRUE))!=-1) |
203 | { | 203 | { |
204 | QString rec; | 204 | QString rec; |
205 | 205 | ||
206 | if (p.separatorAt(pos-1)!='-') | 206 | if (p.separatorAt(pos-1)!='-') |
207 | { | 207 | { |
208 | pos++; | 208 | pos++; |
209 | mail->recipients.append(p.getString(&pos, '\r', TRUE)); | 209 | mail->recipients.append(p.getString(&pos, '\r', TRUE)); |
210 | } | 210 | } |
211 | /*else { | 211 | /*else { |
212 | if ((p.separatorAt(pos) == '<')|| (p.separatorAt(pos) == ' ')) //No name.. nasty | 212 | if ((p.separatorAt(pos) == '<')|| (p.separatorAt(pos) == ' ')) //No name.. nasty |
213 | pos++; | 213 | pos++; |
214 | pos++; | 214 | pos++; |
215 | mail->fromMail = p.getString(&pos, 'z', TRUE); | 215 | mail->fromMail = p.getString(&pos, 'z', TRUE); |
216 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') | 216 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') |
217 | mail->fromMail.truncate(mail->fromMail.length() - 1); | 217 | mail->fromMail.truncate(mail->fromMail.length() - 1); |
218 | mail->from=mail->fromMail; | 218 | mail->from=mail->fromMail; |
219 | } | 219 | } |
220 | mail->recipients.append (p.getString(&pos, 'z', TRUE) ); | 220 | mail->recipients.append (p.getString(&pos, 'z', TRUE) ); |
221 | }*/ | 221 | }*/ |
222 | } | 222 | } |
223 | // | 223 | // |
224 | //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); | 224 | //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); |
225 | 225 | ||
226 | if ((pos = p.find("CC",':', 0, TRUE)) != -1) | 226 | if ((pos = p.find("CC",':', 0, TRUE)) != -1) |
227 | { | 227 | { |
228 | pos++; | 228 | pos++; |
229 | mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); | 229 | mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); |
230 | } | 230 | } |
231 | 231 | ||
232 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { | 232 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { |
233 | pos++; | 233 | pos++; |
234 | mail->subject = p.getString(&pos, 'z', TRUE); | 234 | mail->subject = p.getString(&pos, 'z', TRUE); |
235 | } | 235 | } |
236 | 236 | ||
237 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { | 237 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { |
238 | pos++; | 238 | pos++; |
239 | mail->date = p.getString(&pos, 'z', TRUE); | 239 | mail->date = p.getString(&pos, 'z', TRUE); |
240 | } | 240 | } |
241 | 241 | ||
242 | 242 | ||
243 | 243 | ||
244 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { | 244 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { |
245 | pos++; | 245 | pos++; |
246 | if ( (p.wordAt(pos).upper() == "ID") && | 246 | if ( (p.wordAt(pos).upper() == "ID") && |
247 | (p.separatorAt(pos) == ':') ) { | 247 | (p.separatorAt(pos) == ':') ) { |
248 | 248 | ||
249 | id = p.getString(&pos, 'z', TRUE); | 249 | id = p.getString(&pos, 'z', TRUE); |
250 | mail->id = id; | 250 | mail->id = id; |
251 | } | 251 | } |
252 | } | 252 | } |
253 | 253 | ||
254 | pos = 0; | 254 | pos = 0; |
255 | while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { | 255 | while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { |
256 | pos++; | 256 | pos++; |
257 | if ( (p.wordAt(pos).upper() == "VERSION") && | 257 | if ( (p.wordAt(pos).upper() == "VERSION") && |
258 | (p.separatorAt(pos) == ':') ) { | 258 | (p.separatorAt(pos) == ':') ) { |
259 | pos++; | 259 | pos++; |
260 | if (p.getString(&pos, 'z', true) == "1.0") { | 260 | if (p.getString(&pos, 'z', true) == "1.0") { |
261 | mail->mimeType = 1; | 261 | mail->mimeType = 1; |
262 | } | 262 | } |
263 | } | 263 | } |
264 | } | 264 | } |
265 | 265 | ||
266 | if (mail->mimeType == 1) { | 266 | if (mail->mimeType == 1) { |
267 | boundary = ""; | 267 | boundary = ""; |
268 | if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { | 268 | if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { |
269 | pos++; | 269 | pos++; |
270 | boundary = p.getString(&pos, 'z', true); | 270 | boundary = p.getString(&pos, 'z', true); |
271 | if (boundary[0] == '"') { | 271 | if (boundary[0] == '"') { |
272 | boundary = boundary.left(boundary.length() - 1); //strip " | 272 | boundary = boundary.left(boundary.length() - 1); //strip " |
273 | boundary = boundary.right(boundary.length() - 1); //strip " | 273 | boundary = boundary.right(boundary.length() - 1); //strip " |
274 | } | 274 | } |
275 | boundary = "--" + boundary; //create boundary field | 275 | boundary = "--" + boundary; //create boundary field |
276 | } | 276 | } |
277 | 277 | ||
278 | if (boundary == "") { //fooled by Mime-Version | 278 | if (boundary == "") { //fooled by Mime-Version |
279 | mail->body = body; | 279 | mail->body = body; |
280 | mail->bodyPlain = body; | 280 | mail->bodyPlain = body; |
281 | return mail; | 281 | return mail; |
282 | } | 282 | } |
283 | 283 | ||
284 | while (body.length() > 0) { | 284 | while (body.length() > 0) { |
285 | pos = body.find(boundary, 0, FALSE); | 285 | pos = body.find(boundary, 0, FALSE); |
286 | pos = body.find(delimiter, pos, FALSE); | 286 | pos = body.find(delimiter, pos, FALSE); |
287 | mimeHeader = body.left(pos); | 287 | mimeHeader = body.left(pos); |
288 | mimeBody = body.right(body.length() - pos - delimiter.length()); | 288 | mimeBody = body.right(body.length() - pos - delimiter.length()); |
289 | TextParser bp(mimeHeader, lineShift); | 289 | TextParser bp(mimeHeader, lineShift); |
290 | 290 | ||
291 | contentType = ""; | 291 | contentType = ""; |
292 | contentAttribute = ""; | 292 | contentAttribute = ""; |
293 | fileName = ""; | 293 | fileName = ""; |
294 | if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) { | 294 | if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) { |
295 | pos++; | 295 | pos++; |
296 | if ( (bp.wordAt(pos).upper() == "TYPE") && | 296 | if ( (bp.wordAt(pos).upper() == "TYPE") && |
297 | (bp.separatorAt(pos) == ':') ) { | 297 | (bp.separatorAt(pos) == ':') ) { |
298 | contentType = bp.nextWord().upper(); | 298 | contentType = bp.nextWord().upper(); |
299 | if (bp.nextSeparator() == '/') | 299 | if (bp.nextSeparator() == '/') |
300 | contentAttribute = bp.nextWord().upper(); | 300 | contentAttribute = bp.nextWord().upper(); |
301 | content = contentType + "/" + contentAttribute; | 301 | content = contentType + "/" + contentAttribute; |
302 | } | 302 | } |
303 | if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) { | 303 | if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) { |
304 | pos++; | 304 | pos++; |
305 | encoding = bp.getString(&pos, 'z', TRUE); | 305 | encoding = bp.getString(&pos, 'z', TRUE); |
306 | } | 306 | } |
307 | 307 | ||
308 | if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) { | 308 | if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) { |
309 | pos++; | 309 | pos++; |
310 | fileName = bp.getString(&pos, 'z', TRUE); | 310 | fileName = bp.getString(&pos, 'z', TRUE); |
311 | fileName = fileName.right(fileName.length() - 1); | 311 | fileName = fileName.right(fileName.length() - 1); |
312 | fileName = fileName.left(fileName.length() - 1); | 312 | fileName = fileName.left(fileName.length() - 1); |
313 | } | 313 | } |
314 | 314 | ||
315 | } | 315 | } |
316 | pos = mimeBody.find(boundary, 0, FALSE); | 316 | pos = mimeBody.find(boundary, 0, FALSE); |
317 | if (pos == -1) //should not occur, malformed mail | 317 | if (pos == -1) //should not occur, malformed mail |
318 | pos = mimeBody.length(); | 318 | pos = mimeBody.length(); |
319 | body = mimeBody.right(mimeBody.length() - pos); | 319 | body = mimeBody.right(mimeBody.length() - pos); |
320 | mimeBody = mimeBody.left(pos); | 320 | mimeBody = mimeBody.left(pos); |
321 | 321 | ||
322 | if (fileName != "") { //attatchments of some type, audio, image etc. | 322 | if (fileName != "") { //attatchments of some type, audio, image etc. |
323 | 323 | ||
324 | Enclosure e; | 324 | Enclosure e; |
325 | e.id = enclosureId; | 325 | e.id = enclosureId; |
326 | e.originalName = fileName; | 326 | e.originalName = fileName; |
327 | e.contentType = contentType; | 327 | e.contentType = contentType; |
328 | e.contentAttribute = contentAttribute; | 328 | e.contentAttribute = contentAttribute; |
329 | e.encoding = encoding; | 329 | e.encoding = encoding; |
330 | e.body = mimeBody; | 330 | e.body = mimeBody; |
331 | e.saved = FALSE; | 331 | e.saved = FALSE; |
332 | mail->addEnclosure(&e); | 332 | mail->addEnclosure(&e); |
333 | enclosureId++; | 333 | enclosureId++; |
334 | 334 | ||
335 | } else if (contentType == "TEXT") { | 335 | } else if (contentType == "TEXT") { |
336 | if (contentAttribute == "PLAIN") { | 336 | if (contentAttribute == "PLAIN") { |
337 | mail->body = mimeBody; | 337 | mail->body = mimeBody; |
338 | mail->bodyPlain = mimeBody; | 338 | mail->bodyPlain = mimeBody; |
339 | } | 339 | } |
340 | if (contentAttribute == "HTML") { | 340 | if (contentAttribute == "HTML") { |
341 | mail->body = mimeBody; | 341 | mail->body = mimeBody; |
342 | } | 342 | } |
343 | } | 343 | } |
344 | } | 344 | } |
345 | } else { | 345 | } else { |
346 | mail->bodyPlain = body; | 346 | mail->bodyPlain = body; |
347 | mail->body = body; | 347 | mail->body = body; |
348 | } | 348 | } |
349 | return TRUE; | 349 | return TRUE; |
350 | } | 350 | } |
351 | 351 | ||
352 | bool EmailHandler::getEnclosure(Enclosure *ePtr) | 352 | bool EmailHandler::getEnclosure(Enclosure *ePtr) |
353 | { | 353 | { |
354 | QFile f(ePtr->path + ePtr->name); | 354 | QFile f(ePtr->path + ePtr->name); |
355 | char src[4]; | 355 | char src[4]; |
356 | char *destPtr; | 356 | char *destPtr; |
357 | QByteArray buffer; | 357 | QByteArray buffer; |
358 | uint bufCount, pos, decodedCount, size, x; | 358 | uint bufCount, pos, decodedCount, size, x; |
359 | 359 | ||
360 | if (! f.open(IO_WriteOnly) ) { | 360 | if (! f.open(IO_WriteOnly) ) { |
361 | qWarning("could not save: " + ePtr->path + ePtr->name); | 361 | qWarning("could not save: " + ePtr->path + ePtr->name); |
362 | return FALSE; | 362 | return FALSE; |
363 | } | 363 | } |
364 | 364 | ||
365 | if (ePtr->encoding.upper() == "BASE64") { | 365 | if (ePtr->encoding.upper() == "BASE64") { |
366 | size = (ePtr->body.length() * 3 / 4); //approximate size (always above) | 366 | size = (ePtr->body.length() * 3 / 4); //approximate size (always above) |
367 | buffer.resize(size); | 367 | buffer.resize(size); |
368 | bufCount = 0; | 368 | bufCount = 0; |
369 | pos = 0; | 369 | pos = 0; |
370 | destPtr = buffer.data(); | 370 | destPtr = buffer.data(); |
371 | 371 | ||
372 | while (pos < ePtr->body.length()) { | 372 | while (pos < ePtr->body.length()) { |
373 | decodedCount = 4; | 373 | decodedCount = 4; |
374 | x = 0; | 374 | x = 0; |
375 | while ( (x < 4) && (pos < ePtr->body.length()) ) { | 375 | while ( (x < 4) && (pos < ePtr->body.length()) ) { |
376 | src[x] = ePtr->body[pos].latin1(); | 376 | src[x] = ePtr->body[pos].latin1(); |
377 | pos++; | 377 | pos++; |
378 | if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ') | 378 | if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ') |
379 | x--; | 379 | x--; |
380 | x++; | 380 | x++; |
381 | } | 381 | } |
382 | if (x > 1) { | 382 | if (x > 1) { |
383 | decodedCount = parse64base(src, destPtr); | 383 | decodedCount = parse64base(src, destPtr); |
384 | destPtr += decodedCount; | 384 | destPtr += decodedCount; |
385 | bufCount += decodedCount; | 385 | bufCount += decodedCount; |
386 | } | 386 | } |
387 | } | 387 | } |
388 | 388 | ||
389 | buffer.resize(bufCount); //set correct length of file | 389 | buffer.resize(bufCount); //set correct length of file |
390 | f.writeBlock(buffer); | 390 | f.writeBlock(buffer); |
391 | } else { | 391 | } else { |
392 | QTextStream t(&f); | 392 | QTextStream t(&f); |
393 | t << ePtr->body; | 393 | t << ePtr->body; |
394 | } | 394 | } |
395 | return TRUE; | 395 | return TRUE; |
396 | } | 396 | } |
397 | 397 | ||
398 | int EmailHandler::parse64base(char *src, char *bufOut) { | 398 | int EmailHandler::parse64base(char *src, char *bufOut) { |
399 | 399 | ||
400 | char c, z; | 400 | char c, z; |
401 | char li[4]; | 401 | char li[4]; |
402 | int processed; | 402 | int processed; |
403 | 403 | ||
404 | //conversion table withouth table... | 404 | //conversion table withouth table... |
405 | for (int x = 0; x < 4; x++) { | 405 | for (int x = 0; x < 4; x++) { |
406 | c = src[x]; | 406 | c = src[x]; |
407 | 407 | ||
408 | if ( (int) c >= 'A' && (int) c <= 'Z') | 408 | if ( (int) c >= 'A' && (int) c <= 'Z') |
409 | li[x] = (int) c - (int) 'A'; | 409 | li[x] = (int) c - (int) 'A'; |
410 | if ( (int) c >= 'a' && (int) c <= 'z') | 410 | if ( (int) c >= 'a' && (int) c <= 'z') |
411 | li[x] = (int) c - (int) 'a' + 26; | 411 | li[x] = (int) c - (int) 'a' + 26; |
412 | if ( (int) c >= '0' && (int) c <= '9') | 412 | if ( (int) c >= '0' && (int) c <= '9') |
413 | li[x] = (int) c - (int) '0' + 52; | 413 | li[x] = (int) c - (int) '0' + 52; |
414 | if (c == '+') | 414 | if (c == '+') |
415 | li[x] = 62; | 415 | li[x] = 62; |
416 | if (c == '/') | 416 | if (c == '/') |
417 | li[x] = 63; | 417 | li[x] = 63; |
418 | } | 418 | } |
419 | 419 | ||
420 | processed = 1; | 420 | processed = 1; |
421 | bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits | 421 | bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits |
422 | bufOut[0] <<= 2; | 422 | bufOut[0] <<= 2; |
423 | z = li[1] >> 4; | 423 | z = li[1] >> 4; |
424 | bufOut[0] = bufOut[0] | z; //first byte retrived | 424 | bufOut[0] = bufOut[0] | z; //first byte retrived |
425 | 425 | ||
426 | if (src[2] != '=') { | 426 | if (src[2] != '=') { |
427 | bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits | 427 | bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits |
428 | bufOut[1] <<= 4; | 428 | bufOut[1] <<= 4; |
429 | z = li[2] >> 2; | 429 | z = li[2] >> 2; |
430 | bufOut[1] = bufOut[1] | z; //second byte retrived | 430 | bufOut[1] = bufOut[1] | z; //second byte retrived |
431 | processed++; | 431 | processed++; |
432 | 432 | ||
433 | if (src[3] != '=') { | 433 | if (src[3] != '=') { |
434 | bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits | 434 | bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits |
435 | bufOut[2] <<= 6; | 435 | bufOut[2] <<= 6; |
436 | z = li[3]; | 436 | z = li[3]; |
437 | bufOut[2] = bufOut[2] | z; //third byte retrieved | 437 | bufOut[2] = bufOut[2] | z; //third byte retrieved |
438 | processed++; | 438 | processed++; |
439 | } | 439 | } |
440 | } | 440 | } |
441 | return processed; | 441 | return processed; |
442 | } | 442 | } |
443 | 443 | ||
444 | int EmailHandler::encodeMime(Email *mail) | 444 | int EmailHandler::encodeMime(Email *mail) |
445 | { | 445 | { |
446 | 446 | ||
447 | QString fileName, fileType, contentType, newBody, boundary; | 447 | QString fileName, fileType, contentType, newBody, boundary; |
448 | Enclosure *ePtr; | 448 | Enclosure *ePtr; |
449 | 449 | ||
450 | QString userName = mailAccount.name; | 450 | QString userName = mailAccount.name; |
451 | if (userName.length()>0)//only embrace it if there is a user name | 451 | if (userName.length()>0)//only embrace it if there is a user name |
452 | userName += " <" + mailAccount.emailAddress + ">"; | 452 | userName += " <" + mailAccount.emailAddress + ">"; |
453 | 453 | ||
454 | //add standard headers | 454 | //add standard headers |
455 | newBody = "From: " + userName + "\r\nTo: "; | 455 | newBody = "From: " + userName + "\r\nTo: "; |
456 | for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) { | 456 | for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) { |
457 | newBody += *it + " "; | 457 | newBody += *it + " "; |
458 | } | 458 | } |
459 | 459 | ||
460 | newBody += "\r\nCC: "; | 460 | newBody += "\r\nCC: "; |
461 | 461 | ||
462 | for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) { | 462 | for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) { |
463 | newBody += *it + " "; | 463 | newBody += *it + " "; |
464 | } | 464 | } |
465 | 465 | ||
466 | newBody += "\r\nSubject: " + mail->subject + "\r\n"; | 466 | newBody += "\r\nSubject: " + mail->subject + "\r\n"; |
467 | 467 | ||
468 | if (mail->files.count() == 0) { //just a simple mail | 468 | if (mail->files.count() == 0) { //just a simple mail |
469 | newBody += "\r\n" + mail->body; | 469 | newBody += "\r\n" + mail->body; |
470 | mail->rawMail = newBody; | 470 | mail->rawMail = newBody; |
471 | return 0; | 471 | return 0; |
472 | } | 472 | } |
473 | 473 | ||
474 | //Build mime encoded mail | 474 | //Build mime encoded mail |
475 | boundary = "-----4345=next_bound=0495----"; | 475 | boundary = "-----4345=next_bound=0495----"; |
476 | 476 | ||
477 | newBody += "Mime-Version: 1.0\r\n"; | 477 | newBody += "Mime-Version: 1.0\r\n"; |
478 | newBody += "Content-Type: multipart/mixed; boundary=\"" + | 478 | newBody += "Content-Type: multipart/mixed; boundary=\"" + |
479 | boundary + "\"\r\n\r\n"; | 479 | boundary + "\"\r\n\r\n"; |
480 | 480 | ||
481 | newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n"; | 481 | 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"; | 482 | newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n"; |
483 | newBody += mail->body; | 483 | newBody += mail->body; |
484 | 484 | ||
485 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { | 485 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { |
486 | fileName = ePtr->originalName; | 486 | fileName = ePtr->originalName; |
487 | fileType = ePtr->contentType; | 487 | fileType = ePtr->contentType; |
488 | QFileInfo fi(fileName); | 488 | QFileInfo fi(fileName); |
489 | 489 | ||
490 | // This specification of contentType is temporary | 490 | // This specification of contentType is temporary |
491 | contentType = ""; | 491 | contentType = ""; |
492 | if (fileType == "Picture") { | 492 | if (fileType == "Picture") { |
493 | contentType = "image/x-image"; | 493 | contentType = "image/x-image"; |
494 | } else if (fileType == "Document") { | 494 | } else if (fileType == "Document") { |
495 | contentType = "text/plain"; | 495 | contentType = "text/plain"; |
496 | } else if (fileType == "Sound") { | 496 | } else if (fileType == "Sound") { |
497 | contentType = "audio/x-wav"; | 497 | contentType = "audio/x-wav"; |
498 | } else if (fileType == "Movie") { | 498 | } else if (fileType == "Movie") { |
499 | contentType = "video/mpeg"; | 499 | contentType = "video/mpeg"; |
500 | } else { | 500 | } else { |
501 | contentType = "application/octet-stream"; | 501 | contentType = "application/octet-stream"; |
502 | } | 502 | } |
503 | 503 | ||
504 | newBody += "\r\n\r\n--" + boundary + "\r\n"; | 504 | newBody += "\r\n\r\n--" + boundary + "\r\n"; |
505 | newBody += "Content-Type: " + contentType + "; name=\"" + | 505 | newBody += "Content-Type: " + contentType + "; name=\"" + |
506 | fi.fileName() + "\"\r\n"; | 506 | fi.fileName() + "\"\r\n"; |
507 | newBody += "Content-Transfer-Encoding: base64\r\n"; | 507 | newBody += "Content-Transfer-Encoding: base64\r\n"; |
508 | newBody += "Content-Disposition: inline; filename=\"" + | 508 | newBody += "Content-Disposition: inline; filename=\"" + |
509 | fi.fileName() + "\"\r\n\r\n"; | 509 | fi.fileName() + "\"\r\n\r\n"; |
510 | 510 | ||
511 | if (encodeFile(fileName, &newBody) == -1) //file not found? | 511 | if (encodeFile(fileName, &newBody) == -1) //file not found? |
512 | return -1; | 512 | return -1; |
513 | } | 513 | } |
514 | 514 | ||
515 | newBody += "\r\n\r\n--" + boundary + "--"; | 515 | newBody += "\r\n\r\n--" + boundary + "--"; |
516 | mail->rawMail = newBody; | 516 | mail->rawMail = newBody; |
517 | 517 | ||
518 | return 0; | 518 | return 0; |
519 | } | 519 | } |
520 | 520 | ||
521 | int EmailHandler::encodeFile(QString fileName, QString *toBody) | 521 | int EmailHandler::encodeFile(QString fileName, QString *toBody) |
522 | { | 522 | { |
523 | char *fileData; | 523 | char *fileData; |
524 | char *dataPtr; | 524 | char *dataPtr; |
525 | QString temp; | 525 | QString temp; |
526 | uint dataSize, count; | 526 | uint dataSize, count; |
527 | QFile f(fileName); | 527 | QFile f(fileName); |
528 | 528 | ||
529 | if (! f.open(IO_ReadOnly) ) { | 529 | if (! f.open(IO_ReadOnly) ) { |
530 | qWarning("could not open file: " + fileName); | 530 | qWarning("could not open file: " + fileName); |
531 | return -1; | 531 | return -1; |
532 | } | 532 | } |
533 | QTextStream s(&f); | 533 | QTextStream s(&f); |
534 | dataSize = f.size(); | 534 | dataSize = f.size(); |
535 | fileData = (char *) malloc(dataSize + 3); | 535 | fileData = (char *) malloc(dataSize + 3); |
536 | s.readRawBytes(fileData, dataSize); | 536 | s.readRawBytes(fileData, dataSize); |
537 | 537 | ||
538 | temp = ""; | 538 | temp = ""; |
539 | dataPtr = fileData; | 539 | dataPtr = fileData; |
540 | count = 0; | 540 | count = 0; |
541 | while (dataSize > 0) { | 541 | while (dataSize > 0) { |
542 | if (dataSize < 3) { | 542 | if (dataSize < 3) { |
543 | encode64base(dataPtr, &temp, dataSize); | 543 | encode64base(dataPtr, &temp, dataSize); |
544 | dataSize = 0; | 544 | dataSize = 0; |
545 | } else { | 545 | } else { |
546 | encode64base(dataPtr, &temp, 3); | 546 | encode64base(dataPtr, &temp, 3); |
547 | dataSize -= 3; | 547 | dataSize -= 3; |
548 | dataPtr += 3; | 548 | dataPtr += 3; |
549 | count += 4; | 549 | count += 4; |
550 | } | 550 | } |
551 | if (count > 72) { | 551 | if (count > 72) { |
552 | count = 0; | 552 | count = 0; |
553 | temp += "\r\n"; | 553 | temp += "\r\n"; |
554 | } | 554 | } |
555 | } | 555 | } |
556 | toBody->append(temp); | 556 | toBody->append(temp); |
557 | 557 | ||
558 | delete(fileData); | 558 | delete(fileData); |
559 | f.close(); | 559 | f.close(); |
560 | return 0; | 560 | return 0; |
561 | } | 561 | } |
562 | 562 | ||
563 | void EmailHandler::encode64base(char *src, QString *dest, int len) | 563 | void EmailHandler::encode64base(char *src, QString *dest, int len) |
564 | { | 564 | { |
565 | QString temp; | 565 | QString temp; |
566 | uchar c; | 566 | uchar c; |
567 | uchar bufOut[4]; | 567 | uchar bufOut[4]; |
568 | 568 | ||
569 | bufOut[0] = src[0]; | 569 | bufOut[0] = src[0]; |
570 | bufOut[0] >>= 2; //Done byte 0 | 570 | bufOut[0] >>= 2; //Done byte 0 |
571 | 571 | ||
572 | bufOut[1] = src[0]; | 572 | bufOut[1] = src[0]; |
573 | bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits | 573 | bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits |
574 | bufOut[1] <<= 4; //copy up 4 places | 574 | bufOut[1] <<= 4; //copy up 4 places |
575 | if (len > 1) { | 575 | if (len > 1) { |
576 | c = src[1]; | 576 | c = src[1]; |
577 | } else { | 577 | } else { |
578 | c = 0; | 578 | c = 0; |
579 | } | 579 | } |
580 | 580 | ||
581 | c = c & (16 + 32 + 64 + 128); | 581 | c = c & (16 + 32 + 64 + 128); |
582 | c >>= 4; | 582 | c >>= 4; |
583 | bufOut[1] = bufOut[1] | c; //Done byte 1 | 583 | bufOut[1] = bufOut[1] | c; //Done byte 1 |
584 | 584 | ||
585 | bufOut[2] = src[1]; | 585 | bufOut[2] = src[1]; |
586 | bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8); | 586 | bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8); |
587 | bufOut[2] <<= 2; | 587 | bufOut[2] <<= 2; |
588 | if (len > 2) { | 588 | if (len > 2) { |
589 | c = src[2]; | 589 | c = src[2]; |
590 | } else { | 590 | } else { |
591 | c = 0; | 591 | c = 0; |
592 | } | 592 | } |
593 | c >>= 6; | 593 | c >>= 6; |
594 | bufOut[2] = bufOut[2] | c; | 594 | bufOut[2] = bufOut[2] | c; |
595 | 595 | ||
596 | bufOut[3] = src[2]; | 596 | bufOut[3] = src[2]; |
597 | bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32); | 597 | bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32); |
598 | 598 | ||
599 | if (len == 1) { | 599 | if (len == 1) { |
600 | bufOut[2] = 64; | 600 | bufOut[2] = 64; |
601 | bufOut[3] = 64; | 601 | bufOut[3] = 64; |
602 | } | 602 | } |
603 | if (len == 2) { | 603 | if (len == 2) { |
604 | bufOut[3] = 64; | 604 | bufOut[3] = 64; |
605 | } | 605 | } |
606 | for (int x = 0; x < 4; x++) { | 606 | for (int x = 0; x < 4; x++) { |
607 | if (bufOut[x] <= 25) | 607 | if (bufOut[x] <= 25) |
608 | bufOut[x] += (uint) 'A'; | 608 | bufOut[x] += (uint) 'A'; |
609 | else if (bufOut[x] >= 26 && bufOut[x] <= 51) | 609 | else if (bufOut[x] >= 26 && bufOut[x] <= 51) |
610 | bufOut[x] += (uint) 'a' - 26; | 610 | bufOut[x] += (uint) 'a' - 26; |
611 | else if (bufOut[x] >= 52 && bufOut[x] <= 61) | 611 | else if (bufOut[x] >= 52 && bufOut[x] <= 61) |
612 | bufOut[x] += (uint) '0' - 52; | 612 | bufOut[x] += (uint) '0' - 52; |
613 | else if (bufOut[x] == 62) | 613 | else if (bufOut[x] == 62) |
614 | bufOut[x] = '+'; | 614 | bufOut[x] = '+'; |
615 | else if (bufOut[x] == 63) | 615 | else if (bufOut[x] == 63) |
616 | bufOut[x] = '/'; | 616 | bufOut[x] = '/'; |
617 | else if (bufOut[x] == 64) | 617 | else if (bufOut[x] == 64) |
618 | bufOut[x] = '='; | 618 | bufOut[x] = '='; |
619 | 619 | ||
620 | dest->append(bufOut[x]); | 620 | dest->append(bufOut[x]); |
621 | } | 621 | } |
622 | } | 622 | } |
623 | 623 | ||
624 | void EmailHandler::cancel() | 624 | void EmailHandler::cancel() |
625 | { | 625 | { |
626 | popClient->errorHandling(ErrCancel); | 626 | popClient->errorHandling(ErrCancel); |
627 | smtpClient->errorHandling(ErrCancel); | 627 | smtpClient->errorHandling(ErrCancel); |
628 | } | 628 | } |
diff --git a/noncore/unsupported/mailit/emailhandler.h b/noncore/unsupported/mailit/emailhandler.h index e47fd9a..b645868 100644 --- a/noncore/unsupported/mailit/emailhandler.h +++ b/noncore/unsupported/mailit/emailhandler.h | |||
@@ -1,148 +1,149 @@ | |||
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 | 31 | ||
32 | #include "smtpclient.h" | 32 | #include "smtpclient.h" |
33 | #include "popclient.h" | 33 | #include "popclient.h" |
34 | #include "textparser.h" | 34 | #include "textparser.h" |
35 | #include "maillist.h" | 35 | #include "maillist.h" |
36 | 36 | ||
37 | struct Enclosure | 37 | struct Enclosure |
38 | { | 38 | { |
39 | int id; | 39 | int id; |
40 | QString originalName; | 40 | QString originalName; |
41 | QString name; | 41 | QString name; |
42 | QString path; | 42 | QString path; |
43 | QString contentType; | 43 | QString contentType; |
44 | QString contentAttribute; | 44 | QString contentAttribute; |
45 | QString encoding; | 45 | QString encoding; |
46 | QString body; //might use to much mem. check!! | 46 | QString body; //might use to much mem. check!! |
47 | bool saved, installed; | 47 | bool saved, installed; |
48 | }; | 48 | }; |
49 | 49 | ||
50 | class EnclosureList : public QList<Enclosure> | 50 | class EnclosureList : public QList<Enclosure> |
51 | { | 51 | { |
52 | public: | 52 | public: |
53 | Item newItem(Item d); | 53 | Item newItem(Item d); |
54 | private: | 54 | private: |
55 | Enclosure* dupl(Enclosure *in); | 55 | Enclosure* dupl(Enclosure *in); |
56 | Enclosure *ac; | 56 | Enclosure *ac; |
57 | }; | 57 | }; |
58 | 58 | ||
59 | struct Email | 59 | struct Email |
60 | { | 60 | { |
61 | QString id; | 61 | QString id; |
62 | QString from; | 62 | QString from; |
63 | QString fromMail; | 63 | QString fromMail; |
64 | QStringList recipients; | 64 | QStringList recipients; |
65 | QStringList carbonCopies; | 65 | QStringList carbonCopies; |
66 | QString date; | 66 | QString date; |
67 | QString subject; | 67 | QString subject; |
68 | QString body; | 68 | QString body; |
69 | QString bodyPlain; | 69 | QString bodyPlain; |
70 | bool sent, received, read, downloaded; | 70 | bool sent, received, read, downloaded; |
71 | QString rawMail; | 71 | QString rawMail; |
72 | int mimeType; //1 = Mime 1.0 | 72 | int mimeType; //1 = Mime 1.0 |
73 | int serverId; | 73 | int serverId; |
74 | int internalId; | 74 | int internalId; |
75 | int fromAccountId; | 75 | int fromAccountId; |
76 | QString contentType; //0 = text | 76 | QString contentType; //0 = text |
77 | QString contentAttribute; //0 = plain, 1 = html | 77 | QString contentAttribute; //0 = plain, 1 = html |
78 | EnclosureList files; | 78 | EnclosureList files; |
79 | uint size; | 79 | uint size; |
80 | 80 | ||
81 | void addEnclosure(Enclosure *e) | 81 | void addEnclosure(Enclosure *e) |
82 | { | 82 | { |
83 | files.append(e); | 83 | files.append(e); |
84 | } | 84 | } |
85 | }; | 85 | }; |
86 | 86 | ||
87 | struct MailAccount | 87 | struct MailAccount |
88 | { | 88 | { |
89 | QString accountName; | 89 | QString accountName; |
90 | QString name; | 90 | QString name; |
91 | QString emailAddress; | 91 | QString emailAddress; |
92 | QString popUserName; | 92 | QString popUserName; |
93 | QString popPasswd; | 93 | QString popPasswd; |
94 | QString popServer; | 94 | QString popServer; |
95 | QString smtpServer; | 95 | QString smtpServer; |
96 | bool synchronize; | 96 | bool synchronize; |
97 | int syncLimit; | 97 | int syncLimit; |
98 | int lastServerMailCount; | 98 | int lastServerMailCount; |
99 | int id; | 99 | int id; |
100 | }; | 100 | }; |
101 | 101 | ||
102 | const int ErrUnknownResponse = 1001; | 102 | const int ErrUnknownResponse = 1001; |
103 | const int ErrLoginFailed = 1002; | 103 | const int ErrLoginFailed = 1002; |
104 | const int ErrCancel = 1003; | 104 | const int ErrCancel = 1003; |
105 | 105 | ||
106 | 106 | ||
107 | class EmailHandler : public QObject | 107 | class EmailHandler : public QObject |
108 | { | 108 | { |
109 | Q_OBJECT | 109 | Q_OBJECT |
110 | 110 | ||
111 | public: | 111 | public: |
112 | EmailHandler(); | 112 | EmailHandler(); |
113 | void setAccount(MailAccount account); | 113 | void setAccount(MailAccount account); |
114 | MailAccount* getAccount(){return &mailAccount;} | ||
114 | void sendMail(QList<Email> *mailList); | 115 | void sendMail(QList<Email> *mailList); |
115 | void getMail(); | 116 | void getMail(); |
116 | void getMailHeaders(); | 117 | void getMailHeaders(); |
117 | void getMailByList(MailList *mailList); | 118 | void getMailByList(MailList *mailList); |
118 | bool parse(QString in, QString lineShift, Email *mail); | 119 | bool parse(QString in, QString lineShift, Email *mail); |
119 | bool getEnclosure(Enclosure *ePtr); | 120 | bool getEnclosure(Enclosure *ePtr); |
120 | int parse64base(char *src, char *dest); | 121 | int parse64base(char *src, char *dest); |
121 | int encodeMime(Email *mail); | 122 | int encodeMime(Email *mail); |
122 | int encodeFile(QString fileName, QString *toBody); | 123 | int encodeFile(QString fileName, QString *toBody); |
123 | void encode64base(char *src, QString *dest, int len); | 124 | void encode64base(char *src, QString *dest, int len); |
124 | void cancel(); | 125 | void cancel(); |
125 | 126 | ||
126 | signals: | 127 | signals: |
127 | void mailSent(); | 128 | void mailSent(); |
128 | void smtpError(int); | 129 | void smtpError(int); |
129 | void popError(int); | 130 | void popError(int); |
130 | void mailArrived(const Email &, bool); | 131 | void mailArrived(const Email &, bool); |
131 | void updatePopStatus(const QString &); | 132 | void updatePopStatus(const QString &); |
132 | void updateSmtpStatus(const QString &); | 133 | void updateSmtpStatus(const QString &); |
133 | void mailTransfered(int); | 134 | void mailTransfered(int); |
134 | void mailboxSize(int); | 135 | void mailboxSize(int); |
135 | void currentMailSize(int); | 136 | void currentMailSize(int); |
136 | void downloadedSize(int); | 137 | void downloadedSize(int); |
137 | 138 | ||
138 | public slots: | 139 | public slots: |
139 | void messageArrived(const QString &, int id, uint size, bool complete); | 140 | void messageArrived(const QString &, int id, uint size, bool complete); |
140 | 141 | ||
141 | private: | 142 | private: |
142 | MailAccount mailAccount; | 143 | MailAccount mailAccount; |
143 | SmtpClient *smtpClient; | 144 | SmtpClient *smtpClient; |
144 | PopClient *popClient; | 145 | PopClient *popClient; |
145 | bool headers; | 146 | bool headers; |
146 | }; | 147 | }; |
147 | 148 | ||
148 | #endif | 149 | #endif |
diff --git a/noncore/unsupported/mailit/mailitwindow.cpp b/noncore/unsupported/mailit/mailitwindow.cpp index 7181adf..ffee67e 100644 --- a/noncore/unsupported/mailit/mailitwindow.cpp +++ b/noncore/unsupported/mailit/mailitwindow.cpp | |||
@@ -1,143 +1,165 @@ | |||
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 "mailitwindow.h" | 22 | #include "mailitwindow.h" |
22 | 23 | ||
23 | MailItWindow::MailItWindow(QWidget *parent, const char *name, WFlags fl) | 24 | MailItWindow::MailItWindow(QWidget *parent, const char *name, WFlags fl) |
24 | : QMainWindow(parent, name, WStyle_ContextHelp) | 25 | : QMainWindow(parent, name, WStyle_ContextHelp) |
25 | { | 26 | { |
26 | currentCaption = "Mailit"; | 27 | currentCaption = "Mailit"; |
27 | setCaption(tr(currentCaption)); | 28 | setCaption(tr(currentCaption)); |
28 | views = new QWidgetStack(this); | 29 | views = new QWidgetStack(this); |
29 | setCentralWidget(views); | 30 | setCentralWidget(views); |
30 | QWhatsThis::add(views,tr("Central view area")); | 31 | QWhatsThis::add(views,tr("Central view area")); |
31 | emailClient = new EmailClient(views, "client"); | 32 | emailClient = new EmailClient(views, "client"); |
32 | writeMail = new WriteMail(views, "writing"); | 33 | writeMail = new WriteMail(views, "writing"); |
33 | readMail = new ReadMail(views, "reading"); | 34 | readMail = new ReadMail(views, "reading"); |
34 | 35 | ||
35 | views->raiseWidget(emailClient); | 36 | views->raiseWidget(emailClient); |
36 | 37 | ||
37 | connect(emailClient, SIGNAL(composeRequested()), | 38 | connect(emailClient, SIGNAL(composeRequested()), |
38 | this, SLOT(compose()) ); | 39 | this, SLOT(compose()) ); |
39 | connect(emailClient, SIGNAL(viewEmail(QListView *, Email *)), this, | 40 | connect(emailClient, SIGNAL(viewEmail(QListView *, Email *)), this, |
40 | SLOT(viewMail(QListView *, Email *)) ); | 41 | SLOT(viewMail(QListView *, Email *)) ); |
41 | connect(emailClient, SIGNAL(mailUpdated(Email *)), this, | 42 | connect(emailClient, SIGNAL(mailUpdated(Email *)), this, |
42 | SLOT(updateMailView(Email *)) ); | 43 | SLOT(updateMailView(Email *)) ); |
43 | 44 | ||
44 | connect(writeMail, SIGNAL(cancelMail()), this, SLOT(showEmailClient()) ); | 45 | connect(writeMail, SIGNAL(cancelMail()), this, SLOT(showEmailClient()) ); |
45 | connect(writeMail, SIGNAL(sendMailRequested(const Email &)), this, | 46 | connect(writeMail, SIGNAL(sendMailRequested(const Email &)), this, |
46 | SLOT(showEmailClient()) ); | 47 | SLOT(showEmailClient()) ); |
47 | connect(writeMail, SIGNAL(sendMailRequested(const Email &)), emailClient, | 48 | connect(writeMail, SIGNAL(sendMailRequested(const Email &)), emailClient, |
48 | SLOT(enqueMail(const Email &)) ); | 49 | SLOT(enqueMail(const Email &)) ); |
49 | 50 | ||
50 | connect(readMail, SIGNAL(cancelView()), this, SLOT(showEmailClient()) ); | 51 | connect(readMail, SIGNAL(cancelView()), this, SLOT(showEmailClient()) ); |
51 | connect(readMail, SIGNAL(replyRequested(Email &, bool&)), this, | 52 | connect(readMail, SIGNAL(replyRequested(Email &, bool&)), this, |
52 | SLOT(composeReply(Email &, bool&)) ); | 53 | SLOT(composeReply(Email &, bool&)) ); |
53 | connect(readMail, SIGNAL(forwardRequested(Email &)), this, | 54 | connect(readMail, SIGNAL(forwardRequested(Email &)), this, |
54 | SLOT(composeForward(Email &)) ); | 55 | SLOT(composeForward(Email &)) ); |
55 | 56 | ||
56 | connect(readMail, SIGNAL(removeItem(EmailListItem *, bool &)), emailClient, | 57 | connect(readMail, SIGNAL(removeItem(EmailListItem *, bool &)), emailClient, |
57 | SLOT(deleteMail(EmailListItem *, bool &)) ); | 58 | SLOT(deleteMail(EmailListItem *, bool &)) ); |
58 | connect(readMail, SIGNAL(viewingMail(Email *)), emailClient, | 59 | connect(readMail, SIGNAL(viewingMail(Email *)), emailClient, |
59 | SLOT(moveMailFront(Email *)) ); | 60 | SLOT(moveMailFront(Email *)) ); |
60 | 61 | ||
61 | connect(emailClient, SIGNAL(newCaption(const QString &)), | 62 | connect(emailClient, SIGNAL(newCaption(const QString &)), |
62 | this, SLOT(updateCaption(const QString &)) ); | 63 | this, SLOT(updateCaption(const QString &)) ); |
63 | viewingMail = FALSE; | 64 | viewingMail = FALSE; |
64 | |||
65 | } | 65 | } |
66 | 66 | ||
67 | MailItWindow::~MailItWindow() | 67 | MailItWindow::~MailItWindow() |
68 | { | 68 | { |
69 | } | 69 | } |
70 | 70 | ||
71 | void MailItWindow::closeEvent(QCloseEvent *e) | 71 | void MailItWindow::closeEvent(QCloseEvent *e) |
72 | { | 72 | { |
73 | if (views->visibleWidget() == emailClient) { | 73 | if (views->visibleWidget() == emailClient) { |
74 | e->accept(); | 74 | e->accept(); |
75 | } else { | 75 | } else { |
76 | showEmailClient(); | 76 | showEmailClient(); |
77 | } | 77 | } |
78 | } | 78 | } |
79 | 79 | ||
80 | void MailItWindow::compose() | 80 | void MailItWindow::compose() |
81 | { | 81 | { |
82 | viewingMail = FALSE; | 82 | viewingMail = FALSE; |
83 | emailClient->hide(); | 83 | emailClient->hide(); |
84 | readMail->hide(); | 84 | readMail->hide(); |
85 | views->raiseWidget(writeMail); | 85 | views->raiseWidget(writeMail); |
86 | writeMail->setAddressList(emailClient->getAdrListRef()); | 86 | writeMail->setAddressList(emailClient->getAdrListRef()); |
87 | writeMail->newMail(); | ||
87 | setCaption( tr( "Write mail" ) ); | 88 | setCaption( tr( "Write mail" ) ); |
88 | } | 89 | } |
89 | 90 | ||
90 | void MailItWindow::composeReply(Email &mail, bool& replyAll) | 91 | void MailItWindow::composeReply(Email &mail, bool& replyAll) |
91 | { | 92 | { |
92 | compose(); | 93 | compose(); |
93 | writeMail->reply(mail,replyAll) ; | 94 | writeMail->reply(mail,replyAll) ; |
94 | } | 95 | } |
95 | 96 | ||
96 | void MailItWindow::composeForward(Email &mail) | 97 | void MailItWindow::composeForward(Email &mail) |
97 | { | 98 | { |
98 | compose(); | 99 | compose(); |
99 | writeMail->forward(mail) ; | 100 | writeMail->forward(mail) ; |
100 | } | 101 | } |
101 | 102 | ||
102 | 103 | ||
103 | void MailItWindow::showEmailClient() | 104 | void MailItWindow::showEmailClient() |
104 | { | 105 | { |
105 | viewingMail = FALSE; | 106 | viewingMail = FALSE; |
106 | writeMail->hide(); | 107 | writeMail->hide(); |
107 | readMail->hide(); | 108 | readMail->hide(); |
108 | views->raiseWidget(emailClient); | 109 | views->raiseWidget(emailClient); |
109 | setCaption( tr(currentCaption) ); | 110 | setCaption( tr(currentCaption) ); |
110 | } | 111 | } |
111 | 112 | ||
112 | void MailItWindow::viewMail(QListView *view, Email *mail) | 113 | void MailItWindow::viewMail(QListView *view, Email *mail) |
113 | { | 114 | { |
114 | viewingMail = TRUE; | 115 | viewingMail = TRUE; |
115 | emailClient->hide(); | 116 | emailClient->hide(); |
117 | |||
118 | int result=0; | ||
119 | |||
120 | if ((mail->received)&&(!mail->downloaded)) | ||
121 | { | ||
122 | QMessageBox mb( tr("Mail not downloaded"), | ||
123 | tr("The mail you have clicked \n" | ||
124 | "has not been downloaded yet.\n " | ||
125 | "Would you like to do it now ?"), | ||
126 | QMessageBox::Information, | ||
127 | QMessageBox::Yes | QMessageBox::Default, | ||
128 | QMessageBox::No | QMessageBox::Escape,0 ); | ||
129 | |||
130 | result=mb.exec(); | ||
131 | |||
132 | if (result==QMessageBox::Yes) | ||
133 | { | ||
134 | emailClient->download(mail); | ||
135 | } | ||
136 | } | ||
137 | |||
116 | readMail->update(view, mail); | 138 | readMail->update(view, mail); |
117 | views->raiseWidget(readMail); | 139 | views->raiseWidget(readMail); |
118 | setCaption( tr( "Examine mail" ) ); | 140 | setCaption( tr( "Examine mail" ) ); |
119 | } | 141 | } |
120 | 142 | ||
121 | void MailItWindow::updateMailView(Email *mail) | 143 | void MailItWindow::updateMailView(Email *mail) |
122 | { | 144 | { |
123 | if (viewingMail) { | 145 | if (viewingMail) { |
124 | readMail->mailUpdated(mail); | 146 | readMail->mailUpdated(mail); |
125 | } | 147 | } |
126 | } | 148 | } |
127 | 149 | ||
128 | void MailItWindow::updateCaption(const QString &newCaption) | 150 | void MailItWindow::updateCaption(const QString &newCaption) |
129 | { | 151 | { |
130 | currentCaption = newCaption; | 152 | currentCaption = newCaption; |
131 | setCaption(tr(currentCaption)); | 153 | setCaption(tr(currentCaption)); |
132 | } | 154 | } |
133 | 155 | ||
134 | void MailItWindow::setDocument(const QString &_address) | 156 | void MailItWindow::setDocument(const QString &_address) |
135 | { | 157 | { |
136 | // strip leading 'mailto:' | 158 | // strip leading 'mailto:' |
137 | QString address = _address; | 159 | QString address = _address; |
138 | if (address.startsWith("mailto:")) | 160 | if (address.startsWith("mailto:")) |
139 | address = address.mid(6); | 161 | address = address.mid(6); |
140 | 162 | ||
141 | compose(); | 163 | compose(); |
142 | writeMail->setRecipient(address); | 164 | writeMail->setRecipient(address); |
143 | } | 165 | } |
diff --git a/noncore/unsupported/mailit/popclient.cpp b/noncore/unsupported/mailit/popclient.cpp index 67306be..6105d09 100644 --- a/noncore/unsupported/mailit/popclient.cpp +++ b/noncore/unsupported/mailit/popclient.cpp | |||
@@ -1,367 +1,325 @@ | |||
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 | ||
24 | extern "C" { | 24 | extern "C" { |
25 | #include "md5.h" | 25 | #include "md5.h" |
26 | } | 26 | } |
27 | 27 | ||
28 | #include <qcstring.h> | 28 | #include <qcstring.h> |
29 | 29 | ||
30 | PopClient::PopClient() | 30 | PopClient::PopClient() |
31 | { | 31 | { |
32 | socket = new QSocket(this, "popClient"); | 32 | socket = new QSocket(this, "popClient"); |
33 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); | 33 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); |
34 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); | 34 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); |
35 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); | 35 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); |
36 | 36 | ||
37 | stream = new QTextStream(socket); | 37 | stream = new QTextStream(socket); |
38 | 38 | ||
39 | receiving = FALSE; | 39 | receiving = FALSE; |
40 | synchronize = FALSE; | 40 | synchronize = FALSE; |
41 | lastSync = 0; | 41 | lastSync = 0; |
42 | headerLimit = 0; | 42 | headerLimit = 0; |
43 | preview = FALSE; | 43 | preview = FALSE; |
44 | } | 44 | } |
45 | 45 | ||
46 | PopClient::~PopClient() | 46 | PopClient::~PopClient() |
47 | { | 47 | { |
48 | delete socket; | 48 | delete socket; |
49 | delete stream; | 49 | delete stream; |
50 | } | 50 | } |
51 | 51 | ||
52 | void PopClient::newConnection(QString target, int port) | 52 | void PopClient::newConnection(QString target, int port) |
53 | { | 53 | { |
54 | if (receiving) { | 54 | if (receiving) { |
55 | qWarning("socket in use, connection refused"); | 55 | qWarning("socket in use, connection refused"); |
56 | return; | 56 | return; |
57 | } | 57 | } |
58 | 58 | ||
59 | status = Init; | 59 | status = Init; |
60 | 60 | ||
61 | socket->connectToHost(target, port); | 61 | socket->connectToHost(target, port); |
62 | receiving = TRUE; | 62 | receiving = TRUE; |
63 | selected = FALSE; | 63 | //selected = FALSE; |
64 | 64 | ||
65 | emit updateStatus("DNS lookup"); | 65 | emit updateStatus("DNS lookup"); |
66 | } | 66 | } |
67 | 67 | ||
68 | void PopClient::setAccount(QString popUser, QString popPasswd) | 68 | void PopClient::setAccount(QString popUser, QString popPasswd) |
69 | { | 69 | { |
70 | popUserName = popUser; | 70 | popUserName = popUser; |
71 | popPassword = popPasswd; | 71 | popPassword = popPasswd; |
72 | } | 72 | } |
73 | 73 | ||
74 | void PopClient::setSynchronize(int lastCount) | 74 | void PopClient::setSynchronize(int lastCount) |
75 | { | 75 | { |
76 | synchronize = TRUE; | 76 | synchronize = TRUE; |
77 | lastSync = lastCount; | 77 | lastSync = lastCount; |
78 | } | 78 | } |
79 | 79 | ||
80 | void PopClient::removeSynchronize() | 80 | void PopClient::removeSynchronize() |
81 | { | 81 | { |
82 | synchronize = FALSE; | 82 | synchronize = FALSE; |
83 | lastSync = 0; | 83 | lastSync = 0; |
84 | } | 84 | } |
85 | 85 | ||
86 | void PopClient::headersOnly(bool headers, int limit) | 86 | void PopClient::headersOnly(bool headers, int limit) |
87 | { | 87 | { |
88 | preview = headers; | 88 | preview = headers; |
89 | headerLimit = limit; | 89 | headerLimit = limit; |
90 | } | 90 | } |
91 | 91 | ||
92 | void PopClient::setSelectedMails(MailList *list) | 92 | void PopClient::setSelectedMails(MailList *list) |
93 | { | 93 | { |
94 | selected = TRUE; | 94 | selected = TRUE; |
95 | mailList = list; | 95 | mailList = list; |
96 | } | 96 | } |
97 | 97 | ||
98 | void PopClient::connectionEstablished() | 98 | void PopClient::connectionEstablished() |
99 | { | 99 | { |
100 | emit updateStatus(tr("Connection established")); | 100 | emit updateStatus(tr("Connection established")); |
101 | } | 101 | } |
102 | 102 | ||
103 | void PopClient::errorHandling(int status) | 103 | void PopClient::errorHandling(int status) |
104 | { | 104 | { |
105 | emit updateStatus(tr("Error Occured")); | 105 | emit updateStatus(tr("Error Occured")); |
106 | emit errorOccurred(status); | 106 | emit errorOccurred(status); |
107 | socket->close(); | 107 | socket->close(); |
108 | receiving = FALSE; | 108 | receiving = FALSE; |
109 | } | 109 | } |
110 | 110 | ||
111 | void PopClient::incomingData() | 111 | void PopClient::incomingData() |
112 | { | 112 | { |
113 | QString response, temp, temp2, timeStamp; | 113 | QString response, temp, temp2, timeStamp; |
114 | QString md5Source; | 114 | QString md5Source; |
115 | int start, end; | 115 | int start, end; |
116 | // char *md5Digest; | 116 | // char *md5Digest; |
117 | char md5Digest[16]; | 117 | char md5Digest[16]; |
118 | // if ( !socket->canReadLine() ) | 118 | // if ( !socket->canReadLine() ) |
119 | // return; | 119 | // return; |
120 | 120 | ||
121 | response = socket->readLine(); | 121 | response = socket->readLine(); |
122 | 122 | ||
123 | switch(status) { | 123 | switch(status) { |
124 | //logging in | 124 | //logging in |
125 | case Init: { | 125 | case Init: { |
126 | #ifdef APOP_TEST | 126 | #ifdef APOP_TEST |
127 | start = response.find('<',0); | 127 | start = response.find('<',0); |
128 | end = response.find('>', start); | 128 | end = response.find('>', start); |
129 | if( start >= 0 && end > start ) | 129 | if( start >= 0 && end > start ) |
130 | { | 130 | { |
131 | timeStamp = response.mid( start , end - start + 1); | 131 | timeStamp = response.mid( start , end - start + 1); |
132 | md5Source = timeStamp + popPassword; | 132 | md5Source = timeStamp + popPassword; |
133 | 133 | ||
134 | md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); | 134 | md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); |
135 | 135 | ||
136 | for(int j =0;j < MD5_DIGEST_LENGTH ;j++) | 136 | for(int j =0;j < MD5_DIGEST_LENGTH ;j++) |
137 | { | 137 | { |
138 | printf("%x", md5Digest[j]); | 138 | printf("%x", md5Digest[j]); |
139 | } | 139 | } |
140 | printf("\n"); | 140 | printf("\n"); |
141 | // qDebug(md5Digest); | 141 | // qDebug(md5Digest); |
142 | *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; | 142 | *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; |
143 | // qDebug("%s", stream); | 143 | // qDebug("%s", stream); |
144 | status = Stat; | 144 | status = Stat; |
145 | } | 145 | } |
146 | else | 146 | else |
147 | #endif | 147 | #endif |
148 | { | 148 | { |
149 | timeStamp = ""; | 149 | timeStamp = ""; |
150 | *stream << "USER " << popUserName << "\r\n"; | 150 | *stream << "USER " << popUserName << "\r\n"; |
151 | status = Pass; | 151 | status = Pass; |
152 | } | 152 | } |
153 | 153 | ||
154 | break; | 154 | break; |
155 | } | 155 | } |
156 | 156 | ||
157 | case Pass: { | 157 | case Pass: { |
158 | *stream << "PASS " << popPassword << "\r\n"; | 158 | *stream << "PASS " << popPassword << "\r\n"; |
159 | status = Stat; | 159 | status = Stat; |
160 | break; | 160 | break; |
161 | } | 161 | } |
162 | //ask for number of messages | 162 | //ask for number of messages |
163 | case Stat: { | 163 | case Stat: { |
164 | if (response[0] == '+') { | 164 | if (response[0] == '+') { |
165 | *stream << "STAT" << "\r\n"; | 165 | *stream << "STAT" << "\r\n"; |
166 | status = Mcnt; | 166 | status = Mcnt; |
167 | } else errorHandling(ErrLoginFailed); | 167 | } else errorHandling(ErrLoginFailed); |
168 | break; | 168 | break; |
169 | } | 169 | } |
170 | //get count of messages, eg "+OK 4 900.." -> int 4 | 170 | //get count of messages, eg "+OK 4 900.." -> int 4 |
171 | case Mcnt: { | 171 | case Mcnt: { |
172 | if (response[0] == '+') { | 172 | if (response[0] == '+') { |
173 | temp = response.replace(0, 4, ""); | 173 | temp = response.replace(0, 4, ""); |
174 | int x = temp.find(" ", 0); | 174 | int x = temp.find(" ", 0); |
175 | temp.truncate((uint) x); | 175 | temp.truncate((uint) x); |
176 | newMessages = temp.toInt(); | 176 | newMessages = temp.toInt(); |
177 | messageCount = 1; | 177 | messageCount = 1; |
178 | status = List; | 178 | status = List; |
179 | 179 | ||
180 | if (synchronize) { | 180 | if (synchronize) { |
181 | //messages deleted from server, reload all | 181 | //messages deleted from server, reload all |
182 | if (newMessages < lastSync) | 182 | if (newMessages < lastSync) |
183 | lastSync = 0; | 183 | lastSync = 0; |
184 | messageCount = 1; | 184 | messageCount = 1; |
185 | } | 185 | } |
186 | 186 | ||
187 | if (selected) { | 187 | if (selected) { |
188 | int *ptr = mailList->first(); | 188 | int *ptr = mailList->first(); |
189 | if (ptr != 0) { | 189 | if (ptr != 0) { |
190 | newMessages++; //to ensure no early jumpout | 190 | newMessages++; //to ensure no early jumpout |
191 | messageCount = *(mailList->first()); | 191 | messageCount = *ptr; |
192 | } else newMessages = 0; | 192 | } else newMessages = 0; |
193 | } | 193 | } |
194 | |||
194 | } else errorHandling(ErrUnknownResponse); | 195 | } else errorHandling(ErrUnknownResponse); |
195 | } | 196 | } |
196 | //Read message number x, count upwards to messageCount | 197 | //Read message number x, count upwards to messageCount |
197 | case List: { | 198 | case List: { |
198 | if (messageCount <= newMessages) { | 199 | if (messageCount <= newMessages) { |
199 | *stream << "LIST " << messageCount << "\r\n"; | 200 | *stream << "LIST " << messageCount << "\r\n"; |
200 | status = Size; | 201 | status = Size; |
201 | temp2.setNum(newMessages - lastSync); | 202 | temp2.setNum(newMessages - lastSync); |
202 | temp.setNum(messageCount - lastSync); | 203 | temp.setNum(messageCount - lastSync); |
203 | if (!selected) { | 204 | if (!selected) { |
204 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); | 205 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); |
205 | } else { | 206 | } else { |
206 | //completing a previously closed transfer | 207 | //completing a previously closed transfer |
207 | if ( (messageCount - lastSync) <= 0) { | 208 | /* if ( (messageCount - lastSync) <= 0) { |
208 | temp.setNum(messageCount); | 209 | temp.setNum(messageCount); |
209 | emit updateStatus(tr("Previous message ") + temp); | 210 | emit updateStatus(tr("Previous message ") + temp); |
210 | } else { | 211 | } else {*/ |
211 | emit updateStatus(tr("Completing message ") + temp); | 212 | emit updateStatus(tr("Completing message ") + temp); |
212 | } | 213 | //} |
213 | } | 214 | } |
214 | break; | 215 | break; |
215 | } else { | 216 | } else { |
216 | emit updateStatus(tr("No new Messages")); | 217 | emit updateStatus(tr("No new Messages")); |
217 | status = Quit; | 218 | status = Quit; |
218 | } | 219 | } |
219 | } | 220 | } |
220 | //get size of message, eg "500 characters in message.." -> int 500 | 221 | //get size of message, eg "500 characters in message.." -> int 500 |
221 | case Size: { | 222 | case Size: { |
222 | if (status != Quit) { //because of idiotic switch | 223 | if (status != Quit) { //because of idiotic switch |
223 | if (response[0] == '+') { | 224 | if (response[0] == '+') { |
224 | temp = response.replace(0, 4, ""); | 225 | temp = response.replace(0, 4, ""); |
225 | int x = temp.find(" ", 0); | 226 | int x = temp.find(" ", 0); |
226 | temp = temp.right(temp.length() - ((uint) x + 1) ); | 227 | temp = temp.right(temp.length() - ((uint) x + 1) ); |
227 | mailSize = temp.toInt(); | 228 | mailSize = temp.toInt(); |
228 | emit currentMailSize(mailSize); | 229 | emit currentMailSize(mailSize); |
229 | 230 | ||
230 | status = Retr; | 231 | status = Retr; |
231 | } else { | 232 | } else { |
232 | //qWarning(response); | 233 | //qWarning(response); |
233 | errorHandling(ErrUnknownResponse); | 234 | errorHandling(ErrUnknownResponse); |
234 | } | 235 | } |
235 | } | 236 | } |
236 | } | 237 | } |
237 | //Read message number x, count upwards to messageCount | 238 | //Read message number x, count upwards to messageCount |
238 | case Retr: { | 239 | case Retr: { |
239 | if (status != Quit) { | 240 | if (status != Quit) { |
240 | if (mailSize <= headerLimit) | 241 | if ((selected)||(mailSize <= headerLimit)) |
241 | { | 242 | { |
242 | *stream << "RETR " << messageCount << "\r\n"; | 243 | *stream << "RETR " << messageCount << "\r\n"; |
243 | } else { //only header | 244 | } else { //only header |
244 | *stream << "TOP " << messageCount << " 0\r\n"; | 245 | *stream << "TOP " << messageCount << " 0\r\n"; |
245 | } | 246 | } |
246 | messageCount++; | 247 | messageCount++; |
247 | status = Ignore; | 248 | status = Ignore; |
248 | break; | 249 | break; |
249 | } } | 250 | } } |
250 | case Ignore: { | 251 | case Ignore: { |
251 | if (status != Quit) { //because of idiotic switch | 252 | if (status != Quit) { //because of idiotic switch |
252 | if (response[0] == '+') { | 253 | if (response[0] == '+') { |
253 | message = ""; | 254 | message = ""; |
254 | status = Read; | 255 | status = Read; |
255 | if (!socket->canReadLine()) //sync. problems | 256 | if (!socket->canReadLine()) //sync. problems |
256 | break; | 257 | break; |
257 | response = socket->readLine(); | 258 | response = socket->readLine(); |
258 | } else errorHandling(ErrUnknownResponse); | 259 | } else errorHandling(ErrUnknownResponse); |
259 | } | 260 | } |
260 | } | 261 | } |
261 | //add all incoming lines to body. When size is reached, send | 262 | //add all incoming lines to body. When size is reached, send |
262 | //message, and go back to read new message | 263 | //message, and go back to read new message |
263 | case Read: { | 264 | case Read: { |
264 | if (status != Quit) { //because of idiotic switch | 265 | if (status != Quit) { //because of idiotic switch |
265 | message += response; | 266 | message += response; |
266 | while ( socket->canReadLine() ) { | 267 | while ( socket->canReadLine() ) { |
267 | response = socket->readLine(); | 268 | response = socket->readLine(); |
268 | message += response; | 269 | message += response; |
269 | } | 270 | } |
270 | emit downloadedSize(message.length()); | 271 | emit downloadedSize(message.length()); |
271 | int x = message.find("\r\n.\r\n",-5); | 272 | int x = message.find("\r\n.\r\n",-5); |
272 | if (x == -1) { | 273 | if (x == -1) { |
273 | break; | 274 | break; |
274 | } else { //message reach entire size | 275 | } else { //message reach entire size |
275 | //complete mail downloaded | 276 | |
276 | //if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){ | 277 | if ( (selected)||(mailSize <= headerLimit)) //mail size limit is not used if late download is active |
277 | if ( mailSize <= headerLimit) | ||
278 | { | 278 | { |
279 | emit newMessage(message, messageCount-1, mailSize, TRUE); | 279 | emit newMessage(message, messageCount-1, mailSize, TRUE); |
280 | } else { //incomplete mail downloaded | 280 | } else { //incomplete mail downloaded |
281 | emit newMessage(message, messageCount-1, mailSize, FALSE); | 281 | emit newMessage(message, messageCount-1, mailSize, FALSE); |
282 | } | 282 | } |
283 | if (messageCount > newMessages) //that was the last message | 283 | |
284 | if ((messageCount > newMessages)||(selected)) //last message ? | ||
285 | { | ||
284 | status = Quit; | 286 | status = Quit; |
285 | else { //ask for new message | ||
286 | if (selected) { //grab next from queue | 287 | if (selected) { //grab next from queue |
287 | int *ptr = mailList->next(); | ||
288 | if (ptr != 0) { | ||
289 | messageCount = *ptr; | ||
290 | *stream << "LIST " << messageCount << "\r\n"; | ||
291 | status = Size; | ||
292 | //completing a previously closed transfer | ||
293 | if ( (messageCount - lastSync) <= 0) { | ||
294 | temp.setNum(messageCount); | ||
295 | emit updateStatus(tr("Previous message ") + temp); | ||
296 | } else { | ||
297 | temp.setNum(messageCount - lastSync); | ||
298 | emit updateStatus(tr("Completing message ") + temp); | ||
299 | } | ||
300 | break; | ||
301 | } else { | ||
302 | newMessages--; | 288 | newMessages--; |
303 | status = Quit; | 289 | status = Quit; |
304 | } | 290 | } |
305 | } else { | 291 | } |
292 | else | ||
293 | { | ||
306 | *stream << "LIST " << messageCount << "\r\n"; | 294 | *stream << "LIST " << messageCount << "\r\n"; |
307 | status = Size; | 295 | status = Size; |
308 | temp2.setNum(newMessages - lastSync); | 296 | temp2.setNum(newMessages - lastSync); |
309 | temp.setNum(messageCount - lastSync); | 297 | temp.setNum(messageCount - lastSync); |
310 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); | 298 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); |
311 | 299 | ||
312 | break; | 300 | break; |
313 | } | 301 | } |
314 | } | 302 | } |
315 | } | 303 | } |
316 | if (status != Quit) | 304 | if (status != Quit) |
317 | break; | 305 | break; |
318 | } | ||
319 | } | 306 | } |
320 | case Quit: { | 307 | case Quit: { |
321 | *stream << "Quit\r\n"; | 308 | *stream << "Quit\r\n"; |
322 | status = Done; | 309 | status = Done; |
323 | int newM = newMessages - lastSync; | 310 | int newM = newMessages - lastSync; |
324 | if (newM > 0) { | 311 | if (newM > 0) { |
325 | temp.setNum(newM); | 312 | temp.setNum(newM); |
326 | emit updateStatus(temp + tr(" new messages")); | 313 | emit updateStatus(temp + tr(" new messages")); |
327 | } else { | 314 | } else { |
328 | emit updateStatus(tr("No new messages")); | 315 | emit updateStatus(tr("No new messages")); |
329 | } | 316 | } |
330 | 317 | ||
331 | socket->close(); | 318 | socket->close(); |
332 | receiving = FALSE; | 319 | receiving = FALSE; |
333 | emit mailTransfered(newM); | 320 | emit mailTransfered(newM); |
334 | break; | 321 | break; |
335 | } | 322 | } |
336 | } | 323 | } |
337 | 324 | ||
338 | } | 325 | } |
339 | |||
340 | // if( bAPOPAuthentication ) | ||
341 | // { | ||
342 | // if( m_strTimeStamp.IsEmpty() ) | ||
343 | // { | ||
344 | // SetLastError("Apop error!"); | ||
345 | // return false; | ||
346 | // } | ||
347 | // strMD5Source = m_strTimeStamp+pszPassword; | ||
348 | // strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() ); | ||
349 | // sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst); | ||
350 | // ret = send(m_sPop3Socket , msg , strlen(msg) , NULL); | ||
351 | // if(ret == SOCKET_ERROR) | ||
352 | // { | ||
353 | // SetLastError("Socket error!"); | ||
354 | // m_bSocketOK = false; | ||
355 | // m_bConnected = false; | ||
356 | // return false; | ||
357 | // } | ||
358 | // if( !GetSocketResult(&strResult , COMMAND_END_FLAG) ) | ||
359 | // return false; | ||
360 | // if( 0 == strResult.Find('-' , 0) ) | ||
361 | // { | ||
362 | // SetLastError("Username or Password error!"); | ||
363 | // return false; | ||
364 | // } | ||
365 | // m_bConnected = true; | ||
366 | |||
367 | // } | ||
diff --git a/noncore/unsupported/mailit/writemail.cpp b/noncore/unsupported/mailit/writemail.cpp index 0336c83..dcf0c6e 100644 --- a/noncore/unsupported/mailit/writemail.cpp +++ b/noncore/unsupported/mailit/writemail.cpp | |||
@@ -1,381 +1,389 @@ | |||
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 | ||
25 | WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl ) | 25 | WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl ) |
26 | : QMainWindow( parent, name, fl ) | 26 | : QMainWindow( parent, name, fl ) |
27 | { | 27 | { |
28 | showingAddressList = FALSE; | 28 | showingAddressList = FALSE; |
29 | init(); | 29 | init(); |
30 | 30 | ||
31 | addAtt = new AddAtt(0, "Add Attachments"); | 31 | addAtt = new AddAtt(0, "Add Attachments"); |
32 | } | 32 | } |
33 | 33 | ||
34 | WriteMail::~WriteMail() | 34 | WriteMail::~WriteMail() |
35 | { | 35 | { |
36 | delete addAtt; | 36 | delete addAtt; |
37 | } | 37 | } |
38 | 38 | ||
39 | void WriteMail::setAddressList(AddressList *list) | 39 | void WriteMail::setAddressList(AddressList *list) |
40 | { | 40 | { |
41 | Contact *cPtr; | 41 | Contact *cPtr; |
42 | 42 | ||
43 | addressList = list; | 43 | addressList = list; |
44 | 44 | ||
45 | addressView->clear(); | 45 | addressView->clear(); |
46 | QList<Contact> *cListPtr = addressList->getContactList(); | 46 | QList<Contact> *cListPtr = addressList->getContactList(); |
47 | QListViewItem *item; | 47 | QListViewItem *item; |
48 | for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) { | 48 | for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) { |
49 | item = new QListViewItem(addressView, cPtr->name, cPtr->email); | 49 | item = new QListViewItem(addressView, cPtr->name, cPtr->email); |
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
53 | void WriteMail::init() | 53 | void WriteMail::init() |
54 | { | 54 | { |
55 | setToolBarsMovable(FALSE); | 55 | setToolBarsMovable(FALSE); |
56 | 56 | ||
57 | bar = new QToolBar(this); | 57 | bar = new QToolBar(this); |
58 | bar->setHorizontalStretchable( TRUE ); | 58 | bar->setHorizontalStretchable( TRUE ); |
59 | 59 | ||
60 | menu = new QMenuBar( bar ); | 60 | menu = new QMenuBar( bar ); |
61 | 61 | ||
62 | mailMenu = new QPopupMenu(menu); | 62 | mailMenu = new QPopupMenu(menu); |
63 | menu->insertItem( tr( "&Mail" ), mailMenu); | 63 | menu->insertItem( tr( "&Mail" ), mailMenu); |
64 | addMenu = new QPopupMenu(menu); | 64 | addMenu = new QPopupMenu(menu); |
65 | menu->insertItem( tr( "&Add" ), addMenu); | 65 | menu->insertItem( tr( "&Add" ), addMenu); |
66 | 66 | ||
67 | bar = new QToolBar(this); | 67 | bar = new QToolBar(this); |
68 | attachButton = new QAction(tr("Attachment"), Resource::loadPixmap("mailit/attach"), QString::null, 0, this, 0); | 68 | attachButton = new QAction(tr("Attachment"), Resource::loadPixmap("mailit/attach"), QString::null, 0, this, 0); |
69 | attachButton->addTo(bar); | 69 | attachButton->addTo(bar); |
70 | attachButton->addTo(addMenu); | 70 | attachButton->addTo(addMenu); |
71 | connect( attachButton, SIGNAL( activated() ), this, SLOT( attachFile() ) ); | 71 | connect( attachButton, SIGNAL( activated() ), this, SLOT( attachFile() ) ); |
72 | attachButton->setWhatsThis(tr("Click here to attach files to your mail")); | 72 | attachButton->setWhatsThis(tr("Click here to attach files to your mail")); |
73 | 73 | ||
74 | confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0); | 74 | confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0); |
75 | confirmButton->addTo(bar); | 75 | confirmButton->addTo(bar); |
76 | confirmButton->addTo(mailMenu); | 76 | confirmButton->addTo(mailMenu); |
77 | connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) ); | 77 | connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) ); |
78 | confirmButton->setWhatsThis(tr("This button puts your mail in the send queue")); | 78 | confirmButton->setWhatsThis(tr("This button puts your mail in the send queue")); |
79 | 79 | ||
80 | newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0); | 80 | newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0); |
81 | newButton->addTo(mailMenu); | 81 | newButton->addTo(mailMenu); |
82 | connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) ); | 82 | connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) ); |
83 | newButton->setWhatsThis(tr("Click here to create a new mail")); | 83 | newButton->setWhatsThis(tr("Click here to create a new mail")); |
84 | 84 | ||
85 | widget = new QWidget(this, "widget"); | 85 | widget = new QWidget(this, "widget"); |
86 | grid = new QGridLayout( widget ); | 86 | grid = new QGridLayout( widget ); |
87 | 87 | ||
88 | recipientsBox = new QComboBox( FALSE, widget, "toLabel" ); | 88 | recipientsBox = new QComboBox( FALSE, widget, "toLabel" ); |
89 | recipientsBox->insertItem( tr( "To:" ) ); | 89 | recipientsBox->insertItem( tr( "To:" ) ); |
90 | recipientsBox->insertItem( tr( "CC:" ) ); | 90 | recipientsBox->insertItem( tr( "CC:" ) ); |
91 | recipientsBox->setCurrentItem(0); | 91 | recipientsBox->setCurrentItem(0); |
92 | grid->addWidget( recipientsBox, 0, 0 ); | 92 | grid->addWidget( recipientsBox, 0, 0 ); |
93 | connect(recipientsBox,SIGNAL(activated(int)),this, SLOT(changeRecipients(int))); | 93 | connect(recipientsBox,SIGNAL(activated(int)),this, SLOT(changeRecipients(int))); |
94 | 94 | ||
95 | subjetLabel = new QLabel( widget, "subjetLabel" ); | 95 | subjetLabel = new QLabel( widget, "subjetLabel" ); |
96 | subjetLabel->setText( tr( "Subject:" ) ); | 96 | subjetLabel->setText( tr( "Subject:" ) ); |
97 | 97 | ||
98 | grid->addWidget( subjetLabel, 1, 0 ); | 98 | grid->addWidget( subjetLabel, 1, 0 ); |
99 | 99 | ||
100 | ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" ); | 100 | ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" ); |
101 | ToolButton13_2->setText( tr( "..." ) ); | 101 | ToolButton13_2->setText( tr( "..." ) ); |
102 | grid->addWidget( ToolButton13_2, 1, 2 ); | 102 | grid->addWidget( ToolButton13_2, 1, 2 ); |
103 | 103 | ||
104 | subjectInput = new QLineEdit( widget, "subjectInput" ); | 104 | subjectInput = new QLineEdit( widget, "subjectInput" ); |
105 | grid->addWidget( subjectInput, 1, 1 ); | 105 | grid->addWidget( subjectInput, 1, 1 ); |
106 | QWhatsThis::add(subjectInput,QWidget::tr("The mail subject should be entered here")); | 106 | QWhatsThis::add(subjectInput,QWidget::tr("The mail subject should be entered here")); |
107 | 107 | ||
108 | toInput = new QLineEdit( widget, "toInput" ); | 108 | toInput = new QLineEdit( widget, "toInput" ); |
109 | grid->addWidget( toInput, 0, 1 ); | 109 | grid->addWidget( toInput, 0, 1 ); |
110 | QWhatsThis::add(recipientsBox,QWidget::tr("Recipients can be entered here")); | 110 | QWhatsThis::add(recipientsBox,QWidget::tr("Recipients can be entered here")); |
111 | 111 | ||
112 | ccInput = new QLineEdit( widget, "ccInput" ); | 112 | ccInput = new QLineEdit( widget, "ccInput" ); |
113 | ccInput->hide(); | 113 | ccInput->hide(); |
114 | grid->addWidget( ccInput, 0, 1 ); | 114 | 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")); | 115 | QWhatsThis::add(ccInput,QWidget::tr("If you would like to send copies of your mail they can be entered here")); |
116 | 116 | ||
117 | addressButton = new QToolButton( widget, "addressButton" ); | 117 | addressButton = new QToolButton( widget, "addressButton" ); |
118 | addressButton->setPixmap( Resource::loadPixmap("AddressBook") ); | 118 | addressButton->setPixmap( Resource::loadPixmap("AddressBook") ); |
119 | addressButton->setToggleButton(TRUE); | 119 | addressButton->setToggleButton(TRUE); |
120 | grid->addWidget( addressButton, 0, 2 ); | 120 | grid->addWidget( addressButton, 0, 2 ); |
121 | connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) ); | 121 | 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")); | 122 | QWhatsThis::add(addressButton,QWidget::tr("This button opens the address selector with all mail adresses from your OPIE addressbook")); |
123 | 123 | ||
124 | emailInput = new QMultiLineEdit( widget, "emailInput" ); | 124 | emailInput = new QMultiLineEdit( widget, "emailInput" ); |
125 | grid->addMultiCellWidget( emailInput, 2, 2, 0, 2); | 125 | grid->addMultiCellWidget( emailInput, 2, 2, 0, 2); |
126 | QWhatsThis::add(recipientsBox,QWidget::tr("Enter your mail text here")); | 126 | QWhatsThis::add(emailInput,QWidget::tr("Enter your mail text here")); |
127 | 127 | ||
128 | addressView = new QListView( widget, "addressView"); | 128 | addressView = new QListView( widget, "addressView"); |
129 | addressView->addColumn("Name"); | 129 | addressView->addColumn("Name"); |
130 | addressView->addColumn("EMail"); | 130 | addressView->addColumn("EMail"); |
131 | addressView->setAllColumnsShowFocus(TRUE); | 131 | addressView->setAllColumnsShowFocus(TRUE); |
132 | addressView->setMultiSelection(TRUE); | 132 | addressView->setMultiSelection(TRUE); |
133 | addressView->hide(); | 133 | addressView->hide(); |
134 | grid->addMultiCellWidget( addressView, 3, 3, 0, 2); | 134 | grid->addMultiCellWidget( addressView, 3, 3, 0, 2); |
135 | QWhatsThis::add(recipientsBox,QWidget::tr("Chose the recipients from this list")); | 135 | QWhatsThis::add(recipientsBox,QWidget::tr("Choose the recipients from this list")); |
136 | 136 | ||
137 | okButton = new QToolButton(bar, "ok"); | 137 | okButton = new QToolButton(bar, "ok"); |
138 | okButton->setPixmap( Resource::loadPixmap("enter") ); | 138 | okButton->setPixmap( Resource::loadPixmap("enter") ); |
139 | okButton->hide(); | 139 | okButton->hide(); |
140 | connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) ); | 140 | connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) ); |
141 | QWhatsThis::add(okButton,QWidget::tr("Queue your mail by clicking here")); | 141 | QWhatsThis::add(okButton,QWidget::tr("Queue your mail by clicking here")); |
142 | 142 | ||
143 | setCentralWidget(widget); | 143 | setCentralWidget(widget); |
144 | } | 144 | } |
145 | 145 | ||
146 | void WriteMail::reject() | 146 | void WriteMail::reject() |
147 | { | 147 | { |
148 | emit cancelMail(); | 148 | emit cancelMail(); |
149 | } | 149 | } |
150 | 150 | ||
151 | // need to insert date | ||
152 | void WriteMail::accept() | 151 | void WriteMail::accept() |
153 | { | 152 | { |
154 | QStringList attachedFiles, attachmentsType; | 153 | QStringList attachedFiles, attachmentsType; |
155 | int idCount = 0; | 154 | int idCount = 0; |
156 | 155 | ||
157 | if (toInput->text() == "") | 156 | if (toInput->text() == "") |
158 | { | 157 | { |
159 | QMessageBox::warning(this,tr("No recipient"), tr("Send mail to whom?"), tr("OK\n")); | 158 | QMessageBox::warning(this,tr("No recipient"), tr("Send mail to whom?"), tr("OK\n")); |
160 | return; | 159 | return; |
161 | } | 160 | } |
162 | 161 | ||
163 | if (! getRecipients(false) ) | 162 | if (! getRecipients(false) ) |
164 | { | 163 | { |
165 | QMessageBox::warning(this,tr("Incorrect recipient separator"), | 164 | QMessageBox::warning(this,tr("Incorrect recipient separator"), |
166 | tr("Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n")); | 165 | tr("Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n")); |
167 | return; | 166 | return; |
168 | } | 167 | } |
169 | 168 | ||
170 | if ((ccInput->text()!="") && (! getRecipients(true) )) | 169 | if ((ccInput->text()!="") && (! getRecipients(true) )) |
171 | { | 170 | { |
172 | QMessageBox::warning(this,tr("Incorrect carbon copy separator"), | 171 | QMessageBox::warning(this,tr("Incorrect carbon copy separator"), |
173 | tr("CC Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n")); | 172 | tr("CC Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n")); |
174 | return; | 173 | return; |
175 | } | 174 | } |
176 | 175 | ||
177 | mail.subject = subjectInput->text(); | 176 | mail.subject = subjectInput->text(); |
178 | mail.body = emailInput->text(); | 177 | mail.body = emailInput->text(); |
179 | mail.sent = false; | 178 | mail.sent = false; |
180 | mail.received = false; | 179 | mail.received = false; |
181 | 180 | ||
182 | mail.rawMail = "To: "; | 181 | mail.rawMail = "To: "; |
183 | 182 | ||
184 | for (QStringList::Iterator it = mail.recipients.begin(); | 183 | for (QStringList::Iterator it = mail.recipients.begin(); |
185 | it != mail.recipients.end(); ++it) { | 184 | it != mail.recipients.end(); ++it) { |
186 | 185 | ||
187 | mail.rawMail += (*it); | 186 | mail.rawMail += (*it); |
188 | mail.rawMail += ",\n"; | 187 | mail.rawMail += ",\n"; |
189 | } | 188 | } |
190 | 189 | ||
191 | mail.rawMail.truncate(mail.rawMail.length()-2); | 190 | mail.rawMail.truncate(mail.rawMail.length()-2); |
192 | 191 | ||
193 | mail.rawMail += "\nCC: "; | 192 | mail.rawMail += "\nCC: "; |
194 | 193 | ||
195 | for (QStringList::Iterator it = mail.carbonCopies.begin(); | 194 | for (QStringList::Iterator it = mail.carbonCopies.begin(); |
196 | it != mail.carbonCopies.end(); ++it) { | 195 | it != mail.carbonCopies.end(); ++it) { |
197 | 196 | ||
198 | mail.rawMail += (*it); | 197 | mail.rawMail += (*it); |
199 | mail.rawMail += ",\n"; | 198 | mail.rawMail += ",\n"; |
200 | } | 199 | } |
201 | 200 | ||
202 | mail.rawMail += mail.from; | 201 | mail.rawMail += mail.from; |
203 | mail.rawMail += "\nSubject: "; | 202 | mail.rawMail += "\nSubject: "; |
204 | mail.rawMail += mail.subject; | 203 | mail.rawMail += mail.subject; |
205 | mail.rawMail += "\n\n"; | 204 | mail.rawMail += "\n\n"; |
206 | 205 | ||
207 | attachedFiles = addAtt->returnattachedFiles(); | 206 | attachedFiles = addAtt->returnattachedFiles(); |
208 | attachmentsType = addAtt->returnFileTypes(); | 207 | attachmentsType = addAtt->returnFileTypes(); |
209 | 208 | ||
210 | QStringList::Iterator itType = attachmentsType.begin(); | 209 | QStringList::Iterator itType = attachmentsType.begin(); |
211 | 210 | ||
212 | Enclosure e; | 211 | Enclosure e; |
213 | for ( QStringList::Iterator it = attachedFiles.begin(); it != attachedFiles.end(); ++it ) { | 212 | for ( QStringList::Iterator it = attachedFiles.begin(); it != attachedFiles.end(); ++it ) { |
214 | e.id = idCount; | 213 | e.id = idCount; |
215 | e.originalName = (*it).latin1(); | 214 | e.originalName = (*it).latin1(); |
216 | e.contentType = (*itType).latin1(); | 215 | e.contentType = (*itType).latin1(); |
217 | e.contentAttribute = (*itType).latin1(); | 216 | e.contentAttribute = (*itType).latin1(); |
218 | e.saved = TRUE; | 217 | e.saved = TRUE; |
219 | mail.addEnclosure(&e); | 218 | mail.addEnclosure(&e); |
220 | 219 | ||
221 | itType++; | 220 | itType++; |
222 | idCount++; | 221 | idCount++; |
223 | } | 222 | } |
224 | mail.rawMail += mail.body; | 223 | mail.rawMail += mail.body; |
225 | mail.rawMail += "\n"; | 224 | mail.rawMail += "\n"; |
226 | mail.rawMail += ".\n"; | 225 | mail.rawMail += ".\n"; |
227 | emit sendMailRequested(mail); | 226 | emit sendMailRequested(mail); |
228 | addAtt->clear(); | 227 | addAtt->clear(); |
229 | } | 228 | } |
230 | 229 | ||
231 | void WriteMail::getAddress() | 230 | void WriteMail::getAddress() |
232 | { | 231 | { |
233 | showingAddressList = !showingAddressList; | 232 | showingAddressList = !showingAddressList; |
234 | 233 | ||
235 | if (showingAddressList) { | 234 | if (showingAddressList) { |
236 | emailInput->hide(); | 235 | emailInput->hide(); |
237 | addressView->show(); | 236 | addressView->show(); |
238 | okButton->show(); | 237 | okButton->show(); |
239 | 238 | ||
240 | } else { | 239 | } else { |
241 | addressView->hide(); | 240 | addressView->hide(); |
242 | okButton->hide(); | 241 | okButton->hide(); |
243 | emailInput->show(); | 242 | emailInput->show(); |
244 | } | 243 | } |
245 | } | 244 | } |
246 | 245 | ||
247 | void WriteMail::attachFile() | 246 | void WriteMail::attachFile() |
248 | { | 247 | { |
249 | addAtt->showMaximized(); | 248 | addAtt->showMaximized(); |
250 | } | 249 | } |
251 | 250 | ||
252 | void WriteMail::reply(Email replyMail, bool replyAll) | 251 | void WriteMail::reply(Email replyMail, bool replyAll) |
253 | { | 252 | { |
254 | int pos; | 253 | int pos; |
254 | QString ccRecipients; | ||
255 | 255 | ||
256 | mail = replyMail; | 256 | mail = replyMail; |
257 | mail.files.clear(); | 257 | mail.files.clear(); |
258 | 258 | ||
259 | toInput->setText(mail.fromMail); | 259 | toInput->setText(mail.fromMail); |
260 | //replyAll ? ccInput->setText(mail.c) | ||
261 | 260 | ||
261 | if (replyAll) | ||
262 | { | ||
263 | for (QStringList::Iterator it = mail.carbonCopies.begin();it != mail.carbonCopies.end(); ++it) | ||
264 | { | ||
265 | ccRecipients.append(*it); | ||
266 | ccRecipients.append(";"); | ||
267 | } | ||
268 | ccRecipients.truncate(ccRecipients.length()-1); //no ; at the end | ||
269 | ccInput->setText(ccRecipients); | ||
270 | } | ||
271 | |||
262 | addRecipients(replyAll); | 272 | addRecipients(replyAll); |
263 | 273 | ||
264 | subjectInput->setText(tr("Re: ") + mail.subject); | 274 | subjectInput->setText(tr("Re: ") + mail.subject); |
265 | 275 | ||
266 | pos = 0; | 276 | pos = 0; |
267 | mail.body.insert(pos, ">"); | 277 | mail.body.insert(pos, ">"); |
268 | while (pos != -1) { | 278 | while (pos != -1) { |
269 | pos = mail.body.find('\n', pos); | 279 | pos = mail.body.find('\n', pos); |
270 | if (pos != -1) | 280 | if (pos != -1) |
271 | mail.body.insert(++pos, ">>"); | 281 | mail.body.insert(++pos, ">>"); |
272 | } | 282 | } |
273 | 283 | ||
274 | emailInput->setText(mail.body); | 284 | emailInput->setText(mail.body); |
275 | } | 285 | } |
276 | 286 | ||
277 | void WriteMail::forward(Email forwMail) | 287 | void WriteMail::forward(Email forwMail) |
278 | { | 288 | { |
279 | int pos=0; | 289 | int pos=0; |
280 | 290 | ||
281 | QString fwdBody=tr("======forwarded message from "); | 291 | QString fwdBody=tr("======forwarded message from "); |
282 | fwdBody.append(forwMail.fromMail); | 292 | fwdBody.append(forwMail.fromMail); |
283 | fwdBody.append(tr(" starts======\n\n")); | 293 | fwdBody.append(tr(" starts======\n\n")); |
284 | 294 | ||
285 | mail=forwMail; | 295 | mail=forwMail; |
286 | toInput->setText(""); | 296 | toInput->setText(""); |
287 | ccInput->setText(""); | 297 | ccInput->setText(""); |
288 | subjectInput->setText(tr("FWD: ") + mail.subject); | 298 | subjectInput->setText(tr("FWD: ") + mail.subject); |
289 | 299 | ||
290 | fwdBody+=mail.body; | 300 | fwdBody+=mail.body; |
291 | fwdBody+=QString(tr("======end of forwarded message======\n\n")); | 301 | fwdBody+=QString(tr("======end of forwarded message======\n\n")); |
292 | 302 | ||
293 | emailInput->setText(fwdBody); | 303 | emailInput->setText(fwdBody); |
294 | } | 304 | } |
295 | 305 | ||
296 | bool WriteMail::getRecipients(bool ccField) | 306 | bool WriteMail::getRecipients(bool ccField) |
297 | { | 307 | { |
298 | QString str, temp; | 308 | QString str, temp; |
299 | int pos = 0; | 309 | int pos = 0; |
300 | 310 | ||
301 | mail.recipients.clear(); | 311 | mail.recipients.clear(); |
302 | 312 | ||
303 | ccField ? temp = ccInput->text() : temp=toInput->text() ; | 313 | ccField ? temp = ccInput->text() : temp=toInput->text() ; |
304 | 314 | ||
305 | while ( (pos = temp.find(';')) != -1) { | 315 | while ( (pos = temp.find(';')) != -1) { |
306 | str = temp.left(pos).stripWhiteSpace(); | 316 | str = temp.left(pos).stripWhiteSpace(); |
307 | temp = temp.right(temp.length() - (pos + 1)); | 317 | temp = temp.right(temp.length() - (pos + 1)); |
308 | if ( str.find('@') == -1) | 318 | if ( str.find('@') == -1) |
309 | return false; | 319 | return false; |
310 | ccField ? mail.carbonCopies.append(str) : mail.recipients.append(str); | 320 | ccField ? mail.carbonCopies.append(str) : mail.recipients.append(str); |
311 | addressList->addContact(str, ""); | 321 | addressList->addContact(str, ""); |
312 | } | 322 | } |
313 | temp = temp.stripWhiteSpace(); | 323 | temp = temp.stripWhiteSpace(); |
314 | if ( temp.find('@') == -1) | 324 | if ( temp.find('@') == -1) |
315 | return false; | 325 | return false; |
316 | ccField ? mail.carbonCopies.append(temp) : mail.recipients.append(temp); | 326 | ccField ? mail.carbonCopies.append(temp) : mail.recipients.append(temp); |
317 | addressList->addContact(temp, ""); | 327 | addressList->addContact(temp, ""); |
318 | 328 | ||
319 | return TRUE; | 329 | return TRUE; |
320 | } | 330 | } |
321 | 331 | ||
322 | void WriteMail::addRecipients() | 332 | void WriteMail::addRecipients() |
323 | { | 333 | { |
324 | 334 | toInput->isVisible() ? addRecipients(false) : addRecipients(true); | |
325 | addRecipients(false); | ||
326 | } | 335 | } |
327 | 336 | ||
328 | void WriteMail::addRecipients(bool ccField) | 337 | void WriteMail::addRecipients(bool ccField) |
329 | { | 338 | { |
330 | QString recipients = ""; | 339 | QString recipients = ""; |
331 | 340 | ||
332 | mail.recipients.clear(); | 341 | mail.recipients.clear(); |
333 | 342 | ||
334 | QListViewItem *item = addressView->firstChild(); | 343 | QListViewItem *item = addressView->firstChild(); |
335 | while (item != NULL) { | 344 | while (item != NULL) { |
336 | if ( item->isSelected() ) { | 345 | if ( item->isSelected() ) { |
337 | if (recipients == "") { | 346 | if (recipients == "") { |
338 | recipients = item->text(0); | 347 | recipients = item->text(1); |
339 | } else { | 348 | } else { |
340 | recipients += "; " + item->text(0); | 349 | recipients += "; " + item->text(1); |
341 | } | 350 | } |
342 | } | 351 | } |
343 | item = item->nextSibling(); | 352 | item = item->nextSibling(); |
344 | } | 353 | } |
345 | 354 | ||
346 | ccField ? ccInput->setText(recipients):toInput->setText(recipients); | 355 | ccField ? ccInput->setText(recipients):toInput->setText(recipients); |
347 | 356 | ||
348 | addressView->hide(); | 357 | addressView->hide(); |
349 | okButton->hide(); | 358 | okButton->hide(); |
350 | emailInput->show(); | 359 | emailInput->show(); |
351 | addressButton->setOn(FALSE); | 360 | addressButton->setOn(FALSE); |
352 | showingAddressList = !showingAddressList; | 361 | showingAddressList = !showingAddressList; |
353 | } | 362 | } |
354 | 363 | ||
355 | void WriteMail::changeRecipients(int selection) | 364 | void WriteMail::changeRecipients(int selection) |
356 | { | 365 | { |
357 | if (selection==0) | 366 | if (selection==0) |
358 | { | 367 | { |
359 | toInput->show(); | 368 | toInput->show(); |
360 | ccInput->hide(); | 369 | ccInput->hide(); |
361 | } | 370 | } |
362 | else if (selection==1) | 371 | else if (selection==1) |
363 | { | 372 | { |
364 | toInput->hide(); | 373 | toInput->hide(); |
365 | ccInput->show(); | 374 | ccInput->show(); |
366 | } | 375 | } |
367 | } | 376 | } |
368 | 377 | ||
369 | void WriteMail::setRecipient(const QString &recipient) | 378 | void WriteMail::setRecipient(const QString &recipient) |
370 | { | 379 | { |
371 | toInput->setText(recipient); | 380 | toInput->setText(recipient); |
372 | } | 381 | } |
373 | 382 | ||
374 | void WriteMail::newMail() | 383 | void WriteMail::newMail() |
375 | { | 384 | { |
376 | toInput->clear(); | 385 | toInput->clear(); |
377 | subjectInput->clear(); | 386 | subjectInput->clear(); |
378 | emailInput->clear(); | 387 | emailInput->clear(); |
379 | //to clear selected | ||
380 | setAddressList(addressList); | 388 | setAddressList(addressList); |
381 | } | 389 | } |