summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/viewmail.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp
index 0947879..d86454c 100644
--- a/noncore/net/mail/viewmail.cpp
+++ b/noncore/net/mail/viewmail.cpp
@@ -1,347 +1,349 @@
1#include <qtextbrowser.h> 1#include <qtextbrowser.h>
2#include <qmessagebox.h> 2#include <qmessagebox.h>
3#include <qtextstream.h> 3#include <qtextstream.h>
4#include <qaction.h> 4#include <qaction.h>
5#include <qpopupmenu.h> 5#include <qpopupmenu.h>
6#include <qfile.h> 6#include <qfile.h>
7#include <qapplication.h> 7#include <qapplication.h>
8 8
9#include <opie/ofiledialog.h> 9#include <opie/ofiledialog.h>
10 10
11#include "settings.h" 11#include "settings.h"
12#include "composemail.h" 12#include "composemail.h"
13#include "viewmail.h" 13#include "viewmail.h"
14#include "abstractmail.h" 14#include "abstractmail.h"
15#include "accountview.h" 15#include "accountview.h"
16#include "mailtypes.h" 16#include "mailtypes.h"
17 17
18AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, 18AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file,
19 const QString&fsize,int num) 19 const QString&fsize,int num)
20 : QListViewItem(parent,after),_partNum(num) 20 : QListViewItem(parent,after),_partNum(num)
21{ 21{
22 setText(0, mime); 22 setText(0, mime);
23 setText(1, desc); 23 setText(1, desc);
24 setText(2, file); 24 setText(2, file);
25 setText(3, fsize); 25 setText(3, fsize);
26} 26}
27 27
28void ViewMail::setBody( RecBody body ) { 28void ViewMail::setBody( RecBody body ) {
29 29
30m_body = body; 30m_body = body;
31m_mail[2] = body.Bodytext(); 31m_mail[2] = body.Bodytext();
32attachbutton->setEnabled(body.Parts().count()>0); 32attachbutton->setEnabled(body.Parts().count()>0);
33attachments->setEnabled(body.Parts().count()>0); 33attachments->setEnabled(body.Parts().count()>0);
34if (body.Parts().count()==0) { 34if (body.Parts().count()==0) {
35 return; 35 return;
36} 36}
37AttachItem * curItem=0; 37AttachItem * curItem=0;
38QString type=body.Description().Type()+"/"+body.Description().Subtype(); 38QString type=body.Description().Type()+"/"+body.Description().Subtype();
39QString desc,fsize; 39QString desc,fsize;
40double s = body.Description().Size(); 40double s = body.Description().Size();
41int w; 41int w;
42w=0; 42w=0;
43 43
44while (s>1024) { 44while (s>1024) {
45 s/=1024; 45 s/=1024;
46 ++w; 46 ++w;
47 if (w>=2) break; 47 if (w>=2) break;
48} 48}
49 49
50QString q=""; 50QString q="";
51switch(w) { 51switch(w) {
52case 1: 52case 1:
53 q="k"; 53 q="k";
54 break; 54 break;
55case 2: 55case 2:
56 q="M"; 56 q="M";
57 break; 57 break;
58default: 58default:
59 break; 59 break;
60} 60}
61 61
62{ 62{
63 /* I did not found a method to make a CONTENT reset on a QTextStream 63 /* I did not found a method to make a CONTENT reset on a QTextStream
64 so I use this construct that the stream will re-constructed in each 64 so I use this construct that the stream will re-constructed in each
65 loop. To let it work, the textstream is packed into a own area of 65 loop. To let it work, the textstream is packed into a own area of
66 code is it will be destructed after finishing its small job. 66 code is it will be destructed after finishing its small job.
67 */ 67 */
68 QTextOStream o(&fsize); 68 QTextOStream o(&fsize);
69 if (w>0) o.precision(2); else o.precision(0); 69 if (w>0) o.precision(2); else o.precision(0);
70 o.setf(QTextStream::fixed); 70 o.setf(QTextStream::fixed);
71 o << s << " " << q << "Byte"; 71 o << s << " " << q << "Byte";
72} 72}
73 73
74curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1); 74curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1);
75QString filename = ""; 75QString filename = "";
76for (unsigned int i = 0; i < body.Parts().count();++i) { 76for (unsigned int i = 0; i < body.Parts().count();++i) {
77 type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); 77 type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype();
78 part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); 78 part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin();
79 for (;it!=body.Parts()[i].Parameters().end();++it) { 79 for (;it!=body.Parts()[i].Parameters().end();++it) {
80 qDebug(it.key()); 80 qDebug(it.key());
81 if (it.key().lower()=="name") { 81 if (it.key().lower()=="name") {
82 filename=it.data(); 82 filename=it.data();
83 } 83 }
84 } 84 }
85 s = body.Parts()[i].Size(); 85 s = body.Parts()[i].Size();
86 w = 0; 86 w = 0;
87 while (s>1024) { 87 while (s>1024) {
88 s/=1024; 88 s/=1024;
89 ++w; 89 ++w;
90 if (w>=2) break; 90 if (w>=2) break;
91 } 91 }
92 switch(w) { 92 switch(w) {
93 case 1: 93 case 1:
94 q="k"; 94 q="k";
95 break; 95 break;
96 case 2: 96 case 2:
97 q="M"; 97 q="M";
98 break; 98 break;
99 default: 99 default:
100 q=""; 100 q="";
101 break; 101 break;
102 } 102 }
103 QTextOStream o(&fsize); 103 QTextOStream o(&fsize);
104 if (w>0) o.precision(2); else o.precision(0); 104 if (w>0) o.precision(2); else o.precision(0);
105 o.setf(QTextStream::fixed); 105 o.setf(QTextStream::fixed);
106 o << s << " " << q << "Byte"; 106 o << s << " " << q << "Byte";
107 desc = body.Parts()[i].Description(); 107 desc = body.Parts()[i].Description();
108 curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i); 108 curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i);
109} 109}
110} 110}
111 111
112void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) { 112void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) {
113 if (!item ) 113 if (!item )
114 return; 114 return;
115 115
116 if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { 116 if ( ( ( AttachItem* )item )->Partnumber() == -1 ) {
117 setText(); 117 setText();
118 return; 118 return;
119 } 119 }
120 QPopupMenu *menu = new QPopupMenu(); 120 QPopupMenu *menu = new QPopupMenu();
121 int ret=0; 121 int ret=0;
122 122
123 if ( item->text( 0 ).left( 5 ) == "text/" ) { 123 if ( item->text( 0 ).left( 5 ) == "text/" ) {
124 menu->insertItem( tr( "Show Text" ), 1 ); 124 menu->insertItem( tr( "Show Text" ), 1 );
125 } 125 }
126 menu->insertItem( tr( "Save Attachment" ), 0 ); 126 menu->insertItem( tr( "Save Attachment" ), 0 );
127 menu->insertSeparator(1); 127 menu->insertSeparator(1);
128 128
129 ret = menu->exec( point, 0 ); 129 ret = menu->exec( point, 0 );
130 130
131 switch(ret) { 131 switch(ret) {
132 case 0: 132 case 0:
133 { MimeTypes types; 133 { MimeTypes types;
134 types.insert( "all", "*" ); 134 types.insert( "all", "*" );
135 QString str = OFileDialog::getSaveFileName( 1, 135 QString str = OFileDialog::getSaveFileName( 1,
136 "/", item->text( 2 ) , types, 0 ); 136 "/", item->text( 2 ) , types, 0 );
137 137
138 if( !str.isEmpty() ) { 138 if( !str.isEmpty() ) {
139 encodedString*content = m_recMail.Wrapper()->fetchDecodedPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); 139 encodedString*content = m_recMail.Wrapper()->fetchDecodedPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] );
140 if (content) { 140 if (content) {
141 QFile output(str); 141 QFile output(str);
142 output.open(IO_WriteOnly); 142 output.open(IO_WriteOnly);
143 output.writeBlock(content->Content(),content->Length()); 143 output.writeBlock(content->Content(),content->Length());
144 output.close(); 144 output.close();
145 delete content; 145 delete content;
146 } 146 }
147 } 147 }
148 } 148 }
149 break ; 149 break ;
150 150
151 case 1: 151 case 1:
152 if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { 152 if ( ( ( AttachItem* )item )->Partnumber() == -1 ) {
153 setText(); 153 setText();
154 } else { 154 } else {
155 if ( m_recMail.Wrapper() != 0l ) { // make sure that there is a wrapper , even after delete or simular actions 155 if ( m_recMail.Wrapper() != 0l ) { // make sure that there is a wrapper , even after delete or simular actions
156 browser->setText( m_recMail.Wrapper()->fetchTextPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); 156 browser->setText( m_recMail.Wrapper()->fetchTextPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) );
157 } 157 }
158 } 158 }
159 break; 159 break;
160 } 160 }
161 delete menu; 161 delete menu;
162} 162}
163 163
164 164
165void ViewMail::setMail( RecMail mail ) { 165void ViewMail::setMail( RecMail mail ) {
166 166
167m_recMail = mail; 167m_recMail = mail;
168 168
169m_mail[0] = mail.getFrom(); 169m_mail[0] = mail.getFrom();
170m_mail[1] = mail.getSubject(); 170m_mail[1] = mail.getSubject();
171m_mail[3] = mail.getDate(); 171m_mail[3] = mail.getDate();
172m_mail[4] = mail.Msgid(); 172m_mail[4] = mail.Msgid();
173 173
174m_mail2[0] = mail.To(); 174m_mail2[0] = mail.To();
175m_mail2[1] = mail.CC(); 175m_mail2[1] = mail.CC();
176m_mail2[2] = mail.Bcc(); 176m_mail2[2] = mail.Bcc();
177 177
178setText(); 178setText();
179} 179}
180 180
181 181
182 182
183ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) 183ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl)
184 : ViewMailBase(parent, name, fl), _inLoop(false) 184 : ViewMailBase(parent, name, fl), _inLoop(false)
185{ 185{
186 m_gotBody = false; 186 m_gotBody = false;
187 deleted = false;
187 188
188 connect(reply, SIGNAL(activated()), SLOT(slotReply())); 189 connect(reply, SIGNAL(activated()), SLOT(slotReply()));
189 connect(forward, SIGNAL(activated()), SLOT(slotForward())); 190 connect(forward, SIGNAL(activated()), SLOT(slotForward()));
190 connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail( ) ) ); 191 connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail( ) ) );
191 192
192 attachments->setEnabled(m_gotBody); 193 attachments->setEnabled(m_gotBody);
193 connect( attachments, SIGNAL( clicked ( QListViewItem *, const QPoint & , int ) ), SLOT( slotItemClicked( QListViewItem *, const QPoint & , int ) ) ); 194 connect( attachments, SIGNAL( clicked ( QListViewItem *, const QPoint & , int ) ), SLOT( slotItemClicked( QListViewItem *, const QPoint & , int ) ) );
194 195
196
195} 197}
196 198
197void ViewMail::setText() 199void ViewMail::setText()
198{ 200{
199 201
200 QString toString; 202 QString toString;
201 QString ccString; 203 QString ccString;
202 QString bccString; 204 QString bccString;
203 205
204 for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) { 206 for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) {
205 toString += (*it); 207 toString += (*it);
206 } 208 }
207 for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) { 209 for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) {
208 ccString += (*it); 210 ccString += (*it);
209 } 211 }
210 for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) { 212 for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) {
211 bccString += (*it); 213 bccString += (*it);
212 } 214 }
213 215
214 setCaption( caption().arg( m_mail[0] ) ); 216 setCaption( caption().arg( m_mail[0] ) );
215 217
216 m_mailHtml = "<html><body>" 218 m_mailHtml = "<html><body>"
217 "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" 219 "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>"
218 "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" 220 "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>"
219 "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" 221 "</td></tr><tr bgcolor=\"#EEEEE6\"><td>"
220 "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" 222 "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>"
221 "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + 223 "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" +
222 tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" 224 tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>"
223 "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + 225 "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] +
224 "</td></tr></table><font face=fixed>"; 226 "</td></tr></table><font face=fixed>";
225 227
226 browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); 228 browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" );
227 // remove later in favor of a real handling 229 // remove later in favor of a real handling
228 m_gotBody = true; 230 m_gotBody = true;
229} 231}
230 232
231 233
232ViewMail::~ViewMail() 234ViewMail::~ViewMail()
233{ 235{
234 hide(); 236 hide();
235} 237}
236 238
237void ViewMail::hide() 239void ViewMail::hide()
238{ 240{
239 QWidget::hide(); 241 QWidget::hide();
240 242
241 if (_inLoop) { 243 if (_inLoop) {
242 _inLoop = false; 244 _inLoop = false;
243 qApp->exit_loop(); 245 qApp->exit_loop();
244 246
245 } 247 }
246 248
247} 249}
248 250
249void ViewMail::exec() 251void ViewMail::exec()
250{ 252{
251 show(); 253 show();
252 254
253 if (!_inLoop) { 255 if (!_inLoop) {
254 _inLoop = true; 256 _inLoop = true;
255 qApp->enter_loop(); 257 qApp->enter_loop();
256 } 258 }
257 259
258} 260}
259 261
260QString ViewMail::deHtml(const QString &string) 262QString ViewMail::deHtml(const QString &string)
261{ 263{
262 QString string_ = string; 264 QString string_ = string;
263 string_.replace(QRegExp("&"), "&amp;"); 265 string_.replace(QRegExp("&"), "&amp;");
264 string_.replace(QRegExp("<"), "&lt;"); 266 string_.replace(QRegExp("<"), "&lt;");
265 string_.replace(QRegExp(">"), "&gt;"); 267 string_.replace(QRegExp(">"), "&gt;");
266 string_.replace(QRegExp("\\n"), "<br>"); 268 string_.replace(QRegExp("\\n"), "<br>");
267 return string_; 269 return string_;
268} 270}
269 271
270void ViewMail::slotReply() 272void ViewMail::slotReply()
271{ 273{
272 if (!m_gotBody) { 274 if (!m_gotBody) {
273 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); 275 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok"));
274 return; 276 return;
275 } 277 }
276 278
277 QString rtext; 279 QString rtext;
278 rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose 280 rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose
279 .arg( m_mail[0] ) 281 .arg( m_mail[0] )
280 .arg( m_mail[3] ); 282 .arg( m_mail[3] );
281 283
282 QString text = m_mail[2]; 284 QString text = m_mail[2];
283 QStringList lines = QStringList::split(QRegExp("\\n"), text); 285 QStringList lines = QStringList::split(QRegExp("\\n"), text);
284 QStringList::Iterator it; 286 QStringList::Iterator it;
285 for (it = lines.begin(); it != lines.end(); it++) { 287 for (it = lines.begin(); it != lines.end(); it++) {
286 rtext += "> " + *it + "\n"; 288 rtext += "> " + *it + "\n";
287 } 289 }
288 rtext += "\n"; 290 rtext += "\n";
289 291
290 QString prefix; 292 QString prefix;
291 if ( m_mail[1].find(QRegExp("^Re: *$")) != -1) prefix = ""; 293 if ( m_mail[1].find(QRegExp("^Re: *$")) != -1) prefix = "";
292 else prefix = "Re: "; // no i18n on purpose 294 else prefix = "Re: "; // no i18n on purpose
293 295
294 Settings *settings = new Settings(); 296 Settings *settings = new Settings();
295 ComposeMail composer( settings ,this, 0, true); 297 ComposeMail composer( settings ,this, 0, true);
296 composer.setTo( m_mail[0] ); 298 composer.setTo( m_mail[0] );
297 composer.setSubject( "Re: " + m_mail[1] ); 299 composer.setSubject( "Re: " + m_mail[1] );
298 composer.setMessage( rtext ); 300 composer.setMessage( rtext );
299 composer.showMaximized(); 301 composer.showMaximized();
300 if ( QDialog::Accepted==composer.exec()) { 302 if ( QDialog::Accepted==composer.exec()) {
301 m_recMail.Wrapper()->answeredMail(m_recMail); 303 m_recMail.Wrapper()->answeredMail(m_recMail);
302 } 304 }
303} 305}
304 306
305void ViewMail::slotForward() 307void ViewMail::slotForward()
306{ 308{
307 if (!m_gotBody) { 309 if (!m_gotBody) {
308 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); 310 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok"));
309 return; 311 return;
310 } 312 }
311 313
312 QString ftext; 314 QString ftext;
313 ftext += QString("\n----- Forwarded message from %1 -----\n\n") 315 ftext += QString("\n----- Forwarded message from %1 -----\n\n")
314 .arg( m_mail[0] ); 316 .arg( m_mail[0] );
315 if (!m_mail[3].isNull()) 317 if (!m_mail[3].isNull())
316 ftext += QString("Date: %1\n") 318 ftext += QString("Date: %1\n")
317 .arg( m_mail[3] ); 319 .arg( m_mail[3] );
318 if (!m_mail[0].isNull()) 320 if (!m_mail[0].isNull())
319 ftext += QString("From: %1\n") 321 ftext += QString("From: %1\n")
320 .arg( m_mail[0] ); 322 .arg( m_mail[0] );
321 if (!m_mail[1].isNull()) 323 if (!m_mail[1].isNull())
322 ftext += QString("Subject: %1\n") 324 ftext += QString("Subject: %1\n")
323 .arg( m_mail[1] ); 325 .arg( m_mail[1] );
324 326
325 ftext += QString("\n%1\n") 327 ftext += QString("\n%1\n")
326 .arg( m_mail[2]); 328 .arg( m_mail[2]);
327 329
328 ftext += QString("----- End forwarded message -----\n"); 330 ftext += QString("----- End forwarded message -----\n");
329 331
330 Settings *settings = new Settings(); 332 Settings *settings = new Settings();
331 ComposeMail composer( settings ,this, 0, true); 333 ComposeMail composer( settings ,this, 0, true);
332 composer.setSubject( "Fwd: " + m_mail[1] ); 334 composer.setSubject( "Fwd: " + m_mail[1] );
333 composer.setMessage( ftext ); 335 composer.setMessage( ftext );
334 composer.showMaximized(); 336 composer.showMaximized();
335 if ( QDialog::Accepted==composer.exec()) { 337 if ( QDialog::Accepted==composer.exec()) {
336 338
337 } 339 }
338} 340}
339 341
340void ViewMail::slotDeleteMail( ) 342void ViewMail::slotDeleteMail( )
341{ 343{
342 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 ) { 344 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 ) {
343 m_recMail.Wrapper()->deleteMail( m_recMail ); 345 m_recMail.Wrapper()->deleteMail( m_recMail );
344 hide(); 346 hide();
345 deleted = true; 347 deleted = true;
346 } 348 }
347} 349}