summaryrefslogtreecommitdiff
authorharlekin <harlekin>2003-12-10 02:02:53 (UTC)
committer harlekin <harlekin>2003-12-10 02:02:53 (UTC)
commit1f0b92e554b76852af210ceb277b3e9ecb09a43d (patch) (side-by-side diff)
treea813761b2f0d1a2b8a9a1a996d6e37d511d24f0f
parenta908d0ffdb5cee72b7823fc411119b8e1e3faad8 (diff)
downloadopie-1f0b92e554b76852af210ceb277b3e9ecb09a43d.zip
opie-1f0b92e554b76852af210ceb277b3e9ecb09a43d.tar.gz
opie-1f0b92e554b76852af210ceb277b3e9ecb09a43d.tar.bz2
ssl for imap now working
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp60
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp60
-rw-r--r--noncore/net/mail/mainwindow.cpp2
3 files changed, 67 insertions, 55 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index eae85a7..dc02780 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -18,42 +18,48 @@ IMAPwrapper::~IMAPwrapper()
void IMAPwrapper::imap_progress( size_t current, size_t maximum )
{
qDebug( "IMAP: %i of %i", current, maximum );
}
void IMAPwrapper::login()
{
logout();
const char *server, *user, *pass;
uint16_t port;
int err = MAILIMAP_NO_ERROR;
-
+
server = account->getServer().latin1();
port = account->getPort().toUInt();
user = account->getUser().latin1();
pass = account->getPassword().latin1();
-
- m_imap = mailimap_new( 20, &imap_progress );
+
+ m_imap = mailimap_new( 20, &imap_progress );
/* connect */
- err = mailimap_socket_connect( m_imap, (char*)server, port );
- if ( err != MAILIMAP_NO_ERROR &&
+ // err = mailimap_socket_connect( m_imap, (char*)server, port );
+ 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 ) {
qDebug("error connecting server: %s",m_imap->response);
mailimap_free( m_imap );
m_imap = 0;
return;
}
-
+
/* login */
err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
if ( err != MAILIMAP_NO_ERROR ) {
qDebug("error logging in imap: %s",m_imap->response);
err = mailimap_close( m_imap );
mailimap_free( m_imap );
m_imap = 0;
}
}
void IMAPwrapper::logout()
{
@@ -65,59 +71,59 @@ void IMAPwrapper::logout()
m_imap = 0;
}
void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
{
const char *mb;
int err = MAILIMAP_NO_ERROR;
clist *result;
clistcell *current;
mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
mailimap_fetch_type *fetchType;
mailimap_set *set;
-
+
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 ) {
qDebug("error selecting mailbox: %s",m_imap->response);
logout();
return;
}
int last = m_imap->selection_info->exists;
if (last == 0) {
qDebug("mailbox has no mails");
logout();
return;
}
-
- result = clist_new();
+
+ result = clist_new();
/* the range has to start at 1!!! not with 0!!!! */
set = mailimap_set_new_interval( 1, last );
fetchAtt = mailimap_fetch_att_new_envelope();
fetchAttFlags = mailimap_fetch_att_new_flags();
fetchAttDate = mailimap_fetch_att_new_internaldate();
-
+
//fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt);
mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags);
mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate);
-
+
err = mailimap_fetch( m_imap, set, fetchType, &result );
mailimap_set_free( set );
/* cleans up the fetch_att's too! */
mailimap_fetch_type_free( fetchType );
QString date,subject,from;
if ( err == MAILIMAP_NO_ERROR ) {
current = clist_begin(result);
mailimap_msg_att * msg_att;
int i = 0;
while ( current != 0 ) {
@@ -135,95 +141,95 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
qDebug("Error fetching headers: %s",m_imap->response);
}
logout();
clist_free(result);
}
QList<IMAPFolder>* IMAPwrapper::listFolders()
{
const char *path, *mask;
int err = MAILIMAP_NO_ERROR;
clist *result;
clistcell *current;
-
+
QList<IMAPFolder> * folders = new QList<IMAPFolder>();
folders->setAutoDelete( true );
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" ;
result = clist_new();
mailimap_mailbox_list *list;
err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
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;
folders->append( new IMAPFolder(temp));
current = current->next;
}
} else {
qDebug("error fetching folders: %s",m_imap->response);
}
mailimap_list_result_free( result );
-
+
/*
* second stage - get the other then inbox folders
*/
- mask = "*" ;
+ mask = "*" ;
path = account->getPrefix().latin1();
result = clist_new();
qDebug(path);
err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
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;
current = current->next;
if (temp.lower()=="inbox")
continue;
folders->append(new IMAPFolder(temp));
-
+
}
} else {
qDebug("error fetching folders %s",m_imap->response);
}
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;
QBitArray mFlags(7);
QStringList addresslist;
-
+
if (!m_att) {
return m;
}
c = clist_begin(m_att->list);
while ( c ) {
current = c;
c = c->next;
item = (mailimap_msg_att_item*)current->data;
if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn;
if (!flist->list) {
@@ -320,63 +326,63 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
RecBody IMAPwrapper::fetchBody(const RecMail&mail)
{
RecBody body;
const char *mb;
int err = MAILIMAP_NO_ERROR;
clist *result;
clistcell *current;
mailimap_fetch_att *fetchAtt;
mailimap_fetch_type *fetchType;
mailimap_set *set;
mailimap_body*body_desc;
-
+
mb = mail.getMbox().latin1();
-
+
login();
if (!m_imap) {
return body;
}
/* select mailbox READONLY for operations */
err = mailimap_examine( m_imap, (char*)mb);
if ( err != MAILIMAP_NO_ERROR ) {
qDebug("error selecting mailbox: %s",m_imap->response);
logout();
return body;
}
- result = clist_new();
+ result = clist_new();
/* the range has to start at 1!!! not with 0!!!! */
set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
- fetchAtt = mailimap_fetch_att_new_body();
+ fetchAtt = mailimap_fetch_att_new_body();
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->list->first->data;
body_desc = item->msg_att_static->body;
if (body_desc->type==MAILIMAP_BODY_1PART) {
searchBodyText(mail,body_desc->body_1part,body);
} else {
}
-
+
} else {
qDebug("error fetching body: %s",m_imap->response);
}
clist_free(result);
- logout();
+ logout();
return body;
}
void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
{
if (!mailDescription) {
return;
}
switch (mailDescription->type) {
case MAILIMAP_BODY_TYPE_1PART_TEXT:
fillPlainBody(mail,target_body,mailDescription->body_type_text);
break;
@@ -387,40 +393,40 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mai
}
void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body)
{
const char *mb;
QString body="";
int err = MAILIMAP_NO_ERROR;
clist *result;
clistcell *current;
mailimap_fetch_att *fetchAtt;
mailimap_fetch_type *fetchType;
mailimap_set *set;
-
+
mb = mail.getMbox().latin1();
-
+
if (!m_imap) {
return;
}
- result = clist_new();
+ result = clist_new();
/* the range has to start at 1!!! not with 0!!!! */
set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
fetchAtt = mailimap_fetch_att_new_rfc822_text();
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->list->first->data;
if (item->msg_att_static && item->msg_att_static->rfc822_text) {
body = item->msg_att_static->rfc822_text;
}
} else {
qDebug("error fetching text: %s",m_imap->response);
}
clist_free(result);
target_body.setBodytext(body);
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index eae85a7..dc02780 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -18,42 +18,48 @@ IMAPwrapper::~IMAPwrapper()
void IMAPwrapper::imap_progress( size_t current, size_t maximum )
{
qDebug( "IMAP: %i of %i", current, maximum );
}
void IMAPwrapper::login()
{
logout();
const char *server, *user, *pass;
uint16_t port;
int err = MAILIMAP_NO_ERROR;
-
+
server = account->getServer().latin1();
port = account->getPort().toUInt();
user = account->getUser().latin1();
pass = account->getPassword().latin1();
-
- m_imap = mailimap_new( 20, &imap_progress );
+
+ m_imap = mailimap_new( 20, &imap_progress );
/* connect */
- err = mailimap_socket_connect( m_imap, (char*)server, port );
- if ( err != MAILIMAP_NO_ERROR &&
+ // err = mailimap_socket_connect( m_imap, (char*)server, port );
+ 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 ) {
qDebug("error connecting server: %s",m_imap->response);
mailimap_free( m_imap );
m_imap = 0;
return;
}
-
+
/* login */
err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
if ( err != MAILIMAP_NO_ERROR ) {
qDebug("error logging in imap: %s",m_imap->response);
err = mailimap_close( m_imap );
mailimap_free( m_imap );
m_imap = 0;
}
}
void IMAPwrapper::logout()
{
@@ -65,59 +71,59 @@ void IMAPwrapper::logout()
m_imap = 0;
}
void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
{
const char *mb;
int err = MAILIMAP_NO_ERROR;
clist *result;
clistcell *current;
mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
mailimap_fetch_type *fetchType;
mailimap_set *set;
-
+
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 ) {
qDebug("error selecting mailbox: %s",m_imap->response);
logout();
return;
}
int last = m_imap->selection_info->exists;
if (last == 0) {
qDebug("mailbox has no mails");
logout();
return;
}
-
- result = clist_new();
+
+ result = clist_new();
/* the range has to start at 1!!! not with 0!!!! */
set = mailimap_set_new_interval( 1, last );
fetchAtt = mailimap_fetch_att_new_envelope();
fetchAttFlags = mailimap_fetch_att_new_flags();
fetchAttDate = mailimap_fetch_att_new_internaldate();
-
+
//fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt);
mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags);
mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate);
-
+
err = mailimap_fetch( m_imap, set, fetchType, &result );
mailimap_set_free( set );
/* cleans up the fetch_att's too! */
mailimap_fetch_type_free( fetchType );
QString date,subject,from;
if ( err == MAILIMAP_NO_ERROR ) {
current = clist_begin(result);
mailimap_msg_att * msg_att;
int i = 0;
while ( current != 0 ) {
@@ -135,95 +141,95 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
qDebug("Error fetching headers: %s",m_imap->response);
}
logout();
clist_free(result);
}
QList<IMAPFolder>* IMAPwrapper::listFolders()
{
const char *path, *mask;
int err = MAILIMAP_NO_ERROR;
clist *result;
clistcell *current;
-
+
QList<IMAPFolder> * folders = new QList<IMAPFolder>();
folders->setAutoDelete( true );
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" ;
result = clist_new();
mailimap_mailbox_list *list;
err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
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;
folders->append( new IMAPFolder(temp));
current = current->next;
}
} else {
qDebug("error fetching folders: %s",m_imap->response);
}
mailimap_list_result_free( result );
-
+
/*
* second stage - get the other then inbox folders
*/
- mask = "*" ;
+ mask = "*" ;
path = account->getPrefix().latin1();
result = clist_new();
qDebug(path);
err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
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;
current = current->next;
if (temp.lower()=="inbox")
continue;
folders->append(new IMAPFolder(temp));
-
+
}
} else {
qDebug("error fetching folders %s",m_imap->response);
}
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;
QBitArray mFlags(7);
QStringList addresslist;
-
+
if (!m_att) {
return m;
}
c = clist_begin(m_att->list);
while ( c ) {
current = c;
c = c->next;
item = (mailimap_msg_att_item*)current->data;
if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn;
if (!flist->list) {
@@ -320,63 +326,63 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
RecBody IMAPwrapper::fetchBody(const RecMail&mail)
{
RecBody body;
const char *mb;
int err = MAILIMAP_NO_ERROR;
clist *result;
clistcell *current;
mailimap_fetch_att *fetchAtt;
mailimap_fetch_type *fetchType;
mailimap_set *set;
mailimap_body*body_desc;
-
+
mb = mail.getMbox().latin1();
-
+
login();
if (!m_imap) {
return body;
}
/* select mailbox READONLY for operations */
err = mailimap_examine( m_imap, (char*)mb);
if ( err != MAILIMAP_NO_ERROR ) {
qDebug("error selecting mailbox: %s",m_imap->response);
logout();
return body;
}
- result = clist_new();
+ result = clist_new();
/* the range has to start at 1!!! not with 0!!!! */
set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
- fetchAtt = mailimap_fetch_att_new_body();
+ fetchAtt = mailimap_fetch_att_new_body();
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->list->first->data;
body_desc = item->msg_att_static->body;
if (body_desc->type==MAILIMAP_BODY_1PART) {
searchBodyText(mail,body_desc->body_1part,body);
} else {
}
-
+
} else {
qDebug("error fetching body: %s",m_imap->response);
}
clist_free(result);
- logout();
+ logout();
return body;
}
void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
{
if (!mailDescription) {
return;
}
switch (mailDescription->type) {
case MAILIMAP_BODY_TYPE_1PART_TEXT:
fillPlainBody(mail,target_body,mailDescription->body_type_text);
break;
@@ -387,40 +393,40 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mai
}
void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body)
{
const char *mb;
QString body="";
int err = MAILIMAP_NO_ERROR;
clist *result;
clistcell *current;
mailimap_fetch_att *fetchAtt;
mailimap_fetch_type *fetchType;
mailimap_set *set;
-
+
mb = mail.getMbox().latin1();
-
+
if (!m_imap) {
return;
}
- result = clist_new();
+ result = clist_new();
/* the range has to start at 1!!! not with 0!!!! */
set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
fetchAtt = mailimap_fetch_att_new_rfc822_text();
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->list->first->data;
if (item->msg_att_static && item->msg_att_static->rfc822_text) {
body = item->msg_att_static->rfc822_text;
}
} else {
qDebug("error fetching text: %s",m_imap->response);
}
clist_free(result);
target_body.setBodytext(body);
diff --git a/noncore/net/mail/mainwindow.cpp b/noncore/net/mail/mainwindow.cpp
index 3edfff1..6d13a8b 100644
--- a/noncore/net/mail/mainwindow.cpp
+++ b/noncore/net/mail/mainwindow.cpp
@@ -6,25 +6,25 @@
#include <qpe/qpeapplication.h>
#include "defines.h"
#include "mainwindow.h"
#include "viewmail.h"
#include "mailtypes.h"
#include "mailistviewitem.h"
MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags )
: QMainWindow( parent, name, flags )
{
- setCaption( tr( "Opie-Mail" ) );
+ setCaption( tr( "Mail" ) );
setToolBarsMovable( false );
toolBar = new QToolBar( this );
menuBar = new QMenuBar( toolBar );
mailMenu = new QPopupMenu( menuBar );
menuBar->insertItem( tr( "Mail" ), mailMenu );
settingsMenu = new QPopupMenu( menuBar );
menuBar->insertItem( tr( "Settings" ), settingsMenu );
addToolBar( toolBar );
toolBar->setHorizontalStretchable( true );