-rw-r--r-- | noncore/net/mail/viewmail.cpp | 151 |
1 files changed, 97 insertions, 54 deletions
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp index 99965d4..f015228 100644 --- a/noncore/net/mail/viewmail.cpp +++ b/noncore/net/mail/viewmail.cpp | |||
@@ -1,2 +1,16 @@ | |||
1 | #include "composemail.h" | ||
2 | #include "viewmail.h" | ||
3 | #include "accountview.h" | ||
4 | |||
5 | /* OPIE */ | ||
6 | #include <libmailwrapper/settings.h> | ||
7 | #include <libmailwrapper/abstractmail.h> | ||
8 | #include <libmailwrapper/mailtypes.h> | ||
9 | |||
10 | #include <opie2/ofiledialog.h> | ||
11 | #include <qpe/config.h> | ||
12 | #include <qpe/qpeapplication.h> | ||
13 | |||
14 | /* QT */ | ||
1 | #include <qtextbrowser.h> | 15 | #include <qtextbrowser.h> |
2 | #include <qmessagebox.h> | 16 | #include <qmessagebox.h> |
@@ -8,15 +22,4 @@ | |||
8 | #include <qvaluelist.h> | 22 | #include <qvaluelist.h> |
9 | 23 | ||
10 | #include <qpe/config.h> | ||
11 | |||
12 | #include <opie2/ofiledialog.h> | ||
13 | |||
14 | #include <libmailwrapper/settings.h> | ||
15 | #include "composemail.h" | ||
16 | #include "viewmail.h" | ||
17 | #include <libmailwrapper/abstractmail.h> | ||
18 | #include "accountview.h" | ||
19 | #include <libmailwrapper/mailtypes.h> | ||
20 | |||
21 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, | 24 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, |
22 | const QString&fsize,int num,const QValueList<int>&path) | 25 | const QString&fsize,int num,const QValueList<int>&path) |
@@ -47,5 +50,6 @@ bool AttachItem::isParentof(const QValueList<int>&path) | |||
47 | /* the parent must have one digit less then a child */ | 50 | /* the parent must have one digit less then a child */ |
48 | if (path.count()!=_path.count()+1) return false; | 51 | if (path.count()!=_path.count()+1) return false; |
49 | for (unsigned int i=0; i < _path.count();++i) { | 52 | for (unsigned int i=0; i < _path.count();++i) |
53 | { | ||
50 | if (_path[i]!=path[i]) return false; | 54 | if (_path[i]!=path[i]) return false; |
51 | } | 55 | } |
@@ -56,5 +60,6 @@ AttachItem* ViewMail::searchParent(const QValueList<int>&path) | |||
56 | { | 60 | { |
57 | QListViewItemIterator it( attachments ); | 61 | QListViewItemIterator it( attachments ); |
58 | for ( ; it.current(); ++it ) { | 62 | for ( ; it.current(); ++it ) |
63 | { | ||
59 | AttachItem*ati = (AttachItem*)it.current(); | 64 | AttachItem*ati = (AttachItem*)it.current(); |
60 | if (ati->isParentof(path)) return ati; | 65 | if (ati->isParentof(path)) return ati; |
@@ -69,5 +74,6 @@ AttachItem* ViewMail::lastChild(AttachItem*parent) | |||
69 | if (!item) return item; | 74 | if (!item) return item; |
70 | AttachItem*temp=0; | 75 | AttachItem*temp=0; |
71 | while( (temp=(AttachItem*)item->nextSibling())) { | 76 | while( (temp=(AttachItem*)item->nextSibling())) |
77 | { | ||
72 | item = temp; | 78 | item = temp; |
73 | } | 79 | } |
@@ -75,5 +81,6 @@ AttachItem* ViewMail::lastChild(AttachItem*parent) | |||
75 | } | 81 | } |
76 | 82 | ||
77 | void ViewMail::setBody( RecBody body ) { | 83 | void ViewMail::setBody( RecBody body ) |
84 | { | ||
78 | 85 | ||
79 | m_body = body; | 86 | m_body = body; |
@@ -81,5 +88,6 @@ m_mail[2] = body.Bodytext(); | |||
81 | attachbutton->setEnabled(body.Parts().count()>0); | 88 | attachbutton->setEnabled(body.Parts().count()>0); |
82 | attachments->setEnabled(body.Parts().count()>0); | 89 | attachments->setEnabled(body.Parts().count()>0); |
83 | if (body.Parts().count()==0) { | 90 | if (body.Parts().count()==0) |
91 | { | ||
84 | return; | 92 | return; |
85 | } | 93 | } |
@@ -92,5 +100,6 @@ int w; | |||
92 | w=0; | 100 | w=0; |
93 | 101 | ||
94 | while (s>1024) { | 102 | while (s>1024) |
103 | { | ||
95 | s/=1024; | 104 | s/=1024; |
96 | ++w; | 105 | ++w; |
@@ -99,5 +108,6 @@ while (s>1024) { | |||
99 | 108 | ||
100 | QString q=""; | 109 | QString q=""; |
101 | switch(w) { | 110 | switch(w) |
111 | { | ||
102 | case 1: | 112 | case 1: |
103 | q="k"; | 113 | q="k"; |
@@ -125,10 +135,13 @@ curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body.Desc | |||
125 | QString filename = ""; | 135 | QString filename = ""; |
126 | 136 | ||
127 | for (unsigned int i = 0; i < body.Parts().count();++i) { | 137 | for (unsigned int i = 0; i < body.Parts().count();++i) |
138 | { | ||
128 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); | 139 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); |
129 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); | 140 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); |
130 | for (;it!=body.Parts()[i].Parameters().end();++it) { | 141 | for (;it!=body.Parts()[i].Parameters().end();++it) |
142 | { | ||
131 | qDebug(it.key()); | 143 | qDebug(it.key()); |
132 | if (it.key().lower()=="name") { | 144 | if (it.key().lower()=="name") |
145 | { | ||
133 | filename=it.data(); | 146 | filename=it.data(); |
134 | } | 147 | } |
@@ -136,10 +149,12 @@ for (unsigned int i = 0; i < body.Parts().count();++i) { | |||
136 | s = body.Parts()[i].Size(); | 149 | s = body.Parts()[i].Size(); |
137 | w = 0; | 150 | w = 0; |
138 | while (s>1024) { | 151 | while (s>1024) |
152 | { | ||
139 | s/=1024; | 153 | s/=1024; |
140 | ++w; | 154 | ++w; |
141 | if (w>=2) break; | 155 | if (w>=2) break; |
142 | } | 156 | } |
143 | switch(w) { | 157 | switch(w) |
158 | { | ||
144 | case 1: | 159 | case 1: |
145 | q="k"; | 160 | q="k"; |
@@ -158,5 +173,6 @@ for (unsigned int i = 0; i < body.Parts().count();++i) { | |||
158 | desc = body.Parts()[i].Description(); | 173 | desc = body.Parts()[i].Description(); |
159 | parentItem = searchParent(body.Parts()[i].Positionlist()); | 174 | parentItem = searchParent(body.Parts()[i].Positionlist()); |
160 | if (parentItem) { | 175 | if (parentItem) |
176 | { | ||
161 | AttachItem*temp = lastChild(parentItem); | 177 | AttachItem*temp = lastChild(parentItem); |
162 | if (temp) curItem = temp; | 178 | if (temp) curItem = temp; |
@@ -164,5 +180,7 @@ for (unsigned int i = 0; i < body.Parts().count();++i) { | |||
164 | attachments->setRootIsDecorated(true); | 180 | attachments->setRootIsDecorated(true); |
165 | curItem = parentItem; | 181 | curItem = parentItem; |
166 | } else { | 182 | } |
183 | else | ||
184 | { | ||
167 | curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); | 185 | curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); |
168 | } | 186 | } |
@@ -171,14 +189,17 @@ for (unsigned int i = 0; i < body.Parts().count();++i) { | |||
171 | 189 | ||
172 | 190 | ||
173 | void ViewMail::slotShowHtml( bool state ) { | 191 | void ViewMail::slotShowHtml( bool state ) |
192 | { | ||
174 | m_showHtml = state; | 193 | m_showHtml = state; |
175 | setText(); | 194 | setText(); |
176 | } | 195 | } |
177 | 196 | ||
178 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) { | 197 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) |
198 | { | ||
179 | if (!item ) | 199 | if (!item ) |
180 | return; | 200 | return; |
181 | 201 | ||
182 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { | 202 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) |
203 | { | ||
183 | setText(); | 204 | setText(); |
184 | return; | 205 | return; |
@@ -187,5 +208,6 @@ void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int | |||
187 | int ret=0; | 208 | int ret=0; |
188 | 209 | ||
189 | if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) { | 210 | if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) |
211 | { | ||
190 | menu->insertItem( tr( "Show Text" ), 1 ); | 212 | menu->insertItem( tr( "Show Text" ), 1 ); |
191 | } | 213 | } |
@@ -195,14 +217,18 @@ void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int | |||
195 | ret = menu->exec( point, 0 ); | 217 | ret = menu->exec( point, 0 ); |
196 | 218 | ||
197 | switch(ret) { | 219 | switch(ret) |
220 | { | ||
198 | case 0: | 221 | case 0: |
199 | { MimeTypes types; | 222 | { |
223 | MimeTypes types; | ||
200 | types.insert( "all", "*" ); | 224 | types.insert( "all", "*" ); |
201 | QString str = Opie::OFileDialog::getSaveFileName( 1, | 225 | QString str = Opie::OFileDialog::getSaveFileName( 1, |
202 | "/", item->text( 2 ) , types, 0 ); | 226 | "/", item->text( 2 ) , types, 0 ); |
203 | 227 | ||
204 | if( !str.isEmpty() ) { | 228 | if( !str.isEmpty() ) |
229 | { | ||
205 | encodedString*content = m_recMail.Wrapper()->fetchDecodedPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); | 230 | encodedString*content = m_recMail.Wrapper()->fetchDecodedPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); |
206 | if (content) { | 231 | if (content) |
232 | { | ||
207 | QFile output(str); | 233 | QFile output(str); |
208 | output.open(IO_WriteOnly); | 234 | output.open(IO_WriteOnly); |
@@ -216,8 +242,12 @@ void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int | |||
216 | 242 | ||
217 | case 1: | 243 | case 1: |
218 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { | 244 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) |
245 | { | ||
219 | setText(); | 246 | setText(); |
220 | } else { | 247 | } |
221 | if ( m_recMail.Wrapper() != 0l ) { // make sure that there is a wrapper , even after delete or simular actions | 248 | else |
249 | { | ||
250 | if ( m_recMail.Wrapper() != 0l ) | ||
251 | { // make sure that there is a wrapper , even after delete or simular actions | ||
222 | browser->setText( m_recMail.Wrapper()->fetchTextPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); | 252 | browser->setText( m_recMail.Wrapper()->fetchTextPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); |
223 | } | 253 | } |
@@ -229,5 +259,6 @@ void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int | |||
229 | 259 | ||
230 | 260 | ||
231 | void ViewMail::setMail( RecMail mail ) { | 261 | void ViewMail::setMail( RecMail mail ) |
262 | { | ||
232 | 263 | ||
233 | m_recMail = mail; | 264 | m_recMail = mail; |
@@ -265,5 +296,6 @@ ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) | |||
265 | } | 296 | } |
266 | 297 | ||
267 | void ViewMail::readConfig() { | 298 | void ViewMail::readConfig() |
299 | { | ||
268 | Config cfg( "mail" ); | 300 | Config cfg( "mail" ); |
269 | cfg.setGroup( "Settings" ); | 301 | cfg.setGroup( "Settings" ); |
@@ -279,11 +311,14 @@ void ViewMail::setText() | |||
279 | QString bccString; | 311 | QString bccString; |
280 | 312 | ||
281 | for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) { | 313 | for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) |
314 | { | ||
282 | toString += (*it); | 315 | toString += (*it); |
283 | } | 316 | } |
284 | for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) { | 317 | for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) |
318 | { | ||
285 | ccString += (*it); | 319 | ccString += (*it); |
286 | } | 320 | } |
287 | for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) { | 321 | for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) |
322 | { | ||
288 | bccString += (*it); | 323 | bccString += (*it); |
289 | } | 324 | } |
@@ -301,7 +336,10 @@ void ViewMail::setText() | |||
301 | "</td></tr></table><font face=fixed>"; | 336 | "</td></tr></table><font face=fixed>"; |
302 | 337 | ||
303 | if ( !m_showHtml ) { | 338 | if ( !m_showHtml ) |
339 | { | ||
304 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); | 340 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); |
305 | } else { | 341 | } |
342 | else | ||
343 | { | ||
306 | browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); | 344 | browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); |
307 | } | 345 | } |
@@ -321,5 +359,6 @@ void ViewMail::hide() | |||
321 | QWidget::hide(); | 359 | QWidget::hide(); |
322 | 360 | ||
323 | if (_inLoop) { | 361 | if (_inLoop) |
362 | { | ||
324 | _inLoop = false; | 363 | _inLoop = false; |
325 | qApp->exit_loop(); | 364 | qApp->exit_loop(); |
@@ -333,5 +372,6 @@ void ViewMail::exec() | |||
333 | show(); | 372 | show(); |
334 | 373 | ||
335 | if (!_inLoop) { | 374 | if (!_inLoop) |
375 | { | ||
336 | _inLoop = true; | 376 | _inLoop = true; |
337 | qApp->enter_loop(); | 377 | qApp->enter_loop(); |
@@ -352,5 +392,6 @@ QString ViewMail::deHtml(const QString &string) | |||
352 | void ViewMail::slotReply() | 392 | void ViewMail::slotReply() |
353 | { | 393 | { |
354 | if (!m_gotBody) { | 394 | if (!m_gotBody) |
395 | { | ||
355 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); | 396 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); |
356 | return; | 397 | return; |
@@ -365,5 +406,6 @@ void ViewMail::slotReply() | |||
365 | QStringList lines = QStringList::split(QRegExp("\\n"), text); | 406 | QStringList lines = QStringList::split(QRegExp("\\n"), text); |
366 | QStringList::Iterator it; | 407 | QStringList::Iterator it; |
367 | for (it = lines.begin(); it != lines.end(); it++) { | 408 | for (it = lines.begin(); it != lines.end(); it++) |
409 | { | ||
368 | rtext += "> " + *it + "\n"; | 410 | rtext += "> " + *it + "\n"; |
369 | } | 411 | } |
@@ -379,6 +421,6 @@ void ViewMail::slotReply() | |||
379 | composer.setSubject( "Re: " + m_mail[1] ); | 421 | composer.setSubject( "Re: " + m_mail[1] ); |
380 | composer.setMessage( rtext ); | 422 | composer.setMessage( rtext ); |
381 | composer.showMaximized(); | 423 | if ( QDialog::Accepted == QPEApplication::execDialog( &composer ) ) |
382 | if ( QDialog::Accepted==composer.exec()) { | 424 | { |
383 | m_recMail.Wrapper()->answeredMail(m_recMail); | 425 | m_recMail.Wrapper()->answeredMail(m_recMail); |
384 | } | 426 | } |
@@ -387,5 +429,6 @@ void ViewMail::slotReply() | |||
387 | void ViewMail::slotForward() | 429 | void ViewMail::slotForward() |
388 | { | 430 | { |
389 | if (!m_gotBody) { | 431 | if (!m_gotBody) |
432 | { | ||
390 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); | 433 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); |
391 | return; | 434 | return; |
@@ -414,7 +457,6 @@ void ViewMail::slotForward() | |||
414 | composer.setSubject( "Fwd: " + m_mail[1] ); | 457 | composer.setSubject( "Fwd: " + m_mail[1] ); |
415 | composer.setMessage( ftext ); | 458 | composer.setMessage( ftext ); |
416 | composer.showMaximized(); | 459 | if ( QDialog::Accepted == QPEApplication::execDialog( &composer )) |
417 | if ( QDialog::Accepted==composer.exec()) { | 460 | { |
418 | |||
419 | } | 461 | } |
420 | } | 462 | } |
@@ -422,5 +464,6 @@ void ViewMail::slotForward() | |||
422 | void ViewMail::slotDeleteMail( ) | 464 | void ViewMail::slotDeleteMail( ) |
423 | { | 465 | { |
424 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { | 466 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) |
467 | { | ||
425 | m_recMail.Wrapper()->deleteMail( m_recMail ); | 468 | m_recMail.Wrapper()->deleteMail( m_recMail ); |
426 | hide(); | 469 | hide(); |