summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper
authorzautrix <zautrix>2004-11-07 17:35:51 (UTC)
committer zautrix <zautrix>2004-11-07 17:35:51 (UTC)
commitd90d17044d7daf6677074b0964d59f94407157d5 (patch) (side-by-side diff)
tree82bf4f2001465637572534650769a864c15a6f7c /kmicromail/libmailwrapper
parentb6ef669713ee1d52adcfc9754dd039a4ff6675da (diff)
downloadkdepimpi-d90d17044d7daf6677074b0964d59f94407157d5.zip
kdepimpi-d90d17044d7daf6677074b0964d59f94407157d5.tar.gz
kdepimpi-d90d17044d7daf6677074b0964d59f94407157d5.tar.bz2
some mail fixes and warnings removed
Diffstat (limited to 'kmicromail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/generatemail.cpp16
-rw-r--r--kmicromail/libmailwrapper/generatemail.h1
-rw-r--r--kmicromail/libmailwrapper/genericwrapper.cpp3
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp4
-rw-r--r--kmicromail/libmailwrapper/mailwrapper.h2
5 files changed, 17 insertions, 9 deletions
diff --git a/kmicromail/libmailwrapper/generatemail.cpp b/kmicromail/libmailwrapper/generatemail.cpp
index 32311d7..2d213fe 100644
--- a/kmicromail/libmailwrapper/generatemail.cpp
+++ b/kmicromail/libmailwrapper/generatemail.cpp
@@ -1,39 +1,40 @@
#include "generatemail.h"
#include "mailwrapper.h"
#include <libetpan/libetpan.h>
//#include <qt.h>
#include <stdlib.h>
#include <qfileinfo.h>
using namespace Opie::Core;
const char* Generatemail::USER_AGENT="KOpieMail 33 1/3";
Generatemail::Generatemail()
{
+ mCharset = "iso-8859-1";
}
Generatemail::~Generatemail()
{
}
void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) {
clistiter *it, *it2;
for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
mailimf_address *addr;
addr = (mailimf_address *) it->data;
if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
} else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
mailimf_mailbox *mbox;
mbox = (mailimf_mailbox *) it2->data;
esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
}
}
}
@@ -124,74 +125,75 @@ mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) {
return addresses;
}
mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) {
mailmime * filePart = 0;
mailmime_fields * fields = 0;
mailmime_content * content = 0;
mailmime_parameter * param = 0;
char*name = 0;
char*file = 0;
int err;
int pos = filename.findRev( '/' );
if (filename.length()>0) {
QString tmp = filename.right( filename.length() - ( pos + 1 ) );
name = strdup( tmp.latin1() ); // just filename
file = strdup( filename.latin1() ); // full name with path
}
int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
int mechanism = MAILMIME_MECHANISM_BASE64;
if ( mimetype.startsWith( "text/" ) ) {
param = mailmime_parameter_new( strdup( "charset" ),
- strdup( "iso-8859-1" ) );
+ strdup( mCharset.latin1() ) );
mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
}
fields = mailmime_fields_new_filename(
disptype, name,
mechanism );
content = mailmime_content_new_with_str( (char*)mimetype.latin1() );
if (content!=0 && fields != 0) {
if (param) {
clist_append(content->ct_parameters,param);
param = 0;
}
if (filename.length()>0) {
QFileInfo f(filename);
param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
clist_append(content->ct_parameters,param);
param = 0;
}
filePart = mailmime_new_empty( content, fields );
}
if (filePart) {
if (filename.length()>0) {
err = mailmime_set_body_file( filePart, file );
} else {
- err = mailmime_set_body_text(filePart,strdup( TextContent.utf8()),TextContent.utf8().length());
+ err = mailmime_set_body_text(filePart,strdup( TextContent.utf8().data()),TextContent.utf8().length());
+ //err = mailmime_set_body_text(filePart,strdup( TextContent.latin1()),TextContent.length());
}
if (err != MAILIMF_NO_ERROR) {
qDebug("Error setting body with file ");
mailmime_free( filePart );
filePart = 0;
}
}
if (!filePart) {
if ( param != NULL ) {
mailmime_parameter_free( param );
}
if (content) {
mailmime_content_free( content );
}
if (fields) {
mailmime_fields_free( fields );
} else {
if (name) {
free( name );
}
if (file) {
free( file );
}
@@ -206,71 +208,73 @@ void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files
unsigned int count = files.count();
for ( unsigned int i = 0; i < count; ++i ) {
mailmime *filePart;
int err;
it = ((QList<Attachment>)files).at(i);
filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" );
if ( filePart == NULL ) {
continue;
}
err = mailmime_smart_add_part( message, filePart );
if ( err != MAILIMF_NO_ERROR ) {
mailmime_free( filePart );
}
}
}
mailmime *Generatemail::buildTxtPart(const QString&str ) {
mailmime *txtPart;
mailmime_fields *fields;
mailmime_content *content;
mailmime_parameter *param;
int err;
QCString __str;
+ //qDebug(" Generatemail::buildTxtPart %s", str.latin1());
param = mailmime_parameter_new( strdup( "charset" ),
- strdup( "iso-8859-1" ) );
+ strdup( mCharset.latin1() ) );
if ( param == NULL )
goto err_free;
content = mailmime_content_new_with_str( "text/plain" );
if ( content == NULL )
goto err_free_param;
err = clist_append( content->ct_parameters, param );
if ( err != MAILIMF_NO_ERROR )
goto err_free_content;
fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT);
if ( fields == NULL )
goto err_free_content;
txtPart = mailmime_new_empty( content, fields );
if ( txtPart == NULL )
goto err_free_fields;
{
- __str = str.utf8();
- err = mailmime_set_body_text( txtPart, __str.data(), __str.length() );
+ //__str = str.utf8();
+ __str = QCString (str.latin1());
+ err = mailmime_set_body_text( txtPart, strdup(__str.data()), __str.length() );
}
if ( err != MAILIMF_NO_ERROR )
goto err_free_txtPart;
return txtPart; // Success :)
err_free_txtPart:
mailmime_free( txtPart );
err_free_fields:
mailmime_fields_free( fields );
err_free_content:
mailmime_content_free( content );
err_free_param:
mailmime_parameter_free( param );
err_free:
;
return NULL; // Error :(
}
mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) {
return mailimf_mailbox_new( strdup( name.latin1() ),
strdup( mail.latin1() ) );
}
@@ -377,48 +381,50 @@ mailimf_fields *Generatemail::createImfFields(const Opie::Core::OSmartPointer<Ma
mailimf_address_list_free( cc );
if (to)
mailimf_address_list_free( to );
if (fromBox) {
mailimf_mailbox_free( fromBox );
} else if (from) {
mailimf_mailbox_list_free( from );
}
if (sender) {
mailimf_mailbox_free( sender );
}
if (subject) {
free( subject );
}
}
}
return fields;
}
mailmime *Generatemail::createMimeMail(const Opie::Core::OSmartPointer<Mail> &mail ) {
mailmime *message, *txtPart;
mailimf_fields *fields;
int err;
+ //LR disabled for now
+ //mCharset = mail->getCharset().lower();
fields = createImfFields( mail );
if ( fields == NULL )
goto err_free;
message = mailmime_new_message_data( NULL );
if ( message == NULL )
goto err_free_fields;
mailmime_set_imf_fields( message, fields );
txtPart = buildTxtPart( mail->getMessage() );
if ( txtPart == NULL )
goto err_free_message;
err = mailmime_smart_add_part( message, txtPart );
if ( err != MAILIMF_NO_ERROR )
goto err_free_txtPart;
addFileParts( message, mail->getAttachments() );
return message; // Success :)
err_free_txtPart:
diff --git a/kmicromail/libmailwrapper/generatemail.h b/kmicromail/libmailwrapper/generatemail.h
index b9f8285..a9fb648 100644
--- a/kmicromail/libmailwrapper/generatemail.h
+++ b/kmicromail/libmailwrapper/generatemail.h
@@ -21,27 +21,28 @@ class progressMailSend;
struct mailsmtp;
class Generatemail : public QObject
{
Q_OBJECT
public:
Generatemail();
virtual ~Generatemail();
protected:
static void addRcpts( clist *list, mailimf_address_list *addr_list );
static char *getFrom( mailmime *mail );
static char *getFrom( mailimf_field *ffrom);
static mailimf_field *getField( mailimf_fields *fields, int type );
mailimf_address_list *parseAddresses(const QString&addr );
void addFileParts( mailmime *message,const QList<Attachment>&files );
mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
mailmime *buildTxtPart(const QString&str );
mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
mailimf_fields *createImfFields(const Opie::Core::OSmartPointer<Mail> &mail );
mailmime *createMimeMail(const Opie::Core::OSmartPointer<Mail>&mail );
clist *createRcptList( mailimf_fields *fields );
static const char* USER_AGENT;
+ QString mCharset;
};
#endif
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp
index 28d45ce..eac05e5 100644
--- a/kmicromail/libmailwrapper/genericwrapper.cpp
+++ b/kmicromail/libmailwrapper/genericwrapper.cpp
@@ -204,49 +204,50 @@ void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*m
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;
size_t index = 0;
char*resu = 0;
int err = MAILIMF_NO_ERROR;
QString charset = part->searchParamter( "charset");
qDebug("CHARSET %s ",charset.latin1() );
- if ( !charset.isEmpty() ) {
+ if (false ) {
+ //if ( !charset.isEmpty() ) {
target->setCharset( charset );
err = mailmime_encoded_phrase_parse(charset.latin1(),
b.latin1(), b.length(),&index, "utf-8",&resu);
if (err == MAILIMF_NO_ERROR && resu && strlen(resu)) {
//qDebug("res %d %s ", index, resu);
b = QString::fromUtf8(resu);
}
if (resu) free(resu);
}
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);
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index 2a54381..da7065f 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -738,50 +738,50 @@ void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&t
QValueList<int>countlist = recList;
countlist.append(current_count);
RecPartP currentPart = new RecPart();
mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
QString id("");
currentPart->setPositionlist(countlist);
for (unsigned int j = 0; j < countlist.count();++j) {
id+=(j>0?" ":"");
id+=QString("%1").arg(countlist[j]);
}
//odebug << "ID = " << id.latin1() << "" << oendl;
currentPart->setIdentifier(id);
fillSinglePart(currentPart,part1);
/* important: Check for is NULL 'cause a body can be empty!
And we put it only into the mail if it is the FIRST part */
if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) {
QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding());
size_t index = 0;
char*res = 0;
int err = MAILIMF_NO_ERROR;
QString charset = currentPart->searchParamter( "charset");
qDebug("CHARSET %s ",charset.latin1() );
- //if ( false ) {
- if ( !charset.isEmpty() ) {
+ if ( false ) {
+ //if ( !charset.isEmpty() ) {
target_body->setCharset( charset );
//err = mailmime_encoded_phrase_parse("iso-8859-1",
// text, strlen(text),&index, "iso-8859-1",&res);
err = mailmime_encoded_phrase_parse(charset.latin1(),
body_text.latin1(), body_text.length(),&index, "utf-8",&res);
if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
//qDebug("res %d %s ", index, res);
body_text = QString::fromUtf8(res);
}
if (res) free(res);
}
//qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() );
target_body->setDescription(currentPart);
target_body->setBodytext(body_text);
if (countlist.count()>1) {
target_body->addPart(currentPart);
}
} else {
target_body->addPart(currentPart);
}
if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
}
}
diff --git a/kmicromail/libmailwrapper/mailwrapper.h b/kmicromail/libmailwrapper/mailwrapper.h
index ea6bf36..3e8b51f 100644
--- a/kmicromail/libmailwrapper/mailwrapper.h
+++ b/kmicromail/libmailwrapper/mailwrapper.h
@@ -62,49 +62,49 @@ public:
virtual ~Mail(){}
void addAttachment( Attachment *att ) { attList.append( att ); }
const QList<Attachment>& getAttachments()const { return attList; }
void removeAttachment( Attachment *att ) { attList.remove( att ); }
const QString&getName()const { return name; }
void setName( QString s ) { name = s; }
const QString&getMail()const{ return mail; }
void setMail( const QString&s ) { mail = s; }
const QString&getTo()const{ return to; }
void setTo( const QString&s ) { to = s; }
const QString&getCC()const{ return cc; }
void setCC( const QString&s ) { cc = s; }
const QString&getBCC()const { return bcc; }
void setBCC( const QString&s ) { bcc = s; }
const QString&getMessage()const { return message; }
void setMessage( const QString&s ) { message = s; }
const QString&getSubject()const { return subject; }
void setSubject( const QString&s ) { subject = s; }
const QString&getReply()const{ return reply; }
void setReply( const QString&a ) { reply = a; }
void setInreply(const QStringList&list){m_in_reply_to = list;}
const QStringList&Inreply()const{return m_in_reply_to;}
void setCharset( const QString&a ) { charset= a; }
- const QString& getCharset() { return charset; }
+ const QString& getCharset() const { return charset; }
private:
QList<Attachment> attList;
QString name, mail, to, cc, bcc, reply, subject, message, charset;
QStringList m_in_reply_to;
};
class Folder:public Opie::Core::ORefCount
{
public:
Folder( const QString&init_name,const QString&sep );
virtual ~Folder();
const QString&getDisplayName()const { return nameDisplay; }
const QString&getName()const { return name; }
const QString&getPrefix()const{return prefix; }
virtual bool may_select()const{return true;}
virtual bool no_inferior()const{return true;}
const QString&Separator()const;
protected:
QString nameDisplay, name, separator,prefix;
};
typedef Opie::Core::OSmartPointer<Folder> FolderP;