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