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