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