summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp50
-rw-r--r--noncore/net/mail/pop3wrapper.cpp50
2 files changed, 78 insertions, 22 deletions
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 2411399..b4a8f4b 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -13,33 +13,30 @@ POP3wrapper::~POP3wrapper()
{
logout();
}
void POP3wrapper::pop3_progress( size_t current, size_t maximum )
{
- qDebug( "POP3: %i of %i", current, maximum );
+ //qDebug( "POP3: %i of %i", current, maximum );
}
RecBody POP3wrapper::fetchBody( const RecMail &mail )
{
int err = MAILPOP3_NO_ERROR;
char *message;
- size_t length;
+ size_t length = 0;
login();
if ( !m_pop3 ) return RecBody();
err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
if ( err != MAILPOP3_NO_ERROR ) {
qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
- logout();
return RecBody();
}
- logout();
-
return parseBody( message );
}
RecBody POP3wrapper::parseBody( const char *message )
{
int err = MAILIMF_NO_ERROR;
@@ -72,40 +69,41 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
carray * messages = 0;
login();
if (!m_pop3) return;
mailpop3_list( m_pop3, &messages );
- //for ( int i = carray_count( messages ); i > 0; i-- ) {
for (unsigned int i = 0; i < carray_count(messages);++i) {
mailpop3_msg_info *info;
- int r = mailpop3_get_msg_info(m_pop3,i+1,&info);
+ err = mailpop3_get_msg_info(m_pop3,i+1,&info);
err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
if ( err != MAILPOP3_NO_ERROR ) {
qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
free(header);
- logout();
return;
}
RecMail *mail = parseHeader( header );
mail->setNumber( info->msg_index );
mail->setWrapper(this);
+ mail->setMsgsize(info->msg_size);
target.append( mail );
free(header);
}
- logout();
}
RecMail *POP3wrapper::parseHeader( const char *header )
{
int err = MAILIMF_NO_ERROR;
size_t curTok = 0;
RecMail *mail = new RecMail();
mailimf_fields *fields;
mailimf_references * refs;
mailimf_keywords*keys;
+ QString status;
+ QString value;
+ QBitArray mFlags(7);
err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
mailimf_field *field = (mailimf_field *) current->data;
switch ( field->fld_type ) {
case MAILIMF_FIELD_FROM:
@@ -139,17 +137,37 @@ RecMail *POP3wrapper::parseHeader( const char *header )
case MAILIMF_FIELD_KEYWORDS:
keys = field->fld_data.fld_keywords;
for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
qDebug("Keyword: %s",(char*)cur->data);
}
break;
+ case MAILIMF_FIELD_OPTIONAL_FIELD:
+ status = field->fld_data.fld_optional_field->fld_name;
+ value = field->fld_data.fld_optional_field->fld_value;
+ if (status.lower()=="status") {
+ if (value.lower()=="ro") {
+ mFlags.setBit(FLAG_SEEN);
+ }
+ } else if (status.lower()=="x-status") {
+ qDebug("X-Status: %s",value.latin1());
+ if (value.lower()=="a") {
+
+ mFlags.setBit(FLAG_ANSWERED);
+ }
+ } else {
+// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
+// field->fld_data.fld_optional_field->fld_value);
+ }
+ break;
default:
+ qDebug("Non parsed field");
break;
}
}
if (fields) mailimf_fields_free(fields);
+ mail->setFlags(mFlags);
return mail;
}
QString POP3wrapper::parseDateTime( mailimf_date_time *date )
{
char tmp[23];
@@ -241,13 +259,14 @@ QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
return result;
}
void POP3wrapper::login()
{
- if ( m_pop3 != NULL ) logout();
+ /* 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();
@@ -294,25 +313,34 @@ void POP3wrapper::logout()
m_pop3 = NULL;
}
QList<Folder>* POP3wrapper::listFolders()
{
+ /* TODO: integrate MH directories
+ but not vor version 0.1 ;)
+ */
QList<Folder> * folders = new QList<Folder>();
folders->setAutoDelete( false );
Folder*inb=new Folder("INBOX");
folders->append(inb);
return folders;
}
QString POP3wrapper::fetchPart(const RecMail&,const RecPart&)
{
return "";
}
-void POP3wrapper::deleteMail(const RecMail&)
+void POP3wrapper::deleteMail(const RecMail&mail)
{
+ login();
+ if (!m_pop3) return;
+ int err = mailpop3_dele(m_pop3,mail.getNumber());
+ if (err != MAILPOP3_NO_ERROR) {
+ qDebug("error deleting mail");
+ }
}
void POP3wrapper::answeredMail(const RecMail&)
{
}
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index 2411399..b4a8f4b 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -13,33 +13,30 @@ POP3wrapper::~POP3wrapper()
{
logout();
}
void POP3wrapper::pop3_progress( size_t current, size_t maximum )
{
- qDebug( "POP3: %i of %i", current, maximum );
+ //qDebug( "POP3: %i of %i", current, maximum );
}
RecBody POP3wrapper::fetchBody( const RecMail &mail )
{
int err = MAILPOP3_NO_ERROR;
char *message;
- size_t length;
+ size_t length = 0;
login();
if ( !m_pop3 ) return RecBody();
err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
if ( err != MAILPOP3_NO_ERROR ) {
qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
- logout();
return RecBody();
}
- logout();
-
return parseBody( message );
}
RecBody POP3wrapper::parseBody( const char *message )
{
int err = MAILIMF_NO_ERROR;
@@ -72,40 +69,41 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
carray * messages = 0;
login();
if (!m_pop3) return;
mailpop3_list( m_pop3, &messages );
- //for ( int i = carray_count( messages ); i > 0; i-- ) {
for (unsigned int i = 0; i < carray_count(messages);++i) {
mailpop3_msg_info *info;
- int r = mailpop3_get_msg_info(m_pop3,i+1,&info);
+ err = mailpop3_get_msg_info(m_pop3,i+1,&info);
err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
if ( err != MAILPOP3_NO_ERROR ) {
qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
free(header);
- logout();
return;
}
RecMail *mail = parseHeader( header );
mail->setNumber( info->msg_index );
mail->setWrapper(this);
+ mail->setMsgsize(info->msg_size);
target.append( mail );
free(header);
}
- logout();
}
RecMail *POP3wrapper::parseHeader( const char *header )
{
int err = MAILIMF_NO_ERROR;
size_t curTok = 0;
RecMail *mail = new RecMail();
mailimf_fields *fields;
mailimf_references * refs;
mailimf_keywords*keys;
+ QString status;
+ QString value;
+ QBitArray mFlags(7);
err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
mailimf_field *field = (mailimf_field *) current->data;
switch ( field->fld_type ) {
case MAILIMF_FIELD_FROM:
@@ -139,17 +137,37 @@ RecMail *POP3wrapper::parseHeader( const char *header )
case MAILIMF_FIELD_KEYWORDS:
keys = field->fld_data.fld_keywords;
for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
qDebug("Keyword: %s",(char*)cur->data);
}
break;
+ case MAILIMF_FIELD_OPTIONAL_FIELD:
+ status = field->fld_data.fld_optional_field->fld_name;
+ value = field->fld_data.fld_optional_field->fld_value;
+ if (status.lower()=="status") {
+ if (value.lower()=="ro") {
+ mFlags.setBit(FLAG_SEEN);
+ }
+ } else if (status.lower()=="x-status") {
+ qDebug("X-Status: %s",value.latin1());
+ if (value.lower()=="a") {
+
+ mFlags.setBit(FLAG_ANSWERED);
+ }
+ } else {
+// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
+// field->fld_data.fld_optional_field->fld_value);
+ }
+ break;
default:
+ qDebug("Non parsed field");
break;
}
}
if (fields) mailimf_fields_free(fields);
+ mail->setFlags(mFlags);
return mail;
}
QString POP3wrapper::parseDateTime( mailimf_date_time *date )
{
char tmp[23];
@@ -241,13 +259,14 @@ QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
return result;
}
void POP3wrapper::login()
{
- if ( m_pop3 != NULL ) logout();
+ /* 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();
@@ -294,25 +313,34 @@ void POP3wrapper::logout()
m_pop3 = NULL;
}
QList<Folder>* POP3wrapper::listFolders()
{
+ /* TODO: integrate MH directories
+ but not vor version 0.1 ;)
+ */
QList<Folder> * folders = new QList<Folder>();
folders->setAutoDelete( false );
Folder*inb=new Folder("INBOX");
folders->append(inb);
return folders;
}
QString POP3wrapper::fetchPart(const RecMail&,const RecPart&)
{
return "";
}
-void POP3wrapper::deleteMail(const RecMail&)
+void POP3wrapper::deleteMail(const RecMail&mail)
{
+ login();
+ if (!m_pop3) return;
+ int err = mailpop3_dele(m_pop3,mail.getNumber());
+ if (err != MAILPOP3_NO_ERROR) {
+ qDebug("error deleting mail");
+ }
}
void POP3wrapper::answeredMail(const RecMail&)
{
}