-rw-r--r-- | kmicromail/viewmail.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/kmicromail/viewmail.cpp b/kmicromail/viewmail.cpp index 3bd6f41..60c764c 100644 --- a/kmicromail/viewmail.cpp +++ b/kmicromail/viewmail.cpp | |||
@@ -200,257 +200,258 @@ void ViewMail::setBody(const RecBodyP&body ) | |||
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 | ||
206 | void ViewMail::slotShowHtml( bool state ) | 206 | void ViewMail::slotShowHtml( bool state ) |
207 | { | 207 | { |
208 | m_showHtml = state; | 208 | m_showHtml = state; |
209 | setText(); | 209 | setText(); |
210 | } | 210 | } |
211 | 211 | ||
212 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) | 212 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) |
213 | { | 213 | { |
214 | if (!item ) | 214 | if (!item ) |
215 | return; | 215 | return; |
216 | 216 | ||
217 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) | 217 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) |
218 | { | 218 | { |
219 | setText(); | 219 | setText(); |
220 | return; | 220 | return; |
221 | } | 221 | } |
222 | QPopupMenu *menu = new QPopupMenu(); | 222 | QPopupMenu *menu = new QPopupMenu(); |
223 | int ret=0; | 223 | int ret=0; |
224 | 224 | ||
225 | if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) | 225 | if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) |
226 | { | 226 | { |
227 | menu->insertItem( i18n( "Show Text" ), 1 ); | 227 | menu->insertItem( i18n( "Show Text" ), 1 ); |
228 | } | 228 | } |
229 | if (item->text(0).left(6)=="image/") { | 229 | if (item->text(0).left(6)=="image/") { |
230 | menu->insertItem(i18n("Display image preview"),2); | 230 | menu->insertItem(i18n("Display image preview"),2); |
231 | } | 231 | } |
232 | menu->insertItem( i18n( "Save Attachment" ), 0 ); | 232 | menu->insertItem( i18n( "Save Attachment" ), 0 ); |
233 | menu->insertSeparator(1); | 233 | menu->insertSeparator(1); |
234 | 234 | ||
235 | ret = menu->exec( point, 0 ); | 235 | ret = menu->exec( point, 0 ); |
236 | 236 | ||
237 | switch(ret) | 237 | switch(ret) |
238 | { | 238 | { |
239 | case 0: | 239 | case 0: |
240 | { | 240 | { |
241 | //MimeTypes types; | 241 | //MimeTypes types; |
242 | //types.insert( "all", "*" ); | 242 | //types.insert( "all", "*" ); |
243 | QString str = KFileDialog::getSaveFileName( "/", item->text( 2 ), this ); | 243 | QString str = KFileDialog::getSaveFileName( "/", item->text( 2 ), this ); |
244 | 244 | ||
245 | if( !str.isEmpty() ) | 245 | if( !str.isEmpty() ) |
246 | { | 246 | { |
247 | encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); | 247 | encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); |
248 | if (content) | 248 | if (content) |
249 | { | 249 | { |
250 | QFile output(str); | 250 | QFile output(str); |
251 | output.open(IO_WriteOnly); | 251 | output.open(IO_WriteOnly); |
252 | output.writeBlock(content->Content(),content->Length()); | 252 | output.writeBlock(content->Content(),content->Length()); |
253 | output.close(); | 253 | output.close(); |
254 | delete content; | 254 | delete content; |
255 | } | 255 | } |
256 | } | 256 | } |
257 | } | 257 | } |
258 | break ; | 258 | break ; |
259 | 259 | ||
260 | case 2: | 260 | case 2: |
261 | { | 261 | { |
262 | #ifdef DESKTOP_VERSION | 262 | #ifdef DESKTOP_VERSION |
263 | QString tmpfile = locateLocal( "tmp", "opiemail-image"); | 263 | QString tmpfile = locateLocal( "tmp", "opiemail-image"); |
264 | #else | 264 | #else |
265 | QString tmpfile = "/tmp/opiemail-image"; | 265 | QString tmpfile = "/tmp/opiemail-image"; |
266 | #endif | 266 | #endif |
267 | encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); | 267 | encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); |
268 | if (content) { | 268 | if (content) { |
269 | QFile output(tmpfile); | 269 | QFile output(tmpfile); |
270 | output.open(IO_WriteOnly); | 270 | output.open(IO_WriteOnly); |
271 | output.writeBlock(content->Content(),content->Length()); | 271 | output.writeBlock(content->Content(),content->Length()); |
272 | output.close(); | 272 | output.close(); |
273 | delete content; | 273 | delete content; |
274 | MailImageDlg iview(""); | 274 | MailImageDlg iview(""); |
275 | iview.setName(tmpfile); | 275 | iview.setName(tmpfile); |
276 | KApplication::execDialog(&iview); | 276 | KApplication::execDialog(&iview); |
277 | output.remove(); | 277 | output.remove(); |
278 | } | 278 | } |
279 | } | 279 | } |
280 | break; | 280 | break; |
281 | case 1: | 281 | case 1: |
282 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) | 282 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) |
283 | { | 283 | { |
284 | setText(); | 284 | setText(); |
285 | } | 285 | } |
286 | else | 286 | else |
287 | { | 287 | { |
288 | if ( m_recMail->Wrapper() != 0l ) | 288 | if ( m_recMail->Wrapper() != 0l ) |
289 | { // make sure that there is a wrapper , even after delete or simular actions | 289 | { // 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() ] ) ); | 290 | browser->setText( m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); |
291 | } | 291 | } |
292 | } | 292 | } |
293 | break; | 293 | break; |
294 | } | 294 | } |
295 | delete menu; | 295 | delete menu; |
296 | } | 296 | } |
297 | 297 | ||
298 | 298 | ||
299 | void ViewMail::setMail(const RecMailP&mail ) | 299 | void ViewMail::setMail(const RecMailP&mail ) |
300 | { | 300 | { |
301 | 301 | ||
302 | m_recMail = mail; | 302 | m_recMail = mail; |
303 | 303 | ||
304 | m_mail[0] = mail->getFrom(); | 304 | m_mail[0] = mail->getFrom(); |
305 | m_mail[1] = mail->getSubject(); | 305 | m_mail[1] = mail->getSubject(); |
306 | m_mail[3] = mail->getDate(); | 306 | m_mail[3] = mail->getDate(); |
307 | m_mail[4] = mail->Msgid(); | 307 | m_mail[4] = mail->Msgid(); |
308 | 308 | ||
309 | m_mail2[0] = mail->To(); | 309 | m_mail2[0] = mail->To(); |
310 | m_mail2[1] = mail->CC(); | 310 | m_mail2[1] = mail->CC(); |
311 | m_mail2[2] = mail->Bcc(); | 311 | m_mail2[2] = mail->Bcc(); |
312 | 312 | ||
313 | setText(); | 313 | setText(); |
314 | } | 314 | } |
315 | 315 | ||
316 | 316 | ||
317 | 317 | ||
318 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) | 318 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) |
319 | : ViewMailBase(parent, name, fl), _inLoop(false) | 319 | : ViewMailBase(parent, name, fl), _inLoop(false) |
320 | { | 320 | { |
321 | m_gotBody = false; | 321 | m_gotBody = false; |
322 | deleted = false; | 322 | deleted = false; |
323 | 323 | ||
324 | connect( reply, SIGNAL(activated()), SLOT(slotReply())); | 324 | connect( reply, SIGNAL(activated()), SLOT(slotReply())); |
325 | connect( forward, SIGNAL(activated()), SLOT(slotForward())); | 325 | connect( forward, SIGNAL(activated()), SLOT(slotForward())); |
326 | connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); | 326 | connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); |
327 | connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); | 327 | connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); |
328 | connect( closeMail, SIGNAL( activated() ), SLOT( close() ) ); | 328 | connect( closeMail, SIGNAL( activated() ), SLOT( close() ) ); |
329 | connect( nextMail, SIGNAL( activated() ), SLOT( slotNextMail() ) ); | ||
329 | 330 | ||
330 | attachments->setEnabled(m_gotBody); | 331 | attachments->setEnabled(m_gotBody); |
331 | connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); | 332 | connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); |
332 | 333 | ||
333 | readConfig(); | 334 | readConfig(); |
334 | attachments->setSorting(-1); | 335 | attachments->setSorting(-1); |
335 | } | 336 | } |
336 | 337 | ||
337 | void ViewMail::readConfig() | 338 | void ViewMail::readConfig() |
338 | { | 339 | { |
339 | 340 | ||
340 | setFont ( KOPrefs::instance()->mReadFont ); | 341 | setFont ( KOPrefs::instance()->mReadFont ); |
341 | m_showHtml = KOPrefs::instance()->mViewAsHtml; | 342 | m_showHtml = KOPrefs::instance()->mViewAsHtml; |
342 | showHtml->setOn( m_showHtml ); | 343 | showHtml->setOn( m_showHtml ); |
343 | } | 344 | } |
344 | 345 | ||
345 | void ViewMail::setText() | 346 | void ViewMail::setText() |
346 | { | 347 | { |
347 | 348 | ||
348 | QString toString; | 349 | QString toString; |
349 | QString ccString; | 350 | QString ccString; |
350 | QString bccString; | 351 | QString bccString; |
351 | 352 | ||
352 | 353 | ||
353 | toString = m_mail2[0].join(","); | 354 | toString = m_mail2[0].join(","); |
354 | ccString = m_mail2[1].join(","); | 355 | ccString = m_mail2[1].join(","); |
355 | bccString = m_mail2[2].join(","); | 356 | bccString = m_mail2[2].join(","); |
356 | 357 | ||
357 | 358 | ||
358 | setCaption( i18n("E-Mail by %1").arg( m_mail[0] ) ); | 359 | setCaption( i18n("E-Mail by %1").arg( m_mail[0] ) ); |
359 | 360 | ||
360 | m_mailHtml = "<html><body>" | 361 | m_mailHtml = "<html><body>" |
361 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" | 362 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" |
362 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" | 363 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" |
363 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" | 364 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" |
364 | "<b>" + i18n( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" | 365 | "<b>" + i18n( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" |
365 | "<b>" + i18n( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + | 366 | "<b>" + i18n( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + |
366 | i18n( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" | 367 | i18n( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" |
367 | "<b>" + i18n( "Date" ) + ": </b> " + m_mail[3] + | 368 | "<b>" + i18n( "Date" ) + ": </b> " + m_mail[3] + |
368 | "</td></tr></table><font>"; | 369 | "</td></tr></table><font>"; |
369 | 370 | ||
370 | if ( !m_showHtml ) | 371 | if ( !m_showHtml ) |
371 | { | 372 | { |
372 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); | 373 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); |
373 | } | 374 | } |
374 | else | 375 | else |
375 | { | 376 | { |
376 | browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); | 377 | browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); |
377 | } | 378 | } |
378 | // remove later in favor of a real handling | 379 | // remove later in favor of a real handling |
379 | m_gotBody = true; | 380 | m_gotBody = true; |
380 | } | 381 | } |
381 | 382 | ||
382 | 383 | ||
383 | ViewMail::~ViewMail() | 384 | ViewMail::~ViewMail() |
384 | { | 385 | { |
385 | m_recMail->Wrapper()->cleanMimeCache(); | 386 | m_recMail->Wrapper()->cleanMimeCache(); |
386 | hide(); | 387 | hide(); |
387 | } | 388 | } |
388 | 389 | ||
389 | void ViewMail::hide() | 390 | void ViewMail::hide() |
390 | { | 391 | { |
391 | QWidget::hide(); | 392 | QWidget::hide(); |
392 | 393 | ||
393 | if (_inLoop) | 394 | if (_inLoop) |
394 | { | 395 | { |
395 | _inLoop = false; | 396 | _inLoop = false; |
396 | qApp->exit_loop(); | 397 | qApp->exit_loop(); |
397 | 398 | ||
398 | } | 399 | } |
399 | 400 | ||
400 | } | 401 | } |
401 | 402 | ||
402 | void ViewMail::exec() | 403 | void ViewMail::exec() |
403 | { | 404 | { |
404 | show(); | 405 | show(); |
405 | 406 | ||
406 | if (!_inLoop) | 407 | if (!_inLoop) |
407 | { | 408 | { |
408 | _inLoop = true; | 409 | _inLoop = true; |
409 | qApp->enter_loop(); | 410 | qApp->enter_loop(); |
410 | } | 411 | } |
411 | 412 | ||
412 | } | 413 | } |
413 | 414 | ||
414 | QString ViewMail::deHtml(const QString &string) | 415 | QString ViewMail::deHtml(const QString &string) |
415 | { | 416 | { |
416 | QString string_ = string; | 417 | QString string_ = string; |
417 | string_.replace(QRegExp("&"), "&"); | 418 | string_.replace(QRegExp("&"), "&"); |
418 | string_.replace(QRegExp("<"), "<"); | 419 | string_.replace(QRegExp("<"), "<"); |
419 | string_.replace(QRegExp(">"), ">"); | 420 | string_.replace(QRegExp(">"), ">"); |
420 | string_.replace(QRegExp("\\n"), "<br>"); | 421 | string_.replace(QRegExp("\\n"), "<br>"); |
421 | return string_; | 422 | return string_; |
422 | } | 423 | } |
423 | 424 | ||
424 | void ViewMail::slotReply() | 425 | void ViewMail::slotReply() |
425 | { | 426 | { |
426 | if (!m_gotBody) | 427 | if (!m_gotBody) |
427 | { | 428 | { |
428 | QMessageBox::information(this, i18n("Error"), i18n("<p>The mail body is not yet downloaded, so you cannot reply yet."), i18n("Ok")); | 429 | QMessageBox::information(this, i18n("Error"), i18n("<p>The mail body is not yet downloaded, so you cannot reply yet."), i18n("Ok")); |
429 | return; | 430 | return; |
430 | } | 431 | } |
431 | 432 | ||
432 | QString rtext; | 433 | QString rtext; |
433 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose | 434 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose |
434 | .arg( m_mail[0] ) | 435 | .arg( m_mail[0] ) |
435 | .arg( m_mail[3] ); | 436 | .arg( m_mail[3] ); |
436 | 437 | ||
437 | QString text = m_mail[2]; | 438 | QString text = m_mail[2]; |
438 | QStringList lines = QStringList::split(QRegExp("\\n"), text); | 439 | QStringList lines = QStringList::split(QRegExp("\\n"), text); |
439 | QStringList::Iterator it; | 440 | QStringList::Iterator it; |
440 | for (it = lines.begin(); it != lines.end(); it++) | 441 | for (it = lines.begin(); it != lines.end(); it++) |
441 | { | 442 | { |
442 | rtext += "> " + *it + "\n"; | 443 | rtext += "> " + *it + "\n"; |
443 | } | 444 | } |
444 | rtext += "\n"; | 445 | rtext += "\n"; |
445 | 446 | ||
446 | QString prefix; | 447 | QString prefix; |
447 | if ( m_mail[1].find(QRegExp("^Re: .*$")) != -1) prefix = ""; | 448 | if ( m_mail[1].find(QRegExp("^Re: .*$")) != -1) prefix = ""; |
448 | else prefix = "Re: "; // no i18n on purpose | 449 | else prefix = "Re: "; // no i18n on purpose |
449 | 450 | ||
450 | Settings *settings = new Settings(); | 451 | Settings *settings = new Settings(); |
451 | ComposeMail composer( settings ,this, 0, true); | 452 | ComposeMail composer( settings ,this, 0, true); |
452 | if (m_recMail->Replyto().isEmpty()) { | 453 | if (m_recMail->Replyto().isEmpty()) { |
453 | composer.setTo(m_recMail->getFrom()); | 454 | composer.setTo(m_recMail->getFrom()); |
454 | } else { | 455 | } else { |
455 | composer.setTo(m_recMail->Replyto()); | 456 | composer.setTo(m_recMail->Replyto()); |
456 | } | 457 | } |