summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/mail/mail.pro4
-rw-r--r--noncore/net/mail/mainwindow.cpp6
-rw-r--r--noncore/net/mail/viewmail.cpp216
-rw-r--r--noncore/net/mail/viewmail.h75
-rw-r--r--noncore/net/mail/viewmailbase.cpp75
-rw-r--r--noncore/net/mail/viewmailbase.h36
6 files changed, 412 insertions, 0 deletions
diff --git a/noncore/net/mail/mail.pro b/noncore/net/mail/mail.pro
index 2142cdc..3ae1ddc 100644
--- a/noncore/net/mail/mail.pro
+++ b/noncore/net/mail/mail.pro
@@ -10,2 +10,4 @@ HEADERS = defines.h \
mainwindow.h \
+ viewmail.h \
+ viewmailbase.h \
opiemail.h \
@@ -23,2 +25,4 @@ SOURCES = main.cpp \
logindialog.cpp \
+ viewmail.cpp \
+ viewmailbase.cpp \
settings.cpp
diff --git a/noncore/net/mail/mainwindow.cpp b/noncore/net/mail/mainwindow.cpp
index 6f054cc..6e8f4d3 100644
--- a/noncore/net/mail/mainwindow.cpp
+++ b/noncore/net/mail/mainwindow.cpp
@@ -8,2 +8,3 @@
#include "mainwindow.h"
+#include "viewmail.h"
@@ -140,2 +141,7 @@ void MainWindow::displayMail(QListViewItem*item)
+ ViewMail readMail( this );
+ readMail.setMailInfo( mail.getFrom(), "", mail.getSubject(), "", "", body );
+ readMail.showMaximized();
+ readMail.exec();
+
qDebug(body);
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 @@
+#include <qtextbrowser.h>
+#include <qmessagebox.h>
+#include <qaction.h>
+#include <qapplication.h>
+
+//#include "mailfactory.h"
+//#include "composer.h"
+#include "viewmail.h"
+
+AttachItem::AttachItem(QListView *parent, AttachItemStore &attachItemStore)
+ : QListViewItem(parent), _attachItemStore(attachItemStore)
+{
+ setText(0, _attachItemStore.mimeType());
+ setText(1, _attachItemStore.fileName());
+ setText(2, _attachItemStore.description());
+}
+
+AttachItem::AttachItem(QListViewItem *parent, AttachItemStore &attachItemStore)
+ : QListViewItem(parent), _attachItemStore(attachItemStore)
+{
+ setText(0, _attachItemStore.mimeType());
+ setText(1, _attachItemStore.fileName());
+ setText(2, _attachItemStore.description());
+}
+
+void ViewMail::setMailInfo( const QString & from, const QString & to, const QString & subject, const QString & cc, const QString & bcc, const QString & bodytext ) {
+
+m_mail[0] = from;
+m_mail[1] = to;
+m_mail[2] = subject;
+m_mail[3] = cc;
+m_mail[4] = bcc;
+m_mail[5] = bodytext;
+
+setText();
+
+}
+
+
+ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl)
+ : ViewMailBase(parent, name, fl), _inLoop(false)
+{
+ _gotBody = false;
+
+ connect(reply, SIGNAL(activated()), SLOT(slotReply()));
+ connect(forward, SIGNAL(activated()), SLOT(slotForward()));
+
+ attachments->setEnabled(_gotBody);
+
+// _handler->iUid("FETCH", QString("%1 (BODY[1])").arg(mail.uid()));
+// connect(_handler, SIGNAL(gotResponse(IMAPResponse &)), SLOT(slotIMAPUid(IMAPResponse &)));
+}
+
+void ViewMail::setText()
+{
+
+ setCaption( caption().arg( m_mail[0] ) );
+
+ _mailHtml = tr(
+ "<html><body>"
+ "<div align=center><b>%1</b></div>"
+ "<b>From:</b> %2<br>"
+ "<b>To:</b> %3<br>"
+ "%4"
+ "%5"
+ "<b>Date:</b> %6<hr>"
+ "<font face=fixed>%7</font>")
+ .arg( deHtml( m_mail[2] ) )
+ .arg( deHtml( m_mail[0] ) )
+ .arg( deHtml( m_mail[1] ) )
+ .arg( tr("<b>Cc:</b> %1<br>").arg( deHtml( m_mail[3] ) ) )
+ .arg( tr("<b>Bcc:</b> %1<br>").arg( deHtml( m_mail[4] ) ) )
+ .arg( tr("(no date)" ) )
+ .arg("%1");
+ browser->setText( QString(_mailHtml) + deHtml( m_mail[5] ) );
+}
+
+
+
+ViewMail::~ViewMail()
+{
+ hide();
+}
+
+void ViewMail::hide()
+{
+ QWidget::hide();
+
+ if (_inLoop) {
+ _inLoop = false;
+ qApp->exit_loop();
+ }
+}
+
+void ViewMail::exec()
+{
+ show();
+
+ if (!_inLoop) {
+ _inLoop = true;
+ qApp->enter_loop();
+ }
+}
+
+QString ViewMail::deHtml(const QString &string)
+{
+ QString string_ = string;
+ string_.replace(QRegExp("&"), "&amp;");
+ string_.replace(QRegExp("<"), "&lt;");
+ string_.replace(QRegExp(">"), "&gt;");
+ string_.replace(QRegExp("\\n"), "<br>");
+ return string_;
+}
+
+void ViewMail::slotReply()
+{
+ if (!_gotBody) {
+ QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok"));
+ return;
+ }
+
+ QString rtext;
+// rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose
+// .arg(_mail.envelope().from()[0].toString())
+// .arg(_mail.envelope().mailDate());
+
+// QString text = _mail.bodyPart(1).data();
+// QStringList lines = QStringList::split(QRegExp("\\n"), text);
+ QStringList::Iterator it;
+// for (it = lines.begin(); it != lines.end(); it++) {
+// rtext += "> " + *it + "\n";
+// }
+ rtext += "\n";
+
+ QString prefix;
+// if (_mail.envelope().subject().find(QRegExp("^Re: *$")) != -1) prefix = "";
+// else prefix = "Re: "; // no i18n on purpose
+
+// SendMail sendMail;
+// sendMail.setTo(_mail.envelope().from()[0].toString());
+// sendMail.setSubject(prefix + _mail.envelope().subject());
+// sendMail.setInReplyTo(_mail.envelope().messageId());
+// sendMail.setMessage(rtext);
+
+// Composer composer(this, 0, true);
+// composer.setSendMail(sendMail);
+// composer.showMaximized();
+// composer.exec();
+}
+
+void ViewMail::slotForward()
+{
+ if (!_gotBody) {
+ QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok"));
+ return;
+ }
+
+ QString ftext;
+/* ftext += QString("\n----- Forwarded message from %1 -----\n\n")
+ .arg(_mail.envelope().from()[0].toString());
+ if (!_mail.envelope().mailDate().isNull())
+ ftext += QString("Date: %1\n")
+ .arg(_mail.envelope().mailDate());
+ if (!_mail.envelope().from()[0].toString().isNull())
+ ftext += QString("From: %1\n")
+ .arg(_mail.envelope().from()[0].toString());
+ if (!_mail.envelope().to().toString().isNull())
+ ftext += QString("To: %1\n")
+ .arg(_mail.envelope().to().toString());
+ if (!_mail.envelope().cc().toString().isNull())
+ ftext += QString("Cc: %1\n")
+ .arg(_mail.envelope().cc().toString());
+ if (!_mail.envelope().bcc().toString().isNull())
+ ftext += QString("Bcc: %1\n")
+ .arg(_mail.envelope().bcc().toString());
+ if (!_mail.envelope().subject().isNull())
+ ftext += QString("Subject: %1\n")
+ .arg(_mail.envelope().subject());
+
+ ftext += QString("\n%1\n")
+ .arg(_mail.bodyPart(1).data());
+
+ ftext += QString("----- End forwarded message -----\n");
+*/
+/*
+ SendMail sendMail;
+ sendMail.setSubject("Fwd: " + _mail.envelope().subject());
+ sendMail.setMessage(ftext);
+
+ Composer composer(this, 0, true);
+ composer.setSendMail(sendMail);
+ composer.showMaximized();
+ composer.exec();
+*/
+}
+
+/*
+void ViewMail::slotIMAPUid(IMAPResponse &response)
+{
+ disconnect(_handler, SIGNAL(gotResponse(IMAPResponse &)), this, SLOT(slotIMAPUid(IMAPResponse &)));
+
+ if (response.statusResponse().status() == IMAPResponseEnums::OK) {
+ QValueList<IMAPResponseBodyPart> bodyParts;
+ bodyParts.append(response.FETCH()[0].bodyPart(0));
+ _mail.setBodyParts(bodyParts);
+
+ browser->setText(QString(_mailHtml).arg(deHtml(response.FETCH()[0].bodyPart(0).data())));
+
+// fillList(response.FETCH()[0].bodyStructure());
+
+ _gotBody = true;
+ } else {
+ 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"));
+ }
+}
+*/
diff --git a/noncore/net/mail/viewmail.h b/noncore/net/mail/viewmail.h
new file mode 100644
index 0000000..9d3c6e4
--- a/dev/null
+++ b/noncore/net/mail/viewmail.h
@@ -0,0 +1,75 @@
+#ifndef VIEWMAIL_H
+#define VIEWMAIL_H
+
+#include <qlistview.h>
+#include <qmap.h>
+
+#include "viewmailbase.h"
+//#include "imapresponse.h"
+//#include "mailtable.h"
+
+class AttachItemStore
+{
+public:
+ void setMimeType(QString mimeType) { _mimeType = mimeType; }
+ QString mimeType() { return _mimeType; }
+ void setFileName(QString fileName) { _fileName = fileName; }
+ QString fileName() { return _fileName; }
+ void setDescription(QString description) { _description = description; }
+ QString description() { return _description; }
+ void setPartNum(QString partNum) { _partNum = partNum; }
+ QString partNum() { return _partNum; }
+
+private:
+ QString _mimeType, _fileName, _description, _partNum;
+
+};
+
+class AttachItem : public QListViewItem
+{
+public:
+ AttachItem(QListView *parent, AttachItemStore &attachment);
+ AttachItem(QListViewItem *parent, AttachItemStore &attachment);
+
+ AttachItemStore attachItemStore() { return _attachItemStore; }
+
+private:
+ AttachItemStore _attachItemStore;
+
+};
+
+class ViewMail : public ViewMailBase
+{
+ Q_OBJECT
+
+public:
+ ViewMail( QWidget *parent = 0, const char *name = 0, WFlags fl = Qt::WType_Modal);
+ ~ViewMail();
+
+ void hide();
+ void exec();
+ static QString appName() { return QString::fromLatin1("mail"); }
+ void setMailInfo( const QString & from, const QString & to, const QString & subject, const QString & cc, const QString & bcc, const QString & bodytext );
+
+protected:
+// void fillList(IMAPResponseBODYSTRUCTURE &structure);
+ QString deHtml(const QString &string);
+
+protected slots:
+ void slotReply();
+ void slotForward();
+ void setText();
+
+// void slotIMAPUid(IMAPResponse &response);
+
+private:
+ bool _inLoop;
+// IMAPResponseFETCH _mail;
+// IMAPHandler *_handler;
+ QString _mailHtml;
+ bool _gotBody;
+ QMap <int,QString> m_mail;
+
+};
+
+#endif
diff --git a/noncore/net/mail/viewmailbase.cpp b/noncore/net/mail/viewmailbase.cpp
new file mode 100644
index 0000000..197a665
--- a/dev/null
+++ b/noncore/net/mail/viewmailbase.cpp
@@ -0,0 +1,75 @@
+#include <qtextbrowser.h>
+#include <qlistview.h>
+#include <qaction.h>
+#include <qlabel.h>
+#include <qvbox.h>
+#include <qpopupmenu.h>
+
+#include <qpe/qpetoolbar.h>
+#include <qmenubar.h>
+#include <qpe/resource.h>
+
+#include "viewmailbase.h"
+//#include "opendiag.h"
+
+ViewMailBase::ViewMailBase(QWidget *parent, const char *name, WFlags fl)
+ : QMainWindow(parent, name, fl)
+{
+ setCaption(tr("E-Mail by %1"));
+ setToolBarsMovable(false);
+
+ toolbar = new QToolBar(this);
+ menubar = new QMenuBar( toolbar );
+ mailmenu = new QPopupMenu( menubar );
+ menubar->insertItem( tr( "Mail" ), mailmenu );
+
+ toolbar->setHorizontalStretchable(true);
+ addToolBar(toolbar);
+
+ QLabel *spacer = new QLabel(toolbar);
+ spacer->setBackgroundMode(QWidget::PaletteButton);
+ toolbar->setStretchableWidget(spacer);
+
+ reply = new QAction(tr("Reply"), QIconSet(Resource::loadPixmap("mail/reply")), 0, 0, this);
+ reply->addTo(toolbar);
+ reply->addTo(mailmenu);
+
+ forward = new QAction(tr("Forward"), QIconSet(Resource::loadPixmap("mail/forward")), 0, 0, this);
+ forward->addTo(toolbar);
+ forward->addTo(mailmenu);
+
+ attachbutton = new QAction(tr("Attachments"), QIconSet(Resource::loadPixmap("mail/attach")), 0, 0, this, 0, true);
+ attachbutton->addTo(toolbar);
+ attachbutton->addTo(mailmenu);
+ connect(attachbutton, SIGNAL(toggled(bool)), SLOT(slotChangeAttachview(bool)));
+
+ deleteMail = new QAction(tr("Delete Mail"), QIconSet(Resource::loadPixmap("mail/delete")), 0, 0, this);
+ deleteMail->addTo(toolbar);
+ deleteMail->addTo(mailmenu);
+
+ QVBox *view = new QVBox(this);
+ setCentralWidget(view);
+
+ attachments = new QListView(view);
+ attachments->setMinimumHeight(90);
+ attachments->setMaximumHeight(90);
+ attachments->setAllColumnsShowFocus(true);
+ attachments->addColumn("Mime Type", 100);
+ attachments->addColumn("Filename", 100);
+ attachments->addColumn("Description", 100);
+ attachments->hide();
+
+ browser = new QTextBrowser(view);
+
+// openDiag = new OpenDiag(view);
+// openDiag->hide();
+
+}
+
+void ViewMailBase::slotChangeAttachview(bool state)
+{
+ if (state) attachments->show();
+ else attachments->hide();
+}
+
+
diff --git a/noncore/net/mail/viewmailbase.h b/noncore/net/mail/viewmailbase.h
new file mode 100644
index 0000000..898522e
--- a/dev/null
+++ b/noncore/net/mail/viewmailbase.h
@@ -0,0 +1,36 @@
+#ifndef VIEWMAILBASE_H
+#define VIEWMAILBASE_H
+
+#include <qmainwindow.h>
+
+class QAction;
+class OpenDiag;
+class QListView;
+class QToolBar;
+class QTextBrowser;
+class QMenuBar;
+class QPopupMenu;
+
+class ViewMailBase : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ ViewMailBase(QWidget *parent = 0, const char *name = 0, WFlags fl = 0);
+
+protected:
+ QAction *reply, *forward, *attachbutton, *deleteMail;
+ QListView *attachments;
+ QToolBar *toolbar;
+ QTextBrowser *browser;
+ OpenDiag *openDiag;
+ QMenuBar *menubar;
+ QPopupMenu *mailmenu;
+
+protected slots:
+ void slotChangeAttachview(bool state);
+
+};
+
+#endif
+