diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 84da08d7b7fcda12c85caeb5a10b4903770a6f69 (patch) | |
tree | 2a6aea76f2dfffb4cc04bb907c4725af94f70e72 /kfile-plugins/mhtml | |
download | tdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.tar.gz tdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeaddons@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kfile-plugins/mhtml')
-rw-r--r-- | kfile-plugins/mhtml/Makefile.am | 21 | ||||
-rw-r--r-- | kfile-plugins/mhtml/kfile_mhtml.cpp | 201 | ||||
-rw-r--r-- | kfile-plugins/mhtml/kfile_mhtml.desktop | 60 | ||||
-rw-r--r-- | kfile-plugins/mhtml/kfile_mhtml.h | 45 |
4 files changed, 327 insertions, 0 deletions
diff --git a/kfile-plugins/mhtml/Makefile.am b/kfile-plugins/mhtml/Makefile.am new file mode 100644 index 0000000..326820d --- /dev/null +++ b/kfile-plugins/mhtml/Makefile.am @@ -0,0 +1,21 @@ +## Makefile.am for folder file meta info plugin + +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = kfile_mhtml.h + +kde_module_LTLIBRARIES = kfile_mhtml.la + +kfile_mhtml_la_SOURCES = kfile_mhtml.cpp +kfile_mhtml_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +kfile_mhtml_la_LIBADD = $(LIB_KIO) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +services_DATA = kfile_mhtml.desktop +servicesdir = $(kde_servicesdir) + +messages: + $(XGETTEXT) *.cpp -o $(podir)/kfile_mhtml.pot diff --git a/kfile-plugins/mhtml/kfile_mhtml.cpp b/kfile-plugins/mhtml/kfile_mhtml.cpp new file mode 100644 index 0000000..f9ef320 --- /dev/null +++ b/kfile-plugins/mhtml/kfile_mhtml.cpp @@ -0,0 +1,201 @@ +/*************************************************************************** + * Copyright (C) 2005 by Spiros Georgaras * + * sngeorgaras@otenet.gr * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + + +#include <config.h> +#include "kfile_mhtml.h" + +#include <kgenericfactory.h> +#include <kmdcodec.h> +#include <qstring.h> +#include <qcstring.h> +#include <qfile.h> +#include <qtextstream.h> +#include <qtextcodec.h> + +typedef KGenericFactory<mhtmlPlugin> mhtmlFactory; + +K_EXPORT_COMPONENT_FACTORY(kfile_mhtml, mhtmlFactory( "kfile_mhtml" )) + +mhtmlPlugin::mhtmlPlugin(QObject *parent, const char *name, + const QStringList &args) + : KFilePlugin(parent, name, args) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo( "application/x-mimearchive" ); + KFileMimeTypeInfo::GroupInfo* group = 0L; + group = addGroupInfo(info, "mhtmlInfo", i18n("Document Information")); + KFileMimeTypeInfo::ItemInfo* item; + item = addItemInfo(group, "Subject", i18n("Subject"), QVariant::String); + item = addItemInfo(group, "Sender", i18n("Sender"), QVariant::String); + item = addItemInfo(group, "Recipient", i18n("Recipient"), QVariant::String); + item = addItemInfo(group, "CopyTo", i18n("CC"), QVariant::String); + item = addItemInfo(group, "BlindCopyTo", i18n("BCC"), QVariant::String); + item = addItemInfo(group, "Date", i18n("Date"), QVariant::String); +} + +bool mhtmlPlugin::readInfo( KFileMetaInfo& info, uint /*what*/) +{ + QString mSender; + QString mRecipient; + QString mCopyTo; + QString mBlindCopyTo; + QString mSubject; + QString mDate; + bool canUnfold; + if ( info.path().isEmpty() ) // remote file + return false; + + QFile f(info.path()); + if (!f.open(IO_ReadOnly)) return false; + QTextStream stream(&f); + QString l=stream.readLine(); + int nFieldsFound = 0; + while(!l.isEmpty()){ + if(l.startsWith("From: ")) { + mSender=l.mid(6); + nFieldsFound |= 1; + canUnfold=TRUE; + } else if(l.startsWith("To: ")) { + mRecipient=l.mid(4); + nFieldsFound |= 2; + canUnfold=TRUE; + } else if(l.startsWith("Subject: ")) { + mSubject=l.mid(9); + nFieldsFound |= 4; + canUnfold=TRUE; + } else if(l.startsWith("Cc: ")) { + mCopyTo=l.mid(4); + nFieldsFound |= 8; + canUnfold=TRUE; + } else if(l.startsWith("Bcc: ")) { + mBlindCopyTo=l.mid(5); + nFieldsFound |= 16; + canUnfold=TRUE; + } else if(l.startsWith("Date: ")) { + mDate=l.mid(6); + nFieldsFound |= 32; + canUnfold=FALSE; + }else if(l.startsWith(" ") || l.startsWith("\t")){ + // unfold field + if(canUnfold){ + QString tmp=l.stripWhiteSpace(); + if(nFieldsFound & 16) mBlindCopyTo=mBlindCopyTo+" "+tmp; + else if(nFieldsFound & 8) mCopyTo=mCopyTo+" "+tmp; + else if(nFieldsFound & 4) mSubject=mSubject+" "+tmp; + else if(nFieldsFound & 2) mRecipient=mRecipient+" "+tmp; + else if(nFieldsFound & 1) mSender=mSender+" "+tmp; + } + }else canUnfold=FALSE; + // break out of the loop once the six fields have been found + if ( nFieldsFound == 32+16+8+4+2+1 ) + break; + l=stream.readLine(); + } + f.close(); + KFileMetaInfoGroup group = appendGroup(info, "mhtmlInfo"); + appendItem(group, "Subject", decodeRFC2047Phrase(mSubject,FALSE)); + appendItem(group, "Sender", decodeRFC2047Phrase(mSender)); + appendItem(group, "Recipient", decodeRFC2047Phrase(mRecipient)); + appendItem(group, "CopyTo", decodeRFC2047Phrase(mCopyTo)); + appendItem(group, "BlindCopyTo", decodeRFC2047Phrase(mBlindCopyTo)); + appendItem(group, "Date", mDate); + return true; +} + +QString mhtmlPlugin::decodeRFC2047Phrase(const QString &msg, bool removeLessGreater){ + int st=msg.find("=?"); + int en=-1; + QString msgCopy=msg; + QString decodedText=msgCopy.left(st); + QString encodedText=msgCopy.mid(st); + st=encodedText.find("=?"); + while(st!=-1){ + en=encodedText.find("?="); + while(encodedText.mid(en+2,1)!=" " && en+2<(int)encodedText.length()) en=encodedText.find("?=",en+1); + if(en==-1) break; + decodedText+=encodedText.left(st); + QString tmp=encodedText.mid(st,en-st+2); + encodedText=encodedText.mid(en+2); + decodedText+=decodeRFC2047String(tmp); + st=encodedText.find("=?",st+1); + } + decodedText += encodedText; + // remove unwanted '<' and '>' + if(removeLessGreater){ + if(decodedText.stripWhiteSpace().startsWith("<") && decodedText.stripWhiteSpace().endsWith(">")){ + QString tmp=decodedText.stripWhiteSpace(); + tmp=tmp.mid(1,tmp.length()-2); + decodedText=tmp; + }else{ + QString dec=decodedText; + QString tmp; + + st=decodedText.find("<"); + while(st!=-1){ + st=dec.find("<",st); + if(st==0 || (st!=0 && (dec.mid(st-2,2)==", "))){ + en=dec.find(">",st); + if(en==-1 && dec.find(",",st)<en){ + st++; + continue; + } + dec=dec.left(st)+dec.mid(st+1,en-st-1)+dec.mid(en+1); + }else if(st!=-1) st++; + } + decodedText=dec; + } + } + return decodedText; +} + +QString mhtmlPlugin::decodeRFC2047String(const QString &msg){ + QString charset; + QString encoding; + QString notEncodedText; + QString encodedText; + QString decodedText; + int encEnd=0; + if(msg.startsWith("=?") && (encEnd=msg.findRev("?="))!=-1){ + notEncodedText=msg.mid(encEnd+2); + encodedText=msg.left(encEnd); + encodedText=encodedText.mid(2,encodedText.length()-2); + int questionMark=encodedText.find('?'); + if(questionMark==-1) return msg; + charset=encodedText.left(questionMark).lower(); + encoding=encodedText.mid(questionMark+1,1).lower(); + if(encoding!="b" && encoding!="q") return msg; + encodedText=encodedText.mid(questionMark+3); + if(charset.find(" ")!=-1 && encodedText.find(" ")!=-1) return msg; + QCString tmpIn; + QCString tmpOut; + tmpIn = encodedText.local8Bit(); + if(encoding=="q")tmpOut=KCodecs::quotedPrintableDecode(tmpIn); + else tmpOut=KCodecs::base64Decode(tmpIn); + if(charset!="us-ascii"){ + QTextCodec *codec = QTextCodec::codecForName(charset.local8Bit()); + if(!codec) return msg; + decodedText=codec->toUnicode(tmpOut); + decodedText=decodedText.replace("_"," "); + }else decodedText=tmpOut.replace("_"," "); + return decodedText + notEncodedText; + }else return msg; +} +#include "kfile_mhtml.moc" + diff --git a/kfile-plugins/mhtml/kfile_mhtml.desktop b/kfile-plugins/mhtml/kfile_mhtml.desktop new file mode 100644 index 0000000..5e73302 --- /dev/null +++ b/kfile-plugins/mhtml/kfile_mhtml.desktop @@ -0,0 +1,60 @@ +[Desktop Entry] +Type=Service +Name=mhtml Info +Name[bg]=Информация за mhtml +Name[br]=Titouroù mhtml +Name[ca]=Informació mhtml +Name[cs]=mhtml informace +Name[da]=mhtml-info +Name[de]=MHTML-Information +Name[el]=Πληροφορίες mhtml +Name[eo]=mhtml informo +Name[es]=Información mhtml +Name[et]=mhtmli info +Name[eu]=mhtml infoa +Name[fa]=اطلاعات mhtml +Name[fi]=mhtml tiedot +Name[fr]=Informations sur « mhtml » +Name[fy]=mhtml-ynformaasje +Name[ga]=Eolas mhtml +Name[gl]=Información de mhtml +Name[he]=מידע אודות mhtml +Name[hr]=Podaci o mhtml +Name[hu]=Mhtml-információ +Name[is]=Upplýsingar um mhtml +Name[it]=Informazioni su mhtml +Name[ja]=mhtml 情報 +Name[ka]=mhtml ინფორმაცია +Name[kk]=mhtml мәліметі +Name[km]=ព័ត៌មាន mhtml +Name[lt]=mhtml info +Name[mk]=Информации за mhtml +Name[ms]=Maklumat mhtml +Name[nb]=mhtml-informasjon +Name[nds]=MHTML-Informatschonen +Name[ne]=एमएचटीएमएल सूचना +Name[nl]=mhtml-informatie +Name[nn]=mhtml-informasjon +Name[pa]=mhtml ਜਾਣਕਾਰੀ +Name[pl]=Informacja mhtml +Name[pt]=Informações de mhtml +Name[pt_BR]=Informações sobre mhtml +Name[ru]=Информация mhtml +Name[sk]=Informácie o mhtml +Name[sl]=Informacija o mhtml +Name[sr]=MHTML информације +Name[sr@Latn]=MHTML informacije +Name[sv]=MHTML-information +Name[ta]=mhtml தகவல் +Name[tr]=mhtml Bilgisi +Name[uk]=Інформація про mhtml +Name[uz]=mhtml fayllari haqida maʼlumot +Name[uz@cyrillic]=mhtml файллари ҳақида маълумот +Name[vi]=Thông tin mhtml +Name[zh_CN]=mhtml 信息 +Name[zh_TW]=mhtml 資訊 +ServiceTypes=KFilePlugin +X-KDE-Library=kfile_mhtml +MimeType=application/x-mimearchive +PreferredGroups=mhtmlInfo +PreferredItems=Subject,Sender,Recipient,CopyTo,BlindCopyTo,Date diff --git a/kfile-plugins/mhtml/kfile_mhtml.h b/kfile-plugins/mhtml/kfile_mhtml.h new file mode 100644 index 0000000..dc29ec3 --- /dev/null +++ b/kfile-plugins/mhtml/kfile_mhtml.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2005 by Spiros Georgaras * + * sngeorgaras@otenet.gr * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + + +#ifndef __KFILE_MHTML_H__ +#define __KFILE_MHTML_H__ + +/** + * Note: For further information look into <$KDEDIR/include/kfilemetainfo.h> + */ +#include <kfilemetainfo.h> + +class QStringList; + +class mhtmlPlugin: public KFilePlugin +{ + Q_OBJECT + +public: + mhtmlPlugin( QObject *parent, const char *name, const QStringList& args ); + virtual bool readInfo( KFileMetaInfo& info, uint what); +private: + QString decodeRFC2047Phrase(const QString &msg, bool removeLessGreater=TRUE); + QString decodeRFC2047String(const QString &msg); +}; + +#endif // __KFILE_MHTML_H__ + |