summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/viewmail.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp
index 5206220..a89393c 100644
--- a/noncore/net/mail/viewmail.cpp
+++ b/noncore/net/mail/viewmail.cpp
@@ -1,578 +1,580 @@
1#include "composemail.h" 1#include "composemail.h"
2#include "viewmail.h" 2#include "viewmail.h"
3 3
4#include <libmailwrapper/settings.h> 4#include <libmailwrapper/settings.h>
5#include <libmailwrapper/abstractmail.h> 5#include <libmailwrapper/abstractmail.h>
6#include <libmailwrapper/mailtypes.h> 6#include <libmailwrapper/mailtypes.h>
7 7
8/* OPIE */ 8/* OPIE */
9#include <opie2/odebug.h> 9#include <opie2/odebug.h>
10#include <opie2/ofiledialog.h> 10#include <opie2/ofiledialog.h>
11#include <opie2/oimagescrollview.h> 11#include <opie2/oimagescrollview.h>
12#include <qpe/config.h> 12#include <qpe/config.h>
13#include <qpe/qpeapplication.h> 13#include <qpe/qpeapplication.h>
14 14
15/* QT */ 15/* QT */
16#include <qtextbrowser.h> 16#include <qtextbrowser.h>
17#include <qmessagebox.h> 17#include <qmessagebox.h>
18#include <qtextstream.h> 18#include <qtextstream.h>
19#include <qaction.h> 19#include <qaction.h>
20#include <qpopupmenu.h> 20#include <qpopupmenu.h>
21#include <qfile.h> 21#include <qfile.h>
22#include <qlayout.h> 22#include <qlayout.h>
23#include <qstylesheet.h> 23#include <qstylesheet.h>
24 24
25using namespace Opie::Ui; 25using namespace Opie::Ui;
26using namespace Opie::Core; 26using namespace Opie::Core;
27 27
28AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, 28AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file,
29 const QString&fsize,int num,const QValueList<int>&path) 29 const QString&fsize,int num,const QValueList<int>&path)
30 : QListViewItem(parent,after),_partNum(num) 30 : QListViewItem(parent,after),_partNum(num)
31{ 31{
32 _path=path; 32 _path=path;
33 setText(0, mime); 33 setText(0, mime);
34 setText(1, desc); 34 setText(1, desc);
35 setText(2, file); 35 setText(2, file);
36 setText(3, fsize); 36 setText(3, fsize);
37} 37}
38 38
39AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, 39AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file,
40 const QString&fsize,int num,const QValueList<int>&path) 40 const QString&fsize,int num,const QValueList<int>&path)
41 : QListViewItem(parent,after),_partNum(num) 41 : QListViewItem(parent,after),_partNum(num)
42{ 42{
43 _path=path; 43 _path=path;
44 setText(0, mime); 44 setText(0, mime);
45 setText(1, desc); 45 setText(1, desc);
46 setText(2, file); 46 setText(2, file);
47 setText(3, fsize); 47 setText(3, fsize);
48} 48}
49 49
50bool AttachItem::isParentof(const QValueList<int>&path) 50bool AttachItem::isParentof(const QValueList<int>&path)
51{ 51{
52 /* if not set, then no parent */ 52 /* if not set, then no parent */
53 if (path.count()==0||_path.count()==0) return false; 53 if (path.count()==0||_path.count()==0) return false;
54 /* the parent must have one digit less then a child */ 54 /* the parent must have one digit less then a child */
55 if (path.count()!=_path.count()+1) return false; 55 if (path.count()!=_path.count()+1) return false;
56 for (unsigned int i=0; i < _path.count();++i) 56 for (unsigned int i=0; i < _path.count();++i)
57 { 57 {
58 if (_path[i]!=path[i]) return false; 58 if (_path[i]!=path[i]) return false;
59 } 59 }
60 return true; 60 return true;
61} 61}
62 62
63AttachItem* ViewMail::searchParent(const QValueList<int>&path) 63AttachItem* ViewMail::searchParent(const QValueList<int>&path)
64{ 64{
65 QListViewItemIterator it( attachments ); 65 QListViewItemIterator it( attachments );
66 for ( ; it.current(); ++it ) 66 for ( ; it.current(); ++it )
67 { 67 {
68 AttachItem*ati = (AttachItem*)it.current(); 68 AttachItem*ati = (AttachItem*)it.current();
69 if (ati->isParentof(path)) return ati; 69 if (ati->isParentof(path)) return ati;
70 } 70 }
71 return 0; 71 return 0;
72} 72}
73 73
74AttachItem* ViewMail::lastChild(AttachItem*parent) 74AttachItem* ViewMail::lastChild(AttachItem*parent)
75{ 75{
76 if (!parent) return 0; 76 if (!parent) return 0;
77 AttachItem* item = (AttachItem*)parent->firstChild(); 77 AttachItem* item = (AttachItem*)parent->firstChild();
78 if (!item) return item; 78 if (!item) return item;
79 AttachItem*temp=0; 79 AttachItem*temp=0;
80 while( (temp=(AttachItem*)item->nextSibling())) 80 while( (temp=(AttachItem*)item->nextSibling()))
81 { 81 {
82 item = temp; 82 item = temp;
83 } 83 }
84 return item; 84 return item;
85} 85}
86 86
87void ViewMail::setBody(const RecBodyP&body ) 87void ViewMail::setBody(const RecBodyP&body )
88{ 88{
89 89
90 m_body = body; 90 m_body = body;
91 m_mail[2] = body->Bodytext(); 91 m_mail[2] = body->Bodytext();
92 attachbutton->setEnabled(body->Parts().count()>0); 92 attachbutton->setEnabled(body->Parts().count()>0);
93 attachments->setEnabled(body->Parts().count()>0); 93 attachments->setEnabled(body->Parts().count()>0);
94 if (body->Parts().count()==0) 94 if (body->Parts().count()==0)
95 { 95 {
96 return; 96 return;
97 } 97 }
98 AttachItem * curItem=0; 98 AttachItem * curItem=0;
99 AttachItem * parentItem = 0; 99 AttachItem * parentItem = 0;
100 QString type=body->Description()->Type()+"/"+body->Description()->Subtype(); 100 QString type=body->Description()->Type()+"/"+body->Description()->Subtype();
101 QString desc,fsize; 101 QString desc,fsize;
102 double s = body->Description()->Size(); 102 double s = body->Description()->Size();
103 int w; 103 int w;
104 w=0; 104 w=0;
105 105
106 while (s>1024) 106 while (s>1024)
107 { 107 {
108 s/=1024; 108 s/=1024;
109 ++w; 109 ++w;
110 if (w>=2) break; 110 if (w>=2) break;
111 } 111 }
112 112
113 QString q=""; 113 QString q="";
114 switch(w) 114 switch(w)
115 { 115 {
116 case 1: 116 case 1:
117 q="k"; 117 q="k";
118 break; 118 break;
119 case 2: 119 case 2:
120 q="M"; 120 q="M";
121 break; 121 break;
122 default: 122 default:
123 break; 123 break;
124 } 124 }
125 125
126 { 126 {
127 /* I did not found a method to make a CONTENT reset on a QTextStream 127 /* I did not found a method to make a CONTENT reset on a QTextStream
128 so I use this construct that the stream will re-constructed in each 128 so I use this construct that the stream will re-constructed in each
129 loop. To let it work, the textstream is packed into a own area of 129 loop. To let it work, the textstream is packed into a own area of
130 code is it will be destructed after finishing its small job. 130 code is it will be destructed after finishing its small job.
131 */ 131 */
132 QTextOStream o(&fsize); 132 QTextOStream o(&fsize);
133 if (w>0) o.precision(2); else o.precision(0); 133 if (w>0) o.precision(2); else o.precision(0);
134 o.setf(QTextStream::fixed); 134 o.setf(QTextStream::fixed);
135 o << s << " " << q << "Byte"; 135 o << s << " " << q << "Byte";
136 } 136 }
137 137
138 curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body->Description()->Positionlist()); 138 curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1,body->Description()->Positionlist());
139 QString filename = ""; 139 QString filename = "";
140 140
141 for (unsigned int i = 0; i < body->Parts().count();++i) 141 for (unsigned int i = 0; i < body->Parts().count();++i)
142 { 142 {
143 filename = ""; 143 filename = "";
144 type = body->Parts()[i]->Type()+"/"+body->Parts()[i]->Subtype(); 144 type = body->Parts()[i]->Type()+"/"+body->Parts()[i]->Subtype();
145 part_plist_t::ConstIterator it = body->Parts()[i]->Parameters().begin(); 145 part_plist_t::ConstIterator it = body->Parts()[i]->Parameters().begin();
146 for (;it!=body->Parts()[i]->Parameters().end();++it) 146 for (;it!=body->Parts()[i]->Parameters().end();++it)
147 { 147 {
148 odebug << it.key() << oendl; 148 odebug << it.key() << oendl;
149 if (it.key().lower()=="name") 149 if (it.key().lower()=="name")
150 { 150 {
151 filename=it.data(); 151 filename=it.data();
152 } 152 }
153 } 153 }
154 s = body->Parts()[i]->Size(); 154 s = body->Parts()[i]->Size();
155 w = 0; 155 w = 0;
156 while (s>1024) 156 while (s>1024)
157 { 157 {
158 s/=1024; 158 s/=1024;
159 ++w; 159 ++w;
160 if (w>=2) break; 160 if (w>=2) break;
161 } 161 }
162 switch(w) 162 switch(w)
163 { 163 {
164 case 1: 164 case 1:
165 q="k"; 165 q="k";
166 break; 166 break;
167 case 2: 167 case 2:
168 q="M"; 168 q="M";
169 break; 169 break;
170 default: 170 default:
171 q=""; 171 q="";
172 break; 172 break;
173 } 173 }
174 QTextOStream o(&fsize); 174 QTextOStream o(&fsize);
175 if (w>0) o.precision(2); else o.precision(0); 175 if (w>0) o.precision(2); else o.precision(0);
176 o.setf(QTextStream::fixed); 176 o.setf(QTextStream::fixed);
177 o << s << " " << q << "Byte"; 177 o << s << " " << q << "Byte";
178 desc = body->Parts()[i]->Description(); 178 desc = body->Parts()[i]->Description();
179 parentItem = searchParent(body->Parts()[i]->Positionlist()); 179 parentItem = searchParent(body->Parts()[i]->Positionlist());
180 if (parentItem) 180 if (parentItem)
181 { 181 {
182 AttachItem*temp = lastChild(parentItem); 182 AttachItem*temp = lastChild(parentItem);
183 if (temp) curItem = temp; 183 if (temp) curItem = temp;
184 curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); 184 curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist());
185 attachments->setRootIsDecorated(true); 185 attachments->setRootIsDecorated(true);
186 curItem = parentItem; 186 curItem = parentItem;
187 } 187 }
188 else 188 else
189 { 189 {
190 curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist()); 190 curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body->Parts()[i]->Positionlist());
191 } 191 }
192 } 192 }
193} 193}
194 194
195 195
196void ViewMail::slotShowHtml( bool state ) 196void ViewMail::slotShowHtml( bool state )
197{ 197{
198 m_showHtml = state; 198 m_showHtml = state;
199 m_lasttextpart=-2;
199 setMainText(); 200 setMainText();
200} 201}
201 202
202void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) 203void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int )
203{ 204{
204 if (!item ) 205 if (!item )
205 return; 206 return;
206 207
207 if ( ( ( AttachItem* )item )->Partnumber() == -1 ) 208 if ( ( ( AttachItem* )item )->Partnumber() == -1 )
208 { 209 {
209 setMainText(); 210 setMainText();
210 return; 211 return;
211 } 212 }
212 QPopupMenu *menu = new QPopupMenu(); 213 QPopupMenu *menu = new QPopupMenu();
213 int ret=0; 214 int ret=0;
214 215
215 if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) 216 if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" )
216 { 217 {
217 menu->insertItem( tr( "Show Text" ), 1 ); 218 menu->insertItem( tr( "Show Text" ), 1 );
218 } 219 }
219 if (item->text(0).left(6)=="image/") { 220 if (item->text(0).left(6)=="image/") {
220 menu->insertItem(tr("Display image preview"),2); 221 menu->insertItem(tr("Display image preview"),2);
221 } 222 }
222 menu->insertItem( tr( "Save Attachment" ), 0 ); 223 menu->insertItem( tr( "Save Attachment" ), 0 );
223 menu->insertSeparator(1); 224 menu->insertSeparator(1);
224 225
225 ret = menu->exec( point, 0 ); 226 ret = menu->exec( point, 0 );
226 227
227 switch(ret) 228 switch(ret)
228 { 229 {
229 case 0: 230 case 0:
230 { 231 {
231 MimeTypes types; 232 MimeTypes types;
232 types.insert( "all", "*" ); 233 types.insert( "all", "*" );
233 QString str = OFileDialog::getSaveFileName( 1, 234 QString str = OFileDialog::getSaveFileName( 1,
234 "/", item->text( 2 ) , types, 0 ); 235 "/", item->text( 2 ) , types, 0 );
235 236
236 if( !str.isEmpty() ) 237 if( !str.isEmpty() )
237 { 238 {
238 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); 239 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] );
239 if (content) 240 if (content)
240 { 241 {
241 QFile output(str); 242 QFile output(str);
242 output.open(IO_WriteOnly); 243 output.open(IO_WriteOnly);
243 output.writeBlock(content->Content(),content->Length()); 244 output.writeBlock(content->Content(),content->Length());
244 output.close(); 245 output.close();
245 delete content; 246 delete content;
246 } 247 }
247 } 248 }
248 } 249 }
249 break ; 250 break ;
250 251
251 case 2: 252 case 2:
252 { 253 {
253 if (m_lastimagepart== (( AttachItem* )item )->Partnumber()) { 254 if (m_lastimagepart== (( AttachItem* )item )->Partnumber()) {
254 if (m_lastdlg) { 255 if (m_lastdlg) {
255 setUpdatesEnabled(false); 256 setUpdatesEnabled(false);
256 browser->hide(); 257 browser->hide();
257 m_lastdlg->show(); 258 m_lastdlg->show();
258 setUpdatesEnabled(true); 259 setUpdatesEnabled(true);
259 return; 260 return;
260 } 261 }
261 } 262 }
262 QString tmpfile = QString("/tmp/opiemail-image-%1").arg(_icounter++); 263 QString tmpfile = QString("/tmp/opiemail-image-%1").arg(_icounter++);
263 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); 264 encodedString*content = m_recMail->Wrapper()->fetchDecodedPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] );
264 if (content && content->Length()) { 265 if (content && content->Length()) {
265 QFile output(tmpfile); 266 QFile output(tmpfile);
266 output.open(IO_WriteOnly); 267 output.open(IO_WriteOnly);
267 output.writeBlock(content->Content(),content->Length()); 268 output.writeBlock(content->Content(),content->Length());
268 output.close(); 269 output.close();
269 delete content; 270 delete content;
270 if (!m_PicsInline) { 271 if (!m_PicsInline) {
271 MailImageDlg iview(""); 272 MailImageDlg iview("");
272 iview.setName(tmpfile); 273 iview.setName(tmpfile);
273 QPEApplication::execDialog(&iview); 274 QPEApplication::execDialog(&iview);
274 } else { 275 } else {
275 if (!m_lastdlg) { 276 if (!m_lastdlg) {
276 m_lastdlg=new Opie::MM::OImageScrollView("",browser->parentWidget(),false); 277 m_lastdlg=new Opie::MM::OImageScrollView("",browser->parentWidget(),false);
277 m_lastdlg->setAutoScale(true); 278 m_lastdlg->setAutoScale(true);
278 } 279 }
279 //m_lastdlg->setImage(""); 280 //m_lastdlg->setImage("");
280 m_lastdlg->setImage(tmpfile); 281 m_lastdlg->setImage(tmpfile);
281 browser->hide(); 282 browser->hide();
282 m_lastdlg->show(); 283 m_lastdlg->show();
283 } 284 }
284 output.remove(); 285 output.remove();
285 } else { 286 } else {
286 QMessageBox::critical(this, tr("Reading attachment"), tr("Could not read content of attachment")); 287 QMessageBox::critical(this, tr("Reading attachment"), tr("Could not read content of attachment"));
287 } 288 }
288 m_lastimagepart=(( AttachItem* )item )->Partnumber(); 289 m_lastimagepart=(( AttachItem* )item )->Partnumber();
289 } 290 }
290 break; 291 break;
291 case 1: 292 case 1:
292 if ( ( ( AttachItem* )item )->Partnumber() == -1 ) 293 if ( ( ( AttachItem* )item )->Partnumber() == -1 )
293 { 294 {
294 setMainText(); 295 setMainText();
295 } 296 }
296 else 297 else
297 { 298 {
298 if ( m_recMail->Wrapper() != 0l ) 299 if ( m_recMail->Wrapper() != 0l )
299 { // make sure that there is a wrapper , even after delete or simular actions 300 { // make sure that there is a wrapper , even after delete or simular actions
300 if (m_lastdlg) { 301 if (m_lastdlg) {
301 m_lastdlg->hide(); 302 m_lastdlg->hide();
302 browser->show(); 303 browser->show();
303 } 304 }
304 if (m_lasttextpart == ( ( AttachItem* )item )->Partnumber() ) return; 305 if (m_lasttextpart == ( ( AttachItem* )item )->Partnumber() ) return;
305 m_lasttextpart = ( ( AttachItem* )item )->Partnumber(); 306 m_lasttextpart = ( ( AttachItem* )item )->Partnumber();
306 QString s = m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] );; 307 QString s = m_recMail->Wrapper()->fetchTextPart( m_recMail, m_body->Parts()[ ( ( AttachItem* )item )->Partnumber() ] );;
307 if (item->text(0).right(4)!="html") { 308 if (item->text(0).right(4)!="html") {
308 s = QString("<html><body>\n<font face=fixed>%1</font></body></html>").arg(QStyleSheet::convertFromPlainText(s)); 309 s = QString("<html><body>\n<font face=fixed>%1</font></body></html>").arg(QStyleSheet::convertFromPlainText(s));
309 } 310 }
310 browser->setText(s); 311 browser->setText(s);
311 } 312 }
312 } 313 }
313 break; 314 break;
314 } 315 }
315 delete menu; 316 delete menu;
316} 317}
317 318
318 319
319void ViewMail::setMail(const RecMailP&mail ) 320void ViewMail::setMail(const RecMailP&mail )
320{ 321{
321 322
322 m_recMail = mail; 323 m_recMail = mail;
323 324
324 m_mail[0] = mail->getFrom(); 325 m_mail[0] = mail->getFrom();
325 m_mail[1] = mail->getSubject(); 326 m_mail[1] = mail->getSubject();
326 m_mail[3] = mail->getStringDate(); 327 m_mail[3] = mail->getStringDate();
327 m_mail[4] = mail->Msgid(); 328 m_mail[4] = mail->Msgid();
328 329
329 m_mail2[0] = mail->To(); 330 m_mail2[0] = mail->To();
330 m_mail2[1] = mail->CC(); 331 m_mail2[1] = mail->CC();
331 m_mail2[2] = mail->Bcc(); 332 m_mail2[2] = mail->Bcc();
332 333
333 setCaption(tr("E-Mail by %1").arg( m_mail[0] ) ); 334 setCaption(tr("E-Mail by %1").arg( m_mail[0] ) );
335 m_lasttextpart=-2;
334 setMainText(); 336 setMainText();
335} 337}
336 338
337 339
338 340
339ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) 341ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl)
340 : ViewMailBase(parent, name, fl), _inLoop(false) 342 : ViewMailBase(parent, name, fl), _inLoop(false)
341{ 343{
342 m_gotBody = false; 344 m_gotBody = false;
343 deleted = false; 345 deleted = false;
344 346
345 connect( reply, SIGNAL(activated()), SLOT(slotReply())); 347 connect( reply, SIGNAL(activated()), SLOT(slotReply()));
346 connect( forward, SIGNAL(activated()), SLOT(slotForward())); 348 connect( forward, SIGNAL(activated()), SLOT(slotForward()));
347 connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) ); 349 connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail() ) );
348 connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) ); 350 connect( showHtml, SIGNAL( toggled(bool) ), SLOT( slotShowHtml(bool) ) );
349 connect( showPicsInline, SIGNAL( toggled(bool) ), SLOT( slotImageInline(bool) ) ); 351 connect( showPicsInline, SIGNAL( toggled(bool) ), SLOT( slotImageInline(bool) ) );
350 352
351 attachments->setEnabled(m_gotBody); 353 attachments->setEnabled(m_gotBody);
352 connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) ); 354 connect( attachments, SIGNAL( clicked(QListViewItem*,const QPoint&, int) ), SLOT( slotItemClicked(QListViewItem*,const QPoint&, int) ) );
353 m_lastdlg = 0; 355 m_lastdlg = 0;
354 _icounter = 0; 356 _icounter = 0;
355 m_lastimagepart = -1; 357 m_lastimagepart = -1;
356 m_lasttextpart = -2; 358 m_lasttextpart = -2;
357 359
358 readConfig(); 360 readConfig();
359 attachments->setSorting(-1); 361 attachments->setSorting(-1);
360} 362}
361 363
362void ViewMail::slotImageInline(bool how) 364void ViewMail::slotImageInline(bool how)
363{ 365{
364 Config cfg( "mail" ); 366 Config cfg( "mail" );
365 cfg.writeEntry( "showPicsInline", how); 367 cfg.writeEntry( "showPicsInline", how);
366 m_PicsInline = how; 368 m_PicsInline = how;
367 if (m_lastdlg&&!how) { 369 if (m_lastdlg&&!how) {
368 browser->show(); 370 browser->show();
369 m_lastdlg->hide(); 371 m_lastdlg->hide();
370 m_lastdlg->reparent(0,QPoint(0,0),false); 372 m_lastdlg->reparent(0,QPoint(0,0),false);
371 delete m_lastdlg; 373 delete m_lastdlg;
372 m_lastdlg = 0; 374 m_lastdlg = 0;
373 m_lastimagepart = -1; 375 m_lastimagepart = -1;
374 } 376 }
375} 377}
376 378
377void ViewMail::readConfig() 379void ViewMail::readConfig()
378{ 380{
379 Config cfg( "mail" ); 381 Config cfg( "mail" );
380 cfg.setGroup( "Settings" ); 382 cfg.setGroup( "Settings" );
381 m_showHtml = cfg.readBoolEntry( "showHtml", false ); 383 m_showHtml = cfg.readBoolEntry( "showHtml", false );
382 m_PicsInline = cfg.readBoolEntry( "showPicsInline", true ); 384 m_PicsInline = cfg.readBoolEntry( "showPicsInline", true );
383 showPicsInline->setOn(m_PicsInline); 385 showPicsInline->setOn(m_PicsInline);
384 showHtml->setOn( m_showHtml ); 386 showHtml->setOn( m_showHtml );
385} 387}
386 388
387void ViewMail::setMainText() 389void ViewMail::setMainText()
388{ 390{
389 QString toString; 391 QString toString;
390 QString ccString; 392 QString ccString;
391 QString bccString; 393 QString bccString;
392 QString mailHtml; 394 QString mailHtml;
393 395
394 if (m_lastdlg) { 396 if (m_lastdlg) {
395 m_lastdlg->hide(); 397 m_lastdlg->hide();
396 } 398 }
397 browser->show(); 399 browser->show();
398 if (m_lasttextpart == -1) return; 400 if (m_lasttextpart == -1) return;
399 m_lasttextpart = -1; 401 m_lasttextpart = -1;
400 for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) 402 for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it )
401 { 403 {
402 toString += (*it); 404 toString += (*it);
403 } 405 }
404 for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) 406 for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it )
405 { 407 {
406 ccString += (*it); 408 ccString += (*it);
407 } 409 }
408 for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) 410 for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it )
409 { 411 {
410 bccString += (*it); 412 bccString += (*it);
411 } 413 }
412 browser->setTextFormat(Qt::RichText); 414 browser->setTextFormat(Qt::RichText);
413 mailHtml = "<html><body>" 415 mailHtml = "<html><body>"
414 "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" 416 "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>"
415 "<div align=left><b>" + deHtml(m_mail[1]) + "</b></div>" 417 "<div align=left><b>" + deHtml(m_mail[1]) + "</b></div>"
416 "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" 418 "</td></tr><tr bgcolor=\"#EEEEE6\"><td>"
417 "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" 419 "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>"
418 "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + 420 "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" +
419 tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" 421 tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>"
420 "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + 422 "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] +
421 "</td></tr></table>"; 423 "</td></tr></table>";
422 if ( !m_showHtml ) { 424 if ( !m_showHtml ) {
423 browser->setText( mailHtml+"<font face=fixed>" + QStyleSheet::convertFromPlainText(m_mail[2]) + "</font></body></html>" ); 425 browser->setText( mailHtml+"<font face=fixed>" + QStyleSheet::convertFromPlainText(m_mail[2]) + "</font></body></html>" );
424 } else { 426 } else {
425 browser->setText(mailHtml+m_mail[2].simplifyWhiteSpace()+"</html>"); 427 browser->setText(mailHtml+m_mail[2].simplifyWhiteSpace()+"</html>");
426 } 428 }
427 // remove later in favor of a real handling 429 // remove later in favor of a real handling
428 m_gotBody = true; 430 m_gotBody = true;
429} 431}
430 432
431 433
432ViewMail::~ViewMail() 434ViewMail::~ViewMail()
433{ 435{
434 m_recMail->Wrapper()->cleanMimeCache(); 436 m_recMail->Wrapper()->cleanMimeCache();
435 hide(); 437 hide();
436} 438}
437 439
438void ViewMail::hide() 440void ViewMail::hide()
439{ 441{
440 QWidget::hide(); 442 QWidget::hide();
441 443
442 if (_inLoop) 444 if (_inLoop)
443 { 445 {
444 _inLoop = false; 446 _inLoop = false;
445 qApp->exit_loop(); 447 qApp->exit_loop();
446 448
447 } 449 }
448 450
449} 451}
450 452
451void ViewMail::exec() 453void ViewMail::exec()
452{ 454{
453 show(); 455 show();
454 456
455 if (!_inLoop) 457 if (!_inLoop)
456 { 458 {
457 _inLoop = true; 459 _inLoop = true;
458 qApp->enter_loop(); 460 qApp->enter_loop();
459 } 461 }
460 462
461} 463}
462 464
463QString ViewMail::deHtml(const QString &aString) 465QString ViewMail::deHtml(const QString &aString)
464{ 466{
465 QString string_ = aString; 467 QString string_ = aString;
466 string_.replace(QRegExp("&"), "&amp;"); 468 string_.replace(QRegExp("&"), "&amp;");
467 string_.replace(QRegExp("<"), "&lt;"); 469 string_.replace(QRegExp("<"), "&lt;");
468 string_.replace(QRegExp(">"), "&gt;"); 470 string_.replace(QRegExp(">"), "&gt;");
469 string_.replace(QRegExp("\\n"), "<br>"); 471 string_.replace(QRegExp("\\n"), "<br>");
470 return string_; 472 return string_;
471} 473}
472 474
473void ViewMail::slotReply() 475void ViewMail::slotReply()
474{ 476{
475 if (!m_gotBody) 477 if (!m_gotBody)
476 { 478 {
477 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); 479 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok"));
478 return; 480 return;
479 } 481 }
480 482
481 QString rtext; 483 QString rtext;
482 rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose 484 rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose
483 .arg( m_mail[0] ) 485 .arg( m_mail[0] )
484 .arg( m_mail[3] ); 486 .arg( m_mail[3] );
485 487
486 QString text = m_mail[2]; 488 QString text = m_mail[2];
487 QStringList lines = QStringList::split(QRegExp("\\n"), text); 489 QStringList lines = QStringList::split(QRegExp("\\n"), text);
488 QStringList::Iterator it; 490 QStringList::Iterator it;
489 for (it = lines.begin(); it != lines.end(); it++) 491 for (it = lines.begin(); it != lines.end(); it++)
490 { 492 {
491 rtext += "> " + *it + "\n"; 493 rtext += "> " + *it + "\n";
492 } 494 }
493 rtext += "\n"; 495 rtext += "\n";
494 496
495 QString prefix; 497 QString prefix;
496 if ( m_mail[1].find(QRegExp("^Re: .*$")) != -1) prefix = ""; 498 if ( m_mail[1].find(QRegExp("^Re: .*$")) != -1) prefix = "";
497 else prefix = "Re: "; // no i18n on purpose 499 else prefix = "Re: "; // no i18n on purpose
498 500
499 Settings *settings = new Settings(); 501 Settings *settings = new Settings();
500 ComposeMail composer( settings ,this, 0, true); 502 ComposeMail composer( settings ,this, 0, true);
501 if (m_recMail->Replyto().isEmpty()) { 503 if (m_recMail->Replyto().isEmpty()) {
502 composer.setTo( m_recMail->getFrom()); 504 composer.setTo( m_recMail->getFrom());
503 } else { 505 } else {
504 composer.setTo( m_recMail->Replyto()); 506 composer.setTo( m_recMail->Replyto());
505 } 507 }
506 composer.setSubject( prefix + m_mail[1] ); 508 composer.setSubject( prefix + m_mail[1] );
507 composer.setMessage( rtext ); 509 composer.setMessage( rtext );
508 composer.setInReplyTo(m_recMail->Msgid()); 510 composer.setInReplyTo(m_recMail->Msgid());
509 511
510 if ( QDialog::Accepted == QPEApplication::execDialog( &composer ) ) 512 if ( QDialog::Accepted == QPEApplication::execDialog( &composer ) )
511 { 513 {
512 m_recMail->Wrapper()->answeredMail(m_recMail); 514 m_recMail->Wrapper()->answeredMail(m_recMail);
513 } 515 }
514} 516}
515 517
516void ViewMail::slotForward() 518void ViewMail::slotForward()
517{ 519{
518 if (!m_gotBody) 520 if (!m_gotBody)
519 { 521 {
520 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); 522 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok"));
521 return; 523 return;
522 } 524 }
523 525
524 QString ftext; 526 QString ftext;
525 ftext += QString("\n----- Forwarded message from %1 -----\n\n") 527 ftext += QString("\n----- Forwarded message from %1 -----\n\n")
526 .arg( m_mail[0] ); 528 .arg( m_mail[0] );
527 if (!m_mail[3].isNull()) 529 if (!m_mail[3].isNull())
528 ftext += QString("Date: %1\n") 530 ftext += QString("Date: %1\n")
529 .arg( m_mail[3] ); 531 .arg( m_mail[3] );
530 if (!m_mail[0].isNull()) 532 if (!m_mail[0].isNull())
531 ftext += QString("From: %1\n") 533 ftext += QString("From: %1\n")
532 .arg( m_mail[0] ); 534 .arg( m_mail[0] );
533 if (!m_mail[1].isNull()) 535 if (!m_mail[1].isNull())
534 ftext += QString("Subject: %1\n") 536 ftext += QString("Subject: %1\n")
535 .arg( m_mail[1] ); 537 .arg( m_mail[1] );
536 538
537 ftext += QString("\n%1\n") 539 ftext += QString("\n%1\n")
538 .arg( m_mail[2]); 540 .arg( m_mail[2]);
539 541
540 ftext += QString("----- End forwarded message -----\n"); 542 ftext += QString("----- End forwarded message -----\n");
541 543
542 Settings *settings = new Settings(); 544 Settings *settings = new Settings();
543 ComposeMail composer( settings ,this, 0, true); 545 ComposeMail composer( settings ,this, 0, true);
544 composer.setSubject( "Fwd: " + m_mail[1] ); 546 composer.setSubject( "Fwd: " + m_mail[1] );
545 composer.setMessage( ftext ); 547 composer.setMessage( ftext );
546 if ( QDialog::Accepted == QPEApplication::execDialog( &composer )) 548 if ( QDialog::Accepted == QPEApplication::execDialog( &composer ))
547 { 549 {
548 } 550 }
549} 551}
550 552
551void ViewMail::slotDeleteMail( ) 553void ViewMail::slotDeleteMail( )
552{ 554{
553 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 ) 555 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 )
554 { 556 {
555 m_recMail->Wrapper()->deleteMail( m_recMail ); 557 m_recMail->Wrapper()->deleteMail( m_recMail );
556 hide(); 558 hide();
557 deleted = true; 559 deleted = true;
558 } 560 }
559} 561}
560 562
561MailImageDlg::MailImageDlg(const QString&fname,QWidget *parent, const char *name, bool modal, WFlags f) 563MailImageDlg::MailImageDlg(const QString&fname,QWidget *parent, const char *name, bool modal, WFlags f)
562 : Opie::Ui::ODialog(parent,name,modal,f) 564 : Opie::Ui::ODialog(parent,name,modal,f)
563{ 565{
564 QVBoxLayout*dlglayout = new QVBoxLayout(this); 566 QVBoxLayout*dlglayout = new QVBoxLayout(this);
565 dlglayout->setSpacing(2); 567 dlglayout->setSpacing(2);
566 dlglayout->setMargin(1); 568 dlglayout->setMargin(1);
567 m_imageview = new Opie::MM::OImageScrollView(this); 569 m_imageview = new Opie::MM::OImageScrollView(this);
568 dlglayout->addWidget(m_imageview); 570 dlglayout->addWidget(m_imageview);
569} 571}
570 572
571MailImageDlg::~MailImageDlg() 573MailImageDlg::~MailImageDlg()
572{ 574{
573} 575}
574 576
575void MailImageDlg::setName(const QString&fname) 577void MailImageDlg::setName(const QString&fname)
576{ 578{
577 m_imageview->setImage(fname); 579 m_imageview->setImage(fname);
578} 580}