summaryrefslogtreecommitdiff
path: root/noncore/net/mail/viewmail.cpp
Unidiff
Diffstat (limited to 'noncore/net/mail/viewmail.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/mail/viewmail.cpp216
1 files changed, 216 insertions, 0 deletions
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp
new file mode 100644
index 0000000..b648b34
--- a/dev/null
+++ b/noncore/net/mail/viewmail.cpp
@@ -0,0 +1,216 @@
1#include <qtextbrowser.h>
2#include <qmessagebox.h>
3#include <qaction.h>
4#include <qapplication.h>
5
6//#include "mailfactory.h"
7//#include "composer.h"
8#include "viewmail.h"
9
10AttachItem::AttachItem(QListView *parent, AttachItemStore &attachItemStore)
11 : QListViewItem(parent), _attachItemStore(attachItemStore)
12{
13 setText(0, _attachItemStore.mimeType());
14 setText(1, _attachItemStore.fileName());
15 setText(2, _attachItemStore.description());
16}
17
18AttachItem::AttachItem(QListViewItem *parent, AttachItemStore &attachItemStore)
19 : QListViewItem(parent), _attachItemStore(attachItemStore)
20{
21 setText(0, _attachItemStore.mimeType());
22 setText(1, _attachItemStore.fileName());
23 setText(2, _attachItemStore.description());
24}
25
26void ViewMail::setMailInfo( const QString & from, const QString & to, const QString & subject, const QString & cc, const QString & bcc, const QString & bodytext ) {
27
28m_mail[0] = from;
29m_mail[1] = to;
30m_mail[2] = subject;
31m_mail[3] = cc;
32m_mail[4] = bcc;
33m_mail[5] = bodytext;
34
35setText();
36
37}
38
39
40ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl)
41 : ViewMailBase(parent, name, fl), _inLoop(false)
42{
43 _gotBody = false;
44
45 connect(reply, SIGNAL(activated()), SLOT(slotReply()));
46 connect(forward, SIGNAL(activated()), SLOT(slotForward()));
47
48 attachments->setEnabled(_gotBody);
49
50 //_handler->iUid("FETCH", QString("%1 (BODY[1])").arg(mail.uid()));
51 //connect(_handler, SIGNAL(gotResponse(IMAPResponse &)), SLOT(slotIMAPUid(IMAPResponse &)));
52}
53
54void ViewMail::setText()
55{
56
57 setCaption( caption().arg( m_mail[0] ) );
58
59 _mailHtml = tr(
60 "<html><body>"
61 "<div align=center><b>%1</b></div>"
62 "<b>From:</b> %2<br>"
63 "<b>To:</b> %3<br>"
64 "%4"
65 "%5"
66 "<b>Date:</b> %6<hr>"
67 "<font face=fixed>%7</font>")
68 .arg( deHtml( m_mail[2] ) )
69 .arg( deHtml( m_mail[0] ) )
70 .arg( deHtml( m_mail[1] ) )
71 .arg( tr("<b>Cc:</b> %1<br>").arg( deHtml( m_mail[3] ) ) )
72 .arg( tr("<b>Bcc:</b> %1<br>").arg( deHtml( m_mail[4] ) ) )
73 .arg( tr("(no date)" ) )
74 .arg("%1");
75 browser->setText( QString(_mailHtml) + deHtml( m_mail[5] ) );
76}
77
78
79
80ViewMail::~ViewMail()
81{
82 hide();
83}
84
85void ViewMail::hide()
86{
87 QWidget::hide();
88
89 if (_inLoop) {
90 _inLoop = false;
91 qApp->exit_loop();
92 }
93}
94
95void ViewMail::exec()
96{
97 show();
98
99 if (!_inLoop) {
100 _inLoop = true;
101 qApp->enter_loop();
102 }
103}
104
105QString ViewMail::deHtml(const QString &string)
106{
107 QString string_ = string;
108 string_.replace(QRegExp("&"), "&amp;");
109 string_.replace(QRegExp("<"), "&lt;");
110 string_.replace(QRegExp(">"), "&gt;");
111 string_.replace(QRegExp("\\n"), "<br>");
112 return string_;
113}
114
115void ViewMail::slotReply()
116{
117 if (!_gotBody) {
118 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok"));
119 return;
120 }
121
122 QString rtext;
123 // rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose
124 // .arg(_mail.envelope().from()[0].toString())
125 // .arg(_mail.envelope().mailDate());
126
127 //QString text = _mail.bodyPart(1).data();
128 //QStringList lines = QStringList::split(QRegExp("\\n"), text);
129 QStringList::Iterator it;
130 //for (it = lines.begin(); it != lines.end(); it++) {
131 // rtext += "> " + *it + "\n";
132 //}
133 rtext += "\n";
134
135 QString prefix;
136 //if (_mail.envelope().subject().find(QRegExp("^Re: *$")) != -1) prefix = "";
137 // else prefix = "Re: "; // no i18n on purpose
138
139 //SendMail sendMail;
140 //sendMail.setTo(_mail.envelope().from()[0].toString());
141 //sendMail.setSubject(prefix + _mail.envelope().subject());
142 //sendMail.setInReplyTo(_mail.envelope().messageId());
143 //sendMail.setMessage(rtext);
144
145 //Composer composer(this, 0, true);
146 //composer.setSendMail(sendMail);
147 //composer.showMaximized();
148 //composer.exec();
149}
150
151void ViewMail::slotForward()
152{
153 if (!_gotBody) {
154 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok"));
155 return;
156 }
157
158 QString ftext;
159 /*ftext += QString("\n----- Forwarded message from %1 -----\n\n")
160 .arg(_mail.envelope().from()[0].toString());
161 if (!_mail.envelope().mailDate().isNull())
162 ftext += QString("Date: %1\n")
163 .arg(_mail.envelope().mailDate());
164 if (!_mail.envelope().from()[0].toString().isNull())
165 ftext += QString("From: %1\n")
166 .arg(_mail.envelope().from()[0].toString());
167 if (!_mail.envelope().to().toString().isNull())
168 ftext += QString("To: %1\n")
169 .arg(_mail.envelope().to().toString());
170 if (!_mail.envelope().cc().toString().isNull())
171 ftext += QString("Cc: %1\n")
172 .arg(_mail.envelope().cc().toString());
173 if (!_mail.envelope().bcc().toString().isNull())
174 ftext += QString("Bcc: %1\n")
175 .arg(_mail.envelope().bcc().toString());
176 if (!_mail.envelope().subject().isNull())
177 ftext += QString("Subject: %1\n")
178 .arg(_mail.envelope().subject());
179
180 ftext += QString("\n%1\n")
181 .arg(_mail.bodyPart(1).data());
182
183 ftext += QString("----- End forwarded message -----\n");
184*/
185/*
186 SendMail sendMail;
187 sendMail.setSubject("Fwd: " + _mail.envelope().subject());
188 sendMail.setMessage(ftext);
189
190 Composer composer(this, 0, true);
191 composer.setSendMail(sendMail);
192 composer.showMaximized();
193 composer.exec();
194*/
195}
196
197/*
198void ViewMail::slotIMAPUid(IMAPResponse &response)
199{
200 disconnect(_handler, SIGNAL(gotResponse(IMAPResponse &)), this, SLOT(slotIMAPUid(IMAPResponse &)));
201
202 if (response.statusResponse().status() == IMAPResponseEnums::OK) {
203 QValueList<IMAPResponseBodyPart> bodyParts;
204 bodyParts.append(response.FETCH()[0].bodyPart(0));
205 _mail.setBodyParts(bodyParts);
206
207 browser->setText(QString(_mailHtml).arg(deHtml(response.FETCH()[0].bodyPart(0).data())));
208
209 // fillList(response.FETCH()[0].bodyStructure());
210
211 _gotBody = true;
212 } else {
213 QMessageBox::warning(this, tr("Error"), tr("<p>I was unable to retrieve the mail from the server. You can try again later or give up.</p>"), tr("Ok"));
214 }
215}
216*/