summaryrefslogtreecommitdiff
path: root/noncore/net/mail/libmailwrapper/imapwrapper.cpp
Side-by-side diff
Diffstat (limited to 'noncore/net/mail/libmailwrapper/imapwrapper.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp49
1 files changed, 24 insertions, 25 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 3b3be0f..071e734 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -184,49 +184,49 @@ void IMAPwrapper::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));
ok = false;
}
}
if (!ok) {
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;
m_Lastmbox = "";
}
-void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
+void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::OSmartPointer<RecMail> > &target )
{
int err = MAILIMAP_NO_ERROR;
clist *result = 0;
clistcell *current;
mailimap_fetch_type *fetchType = 0;
mailimap_set *set = 0;
login();
if (!m_imap) {
return;
}
/* select mailbox READONLY for operations */
err = selectMbox(mailbox);
if ( err != MAILIMAP_NO_ERROR ) {
return;
}
int last = m_imap->imap_selection_info->sel_exists;
if (last == 0) {
Global::statusMessage(tr("Mailbox has no mails"));
return;
} else {
}
@@ -245,49 +245,49 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
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);
}
}
Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count()));
} else {
Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
}
if (result) mailimap_fetch_list_free(result);
}
-QValueList<Opie::osmart_pointer<Folder> >* IMAPwrapper::listFolders()
+QValueList<Opie::OSmartPointer<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;
QValueList<FolderP>* folders = new QValueList<FolderP>();
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;
@@ -461,73 +461,73 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
}
} 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 IMAPwrapper::fetchBody(const RecMailP&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();
+ mb = mail->getMbox().latin1();
login();
if (!m_imap) {
return body;
}
- err = selectMbox(mail.getMbox());
+ err = selectMbox(mail->getMbox());
if ( err != MAILIMAP_NO_ERROR ) {
return body;
}
/* the range has to start at 1!!! not with 0!!!! */
- set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
+ 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;
@@ -547,71 +547,71 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
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*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call)
{
encodedString*res=new encodedString;
int err;
mailimap_fetch_type *fetchType;
mailimap_set *set;
clistcell*current,*cur;
mailimap_section_part * section_part = 0;
mailimap_section_spec * section_spec = 0;
mailimap_section * section = 0;
mailimap_fetch_att * fetch_att = 0;
login();
if (!m_imap) {
return res;
}
if (!internal_call) {
- err = selectMbox(mail.getMbox());
+ err = selectMbox(mail->getMbox());
if ( err != MAILIMAP_NO_ERROR ) {
return res;
}
}
- set = mailimap_set_new_single(mail.getNumber());
+ set = mailimap_set_new_single(mail->getNumber());
clist*id_list = 0;
/* if path == empty then its a request for the whole rfc822 mail and generates
a "fetch <id> (body[])" statement on imap server */
if (path.count()>0 ) {
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);
}
section_part = mailimap_section_part_new(id_list);
section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
}
section = mailimap_section_new(section_spec);
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 );
@@ -620,49 +620,49 @@ encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>
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,
+void IMAPwrapper::traverseBody(const RecMailP&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) {
@@ -848,140 +848,140 @@ void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
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)
+void IMAPwrapper::deleteMail(const RecMailP&mail)
{
mailimap_flag_list*flist;
mailimap_set *set;
mailimap_store_att_flags * store_flags;
int err;
login();
if (!m_imap) {
return;
}
- err = selectMbox(mail.getMbox());
+ err = selectMbox(mail->getMbox());
if ( err != MAILIMAP_NO_ERROR ) {
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());
+ 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)
+void IMAPwrapper::answeredMail(const RecMailP&mail)
{
mailimap_flag_list*flist;
mailimap_set *set;
mailimap_store_att_flags * store_flags;
int err;
login();
if (!m_imap) {
return;
}
- err = selectMbox(mail.getMbox());
+ err = selectMbox(mail->getMbox());
if ( err != MAILIMAP_NO_ERROR ) {
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());
+ 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 IMAPwrapper::fetchTextPart(const RecMailP&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)
+QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPart&part)
{
return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
}
-encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
+encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&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)
+encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPart&part)
{
return fetchRawPart(mail,part.Positionlist(),false);
}
int IMAPwrapper::deleteAllMail(const FolderP&folder)
{
login();
if (!m_imap) {
return 0;
}
mailimap_flag_list*flist;
mailimap_set *set;
mailimap_store_att_flags * store_flags;
int err = selectMbox(folder->getName());
if ( err != MAILIMAP_NO_ERROR ) {
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();
@@ -1034,49 +1034,48 @@ int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,cons
return 0;
}
return 1;
}
int IMAPwrapper::deleteMbox(const FolderP&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);
if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
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;
@@ -1094,92 +1093,92 @@ void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
}
void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
{
login();
if (!m_imap) return;
if (!msg) return;
int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
if (r != MAILIMAP_NO_ERROR) {
Global::statusMessage("Error storing mail!");
}
}
MAILLIB::ATYPE IMAPwrapper::getType()const
{
return account->getType();
}
const QString&IMAPwrapper::getName()const
{
qDebug("Get name: %s",account->getAccountName().latin1());
return account->getAccountName();
}
-encodedString* IMAPwrapper::fetchRawBody(const RecMail&mail)
+encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail)
{
// dummy
QValueList<int> path;
return fetchRawPart(mail,path,false);
}
void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder,
const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
{
if (targetWrapper != this) {
AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit);
qDebug("Using generic");
return;
}
mailimap_set *set = 0;
login();
if (!m_imap) {
return;
}
int err = selectMbox(fromFolder->getName());
if ( err != MAILIMAP_NO_ERROR ) {
return;
}
int last = m_imap->imap_selection_info->sel_exists;
set = mailimap_set_new_interval( 1, last );
err = mailimap_copy(m_imap,set,targetFolder.latin1());
mailimap_set_free( set );
if ( err != MAILIMAP_NO_ERROR ) {
QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response);
Global::statusMessage(error_msg);
qDebug(error_msg);
return;
}
if (moveit) {
deleteAllMail(fromFolder);
}
}
-void IMAPwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
+void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
{
if (targetWrapper != this) {
qDebug("Using generic");
AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit);
return;
}
mailimap_set *set = 0;
login();
if (!m_imap) {
return;
}
- int err = selectMbox(mail.getMbox());
+ int err = selectMbox(mail->getMbox());
if ( err != MAILIMAP_NO_ERROR ) {
return;
}
- set = mailimap_set_new_single(mail.getNumber());
+ set = mailimap_set_new_single(mail->getNumber());
err = mailimap_copy(m_imap,set,targetFolder.latin1());
mailimap_set_free( set );
if ( err != MAILIMAP_NO_ERROR ) {
QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response);
Global::statusMessage(error_msg);
qDebug(error_msg);
return;
}
if (moveit) {
deleteMail(mail);
}
}