summaryrefslogtreecommitdiffabout
path: root/kmicromail/viewmail.cpp
authorzautrix <zautrix>2005-01-24 16:32:44 (UTC)
committer zautrix <zautrix>2005-01-24 16:32:44 (UTC)
commit6c89efd80c1e94a0c070025d07c7a4c656f2a81e (patch) (unidiff)
tree44e8cac0fe7b117be19ec8c1f14c9c888838fdb3 /kmicromail/viewmail.cpp
parentd4f5ce1bedd03191da5ecef2dc68381c10ef1fba (diff)
downloadkdepimpi-6c89efd80c1e94a0c070025d07c7a4c656f2a81e.zip
kdepimpi-6c89efd80c1e94a0c070025d07c7a4c656f2a81e.tar.gz
kdepimpi-6c89efd80c1e94a0c070025d07c7a4c656f2a81e.tar.bz2
view source
Diffstat (limited to 'kmicromail/viewmail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/viewmail.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/kmicromail/viewmail.cpp b/kmicromail/viewmail.cpp
index 6d88cad..767a369 100644
--- a/kmicromail/viewmail.cpp
+++ b/kmicromail/viewmail.cpp
@@ -142,271 +142,293 @@ void ViewMail::setBody(const RecBodyP&body )
142 */ 142 */
143 QTextOStream o(&fsize); 143 QTextOStream o(&fsize);
144 if (w>0) o.precision(2); else o.precision(0); 144 if (w>0) o.precision(2); else o.precision(0);
145 o.setf(QTextStream::fixed); 145 o.setf(QTextStream::fixed);
146 o << s << " " << q << "Byte"; 146 o << s << " " << q << "Byte";
147 } 147 }
148 148
149 curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body->Description()->Positionlist()); 149 curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body->Description()->Positionlist());
150 QString filename = ""; 150 QString filename = "";
151 151
152 for (unsigned int i = 0; i < body->Parts().count();++i) 152 for (unsigned int i = 0; i < body->Parts().count();++i)
153 { 153 {
154 filename = ""; 154 filename = "";
155 type = body->Parts()[i]->Type()+"/"+body->Parts()[i]->Subtype(); 155 type = body->Parts()[i]->Type()+"/"+body->Parts()[i]->Subtype();
156 part_plist_t::ConstIterator it = body->Parts()[i]->Parameters().begin(); 156 part_plist_t::ConstIterator it = body->Parts()[i]->Parameters().begin();
157 for (;it!=body->Parts()[i]->Parameters().end();++it) 157 for (;it!=body->Parts()[i]->Parameters().end();++it)
158 { 158 {
159 if (it.key().lower()=="name") 159 if (it.key().lower()=="name")
160 { 160 {
161 filename=it.data(); 161 filename=it.data();
162 } 162 }
163 } 163 }
164 s = body->Parts()[i]->Size(); 164 s = body->Parts()[i]->Size();
165 w = 0; 165 w = 0;
166 while (s>1024) 166 while (s>1024)
167 { 167 {
168 s/=1024; 168 s/=1024;
169 ++w; 169 ++w;
170 if (w>=2) break; 170 if (w>=2) break;
171 } 171 }
172 switch(w) 172 switch(w)
173 { 173 {
174 case 1: 174 case 1:
175 q="k"; 175 q="k";
176 break; 176 break;
177 case 2: 177 case 2:
178 q="M"; 178 q="M";
179 break; 179 break;
180 default: 180 default:
181 q=""; 181 q="";
182 break; 182 break;
183 } 183 }
184 QTextOStream o(&fsize); 184 QTextOStream o(&fsize);
185 if (w>0) o.precision(2); else o.precision(0); 185 if (w>0) o.precision(2); else o.precision(0);
186 o.setf(QTextStream::fixed); 186 o.setf(QTextStream::fixed);
187 o << s << " " << q << "Byte"; 187 o << s << " " << q << "Byte";
188 desc = body->Parts()[i]->Description(); 188 desc = body->Parts()[i]->Description();
189 parentItem = searchParent(body->Parts()[i]->Positionlist()); 189 parentItem = searchParent(body->Parts()[i]->Positionlist());
190 if (parentItem) 190 if (parentItem)
191 { 191 {
192 AttachItem*temp = lastChild(parentItem); 192 AttachItem*temp = lastChild(parentItem);
193 if (temp) curItem = temp; 193 if (temp) curItem = temp;
194 curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); 194 curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist());
195 attachments->setRootIsDecorated(true); 195 attachments->setRootIsDecorated(true);
196 curItem = parentItem; 196 curItem = parentItem;
197 } 197 }
198 else 198 else
199 { 199 {
200 curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); 200 curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist());
201 } 201 }
202 } 202 }
203} 203}
204 204
205 205
206void ViewMail::slotViewSource()
207{
208
209 if ( !sourceOn ) {
210 sourceOn = true;
211 viewSource->setText(i18n("View Body Text"));
212 encodedString*st = 0;
213 st = m_recMail->Wrapper()->fetchRawBody(m_recMail);
214 if ( st ) {
215 QString source = QString::fromUtf8( st->Content(), st->Length());
216 browser->setText( source );
217 delete st;
218 }
219 } else
220 setText();
221
222
223}
206void ViewMail::slotShowHtml( bool state ) 224void ViewMail::slotShowHtml( bool state )
207{ 225{
208 m_showHtml = state; 226 m_showHtml = state;
209 setText(); 227 setText();
210} 228}
211 229
212void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) 230void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int )
213{ 231{
214 if (!item ) 232 if (!item )
215 return; 233 return;
216 234
217 if ( ( ( AttachItem* )item )->Partnumber() == -1 ) 235 if ( ( ( AttachItem* )item )->Partnumber() == -1 )
218 { 236 {
219 setText(); 237 setText();
220 return; 238 return;
221 } 239 }
222 QPopupMenu *menu = new QPopupMenu(); 240 QPopupMenu *menu = new QPopupMenu();
223 int ret=0; 241 int ret=0;
224 242
225 if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) 243 if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" )
226 { 244 {
227 menu->insertItem( i18n( "Show Text" ), 1 ); 245 menu->insertItem( i18n( "Show Text" ), 1 );
228 } 246 }
229 if (item->text(0).left(6)=="image/") { 247 if (item->text(0).left(6)=="image/") {
230 menu->insertItem(i18n("Display image preview"),2); 248 menu->insertItem(i18n("Display image preview"),2);
231 } 249 }
232 menu->insertItem( i18n( "Save Attachment" ), 0 ); 250 menu->insertItem( i18n( "Save Attachment" ), 0 );
233 menu->insertSeparator(1); 251 menu->insertSeparator(1);
234 252
235 ret = menu->exec( point, 0 ); 253 ret = menu->exec( point, 0 );
236 254
237 switch(ret) 255 switch(ret)
238 { 256 {
239 case 0: 257 case 0:
240 { 258 {
241 //MimeTypes types; 259 //MimeTypes types;
242 //types.insert( "all", "*" ); 260 //types.insert( "all", "*" );
243 QString str = KFileDialog::getSaveFileName( "/", item->text( 2 ), this ); 261 QString str = KFileDialog::getSaveFileName( "/", item->text( 2 ), this );
244 262
245 if( !str.isEmpty() ) 263 if( !str.isEmpty() )
246 { 264 {
247 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); 265 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] );
248 if (content) 266 if (content)
249 { 267 {
250 QFile output(str); 268 QFile output(str);
251 output.open(IO_WriteOnly); 269 output.open(IO_WriteOnly);
252 output.writeBlock(content->Content(),content->Length()); 270 output.writeBlock(content->Content(),content->Length());
253 output.close(); 271 output.close();
254 delete content; 272 delete content;
255 } 273 }
256 } 274 }
257 } 275 }
258 break ; 276 break ;
259 277
260 case 2: 278 case 2:
261 { 279 {
262#ifdef DESKTOP_VERSION 280#ifdef DESKTOP_VERSION
263 QString tmpfile = locateLocal( "tmp", "opiemail-image"); 281 QString tmpfile = locateLocal( "tmp", "opiemail-image");
264#else 282#else
265 QString tmpfile = "/tmp/opiemail-image"; 283 QString tmpfile = "/tmp/opiemail-image";
266#endif 284#endif
267 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); 285 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] );
268 if (content) { 286 if (content) {
269 QFile output(tmpfile); 287 QFile output(tmpfile);
270 output.open(IO_WriteOnly); 288 output.open(IO_WriteOnly);
271 output.writeBlock(content->Content(),content->Length()); 289 output.writeBlock(content->Content(),content->Length());
272 output.close(); 290 output.close();
273 delete content; 291 delete content;
274 MailImageDlg iview(""); 292 MailImageDlg iview("");
275 iview.setName(tmpfile); 293 iview.setName(tmpfile);
276 KApplication::execDialog(&iview); 294 KApplication::execDialog(&iview);
277 output.remove(); 295 output.remove();
278 } 296 }
279 } 297 }
280 break; 298 break;
281 case 1: 299 case 1:
282 if ( ( ( AttachItem* )item )->Partnumber() == -1 ) 300 if ( ( ( AttachItem* )item )->Partnumber() == -1 )
283 { 301 {
284 setText(); 302 setText();
285 } 303 }
286 else 304 else
287 { 305 {
288 if ( m_recMail->Wrapper() != 0l ) 306 if ( m_recMail->Wrapper() != 0l )
289 { // make sure that there is a wrapper , even after delete or simular actions 307 { // make sure that there is a wrapper , even after delete or simular actions
290 browser->setText( m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); 308 browser->setText( m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) );
291 } 309 }
292 } 310 }
293 break; 311 break;
294 } 312 }
295 delete menu; 313 delete menu;
296} 314}
297 315
298 316
299void ViewMail::setMail(const RecMailP&mail ) 317void ViewMail::setMail(const RecMailP&mail )
300{ 318{
301 319
302 m_recMail = mail; 320 m_recMail = mail;
303 321
304 m_mail[0] = mail->getFrom(); 322 m_mail[0] = mail->getFrom();
305 m_mail[1] = mail->getSubject(); 323 m_mail[1] = mail->getSubject();
306 m_mail[3] = mail->getDate(); 324 m_mail[3] = mail->getDate();
307 m_mail[4] = mail->Msgid(); 325 m_mail[4] = mail->Msgid();
308 326
309 m_mail2[0] = mail->To(); 327 m_mail2[0] = mail->To();
310 m_mail2[1] = mail->CC(); 328 m_mail2[1] = mail->CC();
311 m_mail2[2] = mail->Bcc(); 329 m_mail2[2] = mail->Bcc();
312 330
313 setText(); 331 setText();
314} 332}
315 333
316 334
317 335
318ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) 336ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl)
319 : ViewMailBase(parent, name, fl), _inLoop(false) 337 : ViewMailBase(parent, name, fl), _inLoop(false)
320{ 338{
321 m_gotBody = false; 339 m_gotBody = false;
322 deleted = false; 340 deleted = false;
323 341 sourceOn = false;
324 connect( reply, SIGNAL(activated()), SLOT(slotReply())); 342 connect( reply, SIGNAL(activated()), SLOT(slotReply()));
325 connect( forward, SIGNAL(activated()), SLOT(slotForward())); 343 connect( forward, SIGNAL(activated()), SLOT(slotForward()));
326 connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); 344 connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) );
327 connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); 345 connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) );
328 connect( closeMail, SIGNAL( activated() ), SLOT( close() ) ); 346 connect( closeMail, SIGNAL( activated() ), SLOT( close() ) );
329 connect( nextMail, SIGNAL( activated() ), SLOT( slotNextMail() ) ); 347 connect( nextMail, SIGNAL( activated() ), SLOT( slotNextMail() ) );
348 connect( viewSource, SIGNAL( activated() ), SLOT( slotViewSource() ) );
349 connect( downloadMail, SIGNAL( activated() ), SIGNAL( signalDownloadMail() ) );
330 350
331 attachments->setEnabled(m_gotBody); 351 attachments->setEnabled(m_gotBody);
332 connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); 352 connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) );
333 353
334 readConfig(); 354 readConfig();
335 attachments->setSorting(-1); 355 attachments->setSorting(-1);
336} 356}
337 357
338void ViewMail::readConfig() 358void ViewMail::readConfig()
339{ 359{
340 360
341 setFont ( KOPrefs::instance()->mReadFont ); 361 setFont ( KOPrefs::instance()->mReadFont );
342 m_showHtml = KOPrefs::instance()->mViewAsHtml; 362 m_showHtml = KOPrefs::instance()->mViewAsHtml;
343 showHtml->setOn( m_showHtml ); 363 showHtml->setOn( m_showHtml );
344} 364}
345 365
346void ViewMail::setText() 366void ViewMail::setText()
347{ 367{
348 368
369 viewSource->setText(i18n("View Source"));
370 sourceOn = false;
349 QString toString; 371 QString toString;
350 QString ccString; 372 QString ccString;
351 QString bccString; 373 QString bccString;
352 374
353 375
354 toString = m_mail2[0].join(","); 376 toString = m_mail2[0].join(",");
355 ccString = m_mail2[1].join(","); 377 ccString = m_mail2[1].join(",");
356 bccString = m_mail2[2].join(","); 378 bccString = m_mail2[2].join(",");
357 379
358 380
359 setCaption( i18n("E-Mail by %1").arg( m_mail[0] ) ); 381 setCaption( i18n("E-Mail by %1").arg( m_mail[0] ) );
360 382
361 m_mailHtml = "<html><body>" 383 m_mailHtml = "<html><body>"
362 "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" 384 "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>"
363 "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" 385 "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>"
364 "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" 386 "</td></tr><tr bgcolor=\"#EEEEE6\"><td>"
365 "<b>" + i18n( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" 387 "<b>" + i18n( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>"
366 "<b>" + i18n( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + 388 "<b>" + i18n( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" +
367 i18n( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" 389 i18n( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>"
368 "<b>" + i18n( "Date" ) + ": </b> " + m_mail[3] + 390 "<b>" + i18n( "Date" ) + ": </b> " + m_mail[3] +
369 "</td></tr></table><font>"; 391 "</td></tr></table><font>";
370 392
371 if ( !m_showHtml ) 393 if ( !m_showHtml )
372 { 394 {
373 browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); 395 browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" );
374 } 396 }
375 else 397 else
376 { 398 {
377 browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); 399 browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" );
378 } 400 }
379 // remove later in favor of a real handling 401 // remove later in favor of a real handling
380 m_gotBody = true; 402 m_gotBody = true;
381} 403}
382 404
383 405
384ViewMail::~ViewMail() 406ViewMail::~ViewMail()
385{ 407{
386 m_recMail->Wrapper()->cleanMimeCache(); 408 m_recMail->Wrapper()->cleanMimeCache();
387 hide(); 409 hide();
388} 410}
389 411
390void ViewMail::hide() 412void ViewMail::hide()
391{ 413{
392 QWidget::hide(); 414 QWidget::hide();
393 415
394 if (_inLoop) 416 if (_inLoop)
395 { 417 {
396 _inLoop = false; 418 _inLoop = false;
397 qApp->exit_loop(); 419 qApp->exit_loop();
398 420
399 } 421 }
400 422
401} 423}
402 424
403void ViewMail::exec() 425void ViewMail::exec()
404{ 426{
405 show(); 427 show();
406 428
407 if (!_inLoop) 429 if (!_inLoop)
408 { 430 {
409 _inLoop = true; 431 _inLoop = true;
410 qApp->enter_loop(); 432 qApp->enter_loop();
411 } 433 }
412 434
@@ -471,64 +493,65 @@ void ViewMail::slotForward()
471{ 493{
472 if (!m_gotBody) 494 if (!m_gotBody)
473 { 495 {
474 QMessageBox::information(this, i18n("Error"), i18n("<p>The mail body is not yet downloaded, so you cannot forward yet."), i18n("Ok")); 496 QMessageBox::information(this, i18n("Error"), i18n("<p>The mail body is not yet downloaded, so you cannot forward yet."), i18n("Ok"));
475 return; 497 return;
476 } 498 }
477 499
478 QString ftext; 500 QString ftext;
479 ftext += QString("\n----- Forwarded message from %1 -----\n\n") 501 ftext += QString("\n----- Forwarded message from %1 -----\n\n")
480 .arg( m_mail[0] ); 502 .arg( m_mail[0] );
481 if (!m_mail[3].isNull()) 503 if (!m_mail[3].isNull())
482 ftext += QString("Date: %1\n") 504 ftext += QString("Date: %1\n")
483 .arg( m_mail[3] ); 505 .arg( m_mail[3] );
484 if (!m_mail[0].isNull()) 506 if (!m_mail[0].isNull())
485 ftext += QString("From: %1\n") 507 ftext += QString("From: %1\n")
486 .arg( m_mail[0] ); 508 .arg( m_mail[0] );
487 if (!m_mail[1].isNull()) 509 if (!m_mail[1].isNull())
488 ftext += QString("Subject: %1\n") 510 ftext += QString("Subject: %1\n")
489 .arg( m_mail[1] ); 511 .arg( m_mail[1] );
490 512
491 ftext += QString("\n%1\n") 513 ftext += QString("\n%1\n")
492 .arg( m_mail[2]); 514 .arg( m_mail[2]);
493 515
494 ftext += QString("----- End forwarded message -----\n"); 516 ftext += QString("----- End forwarded message -----\n");
495 517
496 Settings *settings = new Settings(); 518 Settings *settings = new Settings();
497 ComposeMail composer( settings ,this, 0, true); 519 ComposeMail composer( settings ,this, 0, true);
498 composer.setSubject( "Fwd: " + m_mail[1] ); 520 composer.setSubject( "Fwd: " + m_mail[1] );
499 composer.setMessage( ftext ); 521 composer.setMessage( ftext );
500 if ( QDialog::Accepted == KApplication::execDialog( &composer )) 522 if ( QDialog::Accepted == KApplication::execDialog( &composer ))
501 { 523 {
502 } 524 }
503} 525}
504 526
505void ViewMail::slotDeleteMail( ) 527void ViewMail::slotDeleteMail( )
506{ 528{
507 if ( QMessageBox::warning(this, i18n("Delete Mail"), QString( i18n("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 529 if ( QMessageBox::warning(this, i18n("Delete Mail"), QString( i18n("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
508 { 530 {
509 emit deleteAndDisplayNextMail( this); 531 emit deleteAndDisplayNextMail( this);
510 //m_recMail->Wrapper()->deleteMail( m_recMail ); 532 //m_recMail->Wrapper()->deleteMail( m_recMail );
511 //hide(); 533 //hide();
512 deleted = true; 534 deleted = true;
513 } 535 }
514} 536}
515 537
516MailImageDlg::MailImageDlg(const QString&fname,QWidget *parent, const char *name, bool modal, WFlags f) 538MailImageDlg::MailImageDlg(const QString&fname,QWidget *parent, const char *name, bool modal, WFlags f)
517 : QDialog(parent,name,modal) 539 : QDialog(parent,name,modal)
518{ 540{
519 QVBoxLayout*dlglayout = new QVBoxLayout(this); 541 QVBoxLayout*dlglayout = new QVBoxLayout(this);
520 dlglayout->setSpacing(2); 542 dlglayout->setSpacing(2);
521 dlglayout->setMargin(1); 543 dlglayout->setMargin(1);
522 //m_imageview = new Opie::MM::OImageScrollView(this); 544 //m_imageview = new Opie::MM::OImageScrollView(this);
523 //dlglayout->addWidget(m_imageview); 545 //dlglayout->addWidget(m_imageview);
524} 546}
525 547
526MailImageDlg::~MailImageDlg() 548MailImageDlg::~MailImageDlg()
527{ 549{
528} 550}
529 551
530void MailImageDlg::setName(const QString&fname) 552void MailImageDlg::setName(const QString&fname)
531{ 553{
532 qDebug("viewmail.cpp: MailImageDlg::setName Pending"); 554 qDebug("viewmail.cpp: MailImageDlg::setName Pending");
533 // m_imageview->setImage(fname); 555 // m_imageview->setImage(fname);
534} 556}
557