00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include <config.h>
00021
#include "kfile_rfc822.h"
00022
00023
#include <kprocess.h>
00024
#include <klocale.h>
00025
#include <kgenericfactory.h>
00026
#include <kstringvalidator.h>
00027
#include <kdebug.h>
00028
00029
#include <qdict.h>
00030
#include <qvalidator.h>
00031
#include <qcstring.h>
00032
#include <qfile.h>
00033
#include <qdatetime.h>
00034
00035
#if !defined(__osf__)
00036
#include <inttypes.h>
00037
#else
00038
typedef unsigned short uint32_t;
00039
#endif
00040
00041
typedef KGenericFactory<KRfc822Plugin> Rfc822Factory;
00042
00043 K_EXPORT_COMPONENT_FACTORY(kfile_rfc822, Rfc822Factory(
"kfile_rfc822" ))
00044
00045 KRfc822Plugin::KRfc822Plugin(
QObject *parent, const
char *name,
00046 const
QStringList &args)
00047
00048 : KFilePlugin(parent, name, args)
00049 {
00050 KFileMimeTypeInfo* info = addMimeTypeInfo(
"message/rfc822" );
00051
00052 KFileMimeTypeInfo::GroupInfo* group = 0L;
00053
00054 group = addGroupInfo(info,
"Technical", i18n(
"Technical Details"));
00055
00056 KFileMimeTypeInfo::ItemInfo* item;
00057
00058 item = addItemInfo(group,
"From", i18n(
"From"), QVariant::String);
00059 item = addItemInfo(group,
"To", i18n(
"To"), QVariant::String);
00060 item = addItemInfo(group,
"Subject", i18n(
"Subject"), QVariant::String);
00061 item = addItemInfo(group,
"Date", i18n(
"Date"), QVariant::String);
00062 item = addItemInfo(group,
"Content-Type", i18n(
"Content-Type"), QVariant::String);
00063 }
00064
00065
00066
bool KRfc822Plugin::readInfo( KFileMetaInfo& info, uint )
00067 {
00068
00069
QFile file(info.path());
00070
00071
if (!file.open(IO_ReadOnly))
00072 {
00073 kdDebug(7034) <<
"Couldn't open " << QFile::encodeName(info.path()) << endl;
00074
return false;
00075 }
00076
00077
00078
00079
00080
00081
00082
char id_from[] =
"From: ";
00083
char id_to[] =
"To: ";
00084
char id_subject[] =
"Subject: ";
00085
char id_date[] =
"Date: ";
00086
char id_contenttype[] =
"Content-Type: ";
00087
00088
00089
char linebuf[4096];
00090
00091
00092
char buf_from[1000] =
"";
00093
char buf_to[1000] =
"";
00094
char buf_subject[1000] =
"";
00095
char buf_date[1000] =
"";
00096
char buf_contenttype[1000] =
"";
00097
00098 memset(buf_from, 0, 999);
00099 memset(buf_to, 0, 999);
00100 memset(buf_subject, 0, 999);
00101 memset(buf_date, 0, 999);
00102 memset(buf_contenttype, 0, 999);
00103
char * myptr;
00104
00105
bool done=
false;
00106
while (!done) {
00107
00108
00109 file.readLine(linebuf,
sizeof( linebuf ));
00110
00111
00112
if (memcmp(linebuf, id_from, 6) == 0) {
00113
00114 myptr = linebuf + 6;
00115 strncpy(buf_from, myptr,
sizeof( buf_from ));
00116 buf_from[998]=
'\0';
00117 }
else if (memcmp(linebuf, id_to, 4) == 0) {
00118
00119 myptr = linebuf + 4;
00120 strncpy(buf_to, myptr,
sizeof( buf_to ));
00121 buf_to[998]=
'\0';
00122 }
else if (memcmp(linebuf, id_subject, 9) == 0) {
00123
00124 myptr = linebuf + 9;
00125 strncpy(buf_subject, myptr,
sizeof( buf_subject ));
00126 buf_subject[998]=
'\0';
00127 }
else if (memcmp(linebuf, id_date, 6) == 0) {
00128
00129 myptr = linebuf + 6;
00130 strncpy(buf_date, myptr,
sizeof( buf_date ));
00131 buf_date[998]=
'\0';
00132 }
else if (memcmp(linebuf, id_contenttype, 14) == 0) {
00133
00134 myptr = linebuf + 14;
00135 strncpy(buf_contenttype, myptr,
sizeof( buf_contenttype ));
00136 buf_contenttype[998]=
'\0';
00137 }
00138
00139
00140
if (
00141 ((strlen(buf_from) > 0) && (strlen(buf_to) > 0) &&
00142 (strlen(buf_subject) > 0) && (strlen(buf_date) > 0) &&
00143 (strlen(buf_contenttype) > 0)) ||
00144 (file.atEnd())
00145 )
00146 done =
true;
00147
00148 };
00149
00150 KFileMetaInfoGroup group = appendGroup(info,
"Technical");
00151
00152
if (strlen(buf_from) > 0) appendItem(group,
"From", buf_from);
00153
if (strlen(buf_to) > 0) appendItem(group,
"To", buf_to);
00154
if (strlen(buf_subject) > 0) appendItem(group,
"Subject", buf_subject);
00155
if (strlen(buf_date) > 0) appendItem(group,
"Date", buf_date);
00156
if (strlen(buf_contenttype) > 0) appendItem(group,
"Content-Type", buf_contenttype);
00157
00158
return true;
00159 }
00160
00161
#include "kfile_rfc822.moc"