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