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