author | alwin <alwin> | 2003-12-13 03:51:21 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-13 03:51:21 (UTC) |
commit | 7f0861e63db74263ff286e09fbc4faf16d367a5b (patch) (side-by-side diff) | |
tree | d97bd868343b179039c141fee3725f7781a0fca1 | |
parent | a170120c655169de904ff282e23461ba4eef2b47 (diff) | |
download | opie-7f0861e63db74263ff286e09fbc4faf16d367a5b.zip opie-7f0861e63db74263ff286e09fbc4faf16d367a5b.tar.gz opie-7f0861e63db74263ff286e09fbc4faf16d367a5b.tar.bz2 |
displaying list of attachments of a mail works. (Of course only if
the mail HAS attachments ;)
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 1 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 1 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailtypes.cpp | 12 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailtypes.h | 5 | ||||
-rw-r--r-- | noncore/net/mail/mailtypes.cpp | 12 | ||||
-rw-r--r-- | noncore/net/mail/mailtypes.h | 5 | ||||
-rw-r--r-- | noncore/net/mail/viewmail.cpp | 94 | ||||
-rw-r--r-- | noncore/net/mail/viewmail.h | 26 | ||||
-rw-r--r-- | noncore/net/mail/viewmailbase.cpp | 7 |
9 files changed, 120 insertions, 43 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index 3941cec..11bf3b8 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp @@ -665,30 +665,31 @@ void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) encoding = "7bit"; break; case MAILIMAP_BODY_FLD_ENC_8BIT: encoding = "8bit"; break; case MAILIMAP_BODY_FLD_ENC_BINARY: encoding="binary"; break; case MAILIMAP_BODY_FLD_ENC_BASE64: encoding="base64"; break; case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: encoding="quoted-printable"; break; case MAILIMAP_BODY_FLD_ENC_OTHER: default: if (enc->enc_value) { char*t=enc->enc_value; encoding=QString(enc->enc_value); enc->enc_value=0L; free(t); } } target_part.setEncoding(encoding); + target_part.setSize(which->bd_size); } QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) { return fetchPart(mail,part.Positionlist(),false); } diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 3941cec..11bf3b8 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp @@ -665,30 +665,31 @@ void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) encoding = "7bit"; break; case MAILIMAP_BODY_FLD_ENC_8BIT: encoding = "8bit"; break; case MAILIMAP_BODY_FLD_ENC_BINARY: encoding="binary"; break; case MAILIMAP_BODY_FLD_ENC_BASE64: encoding="base64"; break; case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: encoding="quoted-printable"; break; case MAILIMAP_BODY_FLD_ENC_OTHER: default: if (enc->enc_value) { char*t=enc->enc_value; encoding=QString(enc->enc_value); enc->enc_value=0L; free(t); } } target_part.setEncoding(encoding); + target_part.setSize(which->bd_size); } QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) { return fetchPart(mail,part.Positionlist(),false); } diff --git a/noncore/net/mail/libmailwrapper/mailtypes.cpp b/noncore/net/mail/libmailwrapper/mailtypes.cpp index 9c312e9..5cd45ed 100644 --- a/noncore/net/mail/libmailwrapper/mailtypes.cpp +++ b/noncore/net/mail/libmailwrapper/mailtypes.cpp @@ -47,58 +47,68 @@ const QStringList&RecMail::To()const return to; } void RecMail::setCC(const QStringList&list) { cc = list; } const QStringList&RecMail::CC()const { return cc; } void RecMail::setBcc(const QStringList&list) { bcc = list; } const QStringList& RecMail::Bcc()const { return bcc; } RecPart::RecPart() - : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0) + : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0),m_size(0) { m_Parameters.clear(); m_poslist.clear(); } RecPart::~RecPart() { } +void RecPart::setSize(unsigned int size) +{ + m_size = size; +} + +const unsigned int RecPart::Size()const +{ + return m_size; +} + void RecPart::setLines(unsigned int lines) { m_lines = lines; } const unsigned int RecPart::Lines()const { return m_lines; } const QString& RecPart::Type()const { return m_type; } void RecPart::setType(const QString&type) { m_type = type; } const QString& RecPart::Subtype()const { return m_subtype; } diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h index f308bc7..24518cf 100644 --- a/noncore/net/mail/libmailwrapper/mailtypes.h +++ b/noncore/net/mail/libmailwrapper/mailtypes.h @@ -55,67 +55,70 @@ public: void setTo(const QStringList&list); const QStringList&To()const; void setCC(const QStringList&list); const QStringList&CC()const; void setBcc(const QStringList&list); const QStringList&Bcc()const; const QBitArray&getFlags()const{return msg_flags;} void setFlags(const QBitArray&flags){msg_flags = flags;} protected: QString subject,date,from,mbox,msg_id,replyto; int msg_number,msg_size; QBitArray msg_flags; QStringList to,cc,bcc; void init(); void copy_old(const RecMail&old); }; typedef QMap<QString,QString> part_plist_t; class RecPart { protected: QString m_type,m_subtype,m_identifier,m_encoding; - unsigned int m_lines; + unsigned int m_lines,m_size; part_plist_t m_Parameters; /* describes the position in the mail */ QValueList<int> m_poslist; public: RecPart(); virtual ~RecPart(); const QString&Type()const; void setType(const QString&type); const QString&Subtype()const; void setSubtype(const QString&subtype); const QString&Identifier()const; void setIdentifier(const QString&identifier); const QString&Encoding()const; void setEncoding(const QString&encoding); void setLines(unsigned int lines); const unsigned int Lines()const; + void setSize(unsigned int size); + const unsigned int Size()const; + void setParameters(const part_plist_t&list); const part_plist_t&Parameters()const; void addParameter(const QString&key,const QString&value); const QString searchParamter(const QString&key)const; void setPositionlist(const QValueList<int>&poslist); const QValueList<int>& Positionlist()const; }; class RecBody { protected: QString m_BodyText; QValueList<RecPart> m_PartsList; RecPart m_description; public: RecBody(); virtual ~RecBody(); void setBodytext(const QString&); const QString& Bodytext()const; void setDescription(const RecPart&des); const RecPart& Description()const; diff --git a/noncore/net/mail/mailtypes.cpp b/noncore/net/mail/mailtypes.cpp index 9c312e9..5cd45ed 100644 --- a/noncore/net/mail/mailtypes.cpp +++ b/noncore/net/mail/mailtypes.cpp @@ -47,58 +47,68 @@ const QStringList&RecMail::To()const return to; } void RecMail::setCC(const QStringList&list) { cc = list; } const QStringList&RecMail::CC()const { return cc; } void RecMail::setBcc(const QStringList&list) { bcc = list; } const QStringList& RecMail::Bcc()const { return bcc; } RecPart::RecPart() - : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0) + : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0),m_size(0) { m_Parameters.clear(); m_poslist.clear(); } RecPart::~RecPart() { } +void RecPart::setSize(unsigned int size) +{ + m_size = size; +} + +const unsigned int RecPart::Size()const +{ + return m_size; +} + void RecPart::setLines(unsigned int lines) { m_lines = lines; } const unsigned int RecPart::Lines()const { return m_lines; } const QString& RecPart::Type()const { return m_type; } void RecPart::setType(const QString&type) { m_type = type; } const QString& RecPart::Subtype()const { return m_subtype; } diff --git a/noncore/net/mail/mailtypes.h b/noncore/net/mail/mailtypes.h index f308bc7..24518cf 100644 --- a/noncore/net/mail/mailtypes.h +++ b/noncore/net/mail/mailtypes.h @@ -55,67 +55,70 @@ public: void setTo(const QStringList&list); const QStringList&To()const; void setCC(const QStringList&list); const QStringList&CC()const; void setBcc(const QStringList&list); const QStringList&Bcc()const; const QBitArray&getFlags()const{return msg_flags;} void setFlags(const QBitArray&flags){msg_flags = flags;} protected: QString subject,date,from,mbox,msg_id,replyto; int msg_number,msg_size; QBitArray msg_flags; QStringList to,cc,bcc; void init(); void copy_old(const RecMail&old); }; typedef QMap<QString,QString> part_plist_t; class RecPart { protected: QString m_type,m_subtype,m_identifier,m_encoding; - unsigned int m_lines; + unsigned int m_lines,m_size; part_plist_t m_Parameters; /* describes the position in the mail */ QValueList<int> m_poslist; public: RecPart(); virtual ~RecPart(); const QString&Type()const; void setType(const QString&type); const QString&Subtype()const; void setSubtype(const QString&subtype); const QString&Identifier()const; void setIdentifier(const QString&identifier); const QString&Encoding()const; void setEncoding(const QString&encoding); void setLines(unsigned int lines); const unsigned int Lines()const; + void setSize(unsigned int size); + const unsigned int Size()const; + void setParameters(const part_plist_t&list); const part_plist_t&Parameters()const; void addParameter(const QString&key,const QString&value); const QString searchParamter(const QString&key)const; void setPositionlist(const QValueList<int>&poslist); const QValueList<int>& Positionlist()const; }; class RecBody { protected: QString m_BodyText; QValueList<RecPart> m_PartsList; RecPart m_description; public: RecBody(); virtual ~RecBody(); void setBodytext(const QString&); const QString& Bodytext()const; void setDescription(const RecPart&des); const RecPart& Description()const; diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp index 7b8494d..39c9820 100644 --- a/noncore/net/mail/viewmail.cpp +++ b/noncore/net/mail/viewmail.cpp @@ -1,54 +1,122 @@ #include <qtextbrowser.h> #include <qmessagebox.h> +#include <qtextstream.h> #include <qaction.h> #include <qapplication.h> #include "settings.h" #include "composemail.h" #include "viewmail.h" -AttachItem::AttachItem(QListView *parent, AttachItemStore &attachItemStore) - : QListViewItem(parent), _attachItemStore(attachItemStore) +AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num) + : QListViewItem(parent,after),_partNum(num) { - 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()); + setText(0, mime); + setText(1, file); + setText(2, desc); } void ViewMail::setBody( RecBody body ) { m_mail[2] = body.Bodytext(); +attachbutton->setEnabled(body.Parts().count()>0); +attachments->setEnabled(body.Parts().count()>0); +if (body.Parts().count()==0) { + return; +} +AttachItem * curItem=0; +QString type=body.Description().Type()+"/"+body.Description().Subtype(); +QString desc; +double s = body.Description().Size(); +int w; +w=0; + +while (s>1024) { + s/=1024; + ++w; + if (w>=2) break; +} + +QString q=""; +switch(w) { +case 1: + q="k"; + break; +case 2: + q="M"; + break; +default: + break; +} +{ + /* I did not found a method to make a CONTENT reset on a QTextStream + so I use this construct that the stream will re-constructed in each + loop. To let it work, the textstream is packed into a own area of + code is it will be destructed after finishing its small job. + */ + QTextOStream o(&desc); + if (w>0) o.precision(2); else o.precision(0); + o.setf(QTextStream::fixed); + o << s << " " << q << "Byte"; +} + +curItem=new AttachItem(attachments,curItem,type,"Mailbody",desc,-1); +QString filename = ""; +for (unsigned int i = 0; i < body.Parts().count();++i) { + type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); + part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); + for (;it!=body.Parts()[i].Parameters().end();++it) { + if (it.key().lower()=="name") { + filename=it.data(); + } + } + s = body.Parts()[i].Size(); + w = 0; + while (s>1024) { + s/=1024; + ++w; + if (w>=2) break; + } + switch(w) { + case 1: + q="k"; + break; + case 2: + q="M"; + break; + default: + q=""; + break; + } + QTextOStream o(&desc); + if (w>0) o.precision(2); else o.precision(0); + o.setf(QTextStream::fixed); + o << s << " " << q << "Byte"; + curItem=new AttachItem(attachments,curItem,type,filename,desc,i); +} } void ViewMail::setMail( RecMail mail ) { m_mail[0] = mail.getFrom(); m_mail[1] = mail.getSubject(); m_mail[3] = mail.getDate(); m_mail[4] = mail.Msgid(); m_mail2[0] = mail.To(); m_mail2[1] = mail.CC(); m_mail2[2] = mail.Bcc(); setText(); } ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) : ViewMailBase(parent, name, fl), _inLoop(false) { m_gotBody = false; connect(reply, SIGNAL(activated()), SLOT(slotReply())); diff --git a/noncore/net/mail/viewmail.h b/noncore/net/mail/viewmail.h index 61baa1d..b497434 100644 --- a/noncore/net/mail/viewmail.h +++ b/noncore/net/mail/viewmail.h @@ -1,62 +1,42 @@ #ifndef VIEWMAIL_H #define VIEWMAIL_H #include <qlistview.h> #include <qmap.h> #include <qstringlist.h> #include "viewmailbase.h" #include "mailtypes.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; } + AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num); + int Partnumber() { return _partNum; } private: - AttachItemStore _attachItemStore; - + int _partNum; }; 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(); void setMail( RecMail mail ); void setBody( RecBody body ); protected: QString deHtml(const QString &string); protected slots: void slotReply(); void slotForward(); void setText(); private: diff --git a/noncore/net/mail/viewmailbase.cpp b/noncore/net/mail/viewmailbase.cpp index 197a665..38f92b4 100644 --- a/noncore/net/mail/viewmailbase.cpp +++ b/noncore/net/mail/viewmailbase.cpp @@ -33,43 +33,44 @@ ViewMailBase::ViewMailBase(QWidget *parent, const char *name, WFlags fl) 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->addColumn("Mime Type", 60); + attachments->addColumn(tr("Filename"), 100); + attachments->addColumn(tr("Size"), 80); + attachments->setSorting(-1); attachments->hide(); browser = new QTextBrowser(view); // openDiag = new OpenDiag(view); // openDiag->hide(); } void ViewMailBase::slotChangeAttachview(bool state) { if (state) attachments->show(); else attachments->hide(); } |