summaryrefslogtreecommitdiff
authoralwin <alwin>2004-01-04 01:53:04 (UTC)
committer alwin <alwin>2004-01-04 01:53:04 (UTC)
commit6fd109ed595e4e28f49f5de0a26e9f9445e672f6 (patch) (side-by-side diff)
tree4bbd79045d003701bd6bdd649b1057fee9549fc6
parent4c9f71fba68fcf98b0b4c9b14b699282dfe962e5 (diff)
downloadopie-6fd109ed595e4e28f49f5de0a26e9f9445e672f6.zip
opie-6fd109ed595e4e28f49f5de0a26e9f9445e672f6.tar.gz
opie-6fd109ed595e4e28f49f5de0a26e9f9445e672f6.tar.bz2
moved to shared lib for usage with tody and taskbar plugin
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/abstractmail.cpp94
-rw-r--r--noncore/net/mail/abstractmail.h53
-rw-r--r--noncore/net/mail/imapwrapper.cpp976
-rw-r--r--noncore/net/mail/imapwrapper.h68
-rw-r--r--noncore/net/mail/mailtypes.cpp335
-rw-r--r--noncore/net/mail/mailtypes.h192
-rw-r--r--noncore/net/mail/mboxwrapper.cpp324
-rw-r--r--noncore/net/mail/mboxwrapper.h42
-rw-r--r--noncore/net/mail/pop3wrapper.cpp229
-rw-r--r--noncore/net/mail/pop3wrapper.h39
-rw-r--r--noncore/net/mail/smtpwrapper.cpp732
-rw-r--r--noncore/net/mail/smtpwrapper.h71
12 files changed, 0 insertions, 3155 deletions
diff --git a/noncore/net/mail/abstractmail.cpp b/noncore/net/mail/abstractmail.cpp
deleted file mode 100644
index f303d72..0000000
--- a/noncore/net/mail/abstractmail.cpp
+++ b/dev/null
@@ -1,94 +0,0 @@
-#include "abstractmail.h"
-#include "imapwrapper.h"
-#include "pop3wrapper.h"
-#include "mboxwrapper.h"
-#include "mailtypes.h"
-
-#include <qstring.h>
-#include <qfile.h>
-#include <qtextstream.h>
-#include <stdlib.h>
-#include <libetpan/mailmime_content.h>
-#include <libetpan/mailmime.h>
-
-AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
-{
- return new IMAPwrapper(a);
-}
-
-AbstractMail* AbstractMail::getWrapper(POP3account *a)
-{
- return new POP3wrapper(a);
-}
-
-AbstractMail* AbstractMail::getWrapper(const QString&a)
-{
- return new MBOXwrapper(a);
-}
-
-encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
-{
- qDebug("Decode string start");
- 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);
- }
- qDebug("Decode string finished");
- return result;
-}
-
-QString AbstractMail::convert_String(const char*text)
-{
- size_t index = 0;
- char*res = 0;
-
- /* attention - doesn't work with arm systems! */
- int err = mailmime_encoded_phrase_parse("iso-8859-1",
- text, strlen(text),&index, "iso-8859-1",&res);
- if (err != MAILIMF_NO_ERROR) {
- if (res) free(res);
- return QString(text);
- }
- if (res) {
- QString result(res);
- free(res);
- return result;
- }
- return QString(text);
-}
-
-/* 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 Folder*,const QString& delemiter,bool)
-{
- return 0;
-}
diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h
deleted file mode 100644
index dab9e10..0000000
--- a/noncore/net/mail/abstractmail.h
+++ b/dev/null
@@ -1,53 +0,0 @@
-#ifndef __abstract_mail_
-#define __abstract_mail_
-
-#include <qobject.h>
-#include "settings.h"
-
-class RecMail;
-class RecBody;
-class RecPart;
-class IMAPwrapper;
-class POP3wrapper;
-class Folder;
-class encodedString;
-struct folderStat;
-
-class AbstractMail:public QObject
-{
- Q_OBJECT
-public:
- AbstractMail(){};
- virtual ~AbstractMail(){}
- virtual QList<Folder>* listFolders()=0;
- virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
- virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0;
- virtual RecBody fetchBody(const RecMail&mail)=0;
- virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
- virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
- virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
-
- virtual void deleteMail(const RecMail&mail)=0;
- virtual void answeredMail(const RecMail&mail)=0;
- virtual void cleanMimeCache(){};
- virtual int deleteAllMail(const Folder*){return 1;}
- virtual int deleteMbox(const Folder*){return 1;}
-
- /* mail box methods */
- /* parameter is the box to create.
- * if the implementing subclass has prefixes,
- * them has to be appended automatic.
- */
- virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
-
- static AbstractMail* getWrapper(IMAPaccount *a);
- static AbstractMail* getWrapper(POP3account *a);
- /* mbox only! */
- static AbstractMail* getWrapper(const QString&a);
-
-protected:
- static encodedString*decode_String(const encodedString*text,const QString&enc);
- static QString convert_String(const char*text);
- static QString gen_attachment_id();
-};
-#endif
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
deleted file mode 100644
index f1d42c2..0000000
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/dev/null
@@ -1,976 +0,0 @@
-#include <stdlib.h>
-#include <libetpan/libetpan.h>
-#include <qpe/global.h>
-
-#include "imapwrapper.h"
-#include "mailtypes.h"
-#include "logindialog.h"
-
-IMAPwrapper::IMAPwrapper( IMAPaccount *a )
- : AbstractMail()
-{
- account = a;
- m_imap = 0;
-}
-
-IMAPwrapper::~IMAPwrapper()
-{
- logout();
-}
-
-void IMAPwrapper::imap_progress( size_t current, size_t maximum )
-{
- qDebug( "IMAP: %i of %i", current, maximum );
-}
-
-void IMAPwrapper::login()
-{
- const char *server, *user, *pass;
- uint16_t port;
- int err = MAILIMAP_NO_ERROR;
-
- /* we are connected this moment */
- /* TODO: setup a timer holding the line or if connection closed - delete the value */
- if (m_imap) {
- err = mailimap_noop(m_imap);
- if (err!=MAILIMAP_NO_ERROR) {
- logout();
- } else {
- mailstream_flush(m_imap->imap_stream);
- return;
- }
- }
- server = account->getServer().latin1();
- port = account->getPort().toUInt();
- if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
- LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
- login.show();
- if ( QDialog::Accepted == login.exec() ) {
- // ok
- user = strdup( login.getUser().latin1() );
- pass = strdup( login.getPassword().latin1() );
- } else {
- // cancel
- qDebug( "IMAP: Login canceled" );
- return;
- }
- } else {
- user = account->getUser().latin1();
- pass = account->getPassword().latin1();
- }
-
- m_imap = mailimap_new( 20, &imap_progress );
-
- /* connect */
- if (account->getSSL()) {
- err = mailimap_ssl_connect( m_imap, (char*)server, port );
- } else {
- err = mailimap_socket_connect( m_imap, (char*)server, port );
- }
-
- if ( err != MAILIMAP_NO_ERROR &&
- err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
- err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
- QString failure = "";
- if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
- failure="Connection refused";
- } else {
- failure="Unknown failure";
- }
- Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
- mailimap_free( m_imap );
- m_imap = 0;
- return;
- }
-
- /* login */
- err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
- if ( err != MAILIMAP_NO_ERROR ) {
- Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
- err = mailimap_close( m_imap );
- mailimap_free( m_imap );
- m_imap = 0;
- }
-}
-
-void IMAPwrapper::logout()
-{
- int err = MAILIMAP_NO_ERROR;
- if (!m_imap) return;
- err = mailimap_logout( m_imap );
- err = mailimap_close( m_imap );
- mailimap_free( m_imap );
- m_imap = 0;
-}
-
-void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
-{
- const char *mb = 0;
- int err = MAILIMAP_NO_ERROR;
- clist *result = 0;
- clistcell *current;
-// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
- mailimap_fetch_type *fetchType = 0;
- mailimap_set *set = 0;
-
- mb = mailbox.latin1();
- login();
- if (!m_imap) {
- return;
- }
- /* select mailbox READONLY for operations */
- err = mailimap_examine( m_imap, (char*)mb);
- if ( err != MAILIMAP_NO_ERROR ) {
- Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response));
- return;
- }
-
- int last = m_imap->imap_selection_info->sel_exists;
-
- if (last == 0) {
- Global::statusMessage(tr("Mailbox has no mails"));
- return;
- } else {
- Global::statusMessage(tr("Mailbox has %1 mails").arg(last));
- }
-
- /* the range has to start at 1!!! not with 0!!!! */
- set = mailimap_set_new_interval( 1, last );
- fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
- mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
- mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
- mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
- mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
-
- err = mailimap_fetch( m_imap, set, fetchType, &result );
- mailimap_set_free( set );
- mailimap_fetch_type_free( fetchType );
-
- QString date,subject,from;
-
- if ( err == MAILIMAP_NO_ERROR ) {
- mailimap_msg_att * msg_att;
- int i = 0;
- for (current = clist_begin(result); current != 0; current=clist_next(current)) {
- ++i;
- msg_att = (mailimap_msg_att*)current->data;
- RecMail*m = parse_list_result(msg_att);
- if (m) {
- m->setNumber(i);
- m->setMbox(mailbox);
- m->setWrapper(this);
- target.append(m);
- }
- }
- } else {
- Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
- }
- if (result) mailimap_fetch_list_free(result);
-}
-
-QList<Folder>* IMAPwrapper::listFolders()
-{
- const char *path, *mask;
- int err = MAILIMAP_NO_ERROR;
- clist *result = 0;
- clistcell *current = 0;
- clistcell*cur_flag = 0;
- mailimap_mbx_list_flags*bflags = 0;
-
- QList<Folder> * folders = new QList<Folder>();
- folders->setAutoDelete( false );
- login();
- if (!m_imap) {
- return folders;
- }
-
-/*
- * First we have to check for INBOX 'cause it sometimes it's not inside the path.
- * We must not forget to filter them out in next loop!
- * it seems like ugly code. and yes - it is ugly code. but the best way.
- */
- QString temp;
- mask = "INBOX" ;
- mailimap_mailbox_list *list;
- err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
- QString del;
- bool selectable = true;
- bool no_inferiors = false;
- if ( err == MAILIMAP_NO_ERROR ) {
- current = result->first;
- for ( int i = result->count; i > 0; i-- ) {
- list = (mailimap_mailbox_list *) current->data;
- // it is better use the deep copy mechanism of qt itself
- // instead of using strdup!
- temp = list->mb_name;
- del = list->mb_delimiter;
- current = current->next;
- if ( (bflags = list->mb_flag) ) {
- selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
- bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
- for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
- if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
- no_inferiors = true;
- }
- }
- }
- folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
- }
- } else {
- qDebug("error fetching folders: %s",m_imap->imap_response);
- }
- mailimap_list_result_free( result );
-
-/*
- * second stage - get the other then inbox folders
- */
- mask = "*" ;
- path = account->getPrefix().latin1();
- if (!path) path = "";
- qDebug(path);
- err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
- if ( err == MAILIMAP_NO_ERROR ) {
- current = result->first;
- for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
- no_inferiors = false;
- list = (mailimap_mailbox_list *) current->data;
- // it is better use the deep copy mechanism of qt itself
- // instead of using strdup!
- temp = list->mb_name;
- if (temp.lower()=="inbox")
- continue;
- if (temp.lower()==account->getPrefix().lower())
- continue;
- if ( (bflags = list->mb_flag) ) {
- selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
- bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
- for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
- if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
- no_inferiors = true;
- }
- }
- }
- del = list->mb_delimiter;
- folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
- }
- } else {
- qDebug("error fetching folders %s",m_imap->imap_response);
- }
- if (result) mailimap_list_result_free( result );
- return folders;
-}
-
-RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
-{
- RecMail * m = 0;
- mailimap_msg_att_item *item=0;
- clistcell *current,*c,*cf;
- mailimap_msg_att_dynamic*flist;
- mailimap_flag_fetch*cflag;
- int size;
- QBitArray mFlags(7);
- QStringList addresslist;
-
- if (!m_att) {
- return m;
- }
- m = new RecMail();
- for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
- current = c;
- size = 0;
- item = (mailimap_msg_att_item*)current->data;
- if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
- flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
- if (!flist->att_list) {
- continue;
- }
- cf = flist->att_list->first;
- for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
- cflag = (mailimap_flag_fetch*)cf->data;
- if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
- switch (cflag->fl_flag->fl_type) {
- case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
- mFlags.setBit(FLAG_ANSWERED);
- break;
- case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
- mFlags.setBit(FLAG_FLAGGED);
- break;
- case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
- mFlags.setBit(FLAG_DELETED);
- break;
- case MAILIMAP_FLAG_SEEN: /* \Seen flag */
- mFlags.setBit(FLAG_SEEN);
- break;
- case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
- mFlags.setBit(FLAG_DRAFT);
- break;
- case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
- break;
- case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
- break;
- default:
- break;
- }
- } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
- mFlags.setBit(FLAG_RECENT);
- }
- }
- continue;
- }
- if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
- mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
- m->setDate(head->env_date);
- m->setSubject(convert_String((const char*)head->env_subject));
- //m->setSubject(head->env_subject);
- if (head->env_from!=NULL) {
- addresslist = address_list_to_stringlist(head->env_from->frm_list);
- if (addresslist.count()) {
- m->setFrom(addresslist.first());
- }
- }
- if (head->env_to!=NULL) {
- addresslist = address_list_to_stringlist(head->env_to->to_list);
- m->setTo(addresslist);
- }
- if (head->env_cc!=NULL) {
- addresslist = address_list_to_stringlist(head->env_cc->cc_list);
- m->setCC(addresslist);
- }
- if (head->env_bcc!=NULL) {
- addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
- m->setBcc(addresslist);
- }
- if (head->env_reply_to!=NULL) {
- addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
- if (addresslist.count()) {
- m->setReplyto(addresslist.first());
- }
- }
- m->setMsgid(QString(head->env_message_id));
- } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
-#if 0
- mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
- QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
- qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec);
- qDebug(da.toString());
-#endif
- } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
- size = item->att_data.att_static->att_data.att_rfc822_size;
- }
- }
- /* msg is already deleted */
- if (mFlags.testBit(FLAG_DELETED) && m) {
- delete m;
- m = 0;
- }
- if (m) {
- m->setFlags(mFlags);
- m->setMsgsize(size);
- }
- return m;
-}
-
-RecBody IMAPwrapper::fetchBody(const RecMail&mail)
-{
- RecBody body;
- const char *mb;
- int err = MAILIMAP_NO_ERROR;
- clist *result = 0;
- clistcell *current;
- mailimap_fetch_att *fetchAtt = 0;
- mailimap_fetch_type *fetchType = 0;
- mailimap_set *set = 0;
- mailimap_body*body_desc = 0;
-
- mb = mail.getMbox().latin1();
-
- login();
- if (!m_imap) {
- return body;
- }
-
- err = mailimap_select( m_imap, (char*)mb);
- if ( err != MAILIMAP_NO_ERROR ) {
- qDebug("error selecting mailbox: %s",m_imap->imap_response);
- return body;
- }
-
- /* the range has to start at 1!!! not with 0!!!! */
- set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
- fetchAtt = mailimap_fetch_att_new_bodystructure();
- fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
- err = mailimap_fetch( m_imap, set, fetchType, &result );
- mailimap_set_free( set );
- mailimap_fetch_type_free( fetchType );
-
- if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
- mailimap_msg_att * msg_att;
- msg_att = (mailimap_msg_att*)current->data;
- mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
- QValueList<int> path;
- body_desc = item->att_data.att_static->att_data.att_body;
- traverseBody(mail,body_desc,body,0,path);
- } else {
- qDebug("error fetching body: %s",m_imap->imap_response);
- }
- if (result) mailimap_fetch_list_free(result);
- return body;
-}
-
-QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
-{
- QStringList l;
- QString from;
- bool named_from;
- clistcell *current = NULL;
- mailimap_address * current_address=NULL;
- if (!list) {
- return l;
- }
- unsigned int count = 0;
- for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
- from = "";
- named_from = false;
- current_address=(mailimap_address*)current->data;
- if (current_address->ad_personal_name){
- from+=convert_String((const char*)current_address->ad_personal_name);
- from+=" ";
- named_from = true;
- }
- if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
- from+="<";
- }
- if (current_address->ad_mailbox_name) {
- from+=QString(current_address->ad_mailbox_name);
- from+="@";
- }
- if (current_address->ad_host_name) {
- from+=QString(current_address->ad_host_name);
- }
- if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
- from+=">";
- }
- l.append(QString(from));
- if (++count > 99) {
- break;
- }
- }
- return l;
-}
-
-encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
-{
- encodedString*res=new encodedString;
- const char*mb;
- int err;
- mailimap_fetch_type *fetchType;
- mailimap_set *set;
- clistcell*current,*cur;
-
- login();
- if (!m_imap) {
- return res;
- }
- if (!internal_call) {
- mb = mail.getMbox().latin1();
- err = mailimap_select( m_imap, (char*)mb);
- if ( err != MAILIMAP_NO_ERROR ) {
- qDebug("error selecting mailbox: %s",m_imap->imap_response);
- return res;
- }
- }
- set = mailimap_set_new_single(mail.getNumber());
- clist*id_list=clist_new();
- for (unsigned j=0; j < path.count();++j) {
- uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
- *p_id = path[j];
- clist_append(id_list,p_id);
- }
- mailimap_section_part * section_part = mailimap_section_part_new(id_list);
- mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
- mailimap_section * section = mailimap_section_new(section_spec);
- mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
-
- fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
-
- clist*result = 0;
-
- err = mailimap_fetch( m_imap, set, fetchType, &result );
- mailimap_set_free( set );
- mailimap_fetch_type_free( fetchType );
-
- if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
- mailimap_msg_att * msg_att;
- msg_att = (mailimap_msg_att*)current->data;
- mailimap_msg_att_item*msg_att_item;
- for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
- msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
- if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
- if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
- char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
- /* detach - we take over the content */
- msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
- res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
- }
- }
- }
- } else {
- qDebug("error fetching text: %s",m_imap->imap_response);
- }
- if (result) mailimap_fetch_list_free(result);
- return res;
-}
-
-/* current_recursion is for recursive calls.
- current_count means the position inside the internal loop! */
-void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,
- int current_recursion,QValueList<int>recList,int current_count)
-{
- if (!body || current_recursion>=10) {
- return;
- }
- switch (body->bd_type) {
- case MAILIMAP_BODY_1PART:
- {
- QValueList<int>countlist = recList;
- countlist.append(current_count);
- RecPart currentPart;
- 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]);
- }
- qDebug("ID = %s",id.latin1());
- 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());
- 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);
- }
- }
- break;
- case MAILIMAP_BODY_MPART:
- {
- QValueList<int>countlist = recList;
- clistcell*current=0;
- mailimap_body*current_body=0;
- unsigned int ccount = 1;
- mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
- for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
- current_body = (mailimap_body*)current->data;
- if (current_body->bd_type==MAILIMAP_BODY_MPART) {
- RecPart targetPart;
- targetPart.setType("multipart");
- fillMultiPart(targetPart,mailDescription);
- countlist.append(current_count);
- targetPart.setPositionlist(countlist);
- target_body.addPart(targetPart);
- QString id("");
- for (unsigned int j = 0; j < countlist.count();++j) {
- id+=(j>0?" ":"");
- id+=QString("%1").arg(countlist[j]);
- }
- qDebug("ID(mpart) = %s",id.latin1());
- }
- traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
- if (current_body->bd_type==MAILIMAP_BODY_MPART) {
- countlist = recList;
- }
- ++ccount;
- }
- }
- break;
- default:
- break;
- }
-}
-
-void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
-{
- if (!Description) {
- return;
- }
- switch (Description->bd_type) {
- case MAILIMAP_BODY_TYPE_1PART_TEXT:
- target_part.setType("text");
- fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
- break;
- case MAILIMAP_BODY_TYPE_1PART_BASIC:
- fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
- break;
- case MAILIMAP_BODY_TYPE_1PART_MSG:
- target_part.setType("message");
- fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
- break;
- default:
- break;
- }
-}
-
-void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
-{
- if (!which) {
- return;
- }
- QString sub;
- sub = which->bd_media_text;
- qDebug("Type= text/%s",which->bd_media_text);
- target_part.setSubtype(sub.lower());
- target_part.setLines(which->bd_lines);
- fillBodyFields(target_part,which->bd_fields);
-}
-
-void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
-{
- if (!which) {
- return;
- }
- target_part.setSubtype("rfc822");
- qDebug("Message part");
- /* we set this type to text/plain */
- target_part.setLines(which->bd_lines);
- fillBodyFields(target_part,which->bd_fields);
-}
-
-void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which)
-{
- if (!which) return;
- QString sub = which->bd_media_subtype;
- target_part.setSubtype(sub.lower());
- if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
- clistcell*cur = 0;
- mailimap_single_body_fld_param*param=0;
- for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
- param = (mailimap_single_body_fld_param*)cur->data;
- if (param) {
- target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
- }
- }
- }
-}
-
-void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
-{
- if (!which) {
- return;
- }
- QString type,sub;
- switch (which->bd_media_basic->med_type) {
- case MAILIMAP_MEDIA_BASIC_APPLICATION:
- type = "application";
- break;
- case MAILIMAP_MEDIA_BASIC_AUDIO:
- type = "audio";
- break;
- case MAILIMAP_MEDIA_BASIC_IMAGE:
- type = "image";
- break;
- case MAILIMAP_MEDIA_BASIC_MESSAGE:
- type = "message";
- break;
- case MAILIMAP_MEDIA_BASIC_VIDEO:
- type = "video";
- break;
- case MAILIMAP_MEDIA_BASIC_OTHER:
- default:
- if (which->bd_media_basic->med_basic_type) {
- type = which->bd_media_basic->med_basic_type;
- } else {
- type = "";
- }
- break;
- }
- if (which->bd_media_basic->med_subtype) {
- sub = which->bd_media_basic->med_subtype;
- } else {
- sub = "";
- }
- qDebug("Type = %s/%s",type.latin1(),sub.latin1());
- target_part.setType(type.lower());
- target_part.setSubtype(sub.lower());
- fillBodyFields(target_part,which->bd_fields);
-}
-
-void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
-{
- if (!which) return;
- if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
- clistcell*cur;
- mailimap_single_body_fld_param*param=0;
- for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
- param = (mailimap_single_body_fld_param*)cur->data;
- if (param) {
- target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
- }
- }
- }
- mailimap_body_fld_enc*enc = which->bd_encoding;
- QString encoding("");
- switch (enc->enc_type) {
- case MAILIMAP_BODY_FLD_ENC_7BIT:
- encoding = "7bit";
- break;
- case MAILIMAP_BODY_FLD_ENC_8BIT:
- encoding = "8bit";
- break;
- case MAILIMAP_BODY_FLD_ENC_BINARY:
- encoding="binary";
- break;
- case MAILIMAP_BODY_FLD_ENC_BASE64:
- encoding="base64";
- break;
- case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
- encoding="quoted-printable";
- break;
- case MAILIMAP_BODY_FLD_ENC_OTHER:
- default:
- if (enc->enc_value) {
- char*t=enc->enc_value;
- encoding=QString(enc->enc_value);
- enc->enc_value=0L;
- free(t);
- }
- }
- if (which->bd_description) {
- target_part.setDescription(QString(which->bd_description));
- }
- target_part.setEncoding(encoding);
- target_part.setSize(which->bd_size);
-}
-
-void IMAPwrapper::deleteMail(const RecMail&mail)
-{
- mailimap_flag_list*flist;
- mailimap_set *set;
- mailimap_store_att_flags * store_flags;
- int err;
- login();
- if (!m_imap) {
- return;
- }
- const char *mb = mail.getMbox().latin1();
- err = mailimap_select( m_imap, (char*)mb);
- if ( err != MAILIMAP_NO_ERROR ) {
- qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
- return;
- }
- flist = mailimap_flag_list_new_empty();
- mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
- store_flags = mailimap_store_att_flags_new_set_flags(flist);
- set = mailimap_set_new_single(mail.getNumber());
- err = mailimap_store(m_imap,set,store_flags);
- mailimap_set_free( set );
- mailimap_store_att_flags_free(store_flags);
-
- if (err != MAILIMAP_NO_ERROR) {
- qDebug("error deleting mail: %s",m_imap->imap_response);
- return;
- }
- qDebug("deleting mail: %s",m_imap->imap_response);
- /* should we realy do that at this moment? */
- err = mailimap_expunge(m_imap);
- if (err != MAILIMAP_NO_ERROR) {
- qDebug("error deleting mail: %s",m_imap->imap_response);
- }
- qDebug("Delete successfull %s",m_imap->imap_response);
-}
-
-void IMAPwrapper::answeredMail(const RecMail&mail)
-{
- mailimap_flag_list*flist;
- mailimap_set *set;
- mailimap_store_att_flags * store_flags;
- int err;
- login();
- if (!m_imap) {
- return;
- }
- const char *mb = mail.getMbox().latin1();
- err = mailimap_select( m_imap, (char*)mb);
- if ( err != MAILIMAP_NO_ERROR ) {
- qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
- return;
- }
- flist = mailimap_flag_list_new_empty();
- mailimap_flag_list_add(flist,mailimap_flag_new_answered());
- store_flags = mailimap_store_att_flags_new_add_flags(flist);
- set = mailimap_set_new_single(mail.getNumber());
- err = mailimap_store(m_imap,set,store_flags);
- mailimap_set_free( set );
- mailimap_store_att_flags_free(store_flags);
-
- if (err != MAILIMAP_NO_ERROR) {
- qDebug("error marking mail: %s",m_imap->imap_response);
- return;
- }
-}
-
-QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
-{
- QString body("");
- encodedString*res = fetchRawPart(mail,path,internal_call);
- encodedString*r = decode_String(res,enc);
- delete res;
- if (r) {
- if (r->Length()>0) {
- body = r->Content();
- }
- delete r;
- }
- return body;
-}
-
-QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
-{
- return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
-}
-
-encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
-{
- encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
- encodedString*r = decode_String(res,part.Encoding());
- delete res;
- return r;
-}
-
-encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
-{
- return fetchRawPart(mail,part.Positionlist(),false);
-}
-
-int IMAPwrapper::deleteAllMail(const Folder*folder)
-{
- login();
- if (!m_imap) {
- return 0;
- }
- mailimap_flag_list*flist;
- mailimap_set *set;
- mailimap_store_att_flags * store_flags;
- int err = mailimap_select( m_imap, folder->getName().latin1());
- if ( err != MAILIMAP_NO_ERROR ) {
- Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response));
- return 0;
- }
- int last = m_imap->imap_selection_info->sel_exists;
- if (last == 0) {
- Global::statusMessage(tr("Mailbox has no mails!"));
- return 0;
- }
- flist = mailimap_flag_list_new_empty();
- mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
- store_flags = mailimap_store_att_flags_new_set_flags(flist);
- set = mailimap_set_new_interval( 1, last );
- err = mailimap_store(m_imap,set,store_flags);
- mailimap_set_free( set );
- mailimap_store_att_flags_free(store_flags);
- if (err != MAILIMAP_NO_ERROR) {
- Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
- return 0;
- }
- qDebug("deleting mail: %s",m_imap->imap_response);
- /* should we realy do that at this moment? */
- err = mailimap_expunge(m_imap);
- if (err != MAILIMAP_NO_ERROR) {
- Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
- return 0;
- }
- qDebug("Delete successfull %s",m_imap->imap_response);
- return 1;
-}
-
-int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder)
-{
- if (folder.length()==0) return 0;
- login();
- if (!m_imap) {return 0;}
- QString pre = account->getPrefix();
- if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
- pre+=delemiter;
- }
- if (parentfolder) {
- pre += parentfolder->getDisplayName()+delemiter;
- }
- pre+=folder;
- if (getsubfolder) {
- if (delemiter.length()>0) {
- pre+=delemiter;
- } else {
- Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
- return 0;
- }
- }
- qDebug("Creating %s",pre.latin1());
- int res = mailimap_create(m_imap,pre.latin1());
- if (res != MAILIMAP_NO_ERROR) {
- Global::statusMessage(tr("%1").arg(m_imap->imap_response));
- return 0;
- }
- return 1;
-}
-
-int IMAPwrapper::deleteMbox(const Folder*folder)
-{
- if (!folder) return 0;
- login();
- if (!m_imap) {return 0;}
- int res = mailimap_delete(m_imap,folder->getName());
- if (res != MAILIMAP_NO_ERROR) {
- Global::statusMessage(tr("%1").arg(m_imap->imap_response));
- return 0;
- }
- return 1;
-}
-
-void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
-{
- mailimap_status_att_list * att_list =0;
- mailimap_mailbox_data_status * status=0;
- clistiter * cur = 0;
- int r = 0;
- int res = 0;
- target_stat.message_count = 0;
- target_stat.message_unseen = 0;
- target_stat.message_recent = 0;
- login();
- if (!m_imap) {
- return;
- }
- att_list = mailimap_status_att_list_new_empty();
- if (!att_list) return;
- r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
- r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
- r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
- r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
- for (cur = clist_begin(status->st_info_list);
- cur != NULL ; cur = clist_next(cur)) {
- mailimap_status_info * status_info;
- status_info = (mailimap_status_info *)clist_content(cur);
- switch (status_info->st_att) {
- case MAILIMAP_STATUS_ATT_MESSAGES:
- target_stat.message_count = status_info->st_value;
- break;
- case MAILIMAP_STATUS_ATT_RECENT:
- target_stat.message_recent = status_info->st_value;
- break;
- case MAILIMAP_STATUS_ATT_UNSEEN:
- target_stat.message_unseen = status_info->st_value;
- break;
- }
- }
- mailimap_mailbox_data_status_free(status);
- mailimap_status_att_list_free(att_list);
-}
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h
deleted file mode 100644
index 8f5a2b5..0000000
--- a/noncore/net/mail/imapwrapper.h
+++ b/dev/null
@@ -1,68 +0,0 @@
-#ifndef __IMAPWRAPPER
-#define __IMAPWRAPPER
-
-#include <qlist.h>
-#include "mailwrapper.h"
-#include "abstractmail.h"
-#include <libetpan/clist.h>
-
-struct mailimap;
-struct mailimap_body;
-struct mailimap_body_type_1part;
-struct mailimap_body_type_text;
-struct mailimap_body_type_basic;
-struct mailimap_body_type_msg;
-struct mailimap_body_type_mpart;
-struct mailimap_body_fields;
-struct mailimap_msg_att;
-class encodedString;
-
-class IMAPwrapper : public AbstractMail
-{
- Q_OBJECT
-public:
- IMAPwrapper( IMAPaccount *a );
- virtual ~IMAPwrapper();
- virtual QList<Folder>* listFolders();
- virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
- virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
-
- virtual void deleteMail(const RecMail&mail);
- virtual void answeredMail(const RecMail&mail);
- virtual int deleteAllMail(const Folder*folder);
-
- virtual RecBody fetchBody(const RecMail&mail);
- virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
- virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
- virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
-
- virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
- virtual int deleteMbox(const Folder*folder);
-
- static void imap_progress( size_t current, size_t maximum );
-
-protected:
- RecMail*parse_list_result(mailimap_msg_att*);
- void login();
- void logout();
-
- virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
- virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call);
-
- void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
- void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
- void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
- void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
- void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which);
- void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1);
-
- /* just helpers */
- static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
- static QStringList address_list_to_stringlist(clist*list);
-
-
- IMAPaccount *account;
- mailimap *m_imap;
-};
-
-#endif
diff --git a/noncore/net/mail/mailtypes.cpp b/noncore/net/mail/mailtypes.cpp
deleted file mode 100644
index d8a36e7..0000000
--- a/noncore/net/mail/mailtypes.cpp
+++ b/dev/null
@@ -1,335 +0,0 @@
-#include "mailtypes.h"
-#include <stdlib.h>
-
-RecMail::RecMail()
- :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
-{
- init();
-}
-
-RecMail::RecMail(const RecMail&old)
- :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7)
-{
- init();
- copy_old(old);
- qDebug("Copy constructor RecMail");
-}
-
-RecMail::~RecMail()
-{
- wrapper = 0;
-}
-
-void RecMail::copy_old(const RecMail&old)
-{
- subject = old.subject;
- date = old.date;
- mbox = old.mbox;
- msg_id = old.msg_id;
- msg_size = old.msg_size;
- msg_number = old.msg_number;
- from = old.from;
- msg_flags = old.msg_flags;
- to = old.to;
- cc = old.cc;
- bcc = old.bcc;
- wrapper = old.wrapper;
-}
-
-void RecMail::init()
-{
- to.clear();
- cc.clear();
- bcc.clear();
- wrapper = 0;
-}
-
-void RecMail::setWrapper(AbstractMail*awrapper)
-{
- wrapper = awrapper;
-}
-
-AbstractMail* RecMail::Wrapper()
-{
- return wrapper;
-}
-
-void RecMail::setTo(const QStringList&list)
-{
- to = list;
-}
-
-const QStringList&RecMail::To()const
-{
- return to;
-}
-
-void RecMail::setCC(const QStringList&list)
-{
- cc = list;
-}
-
-const QStringList&RecMail::CC()const
-{
- return cc;
-}
-
-void RecMail::setBcc(const QStringList&list)
-{
- bcc = list;
-}
-
-const QStringList& RecMail::Bcc()const
-{
- return bcc;
-}
-
-RecPart::RecPart()
- : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0)
-{
- m_Parameters.clear();
- m_poslist.clear();
-}
-
-RecPart::~RecPart()
-{
-}
-
-void RecPart::setSize(unsigned int size)
-{
- m_size = size;
-}
-
-const unsigned int RecPart::Size()const
-{
- return m_size;
-}
-
-void RecPart::setLines(unsigned int lines)
-{
- m_lines = lines;
-}
-
-const unsigned int RecPart::Lines()const
-{
- return m_lines;
-}
-
-const QString& RecPart::Type()const
-{
- return m_type;
-}
-
-void RecPart::setType(const QString&type)
-{
- m_type = type;
-}
-
-const QString& RecPart::Subtype()const
-{
- return m_subtype;
-}
-
-void RecPart::setSubtype(const QString&subtype)
-{
- m_subtype = subtype;
-}
-
-const QString& RecPart::Identifier()const
-{
- return m_identifier;
-}
-
-void RecPart::setIdentifier(const QString&identifier)
-{
- m_identifier = identifier;
-}
-
-const QString& RecPart::Encoding()const
-{
- return m_encoding;
-}
-
-void RecPart::setEncoding(const QString&encoding)
-{
- m_encoding = encoding;
-}
-
-const QString& RecPart::Description()const
-{
- return m_description;
-}
-
-void RecPart::setDescription(const QString&desc)
-{
- m_description = desc;
-}
-
-void RecPart::setParameters(const part_plist_t&list)
-{
- m_Parameters = list;
-}
-
-const part_plist_t& RecPart::Parameters()const
-{
- return m_Parameters;
-}
-
-void RecPart::addParameter(const QString&key,const QString&value)
-{
- m_Parameters[key]=value;
-}
-
-const QString RecPart::searchParamter(const QString&key)const
-{
- QString value("");
- part_plist_t::ConstIterator it = m_Parameters.find(key);
- if (it != m_Parameters.end()) {
- value = it.data();
- }
- return value;
-}
-
-void RecPart::setPositionlist(const QValueList<int>&poslist)
-{
- m_poslist = poslist;
-}
-
-const QValueList<int>& RecPart::Positionlist()const
-{
- return m_poslist;
-}
-
-RecBody::RecBody()
- : m_BodyText(),m_PartsList(),m_description()
-{
- m_PartsList.clear();
-}
-
-RecBody::~RecBody()
-{
-}
-
-void RecBody::setBodytext(const QString&bodyText)
-{
- m_BodyText = bodyText;
-}
-
-const QString& RecBody::Bodytext()const
-{
- return m_BodyText;
-}
-
-void RecBody::setParts(const QValueList<RecPart>&parts)
-{
- m_PartsList.clear();
- m_PartsList = parts;
-}
-
-const QValueList<RecPart>& RecBody::Parts()const
-{
- return m_PartsList;
-}
-
-void RecBody::addPart(const RecPart& part)
-{
- m_PartsList.append(part);
-}
-
-void RecBody::setDescription(const RecPart&des)
-{
- m_description = des;
-}
-
-const RecPart& RecBody::Description()const
-{
- return m_description;
-}
-
-/* handling encoded content */
-encodedString::encodedString()
-{
- init();
-}
-
-encodedString::encodedString(const char*nContent,unsigned int nSize)
-{
- init();
- setContent(nContent,nSize);
-}
-
-encodedString::encodedString(char*nContent,unsigned int nSize)
-{
- init();
- setContent(nContent,nSize);
-}
-
-encodedString::encodedString(const encodedString&old)
-{
- init();
- copy_old(old);
- qDebug("encodedeString: copy constructor!");
-}
-
-encodedString& encodedString::operator=(const encodedString&old)
-{
- init();
- copy_old(old);
- qDebug("encodedString: assign operator!");
- return *this;
-}
-
-encodedString::~encodedString()
-{
- clean();
-}
-
-void encodedString::init()
-{
- content = 0;
- size = 0;
-}
-
-void encodedString::clean()
-{
- if (content) {
- free(content);
- }
- content = 0;
- size = 0;
-}
-
-void encodedString::copy_old(const encodedString&old)
-{
- clean();
- if (old.size>0 && old.content) {
- content = (char*)malloc(old.size*sizeof(char));
- memcpy(content,old.content,size);
- size = old.size;
- }
-}
-
-const char*encodedString::Content()const
-{
- return content;
-}
-
-const int encodedString::Length()const
-{
- return size;
-}
-
-void encodedString::setContent(const char*nContent,int nSize)
-{
- if (nSize>0 && nContent) {
- content = (char*)malloc(nSize*sizeof(char));
- memcpy(content,nContent,nSize);
- size = nSize;
- }
-}
-
-void encodedString::setContent(char*nContent,int nSize)
-{
- content = nContent;
- size = nSize;
-}
diff --git a/noncore/net/mail/mailtypes.h b/noncore/net/mail/mailtypes.h
deleted file mode 100644
index 05c4816..0000000
--- a/noncore/net/mail/mailtypes.h
+++ b/dev/null
@@ -1,192 +0,0 @@
-#ifndef __MAIL_TYPES_H
-#define __MAIL_TYPES_H
-
-#define FLAG_ANSWERED 0
-#define FLAG_FLAGGED 1
-#define FLAG_DELETED 2
-#define FLAG_SEEN 3
-#define FLAG_DRAFT 4
-#define FLAG_RECENT 5
-
-#include <qlist.h>
-#include <qbitarray.h>
-#include <qstring.h>
-#include <qstringlist.h>
-#include <qmap.h>
-#include <qvaluelist.h>
-
-class AbstractMail;
-/* a class to describe mails in a mailbox */
-/* Attention!
- From programmers point of view it would make sense to
- store the mail body into this class, too.
- But: not from the point of view of the device.
- Mailbodies can be real large. So we request them when
- needed from the mail-wrapper class direct from the server itself
- (imap) or from a file-based cache (pop3?)
- So there is no interface "const QString&body()" but you should
- make a request to the mailwrapper with this class as parameter to
- get the body. Same words for the attachments.
-*/
-class RecMail
-{
-public:
- RecMail();
- RecMail(const RecMail&old);
- virtual ~RecMail();
-
- const int getNumber()const{return msg_number;}
- void setNumber(int number){msg_number=number;}
- const QString&getDate()const{ return date; }
- void setDate( const QString&a ) { date = a; }
- const QString&getFrom()const{ return from; }
- void setFrom( const QString&a ) { from = a; }
- const QString&getSubject()const { return subject; }
- void setSubject( const QString&s ) { subject = s; }
- const QString&getMbox()const{return mbox;}
- void setMbox(const QString&box){mbox = box;}
- void setMsgid(const QString&id){msg_id=id;}
- const QString&Msgid()const{return msg_id;}
- void setReplyto(const QString&reply){replyto=reply;}
- const QString&Replyto()const{return replyto;}
- void setMsgsize(int size){msg_size = size;}
- const int Msgsize()const{return msg_size;}
-
-
- void setTo(const QStringList&list);
- const QStringList&To()const;
- void setCC(const QStringList&list);
- const QStringList&CC()const;
- void setBcc(const QStringList&list);
- const QStringList&Bcc()const;
- const QBitArray&getFlags()const{return msg_flags;}
- void setFlags(const QBitArray&flags){msg_flags = flags;}
-
- void setWrapper(AbstractMail*wrapper);
- AbstractMail* Wrapper();
-
-protected:
- QString subject,date,from,mbox,msg_id,replyto;
- int msg_number,msg_size;
- QBitArray msg_flags;
- QStringList to,cc,bcc;
- AbstractMail*wrapper;
- void init();
- void copy_old(const RecMail&old);
-};
-
-typedef QMap<QString,QString> part_plist_t;
-
-class RecPart
-{
-protected:
- QString m_type,m_subtype,m_identifier,m_encoding,m_description;
- unsigned int m_lines,m_size;
- part_plist_t m_Parameters;
- /* describes the position in the mail */
- QValueList<int> m_poslist;
-
-public:
- RecPart();
- virtual ~RecPart();
-
- const QString&Type()const;
- void setType(const QString&type);
- const QString&Subtype()const;
- void setSubtype(const QString&subtype);
- const QString&Identifier()const;
- void setIdentifier(const QString&identifier);
- const QString&Encoding()const;
- void setEncoding(const QString&encoding);
- const QString&Description()const;
- void setDescription(const QString&desc);
- void setLines(unsigned int lines);
- const unsigned int Lines()const;
- void setSize(unsigned int size);
- const unsigned int Size()const;
-
-
- void setParameters(const part_plist_t&list);
- const part_plist_t&Parameters()const;
- void addParameter(const QString&key,const QString&value);
- const QString searchParamter(const QString&key)const;
- void setPositionlist(const QValueList<int>&poslist);
- const QValueList<int>& Positionlist()const;
-};
-
-class RecBody
-{
-protected:
- QString m_BodyText;
- QValueList<RecPart> m_PartsList;
- RecPart m_description;
-
-public:
- RecBody();
- virtual ~RecBody();
- void setBodytext(const QString&);
- const QString& Bodytext()const;
-
- void setDescription(const RecPart&des);
- const RecPart& Description()const;
-
- void setParts(const QValueList<RecPart>&parts);
- const QValueList<RecPart>& Parts()const;
- void addPart(const RecPart&part);
-};
-
-class encodedString
-{
-public:
- encodedString();
- /*
- creates an new content string.
- it makes a deep copy of it!
- */
- encodedString(const char*nContent,unsigned int length);
- /*
- Take over the nContent. Means: it will just copy the pointer, not the content.
- so make sure: No one else frees the string, the string has allocated with
- malloc for compatibility with c-based libs
- */
- encodedString(char*nContent,unsigned int nSize);
- /* copy construkor - makes ALWAYS a deep copy!!!! */
- encodedString(const encodedString&old);
- /* assign operator - makes ALWAYS a deep copy!!!! */
- encodedString& operator=(const encodedString&old);
- /* destructor - cleans the content */
- virtual ~encodedString();
-
- /* returns a pointer to the content - do not delete yoursel! */
- const char*Content()const;
- /* returns the lengths of the content 'cause it must not be a null-terminated string! */
- const int Length()const;
-
- /*
- makes a deep copy of nContent!
- */
- void setContent(const char*nContent,int nSize);
- /*
- Take over the nContent. Means: it will just copy the pointer, not the content.
- so make sure: No one else frees the string, the string has allocated with
- malloc for compatibility with c-based libs
- */
- void setContent(char*nContent,int nSize);
-
-protected:
- char * content;
- unsigned int size;
-
- void init();
- void copy_old(const encodedString&old);
- void clean();
-};
-
-struct folderStat
-{
- unsigned int message_count;
- unsigned int message_unseen;
- unsigned int message_recent;
-};
-
-#endif
diff --git a/noncore/net/mail/mboxwrapper.cpp b/noncore/net/mail/mboxwrapper.cpp
deleted file mode 100644
index 540a971..0000000
--- a/noncore/net/mail/mboxwrapper.cpp
+++ b/dev/null
@@ -1,324 +0,0 @@
-#include "mboxwrapper.h"
-#include "mailtypes.h"
-#include "mailwrapper.h"
-#include <libetpan/libetpan.h>
-#include <qdir.h>
-#include <stdlib.h>
-#include <qpe/global.h>
-
-MBOXwrapper::MBOXwrapper(const QString & mbox_dir)
- : Genericwrapper(),MBOXPath(mbox_dir)
-{
- QDir dir(MBOXPath);
- if (!dir.exists()) {
- dir.mkdir(MBOXPath);
- }
-}
-
-MBOXwrapper::~MBOXwrapper()
-{
-}
-
-void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target )
-{
- mailstorage*storage = mailstorage_new(NULL);
- QString p = MBOXPath+"/";
- p+=mailbox;
-
- int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
- mailfolder*folder;
- folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
- r = mailfolder_connect(folder);
- if (r != MAIL_NO_ERROR) {
- qDebug("Error initializing mbox");
- mailfolder_free(folder);
- mailstorage_free(storage);
- return;
- }
-
- parseList(target,folder->fld_session,mailbox);
-
- mailfolder_disconnect(folder);
- mailfolder_free(folder);
- mailstorage_free(storage);
- Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count()));
-}
-
-QList<Folder>* MBOXwrapper::listFolders()
-{
- QList<Folder> * folders = new QList<Folder>();
- folders->setAutoDelete( false );
- QDir dir(MBOXPath);
- if (!dir.exists()) return folders;
- dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable);
- QStringList entries = dir.entryList();
- QStringList::ConstIterator it = entries.begin();
- for (;it!=entries.end();++it) {
- Folder*inb=new Folder(*it,"/");
- folders->append(inb);
- }
- return folders;
-}
-
-void MBOXwrapper::deleteMail(const RecMail&mail)
-{
- mailstorage*storage = mailstorage_new(NULL);
- QString p = MBOXPath+"/";
- p+=mail.getMbox();
- int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
- mailfolder*folder;
- folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
- r = mailfolder_connect(folder);
- if (r != MAIL_NO_ERROR) {
- qDebug("Error initializing mbox");
- mailfolder_free(folder);
- mailstorage_free(storage);
- return;
- }
- r = mailsession_remove_message(folder->fld_session,mail.getNumber());
- if (r != MAIL_NO_ERROR) {
- qDebug("error deleting mail");
- }
- mailfolder_free(folder);
- mailstorage_free(storage);
-}
-
-void MBOXwrapper::answeredMail(const RecMail&)
-{
-}
-
-RecBody MBOXwrapper::fetchBody( const RecMail &mail )
-{
- RecBody body;
- mailstorage*storage = mailstorage_new(NULL);
- QString p = MBOXPath+"/";
- p+=mail.getMbox();
- mailmessage * msg;
- char*data=0;
- size_t size;
-
- int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
- mailfolder*folder;
- folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
- r = mailfolder_connect(folder);
- if (r != MAIL_NO_ERROR) {
- qDebug("Error initializing mbox");
- mailfolder_free(folder);
- mailstorage_free(storage);
- return body;
- }
- r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg);
- if (r != MAIL_NO_ERROR) {
- qDebug("Error fetching mail %i",mail.getNumber());
- mailfolder_free(folder);
- mailstorage_free(storage);
- return body;
- }
- r = mailmessage_fetch(msg,&data,&size);
- if (r != MAIL_NO_ERROR) {
- qDebug("Error fetching mail %i",mail.getNumber());
- mailfolder_free(folder);
- mailstorage_free(storage);
- mailmessage_free(msg);
- return body;
- }
- body = parseMail(msg);
- mailmessage_fetch_result_free(msg,data);
- mailfolder_free(folder);
- mailstorage_free(storage);
-
- return body;
-}
-
-void MBOXwrapper::mbox_progress( size_t current, size_t maximum )
-{
- qDebug("MBOX %i von %i",current,maximum);
-}
-
-int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool )
-{
- QString p = MBOXPath+"/";
- p+=folder;
- QFileInfo fi(p);
- if (fi.exists()) {
- Global::statusMessage(tr("Mailbox exists."));
- return 0;
- }
- mailmbox_folder*f = 0;
- if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) {
- Global::statusMessage(tr("Error init folder"));
- return 0;
- }
- if (f) mailmbox_done(f);
- return 1;
-}
-
-void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
-{
- QString p = MBOXPath+"/";
- p+=folder;
- mailmbox_folder*f = 0;
- int r = mailmbox_init(p.latin1(),0,1,0,&f);
- if (r != MAIL_NO_ERROR) {
- Global::statusMessage(tr("Error init folder"));
- return;
- }
- r = mailmbox_append_message(f,msg,length);
- if (r != MAIL_NO_ERROR) {
- Global::statusMessage(tr("Error writing to message folder"));
- }
- mailmbox_done(f);
-}
-
-void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length)
-{
- RecBody body;
- mailstorage*storage = mailstorage_new(NULL);
- QString p = MBOXPath+"/";
- p+=mail.getMbox();
- mailmessage * msg;
- char*data=0;
- size_t size;
-
- int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
- mailfolder*folder;
- folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
- r = mailfolder_connect(folder);
- if (r != MAIL_NO_ERROR) {
- Global::statusMessage(tr("Error initializing mbox"));
- mailfolder_free(folder);
- mailstorage_free(storage);
- return;
- }
- r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg);
- if (r != MAIL_NO_ERROR) {
- Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
- mailfolder_free(folder);
- mailstorage_free(storage);
- return;
- }
- r = mailmessage_fetch(msg,&data,&size);
- if (r != MAIL_NO_ERROR) {
- Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
- mailfolder_free(folder);
- mailstorage_free(storage);
- mailmessage_free(msg);
- return;
- }
- *target = data;
- *length = size;
- mailfolder_free(folder);
- mailstorage_free(storage);
- mailmessage_free(msg);
-}
-
-void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target)
-{
- QString p = MBOXPath+"/";
- p+=mailbox;
- mailmbox_folder*f = 0;
- int r = mailmbox_init(p.latin1(),0,1,0,&f);
- if (r != MAIL_NO_ERROR) {
- qDebug("Error init folder");
- return;
- }
- deleteMails(f,target);
- mailmbox_done(f);
-}
-
-void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target)
-{
- if (!f) return;
- int r;
- for (unsigned int i=0; i < target.count();++i) {
- r = mailmbox_delete_msg(f,target.at(i)->getNumber());
- if (r!=MAILMBOX_NO_ERROR) {
- qDebug("error delete mail");
- }
- }
- r = mailmbox_expunge(f);
- if (r != MAILMBOX_NO_ERROR) {
- qDebug("error expunge mailbox");
- }
-}
-
-int MBOXwrapper::deleteAllMail(const Folder*tfolder)
-{
- if (!tfolder) return 0;
- QString p = MBOXPath+tfolder->getDisplayName();
- int res = 1;
-
- mailfolder*folder = 0;
- mailmessage_list*l=0;
- mailstorage*storage = mailstorage_new(NULL);
- int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
- if (r != MAIL_NO_ERROR) {
- Global::statusMessage(tr("Error initializing mbox"));
- res = 0;
- }
- if (res) {
- folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
- r = mailfolder_connect(folder);
- if (r != MAIL_NO_ERROR) {
- Global::statusMessage(tr("Error initializing mbox"));
- res = 0;
- }
- }
- if (res) {
- r = mailsession_get_messages_list(folder->fld_session,&l);
- if (r != MAIL_NO_ERROR) {
- qDebug("Error message list");
- res=0;
- }
- }
- for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
- r = mailsession_remove_message(folder->fld_session,i+1);
- if (r != MAIL_NO_ERROR) {
- Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
- res = 0;
- break;
- }
- }
- if (l) mailmessage_list_free(l);
- if (folder) mailfolder_free(folder);
- if (storage) mailstorage_free(storage);
- return res;
-}
-
-int MBOXwrapper::deleteMbox(const Folder*tfolder)
-{
- if (!tfolder) return 0;
- QString p = MBOXPath+tfolder->getDisplayName();
- QFile fi(p);
- if (!fi.exists()) {
- Global::statusMessage(tr("Mailbox doesn't exist."));
- return 0;
- }
- if (!fi.remove()) {
- Global::statusMessage(tr("Error deleting Mailbox."));
- return 0;
- }
- return 1;
-}
-
-void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
-{
- mailfolder*folder = 0;
- mailstorage*storage = mailstorage_new(NULL);
- target_stat.message_count = 0;
- target_stat.message_unseen = 0;
- target_stat.message_recent = 0;
- QString p = MBOXPath+"/"+mailbox;
- QFile fi(p);
- if (!fi.exists()) {
- Global::statusMessage(tr("Mailbox doesn't exist."));
- return;
- }
- int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
- folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
- r = mailfolder_connect(folder);
- r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count,
- &target_stat.message_recent,&target_stat.message_unseen);
- if (folder) mailfolder_free(folder);
- if (storage) mailstorage_free(storage);
-}
diff --git a/noncore/net/mail/mboxwrapper.h b/noncore/net/mail/mboxwrapper.h
deleted file mode 100644
index f822997..0000000
--- a/noncore/net/mail/mboxwrapper.h
+++ b/dev/null
@@ -1,42 +0,0 @@
-#ifndef __MBOX_WRAPPER_H
-#define __MBOX_WRAPPER_H
-
-#include "genericwrapper.h"
-#include <qstring.h>
-
-class RecMail;
-class RecBody;
-struct mailmbox_folder;
-
-class MBOXwrapper : public Genericwrapper
-{
- Q_OBJECT
-public:
- MBOXwrapper(const QString & dir);
- virtual ~MBOXwrapper();
-
- virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
- virtual QList<Folder>* listFolders();
- virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
-
- virtual void deleteMail(const RecMail&mail);
- virtual void answeredMail(const RecMail&mail);
-
- virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false);
- virtual int deleteMbox(const Folder*);
-
- virtual void storeMessage(const char*msg,size_t length, const QString&folder);
-
- virtual RecBody fetchBody( const RecMail &mail );
- static void mbox_progress( size_t current, size_t maximum );
-
- virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length);
- virtual void deleteMails(const QString & mailbox,QList<RecMail> &target);
- virtual int deleteAllMail(const Folder*);
-
-protected:
- static void deleteMails(mailmbox_folder*f,QList<RecMail> &target);
- QString MBOXPath;
-};
-
-#endif
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
deleted file mode 100644
index d76d82a..0000000
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/dev/null
@@ -1,229 +0,0 @@
-#include <stdlib.h>
-#include "pop3wrapper.h"
-#include "mailtypes.h"
-#include "logindialog.h"
-#include <libetpan/libetpan.h>
-#include <qpe/global.h>
-#include <qfile.h>
-#include <qstring.h>
-
-/* we don't fetch messages larger than 5 MB */
-#define HARD_MSG_SIZE_LIMIT 5242880
-
-POP3wrapper::POP3wrapper( POP3account *a )
- : Genericwrapper()
-{
- account = a;
- m_pop3 = NULL;
- m_folder = NULL;
- msgTempName = a->getFileName()+"_msg_cache";
- last_msg_id = 0;
-}
-
-POP3wrapper::~POP3wrapper()
-{
- logout();
- QFile msg_cache(msgTempName);
- if (msg_cache.exists()) {
- msg_cache.remove();
- }
-}
-
-void POP3wrapper::pop3_progress( size_t current, size_t maximum )
-{
- qDebug( "POP3: %i of %i", current, maximum );
-}
-
-RecBody POP3wrapper::fetchBody( const RecMail &mail )
-{
- int err = MAILPOP3_NO_ERROR;
- char *message = 0;
- size_t length = 0;
-
- login();
- if ( !m_pop3 ) {
- return RecBody();
- }
-
- RecBody body;
- mailmessage * mailmsg;
- if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
- qDebug("Message to large: %i",mail.Msgsize());
- return body;
- }
-
- QFile msg_cache(msgTempName);
-
- cleanMimeCache();
-
- if (mail.getNumber()!=last_msg_id) {
- if (msg_cache.exists()) {
- msg_cache.remove();
- }
- msg_cache.open(IO_ReadWrite|IO_Truncate);
- last_msg_id = mail.getNumber();
- err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg);
- err = mailmessage_fetch(mailmsg,&message,&length);
- msg_cache.writeBlock(message,length);
- } else {
- QString msg="";
- msg_cache.open(IO_ReadOnly);
- message = new char[4096];
- memset(message,0,4096);
- while (msg_cache.readBlock(message,4095)>0) {
- msg+=message;
- memset(message,0,4096);
- }
- delete message;
- message = (char*)malloc(msg.length()+1*sizeof(char));
- memset(message,0,msg.length()+1);
- memcpy(message,msg.latin1(),msg.length());
- /* transform to libetpan stuff */
- mailmsg = mailmessage_new();
- mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
- generic_message_t * msg_data;
- msg_data = (generic_message_t *)mailmsg->msg_data;
- msg_data->msg_fetched = 1;
- msg_data->msg_message = message;
- msg_data->msg_length = strlen(message);
- }
- body = parseMail(mailmsg);
-
- /* clean up */
- if (mailmsg) mailmessage_free(mailmsg);
- if (message) free(message);
-
- return body;
-}
-
-void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
-{
- login();
- if (!m_pop3) return;
- uint32_t res_messages,res_recent,res_unseen;
- mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen);
- parseList(target,m_folder->fld_session,"INBOX");
- Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
-}
-
-void POP3wrapper::login()
-{
- /* we'll hold the line */
- if ( m_pop3 != NULL ) return;
-
- const char *server, *user, *pass;
- uint16_t port;
- int err = MAILPOP3_NO_ERROR;
-
- server = account->getServer().latin1();
- port = account->getPort().toUInt();
-
- if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
- LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
- login.show();
- if ( QDialog::Accepted == login.exec() ) {
- // ok
- user = login.getUser().latin1();
- pass = login.getPassword().latin1();
- } else {
- // cancel
- qDebug( "POP3: Login canceled" );
- return;
- }
- } else {
- user = account->getUser().latin1();
- pass = account->getPassword().latin1();
- }
-
- bool ssl = account->getSSL();
-
- m_pop3=mailstorage_new(NULL);
- pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP,
- (char*)user,(char*)pass,0,0,0);
-
- m_folder = mailfolder_new(m_pop3, NULL, NULL);
-
- if (m_folder==0) {
- Global::statusMessage(tr("Error initializing folder"));
- mailstorage_free(m_pop3);
- m_pop3 = NULL;
- return;
- }
- err = mailfolder_connect(m_folder);
- if (err != MAIL_NO_ERROR) {
- Global::statusMessage(tr("Error initializing folder"));
- mailfolder_free(m_folder);
- m_folder = 0;
- mailstorage_free(m_pop3);
- m_pop3 = 0;
- }
- qDebug( "POP3: logged in!" );
-}
-
-void POP3wrapper::logout()
-{
- int err = MAILPOP3_NO_ERROR;
- if ( m_pop3 == NULL ) return;
- mailfolder_free(m_folder);
- m_folder = 0;
- mailstorage_free(m_pop3);
- m_pop3 = 0;
-}
-
-
-QList<Folder>* POP3wrapper::listFolders()
-{
- QList<Folder> * folders = new QList<Folder>();
- folders->setAutoDelete( false );
- Folder*inb=new Folder("INBOX","/");
- folders->append(inb);
- return folders;
-}
-
-void POP3wrapper::deleteMail(const RecMail&mail)
-{
- login();
- if (!m_pop3) return;
- int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber());
- if (err != MAIL_NO_ERROR) {
- Global::statusMessage(tr("error deleting mail"));
- }
-}
-
-void POP3wrapper::answeredMail(const RecMail&)
-{
-}
-
-int POP3wrapper::deleteAllMail(const Folder*)
-{
- login();
- if (!m_pop3) return 0;
- int res = 1;
-
- uint32_t result = 0;
- int err = mailsession_messages_number(m_folder->fld_session,NULL,&result);
- if (err != MAIL_NO_ERROR) {
- Global::statusMessage(tr("Error getting folder info"));
- return 0;
- }
- for (unsigned int i = 0; i < result; ++i) {
- err = mailsession_remove_message(m_folder->fld_session,i+1);
- if (err != MAIL_NO_ERROR) {
- Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
- res=0;
- }
- break;
- }
- return res;
-}
-
-void POP3wrapper::statusFolder(folderStat&target_stat,const QString&)
-{
- login();
- target_stat.message_count = 0;
- target_stat.message_unseen = 0;
- target_stat.message_recent = 0;
- if (!m_pop3) return;
- int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count,
- &target_stat.message_recent,&target_stat.message_unseen);
-}
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h
deleted file mode 100644
index 536cadc..0000000
--- a/noncore/net/mail/pop3wrapper.h
+++ b/dev/null
@@ -1,39 +0,0 @@
-#ifndef __POP3WRAPPER
-#define __POP3WRAPPER
-
-#include "mailwrapper.h"
-#include "genericwrapper.h"
-#include <qstring.h>
-
-struct mailstorage;
-struct mailfolder;
-
-class POP3wrapper : public Genericwrapper
-{
- Q_OBJECT
-
-public:
- POP3wrapper( POP3account *a );
- virtual ~POP3wrapper();
- /* mailbox will be ignored */
- virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
- virtual QList<Folder>* listFolders();
- /* mailbox will be ignored */
- virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
-
- virtual void deleteMail(const RecMail&mail);
- virtual void answeredMail(const RecMail&mail);
- virtual int deleteAllMail(const Folder*);
-
- virtual RecBody fetchBody( const RecMail &mail );
- static void pop3_progress( size_t current, size_t maximum );
-
-protected:
- void login();
- void logout();
- POP3account *account;
- mailstorage*m_pop3;
- mailfolder*m_folder;
-};
-
-#endif
diff --git a/noncore/net/mail/smtpwrapper.cpp b/noncore/net/mail/smtpwrapper.cpp
deleted file mode 100644
index 7e03af9..0000000
--- a/noncore/net/mail/smtpwrapper.cpp
+++ b/dev/null
@@ -1,732 +0,0 @@
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <qdir.h>
-#include <qt.h>
-
-#include <qpe/config.h>
-#include <qpe/qcopenvelope_qws.h>
-
-#include <libetpan/libetpan.h>
-
-#include "smtpwrapper.h"
-#include "mailwrapper.h"
-#include "mboxwrapper.h"
-#include "logindialog.h"
-#include "mailtypes.h"
-#include "defines.h"
-#include "sendmailprogress.h"
-
-progressMailSend*SMTPwrapper::sendProgress = 0;
-
-SMTPwrapper::SMTPwrapper( Settings *s )
- : QObject()
-{
- settings = s;
- Config cfg( "mail" );
- cfg.setGroup( "Status" );
- m_queuedMail = cfg.readNumEntry( "outgoing", 0 );
- emit queuedMails( m_queuedMail );
- connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) );
-}
-
-void SMTPwrapper::emitQCop( int queued ) {
- QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" );
- env << queued;
-}
-
-QString SMTPwrapper::mailsmtpError( int errnum )
-{
- switch ( errnum ) {
- case MAILSMTP_NO_ERROR:
- return tr( "No error" );
- case MAILSMTP_ERROR_UNEXPECTED_CODE:
- return tr( "Unexpected error code" );
- case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
- return tr( "Service not available" );
- case MAILSMTP_ERROR_STREAM:
- return tr( "Stream error" );
- case MAILSMTP_ERROR_HOSTNAME:
- return tr( "gethostname() failed" );
- case MAILSMTP_ERROR_NOT_IMPLEMENTED:
- return tr( "Not implemented" );
- case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
- return tr( "Error, action not taken" );
- case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
- return tr( "Data exceeds storage allocation" );
- case MAILSMTP_ERROR_IN_PROCESSING:
- return tr( "Error in processing" );
- // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
- // return tr( "Insufficient system storage" );
- case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
- return tr( "Mailbox unavailable" );
- case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
- return tr( "Mailbox name not allowed" );
- case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
- return tr( "Bad command sequence" );
- case MAILSMTP_ERROR_USER_NOT_LOCAL:
- return tr( "User not local" );
- case MAILSMTP_ERROR_TRANSACTION_FAILED:
- return tr( "Transaction failed" );
- case MAILSMTP_ERROR_MEMORY:
- return tr( "Memory error" );
- case MAILSMTP_ERROR_CONNECTION_REFUSED:
- return tr( "Connection refused" );
- default:
- return tr( "Unknown error code" );
- }
-}
-
-mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail )
-{
- return mailimf_mailbox_new( strdup( name.latin1() ),
- strdup( mail.latin1() ) );
-}
-
-mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr )
-{
- mailimf_address_list *addresses;
-
- if ( addr.isEmpty() ) return NULL;
-
- addresses = mailimf_address_list_new_empty();
-
- bool literal_open = false;
- unsigned int startpos = 0;
- QStringList list;
- QString s;
- unsigned int i = 0;
- for (; i < addr.length();++i) {
- switch (addr[i]) {
- case '\"':
- literal_open = !literal_open;
- break;
- case ',':
- if (!literal_open) {
- s = addr.mid(startpos,i-startpos);
- if (!s.isEmpty()) {
- list.append(s);
- qDebug("Appended %s",s.latin1());
- }
- // !!!! this is a MUST BE!
- startpos = ++i;
- }
- break;
- default:
- break;
- }
- }
- s = addr.mid(startpos,i-startpos);
- if (!s.isEmpty()) {
- list.append(s);
- qDebug("Appended %s",s.latin1());
- }
- QStringList::Iterator it;
- for ( it = list.begin(); it != list.end(); it++ ) {
- int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() );
- if ( err != MAILIMF_NO_ERROR ) {
- qDebug( "Error parsing" );
- qDebug( *it );
- } else {
- qDebug( "Parse success! %s",(*it).latin1());
- }
- }
- return addresses;
-}
-
-mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail )
-{
- mailimf_fields *fields;
- mailimf_field *xmailer;
- mailimf_mailbox *sender=0,*fromBox=0;
- mailimf_mailbox_list *from=0;
- mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0;
- char *subject = strdup( mail.getSubject().latin1() );
- int err;
-
- sender = newMailbox( mail.getName(), mail.getMail() );
- if ( sender == NULL ) goto err_free;
-
- fromBox = newMailbox( mail.getName(), mail.getMail() );
- if ( fromBox == NULL ) goto err_free_sender;
-
- from = mailimf_mailbox_list_new_empty();
- if ( from == NULL ) goto err_free_fromBox;
-
- err = mailimf_mailbox_list_add( from, fromBox );
- if ( err != MAILIMF_NO_ERROR ) goto err_free_from;
-
- to = parseAddresses( mail.getTo() );
- if ( to == NULL ) goto err_free_from;
-
- cc = parseAddresses( mail.getCC() );
- bcc = parseAddresses( mail.getBCC() );
- reply = parseAddresses( mail.getReply() );
-
- fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
- NULL, NULL, subject );
- if ( fields == NULL ) goto err_free_reply;
-
- xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
- strdup( USER_AGENT ) );
- if ( xmailer == NULL ) goto err_free_fields;
-
- err = mailimf_fields_add( fields, xmailer );
- if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer;
-
- return fields; // Success :)
-
-err_free_xmailer:
- if (xmailer) mailimf_field_free( xmailer );
-err_free_fields:
- if (fields) mailimf_fields_free( fields );
-err_free_reply:
- if (reply) mailimf_address_list_free( reply );
- if (bcc) mailimf_address_list_free( bcc );
- if (cc) mailimf_address_list_free( cc );
- if (to) mailimf_address_list_free( to );
-err_free_from:
- if (from) mailimf_mailbox_list_free( from );
-err_free_fromBox:
- mailimf_mailbox_free( fromBox );
-err_free_sender:
- if (sender) mailimf_mailbox_free( sender );
-err_free:
- if (subject) free( subject );
- qDebug( "createImfFields - error" );
-
- return NULL; // Error :(
-}
-
-mailmime *SMTPwrapper::buildTxtPart(const QString&str )
-{
- mailmime *txtPart;
- mailmime_fields *fields;
- mailmime_content *content;
- mailmime_parameter *param;
- int err;
-
- param = mailmime_parameter_new( strdup( "charset" ),
- strdup( "iso-8859-1" ) );
- 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;
-
- err = mailmime_set_body_text( txtPart, (char*)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:
- qDebug( "buildTxtPart - error" );
-
- return NULL; // Error :(
-}
-
-mailmime *SMTPwrapper::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" ) );
- 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.data()),TextContent.length());
- }
- if (err != MAILIMF_NO_ERROR) {
- qDebug("Error setting body with file %s",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 );
- }
- }
- }
- return filePart; // Success :)
-
-}
-
-void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files )
-{
- const Attachment *it;
- unsigned int count = files.count();
- qDebug("List contains %i values",count);
- for ( unsigned int i = 0; i < count; ++i ) {
- qDebug( "Adding file" );
- mailmime *filePart;
- int err;
- it = ((QList<Attachment>)files).at(i);
-
- filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" );
- if ( filePart == NULL ) {
- qDebug( "addFileParts: error adding file:" );
- qDebug( it->getFileName() );
- continue;
- }
- err = mailmime_smart_add_part( message, filePart );
- if ( err != MAILIMF_NO_ERROR ) {
- mailmime_free( filePart );
- qDebug("error smart add");
- }
- }
-}
-
-mailmime *SMTPwrapper::createMimeMail(const Mail &mail )
-{
- mailmime *message, *txtPart;
- mailimf_fields *fields;
- int err;
-
- 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:
- mailmime_free( txtPart );
-err_free_message:
- mailmime_free( message );
-err_free_fields:
- mailimf_fields_free( fields );
-err_free:
- qDebug( "createMimeMail: error" );
-
- return NULL; // Error :(
-}
-
-mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type )
-{
- mailimf_field *field;
- clistiter *it;
-
- it = clist_begin( fields->fld_list );
- while ( it ) {
- field = (mailimf_field *) it->data;
- if ( field->fld_type == type ) {
- return field;
- }
- it = it->next;
- }
-
- return NULL;
-}
-
-void SMTPwrapper::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 );
- }
- }
- }
-}
-
-clist *SMTPwrapper::createRcptList( mailimf_fields *fields )
-{
- clist *rcptList;
- mailimf_field *field;
-
- rcptList = esmtp_address_list_new();
-
- field = getField( fields, MAILIMF_FIELD_TO );
- if ( field && (field->fld_type == MAILIMF_FIELD_TO)
- && field->fld_data.fld_to->to_addr_list ) {
- addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
- }
-
- field = getField( fields, MAILIMF_FIELD_CC );
- if ( field && (field->fld_type == MAILIMF_FIELD_CC)
- && field->fld_data.fld_cc->cc_addr_list ) {
- addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
- }
-
- field = getField( fields, MAILIMF_FIELD_BCC );
- if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
- && field->fld_data.fld_bcc->bcc_addr_list ) {
- addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
- }
-
- return rcptList;
-}
-
-char *SMTPwrapper::getFrom( mailimf_field *ffrom)
-{
- char *from = NULL;
- if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
- && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
- clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
- clistiter *it;
- for ( it = clist_begin( cl ); it; it = it->next ) {
- mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
- from = strdup( mb->mb_addr_spec );
- }
- }
-
- return from;
-}
-
-char *SMTPwrapper::getFrom( mailmime *mail )
-{
- /* no need to delete - its just a pointer to structure content */
- mailimf_field *ffrom = 0;
- ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
- return getFrom(ffrom);
-}
-
-void SMTPwrapper::progress( size_t current, size_t maximum )
-{
- if (SMTPwrapper::sendProgress) {
- SMTPwrapper::sendProgress->setSingleMail(current, maximum );
- qApp->processEvents();
- }
-}
-
-void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box)
-{
- if (!mail) return;
- QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
- MBOXwrapper*wrap = new MBOXwrapper(localfolders);
- wrap->storeMessage(mail,length,box);
- delete wrap;
-}
-
-void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
-{
- clist *rcpts = 0;
- char *from, *data;
- size_t size;
-
- if ( smtp == NULL ) {
- return;
- }
- from = data = 0;
-
- mailmessage * msg = 0;
- msg = mime_message_init(mail);
- mime_message_set_tmpdir(msg,getenv( "HOME" ));
- int r = mailmessage_fetch(msg,&data,&size);
- mime_message_detach_mime(msg);
- mailmessage_free(msg);
- if (r != MAIL_NO_ERROR || !data) {
- if (data) free(data);
- qDebug("Error fetching mime...");
- return;
- }
- QString tmp = data;
- tmp.replace(QRegExp("\r+",true,false),"");
- msg = 0;
- if (later) {
- storeMail((char*)tmp.data(),tmp.length(),"Outgoing");
- if (data) free( data );
- Config cfg( "mail" );
- cfg.setGroup( "Status" );
- cfg.writeEntry( "outgoing", ++m_queuedMail );
- emit queuedMails( m_queuedMail );
- return;
- }
- from = getFrom( mail );
- rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
- smtpSend(from,rcpts,data,size,smtp);
- if (data) {free(data);}
- if (from) {free(from);}
- if (rcpts) smtp_address_list_free( rcpts );
-}
-
-int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp )
-{
- char *server, *user, *pass;
- bool ssl;
- uint16_t port;
- mailsmtp *session;
- int err,result;
-
- result = 1;
- server = user = pass = 0;
- server = strdup( smtp->getServer().latin1() );
- ssl = smtp->getSSL();
- port = smtp->getPort().toUInt();
-
- session = mailsmtp_new( 20, &progress );
- if ( session == NULL ) goto free_mem;
-
- qDebug( "Servername %s at port %i", server, port );
- if ( ssl ) {
- qDebug( "SSL session" );
- err = mailsmtp_ssl_connect( session, server, port );
- } else {
- qDebug( "No SSL session" );
- err = mailsmtp_socket_connect( session, server, port );
- }
- if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;}
-
- err = mailsmtp_init( session );
- if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;}
-
- qDebug( "INIT OK" );
-
- if ( smtp->getLogin() ) {
- if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
- // get'em
- LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
- login.show();
- if ( QDialog::Accepted == login.exec() ) {
- // ok
- user = strdup( login.getUser().latin1() );
- pass = strdup( login.getPassword().latin1() );
- } else {
- result = 0; goto free_con_session;
- }
- } else {
- user = strdup( smtp->getUser().latin1() );
- pass = strdup( smtp->getPassword().latin1() );
- }
- qDebug( "session->auth: %i", session->auth);
- err = mailsmtp_auth( session, user, pass );
- if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
- qDebug( "Done auth!" );
- }
-
- err = mailsmtp_send( session, from, rcpts, data, size );
- if ( err != MAILSMTP_NO_ERROR ) {
- qDebug("Error sending mail: %s",mailsmtpError(err).latin1());
- result = 0; goto free_con_session;
- }
-
- qDebug( "Mail sent." );
- storeMail(data,size,"Sent");
-
-free_con_session:
- mailsmtp_quit( session );
-free_mem_session:
- mailsmtp_free( session );
-free_mem:
- if (server) free( server );
- if ( smtp->getLogin() ) {
- free( user );
- free( pass );
- }
- return result;
-}
-
-void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later )
-{
- mailmime * mimeMail;
-
- SMTPaccount *smtp = aSmtp;
-
- if (!later && !smtp) {
- qDebug("Didn't get any send method - giving up");
- return;
- }
- mimeMail = createMimeMail(mail );
- if ( mimeMail == NULL ) {
- qDebug( "sendMail: error creating mime mail" );
- } else {
- sendProgress = new progressMailSend();
- sendProgress->show();
- sendProgress->setMaxMails(1);
- smtpSend( mimeMail,later,smtp);
- qDebug("Clean up done");
- sendProgress->hide();
- delete sendProgress;
- sendProgress = 0;
- mailmime_free( mimeMail );
- }
-}
-
-int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
-{
- char*data = 0;
- size_t length = 0;
- size_t curTok = 0;
- mailimf_fields *fields = 0;
- mailimf_field*ffrom = 0;
- clist *rcpts = 0;
- char*from = 0;
- int res = 0;
-
- wrap->fetchRawBody(*which,&data,&length);
- if (!data) return 0;
- int err = mailimf_fields_parse( data, length, &curTok, &fields );
- if (err != MAILIMF_NO_ERROR) {
- free(data);
- delete wrap;
- return 0;
- }
-
- rcpts = createRcptList( fields );
- ffrom = getField(fields, MAILIMF_FIELD_FROM );
- from = getFrom(ffrom);
-
- qDebug("Size: %i vs. %i",length,strlen(data));
- if (rcpts && from) {
- res = smtpSend(from,rcpts,data,length,smtp );
- }
- if (fields) {
- mailimf_fields_free(fields);
- fields = 0;
- }
- if (data) {
- free(data);
- }
- if (from) {
- free(from);
- }
- if (rcpts) {
- smtp_address_list_free( rcpts );
- }
- return res;
-}
-
-/* this is a special fun */
-bool SMTPwrapper::flushOutbox(SMTPaccount*smtp)
-{
- bool returnValue = true;
-
- if (!smtp) return false;
-
- QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
- MBOXwrapper*wrap = new MBOXwrapper(localfolders);
- if (!wrap) {
- qDebug("memory error");
- return false;
- }
- QList<RecMail> mailsToSend;
- QList<RecMail> mailsToRemove;
- QString mbox("Outgoing");
- wrap->listMessages(mbox,mailsToSend);
- if (mailsToSend.count()==0) {
- delete wrap;
- return false;
- }
- mailsToSend.setAutoDelete(false);
- sendProgress = new progressMailSend();
- sendProgress->show();
- sendProgress->setMaxMails(mailsToSend.count());
-
- while (mailsToSend.count()>0) {
- if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) {
- QMessageBox::critical(0,tr("Error sending mail"),
- tr("Error sending queued mail - breaking"));
- returnValue = false;
- break;
- }
- mailsToRemove.append(mailsToSend.at(0));
- mailsToSend.removeFirst();
- sendProgress->setCurrentMails(mailsToRemove.count());
- }
- Config cfg( "mail" );
- cfg.setGroup( "Status" );
- m_queuedMail = 0;
- cfg.writeEntry( "outgoing", m_queuedMail );
- emit queuedMails( m_queuedMail );
- sendProgress->hide();
- delete sendProgress;
- sendProgress = 0;
- wrap->deleteMails(mbox,mailsToRemove);
- mailsToSend.setAutoDelete(true);
- delete wrap;
- return returnValue;
-}
diff --git a/noncore/net/mail/smtpwrapper.h b/noncore/net/mail/smtpwrapper.h
deleted file mode 100644
index 05becf2..0000000
--- a/noncore/net/mail/smtpwrapper.h
+++ b/dev/null
@@ -1,71 +0,0 @@
-#ifndef SMTPwrapper_H
-#define SMTPwrapper_H
-
-#include <qpe/applnk.h>
-
-#include <qbitarray.h>
-#include <qdatetime.h>
-#include <libetpan/clist.h>
-
-#include "settings.h"
-
-class Mail;
-class MBOXwrapper;
-class RecMail;
-class Attachment;
-struct mailimf_fields;
-struct mailimf_field;
-struct mailimf_mailbox;
-struct mailmime;
-struct mailimf_address_list;
-class progressMailSend;
-
-class SMTPwrapper : public QObject
-{
- Q_OBJECT
-
-public:
- SMTPwrapper( Settings *s );
- virtual ~SMTPwrapper(){}
- void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false );
- bool flushOutbox(SMTPaccount*smtp);
-
- static progressMailSend*sendProgress;
-
-signals:
- void queuedMails( int );
-
-protected:
- mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
- mailimf_fields *createImfFields(const Mail &mail );
- mailmime *createMimeMail(const Mail&mail );
-
- mailimf_address_list *parseAddresses(const QString&addr );
- void addFileParts( mailmime *message,const QList<Attachment>&files );
- mailmime *buildTxtPart(const QString&str );
- mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
- void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp );
- clist *createRcptList( mailimf_fields *fields );
-
- static void storeMail(char*mail, size_t length, const QString&box);
- static QString mailsmtpError( int err );
- static void progress( size_t current, size_t maximum );
- 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 );
- int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp );
-
- void storeMail(mailmime*mail, const QString&box);
- Settings *settings;
-
- int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which);
-
- int m_queuedMail;
-
-protected slots:
- void emitQCop( int queued );
-
-};
-
-#endif