summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-17 00:30:31 (UTC)
committer alwin <alwin>2003-12-17 00:30:31 (UTC)
commita928f1fc8469124e10a7042846d258401e41f7d6 (patch) (side-by-side diff)
tree225db6d7356d3ff3a0a3f3768c2fc0fa10360edc
parent27151bb106e2cbd7f649dae228189ebcaccd7aac (diff)
downloadopie-a928f1fc8469124e10a7042846d258401e41f7d6.zip
opie-a928f1fc8469124e10a7042846d258401e41f7d6.tar.gz
opie-a928f1fc8469124e10a7042846d258401e41f7d6.tar.bz2
imap folder will be displayed more structured
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/accountview.cpp69
-rw-r--r--noncore/net/mail/accountview.h2
-rw-r--r--noncore/net/mail/imapwrapper.cpp7
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp7
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.cpp11
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.h7
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp2
-rw-r--r--noncore/net/mail/mailwrapper.cpp11
-rw-r--r--noncore/net/mail/mailwrapper.h7
-rw-r--r--noncore/net/mail/pop3wrapper.cpp2
10 files changed, 100 insertions, 25 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index 8e21d39..b6bf298 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -97,88 +97,143 @@ IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent )
IMAPviewItem::~IMAPviewItem()
{
delete wrapper;
}
AbstractMail *IMAPviewItem::getWrapper()
{
return wrapper;
}
void IMAPviewItem::refresh(QList<RecMail>&)
{
+ if (childCount()>0) return;
QList<Folder> *folders = wrapper->listFolders();
- QListViewItem *child = firstChild();
+ QListViewItem *child = firstChild();
while ( child ) {
QListViewItem *tmp = child;
child = child->nextSibling();
delete tmp;
}
Folder *it;
QListViewItem*item = 0;
- for ( it = folders->first(); it; it = folders->next() ) {
- item = new IMAPfolderItem( it, this , item );
- item->setSelectable(it->may_select());
- }
+ QListViewItem*titem = 0;
+ QListViewItem*inboxitem = 0;
+ QString fname,del,search;
+ int pos;
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
folders->setAutoDelete(false);
+
+ for ( it = folders->first(); it; it = folders->next() ) {
+ if (it->getDisplayName().lower()=="inbox") {
+ inboxitem = new IMAPfolderItem( it, this , item );
+ folders->remove(it);
+ qDebug("inbox found");
+ break;
+ }
+ }
+
+ for ( it = folders->first(); it; it = folders->next() ) {
+ fname = it->getDisplayName();
+ pos = fname.findRev(it->Separator());
+ if (pos != -1) {
+ fname = fname.left(pos);
+ qDebug(fname);
+ }
+ IMAPfolderItem*pitem = (IMAPfolderItem*)firstChild();
+ while (pitem) {
+ if (pitem->matchName(fname)) {
+ break;
+ }
+ pitem=(IMAPfolderItem*)pitem->nextSibling();
+ }
+ if (pitem) {
+ titem = item;
+ item = new IMAPfolderItem(it,pitem,item,this);
+ item->setSelectable(it->may_select());
+ /* setup the short name */
+ item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1));
+ item = titem;
+ } else {
+ item = new IMAPfolderItem( it, this , (inboxitem?inboxitem:item) );
+ item->setSelectable(it->may_select());
+ }
+ }
delete folders;
}
RecBody IMAPviewItem::fetchBody(const RecMail&)
{
return RecBody();
}
IMAPfolderItem::~IMAPfolderItem()
{
delete folder;
}
IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after )
- : AccountViewItem( parent,after )
+ : AccountViewItem( parent )
{
folder = folderInit;
imap = parent;
if (folder->getDisplayName().lower()!="inbox") {
setPixmap( 0, PIXMAP_IMAPFOLDER );
} else {
setPixmap( 0, PIXMAP_INBOXFOLDER);
}
setText( 0, folder->getDisplayName() );
}
+IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master )
+ : AccountViewItem( parent,after )
+{
+ folder = folderInit;
+ imap = master;
+ if (folder->getDisplayName().lower()!="inbox") {
+ setPixmap( 0, PIXMAP_IMAPFOLDER );
+ } else {
+ setPixmap( 0, PIXMAP_INBOXFOLDER);
+ }
+ setText( 0, folder->getDisplayName() );
+}
+
+bool IMAPfolderItem::matchName(const QString&name)const
+{
+ return folder->getDisplayName()==name;
+}
+
void IMAPfolderItem::refresh(QList<RecMail>&target)
{
if (folder->may_select())
imap->getWrapper()->listMessages( folder->getName(),target );
}
RecBody IMAPfolderItem::fetchBody(const RecMail&aMail)
{
return imap->getWrapper()->fetchBody(aMail);
}
/**
* Generic stuff
*/
AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
: QListView( parent, name, flags )
{
connect( this, SIGNAL( selectionChanged( QListViewItem * ) ),
SLOT( refresh( QListViewItem * ) ) );
- setSorting(-1);
+ setSorting(0);
}
void AccountView::populate( QList<Account> list )
{
clear();
Account *it;
for ( it = list.first(); it; it = list.next() ) {
if ( it->getType().compare( "IMAP" ) == 0 ) {
IMAPaccount *imap = static_cast<IMAPaccount *>(it);
qDebug( "added IMAP " + imap->getAccountName() );
(void) new IMAPviewItem( imap, this );
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h
index d035af4..a57935f 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -61,27 +61,29 @@ public:
virtual RecBody fetchBody(const RecMail&);
AbstractMail *getWrapper();
private:
IMAPaccount *account;
AbstractMail *wrapper;
};
class IMAPfolderItem : public AccountViewItem
{
public:
IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after );
+ IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master );
~IMAPfolderItem();
virtual void refresh(QList<RecMail>&);
virtual RecBody fetchBody(const RecMail&);
+ bool matchName(const QString&name)const;
private:
Folder *folder;
IMAPviewItem *imap;
};
class AccountView : public QListView
{
Q_OBJECT
public:
AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
void populate( QList<Account> list );
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index d56d7f9..8a86c95 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -156,32 +156,34 @@ QList<Folder>* IMAPwrapper::listFolders()
}
/*
* 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 );
+ QString del;
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;
- folders->append( new IMAPFolder(temp));
+ del = list->mb_delimiter;
+ folders->append( new IMAPFolder(temp,del,true,account->getPrefix()));
current = current->next;
}
} 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();
@@ -197,25 +199,26 @@ QList<Folder>* IMAPwrapper::listFolders()
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);
}
- folders->append(new IMAPFolder(temp,selectable,account->getPrefix()));
+ del = list->mb_delimiter;
+ folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix()));
}
} else {
qDebug("error fetching folders %s",m_imap->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;
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index d56d7f9..8a86c95 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -156,32 +156,34 @@ QList<Folder>* IMAPwrapper::listFolders()
}
/*
* 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 );
+ QString del;
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;
- folders->append( new IMAPFolder(temp));
+ del = list->mb_delimiter;
+ folders->append( new IMAPFolder(temp,del,true,account->getPrefix()));
current = current->next;
}
} 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();
@@ -197,25 +199,26 @@ QList<Folder>* IMAPwrapper::listFolders()
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);
}
- folders->append(new IMAPFolder(temp,selectable,account->getPrefix()));
+ del = list->mb_delimiter;
+ folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix()));
}
} else {
qDebug("error fetching folders %s",m_imap->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;
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
index 96602c2..858283f 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
@@ -8,47 +8,52 @@
#include "mailwrapper.h"
#include "logindialog.h"
//#include "mail.h"
#include "defines.h"
Attachment::Attachment( DocLnk lnk )
{
doc = lnk;
size = QFileInfo( doc.file() ).size();
}
-Folder::Folder(const QString&tmp_name )
+Folder::Folder(const QString&tmp_name, const QString&sep )
{
name = tmp_name;
nameDisplay = name;
for ( int pos = nameDisplay.find( '&' ); pos != -1;
pos = nameDisplay.find( '&' ) ) {
int end = nameDisplay.find( '-' );
if ( end == -1 || end <= pos ) break;
QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 );
// TODO: do real base64 decoding here !
if ( str64.compare( "APw" ) == 0 ) {
nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" );
} else if ( str64.compare( "APY" ) == 0 ) {
nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" );
}
}
qDebug( "folder " + name + " - displayed as " + nameDisplay );
+ separator = sep;
}
+const QString& Folder::Separator()const
+{
+ return separator;
+}
-IMAPFolder::IMAPFolder(const QString&name,bool select,const QString&prefix )
- : Folder( name ),m_MaySelect(select)
+IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix )
+ : Folder( name,sep ),m_MaySelect(select)
{
if (prefix.length()>0) {
if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
}
}
}
MailWrapper::MailWrapper( Settings *s )
: QObject()
{
settings = s;
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h
index 6994dd8..d78f8e9 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.h
@@ -62,38 +62,39 @@ public:
void setReply( const QString&a ) { reply = a; }
private:
QList<Attachment> attList;
QString name, mail, to, cc, bcc, reply, subject, message;
};
class Folder : public QObject
{
Q_OBJECT
public:
- Folder( const QString&init_name );
+ Folder( const QString&init_name,const QString&sep );
const QString&getDisplayName()const { return nameDisplay; }
const QString&getName()const { return name; }
virtual bool may_select()const{return true;};
+ const QString&Separator()const;
protected:
- QString nameDisplay, name;
+ QString nameDisplay, name, separator;
};
class IMAPFolder : public Folder
{
public:
- IMAPFolder(const QString&name,bool select=true,const QString&prefix="" );
+ IMAPFolder(const QString&name, const QString&sep, bool select=true,const QString&prefix="" );
virtual bool may_select()const{return m_MaySelect;}
private:
bool m_MaySelect;
};
class MailWrapper : public QObject
{
Q_OBJECT
public:
MailWrapper( Settings *s );
void sendMail( Mail mail );
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 075d8c7..4508a95 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -314,25 +314,25 @@ void POP3wrapper::logout()
mailpop3_free( m_pop3 );
m_pop3 = NULL;
}
QList<Folder>* POP3wrapper::listFolders()
{
/* TODO: integrate MH directories
but not before version 0.1 ;)
*/
QList<Folder> * folders = new QList<Folder>();
folders->setAutoDelete( false );
- Folder*inb=new Folder("INBOX");
+ Folder*inb=new Folder("INBOX","/");
folders->append(inb);
return folders;
}
QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&)
{
return "";
}
void POP3wrapper::deleteMail(const RecMail&mail)
{
login();
diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp
index 96602c2..858283f 100644
--- a/noncore/net/mail/mailwrapper.cpp
+++ b/noncore/net/mail/mailwrapper.cpp
@@ -8,47 +8,52 @@
#include "mailwrapper.h"
#include "logindialog.h"
//#include "mail.h"
#include "defines.h"
Attachment::Attachment( DocLnk lnk )
{
doc = lnk;
size = QFileInfo( doc.file() ).size();
}
-Folder::Folder(const QString&tmp_name )
+Folder::Folder(const QString&tmp_name, const QString&sep )
{
name = tmp_name;
nameDisplay = name;
for ( int pos = nameDisplay.find( '&' ); pos != -1;
pos = nameDisplay.find( '&' ) ) {
int end = nameDisplay.find( '-' );
if ( end == -1 || end <= pos ) break;
QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 );
// TODO: do real base64 decoding here !
if ( str64.compare( "APw" ) == 0 ) {
nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" );
} else if ( str64.compare( "APY" ) == 0 ) {
nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" );
}
}
qDebug( "folder " + name + " - displayed as " + nameDisplay );
+ separator = sep;
}
+const QString& Folder::Separator()const
+{
+ return separator;
+}
-IMAPFolder::IMAPFolder(const QString&name,bool select,const QString&prefix )
- : Folder( name ),m_MaySelect(select)
+IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix )
+ : Folder( name,sep ),m_MaySelect(select)
{
if (prefix.length()>0) {
if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
}
}
}
MailWrapper::MailWrapper( Settings *s )
: QObject()
{
settings = s;
diff --git a/noncore/net/mail/mailwrapper.h b/noncore/net/mail/mailwrapper.h
index 6994dd8..d78f8e9 100644
--- a/noncore/net/mail/mailwrapper.h
+++ b/noncore/net/mail/mailwrapper.h
@@ -62,38 +62,39 @@ public:
void setReply( const QString&a ) { reply = a; }
private:
QList<Attachment> attList;
QString name, mail, to, cc, bcc, reply, subject, message;
};
class Folder : public QObject
{
Q_OBJECT
public:
- Folder( const QString&init_name );
+ Folder( const QString&init_name,const QString&sep );
const QString&getDisplayName()const { return nameDisplay; }
const QString&getName()const { return name; }
virtual bool may_select()const{return true;};
+ const QString&Separator()const;
protected:
- QString nameDisplay, name;
+ QString nameDisplay, name, separator;
};
class IMAPFolder : public Folder
{
public:
- IMAPFolder(const QString&name,bool select=true,const QString&prefix="" );
+ IMAPFolder(const QString&name, const QString&sep, bool select=true,const QString&prefix="" );
virtual bool may_select()const{return m_MaySelect;}
private:
bool m_MaySelect;
};
class MailWrapper : public QObject
{
Q_OBJECT
public:
MailWrapper( Settings *s );
void sendMail( Mail mail );
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index 075d8c7..4508a95 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -314,25 +314,25 @@ void POP3wrapper::logout()
mailpop3_free( m_pop3 );
m_pop3 = NULL;
}
QList<Folder>* POP3wrapper::listFolders()
{
/* TODO: integrate MH directories
but not before version 0.1 ;)
*/
QList<Folder> * folders = new QList<Folder>();
folders->setAutoDelete( false );
- Folder*inb=new Folder("INBOX");
+ Folder*inb=new Folder("INBOX","/");
folders->append(inb);
return folders;
}
QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&)
{
return "";
}
void POP3wrapper::deleteMail(const RecMail&mail)
{
login();