summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper
authorzautrix <zautrix>2004-09-11 16:02:52 (UTC)
committer zautrix <zautrix>2004-09-11 16:02:52 (UTC)
commit53e10fa5e66620ff1eba1c9d17738103ad511c91 (patch) (side-by-side diff)
treec9ed39ce780dc3e8b9b7138781d77db793defdc9 /kmicromail/libmailwrapper
parent32f9963a39236d08718a36d5adad2a0c5c4e2602 (diff)
downloadkdepimpi-53e10fa5e66620ff1eba1c9d17738103ad511c91.zip
kdepimpi-53e10fa5e66620ff1eba1c9d17738103ad511c91.tar.gz
kdepimpi-53e10fa5e66620ff1eba1c9d17738103ad511c91.tar.bz2
More mail enh.
Diffstat (limited to 'kmicromail/libmailwrapper') (more/less context) (show whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/abstractmail.cpp11
-rw-r--r--kmicromail/libmailwrapper/genericwrapper.cpp16
2 files changed, 16 insertions, 11 deletions
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp
index 374d606..44878e0 100644
--- a/kmicromail/libmailwrapper/abstractmail.cpp
+++ b/kmicromail/libmailwrapper/abstractmail.cpp
@@ -1,277 +1,272 @@
// CHANGED 2004-09-31 Lutz Rogowski
#include "abstractmail.h"
#include "imapwrapper.h"
#include "pop3wrapper.h"
#include "nntpwrapper.h"
#include "mhwrapper.h"
#include "mailtypes.h"
#include <qpe/global.h>
#include <qprogressbar.h>
#include <qapplication.h>
#include <qmessagebox.h>
#include <kdecore/kstandarddirs.h>
#include <qfile.h>
#include <qtextstream.h>
#include <stdlib.h>
#include <libetpan/mailmime_content.h>
#include <libetpan/mailmime.h>
using namespace Opie::Core;
AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
{
return new IMAPwrapper(a);
}
AbstractMail* AbstractMail::getWrapper(POP3account *a)
{
return new POP3wrapper(a);
}
AbstractMail* AbstractMail::getWrapper(NNTPaccount *a)
{
return new NNTPwrapper(a);
}
AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
{
return new MHwrapper(a,name);
}
AbstractMail* AbstractMail::getWrapper(Account*a)
{
if (!a) return 0;
switch (a->getType()) {
case MAILLIB::A_IMAP:
return new IMAPwrapper((IMAPaccount*)a);
break;
case MAILLIB::A_POP3:
return new POP3wrapper((POP3account*)a);
break;
case MAILLIB::A_NNTP:
return new NNTPwrapper((NNTPaccount*)a);
break;
default:
return 0;
}
}
encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
{
// odebug << "Decode string start" << oendl;
char*result_text;
size_t index = 0;
/* reset for recursive use! */
size_t target_length = 0;
result_text = 0;
int mimetype = MAILMIME_MECHANISM_7BIT;
if (enc.lower()=="quoted-printable") {
mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
} else if (enc.lower()=="base64") {
mimetype = MAILMIME_MECHANISM_BASE64;
} else if (enc.lower()=="8bit") {
mimetype = MAILMIME_MECHANISM_8BIT;
} else if (enc.lower()=="binary") {
mimetype = MAILMIME_MECHANISM_BINARY;
}
int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
&result_text,&target_length);
encodedString* result = new encodedString();
if (err == MAILIMF_NO_ERROR) {
result->setContent(result_text,target_length);
}
//odebug << "Decode string finished" << oendl;
return result;
}
QString AbstractMail::convert_String(const char*text)
{
//size_t index = 0;
char*res = 0;
int err = MAILIMF_NO_ERROR;
QString result(text);
/* due a bug in libetpan it isn't usable this moment */
/* int err = mailmime_encoded_phrase_parse("iso-8859-1",
text, strlen(text),&index, "iso-8859-1",&res);*/
//odebug << "Input: " << text << "" << oendl;
if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
// result = QString(res);
// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl;
}
if (res) free(res);
return result;
}
/* cp & paste from launcher */
QString AbstractMail::gen_attachment_id()
{
QFile file( "/proc/sys/kernel/random/uuid" );
if (!file.open(IO_ReadOnly ) )
return QString::null;
QTextStream stream(&file);
return "{" + stream.read().stripWhiteSpace() + "}";
}
int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool)
{
return 0;
}
QString AbstractMail::defaultLocalfolder()
{
// QString f = getenv( "HOME" );
QString f = locateLocal( "data", "kopiemail/localmail");
// f += "/Applications/opiemail/localmail";
return f;
}
QString AbstractMail::draftFolder()
{
return QString("Drafts");
}
/* temporary - will be removed when implemented in all classes */
void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &)
{
}
void AbstractMail::deleteMailList(const QValueList<RecMailP>&target)
{
//qDebug("AbstractMail::deleteMailList:: Please reimplement! ");
// this is currently re-implemented in pop3wrapper and imapwrapper
int iii = 0;
int count = target.count();
QWidget wid;
wid.show();
while (iii < count ) {
Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count));
wid.raise();
qApp->processEvents();
RecMailP mail = (*target.at( iii ));
deleteMail(mail);
++iii;
}
}
void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail )
{
- qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1());
+ //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1());
// get local folder
Account * acc = getAccount();
if ( !acc ) return;
QString lfName = acc->getLocalFolder();
if ( lfName.isEmpty() )
lfName = acc->getAccountName();
// create local folder
if ( !targetMail->createMbox(lfName))
{
QMessageBox::critical(0,tr("Error creating new Folder"),
tr("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName));
return;
}
QValueList<RecMailP> t;
listMessages(fromFolder->getName(),t,acc->getMaxMailSize() );
if ( t.count() == 0 ) {
Global::statusMessage(tr("There are no new messages"));
return;
}
QValueList<RecMailP> e;
targetMail->listMessages(lfName,e,acc->getMaxMailSize() );
- qDebug("target has mails %d ", e.count());
+ //qDebug("target has mails %d ", e.count());
QValueList<RecMailP> n;
int iii = 0;
int count = t.count();
while (iii < count ) {
RecMailP r = (*t.at( iii ));
bool found = false;
int jjj = 0;
int countE = e.count();
while (jjj < countE ) {
RecMailP re = (*e.at( jjj ));
if ( re->isEqual(r) ) {
found = true;
break;
}
++jjj;
}
- if ( found )
- qDebug("found ");
- else
- qDebug("NOT found ");
-
if ( !found ) {
n.append( r );
}
++iii;
}
if ( n.count() == 0 ) {
Global::statusMessage(tr("There are no new messages"));
return;
}
mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer());
-
+ Global::statusMessage(tr("Downloaded %1 messages").arg(n.count()));
#if 0
QValueList<RecMailP> t;
listMessages(fromFolder->getName(),t, maxSizeInKb);
mvcpMailList( t,targetFolder,targetWrapper,moveit);
#endif
}
void AbstractMail::mvcpAllMails(const FolderP&fromFolder,
const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
{
QValueList<RecMailP> t;
listMessages(fromFolder->getName(),t, maxSizeInKb);
mvcpMailList( t,targetFolder,targetWrapper,moveit);
}
void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t,
const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
{
encodedString*st = 0;
int iii = 0;
int count = t.count();
if ( count == 0 )
return;
// wel, processevents is qite strange, we need a widget for getting
// Global::statusMessage(tr("Copy2 message %1").arg(iii)); displayed
QWidget wid;
wid.show();
while (iii < count ) {
Global::statusMessage(tr("Copy message %1 of %2").arg(iii).arg(count));
wid.raise();
qApp->processEvents();
RecMailP r = (*t.at( iii ));
st = fetchRawBody(r);
if (st) {
targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
delete st;
}
++iii;
}
if (moveit) {
deleteMailList( t );
//deleteAllMail(fromFolder);
}
}
void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
{
encodedString*st = 0;
st = fetchRawBody(mail);
if (st) {
targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
delete st;
}
if (moveit) {
deleteMail(mail);
}
}
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp
index 2b04847..ed591fc 100644
--- a/kmicromail/libmailwrapper/genericwrapper.cpp
+++ b/kmicromail/libmailwrapper/genericwrapper.cpp
@@ -1,314 +1,324 @@
// CHANGED 2004-09-31 Lutz Rogowski
#include "genericwrapper.h"
#include <libetpan/libetpan.h>
#include "mailtypes.h"
#include <kconfig.h>
#include <kglobal.h>
#include <kstandarddirs.h>
using namespace Opie::Core;
Genericwrapper::Genericwrapper()
: AbstractMail()
{
bodyCache.clear();
m_storage = 0;
m_folder = 0;
}
Genericwrapper::~Genericwrapper()
{
if (m_folder) {
mailfolder_free(m_folder);
}
if (m_storage) {
mailstorage_free(m_storage);
}
cleanMimeCache();
}
QString Genericwrapper::parseDateTime( mailimf_date_time *date )
{
static bool init = false ;
if ( ! init ) {
KConfig kon ( locateLocal( "config", "korganizerrc" ) );
kon.setGroup("Locale");
KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)kon.readNumEntry( "PreferredDate",0) );
QString dummy = kon.readEntry( "UserDateFormatShort","%aK %d.%m.%y" );// kon.readEntry( "");
KGlobal::locale()->setHore24Format( !kon.readBoolEntry( "PreferredTime",0 ) );
KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
kon.setGroup("Time & Date");
KGlobal::locale()->setDaylightSaving( kon.readBoolEntry( "UseDaylightsaving", true ),
kon.readNumEntry( "DaylightsavingStart", 90),
kon.readNumEntry( "DaylightsavingEnd",304) );
KGlobal::locale()->setTimezone( kon.readEntry( "TimeZoneName" ," 00:00 Europe/London(UTC)") );
init = true;
}
- QDateTime dt (QDate(date->dt_year,date->dt_month, date->dt_day ),QTime(date->dt_hour, date->dt_min, date->dt_sec ) );
+ QDate da (date->dt_year,date->dt_month, date->dt_day );
+ QTime ti ( date->dt_hour, date->dt_min, date->dt_sec );
+ QDateTime dt ( da ,ti );
int off = KGlobal::locale()->localTimeOffset( dt );
- dt = dt.addSecs( off*60 );
- QString ret = KGlobal::locale()->formatDateTime( dt,true,true);
+ //dt = dt.addSecs( off*60 );
+ QString ret;
+ if ( da == QDate::currentDate () )
+ ret = KGlobal::locale()->formatTime( ti,true);
+
+ else {
+ ret = KGlobal::locale()->formatDateTime( dt,true,true);
+ }
+#if 0
if ( off < 0 )
ret += " -";
else
ret += " +";
ret += QString::number( off / 60 );
ret += "h";
+#endif
#if 0
char tmp[23];
// snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
// date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i",
date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
return QString( tmp );
#endif
return ret;
}
void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime)
{
if (!mime) {
return;
}
mailmime_field*field = 0;
mailmime_single_fields fields;
memset(&fields, 0, sizeof(struct mailmime_single_fields));
if (mime->mm_mime_fields != NULL) {
mailmime_single_fields_init(&fields, mime->mm_mime_fields,
mime->mm_content_type);
}
mailmime_content*type = fields.fld_content;
clistcell*current;
if (!type) {
target->setType("text");
target->setSubtype("plain");
} else {
target->setSubtype(type->ct_subtype);
switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
case MAILMIME_DISCRETE_TYPE_TEXT:
target->setType("text");
break;
case MAILMIME_DISCRETE_TYPE_IMAGE:
target->setType("image");
break;
case MAILMIME_DISCRETE_TYPE_AUDIO:
target->setType("audio");
break;
case MAILMIME_DISCRETE_TYPE_VIDEO:
target->setType("video");
break;
case MAILMIME_DISCRETE_TYPE_APPLICATION:
target->setType("application");
break;
case MAILMIME_DISCRETE_TYPE_EXTENSION:
default:
if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension);
}
break;
}
if (type->ct_parameters) {
fillParameters(target,type->ct_parameters);
}
}
if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) {
field = (mailmime_field*)current->data;
switch(field->fld_type) {
case MAILMIME_FIELD_TRANSFER_ENCODING:
target->setEncoding(getencoding(field->fld_data.fld_encoding));
break;
case MAILMIME_FIELD_ID:
target->setIdentifier(field->fld_data.fld_id);
break;
case MAILMIME_FIELD_DESCRIPTION:
target->setDescription(field->fld_data.fld_description);
break;
default:
break;
}
}
}
}
void Genericwrapper::fillParameters(RecPartP&target,clist*parameters)
{
if (!parameters) {return;}
clistcell*current=0;
mailmime_parameter*param;
for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
param = (mailmime_parameter*)current->data;
if (param) {
target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
}
}
}
QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
{
QString enc="7bit";
if (!aEnc) return enc;
switch(aEnc->enc_type) {
case MAILMIME_MECHANISM_7BIT:
enc = "7bit";
break;
case MAILMIME_MECHANISM_8BIT:
enc = "8bit";
break;
case MAILMIME_MECHANISM_BINARY:
enc = "binary";
break;
case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
enc = "quoted-printable";
break;
case MAILMIME_MECHANISM_BASE64:
enc = "base64";
break;
case MAILMIME_MECHANISM_TOKEN:
default:
if (aEnc->enc_token) {
enc = QString(aEnc->enc_token);
}
break;
}
return enc;
}
void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count)
{
if (current_rec >= 10) {
; // odebug << "too deep recursion!" << oendl;
}
if (!message || !mime) {
return;
}
int r;
char*data = 0;
size_t len;
clistiter * cur = 0;
QString b;
RecPartP part = new RecPart();
switch (mime->mm_type) {
case MAILMIME_SINGLE:
{
QValueList<int>countlist = recList;
countlist.append(current_count);
r = mailmessage_fetch_section(message,mime,&data,&len);
part->setSize(len);
part->setPositionlist(countlist);
b = gen_attachment_id();
part->setIdentifier(b);
fillSingleBody(part,message,mime);
if (part->Type()=="text" && target->Bodytext().isNull()) {
encodedString*rs = new encodedString();
rs->setContent(data,len);
encodedString*res = decode_String(rs,part->Encoding());
if (countlist.count()>2) {
bodyCache[b]=rs;
target->addPart(part);
} else {
delete rs;
}
b = QString(res->Content());
delete res;
target->setBodytext(b);
target->setDescription(part);
} else {
bodyCache[b]=new encodedString(data,len);
target->addPart(part);
}
}
break;
case MAILMIME_MULTIPLE:
{
unsigned int ccount = 1;
mailmime*cbody=0;
QValueList<int>countlist = recList;
for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
cbody = (mailmime*)clist_content(cur);
if (cbody->mm_type==MAILMIME_MULTIPLE) {
RecPartP targetPart = new RecPart();
targetPart->setType("multipart");
countlist.append(current_count);
targetPart->setPositionlist(countlist);
target->addPart(targetPart);
}
traverseBody(target,message, cbody,countlist,current_rec+1,ccount);
if (cbody->mm_type==MAILMIME_MULTIPLE) {
countlist = recList;
}
++ccount;
}
}
break;
case MAILMIME_MESSAGE:
{
QValueList<int>countlist = recList;
countlist.append(current_count);
/* the own header is always at recursion 0 - we don't need that */
if (current_rec > 0) {
part->setPositionlist(countlist);
r = mailmessage_fetch_section(message,mime,&data,&len);
part->setSize(len);
part->setPositionlist(countlist);
b = gen_attachment_id();
part->setIdentifier(b);
part->setType("message");
part->setSubtype("rfc822");
bodyCache[b]=new encodedString(data,len);
target->addPart(part);
}
if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1);
}
}
break;
}
}
RecBodyP Genericwrapper::parseMail( mailmessage * msg )
{
int err = MAILIMF_NO_ERROR;
mailmime_single_fields fields;
/* is bound to msg and will be freed there */
mailmime * mime=0;
RecBodyP body = new RecBody();
memset(&fields, 0, sizeof(struct mailmime_single_fields));
err = mailmessage_get_bodystructure(msg,&mime);
QValueList<int>recList;
traverseBody(body,msg,mime,recList);
return body;
}
QString Genericwrapper::parseAddressList( mailimf_address_list *list )
{
QString result( "" );
bool first = true;
if (list == 0) return result;
for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
mailimf_address *addr = (mailimf_address *) current->data;
if ( !first ) {
result.append( "," );
} else {
first = false;
}
switch ( addr->ad_type ) {
case MAILIMF_ADDRESS_MAILBOX:
result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
break;
case MAILIMF_ADDRESS_GROUP:
result.append( parseGroup( addr->ad_data.ad_group ) );
break;
default:
; // odebug << "Generic: unkown mailimf address type" << oendl;