summaryrefslogtreecommitdiff
path: root/noncore/net/mail/viewmail.cpp
Unidiff
Diffstat (limited to 'noncore/net/mail/viewmail.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/mail/viewmail.cpp151
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,3 +1,17 @@
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>
3#include <qtextstream.h> 17#include <qtextstream.h>
@@ -7,17 +21,6 @@
7#include <qapplication.h> 21#include <qapplication.h>
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
21AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, 24AttachItem::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)
23 : QListViewItem(parent,after),_partNum(num) 26 : QListViewItem(parent,after),_partNum(num)
@@ -46,7 +49,8 @@ bool AttachItem::isParentof(const QValueList<int>&path)
46 if (path.count()==0||_path.count()==0) return false; 49 if (path.count()==0||_path.count()==0) return false;
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 }
52 return true; 56 return true;
@@ -55,7 +59,8 @@ bool AttachItem::isParentof(const QValueList<int>&path)
55AttachItem* ViewMail::searchParent(const QValueList<int>&path) 59AttachItem* 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;
61 } 66 }
@@ -68,19 +73,22 @@ AttachItem* ViewMail::lastChild(AttachItem*parent)
68 AttachItem* item = (AttachItem*)parent->firstChild(); 73 AttachItem* item = (AttachItem*)parent->firstChild();
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 }
74 return item; 80 return item;
75} 81}
76 82
77void ViewMail::setBody( RecBody body ) { 83void ViewMail::setBody( RecBody body )
84{
78 85
79m_body = body; 86m_body = body;
80m_mail[2] = body.Bodytext(); 87m_mail[2] = body.Bodytext();
81attachbutton->setEnabled(body.Parts().count()>0); 88attachbutton->setEnabled(body.Parts().count()>0);
82attachments->setEnabled(body.Parts().count()>0); 89attachments->setEnabled(body.Parts().count()>0);
83if (body.Parts().count()==0) { 90 if (body.Parts().count()==0)
91 {
84 return; 92 return;
85} 93}
86AttachItem * curItem=0; 94AttachItem * curItem=0;
@@ -91,14 +99,16 @@ double s = body.Description().Size();
91int w; 99int w;
92w=0; 100w=0;
93 101
94while (s>1024) { 102 while (s>1024)
103 {
95 s/=1024; 104 s/=1024;
96 ++w; 105 ++w;
97 if (w>=2) break; 106 if (w>=2) break;
98} 107}
99 108
100QString q=""; 109QString q="";
101switch(w) { 110 switch(w)
111 {
102case 1: 112case 1:
103 q="k"; 113 q="k";
104 break; 114 break;
@@ -124,23 +134,28 @@ default:
124curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body.Description().Positionlist()); 134curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body.Description().Positionlist());
125QString filename = ""; 135QString filename = "";
126 136
127for (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 }
135 } 148 }
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";
146 break; 161 break;
@@ -157,36 +172,43 @@ for (unsigned int i = 0; i < body.Parts().count();++i) {
157 o << s << " " << q << "Byte"; 172 o << s << " " << q << "Byte";
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;
163 curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist()); 179 curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist());
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 }
169} 187}
170} 188}
171 189
172 190
173void ViewMail::slotShowHtml( bool state ) { 191void ViewMail::slotShowHtml( bool state )
192{
174 m_showHtml = state; 193 m_showHtml = state;
175 setText(); 194 setText();
176} 195}
177 196
178void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) { 197void 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;
185 } 206 }
186 QPopupMenu *menu = new QPopupMenu(); 207 QPopupMenu *menu = new QPopupMenu();
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 }
192 menu->insertItem( tr( "Save Attachment" ), 0 ); 214 menu->insertItem( tr( "Save Attachment" ), 0 );
@@ -194,16 +216,20 @@ void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int
194 216
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);
209 output.writeBlock(content->Content(),content->Length()); 235 output.writeBlock(content->Content(),content->Length());
@@ -215,10 +241,14 @@ void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int
215 break ; 241 break ;
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 }
224 } 254 }
@@ -228,7 +258,8 @@ void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int
228} 258}
229 259
230 260
231void ViewMail::setMail( RecMail mail ) { 261void ViewMail::setMail( RecMail mail )
262{
232 263
233 m_recMail = mail; 264 m_recMail = mail;
234 265
@@ -264,7 +295,8 @@ ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl)
264 attachments->setSorting(-1); 295 attachments->setSorting(-1);
265} 296}
266 297
267void ViewMail::readConfig() { 298void ViewMail::readConfig()
299{
268 Config cfg( "mail" ); 300 Config cfg( "mail" );
269 cfg.setGroup( "Settings" ); 301 cfg.setGroup( "Settings" );
270 m_showHtml = cfg.readBoolEntry( "showHtml", false ); 302 m_showHtml = cfg.readBoolEntry( "showHtml", false );
@@ -278,13 +310,16 @@ void ViewMail::setText()
278 QString ccString; 310 QString ccString;
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 }
290 325
@@ -300,9 +335,12 @@ void ViewMail::setText()
300 "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + 335 "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] +
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 }
308 // remove later in favor of a real handling 346 // remove later in favor of a real handling
@@ -320,7 +358,8 @@ void ViewMail::hide()
320{ 358{
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();
326 365
@@ -332,7 +371,8 @@ void ViewMail::exec()
332{ 371{
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();
338 } 378 }
@@ -351,7 +391,8 @@ QString ViewMail::deHtml(const QString &string)
351 391
352void ViewMail::slotReply() 392void 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;
357 } 398 }
@@ -364,7 +405,8 @@ void ViewMail::slotReply()
364 QString text = m_mail[2]; 405 QString text = m_mail[2];
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 }
370 rtext += "\n"; 412 rtext += "\n";
@@ -378,15 +420,16 @@ void ViewMail::slotReply()
378 composer.setTo( m_mail[0] ); 420 composer.setTo( m_mail[0] );
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 }
385} 427}
386 428
387void ViewMail::slotForward() 429void 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;
392 } 435 }
@@ -413,15 +456,15 @@ void ViewMail::slotForward()
413 ComposeMail composer( settings ,this, 0, true); 456 ComposeMail composer( settings ,this, 0, true);
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}
421 463
422void ViewMail::slotDeleteMail( ) 464void 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();
427 deleted = true; 470 deleted = true;