summaryrefslogtreecommitdiff
path: root/noncore/net/mail/viewmail.cpp
Side-by-side diff
Diffstat (limited to 'noncore/net/mail/viewmail.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/mail/viewmail.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp
index d4c5150..ed77eb5 100644
--- a/noncore/net/mail/viewmail.cpp
+++ b/noncore/net/mail/viewmail.cpp
@@ -17,180 +17,194 @@
#include "abstractmail.h"
#include "accountview.h"
#include "mailtypes.h"
AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file,
const QString&fsize,int num,const QValueList<int>&path)
: QListViewItem(parent,after),_partNum(num)
{
_path=path;
setText(0, mime);
setText(1, desc);
setText(2, file);
setText(3, fsize);
}
AttachItem::AttachItem(QListViewItem * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file,
const QString&fsize,int num,const QValueList<int>&path)
: QListViewItem(parent,after),_partNum(num)
{
_path=path;
setText(0, mime);
setText(1, desc);
setText(2, file);
setText(3, fsize);
}
bool AttachItem::isParentof(const QValueList<int>&path)
{
/* if not set, then no parent */
if (path.count()==0||_path.count()==0) return false;
/* the parent must have one digit less then a child */
if (path.count()!=_path.count()+1) return false;
for (unsigned int i=0; i < _path.count();++i) {
if (_path[i]!=path[i]) return false;
}
return true;
}
AttachItem* ViewMail::searchParent(const QValueList<int>&path)
{
QListViewItemIterator it( attachments );
for ( ; it.current(); ++it ) {
AttachItem*ati = (AttachItem*)it.current();
if (ati->isParentof(path)) return ati;
}
return 0;
}
+AttachItem* ViewMail::lastChild(AttachItem*parent)
+{
+ if (!parent) return 0;
+ AttachItem* item = (AttachItem*)parent->firstChild();
+ if (!item) return item;
+ AttachItem*temp=0;
+ while( (temp=(AttachItem*)item->nextSibling())) {
+ item = temp;
+ }
+ return item;
+}
+
void ViewMail::setBody( RecBody body ) {
m_body = 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;
AttachItem * parentItem = 0;
QString type=body.Description().Type()+"/"+body.Description().Subtype();
QString desc,fsize;
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(&fsize);
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","",fsize,-1,body.Description().Positionlist());
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) {
qDebug(it.key());
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(&fsize);
if (w>0) o.precision(2); else o.precision(0);
o.setf(QTextStream::fixed);
o << s << " " << q << "Byte";
desc = body.Parts()[i].Description();
parentItem = searchParent(body.Parts()[i].Positionlist());
if (parentItem) {
+ AttachItem*temp = lastChild(parentItem);
+ if (temp) curItem = temp;
curItem=new AttachItem(parentItem,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist());
attachments->setRootIsDecorated(true);
curItem = parentItem;
} else {
curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i,body.Parts()[i].Positionlist());
}
}
}
void ViewMail::slotShowHtml( bool state ) {
m_showHtml = state;
setText();
}
void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) {
if (!item )
return;
if ( ( ( AttachItem* )item )->Partnumber() == -1 ) {
setText();
return;
}
QPopupMenu *menu = new QPopupMenu();
int ret=0;
if ( item->text( 0 ).left( 5 ) == "text/" || item->text(0)=="message/rfc822" ) {
menu->insertItem( tr( "Show Text" ), 1 );
}
menu->insertItem( tr( "Save Attachment" ), 0 );
menu->insertSeparator(1);
ret = menu->exec( point, 0 );
switch(ret) {
case 0:
{ MimeTypes types;
types.insert( "all", "*" );
QString str = OFileDialog::getSaveFileName( 1,
"/", item->text( 2 ) , types, 0 );
if( !str.isEmpty() ) {
encodedString*content = m_recMail.Wrapper()->fetchDecodedPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] );
if (content) {
QFile output(str);
output.open(IO_WriteOnly);
output.writeBlock(content->Content(),content->Length());
output.close();