summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper
authorzautrix <zautrix>2004-08-31 21:01:18 (UTC)
committer zautrix <zautrix>2004-08-31 21:01:18 (UTC)
commit3f5c51234c8068f3d4826a2a0066648ace21a19f (patch) (unidiff)
tree91b76c1c7ddec6628c573e409070070747d99feb /kmicromail/libmailwrapper
parent95f8d4f1de557bd25ae38807d970208399cec5d1 (diff)
downloadkdepimpi-3f5c51234c8068f3d4826a2a0066648ace21a19f.zip
kdepimpi-3f5c51234c8068f3d4826a2a0066648ace21a19f.tar.gz
kdepimpi-3f5c51234c8068f3d4826a2a0066648ace21a19f.tar.bz2
Enhancements of kopiemail
Diffstat (limited to 'kmicromail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/abstractmail.cpp29
-rw-r--r--kmicromail/libmailwrapper/abstractmail.h8
-rw-r--r--kmicromail/libmailwrapper/genericwrapper.cpp6
-rw-r--r--kmicromail/libmailwrapper/genericwrapper.h3
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp68
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.h6
-rw-r--r--kmicromail/libmailwrapper/mhwrapper.cpp5
-rw-r--r--kmicromail/libmailwrapper/mhwrapper.h3
-rw-r--r--kmicromail/libmailwrapper/nntpwrapper.cpp5
-rw-r--r--kmicromail/libmailwrapper/nntpwrapper.h3
-rw-r--r--kmicromail/libmailwrapper/pop3wrapper.cpp21
-rw-r--r--kmicromail/libmailwrapper/pop3wrapper.h4
12 files changed, 128 insertions, 33 deletions
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp
index 128a7c0..3998abd 100644
--- a/kmicromail/libmailwrapper/abstractmail.cpp
+++ b/kmicromail/libmailwrapper/abstractmail.cpp
@@ -1,172 +1,187 @@
1// CHANGED 2004-09-31 Lutz Rogowski
1#include "abstractmail.h" 2#include "abstractmail.h"
2#include "imapwrapper.h" 3#include "imapwrapper.h"
3#include "pop3wrapper.h" 4#include "pop3wrapper.h"
4#include "nntpwrapper.h" 5#include "nntpwrapper.h"
5#include "mhwrapper.h" 6#include "mhwrapper.h"
6#include "mailtypes.h" 7#include "mailtypes.h"
7 8
8 9
9 10
10#include <kdecore/kstandarddirs.h> 11#include <kdecore/kstandarddirs.h>
11#include <qfile.h> 12#include <qfile.h>
12#include <qtextstream.h> 13#include <qtextstream.h>
13#include <stdlib.h> 14#include <stdlib.h>
14#include <libetpan/mailmime_content.h> 15#include <libetpan/mailmime_content.h>
15#include <libetpan/mailmime.h> 16#include <libetpan/mailmime.h>
16 17
17using namespace Opie::Core; 18using namespace Opie::Core;
18AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 19AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
19{ 20{
20 return new IMAPwrapper(a); 21 return new IMAPwrapper(a);
21} 22}
22 23
23AbstractMail* AbstractMail::getWrapper(POP3account *a) 24AbstractMail* AbstractMail::getWrapper(POP3account *a)
24{ 25{
25 return new POP3wrapper(a); 26 return new POP3wrapper(a);
26} 27}
27 28
28AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) 29AbstractMail* AbstractMail::getWrapper(NNTPaccount *a)
29{ 30{
30 return new NNTPwrapper(a); 31 return new NNTPwrapper(a);
31} 32}
32 33
33AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) 34AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
34{ 35{
35 return new MHwrapper(a,name); 36 return new MHwrapper(a,name);
36} 37}
37 38
38AbstractMail* AbstractMail::getWrapper(Account*a) 39AbstractMail* AbstractMail::getWrapper(Account*a)
39{ 40{
40 if (!a) return 0; 41 if (!a) return 0;
41 switch (a->getType()) { 42 switch (a->getType()) {
42 case MAILLIB::A_IMAP: 43 case MAILLIB::A_IMAP:
43 return new IMAPwrapper((IMAPaccount*)a); 44 return new IMAPwrapper((IMAPaccount*)a);
44 break; 45 break;
45 case MAILLIB::A_POP3: 46 case MAILLIB::A_POP3:
46 return new POP3wrapper((POP3account*)a); 47 return new POP3wrapper((POP3account*)a);
47 break; 48 break;
48 case MAILLIB::A_NNTP: 49 case MAILLIB::A_NNTP:
49 return new NNTPwrapper((NNTPaccount*)a); 50 return new NNTPwrapper((NNTPaccount*)a);
50 break; 51 break;
51 default: 52 default:
52 return 0; 53 return 0;
53 } 54 }
54} 55}
55 56
56encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 57encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
57{ 58{
58 // odebug << "Decode string start" << oendl; 59 // odebug << "Decode string start" << oendl;
59 char*result_text; 60 char*result_text;
60 size_t index = 0; 61 size_t index = 0;
61 /* reset for recursive use! */ 62 /* reset for recursive use! */
62 size_t target_length = 0; 63 size_t target_length = 0;
63 result_text = 0; 64 result_text = 0;
64 int mimetype = MAILMIME_MECHANISM_7BIT; 65 int mimetype = MAILMIME_MECHANISM_7BIT;
65 if (enc.lower()=="quoted-printable") { 66 if (enc.lower()=="quoted-printable") {
66 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 67 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
67 } else if (enc.lower()=="base64") { 68 } else if (enc.lower()=="base64") {
68 mimetype = MAILMIME_MECHANISM_BASE64; 69 mimetype = MAILMIME_MECHANISM_BASE64;
69 } else if (enc.lower()=="8bit") { 70 } else if (enc.lower()=="8bit") {
70 mimetype = MAILMIME_MECHANISM_8BIT; 71 mimetype = MAILMIME_MECHANISM_8BIT;
71 } else if (enc.lower()=="binary") { 72 } else if (enc.lower()=="binary") {
72 mimetype = MAILMIME_MECHANISM_BINARY; 73 mimetype = MAILMIME_MECHANISM_BINARY;
73 } 74 }
74 75
75 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 76 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
76 &result_text,&target_length); 77 &result_text,&target_length);
77 78
78 encodedString* result = new encodedString(); 79 encodedString* result = new encodedString();
79 if (err == MAILIMF_NO_ERROR) { 80 if (err == MAILIMF_NO_ERROR) {
80 result->setContent(result_text,target_length); 81 result->setContent(result_text,target_length);
81 } 82 }
82 //odebug << "Decode string finished" << oendl; 83 //odebug << "Decode string finished" << oendl;
83 return result; 84 return result;
84} 85}
85 86
86QString AbstractMail::convert_String(const char*text) 87QString AbstractMail::convert_String(const char*text)
87{ 88{
88 //size_t index = 0; 89 //size_t index = 0;
89 char*res = 0; 90 char*res = 0;
90 int err = MAILIMF_NO_ERROR; 91 int err = MAILIMF_NO_ERROR;
91 92
92 QString result(text); 93 QString result(text);
93 94
94 /* due a bug in libetpan it isn't usable this moment */ 95 /* due a bug in libetpan it isn't usable this moment */
95/* int err = mailmime_encoded_phrase_parse("iso-8859-1", 96/* int err = mailmime_encoded_phrase_parse("iso-8859-1",
96 text, strlen(text),&index, "iso-8859-1",&res);*/ 97 text, strlen(text),&index, "iso-8859-1",&res);*/
97 //odebug << "Input: " << text << "" << oendl; 98 //odebug << "Input: " << text << "" << oendl;
98 if (err == MAILIMF_NO_ERROR && res && strlen(res)) { 99 if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
99// result = QString(res); 100// result = QString(res);
100// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl; 101// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl;
101 } 102 }
102 if (res) free(res); 103 if (res) free(res);
103 return result; 104 return result;
104} 105}
105 106
106/* cp & paste from launcher */ 107/* cp & paste from launcher */
107QString AbstractMail::gen_attachment_id() 108QString AbstractMail::gen_attachment_id()
108{ 109{
109 QFile file( "/proc/sys/kernel/random/uuid" ); 110 QFile file( "/proc/sys/kernel/random/uuid" );
110 if (!file.open(IO_ReadOnly ) ) 111 if (!file.open(IO_ReadOnly ) )
111 return QString::null; 112 return QString::null;
112 113
113 QTextStream stream(&file); 114 QTextStream stream(&file);
114 115
115 return "{" + stream.read().stripWhiteSpace() + "}"; 116 return "{" + stream.read().stripWhiteSpace() + "}";
116} 117}
117 118
118int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) 119int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool)
119{ 120{
120 return 0; 121 return 0;
121} 122}
122 123
123QString AbstractMail::defaultLocalfolder() 124QString AbstractMail::defaultLocalfolder()
124{ 125{
125 // QString f = getenv( "HOME" ); 126 // QString f = getenv( "HOME" );
126 QString f = locateLocal( "data", "kmicromail/localmail"); 127 QString f = locateLocal( "data", "kmicromail/localmail");
127 // f += "/Applications/opiemail/localmail"; 128 // f += "/Applications/opiemail/localmail";
128 return f; 129 return f;
129} 130}
130 131
131QString AbstractMail::draftFolder() 132QString AbstractMail::draftFolder()
132{ 133{
133 return QString("Drafts"); 134 return QString("Drafts");
134} 135}
135 136
136/* temporary - will be removed when implemented in all classes */ 137/* temporary - will be removed when implemented in all classes */
137void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) 138void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &)
138{ 139{
139} 140}
141void AbstractMail::deleteMailList(const QValueList<RecMailP>&target)
142{
143 qDebug("AbstractMail::deleteMailList:: Please reimplement! ");
140 144
145}
141void AbstractMail::mvcpAllMails(const FolderP&fromFolder, 146void AbstractMail::mvcpAllMails(const FolderP&fromFolder,
142 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 147 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
148{
149 QValueList<RecMailP> t;
150 listMessages(fromFolder->getName(),t, maxSizeInKb);
151 mvcpMailList( t,targetFolder,targetWrapper,moveit);
152
153}
154void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t,
155 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
143{ 156{
144 QValueList<RecMailP> t; 157
145 listMessages(fromFolder->getName(),t);
146 encodedString*st = 0; 158 encodedString*st = 0;
147 while (t.count()>0) { 159 int iii = 0;
148 RecMailP r = (*t.begin()); 160 int count = t.count();
161 while (iii < count ) {
162 RecMailP r = (*t.at( iii ));
149 st = fetchRawBody(r); 163 st = fetchRawBody(r);
150 if (st) { 164 if (st) {
151 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 165 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
152 delete st; 166 delete st;
153 } 167 }
154 t.remove(t.begin()); 168 ++iii;
155 } 169 }
156 if (moveit) { 170 if (moveit) {
157 deleteAllMail(fromFolder); 171 deleteMailList( t );
172 //deleteAllMail(fromFolder);
158 } 173 }
159} 174}
160 175
161void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 176void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
162{ 177{
163 encodedString*st = 0; 178 encodedString*st = 0;
164 st = fetchRawBody(mail); 179 st = fetchRawBody(mail);
165 if (st) { 180 if (st) {
166 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 181 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
167 delete st; 182 delete st;
168 } 183 }
169 if (moveit) { 184 if (moveit) {
170 deleteMail(mail); 185 deleteMail(mail);
171 } 186 }
172} 187}
diff --git a/kmicromail/libmailwrapper/abstractmail.h b/kmicromail/libmailwrapper/abstractmail.h
index e5d64a6..cae83f4 100644
--- a/kmicromail/libmailwrapper/abstractmail.h
+++ b/kmicromail/libmailwrapper/abstractmail.h
@@ -1,72 +1,76 @@
1// CHANGED 2004-09-31 Lutz Rogowski
1#ifndef __abstract_mail_ 2#ifndef __abstract_mail_
2#define __abstract_mail_ 3#define __abstract_mail_
3 4
4#include "maildefines.h" 5#include "maildefines.h"
5 6
6#include "settings.h" 7#include "settings.h"
7 8
8#include <qobject.h> 9#include <qobject.h>
9#include <opie2/osmartpointer.h> 10#include <opie2/osmartpointer.h>
10#include "mailtypes.h" 11#include "mailtypes.h"
11 12
12class IMAPwrapper; 13class IMAPwrapper;
13class POP3wrapper; 14class POP3wrapper;
14class Folder; 15class Folder;
15class encodedString; 16class encodedString;
16struct folderStat; 17struct folderStat;
17 18
18class AbstractMail:public QObject 19class AbstractMail:public QObject
19{ 20{
20 Q_OBJECT 21 Q_OBJECT
21public: 22public:
22 AbstractMail(){}; 23 AbstractMail(){};
23 virtual ~AbstractMail(){} 24 virtual ~AbstractMail(){}
24 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders()=0; 25 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders()=0;
25 virtual void listMessages(const QString & mailbox,QValueList<RecMailP>&target )=0; 26 virtual void listMessages(const QString & mailbox,QValueList<RecMailP>&target, int sizeInKb = 0 )=0;
26 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0; 27 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0;
27 virtual RecBodyP fetchBody(const RecMailP&mail)=0; 28 virtual RecBodyP fetchBody(const RecMailP&mail)=0;
28 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part)=0; 29 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part)=0;
29 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part)=0; 30 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part)=0;
30 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part)=0; 31 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part)=0;
31 virtual encodedString* fetchRawBody(const RecMailP&mail)=0; 32 virtual encodedString* fetchRawBody(const RecMailP&mail)=0;
32 33
33 virtual void deleteMail(const RecMailP&mail)=0; 34 virtual void deleteMail(const RecMailP&mail)=0;
35 virtual void deleteMailList(const QValueList<RecMailP>&target);
34 virtual void answeredMail(const RecMailP&mail)=0; 36 virtual void answeredMail(const RecMailP&mail)=0;
35 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&)=0; 37 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&)=0;
36 virtual void deleteMails(const QString & FolderName,const QValueList<Opie::Core::OSmartPointer<RecMail> >&target); 38 virtual void deleteMails(const QString & FolderName,const QValueList<Opie::Core::OSmartPointer<RecMail> >&target);
37 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&)=0; 39 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&)=0;
38 virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0; 40 virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0;
39 41
40 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, 42 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder,
41 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 43 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int sizeInKb = 0);
44 virtual void mvcpMailList(const QValueList<RecMailP>& t,
45 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
42 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 46 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
43 47
44 virtual void cleanMimeCache(){}; 48 virtual void cleanMimeCache(){};
45 /* mail box methods */ 49 /* mail box methods */
46 /* parameter is the box to create. 50 /* parameter is the box to create.
47 * if the implementing subclass has prefixes, 51 * if the implementing subclass has prefixes,
48 * them has to be appended automatic. 52 * them has to be appended automatic.
49 */ 53 */
50 virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0, 54 virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0,
51 const QString& delemiter="/",bool getsubfolder=false); 55 const QString& delemiter="/",bool getsubfolder=false);
52 virtual void logout()=0; 56 virtual void logout()=0;
53 57
54 static AbstractMail* getWrapper(IMAPaccount *a); 58 static AbstractMail* getWrapper(IMAPaccount *a);
55 static AbstractMail* getWrapper(POP3account *a); 59 static AbstractMail* getWrapper(POP3account *a);
56 static AbstractMail* getWrapper(NNTPaccount *a); 60 static AbstractMail* getWrapper(NNTPaccount *a);
57 /* mbox only! */ 61 /* mbox only! */
58 static AbstractMail* getWrapper(const QString&a,const QString&name="Local Folders"); 62 static AbstractMail* getWrapper(const QString&a,const QString&name="Local Folders");
59 static AbstractMail* getWrapper(Account*a); 63 static AbstractMail* getWrapper(Account*a);
60 64
61 static QString defaultLocalfolder(); 65 static QString defaultLocalfolder();
62 static QString draftFolder(); 66 static QString draftFolder();
63 67
64 virtual MAILLIB::ATYPE getType()const=0; 68 virtual MAILLIB::ATYPE getType()const=0;
65 virtual const QString&getName()const=0; 69 virtual const QString&getName()const=0;
66 70
67protected: 71protected:
68 static encodedString*decode_String(const encodedString*text,const QString&enc); 72 static encodedString*decode_String(const encodedString*text,const QString&enc);
69 static QString convert_String(const char*text); 73 static QString convert_String(const char*text);
70 static QString gen_attachment_id(); 74 static QString gen_attachment_id();
71}; 75};
72#endif 76#endif
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp
index f804e44..1fd4bb1 100644
--- a/kmicromail/libmailwrapper/genericwrapper.cpp
+++ b/kmicromail/libmailwrapper/genericwrapper.cpp
@@ -1,480 +1,482 @@
1// CHANGED 2004-09-31 Lutz Rogowski
1#include "genericwrapper.h" 2#include "genericwrapper.h"
2#include <libetpan/libetpan.h> 3#include <libetpan/libetpan.h>
3#include "mailtypes.h" 4#include "mailtypes.h"
4 5
5 6
6 7
7using namespace Opie::Core; 8using namespace Opie::Core;
8Genericwrapper::Genericwrapper() 9Genericwrapper::Genericwrapper()
9 : AbstractMail() 10 : AbstractMail()
10{ 11{
11 bodyCache.clear(); 12 bodyCache.clear();
12 m_storage = 0; 13 m_storage = 0;
13 m_folder = 0; 14 m_folder = 0;
14} 15}
15 16
16Genericwrapper::~Genericwrapper() 17Genericwrapper::~Genericwrapper()
17{ 18{
18 if (m_folder) { 19 if (m_folder) {
19 mailfolder_free(m_folder); 20 mailfolder_free(m_folder);
20 } 21 }
21 if (m_storage) { 22 if (m_storage) {
22 mailstorage_free(m_storage); 23 mailstorage_free(m_storage);
23 } 24 }
24 cleanMimeCache(); 25 cleanMimeCache();
25} 26}
26 27
27void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) 28void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime)
28{ 29{
29 if (!mime) { 30 if (!mime) {
30 return; 31 return;
31 } 32 }
32 mailmime_field*field = 0; 33 mailmime_field*field = 0;
33 mailmime_single_fields fields; 34 mailmime_single_fields fields;
34 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 35 memset(&fields, 0, sizeof(struct mailmime_single_fields));
35 if (mime->mm_mime_fields != NULL) { 36 if (mime->mm_mime_fields != NULL) {
36 mailmime_single_fields_init(&fields, mime->mm_mime_fields, 37 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
37 mime->mm_content_type); 38 mime->mm_content_type);
38 } 39 }
39 40
40 mailmime_content*type = fields.fld_content; 41 mailmime_content*type = fields.fld_content;
41 clistcell*current; 42 clistcell*current;
42 if (!type) { 43 if (!type) {
43 target->setType("text"); 44 target->setType("text");
44 target->setSubtype("plain"); 45 target->setSubtype("plain");
45 } else { 46 } else {
46 target->setSubtype(type->ct_subtype); 47 target->setSubtype(type->ct_subtype);
47 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { 48 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
48 case MAILMIME_DISCRETE_TYPE_TEXT: 49 case MAILMIME_DISCRETE_TYPE_TEXT:
49 target->setType("text"); 50 target->setType("text");
50 break; 51 break;
51 case MAILMIME_DISCRETE_TYPE_IMAGE: 52 case MAILMIME_DISCRETE_TYPE_IMAGE:
52 target->setType("image"); 53 target->setType("image");
53 break; 54 break;
54 case MAILMIME_DISCRETE_TYPE_AUDIO: 55 case MAILMIME_DISCRETE_TYPE_AUDIO:
55 target->setType("audio"); 56 target->setType("audio");
56 break; 57 break;
57 case MAILMIME_DISCRETE_TYPE_VIDEO: 58 case MAILMIME_DISCRETE_TYPE_VIDEO:
58 target->setType("video"); 59 target->setType("video");
59 break; 60 break;
60 case MAILMIME_DISCRETE_TYPE_APPLICATION: 61 case MAILMIME_DISCRETE_TYPE_APPLICATION:
61 target->setType("application"); 62 target->setType("application");
62 break; 63 break;
63 case MAILMIME_DISCRETE_TYPE_EXTENSION: 64 case MAILMIME_DISCRETE_TYPE_EXTENSION:
64 default: 65 default:
65 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { 66 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
66 target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); 67 target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension);
67 } 68 }
68 break; 69 break;
69 } 70 }
70 if (type->ct_parameters) { 71 if (type->ct_parameters) {
71 fillParameters(target,type->ct_parameters); 72 fillParameters(target,type->ct_parameters);
72 } 73 }
73 } 74 }
74 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { 75 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
75 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { 76 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) {
76 field = (mailmime_field*)current->data; 77 field = (mailmime_field*)current->data;
77 switch(field->fld_type) { 78 switch(field->fld_type) {
78 case MAILMIME_FIELD_TRANSFER_ENCODING: 79 case MAILMIME_FIELD_TRANSFER_ENCODING:
79 target->setEncoding(getencoding(field->fld_data.fld_encoding)); 80 target->setEncoding(getencoding(field->fld_data.fld_encoding));
80 break; 81 break;
81 case MAILMIME_FIELD_ID: 82 case MAILMIME_FIELD_ID:
82 target->setIdentifier(field->fld_data.fld_id); 83 target->setIdentifier(field->fld_data.fld_id);
83 break; 84 break;
84 case MAILMIME_FIELD_DESCRIPTION: 85 case MAILMIME_FIELD_DESCRIPTION:
85 target->setDescription(field->fld_data.fld_description); 86 target->setDescription(field->fld_data.fld_description);
86 break; 87 break;
87 default: 88 default:
88 break; 89 break;
89 } 90 }
90 } 91 }
91 } 92 }
92} 93}
93 94
94void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) 95void Genericwrapper::fillParameters(RecPartP&target,clist*parameters)
95{ 96{
96 if (!parameters) {return;} 97 if (!parameters) {return;}
97 clistcell*current=0; 98 clistcell*current=0;
98 mailmime_parameter*param; 99 mailmime_parameter*param;
99 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { 100 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
100 param = (mailmime_parameter*)current->data; 101 param = (mailmime_parameter*)current->data;
101 if (param) { 102 if (param) {
102 target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 103 target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
103 } 104 }
104 } 105 }
105} 106}
106 107
107QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) 108QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
108{ 109{
109 QString enc="7bit"; 110 QString enc="7bit";
110 if (!aEnc) return enc; 111 if (!aEnc) return enc;
111 switch(aEnc->enc_type) { 112 switch(aEnc->enc_type) {
112 case MAILMIME_MECHANISM_7BIT: 113 case MAILMIME_MECHANISM_7BIT:
113 enc = "7bit"; 114 enc = "7bit";
114 break; 115 break;
115 case MAILMIME_MECHANISM_8BIT: 116 case MAILMIME_MECHANISM_8BIT:
116 enc = "8bit"; 117 enc = "8bit";
117 break; 118 break;
118 case MAILMIME_MECHANISM_BINARY: 119 case MAILMIME_MECHANISM_BINARY:
119 enc = "binary"; 120 enc = "binary";
120 break; 121 break;
121 case MAILMIME_MECHANISM_QUOTED_PRINTABLE: 122 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
122 enc = "quoted-printable"; 123 enc = "quoted-printable";
123 break; 124 break;
124 case MAILMIME_MECHANISM_BASE64: 125 case MAILMIME_MECHANISM_BASE64:
125 enc = "base64"; 126 enc = "base64";
126 break; 127 break;
127 case MAILMIME_MECHANISM_TOKEN: 128 case MAILMIME_MECHANISM_TOKEN:
128 default: 129 default:
129 if (aEnc->enc_token) { 130 if (aEnc->enc_token) {
130 enc = QString(aEnc->enc_token); 131 enc = QString(aEnc->enc_token);
131 } 132 }
132 break; 133 break;
133 } 134 }
134 return enc; 135 return enc;
135} 136}
136 137
137void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) 138void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count)
138{ 139{
139 if (current_rec >= 10) { 140 if (current_rec >= 10) {
140 ; // odebug << "too deep recursion!" << oendl; 141 ; // odebug << "too deep recursion!" << oendl;
141 } 142 }
142 if (!message || !mime) { 143 if (!message || !mime) {
143 return; 144 return;
144 } 145 }
145 int r; 146 int r;
146 char*data = 0; 147 char*data = 0;
147 size_t len; 148 size_t len;
148 clistiter * cur = 0; 149 clistiter * cur = 0;
149 QString b; 150 QString b;
150 RecPartP part = new RecPart(); 151 RecPartP part = new RecPart();
151 152
152 switch (mime->mm_type) { 153 switch (mime->mm_type) {
153 case MAILMIME_SINGLE: 154 case MAILMIME_SINGLE:
154 { 155 {
155 QValueList<int>countlist = recList; 156 QValueList<int>countlist = recList;
156 countlist.append(current_count); 157 countlist.append(current_count);
157 r = mailmessage_fetch_section(message,mime,&data,&len); 158 r = mailmessage_fetch_section(message,mime,&data,&len);
158 part->setSize(len); 159 part->setSize(len);
159 part->setPositionlist(countlist); 160 part->setPositionlist(countlist);
160 b = gen_attachment_id(); 161 b = gen_attachment_id();
161 part->setIdentifier(b); 162 part->setIdentifier(b);
162 fillSingleBody(part,message,mime); 163 fillSingleBody(part,message,mime);
163 if (part->Type()=="text" && target->Bodytext().isNull()) { 164 if (part->Type()=="text" && target->Bodytext().isNull()) {
164 encodedString*rs = new encodedString(); 165 encodedString*rs = new encodedString();
165 rs->setContent(data,len); 166 rs->setContent(data,len);
166 encodedString*res = decode_String(rs,part->Encoding()); 167 encodedString*res = decode_String(rs,part->Encoding());
167 if (countlist.count()>2) { 168 if (countlist.count()>2) {
168 bodyCache[b]=rs; 169 bodyCache[b]=rs;
169 target->addPart(part); 170 target->addPart(part);
170 } else { 171 } else {
171 delete rs; 172 delete rs;
172 } 173 }
173 b = QString(res->Content()); 174 b = QString(res->Content());
174 delete res; 175 delete res;
175 target->setBodytext(b); 176 target->setBodytext(b);
176 target->setDescription(part); 177 target->setDescription(part);
177 } else { 178 } else {
178 bodyCache[b]=new encodedString(data,len); 179 bodyCache[b]=new encodedString(data,len);
179 target->addPart(part); 180 target->addPart(part);
180 } 181 }
181 } 182 }
182 break; 183 break;
183 case MAILMIME_MULTIPLE: 184 case MAILMIME_MULTIPLE:
184 { 185 {
185 unsigned int ccount = 1; 186 unsigned int ccount = 1;
186 mailmime*cbody=0; 187 mailmime*cbody=0;
187 QValueList<int>countlist = recList; 188 QValueList<int>countlist = recList;
188 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { 189 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
189 cbody = (mailmime*)clist_content(cur); 190 cbody = (mailmime*)clist_content(cur);
190 if (cbody->mm_type==MAILMIME_MULTIPLE) { 191 if (cbody->mm_type==MAILMIME_MULTIPLE) {
191 RecPartP targetPart = new RecPart(); 192 RecPartP targetPart = new RecPart();
192 targetPart->setType("multipart"); 193 targetPart->setType("multipart");
193 countlist.append(current_count); 194 countlist.append(current_count);
194 targetPart->setPositionlist(countlist); 195 targetPart->setPositionlist(countlist);
195 target->addPart(targetPart); 196 target->addPart(targetPart);
196 } 197 }
197 traverseBody(target,message, cbody,countlist,current_rec+1,ccount); 198 traverseBody(target,message, cbody,countlist,current_rec+1,ccount);
198 if (cbody->mm_type==MAILMIME_MULTIPLE) { 199 if (cbody->mm_type==MAILMIME_MULTIPLE) {
199 countlist = recList; 200 countlist = recList;
200 } 201 }
201 ++ccount; 202 ++ccount;
202 } 203 }
203 } 204 }
204 break; 205 break;
205 case MAILMIME_MESSAGE: 206 case MAILMIME_MESSAGE:
206 { 207 {
207 QValueList<int>countlist = recList; 208 QValueList<int>countlist = recList;
208 countlist.append(current_count); 209 countlist.append(current_count);
209 /* the own header is always at recursion 0 - we don't need that */ 210 /* the own header is always at recursion 0 - we don't need that */
210 if (current_rec > 0) { 211 if (current_rec > 0) {
211 part->setPositionlist(countlist); 212 part->setPositionlist(countlist);
212 r = mailmessage_fetch_section(message,mime,&data,&len); 213 r = mailmessage_fetch_section(message,mime,&data,&len);
213 part->setSize(len); 214 part->setSize(len);
214 part->setPositionlist(countlist); 215 part->setPositionlist(countlist);
215 b = gen_attachment_id(); 216 b = gen_attachment_id();
216 part->setIdentifier(b); 217 part->setIdentifier(b);
217 part->setType("message"); 218 part->setType("message");
218 part->setSubtype("rfc822"); 219 part->setSubtype("rfc822");
219 bodyCache[b]=new encodedString(data,len); 220 bodyCache[b]=new encodedString(data,len);
220 target->addPart(part); 221 target->addPart(part);
221 } 222 }
222 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 223 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
223 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); 224 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1);
224 } 225 }
225 } 226 }
226 break; 227 break;
227 } 228 }
228} 229}
229 230
230RecBodyP Genericwrapper::parseMail( mailmessage * msg ) 231RecBodyP Genericwrapper::parseMail( mailmessage * msg )
231{ 232{
232 int err = MAILIMF_NO_ERROR; 233 int err = MAILIMF_NO_ERROR;
233 mailmime_single_fields fields; 234 mailmime_single_fields fields;
234 /* is bound to msg and will be freed there */ 235 /* is bound to msg and will be freed there */
235 mailmime * mime=0; 236 mailmime * mime=0;
236 RecBodyP body = new RecBody(); 237 RecBodyP body = new RecBody();
237 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 238 memset(&fields, 0, sizeof(struct mailmime_single_fields));
238 err = mailmessage_get_bodystructure(msg,&mime); 239 err = mailmessage_get_bodystructure(msg,&mime);
239 QValueList<int>recList; 240 QValueList<int>recList;
240 traverseBody(body,msg,mime,recList); 241 traverseBody(body,msg,mime,recList);
241 return body; 242 return body;
242} 243}
243 244
244QString Genericwrapper::parseDateTime( mailimf_date_time *date ) 245QString Genericwrapper::parseDateTime( mailimf_date_time *date )
245{ 246{
246 char tmp[23]; 247 char tmp[23];
247 248
248 // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 249 // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
249 // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 250 // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
250 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i", 251 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i",
251 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 252 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
252 253
253 return QString( tmp ); 254 return QString( tmp );
254} 255}
255 256
256QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 257QString Genericwrapper::parseAddressList( mailimf_address_list *list )
257{ 258{
258 QString result( "" ); 259 QString result( "" );
259 260
260 bool first = true; 261 bool first = true;
261 if (list == 0) return result; 262 if (list == 0) return result;
262 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 263 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
263 mailimf_address *addr = (mailimf_address *) current->data; 264 mailimf_address *addr = (mailimf_address *) current->data;
264 265
265 if ( !first ) { 266 if ( !first ) {
266 result.append( "," ); 267 result.append( "," );
267 } else { 268 } else {
268 first = false; 269 first = false;
269 } 270 }
270 271
271 switch ( addr->ad_type ) { 272 switch ( addr->ad_type ) {
272 case MAILIMF_ADDRESS_MAILBOX: 273 case MAILIMF_ADDRESS_MAILBOX:
273 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 274 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
274 break; 275 break;
275 case MAILIMF_ADDRESS_GROUP: 276 case MAILIMF_ADDRESS_GROUP:
276 result.append( parseGroup( addr->ad_data.ad_group ) ); 277 result.append( parseGroup( addr->ad_data.ad_group ) );
277 break; 278 break;
278 default: 279 default:
279 ; // odebug << "Generic: unkown mailimf address type" << oendl; 280 ; // odebug << "Generic: unkown mailimf address type" << oendl;
280 break; 281 break;
281 } 282 }
282 } 283 }
283 284
284 return result; 285 return result;
285} 286}
286 287
287QString Genericwrapper::parseGroup( mailimf_group *group ) 288QString Genericwrapper::parseGroup( mailimf_group *group )
288{ 289{
289 QString result( "" ); 290 QString result( "" );
290 291
291 result.append( group->grp_display_name ); 292 result.append( group->grp_display_name );
292 result.append( ": " ); 293 result.append( ": " );
293 294
294 if ( group->grp_mb_list != NULL ) { 295 if ( group->grp_mb_list != NULL ) {
295 result.append( parseMailboxList( group->grp_mb_list ) ); 296 result.append( parseMailboxList( group->grp_mb_list ) );
296 } 297 }
297 298
298 result.append( ";" ); 299 result.append( ";" );
299 300
300 return result; 301 return result;
301} 302}
302 303
303QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) 304QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
304{ 305{
305 QString result( "" ); 306 QString result( "" );
306 307
307 if ( box->mb_display_name == NULL ) { 308 if ( box->mb_display_name == NULL ) {
308 result.append( box->mb_addr_spec ); 309 result.append( box->mb_addr_spec );
309 } else { 310 } else {
310 result.append( convert_String(box->mb_display_name).latin1() ); 311 result.append( convert_String(box->mb_display_name).latin1() );
311 result.append( " <" ); 312 result.append( " <" );
312 result.append( box->mb_addr_spec ); 313 result.append( box->mb_addr_spec );
313 result.append( ">" ); 314 result.append( ">" );
314 } 315 }
315 316
316 return result; 317 return result;
317} 318}
318 319
319QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) 320QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
320{ 321{
321 QString result( "" ); 322 QString result( "" );
322 323
323 bool first = true; 324 bool first = true;
324 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 325 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
325 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 326 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
326 327
327 if ( !first ) { 328 if ( !first ) {
328 result.append( "," ); 329 result.append( "," );
329 } else { 330 } else {
330 first = false; 331 first = false;
331 } 332 }
332 333
333 result.append( parseMailbox( box ) ); 334 result.append( parseMailbox( box ) );
334 } 335 }
335 336
336 return result; 337 return result;
337} 338}
338 339
339encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) 340encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part)
340{ 341{
341 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); 342 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier());
342 if (it==bodyCache.end()) return new encodedString(); 343 if (it==bodyCache.end()) return new encodedString();
343 encodedString*t = decode_String(it.data(),part->Encoding()); 344 encodedString*t = decode_String(it.data(),part->Encoding());
344 return t; 345 return t;
345} 346}
346 347
347encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) 348encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part)
348{ 349{
349 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); 350 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier());
350 if (it==bodyCache.end()) return new encodedString(); 351 if (it==bodyCache.end()) return new encodedString();
351 encodedString*t = it.data(); 352 encodedString*t = it.data();
352 return t; 353 return t;
353} 354}
354 355
355QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 356QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
356{ 357{
357 encodedString*t = fetchDecodedPart(mail,part); 358 encodedString*t = fetchDecodedPart(mail,part);
358 QString text=t->Content(); 359 QString text=t->Content();
359 delete t; 360 delete t;
360 return text; 361 return text;
361} 362}
362 363
363void Genericwrapper::cleanMimeCache() 364void Genericwrapper::cleanMimeCache()
364{ 365{
365 QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); 366 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
366 for (;it!=bodyCache.end();++it) { 367 for (;it!=bodyCache.end();++it) {
367 encodedString*t = it.data(); 368 encodedString*t = it.data();
368 //it.setValue(0); 369 //it.setValue(0);
369 if (t) delete t; 370 if (t) delete t;
370 } 371 }
371 bodyCache.clear(); 372 bodyCache.clear();
372 ; // odebug << "Genericwrapper: cache cleaned" << oendl; 373 ; // odebug << "Genericwrapper: cache cleaned" << oendl;
373} 374}
374 375
375QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) 376QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies)
376{ 377{
377 QStringList res; 378 QStringList res;
378 if (!in_replies || !in_replies->mid_list) return res; 379 if (!in_replies || !in_replies->mid_list) return res;
379 clistiter * current = 0; 380 clistiter * current = 0;
380 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { 381 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) {
381 QString h((char*)current->data); 382 QString h((char*)current->data);
382 while (h.length()>0 && h[0]=='<') { 383 while (h.length()>0 && h[0]=='<') {
383 h.remove(0,1); 384 h.remove(0,1);
384 } 385 }
385 while (h.length()>0 && h[h.length()-1]=='>') { 386 while (h.length()>0 && h[h.length()-1]=='>') {
386 h.remove(h.length()-1,1); 387 h.remove(h.length()-1,1);
387 } 388 }
388 if (h.length()>0) { 389 if (h.length()>0) {
389 res.append(h); 390 res.append(h);
390 } 391 }
391 } 392 }
392 return res; 393 return res;
393} 394}
394 395
395void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to) 396void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb)
396{ 397{
397 int r; 398 int r;
398 mailmessage_list * env_list = 0; 399 mailmessage_list * env_list = 0;
399 r = mailsession_get_messages_list(session,&env_list); 400 r = mailsession_get_messages_list(session,&env_list);
400 if (r != MAIL_NO_ERROR) { 401 if (r != MAIL_NO_ERROR) {
401 ; // odebug << "Error message list" << oendl; 402 ; // odebug << "Error message list" << oendl;
402 return; 403 return;
403 } 404 }
404 r = mailsession_get_envelopes_list(session, env_list); 405 r = mailsession_get_envelopes_list(session, env_list);
405 if (r != MAIL_NO_ERROR) { 406 if (r != MAIL_NO_ERROR) {
406 ; // odebug << "Error filling message list" << oendl; 407 ; // odebug << "Error filling message list" << oendl;
407 if (env_list) { 408 if (env_list) {
408 mailmessage_list_free(env_list); 409 mailmessage_list_free(env_list);
409 } 410 }
410 return; 411 return;
411 } 412 }
412 mailimf_references * refs = 0; 413 mailimf_references * refs = 0;
413 mailimf_in_reply_to * in_replies = 0; 414 mailimf_in_reply_to * in_replies = 0;
414 uint32_t i = 0; 415 uint32_t i = 0;
415 for(; i < carray_count(env_list->msg_tab) ; ++i) { 416 for(; i < carray_count(env_list->msg_tab) ; ++i) {
416 mailmessage * msg; 417 mailmessage * msg;
417 QBitArray mFlags(7); 418 QBitArray mFlags(7);
418 msg = (mailmessage*)carray_get(env_list->msg_tab, i); 419 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
419 if (msg->msg_fields == NULL) { 420 if (msg->msg_fields == NULL) {
420 //; // odebug << "could not fetch envelope of message " << i << "" << oendl; 421 //; // odebug << "could not fetch envelope of message " << i << "" << oendl;
421 continue; 422 continue;
422 } 423 }
423 RecMailP mail = new RecMail(); 424 RecMailP mail = new RecMail();
424 mail->setWrapper(this); 425 mail->setWrapper(this);
425 mail_flags * flag_result = 0; 426 mail_flags * flag_result = 0;
426 r = mailmessage_get_flags(msg,&flag_result); 427 r = mailmessage_get_flags(msg,&flag_result);
427 if (r == MAIL_ERROR_NOT_IMPLEMENTED) { 428 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
428 mFlags.setBit(FLAG_SEEN); 429 mFlags.setBit(FLAG_SEEN);
429 } 430 }
430 mailimf_single_fields single_fields; 431 mailimf_single_fields single_fields;
431 mailimf_single_fields_init(&single_fields, msg->msg_fields); 432 mailimf_single_fields_init(&single_fields, msg->msg_fields);
432 mail->setMsgsize(msg->msg_size); 433 mail->setMsgsize(msg->msg_size);
433 mail->setFlags(mFlags); 434 mail->setFlags(mFlags);
434 mail->setMbox(mailbox); 435 mail->setMbox(mailbox);
435 mail->setNumber(msg->msg_index); 436 mail->setNumber(msg->msg_index);
436 if (single_fields.fld_subject) 437 if (single_fields.fld_subject)
437 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); 438 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
438 if (single_fields.fld_from) 439 if (single_fields.fld_from)
439 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); 440 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
440 if (!mbox_as_to) { 441 if (!mbox_as_to) {
441 if (single_fields.fld_to) 442 if (single_fields.fld_to)
442 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); 443 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
443 } else { 444 } else {
444 mail->setTo(mailbox); 445 mail->setTo(mailbox);
445 } 446 }
446 if (single_fields.fld_cc) 447 if (single_fields.fld_cc)
447 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); 448 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
448 if (single_fields.fld_bcc) 449 if (single_fields.fld_bcc)
449 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); 450 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
450 if (single_fields.fld_orig_date) 451 if (single_fields.fld_orig_date)
451 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); 452 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) );
452 // crashes when accessing pop3 account? 453 // crashes when accessing pop3 account?
453 if (single_fields.fld_message_id->mid_value) { 454 if (single_fields.fld_message_id->mid_value) {
454 mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); 455 mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
455 ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; 456 ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl;
456 } 457 }
457 458
458 if (single_fields.fld_reply_to) { 459 if (single_fields.fld_reply_to) {
459 QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); 460 QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list);
460 if (t.count()>0) { 461 if (t.count()>0) {
461 mail->setReplyto(t[0]); 462 mail->setReplyto(t[0]);
462 } 463 }
463 } 464 }
464#if 0 465#if 0
465 refs = single_fields.fld_references; 466 refs = single_fields.fld_references;
466 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 467 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
467 char * text = (char*)refs->mid_list->first->data; 468 char * text = (char*)refs->mid_list->first->data;
468 mail->setReplyto(QString(text)); 469 mail->setReplyto(QString(text));
469 } 470 }
470#endif 471#endif
471 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && 472 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list &&
472 clist_count(single_fields.fld_in_reply_to->mid_list)) { 473 clist_count(single_fields.fld_in_reply_to->mid_list)) {
473 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); 474 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to));
474 } 475 }
475 target.append(mail); 476 if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 )
477 target.append(mail);
476 } 478 }
477 if (env_list) { 479 if (env_list) {
478 mailmessage_list_free(env_list); 480 mailmessage_list_free(env_list);
479 } 481 }
480} 482}
diff --git a/kmicromail/libmailwrapper/genericwrapper.h b/kmicromail/libmailwrapper/genericwrapper.h
index 8be9212..235e116 100644
--- a/kmicromail/libmailwrapper/genericwrapper.h
+++ b/kmicromail/libmailwrapper/genericwrapper.h
@@ -1,67 +1,68 @@
1// CHANGED 2004-09-31 Lutz Rogowski
1#ifndef __GENERIC_WRAPPER_H 2#ifndef __GENERIC_WRAPPER_H
2#define __GENERIC_WRAPPER_H 3#define __GENERIC_WRAPPER_H
3 4
4#include "abstractmail.h" 5#include "abstractmail.h"
5#include <qmap.h> 6#include <qmap.h>
6#include <qstring.h> 7#include <qstring.h>
7#include <libetpan/clist.h> 8#include <libetpan/clist.h>
8 9
9class RecMail; 10class RecMail;
10class RecBody; 11class RecBody;
11class encodedString; 12class encodedString;
12struct mailpop3; 13struct mailpop3;
13struct mailmessage; 14struct mailmessage;
14struct mailmime; 15struct mailmime;
15struct mailmime_mechanism; 16struct mailmime_mechanism;
16struct mailimf_mailbox_list; 17struct mailimf_mailbox_list;
17struct mailimf_mailbox; 18struct mailimf_mailbox;
18struct mailimf_date_time; 19struct mailimf_date_time;
19struct mailimf_group; 20struct mailimf_group;
20struct mailimf_address_list; 21struct mailimf_address_list;
21struct mailsession; 22struct mailsession;
22struct mailstorage; 23struct mailstorage;
23struct mailfolder; 24struct mailfolder;
24struct mailimf_in_reply_to; 25struct mailimf_in_reply_to;
25 26
26/* this class hold just the funs shared between 27/* this class hold just the funs shared between
27 * mbox and pop3 (later mh, too) mail access. 28 * mbox and pop3 (later mh, too) mail access.
28 * it is not desigend to make a instance of it! 29 * it is not desigend to make a instance of it!
29 */ 30 */
30class Genericwrapper : public AbstractMail 31class Genericwrapper : public AbstractMail
31{ 32{
32 Q_OBJECT 33 Q_OBJECT
33public: 34public:
34 Genericwrapper(); 35 Genericwrapper();
35 virtual ~Genericwrapper(); 36 virtual ~Genericwrapper();
36 37
37 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part); 38 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part);
38 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part); 39 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part);
39 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part); 40 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part);
40 virtual void cleanMimeCache(); 41 virtual void cleanMimeCache();
41 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&){return 1;} 42 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&){return 1;}
42 virtual void logout(){}; 43 virtual void logout(){};
43 virtual void storeMessage(const char*msg,size_t length, const QString&folder){}; 44 virtual void storeMessage(const char*msg,size_t length, const QString&folder){};
44 45
45protected: 46protected:
46 RecBodyP parseMail( mailmessage * msg ); 47 RecBodyP parseMail( mailmessage * msg );
47 QString parseMailboxList( mailimf_mailbox_list *list ); 48 QString parseMailboxList( mailimf_mailbox_list *list );
48 QString parseMailbox( mailimf_mailbox *box ); 49 QString parseMailbox( mailimf_mailbox *box );
49 QString parseGroup( mailimf_group *group ); 50 QString parseGroup( mailimf_group *group );
50 QString parseAddressList( mailimf_address_list *list ); 51 QString parseAddressList( mailimf_address_list *list );
51 QString parseDateTime( mailimf_date_time *date ); 52 QString parseDateTime( mailimf_date_time *date );
52 53
53 void traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1); 54 void traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1);
54 static void fillSingleBody(RecPartP&target,mailmessage*message,mailmime*mime); 55 static void fillSingleBody(RecPartP&target,mailmessage*message,mailmime*mime);
55 static void fillParameters(RecPartP&target,clist*parameters); 56 static void fillParameters(RecPartP&target,clist*parameters);
56 static QString getencoding(mailmime_mechanism*aEnc); 57 static QString getencoding(mailmime_mechanism*aEnc);
57 virtual void parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to=false); 58 virtual void parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to=false, int maxSizeInKb = 0);
58 QStringList parseInreplies(mailimf_in_reply_to * in_replies); 59 QStringList parseInreplies(mailimf_in_reply_to * in_replies);
59 60
60 QString msgTempName; 61 QString msgTempName;
61 unsigned int last_msg_id; 62 unsigned int last_msg_id;
62 QMap<QString,encodedString*> bodyCache; 63 QMap<QString,encodedString*> bodyCache;
63 mailstorage * m_storage; 64 mailstorage * m_storage;
64 mailfolder*m_folder; 65 mailfolder*m_folder;
65}; 66};
66 67
67#endif 68#endif
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index e0fb6f9..bb8bbfc 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -1,1182 +1,1230 @@
1// CHANGED 2004-09-31 Lutz Rogowski
1#include <stdlib.h> 2#include <stdlib.h>
2#include <libetpan/libetpan.h> 3#include <libetpan/libetpan.h>
3#include <qpe/global.h> 4#include <qpe/global.h>
4#include <qapplication.h> 5#include <qapplication.h>
5#include "imapwrapper.h" 6#include "imapwrapper.h"
6#include "mailtypes.h" 7#include "mailtypes.h"
7#include "logindialog.h" 8#include "logindialog.h"
8 9
9using namespace Opie::Core; 10using namespace Opie::Core;
10IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 11IMAPwrapper::IMAPwrapper( IMAPaccount *a )
11 : AbstractMail() 12 : AbstractMail()
12{ 13{
13 account = a; 14 account = a;
14 m_imap = 0; 15 m_imap = 0;
15 m_Lastmbox = ""; 16 m_Lastmbox = "";
16} 17}
17 18
18IMAPwrapper::~IMAPwrapper() 19IMAPwrapper::~IMAPwrapper()
19{ 20{
20 logout(); 21 logout();
21} 22}
22 23
23/* to avoid to often select statements in loops etc. 24/* to avoid to often select statements in loops etc.
24 we trust that we are logged in and connection is established!*/ 25 we trust that we are logged in and connection is established!*/
25int IMAPwrapper::selectMbox(const QString&mbox) 26int IMAPwrapper::selectMbox(const QString&mbox)
26{ 27{
27 if (mbox == m_Lastmbox) { 28 if (mbox == m_Lastmbox) {
28 return MAILIMAP_NO_ERROR; 29 return MAILIMAP_NO_ERROR;
29 } 30 }
30 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 31 int err = mailimap_select( m_imap, (char*)mbox.latin1());
31 if ( err != MAILIMAP_NO_ERROR ) { 32 if ( err != MAILIMAP_NO_ERROR ) {
32 m_Lastmbox = ""; 33 m_Lastmbox = "";
33 return err; 34 return err;
34 } 35 }
35 m_Lastmbox = mbox; 36 m_Lastmbox = mbox;
36 return err; 37 return err;
37} 38}
38 39
39void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 40void IMAPwrapper::imap_progress( size_t current, size_t maximum )
40{ 41{
41 qApp->processEvents(); 42 qApp->processEvents();
42 qDebug("imap progress %d of %d ",current,maximum ); 43 qDebug("imap progress %d of %d ",current,maximum );
43} 44}
44 45
45bool IMAPwrapper::start_tls(bool force_tls) 46bool IMAPwrapper::start_tls(bool force_tls)
46{ 47{
47 int err; 48 int err;
48 bool try_tls; 49 bool try_tls;
49 mailimap_capability_data * cap_data = 0; 50 mailimap_capability_data * cap_data = 0;
50 51
51 err = mailimap_capability(m_imap,&cap_data); 52 err = mailimap_capability(m_imap,&cap_data);
52 if (err != MAILIMAP_NO_ERROR) { 53 if (err != MAILIMAP_NO_ERROR) {
53 Global::statusMessage("error getting capabilities!"); 54 Global::statusMessage("error getting capabilities!");
54 return false; 55 return false;
55 } 56 }
56 clistiter * cur; 57 clistiter * cur;
57 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { 58 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
58 struct mailimap_capability * cap; 59 struct mailimap_capability * cap;
59 cap = (struct mailimap_capability *)clist_content(cur); 60 cap = (struct mailimap_capability *)clist_content(cur);
60 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { 61 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
61 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { 62 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
62 try_tls = true; 63 try_tls = true;
63 break; 64 break;
64 } 65 }
65 } 66 }
66 } 67 }
67 if (cap_data) { 68 if (cap_data) {
68 mailimap_capability_data_free(cap_data); 69 mailimap_capability_data_free(cap_data);
69 } 70 }
70 if (try_tls) { 71 if (try_tls) {
71 err = mailimap_starttls(m_imap); 72 err = mailimap_starttls(m_imap);
72 if (err != MAILIMAP_NO_ERROR && force_tls) { 73 if (err != MAILIMAP_NO_ERROR && force_tls) {
73 Global::statusMessage(tr("Server has no TLS support!")); 74 Global::statusMessage(tr("Server has no TLS support!"));
74 try_tls = false; 75 try_tls = false;
75 } else { 76 } else {
76 mailstream_low * low; 77 mailstream_low * low;
77 mailstream_low * new_low; 78 mailstream_low * new_low;
78 low = mailstream_get_low(m_imap->imap_stream); 79 low = mailstream_get_low(m_imap->imap_stream);
79 if (!low) { 80 if (!low) {
80 try_tls = false; 81 try_tls = false;
81 } else { 82 } else {
82 int fd = mailstream_low_get_fd(low); 83 int fd = mailstream_low_get_fd(low);
83 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 84 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
84 mailstream_low_free(low); 85 mailstream_low_free(low);
85 mailstream_set_low(m_imap->imap_stream, new_low); 86 mailstream_set_low(m_imap->imap_stream, new_low);
86 } else { 87 } else {
87 try_tls = false; 88 try_tls = false;
88 } 89 }
89 } 90 }
90 } 91 }
91 } 92 }
92 return try_tls; 93 return try_tls;
93} 94}
94 95
95void IMAPwrapper::login() 96void IMAPwrapper::login()
96{ 97{
97 const char *server, *user, *pass; 98 const char *server, *user, *pass;
98 uint16_t port; 99 uint16_t port;
99 int err = MAILIMAP_NO_ERROR; 100 int err = MAILIMAP_NO_ERROR;
100 101
101 if (account->getOffline()) return; 102 if (account->getOffline()) return;
102 /* we are connected this moment */ 103 /* we are connected this moment */
103 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 104 /* TODO: setup a timer holding the line or if connection closed - delete the value */
104 if (m_imap) { 105 if (m_imap) {
105 err = mailimap_noop(m_imap); 106 err = mailimap_noop(m_imap);
106 if (err!=MAILIMAP_NO_ERROR) { 107 if (err!=MAILIMAP_NO_ERROR) {
107 logout(); 108 logout();
108 } else { 109 } else {
109 mailstream_flush(m_imap->imap_stream); 110 mailstream_flush(m_imap->imap_stream);
110 return; 111 return;
111 } 112 }
112 } 113 }
113 server = account->getServer().latin1(); 114 server = account->getServer().latin1();
114 port = account->getPort().toUInt(); 115 port = account->getPort().toUInt();
115 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 116 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
116 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 117 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
117 login.show(); 118 login.show();
118 if ( QDialog::Accepted == login.exec() ) { 119 if ( QDialog::Accepted == login.exec() ) {
119 // ok 120 // ok
120 user = login.getUser().latin1(); 121 user = login.getUser().latin1();
121 pass = login.getPassword().latin1(); 122 pass = login.getPassword().latin1();
122 } else { 123 } else {
123 // cancel 124 // cancel
124 return; 125 return;
125 } 126 }
126 } else { 127 } else {
127 user = account->getUser().latin1(); 128 user = account->getUser().latin1();
128 pass = account->getPassword().latin1(); 129 pass = account->getPassword().latin1();
129 } 130 }
130 131
131 m_imap = mailimap_new( 20, &imap_progress ); 132 m_imap = mailimap_new( 20, &imap_progress );
132 133
133 /* connect */ 134 /* connect */
134 bool ssl = false; 135 bool ssl = false;
135 bool try_tls = false; 136 bool try_tls = false;
136 bool force_tls = false; 137 bool force_tls = false;
137 138
138 if ( account->ConnectionType() == 2 ) { 139 if ( account->ConnectionType() == 2 ) {
139 ssl = true; 140 ssl = true;
140 } 141 }
141 if (account->ConnectionType()==1) { 142 if (account->ConnectionType()==1) {
142 force_tls = true; 143 force_tls = true;
143 } 144 }
144 145
145 if ( ssl ) { 146 if ( ssl ) {
146 qDebug("using ssl "); 147 qDebug("using ssl ");
147 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 148 err = mailimap_ssl_connect( m_imap, (char*)server, port );
148 } else { 149 } else {
149 err = mailimap_socket_connect( m_imap, (char*)server, port ); 150 err = mailimap_socket_connect( m_imap, (char*)server, port );
150 } 151 }
151 152
152 if ( err != MAILIMAP_NO_ERROR && 153 if ( err != MAILIMAP_NO_ERROR &&
153 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 154 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
154 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 155 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
155 QString failure = ""; 156 QString failure = "";
156 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 157 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
157 failure="Connection refused"; 158 failure="Connection refused";
158 } else { 159 } else {
159 failure="Unknown failure"; 160 failure="Unknown failure";
160 } 161 }
161 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 162 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
162 mailimap_free( m_imap ); 163 mailimap_free( m_imap );
163 m_imap = 0; 164 m_imap = 0;
164 return; 165 return;
165 } 166 }
166 167
167 if (!ssl) { 168 if (!ssl) {
168 try_tls = start_tls(force_tls); 169 try_tls = start_tls(force_tls);
169 } 170 }
170 171
171 bool ok = true; 172 bool ok = true;
172 if (force_tls && !try_tls) { 173 if (force_tls && !try_tls) {
173 Global::statusMessage(tr("Server has no TLS support!")); 174 Global::statusMessage(tr("Server has no TLS support!"));
174 ok = false; 175 ok = false;
175 } 176 }
176 177
177 178
178 /* login */ 179 /* login */
179 180
180 if (ok) { 181 if (ok) {
181 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 182 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
182 if ( err != MAILIMAP_NO_ERROR ) { 183 if ( err != MAILIMAP_NO_ERROR ) {
183 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 184 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
184 ok = false; 185 ok = false;
185 } 186 }
186 } 187 }
187 if (!ok) { 188 if (!ok) {
188 err = mailimap_close( m_imap ); 189 err = mailimap_close( m_imap );
189 mailimap_free( m_imap ); 190 mailimap_free( m_imap );
190 m_imap = 0; 191 m_imap = 0;
191 } 192 }
192} 193}
193 194
194void IMAPwrapper::logout() 195void IMAPwrapper::logout()
195{ 196{
196 int err = MAILIMAP_NO_ERROR; 197 int err = MAILIMAP_NO_ERROR;
197 if (!m_imap) return; 198 if (!m_imap) return;
198 err = mailimap_logout( m_imap ); 199 err = mailimap_logout( m_imap );
199 err = mailimap_close( m_imap ); 200 err = mailimap_close( m_imap );
200 mailimap_free( m_imap ); 201 mailimap_free( m_imap );
201 m_imap = 0; 202 m_imap = 0;
202 m_Lastmbox = ""; 203 m_Lastmbox = "";
203} 204}
204 205
205void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) 206void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb)
206{ 207{
207 int err = MAILIMAP_NO_ERROR; 208 int err = MAILIMAP_NO_ERROR;
208 clist *result = 0; 209 clist *result = 0;
209 clistcell *current; 210 clistcell *current;
210 mailimap_fetch_type *fetchType = 0; 211 mailimap_fetch_type *fetchType = 0;
211 mailimap_set *set = 0; 212 mailimap_set *set = 0;
212 213
213 login(); 214 login();
214 if (!m_imap) { 215 if (!m_imap) {
215 return; 216 return;
216 } 217 }
217 /* select mailbox READONLY for operations */ 218 /* select mailbox READONLY for operations */
218 err = selectMbox(mailbox); 219 err = selectMbox(mailbox);
219 if ( err != MAILIMAP_NO_ERROR ) { 220 if ( err != MAILIMAP_NO_ERROR ) {
220 return; 221 return;
221 } 222 }
222 223
223 int last = m_imap->imap_selection_info->sel_exists; 224 int last = m_imap->imap_selection_info->sel_exists;
224 225
225 if (last == 0) { 226 if (last == 0) {
226 Global::statusMessage(tr("Mailbox has no mails")); 227 Global::statusMessage(tr("Mailbox has no mails"));
227 return; 228 return;
228 } else { 229 } else {
229 } 230 }
230 231
231 /* the range has to start at 1!!! not with 0!!!! */ 232 /* the range has to start at 1!!! not with 0!!!! */
232 set = mailimap_set_new_interval( 1, last ); 233 set = mailimap_set_new_interval( 1, last );
233 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 234 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
234 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 235 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
235 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 236 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
236 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 237 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
237 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 238 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
238 239
239 err = mailimap_fetch( m_imap, set, fetchType, &result ); 240 err = mailimap_fetch( m_imap, set, fetchType, &result );
240 mailimap_set_free( set ); 241 mailimap_set_free( set );
241 mailimap_fetch_type_free( fetchType ); 242 mailimap_fetch_type_free( fetchType );
242 243
243 QString date,subject,from; 244 QString date,subject,from;
244 245
245 if ( err == MAILIMAP_NO_ERROR ) { 246 if ( err == MAILIMAP_NO_ERROR ) {
246 mailimap_msg_att * msg_att; 247 mailimap_msg_att * msg_att;
247 int i = 0; 248 int i = 0;
248 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 249 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
249 ++i; 250 ++i;
250 msg_att = (mailimap_msg_att*)current->data; 251 msg_att = (mailimap_msg_att*)current->data;
251 RecMail*m = parse_list_result(msg_att); 252 RecMail*m = parse_list_result(msg_att);
252 if (m) { 253 if (m) {
253 m->setNumber(i); 254 if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) {
254 m->setMbox(mailbox); 255 m->setNumber(i);
255 m->setWrapper(this); 256 m->setMbox(mailbox);
256 target.append(m); 257 m->setWrapper(this);
258 target.append(m);
259 }
257 } 260 }
258 } 261 }
259 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); 262 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count()));
260 } else { 263 } else {
261 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); 264 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
262 } 265 }
263 if (result) mailimap_fetch_list_free(result); 266 if (result) mailimap_fetch_list_free(result);
264} 267}
265 268
266QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() 269QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders()
267{ 270{
268 const char *path, *mask; 271 const char *path, *mask;
269 int err = MAILIMAP_NO_ERROR; 272 int err = MAILIMAP_NO_ERROR;
270 clist *result = 0; 273 clist *result = 0;
271 clistcell *current = 0; 274 clistcell *current = 0;
272 clistcell*cur_flag = 0; 275 clistcell*cur_flag = 0;
273 mailimap_mbx_list_flags*bflags = 0; 276 mailimap_mbx_list_flags*bflags = 0;
274 277
275 QValueList<FolderP>* folders = new QValueList<FolderP>(); 278 QValueList<FolderP>* folders = new QValueList<FolderP>();
276 login(); 279 login();
277 if (!m_imap) { 280 if (!m_imap) {
278 return folders; 281 return folders;
279 } 282 }
280 283
281/* 284/*
282 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 285 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
283 * We must not forget to filter them out in next loop! 286 * We must not forget to filter them out in next loop!
284 * it seems like ugly code. and yes - it is ugly code. but the best way. 287 * it seems like ugly code. and yes - it is ugly code. but the best way.
285 */ 288 */
286 QString temp; 289 QString temp;
287 mask = "INBOX" ; 290 mask = "INBOX" ;
288 mailimap_mailbox_list *list; 291 mailimap_mailbox_list *list;
289 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 292 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
290 QString del; 293 QString del;
291 bool selectable = true; 294 bool selectable = true;
292 bool no_inferiors = false; 295 bool no_inferiors = false;
293 if ( err == MAILIMAP_NO_ERROR ) { 296 if ( err == MAILIMAP_NO_ERROR ) {
294 current = result->first; 297 current = result->first;
295 for ( int i = result->count; i > 0; i-- ) { 298 for ( int i = result->count; i > 0; i-- ) {
296 list = (mailimap_mailbox_list *) current->data; 299 list = (mailimap_mailbox_list *) current->data;
297 // it is better use the deep copy mechanism of qt itself 300 // it is better use the deep copy mechanism of qt itself
298 // instead of using strdup! 301 // instead of using strdup!
299 temp = list->mb_name; 302 temp = list->mb_name;
300 del = list->mb_delimiter; 303 del = list->mb_delimiter;
301 current = current->next; 304 current = current->next;
302 if ( (bflags = list->mb_flag) ) { 305 if ( (bflags = list->mb_flag) ) {
303 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 306 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
304 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 307 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
305 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 308 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
306 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 309 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
307 no_inferiors = true; 310 no_inferiors = true;
308 } 311 }
309 } 312 }
310 } 313 }
311 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 314 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
312 } 315 }
313 } else { 316 } else {
314 qDebug("error fetching folders: "); 317 qDebug("error fetching folders: ");
315 318
316 } 319 }
317 mailimap_list_result_free( result ); 320 mailimap_list_result_free( result );
318 321
319/* 322/*
320 * second stage - get the other then inbox folders 323 * second stage - get the other then inbox folders
321 */ 324 */
322 mask = "*" ; 325 mask = "*" ;
323 path = account->getPrefix().latin1(); 326 path = account->getPrefix().latin1();
324 if (!path) path = ""; 327 if (!path) path = "";
325 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 328 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
326 if ( err == MAILIMAP_NO_ERROR ) { 329 if ( err == MAILIMAP_NO_ERROR ) {
327 current = result->first; 330 current = result->first;
328 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 331 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
329 no_inferiors = false; 332 no_inferiors = false;
330 list = (mailimap_mailbox_list *) current->data; 333 list = (mailimap_mailbox_list *) current->data;
331 // it is better use the deep copy mechanism of qt itself 334 // it is better use the deep copy mechanism of qt itself
332 // instead of using strdup! 335 // instead of using strdup!
333 temp = list->mb_name; 336 temp = list->mb_name;
334 if (temp.lower()=="inbox") 337 if (temp.lower()=="inbox")
335 continue; 338 continue;
336 if (temp.lower()==account->getPrefix().lower()) 339 if (temp.lower()==account->getPrefix().lower())
337 continue; 340 continue;
338 if ( (bflags = list->mb_flag) ) { 341 if ( (bflags = list->mb_flag) ) {
339 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 342 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
340 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 343 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
341 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 344 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
342 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 345 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
343 no_inferiors = true; 346 no_inferiors = true;
344 } 347 }
345 } 348 }
346 } 349 }
347 del = list->mb_delimiter; 350 del = list->mb_delimiter;
348 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 351 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
349 } 352 }
350 } else { 353 } else {
351 qDebug("error fetching folders "); 354 qDebug("error fetching folders ");
352 355
353 } 356 }
354 if (result) mailimap_list_result_free( result ); 357 if (result) mailimap_list_result_free( result );
355 return folders; 358 return folders;
356} 359}
357 360
358RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 361RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
359{ 362{
360 RecMail * m = 0; 363 RecMail * m = 0;
361 mailimap_msg_att_item *item=0; 364 mailimap_msg_att_item *item=0;
362 clistcell *current,*c,*cf; 365 clistcell *current,*c,*cf;
363 mailimap_msg_att_dynamic*flist; 366 mailimap_msg_att_dynamic*flist;
364 mailimap_flag_fetch*cflag; 367 mailimap_flag_fetch*cflag;
365 int size; 368 int size;
366 QBitArray mFlags(7); 369 QBitArray mFlags(7);
367 QStringList addresslist; 370 QStringList addresslist;
368 371
369 if (!m_att) { 372 if (!m_att) {
370 return m; 373 return m;
371 } 374 }
372 m = new RecMail(); 375 m = new RecMail();
373 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 376 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
374 current = c; 377 current = c;
375 size = 0; 378 size = 0;
376 item = (mailimap_msg_att_item*)current->data; 379 item = (mailimap_msg_att_item*)current->data;
377 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 380 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
378 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 381 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
379 if (!flist->att_list) { 382 if (!flist->att_list) {
380 continue; 383 continue;
381 } 384 }
382 cf = flist->att_list->first; 385 cf = flist->att_list->first;
383 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 386 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
384 cflag = (mailimap_flag_fetch*)cf->data; 387 cflag = (mailimap_flag_fetch*)cf->data;
385 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 388 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
386 switch (cflag->fl_flag->fl_type) { 389 switch (cflag->fl_flag->fl_type) {
387 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 390 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
388 mFlags.setBit(FLAG_ANSWERED); 391 mFlags.setBit(FLAG_ANSWERED);
389 break; 392 break;
390 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 393 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
391 mFlags.setBit(FLAG_FLAGGED); 394 mFlags.setBit(FLAG_FLAGGED);
392 break; 395 break;
393 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 396 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
394 mFlags.setBit(FLAG_DELETED); 397 mFlags.setBit(FLAG_DELETED);
395 break; 398 break;
396 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 399 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
397 mFlags.setBit(FLAG_SEEN); 400 mFlags.setBit(FLAG_SEEN);
398 break; 401 break;
399 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 402 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
400 mFlags.setBit(FLAG_DRAFT); 403 mFlags.setBit(FLAG_DRAFT);
401 break; 404 break;
402 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 405 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
403 break; 406 break;
404 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 407 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
405 break; 408 break;
406 default: 409 default:
407 break; 410 break;
408 } 411 }
409 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 412 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
410 mFlags.setBit(FLAG_RECENT); 413 mFlags.setBit(FLAG_RECENT);
411 } 414 }
412 } 415 }
413 continue; 416 continue;
414 } 417 }
415 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 418 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
416 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 419 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
417 m->setDate(head->env_date); 420 m->setDate(head->env_date);
418 m->setSubject(convert_String((const char*)head->env_subject)); 421 m->setSubject(convert_String((const char*)head->env_subject));
419 //m->setSubject(head->env_subject); 422 //m->setSubject(head->env_subject);
420 if (head->env_from!=NULL) { 423 if (head->env_from!=NULL) {
421 addresslist = address_list_to_stringlist(head->env_from->frm_list); 424 addresslist = address_list_to_stringlist(head->env_from->frm_list);
422 if (addresslist.count()) { 425 if (addresslist.count()) {
423 m->setFrom(addresslist.first()); 426 m->setFrom(addresslist.first());
424 } 427 }
425 } 428 }
426 if (head->env_to!=NULL) { 429 if (head->env_to!=NULL) {
427 addresslist = address_list_to_stringlist(head->env_to->to_list); 430 addresslist = address_list_to_stringlist(head->env_to->to_list);
428 m->setTo(addresslist); 431 m->setTo(addresslist);
429 } 432 }
430 if (head->env_cc!=NULL) { 433 if (head->env_cc!=NULL) {
431 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 434 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
432 m->setCC(addresslist); 435 m->setCC(addresslist);
433 } 436 }
434 if (head->env_bcc!=NULL) { 437 if (head->env_bcc!=NULL) {
435 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 438 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
436 m->setBcc(addresslist); 439 m->setBcc(addresslist);
437 } 440 }
438 /* reply to address, eg. email. */ 441 /* reply to address, eg. email. */
439 if (head->env_reply_to!=NULL) { 442 if (head->env_reply_to!=NULL) {
440 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 443 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
441 if (addresslist.count()) { 444 if (addresslist.count()) {
442 m->setReplyto(addresslist.first()); 445 m->setReplyto(addresslist.first());
443 } 446 }
444 } 447 }
445 if (head->env_in_reply_to!=NULL) { 448 if (head->env_in_reply_to!=NULL) {
446 QString h(head->env_in_reply_to); 449 QString h(head->env_in_reply_to);
447 while (h.length()>0 && h[0]=='<') { 450 while (h.length()>0 && h[0]=='<') {
448 h.remove(0,1); 451 h.remove(0,1);
449 } 452 }
450 while (h.length()>0 && h[h.length()-1]=='>') { 453 while (h.length()>0 && h[h.length()-1]=='>') {
451 h.remove(h.length()-1,1); 454 h.remove(h.length()-1,1);
452 } 455 }
453 if (h.length()>0) { 456 if (h.length()>0) {
454 m->setInreply(QStringList(h)); 457 m->setInreply(QStringList(h));
455 } 458 }
456 } 459 }
457 if (head->env_message_id) { 460 if (head->env_message_id) {
458 m->setMsgid(QString(head->env_message_id)); 461 m->setMsgid(QString(head->env_message_id));
459 } 462 }
460 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 463 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
461#if 0 464#if 0
462 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 465 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
463 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 466 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
464 //odebug << "" << d->dt_year << " " << d->dt_month << " " << d->dt_day << " - " << d->dt_hour << " " << d->dt_min << " " << d->dt_sec << "" << oendl; 467 //odebug << "" << d->dt_year << " " << d->dt_month << " " << d->dt_day << " - " << d->dt_hour << " " << d->dt_min << " " << d->dt_sec << "" << oendl;
465 //odebug << da.toString() << oendl; 468 //odebug << da.toString() << oendl;
466#endif 469#endif
467 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 470 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
468 size = item->att_data.att_static->att_data.att_rfc822_size; 471 size = item->att_data.att_static->att_data.att_rfc822_size;
469 } 472 }
470 } 473 }
471 /* msg is already deleted */ 474 /* msg is already deleted */
472 if (mFlags.testBit(FLAG_DELETED) && m) { 475 if (mFlags.testBit(FLAG_DELETED) && m) {
473 delete m; 476 delete m;
474 m = 0; 477 m = 0;
475 } 478 }
476 if (m) { 479 if (m) {
477 m->setFlags(mFlags); 480 m->setFlags(mFlags);
478 m->setMsgsize(size); 481 m->setMsgsize(size);
479 } 482 }
480 return m; 483 return m;
481} 484}
482 485
483RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) 486RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail)
484{ 487{
485 RecBodyP body = new RecBody(); 488 RecBodyP body = new RecBody();
486 const char *mb; 489 const char *mb;
487 int err = MAILIMAP_NO_ERROR; 490 int err = MAILIMAP_NO_ERROR;
488 clist *result = 0; 491 clist *result = 0;
489 clistcell *current; 492 clistcell *current;
490 mailimap_fetch_att *fetchAtt = 0; 493 mailimap_fetch_att *fetchAtt = 0;
491 mailimap_fetch_type *fetchType = 0; 494 mailimap_fetch_type *fetchType = 0;
492 mailimap_set *set = 0; 495 mailimap_set *set = 0;
493 mailimap_body*body_desc = 0; 496 mailimap_body*body_desc = 0;
494 497
495 mb = mail->getMbox().latin1(); 498 mb = mail->getMbox().latin1();
496 499
497 login(); 500 login();
498 if (!m_imap) { 501 if (!m_imap) {
499 return body; 502 return body;
500 } 503 }
501 err = selectMbox(mail->getMbox()); 504 err = selectMbox(mail->getMbox());
502 if ( err != MAILIMAP_NO_ERROR ) { 505 if ( err != MAILIMAP_NO_ERROR ) {
503 return body; 506 return body;
504 } 507 }
505 508
506 /* the range has to start at 1!!! not with 0!!!! */ 509 /* the range has to start at 1!!! not with 0!!!! */
507 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); 510 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() );
508 fetchAtt = mailimap_fetch_att_new_bodystructure(); 511 fetchAtt = mailimap_fetch_att_new_bodystructure();
509 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 512 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
510 err = mailimap_fetch( m_imap, set, fetchType, &result ); 513 err = mailimap_fetch( m_imap, set, fetchType, &result );
511 mailimap_set_free( set ); 514 mailimap_set_free( set );
512 mailimap_fetch_type_free( fetchType ); 515 mailimap_fetch_type_free( fetchType );
513 516
514 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 517 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
515 mailimap_msg_att * msg_att; 518 mailimap_msg_att * msg_att;
516 msg_att = (mailimap_msg_att*)current->data; 519 msg_att = (mailimap_msg_att*)current->data;
517 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 520 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
518 QValueList<int> path; 521 QValueList<int> path;
519 body_desc = item->att_data.att_static->att_data.att_body; 522 body_desc = item->att_data.att_static->att_data.att_body;
520 traverseBody(mail,body_desc,body,0,path); 523 traverseBody(mail,body_desc,body,0,path);
521 } else { 524 } else {
522 //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; 525 //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl;
523 } 526 }
524 if (result) mailimap_fetch_list_free(result); 527 if (result) mailimap_fetch_list_free(result);
525 return body; 528 return body;
526} 529}
527 530
528QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 531QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
529{ 532{
530 QStringList l; 533 QStringList l;
531 QString from; 534 QString from;
532 bool named_from; 535 bool named_from;
533 clistcell *current = NULL; 536 clistcell *current = NULL;
534 mailimap_address * current_address=NULL; 537 mailimap_address * current_address=NULL;
535 if (!list) { 538 if (!list) {
536 return l; 539 return l;
537 } 540 }
538 unsigned int count = 0; 541 unsigned int count = 0;
539 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 542 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
540 from = ""; 543 from = "";
541 named_from = false; 544 named_from = false;
542 current_address=(mailimap_address*)current->data; 545 current_address=(mailimap_address*)current->data;
543 if (current_address->ad_personal_name){ 546 if (current_address->ad_personal_name){
544 from+=convert_String((const char*)current_address->ad_personal_name); 547 from+=convert_String((const char*)current_address->ad_personal_name);
545 from+=" "; 548 from+=" ";
546 named_from = true; 549 named_from = true;
547 } 550 }
548 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 551 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
549 from+="<"; 552 from+="<";
550 } 553 }
551 if (current_address->ad_mailbox_name) { 554 if (current_address->ad_mailbox_name) {
552 from+=QString(current_address->ad_mailbox_name); 555 from+=QString(current_address->ad_mailbox_name);
553 from+="@"; 556 from+="@";
554 } 557 }
555 if (current_address->ad_host_name) { 558 if (current_address->ad_host_name) {
556 from+=QString(current_address->ad_host_name); 559 from+=QString(current_address->ad_host_name);
557 } 560 }
558 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 561 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
559 from+=">"; 562 from+=">";
560 } 563 }
561 l.append(QString(from)); 564 l.append(QString(from));
562 if (++count > 99) { 565 if (++count > 99) {
563 break; 566 break;
564 } 567 }
565 } 568 }
566 return l; 569 return l;
567} 570}
568 571
569encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) 572encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call)
570{ 573{
571 encodedString*res=new encodedString; 574 encodedString*res=new encodedString;
572 int err; 575 int err;
573 mailimap_fetch_type *fetchType; 576 mailimap_fetch_type *fetchType;
574 mailimap_set *set; 577 mailimap_set *set;
575 clistcell*current,*cur; 578 clistcell*current,*cur;
576 mailimap_section_part * section_part = 0; 579 mailimap_section_part * section_part = 0;
577 mailimap_section_spec * section_spec = 0; 580 mailimap_section_spec * section_spec = 0;
578 mailimap_section * section = 0; 581 mailimap_section * section = 0;
579 mailimap_fetch_att * fetch_att = 0; 582 mailimap_fetch_att * fetch_att = 0;
580 583
581 login(); 584 login();
582 if (!m_imap) { 585 if (!m_imap) {
583 return res; 586 return res;
584 } 587 }
585 if (!internal_call) { 588 if (!internal_call) {
586 err = selectMbox(mail->getMbox()); 589 err = selectMbox(mail->getMbox());
587 if ( err != MAILIMAP_NO_ERROR ) { 590 if ( err != MAILIMAP_NO_ERROR ) {
588 return res; 591 return res;
589 } 592 }
590 } 593 }
591 set = mailimap_set_new_single(mail->getNumber()); 594 set = mailimap_set_new_single(mail->getNumber());
592 595
593 clist*id_list = 0; 596 clist*id_list = 0;
594 597
595 /* if path == empty then its a request for the whole rfc822 mail and generates 598 /* if path == empty then its a request for the whole rfc822 mail and generates
596 a "fetch <id> (body[])" statement on imap server */ 599 a "fetch <id> (body[])" statement on imap server */
597 if (path.count()>0 ) { 600 if (path.count()>0 ) {
598 id_list = clist_new(); 601 id_list = clist_new();
599 for (unsigned j=0; j < path.count();++j) { 602 for (unsigned j=0; j < path.count();++j) {
600 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 603 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
601 *p_id = path[j]; 604 *p_id = path[j];
602 clist_append(id_list,p_id); 605 clist_append(id_list,p_id);
603 } 606 }
604 section_part = mailimap_section_part_new(id_list); 607 section_part = mailimap_section_part_new(id_list);
605 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 608 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
606 } 609 }
607 610
608 section = mailimap_section_new(section_spec); 611 section = mailimap_section_new(section_spec);
609 fetch_att = mailimap_fetch_att_new_body_section(section); 612 fetch_att = mailimap_fetch_att_new_body_section(section);
610 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 613 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
611 614
612 clist*result = 0; 615 clist*result = 0;
613 616
614 err = mailimap_fetch( m_imap, set, fetchType, &result ); 617 err = mailimap_fetch( m_imap, set, fetchType, &result );
615 mailimap_set_free( set ); 618 mailimap_set_free( set );
616 mailimap_fetch_type_free( fetchType ); 619 mailimap_fetch_type_free( fetchType );
617 620
618 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 621 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
619 mailimap_msg_att * msg_att; 622 mailimap_msg_att * msg_att;
620 msg_att = (mailimap_msg_att*)current->data; 623 msg_att = (mailimap_msg_att*)current->data;
621 mailimap_msg_att_item*msg_att_item; 624 mailimap_msg_att_item*msg_att_item;
622 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 625 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
623 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 626 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
624 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 627 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
625 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 628 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
626 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 629 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
627 /* detach - we take over the content */ 630 /* detach - we take over the content */
628 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 631 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
629 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 632 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
630 } 633 }
631 } 634 }
632 } 635 }
633 } else { 636 } else {
634 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; 637 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl;
635 } 638 }
636 if (result) mailimap_fetch_list_free(result); 639 if (result) mailimap_fetch_list_free(result);
637 return res; 640 return res;
638} 641}
639 642
640/* current_recursion is for recursive calls. 643/* current_recursion is for recursive calls.
641 current_count means the position inside the internal loop! */ 644 current_count means the position inside the internal loop! */
642void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, 645void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,
643 int current_recursion,QValueList<int>recList,int current_count) 646 int current_recursion,QValueList<int>recList,int current_count)
644{ 647{
645 if (!body || current_recursion>=10) { 648 if (!body || current_recursion>=10) {
646 return; 649 return;
647 } 650 }
648 switch (body->bd_type) { 651 switch (body->bd_type) {
649 case MAILIMAP_BODY_1PART: 652 case MAILIMAP_BODY_1PART:
650 { 653 {
651 QValueList<int>countlist = recList; 654 QValueList<int>countlist = recList;
652 countlist.append(current_count); 655 countlist.append(current_count);
653 RecPartP currentPart = new RecPart(); 656 RecPartP currentPart = new RecPart();
654 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 657 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
655 QString id(""); 658 QString id("");
656 currentPart->setPositionlist(countlist); 659 currentPart->setPositionlist(countlist);
657 for (unsigned int j = 0; j < countlist.count();++j) { 660 for (unsigned int j = 0; j < countlist.count();++j) {
658 id+=(j>0?" ":""); 661 id+=(j>0?" ":"");
659 id+=QString("%1").arg(countlist[j]); 662 id+=QString("%1").arg(countlist[j]);
660 } 663 }
661 //odebug << "ID = " << id.latin1() << "" << oendl; 664 //odebug << "ID = " << id.latin1() << "" << oendl;
662 currentPart->setIdentifier(id); 665 currentPart->setIdentifier(id);
663 fillSinglePart(currentPart,part1); 666 fillSinglePart(currentPart,part1);
664 /* important: Check for is NULL 'cause a body can be empty! 667 /* important: Check for is NULL 'cause a body can be empty!
665 And we put it only into the mail if it is the FIRST part */ 668 And we put it only into the mail if it is the FIRST part */
666 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { 669 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) {
667 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); 670 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding());
668 target_body->setDescription(currentPart); 671 target_body->setDescription(currentPart);
669 target_body->setBodytext(body_text); 672 target_body->setBodytext(body_text);
670 if (countlist.count()>1) { 673 if (countlist.count()>1) {
671 target_body->addPart(currentPart); 674 target_body->addPart(currentPart);
672 } 675 }
673 } else { 676 } else {
674 target_body->addPart(currentPart); 677 target_body->addPart(currentPart);
675 } 678 }
676 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 679 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
677 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 680 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
678 } 681 }
679 } 682 }
680 break; 683 break;
681 case MAILIMAP_BODY_MPART: 684 case MAILIMAP_BODY_MPART:
682 { 685 {
683 QValueList<int>countlist = recList; 686 QValueList<int>countlist = recList;
684 clistcell*current=0; 687 clistcell*current=0;
685 mailimap_body*current_body=0; 688 mailimap_body*current_body=0;
686 unsigned int ccount = 1; 689 unsigned int ccount = 1;
687 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 690 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
688 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 691 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
689 current_body = (mailimap_body*)current->data; 692 current_body = (mailimap_body*)current->data;
690 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 693 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
691 RecPartP targetPart = new RecPart(); 694 RecPartP targetPart = new RecPart();
692 targetPart->setType("multipart"); 695 targetPart->setType("multipart");
693 fillMultiPart(targetPart,mailDescription); 696 fillMultiPart(targetPart,mailDescription);
694 countlist.append(current_count); 697 countlist.append(current_count);
695 targetPart->setPositionlist(countlist); 698 targetPart->setPositionlist(countlist);
696 target_body->addPart(targetPart); 699 target_body->addPart(targetPart);
697 QString id(""); 700 QString id("");
698 for (unsigned int j = 0; j < countlist.count();++j) { 701 for (unsigned int j = 0; j < countlist.count();++j) {
699 id+=(j>0?" ":""); 702 id+=(j>0?" ":"");
700 id+=QString("%1").arg(countlist[j]); 703 id+=QString("%1").arg(countlist[j]);
701 } 704 }
702 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; 705 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl;
703 } 706 }
704 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 707 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
705 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 708 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
706 countlist = recList; 709 countlist = recList;
707 } 710 }
708 ++ccount; 711 ++ccount;
709 } 712 }
710 } 713 }
711 break; 714 break;
712 default: 715 default:
713 break; 716 break;
714 } 717 }
715} 718}
716 719
717void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) 720void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description)
718{ 721{
719 if (!Description) { 722 if (!Description) {
720 return; 723 return;
721 } 724 }
722 switch (Description->bd_type) { 725 switch (Description->bd_type) {
723 case MAILIMAP_BODY_TYPE_1PART_TEXT: 726 case MAILIMAP_BODY_TYPE_1PART_TEXT:
724 target_part->setType("text"); 727 target_part->setType("text");
725 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 728 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
726 break; 729 break;
727 case MAILIMAP_BODY_TYPE_1PART_BASIC: 730 case MAILIMAP_BODY_TYPE_1PART_BASIC:
728 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 731 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
729 break; 732 break;
730 case MAILIMAP_BODY_TYPE_1PART_MSG: 733 case MAILIMAP_BODY_TYPE_1PART_MSG:
731 target_part->setType("message"); 734 target_part->setType("message");
732 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 735 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
733 break; 736 break;
734 default: 737 default:
735 break; 738 break;
736 } 739 }
737} 740}
738 741
739void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) 742void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which)
740{ 743{
741 if (!which) { 744 if (!which) {
742 return; 745 return;
743 } 746 }
744 QString sub; 747 QString sub;
745 sub = which->bd_media_text; 748 sub = which->bd_media_text;
746 //odebug << "Type= text/" << which->bd_media_text << "" << oendl; 749 //odebug << "Type= text/" << which->bd_media_text << "" << oendl;
747 target_part->setSubtype(sub.lower()); 750 target_part->setSubtype(sub.lower());
748 target_part->setLines(which->bd_lines); 751 target_part->setLines(which->bd_lines);
749 fillBodyFields(target_part,which->bd_fields); 752 fillBodyFields(target_part,which->bd_fields);
750} 753}
751 754
752void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) 755void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which)
753{ 756{
754 if (!which) { 757 if (!which) {
755 return; 758 return;
756 } 759 }
757 target_part->setSubtype("rfc822"); 760 target_part->setSubtype("rfc822");
758 //odebug << "Message part" << oendl; 761 //odebug << "Message part" << oendl;
759 /* we set this type to text/plain */ 762 /* we set this type to text/plain */
760 target_part->setLines(which->bd_lines); 763 target_part->setLines(which->bd_lines);
761 fillBodyFields(target_part,which->bd_fields); 764 fillBodyFields(target_part,which->bd_fields);
762} 765}
763 766
764void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) 767void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which)
765{ 768{
766 if (!which) return; 769 if (!which) return;
767 QString sub = which->bd_media_subtype; 770 QString sub = which->bd_media_subtype;
768 target_part->setSubtype(sub.lower()); 771 target_part->setSubtype(sub.lower());
769 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { 772 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
770 clistcell*cur = 0; 773 clistcell*cur = 0;
771 mailimap_single_body_fld_param*param=0; 774 mailimap_single_body_fld_param*param=0;
772 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 775 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
773 param = (mailimap_single_body_fld_param*)cur->data; 776 param = (mailimap_single_body_fld_param*)cur->data;
774 if (param) { 777 if (param) {
775 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 778 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
776 } 779 }
777 } 780 }
778 } 781 }
779} 782}
780 783
781void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) 784void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which)
782{ 785{
783 if (!which) { 786 if (!which) {
784 return; 787 return;
785 } 788 }
786 QString type,sub; 789 QString type,sub;
787 switch (which->bd_media_basic->med_type) { 790 switch (which->bd_media_basic->med_type) {
788 case MAILIMAP_MEDIA_BASIC_APPLICATION: 791 case MAILIMAP_MEDIA_BASIC_APPLICATION:
789 type = "application"; 792 type = "application";
790 break; 793 break;
791 case MAILIMAP_MEDIA_BASIC_AUDIO: 794 case MAILIMAP_MEDIA_BASIC_AUDIO:
792 type = "audio"; 795 type = "audio";
793 break; 796 break;
794 case MAILIMAP_MEDIA_BASIC_IMAGE: 797 case MAILIMAP_MEDIA_BASIC_IMAGE:
795 type = "image"; 798 type = "image";
796 break; 799 break;
797 case MAILIMAP_MEDIA_BASIC_MESSAGE: 800 case MAILIMAP_MEDIA_BASIC_MESSAGE:
798 type = "message"; 801 type = "message";
799 break; 802 break;
800 case MAILIMAP_MEDIA_BASIC_VIDEO: 803 case MAILIMAP_MEDIA_BASIC_VIDEO:
801 type = "video"; 804 type = "video";
802 break; 805 break;
803 case MAILIMAP_MEDIA_BASIC_OTHER: 806 case MAILIMAP_MEDIA_BASIC_OTHER:
804 default: 807 default:
805 if (which->bd_media_basic->med_basic_type) { 808 if (which->bd_media_basic->med_basic_type) {
806 type = which->bd_media_basic->med_basic_type; 809 type = which->bd_media_basic->med_basic_type;
807 } else { 810 } else {
808 type = ""; 811 type = "";
809 } 812 }
810 break; 813 break;
811 } 814 }
812 if (which->bd_media_basic->med_subtype) { 815 if (which->bd_media_basic->med_subtype) {
813 sub = which->bd_media_basic->med_subtype; 816 sub = which->bd_media_basic->med_subtype;
814 } else { 817 } else {
815 sub = ""; 818 sub = "";
816 } 819 }
817 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; 820 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl;
818 target_part->setType(type.lower()); 821 target_part->setType(type.lower());
819 target_part->setSubtype(sub.lower()); 822 target_part->setSubtype(sub.lower());
820 fillBodyFields(target_part,which->bd_fields); 823 fillBodyFields(target_part,which->bd_fields);
821} 824}
822 825
823void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) 826void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which)
824{ 827{
825 if (!which) return; 828 if (!which) return;
826 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 829 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
827 clistcell*cur; 830 clistcell*cur;
828 mailimap_single_body_fld_param*param=0; 831 mailimap_single_body_fld_param*param=0;
829 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 832 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
830 param = (mailimap_single_body_fld_param*)cur->data; 833 param = (mailimap_single_body_fld_param*)cur->data;
831 if (param) { 834 if (param) {
832 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 835 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
833 } 836 }
834 } 837 }
835 } 838 }
836 mailimap_body_fld_enc*enc = which->bd_encoding; 839 mailimap_body_fld_enc*enc = which->bd_encoding;
837 QString encoding(""); 840 QString encoding("");
838 switch (enc->enc_type) { 841 switch (enc->enc_type) {
839 case MAILIMAP_BODY_FLD_ENC_7BIT: 842 case MAILIMAP_BODY_FLD_ENC_7BIT:
840 encoding = "7bit"; 843 encoding = "7bit";
841 break; 844 break;
842 case MAILIMAP_BODY_FLD_ENC_8BIT: 845 case MAILIMAP_BODY_FLD_ENC_8BIT:
843 encoding = "8bit"; 846 encoding = "8bit";
844 break; 847 break;
845 case MAILIMAP_BODY_FLD_ENC_BINARY: 848 case MAILIMAP_BODY_FLD_ENC_BINARY:
846 encoding="binary"; 849 encoding="binary";
847 break; 850 break;
848 case MAILIMAP_BODY_FLD_ENC_BASE64: 851 case MAILIMAP_BODY_FLD_ENC_BASE64:
849 encoding="base64"; 852 encoding="base64";
850 break; 853 break;
851 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 854 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
852 encoding="quoted-printable"; 855 encoding="quoted-printable";
853 break; 856 break;
854 case MAILIMAP_BODY_FLD_ENC_OTHER: 857 case MAILIMAP_BODY_FLD_ENC_OTHER:
855 default: 858 default:
856 if (enc->enc_value) { 859 if (enc->enc_value) {
857 char*t=enc->enc_value; 860 char*t=enc->enc_value;
858 encoding=QString(enc->enc_value); 861 encoding=QString(enc->enc_value);
859 enc->enc_value=0L; 862 enc->enc_value=0L;
860 free(t); 863 free(t);
861 } 864 }
862 } 865 }
863 if (which->bd_description) { 866 if (which->bd_description) {
864 target_part->setDescription(QString(which->bd_description)); 867 target_part->setDescription(QString(which->bd_description));
865 } 868 }
866 target_part->setEncoding(encoding); 869 target_part->setEncoding(encoding);
867 target_part->setSize(which->bd_size); 870 target_part->setSize(which->bd_size);
868} 871}
872void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target)
873{
874 mailimap_flag_list*flist;
875 mailimap_set *set;
876 mailimap_store_att_flags * store_flags;
877 int err;
878 login();
879 if (!m_imap) {
880 return;
881 }
882 int iii = 0;
883 int count = target.count();
884 qDebug("imap remove count %d ", count);
885 while (iii < count ) {
886 qDebug("IMAP remove %d ", iii);
887 RecMailP mail = (*target.at( iii ));
869 888
889 err = selectMbox(mail->getMbox());
890 if ( err != MAILIMAP_NO_ERROR ) {
891 return;
892 }
893 flist = mailimap_flag_list_new_empty();
894 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
895 store_flags = mailimap_store_att_flags_new_set_flags(flist);
896 set = mailimap_set_new_single(mail->getNumber());
897 err = mailimap_store(m_imap,set,store_flags);
898 mailimap_set_free( set );
899 mailimap_store_att_flags_free(store_flags);
900
901 if (err != MAILIMAP_NO_ERROR) {
902 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
903 return;
904 }
905 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
906 /* should we realy do that at this moment? */
907
908 err = mailimap_expunge(m_imap);
909 if (err != MAILIMAP_NO_ERROR) {
910 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
911 }
912 ++iii;
913 }
914}
870void IMAPwrapper::deleteMail(const RecMailP&mail) 915void IMAPwrapper::deleteMail(const RecMailP&mail)
871{ 916{
872 mailimap_flag_list*flist; 917 mailimap_flag_list*flist;
873 mailimap_set *set; 918 mailimap_set *set;
874 mailimap_store_att_flags * store_flags; 919 mailimap_store_att_flags * store_flags;
875 int err; 920 int err;
876 login(); 921 login();
877 if (!m_imap) { 922 if (!m_imap) {
878 return; 923 return;
879 } 924 }
880 err = selectMbox(mail->getMbox()); 925 err = selectMbox(mail->getMbox());
881 if ( err != MAILIMAP_NO_ERROR ) { 926 if ( err != MAILIMAP_NO_ERROR ) {
882 return; 927 return;
883 } 928 }
884 flist = mailimap_flag_list_new_empty(); 929 flist = mailimap_flag_list_new_empty();
885 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 930 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
886 store_flags = mailimap_store_att_flags_new_set_flags(flist); 931 store_flags = mailimap_store_att_flags_new_set_flags(flist);
887 set = mailimap_set_new_single(mail->getNumber()); 932 set = mailimap_set_new_single(mail->getNumber());
888 err = mailimap_store(m_imap,set,store_flags); 933 err = mailimap_store(m_imap,set,store_flags);
889 mailimap_set_free( set ); 934 mailimap_set_free( set );
890 mailimap_store_att_flags_free(store_flags); 935 mailimap_store_att_flags_free(store_flags);
891 936
892 if (err != MAILIMAP_NO_ERROR) { 937 if (err != MAILIMAP_NO_ERROR) {
893 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 938 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
894 return; 939 return;
895 } 940 }
896 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 941 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
897 /* should we realy do that at this moment? */ 942 /* should we realy do that at this moment? */
943
898 err = mailimap_expunge(m_imap); 944 err = mailimap_expunge(m_imap);
899 if (err != MAILIMAP_NO_ERROR) { 945 if (err != MAILIMAP_NO_ERROR) {
900 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 946 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
901 } 947 }
902 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; 948 qDebug("IMAPwrapper::deleteMail ");
949
903} 950}
904 951
905void IMAPwrapper::answeredMail(const RecMailP&mail) 952void IMAPwrapper::answeredMail(const RecMailP&mail)
906{ 953{
907 mailimap_flag_list*flist; 954 mailimap_flag_list*flist;
908 mailimap_set *set; 955 mailimap_set *set;
909 mailimap_store_att_flags * store_flags; 956 mailimap_store_att_flags * store_flags;
910 int err; 957 int err;
911 login(); 958 login();
912 if (!m_imap) { 959 if (!m_imap) {
913 return; 960 return;
914 } 961 }
915 err = selectMbox(mail->getMbox()); 962 err = selectMbox(mail->getMbox());
916 if ( err != MAILIMAP_NO_ERROR ) { 963 if ( err != MAILIMAP_NO_ERROR ) {
917 return; 964 return;
918 } 965 }
919 flist = mailimap_flag_list_new_empty(); 966 flist = mailimap_flag_list_new_empty();
920 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 967 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
921 store_flags = mailimap_store_att_flags_new_add_flags(flist); 968 store_flags = mailimap_store_att_flags_new_add_flags(flist);
922 set = mailimap_set_new_single(mail->getNumber()); 969 set = mailimap_set_new_single(mail->getNumber());
923 err = mailimap_store(m_imap,set,store_flags); 970 err = mailimap_store(m_imap,set,store_flags);
924 mailimap_set_free( set ); 971 mailimap_set_free( set );
925 mailimap_store_att_flags_free(store_flags); 972 mailimap_store_att_flags_free(store_flags);
926 973
927 if (err != MAILIMAP_NO_ERROR) { 974 if (err != MAILIMAP_NO_ERROR) {
928 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; 975 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl;
929 return; 976 return;
930 } 977 }
931} 978}
932 979
933QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 980QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
934{ 981{
935 QString body(""); 982 QString body("");
936 encodedString*res = fetchRawPart(mail,path,internal_call); 983 encodedString*res = fetchRawPart(mail,path,internal_call);
937 encodedString*r = decode_String(res,enc); 984 encodedString*r = decode_String(res,enc);
938 delete res; 985 delete res;
939 if (r) { 986 if (r) {
940 if (r->Length()>0) { 987 if (r->Length()>0) {
941 body = r->Content(); 988 body = r->Content();
942 } 989 }
943 delete r; 990 delete r;
944 } 991 }
945 return body; 992 return body;
946} 993}
947 994
948QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 995QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
949{ 996{
950 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); 997 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding());
951} 998}
952 999
953encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) 1000encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part)
954{ 1001{
955 encodedString*res = fetchRawPart(mail,part->Positionlist(),false); 1002 encodedString*res = fetchRawPart(mail,part->Positionlist(),false);
956 encodedString*r = decode_String(res,part->Encoding()); 1003 encodedString*r = decode_String(res,part->Encoding());
957 delete res; 1004 delete res;
958 return r; 1005 return r;
959} 1006}
960 1007
961encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) 1008encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part)
962{ 1009{
963 return fetchRawPart(mail,part->Positionlist(),false); 1010 return fetchRawPart(mail,part->Positionlist(),false);
964} 1011}
965 1012
966int IMAPwrapper::deleteAllMail(const FolderP&folder) 1013int IMAPwrapper::deleteAllMail(const FolderP&folder)
967{ 1014{
968 login(); 1015 login();
969 if (!m_imap) { 1016 if (!m_imap) {
970 return 0; 1017 return 0;
971 } 1018 }
972 mailimap_flag_list*flist; 1019 mailimap_flag_list*flist;
973 mailimap_set *set; 1020 mailimap_set *set;
974 mailimap_store_att_flags * store_flags; 1021 mailimap_store_att_flags * store_flags;
975 int err = selectMbox(folder->getName()); 1022 int err = selectMbox(folder->getName());
976 if ( err != MAILIMAP_NO_ERROR ) { 1023 if ( err != MAILIMAP_NO_ERROR ) {
977 return 0; 1024 return 0;
978 } 1025 }
979 1026
980 int last = m_imap->imap_selection_info->sel_exists; 1027 int last = m_imap->imap_selection_info->sel_exists;
981 if (last == 0) { 1028 if (last == 0) {
982 Global::statusMessage(tr("Mailbox has no mails!")); 1029 Global::statusMessage(tr("Mailbox has no mails!"));
983 return 0; 1030 return 0;
984 } 1031 }
985 flist = mailimap_flag_list_new_empty(); 1032 flist = mailimap_flag_list_new_empty();
986 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1033 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
987 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1034 store_flags = mailimap_store_att_flags_new_set_flags(flist);
988 set = mailimap_set_new_interval( 1, last ); 1035 set = mailimap_set_new_interval( 1, last );
989 err = mailimap_store(m_imap,set,store_flags); 1036 err = mailimap_store(m_imap,set,store_flags);
990 mailimap_set_free( set ); 1037 mailimap_set_free( set );
991 mailimap_store_att_flags_free(store_flags); 1038 mailimap_store_att_flags_free(store_flags);
992 if (err != MAILIMAP_NO_ERROR) { 1039 if (err != MAILIMAP_NO_ERROR) {
993 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1040 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
994 return 0; 1041 return 0;
995 } 1042 }
996 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1043 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
997 /* should we realy do that at this moment? */ 1044 /* should we realy do that at this moment? */
998 err = mailimap_expunge(m_imap); 1045 err = mailimap_expunge(m_imap);
999 if (err != MAILIMAP_NO_ERROR) { 1046 if (err != MAILIMAP_NO_ERROR) {
1000 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1047 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
1001 return 0; 1048 return 0;
1002 } 1049 }
1003 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; 1050 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl;
1004 return 1; 1051 return 1;
1005} 1052}
1006 1053
1007int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) 1054int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder)
1008{ 1055{
1009 if (folder.length()==0) return 0; 1056 if (folder.length()==0) return 0;
1010 login(); 1057 login();
1011 if (!m_imap) {return 0;} 1058 if (!m_imap) {return 0;}
1012 QString pre = account->getPrefix(); 1059 QString pre = account->getPrefix();
1013 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 1060 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
1014 pre+=delemiter; 1061 pre+=delemiter;
1015 } 1062 }
1016 if (parentfolder) { 1063 if (parentfolder) {
1017 pre += parentfolder->getDisplayName()+delemiter; 1064 pre += parentfolder->getDisplayName()+delemiter;
1018 } 1065 }
1019 pre+=folder; 1066 pre+=folder;
1020 if (getsubfolder) { 1067 if (getsubfolder) {
1021 if (delemiter.length()>0) { 1068 if (delemiter.length()>0) {
1022 pre+=delemiter; 1069 pre+=delemiter;
1023 } else { 1070 } else {
1024 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); 1071 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
1025 return 0; 1072 return 0;
1026 } 1073 }
1027 } 1074 }
1028 // odebug << "Creating " << pre.latin1() << "" << oendl; 1075 // odebug << "Creating " << pre.latin1() << "" << oendl;
1029 int res = mailimap_create(m_imap,pre.latin1()); 1076 int res = mailimap_create(m_imap,pre.latin1());
1030 if (res != MAILIMAP_NO_ERROR) { 1077 if (res != MAILIMAP_NO_ERROR) {
1031 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1078 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
1032 return 0; 1079 return 0;
1033 } 1080 }
1034 return 1; 1081 return 1;
1035} 1082}
1036 1083
1037int IMAPwrapper::deleteMbox(const FolderP&folder) 1084int IMAPwrapper::deleteMbox(const FolderP&folder)
1038{ 1085{
1039 if (!folder) return 0; 1086 if (!folder) return 0;
1040 login(); 1087 login();
1041 if (!m_imap) {return 0;} 1088 if (!m_imap) {return 0;}
1042 int res = mailimap_delete(m_imap,folder->getName()); 1089 int res = mailimap_delete(m_imap,folder->getName());
1043 if (res != MAILIMAP_NO_ERROR) { 1090 if (res != MAILIMAP_NO_ERROR) {
1044 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1091 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
1045 return 0; 1092 return 0;
1046 } 1093 }
1047 return 1; 1094 return 1;
1048} 1095}
1049 1096
1050void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 1097void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
1051{ 1098{
1052 mailimap_status_att_list * att_list =0; 1099 mailimap_status_att_list * att_list =0;
1053 mailimap_mailbox_data_status * status=0; 1100 mailimap_mailbox_data_status * status=0;
1054 clistiter * cur = 0; 1101 clistiter * cur = 0;
1055 int r = 0; 1102 int r = 0;
1056 target_stat.message_count = 0; 1103 target_stat.message_count = 0;
1057 target_stat.message_unseen = 0; 1104 target_stat.message_unseen = 0;
1058 target_stat.message_recent = 0; 1105 target_stat.message_recent = 0;
1059 login(); 1106 login();
1060 if (!m_imap) { 1107 if (!m_imap) {
1061 return; 1108 return;
1062 } 1109 }
1063 att_list = mailimap_status_att_list_new_empty(); 1110 att_list = mailimap_status_att_list_new_empty();
1064 if (!att_list) return; 1111 if (!att_list) return;
1065 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 1112 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
1066 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 1113 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
1067 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 1114 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
1068 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 1115 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
1069 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { 1116 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
1070 for (cur = clist_begin(status->st_info_list); 1117 for (cur = clist_begin(status->st_info_list);
1071 cur != NULL ; cur = clist_next(cur)) { 1118 cur != NULL ; cur = clist_next(cur)) {
1072 mailimap_status_info * status_info; 1119 mailimap_status_info * status_info;
1073 status_info = (mailimap_status_info *)clist_content(cur); 1120 status_info = (mailimap_status_info *)clist_content(cur);
1074 switch (status_info->st_att) { 1121 switch (status_info->st_att) {
1075 case MAILIMAP_STATUS_ATT_MESSAGES: 1122 case MAILIMAP_STATUS_ATT_MESSAGES:
1076 target_stat.message_count = status_info->st_value; 1123 target_stat.message_count = status_info->st_value;
1077 break; 1124 break;
1078 case MAILIMAP_STATUS_ATT_RECENT: 1125 case MAILIMAP_STATUS_ATT_RECENT:
1079 target_stat.message_recent = status_info->st_value; 1126 target_stat.message_recent = status_info->st_value;
1080 break; 1127 break;
1081 case MAILIMAP_STATUS_ATT_UNSEEN: 1128 case MAILIMAP_STATUS_ATT_UNSEEN:
1082 target_stat.message_unseen = status_info->st_value; 1129 target_stat.message_unseen = status_info->st_value;
1083 break; 1130 break;
1084 } 1131 }
1085 } 1132 }
1086 } else { 1133 } else {
1087 // odebug << "Error retrieving status" << oendl; 1134 // odebug << "Error retrieving status" << oendl;
1088 } 1135 }
1089 if (status) mailimap_mailbox_data_status_free(status); 1136 if (status) mailimap_mailbox_data_status_free(status);
1090 if (att_list) mailimap_status_att_list_free(att_list); 1137 if (att_list) mailimap_status_att_list_free(att_list);
1091} 1138}
1092 1139
1093void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 1140void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
1094{ 1141{
1095 login(); 1142 login();
1096 if (!m_imap) return; 1143 if (!m_imap) return;
1097 if (!msg) return; 1144 if (!msg) return;
1098 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 1145 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
1099 if (r != MAILIMAP_NO_ERROR) { 1146 if (r != MAILIMAP_NO_ERROR) {
1100 Global::statusMessage("Error storing mail!"); 1147 Global::statusMessage("Error storing mail!");
1101 } 1148 }
1102} 1149}
1103 1150
1104MAILLIB::ATYPE IMAPwrapper::getType()const 1151MAILLIB::ATYPE IMAPwrapper::getType()const
1105{ 1152{
1106 return account->getType(); 1153 return account->getType();
1107} 1154}
1108 1155
1109const QString&IMAPwrapper::getName()const 1156const QString&IMAPwrapper::getName()const
1110{ 1157{
1111 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; 1158 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl;
1112 return account->getAccountName(); 1159 return account->getAccountName();
1113} 1160}
1114 1161
1115encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) 1162encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail)
1116{ 1163{
1117 // dummy 1164 // dummy
1118 QValueList<int> path; 1165 QValueList<int> path;
1119 return fetchRawPart(mail,path,false); 1166 return fetchRawPart(mail,path,false);
1120} 1167}
1121 1168
1122void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, 1169void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder,
1123 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 1170 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
1124{ 1171{
1125 if (targetWrapper != this) { 1172 if (targetWrapper != this || maxSizeInKb > 0 ) {
1126 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); 1173 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb);
1174 qDebug("IMAPwrapper::mvcpAllMails::Using generic");
1127 // odebug << "Using generic" << oendl; 1175 // odebug << "Using generic" << oendl;
1128 return; 1176 return;
1129 } 1177 }
1130 mailimap_set *set = 0; 1178 mailimap_set *set = 0;
1131 login(); 1179 login();
1132 if (!m_imap) { 1180 if (!m_imap) {
1133 return; 1181 return;
1134 } 1182 }
1135 int err = selectMbox(fromFolder->getName()); 1183 int err = selectMbox(fromFolder->getName());
1136 if ( err != MAILIMAP_NO_ERROR ) { 1184 if ( err != MAILIMAP_NO_ERROR ) {
1137 return; 1185 return;
1138 } 1186 }
1139 int last = m_imap->imap_selection_info->sel_exists; 1187 int last = m_imap->imap_selection_info->sel_exists;
1140 set = mailimap_set_new_interval( 1, last ); 1188 set = mailimap_set_new_interval( 1, last );
1141 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1189 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1142 mailimap_set_free( set ); 1190 mailimap_set_free( set );
1143 if ( err != MAILIMAP_NO_ERROR ) { 1191 if ( err != MAILIMAP_NO_ERROR ) {
1144 QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); 1192 QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response);
1145 Global::statusMessage(error_msg); 1193 Global::statusMessage(error_msg);
1146 // odebug << error_msg << oendl; 1194 // odebug << error_msg << oendl;
1147 return; 1195 return;
1148 } 1196 }
1149 if (moveit) { 1197 if (moveit) {
1150 deleteAllMail(fromFolder); 1198 deleteAllMail(fromFolder);
1151 } 1199 }
1152} 1200}
1153 1201
1154void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 1202void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
1155{ 1203{
1156 if (targetWrapper != this) { 1204 if (targetWrapper != this) {
1157 // odebug << "Using generic" << oendl; 1205 // odebug << "Using generic" << oendl;
1158 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); 1206 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit);
1159 return; 1207 return;
1160 } 1208 }
1161 mailimap_set *set = 0; 1209 mailimap_set *set = 0;
1162 login(); 1210 login();
1163 if (!m_imap) { 1211 if (!m_imap) {
1164 return; 1212 return;
1165 } 1213 }
1166 int err = selectMbox(mail->getMbox()); 1214 int err = selectMbox(mail->getMbox());
1167 if ( err != MAILIMAP_NO_ERROR ) { 1215 if ( err != MAILIMAP_NO_ERROR ) {
1168 return; 1216 return;
1169 } 1217 }
1170 set = mailimap_set_new_single(mail->getNumber()); 1218 set = mailimap_set_new_single(mail->getNumber());
1171 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1219 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1172 mailimap_set_free( set ); 1220 mailimap_set_free( set );
1173 if ( err != MAILIMAP_NO_ERROR ) { 1221 if ( err != MAILIMAP_NO_ERROR ) {
1174 QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); 1222 QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response);
1175 Global::statusMessage(error_msg); 1223 Global::statusMessage(error_msg);
1176 // odebug << error_msg << oendl; 1224 // odebug << error_msg << oendl;
1177 return; 1225 return;
1178 } 1226 }
1179 if (moveit) { 1227 if (moveit) {
1180 deleteMail(mail); 1228 deleteMail(mail);
1181 } 1229 }
1182} 1230}
diff --git a/kmicromail/libmailwrapper/imapwrapper.h b/kmicromail/libmailwrapper/imapwrapper.h
index e56605a..222fe95 100644
--- a/kmicromail/libmailwrapper/imapwrapper.h
+++ b/kmicromail/libmailwrapper/imapwrapper.h
@@ -1,80 +1,82 @@
1// CHANGED 2004-09-31 Lutz Rogowski
1#ifndef __IMAPWRAPPER 2#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 3#define __IMAPWRAPPER
3 4
4#include <qlist.h> 5#include <qlist.h>
5#include "mailwrapper.h" 6#include "mailwrapper.h"
6#include "abstractmail.h" 7#include "abstractmail.h"
7#include <libetpan/clist.h> 8#include <libetpan/clist.h>
8 9
9struct mailimap; 10struct mailimap;
10struct mailimap_body; 11struct mailimap_body;
11struct mailimap_body_type_1part; 12struct mailimap_body_type_1part;
12struct mailimap_body_type_text; 13struct mailimap_body_type_text;
13struct mailimap_body_type_basic; 14struct mailimap_body_type_basic;
14struct mailimap_body_type_msg; 15struct mailimap_body_type_msg;
15struct mailimap_body_type_mpart; 16struct mailimap_body_type_mpart;
16struct mailimap_body_fields; 17struct mailimap_body_fields;
17struct mailimap_msg_att; 18struct mailimap_msg_att;
18class encodedString; 19class encodedString;
19 20
20class IMAPwrapper : public AbstractMail 21class IMAPwrapper : public AbstractMail
21{ 22{
22 Q_OBJECT 23 Q_OBJECT
23public: 24public:
24 IMAPwrapper( IMAPaccount *a ); 25 IMAPwrapper( IMAPaccount *a );
25 virtual ~IMAPwrapper(); 26 virtual ~IMAPwrapper();
26 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 27 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
27 virtual void listMessages(const QString & mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> >&target ); 28 virtual void listMessages(const QString & mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> >&target , int sizeInKb = 0);
28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 29 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
29 30
30 virtual void deleteMail(const RecMailP&mail); 31 virtual void deleteMail(const RecMailP&mail);
32 void deleteMailList(const QValueList<RecMailP>&target);
31 virtual void answeredMail(const RecMailP&mail); 33 virtual void answeredMail(const RecMailP&mail);
32 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&folder); 34 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&folder);
33 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 35 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
34 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, 36 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder,
35 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 37 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit,int sizeInKb = 0);
36 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 38 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
37 39
38 virtual RecBodyP fetchBody(const RecMailP&mail); 40 virtual RecBodyP fetchBody(const RecMailP&mail);
39 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part); 41 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part);
40 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part); 42 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part);
41 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part); 43 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part);
42 virtual encodedString* fetchRawBody(const RecMailP&mail); 44 virtual encodedString* fetchRawBody(const RecMailP&mail);
43 45
44 virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0, 46 virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0,
45 const QString& delemiter="/",bool getsubfolder=false); 47 const QString& delemiter="/",bool getsubfolder=false);
46 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&folder); 48 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&folder);
47 49
48 static void imap_progress( size_t current, size_t maximum ); 50 static void imap_progress( size_t current, size_t maximum );
49 51
50 virtual void logout(); 52 virtual void logout();
51 virtual MAILLIB::ATYPE getType()const; 53 virtual MAILLIB::ATYPE getType()const;
52 virtual const QString&getName()const; 54 virtual const QString&getName()const;
53 55
54protected: 56protected:
55 RecMail*parse_list_result(mailimap_msg_att*); 57 RecMail*parse_list_result(mailimap_msg_att*);
56 void login(); 58 void login();
57 bool start_tls(bool force=true); 59 bool start_tls(bool force=true);
58 60
59 virtual QString fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); 61 virtual QString fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
60 virtual encodedString*fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call); 62 virtual encodedString*fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call);
61 int selectMbox(const QString&mbox); 63 int selectMbox(const QString&mbox);
62 64
63 void fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description); 65 void fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description);
64 void fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which); 66 void fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which);
65 void fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which); 67 void fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which);
66 void fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which); 68 void fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which);
67 void fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which); 69 void fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which);
68 void traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,int current_recursion,QValueList<int>recList,int current_count=1); 70 void traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,int current_recursion,QValueList<int>recList,int current_count=1);
69 71
70 /* just helpers */ 72 /* just helpers */
71 static void fillBodyFields(RecPartP&target_part,mailimap_body_fields*which); 73 static void fillBodyFields(RecPartP&target_part,mailimap_body_fields*which);
72 static QStringList address_list_to_stringlist(clist*list); 74 static QStringList address_list_to_stringlist(clist*list);
73 75
74 76
75 IMAPaccount *account; 77 IMAPaccount *account;
76 mailimap *m_imap; 78 mailimap *m_imap;
77 QString m_Lastmbox; 79 QString m_Lastmbox;
78}; 80};
79 81
80#endif 82#endif
diff --git a/kmicromail/libmailwrapper/mhwrapper.cpp b/kmicromail/libmailwrapper/mhwrapper.cpp
index 7ef9b32..cbc52d9 100644
--- a/kmicromail/libmailwrapper/mhwrapper.cpp
+++ b/kmicromail/libmailwrapper/mhwrapper.cpp
@@ -1,446 +1,447 @@
1// CHANGED 2004-09-31 Lutz Rogowski
1#include "mhwrapper.h" 2#include "mhwrapper.h"
2#include "mailtypes.h" 3#include "mailtypes.h"
3#include "mailwrapper.h" 4#include "mailwrapper.h"
4#include <libetpan/libetpan.h> 5#include <libetpan/libetpan.h>
5#include <qdir.h> 6#include <qdir.h>
6#include <qmessagebox.h> 7#include <qmessagebox.h>
7#include <stdlib.h> 8#include <stdlib.h>
8#include <qpe/global.h> 9#include <qpe/global.h>
9#include <oprocess.h> 10#include <oprocess.h>
10//#include <opie2/odebug.h> 11//#include <opie2/odebug.h>
11 12
12using namespace Opie::Core; 13using namespace Opie::Core;
13MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) 14MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name)
14 : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) 15 : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name)
15{ 16{
16 if (MHPath.length()>0) { 17 if (MHPath.length()>0) {
17 if (MHPath[MHPath.length()-1]=='/') { 18 if (MHPath[MHPath.length()-1]=='/') {
18 MHPath=MHPath.left(MHPath.length()-1); 19 MHPath=MHPath.left(MHPath.length()-1);
19 } 20 }
20 //odebug << MHPath << oendl; 21 //odebug << MHPath << oendl;
21 QDir dir(MHPath); 22 QDir dir(MHPath);
22 if (!dir.exists()) { 23 if (!dir.exists()) {
23 dir.mkdir(MHPath); 24 dir.mkdir(MHPath);
24 } 25 }
25 init_storage(); 26 init_storage();
26 } 27 }
27} 28}
28 29
29void MHwrapper::init_storage() 30void MHwrapper::init_storage()
30{ 31{
31 int r; 32 int r;
32 QString pre = MHPath; 33 QString pre = MHPath;
33 if (!m_storage) { 34 if (!m_storage) {
34 m_storage = mailstorage_new(NULL); 35 m_storage = mailstorage_new(NULL);
35 r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); 36 r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0);
36 if (r != MAIL_NO_ERROR) { 37 if (r != MAIL_NO_ERROR) {
37 qDebug(" error init storage "); 38 qDebug(" error init storage ");
38 mailstorage_free(m_storage); 39 mailstorage_free(m_storage);
39 m_storage = 0; 40 m_storage = 0;
40 return; 41 return;
41 } 42 }
42 } 43 }
43 r = mailstorage_connect(m_storage); 44 r = mailstorage_connect(m_storage);
44 if (r!=MAIL_NO_ERROR) { 45 if (r!=MAIL_NO_ERROR) {
45 qDebug("error connecting storage "); 46 qDebug("error connecting storage ");
46 mailstorage_free(m_storage); 47 mailstorage_free(m_storage);
47 m_storage = 0; 48 m_storage = 0;
48 } 49 }
49} 50}
50 51
51void MHwrapper::clean_storage() 52void MHwrapper::clean_storage()
52{ 53{
53 if (m_storage) { 54 if (m_storage) {
54 mailstorage_disconnect(m_storage); 55 mailstorage_disconnect(m_storage);
55 mailstorage_free(m_storage); 56 mailstorage_free(m_storage);
56 m_storage = 0; 57 m_storage = 0;
57 } 58 }
58} 59}
59 60
60MHwrapper::~MHwrapper() 61MHwrapper::~MHwrapper()
61{ 62{
62 clean_storage(); 63 clean_storage();
63} 64}
64 65
65void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) 66void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb )
66{ 67{
67 init_storage(); 68 init_storage();
68 if (!m_storage) { 69 if (!m_storage) {
69 return; 70 return;
70 } 71 }
71 QString f = buildPath(mailbox); 72 QString f = buildPath(mailbox);
72 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 73 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
73 if (r!=MAIL_NO_ERROR) { 74 if (r!=MAIL_NO_ERROR) {
74 qDebug("listMessages: error selecting folder! "); 75 qDebug("listMessages: error selecting folder! ");
75 return; 76 return;
76 } 77 }
77 parseList(target,m_storage->sto_session,f); 78 parseList(target,m_storage->sto_session,f, false, maxSizeInKb );
78 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); 79 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count()));
79} 80}
80 81
81QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() 82QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders()
82{ 83{
83 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); 84 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >();
84 /* this is needed! */ 85 /* this is needed! */
85 if (m_storage) mailstorage_disconnect(m_storage); 86 if (m_storage) mailstorage_disconnect(m_storage);
86 init_storage(); 87 init_storage();
87 if (!m_storage) { 88 if (!m_storage) {
88 return folders; 89 return folders;
89 } 90 }
90 mail_list*flist = 0; 91 mail_list*flist = 0;
91 clistcell*current=0; 92 clistcell*current=0;
92 int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); 93 int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist);
93 if (r != MAIL_NO_ERROR || !flist) { 94 if (r != MAIL_NO_ERROR || !flist) {
94 qDebug("error getting folder list "); 95 qDebug("error getting folder list ");
95 return folders; 96 return folders;
96 } 97 }
97 for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { 98 for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) {
98 QString t = (char*)current->data; 99 QString t = (char*)current->data;
99 t.replace(0,MHPath.length(),""); 100 t.replace(0,MHPath.length(),"");
100 folders->append(new MHFolder(t,MHPath)); 101 folders->append(new MHFolder(t,MHPath));
101 } 102 }
102 mail_list_free(flist); 103 mail_list_free(flist);
103 return folders; 104 return folders;
104} 105}
105 106
106void MHwrapper::deleteMail(const RecMailP&mail) 107void MHwrapper::deleteMail(const RecMailP&mail)
107{ 108{
108 init_storage(); 109 init_storage();
109 if (!m_storage) { 110 if (!m_storage) {
110 return; 111 return;
111 } 112 }
112 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 113 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
113 if (r!=MAIL_NO_ERROR) { 114 if (r!=MAIL_NO_ERROR) {
114 qDebug("error selecting folder! "); 115 qDebug("error selecting folder! ");
115 return; 116 return;
116 } 117 }
117 r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); 118 r = mailsession_remove_message(m_storage->sto_session,mail->getNumber());
118 if (r != MAIL_NO_ERROR) { 119 if (r != MAIL_NO_ERROR) {
119 qDebug("error deleting mail "); 120 qDebug("error deleting mail ");
120 } 121 }
121} 122}
122 123
123void MHwrapper::answeredMail(const RecMailP&) 124void MHwrapper::answeredMail(const RecMailP&)
124{ 125{
125} 126}
126 127
127RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) 128RecBodyP MHwrapper::fetchBody( const RecMailP &mail )
128{ 129{
129 RecBodyP body = new RecBody(); 130 RecBodyP body = new RecBody();
130 init_storage(); 131 init_storage();
131 if (!m_storage) { 132 if (!m_storage) {
132 return body; 133 return body;
133 } 134 }
134 mailmessage * msg; 135 mailmessage * msg;
135 char*data=0; 136 char*data=0;
136 137
137 /* mail should hold the complete path! */ 138 /* mail should hold the complete path! */
138 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 139 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
139 if (r != MAIL_NO_ERROR) { 140 if (r != MAIL_NO_ERROR) {
140 return body; 141 return body;
141 } 142 }
142 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); 143 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg);
143 if (r != MAIL_NO_ERROR) { 144 if (r != MAIL_NO_ERROR) {
144 qDebug("Error fetching mail "); 145 qDebug("Error fetching mail ");
145 146
146 return body; 147 return body;
147 } 148 }
148 body = parseMail(msg); 149 body = parseMail(msg);
149 mailmessage_fetch_result_free(msg,data); 150 mailmessage_fetch_result_free(msg,data);
150 return body; 151 return body;
151} 152}
152 153
153void MHwrapper::mbox_progress( size_t current, size_t maximum ) 154void MHwrapper::mbox_progress( size_t current, size_t maximum )
154{ 155{
155 qDebug("MBox Progress %d of %d",current,maximum ); 156 qDebug("MBox Progress %d of %d",current,maximum );
156 //odebug << "MH " << current << " von " << maximum << "" << oendl; 157 //odebug << "MH " << current << " von " << maximum << "" << oendl;
157} 158}
158 159
159QString MHwrapper::buildPath(const QString&p) 160QString MHwrapper::buildPath(const QString&p)
160{ 161{
161 QString f=""; 162 QString f="";
162 if (p.length()==0||p=="/") 163 if (p.length()==0||p=="/")
163 return MHPath; 164 return MHPath;
164 if (!p.startsWith(MHPath)) { 165 if (!p.startsWith(MHPath)) {
165 f+=MHPath; 166 f+=MHPath;
166 } 167 }
167 if (!p.startsWith("/")) { 168 if (!p.startsWith("/")) {
168 f+="/"; 169 f+="/";
169 } 170 }
170 f+=p; 171 f+=p;
171 return f; 172 return f;
172} 173}
173 174
174int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) 175int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool )
175{ 176{
176 init_storage(); 177 init_storage();
177 if (!m_storage) { 178 if (!m_storage) {
178 return 0; 179 return 0;
179 } 180 }
180 QString f; 181 QString f;
181 if (!pfolder) { 182 if (!pfolder) {
182 // toplevel folder 183 // toplevel folder
183 f = buildPath(folder); 184 f = buildPath(folder);
184 } else { 185 } else {
185 f = pfolder->getName(); 186 f = pfolder->getName();
186 f+="/"; 187 f+="/";
187 f+=folder; 188 f+=folder;
188 } 189 }
189 190
190 int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); 191 int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1());
191 if (r != MAIL_NO_ERROR) { 192 if (r != MAIL_NO_ERROR) {
192 qDebug("error creating folder "); 193 qDebug("error creating folder ");
193 return 0; 194 return 0;
194 } 195 }
195 qDebug("Folder created "); 196 qDebug("Folder created ");
196 return 1; 197 return 1;
197} 198}
198 199
199void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) 200void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder)
200{ 201{
201 init_storage(); 202 init_storage();
202 if (!m_storage) { 203 if (!m_storage) {
203 return; 204 return;
204 } 205 }
205 QString f = buildPath(Folder); 206 QString f = buildPath(Folder);
206 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 207 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
207 if (r!=MAIL_NO_ERROR) { 208 if (r!=MAIL_NO_ERROR) {
208 qDebug("error selecting folder! "); 209 qDebug("error selecting folder! ");
209 return; 210 return;
210 } 211 }
211 r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); 212 r = mailsession_append_message(m_storage->sto_session,(char*)msg,length);
212 if (r!=MAIL_NO_ERROR) { 213 if (r!=MAIL_NO_ERROR) {
213 qDebug("error storing mail "); 214 qDebug("error storing mail ");
214 } 215 }
215 return; 216 return;
216} 217}
217 218
218encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) 219encodedString* MHwrapper::fetchRawBody(const RecMailP&mail)
219{ 220{
220 encodedString*result = 0; 221 encodedString*result = 0;
221 init_storage(); 222 init_storage();
222 if (!m_storage) { 223 if (!m_storage) {
223 return result; 224 return result;
224 } 225 }
225 mailmessage * msg = 0; 226 mailmessage * msg = 0;
226 char*data=0; 227 char*data=0;
227 size_t size; 228 size_t size;
228 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 229 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
229 if (r!=MAIL_NO_ERROR) { 230 if (r!=MAIL_NO_ERROR) {
230 qDebug("error selecting folder! "); 231 qDebug("error selecting folder! ");
231 return result; 232 return result;
232 } 233 }
233 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); 234 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg);
234 if (r != MAIL_NO_ERROR) { 235 if (r != MAIL_NO_ERROR) {
235 Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); 236 Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber()));
236 return 0; 237 return 0;
237 } 238 }
238 r = mailmessage_fetch(msg,&data,&size); 239 r = mailmessage_fetch(msg,&data,&size);
239 if (r != MAIL_NO_ERROR) { 240 if (r != MAIL_NO_ERROR) {
240 Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); 241 Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber()));
241 if (msg) mailmessage_free(msg); 242 if (msg) mailmessage_free(msg);
242 return 0; 243 return 0;
243 } 244 }
244 result = new encodedString(data,size); 245 result = new encodedString(data,size);
245 if (msg) mailmessage_free(msg); 246 if (msg) mailmessage_free(msg);
246 return result; 247 return result;
247} 248}
248 249
249void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) 250void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target)
250{ 251{
251 QString f = buildPath(mailbox); 252 QString f = buildPath(mailbox);
252 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 253 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
253 if (r!=MAIL_NO_ERROR) { 254 if (r!=MAIL_NO_ERROR) {
254 qDebug("deleteMails: error selecting folder! "); 255 qDebug("deleteMails: error selecting folder! ");
255 return; 256 return;
256 } 257 }
257 QValueList<RecMailP>::ConstIterator it; 258 QValueList<RecMailP>::ConstIterator it;
258 for (it=target.begin(); it!=target.end();++it) { 259 for (it=target.begin(); it!=target.end();++it) {
259 r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); 260 r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber());
260 if (r != MAIL_NO_ERROR) { 261 if (r != MAIL_NO_ERROR) {
261 qDebug("error deleting mail "); 262 qDebug("error deleting mail ");
262 break; 263 break;
263 } 264 }
264 } 265 }
265} 266}
266 267
267int MHwrapper::deleteAllMail(const FolderP&tfolder) 268int MHwrapper::deleteAllMail(const FolderP&tfolder)
268{ 269{
269 init_storage(); 270 init_storage();
270 if (!m_storage) { 271 if (!m_storage) {
271 return 0; 272 return 0;
272 } 273 }
273 int res = 1; 274 int res = 1;
274 if (!tfolder) return 0; 275 if (!tfolder) return 0;
275 int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); 276 int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
276 if (r!=MAIL_NO_ERROR) { 277 if (r!=MAIL_NO_ERROR) {
277 qDebug("error selecting folder! "); 278 qDebug("error selecting folder! ");
278 return 0; 279 return 0;
279 } 280 }
280 mailmessage_list*l=0; 281 mailmessage_list*l=0;
281 r = mailsession_get_messages_list(m_storage->sto_session,&l); 282 r = mailsession_get_messages_list(m_storage->sto_session,&l);
282 if (r != MAIL_NO_ERROR) { 283 if (r != MAIL_NO_ERROR) {
283 qDebug("Error message list "); 284 qDebug("Error message list ");
284 res = 0; 285 res = 0;
285 } 286 }
286 unsigned j = 0; 287 unsigned j = 0;
287 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { 288 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
288 mailmessage * msg; 289 mailmessage * msg;
289 msg = (mailmessage*)carray_get(l->msg_tab, i); 290 msg = (mailmessage*)carray_get(l->msg_tab, i);
290 j = msg->msg_index; 291 j = msg->msg_index;
291 r = mailsession_remove_message(m_storage->sto_session,j); 292 r = mailsession_remove_message(m_storage->sto_session,j);
292 if (r != MAIL_NO_ERROR) { 293 if (r != MAIL_NO_ERROR) {
293 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 294 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
294 res = 0; 295 res = 0;
295 break; 296 break;
296 } 297 }
297 } 298 }
298 if (l) mailmessage_list_free(l); 299 if (l) mailmessage_list_free(l);
299 return res; 300 return res;
300} 301}
301 302
302int MHwrapper::deleteMbox(const FolderP&tfolder) 303int MHwrapper::deleteMbox(const FolderP&tfolder)
303{ 304{
304 init_storage(); 305 init_storage();
305 if (!m_storage) { 306 if (!m_storage) {
306 return 0; 307 return 0;
307 } 308 }
308 if (!tfolder) return 0; 309 if (!tfolder) return 0;
309 if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; 310 if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0;
310 311
311 int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); 312 int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
312 313
313 if (r != MAIL_NO_ERROR) { 314 if (r != MAIL_NO_ERROR) {
314 qDebug("error deleting mail box "); 315 qDebug("error deleting mail box ");
315 return 0; 316 return 0;
316 } 317 }
317 QString cmd = "rm -rf "+tfolder->getName(); 318 QString cmd = "rm -rf "+tfolder->getName();
318 QStringList command; 319 QStringList command;
319 command << "/bin/sh"; 320 command << "/bin/sh";
320 command << "-c"; 321 command << "-c";
321 command << cmd.latin1(); 322 command << cmd.latin1();
322 OProcess *process = new OProcess(); 323 OProcess *process = new OProcess();
323 324
324 connect(process, SIGNAL(processExited(Opie::Core::OProcess*)), 325 connect(process, SIGNAL(processExited(Opie::Core::OProcess*)),
325 this, SLOT( processEnded(Opie::Core::OProcess*))); 326 this, SLOT( processEnded(Opie::Core::OProcess*)));
326 connect(process, SIGNAL( receivedStderr(Opie::Core::OProcess*,char*,int)), 327 connect(process, SIGNAL( receivedStderr(Opie::Core::OProcess*,char*,int)),
327 this, SLOT( oprocessStderr(Opie::Core::OProcess*,char*,int))); 328 this, SLOT( oprocessStderr(Opie::Core::OProcess*,char*,int)));
328 329
329 *process << command; 330 *process << command;
330 removeMboxfailed = false; 331 removeMboxfailed = false;
331 if(!process->start(OProcess::Block, OProcess::All) ) { 332 if(!process->start(OProcess::Block, OProcess::All) ) {
332 qDebug("could not start process "); 333 qDebug("could not start process ");
333 return 0; 334 return 0;
334 } 335 }
335 qDebug("mail box deleted "); 336 qDebug("mail box deleted ");
336 return 1; 337 return 1;
337} 338}
338 339
339void MHwrapper::processEnded(OProcess *p) 340void MHwrapper::processEnded(OProcess *p)
340{ 341{
341 if (p) delete p; 342 if (p) delete p;
342} 343}
343 344
344void MHwrapper::oprocessStderr(OProcess*, char *buffer, int ) 345void MHwrapper::oprocessStderr(OProcess*, char *buffer, int )
345{ 346{
346 QString lineStr = buffer; 347 QString lineStr = buffer;
347 QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") ); 348 QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") );
348 removeMboxfailed = true; 349 removeMboxfailed = true;
349} 350}
350 351
351void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 352void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
352{ 353{
353 init_storage(); 354 init_storage();
354 if (!m_storage) { 355 if (!m_storage) {
355 return; 356 return;
356 } 357 }
357 target_stat.message_count = 0; 358 target_stat.message_count = 0;
358 target_stat.message_unseen = 0; 359 target_stat.message_unseen = 0;
359 target_stat.message_recent = 0; 360 target_stat.message_recent = 0;
360 QString f = buildPath(mailbox); 361 QString f = buildPath(mailbox);
361 int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, 362 int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count,
362 &target_stat.message_recent,&target_stat.message_unseen); 363 &target_stat.message_recent,&target_stat.message_unseen);
363 if (r != MAIL_NO_ERROR) { 364 if (r != MAIL_NO_ERROR) {
364 Global::statusMessage(tr("Error retrieving status")); 365 Global::statusMessage(tr("Error retrieving status"));
365 } 366 }
366} 367}
367 368
368MAILLIB::ATYPE MHwrapper::getType()const 369MAILLIB::ATYPE MHwrapper::getType()const
369{ 370{
370 return MAILLIB::A_MH; 371 return MAILLIB::A_MH;
371} 372}
372 373
373const QString&MHwrapper::getName()const 374const QString&MHwrapper::getName()const
374{ 375{
375 return MHName; 376 return MHName;
376} 377}
377void MHwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 378void MHwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
378{ 379{
379 init_storage(); 380 init_storage();
380 if (!m_storage) { 381 if (!m_storage) {
381 return; 382 return;
382 } 383 }
383 if (targetWrapper != this) { 384 if (targetWrapper != this) {
384 qDebug("Using generic "); 385 qDebug("Using generic ");
385 Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); 386 Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit);
386 return; 387 return;
387 } 388 }
388 qDebug("Using internal routines for move/copy "); 389 qDebug("Using internal routines for move/copy ");
389 QString tf = buildPath(targetFolder); 390 QString tf = buildPath(targetFolder);
390 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 391 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
391 if (r != MAIL_NO_ERROR) { 392 if (r != MAIL_NO_ERROR) {
392 qDebug("Error selecting source mailbox "); 393 qDebug("Error selecting source mailbox ");
393 return; 394 return;
394 } 395 }
395 if (moveit) { 396 if (moveit) {
396 r = mailsession_move_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); 397 r = mailsession_move_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1());
397 } else { 398 } else {
398 r = mailsession_copy_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); 399 r = mailsession_copy_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1());
399 } 400 }
400 if (r != MAIL_NO_ERROR) { 401 if (r != MAIL_NO_ERROR) {
401 qDebug("Error copy/moving mail internal "); 402 qDebug("Error copy/moving mail internal ");
402 } 403 }
403} 404}
404 405
405void MHwrapper::mvcpAllMails(const FolderP&fromFolder, 406void MHwrapper::mvcpAllMails(const FolderP&fromFolder,
406 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 407 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
407{ 408{
408 init_storage(); 409 init_storage();
409 if (!m_storage) { 410 if (!m_storage) {
410 return; 411 return;
411 } 412 }
412 if (targetWrapper != this) { 413 if (targetWrapper != this) {
413 qDebug("Using generic "); 414 qDebug("Using generic ");
414 Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); 415 Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit);
415 return; 416 return;
416 } 417 }
417 if (!fromFolder) return; 418 if (!fromFolder) return;
418 int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1()); 419 int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1());
419 if (r!=MAIL_NO_ERROR) { 420 if (r!=MAIL_NO_ERROR) {
420 qDebug("error selecting source folder! "); 421 qDebug("error selecting source folder! ");
421 return; 422 return;
422 } 423 }
423 QString tf = buildPath(targetFolder); 424 QString tf = buildPath(targetFolder);
424 mailmessage_list*l=0; 425 mailmessage_list*l=0;
425 r = mailsession_get_messages_list(m_storage->sto_session,&l); 426 r = mailsession_get_messages_list(m_storage->sto_session,&l);
426 if (r != MAIL_NO_ERROR) { 427 if (r != MAIL_NO_ERROR) {
427 qDebug("Error message list "); 428 qDebug("Error message list ");
428 } 429 }
429 unsigned j = 0; 430 unsigned j = 0;
430 for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) { 431 for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) {
431 mailmessage * msg; 432 mailmessage * msg;
432 msg = (mailmessage*)carray_get(l->msg_tab, i); 433 msg = (mailmessage*)carray_get(l->msg_tab, i);
433 j = msg->msg_index; 434 j = msg->msg_index;
434 if (moveit) { 435 if (moveit) {
435 r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1()); 436 r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1());
436 } else { 437 } else {
437 r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1()); 438 r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1());
438 } 439 }
439 if (r != MAIL_NO_ERROR) { 440 if (r != MAIL_NO_ERROR) {
440 qDebug("Error copy/moving mail interna "); 441 qDebug("Error copy/moving mail interna ");
441 442
442 break; 443 break;
443 } 444 }
444 } 445 }
445 if (l) mailmessage_list_free(l); 446 if (l) mailmessage_list_free(l);
446} 447}
diff --git a/kmicromail/libmailwrapper/mhwrapper.h b/kmicromail/libmailwrapper/mhwrapper.h
index 4310c84..550824d 100644
--- a/kmicromail/libmailwrapper/mhwrapper.h
+++ b/kmicromail/libmailwrapper/mhwrapper.h
@@ -1,60 +1,61 @@
1// CHANGED 2004-09-31 Lutz Rogowski
1#ifndef __MH_WRAPPER_H 2#ifndef __MH_WRAPPER_H
2#define __MH_WRAPPER_H 3#define __MH_WRAPPER_H
3 4
4#include "maildefines.h" 5#include "maildefines.h"
5 6
6#include "genericwrapper.h" 7#include "genericwrapper.h"
7#include <qstring.h> 8#include <qstring.h>
8 9
9class encodedString; 10class encodedString;
10struct mailmbox_folder; 11struct mailmbox_folder;
11namespace Opie {namespace Core {class OProcess;}} 12namespace Opie {namespace Core {class OProcess;}}
12 13
13class MHwrapper : public Genericwrapper 14class MHwrapper : public Genericwrapper
14{ 15{
15 Q_OBJECT 16 Q_OBJECT
16public: 17public:
17 MHwrapper(const QString & dir,const QString&name); 18 MHwrapper(const QString & dir,const QString&name);
18 virtual ~MHwrapper(); 19 virtual ~MHwrapper();
19 20
20 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ); 21 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 );
21 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 22 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
22 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 23 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
23 24
24 virtual void deleteMail(const RecMailP&mail); 25 virtual void deleteMail(const RecMailP&mail);
25 virtual void answeredMail(const RecMailP&mail); 26 virtual void answeredMail(const RecMailP&mail);
26 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 27 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
27 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, 28 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder,
28 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 29 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
29 30
30 virtual int createMbox(const QString&folder,const Opie::Core::OSmartPointer<Folder>&f=0, 31 virtual int createMbox(const QString&folder,const Opie::Core::OSmartPointer<Folder>&f=0,
31 const QString&d="",bool s=false); 32 const QString&d="",bool s=false);
32 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&); 33 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&);
33 34
34 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 35 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
35 36
36 virtual RecBodyP fetchBody( const RecMailP &mail ); 37 virtual RecBodyP fetchBody( const RecMailP &mail );
37 static void mbox_progress( size_t current, size_t maximum ); 38 static void mbox_progress( size_t current, size_t maximum );
38 39
39 virtual encodedString* fetchRawBody(const RecMailP&mail); 40 virtual encodedString* fetchRawBody(const RecMailP&mail);
40 virtual void deleteMails(const QString & FolderName,const QValueList<Opie::Core::OSmartPointer<RecMail> > &target); 41 virtual void deleteMails(const QString & FolderName,const QValueList<Opie::Core::OSmartPointer<RecMail> > &target);
41 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); 42 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&);
42 virtual MAILLIB::ATYPE getType()const; 43 virtual MAILLIB::ATYPE getType()const;
43 virtual const QString&getName()const; 44 virtual const QString&getName()const;
44 45
45public slots: 46public slots:
46 /* for deleting maildirs we are using a system call */ 47 /* for deleting maildirs we are using a system call */
47 virtual void oprocessStderr(Opie::Core::OProcess*, char *buffer, int ); 48 virtual void oprocessStderr(Opie::Core::OProcess*, char *buffer, int );
48 virtual void processEnded(Opie::Core::OProcess *); 49 virtual void processEnded(Opie::Core::OProcess *);
49protected: 50protected:
50 QString buildPath(const QString&p); 51 QString buildPath(const QString&p);
51 QString MHPath; 52 QString MHPath;
52 QString MHName; 53 QString MHName;
53 54
54 void init_storage(); 55 void init_storage();
55 void clean_storage(); 56 void clean_storage();
56 57
57 bool removeMboxfailed; 58 bool removeMboxfailed;
58}; 59};
59 60
60#endif 61#endif
diff --git a/kmicromail/libmailwrapper/nntpwrapper.cpp b/kmicromail/libmailwrapper/nntpwrapper.cpp
index daa128e..f5d7f16 100644
--- a/kmicromail/libmailwrapper/nntpwrapper.cpp
+++ b/kmicromail/libmailwrapper/nntpwrapper.cpp
@@ -1,289 +1,290 @@
1// CHANGED 2004-09-31 Lutz Rogowski
1#include "nntpwrapper.h" 2#include "nntpwrapper.h"
2#include "logindialog.h" 3#include "logindialog.h"
3#include "mailtypes.h" 4#include "mailtypes.h"
4 5
5#include <qfile.h> 6#include <qfile.h>
6 7
7#include <stdlib.h> 8#include <stdlib.h>
8 9
9#include <libetpan/libetpan.h> 10#include <libetpan/libetpan.h>
10 11
11 12
12 13
13#define HARD_MSG_SIZE_LIMIT 5242880 14#define HARD_MSG_SIZE_LIMIT 5242880
14 15
15using namespace Opie::Core; 16using namespace Opie::Core;
16NNTPwrapper::NNTPwrapper( NNTPaccount *a ) 17NNTPwrapper::NNTPwrapper( NNTPaccount *a )
17: Genericwrapper() { 18: Genericwrapper() {
18 account = a; 19 account = a;
19 m_nntp = NULL; 20 m_nntp = NULL;
20 msgTempName = a->getFileName()+"_msg_cache"; 21 msgTempName = a->getFileName()+"_msg_cache";
21 last_msg_id = 0; 22 last_msg_id = 0;
22} 23}
23 24
24NNTPwrapper::~NNTPwrapper() { 25NNTPwrapper::~NNTPwrapper() {
25 logout(); 26 logout();
26 QFile msg_cache(msgTempName); 27 QFile msg_cache(msgTempName);
27 if (msg_cache.exists()) { 28 if (msg_cache.exists()) {
28 msg_cache.remove(); 29 msg_cache.remove();
29 } 30 }
30} 31}
31 32
32void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) { 33void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) {
33 ; // << "NNTP: " << current << " of " << maximum << "" << oendl; 34 ; // << "NNTP: " << current << " of " << maximum << "" << oendl;
34} 35}
35 36
36 37
37RecBodyP NNTPwrapper::fetchBody( const RecMailP &mail ) { 38RecBodyP NNTPwrapper::fetchBody( const RecMailP &mail ) {
38 int err = NEWSNNTP_NO_ERROR; 39 int err = NEWSNNTP_NO_ERROR;
39 char *message = 0; 40 char *message = 0;
40 size_t length = 0; 41 size_t length = 0;
41 42
42 RecBodyP body = new RecBody(); 43 RecBodyP body = new RecBody();
43 login(); 44 login();
44 if ( !m_nntp ) { 45 if ( !m_nntp ) {
45 return body; 46 return body;
46 } 47 }
47 48
48 mailmessage * mailmsg; 49 mailmessage * mailmsg;
49 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { 50 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) {
50 ; // << "Message to large: " << mail->Msgsize() << "" << oendl; 51 ; // << "Message to large: " << mail->Msgsize() << "" << oendl;
51 return body; 52 return body;
52 } 53 }
53 54
54 QFile msg_cache(msgTempName); 55 QFile msg_cache(msgTempName);
55 56
56 cleanMimeCache(); 57 cleanMimeCache();
57 58
58 if (mail->getNumber()!=last_msg_id) { 59 if (mail->getNumber()!=last_msg_id) {
59 if (msg_cache.exists()) { 60 if (msg_cache.exists()) {
60 msg_cache.remove(); 61 msg_cache.remove();
61 } 62 }
62 msg_cache.open(IO_ReadWrite|IO_Truncate); 63 msg_cache.open(IO_ReadWrite|IO_Truncate);
63 last_msg_id = mail->getNumber(); 64 last_msg_id = mail->getNumber();
64 err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); 65 err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg);
65 err = mailmessage_fetch(mailmsg,&message,&length); 66 err = mailmessage_fetch(mailmsg,&message,&length);
66 msg_cache.writeBlock(message,length); 67 msg_cache.writeBlock(message,length);
67 } else { 68 } else {
68 QString msg=""; 69 QString msg="";
69 msg_cache.open(IO_ReadOnly); 70 msg_cache.open(IO_ReadOnly);
70 message = new char[4096]; 71 message = new char[4096];
71 memset(message,0,4096); 72 memset(message,0,4096);
72 while (msg_cache.readBlock(message,4095)>0) { 73 while (msg_cache.readBlock(message,4095)>0) {
73 msg+=message; 74 msg+=message;
74 memset(message,0,4096); 75 memset(message,0,4096);
75 } 76 }
76 delete message; 77 delete message;
77 message = (char*)malloc(msg.length()+1*sizeof(char)); 78 message = (char*)malloc(msg.length()+1*sizeof(char));
78 memset(message,0,msg.length()+1); 79 memset(message,0,msg.length()+1);
79 memcpy(message,msg.latin1(),msg.length()); 80 memcpy(message,msg.latin1(),msg.length());
80 /* transform to libetpan stuff */ 81 /* transform to libetpan stuff */
81 mailmsg = mailmessage_new(); 82 mailmsg = mailmessage_new();
82 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 83 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
83 generic_message_t * msg_data; 84 generic_message_t * msg_data;
84 msg_data = (generic_message_t *)mailmsg->msg_data; 85 msg_data = (generic_message_t *)mailmsg->msg_data;
85 msg_data->msg_fetched = 1; 86 msg_data->msg_fetched = 1;
86 msg_data->msg_message = message; 87 msg_data->msg_message = message;
87 msg_data->msg_length = strlen(message); 88 msg_data->msg_length = strlen(message);
88 } 89 }
89 body = parseMail(mailmsg); 90 body = parseMail(mailmsg);
90 91
91 /* clean up */ 92 /* clean up */
92 if (mailmsg) 93 if (mailmsg)
93 mailmessage_free(mailmsg); 94 mailmessage_free(mailmsg);
94 if (message) 95 if (message)
95 free(message); 96 free(message);
96 97
97 return body; 98 return body;
98} 99}
99 100
100 101
101void NNTPwrapper::listMessages(const QString & which, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) 102void NNTPwrapper::listMessages(const QString & which, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb)
102{ 103{
103 login(); 104 login();
104 if (!m_nntp) 105 if (!m_nntp)
105 return; 106 return;
106 uint32_t res_messages,res_recent,res_unseen; 107 uint32_t res_messages,res_recent,res_unseen;
107 mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen); 108 mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen);
108 parseList(target,m_nntp->sto_session,which,true); 109 parseList(target,m_nntp->sto_session,which,true, maxSizeInKb);
109} 110}
110 111
111void NNTPwrapper::login() 112void NNTPwrapper::login()
112{ 113{
113 if (account->getOffline()) 114 if (account->getOffline())
114 return; 115 return;
115 /* we'll hold the line */ 116 /* we'll hold the line */
116 if ( m_nntp != NULL ) 117 if ( m_nntp != NULL )
117 return; 118 return;
118 119
119 const char *server, *user, *pass; 120 const char *server, *user, *pass;
120 QString User,Pass; 121 QString User,Pass;
121 uint16_t port; 122 uint16_t port;
122 int err = NEWSNNTP_NO_ERROR; 123 int err = NEWSNNTP_NO_ERROR;
123 124
124 server = account->getServer().latin1(); 125 server = account->getServer().latin1();
125 port = account->getPort().toUInt(); 126 port = account->getPort().toUInt();
126 127
127 user = pass = 0; 128 user = pass = 0;
128 129
129 if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) { 130 if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) {
130 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 131 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
131 login.show(); 132 login.show();
132 if ( QDialog::Accepted == login.exec() ) { 133 if ( QDialog::Accepted == login.exec() ) {
133 // ok 134 // ok
134 User = login.getUser().latin1(); 135 User = login.getUser().latin1();
135 Pass = login.getPassword().latin1(); 136 Pass = login.getPassword().latin1();
136 } else { 137 } else {
137 // cancel 138 // cancel
138 ; // << "NNTP: Login canceled" << oendl; 139 ; // << "NNTP: Login canceled" << oendl;
139 return; 140 return;
140 } 141 }
141 } else { 142 } else {
142 User = account->getUser().latin1(); 143 User = account->getUser().latin1();
143 Pass = account->getPassword().latin1(); 144 Pass = account->getPassword().latin1();
144 } 145 }
145 146
146 if (User.isEmpty()) { 147 if (User.isEmpty()) {
147 user=0; 148 user=0;
148 pass = 0; 149 pass = 0;
149 } else { 150 } else {
150 user=User.latin1(); 151 user=User.latin1();
151 pass=Pass.latin1(); 152 pass=Pass.latin1();
152 } 153 }
153 // bool ssl = account->getSSL(); 154 // bool ssl = account->getSSL();
154 155
155 m_nntp=mailstorage_new(NULL); 156 m_nntp=mailstorage_new(NULL);
156 157
157 int conntypeset = account->ConnectionType(); 158 int conntypeset = account->ConnectionType();
158 int conntype = 0; 159 int conntype = 0;
159 if ( conntypeset == 3 ) { 160 if ( conntypeset == 3 ) {
160 conntype = CONNECTION_TYPE_COMMAND; 161 conntype = CONNECTION_TYPE_COMMAND;
161 } else if ( conntypeset == 2 ) { 162 } else if ( conntypeset == 2 ) {
162 conntype = CONNECTION_TYPE_TLS; 163 conntype = CONNECTION_TYPE_TLS;
163 } else if ( conntypeset == 1 ) { 164 } else if ( conntypeset == 1 ) {
164 conntype = CONNECTION_TYPE_STARTTLS; 165 conntype = CONNECTION_TYPE_STARTTLS;
165 } else if ( conntypeset == 0 ) { 166 } else if ( conntypeset == 0 ) {
166 conntype = CONNECTION_TYPE_TRY_STARTTLS; 167 conntype = CONNECTION_TYPE_TRY_STARTTLS;
167 } 168 }
168 169
169 nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN, 170 nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN,
170 (char*)user,(char*)pass,0,0,0); 171 (char*)user,(char*)pass,0,0,0);
171 172
172 err = mailstorage_connect( m_nntp ); 173 err = mailstorage_connect( m_nntp );
173 174
174 if (err != NEWSNNTP_NO_ERROR) { 175 if (err != NEWSNNTP_NO_ERROR) {
175 ; // << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; 176 ; // << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl;
176 // Global::statusMessage(tr("Error initializing folder")); 177 // Global::statusMessage(tr("Error initializing folder"));
177 mailstorage_free(m_nntp); 178 mailstorage_free(m_nntp);
178 m_nntp = 0; 179 m_nntp = 0;
179 180
180 } else { 181 } else {
181 mailsession * session = m_nntp->sto_session; 182 mailsession * session = m_nntp->sto_session;
182 newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; 183 newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session;
183 news->nntp_progr_fun = &nntp_progress; 184 news->nntp_progr_fun = &nntp_progress;
184 } 185 }
185 186
186} 187}
187 188
188void NNTPwrapper::logout() 189void NNTPwrapper::logout()
189{ 190{
190 int err = NEWSNNTP_NO_ERROR; 191 int err = NEWSNNTP_NO_ERROR;
191 if ( m_nntp == NULL ) 192 if ( m_nntp == NULL )
192 return; 193 return;
193 mailstorage_free(m_nntp); 194 mailstorage_free(m_nntp);
194 m_nntp = 0; 195 m_nntp = 0;
195} 196}
196 197
197QValueList<Opie::Core::OSmartPointer<Folder> >* NNTPwrapper::listFolders() { 198QValueList<Opie::Core::OSmartPointer<Folder> >* NNTPwrapper::listFolders() {
198 199
199 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); 200 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >();
200 QStringList groups; 201 QStringList groups;
201 if (account) { 202 if (account) {
202 groups = account->getGroups(); 203 groups = account->getGroups();
203 } 204 }
204 for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) { 205 for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) {
205 folders->append(new Folder((*it),".")); 206 folders->append(new Folder((*it),"."));
206 } 207 }
207 return folders; 208 return folders;
208} 209}
209 210
210/* we made this method in raw nntp access of etpan and not via generic interface 211/* we made this method in raw nntp access of etpan and not via generic interface
211 * 'cause in that case there will be doubled copy operations. eg. the etpan would 212 * 'cause in that case there will be doubled copy operations. eg. the etpan would
212 * copy that stuff into its own structures and we must copy it into useable c++ 213 * copy that stuff into its own structures and we must copy it into useable c++
213 * structures for our frontend. this would not make sense, so it is better to reimplement 214 * structures for our frontend. this would not make sense, so it is better to reimplement
214 * the stuff from generic interface of etpan but copy it direct to qt classes. 215 * the stuff from generic interface of etpan but copy it direct to qt classes.
215 */ 216 */
216QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) { 217QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) {
217 login(); 218 login();
218 QStringList res; 219 QStringList res;
219 clist *result = 0; 220 clist *result = 0;
220 clistcell *current = 0; 221 clistcell *current = 0;
221 newsnntp_group_description *group; 222 newsnntp_group_description *group;
222 223
223 if ( m_nntp ) { 224 if ( m_nntp ) {
224 mailsession * session = m_nntp->sto_session; 225 mailsession * session = m_nntp->sto_session;
225 newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; 226 newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session;
226 int err = NEWSNNTP_NO_ERROR; 227 int err = NEWSNNTP_NO_ERROR;
227 if (mask.isEmpty()) { 228 if (mask.isEmpty()) {
228 err = newsnntp_list(news, &result); 229 err = newsnntp_list(news, &result);
229 } else { 230 } else {
230 /* taken from generic wrapper of etpan */ 231 /* taken from generic wrapper of etpan */
231 QString nmask = mask+".*"; 232 QString nmask = mask+".*";
232 err = newsnntp_list_active(news, nmask.latin1(), &result); 233 err = newsnntp_list_active(news, nmask.latin1(), &result);
233 } 234 }
234 if ( err == NEWSNNTP_NO_ERROR && result) { 235 if ( err == NEWSNNTP_NO_ERROR && result) {
235 for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) { 236 for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) {
236 group = ( newsnntp_group_description* ) current->data; 237 group = ( newsnntp_group_description* ) current->data;
237 if (!group||!group->grp_name||strlen(group->grp_name)==0) continue; 238 if (!group||!group->grp_name||strlen(group->grp_name)==0) continue;
238 res.append(group->grp_name); 239 res.append(group->grp_name);
239 } 240 }
240 } 241 }
241 } 242 }
242 if (result) { 243 if (result) {
243 newsnntp_list_free(result); 244 newsnntp_list_free(result);
244 } 245 }
245 return res; 246 return res;
246} 247}
247 248
248void NNTPwrapper::answeredMail(const RecMailP&) {} 249void NNTPwrapper::answeredMail(const RecMailP&) {}
249 250
250void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { 251void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) {
251 login(); 252 login();
252 target_stat.message_count = 0; 253 target_stat.message_count = 0;
253 target_stat.message_unseen = 0; 254 target_stat.message_unseen = 0;
254 target_stat.message_recent = 0; 255 target_stat.message_recent = 0;
255 if (!m_nntp) 256 if (!m_nntp)
256 return; 257 return;
257 int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, 258 int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count,
258 &target_stat.message_recent,&target_stat.message_unseen); 259 &target_stat.message_recent,&target_stat.message_unseen);
259} 260}
260 261
261 262
262encodedString* NNTPwrapper::fetchRawBody(const RecMailP&mail) { 263encodedString* NNTPwrapper::fetchRawBody(const RecMailP&mail) {
263 char*target=0; 264 char*target=0;
264 size_t length=0; 265 size_t length=0;
265 encodedString*res = 0; 266 encodedString*res = 0;
266 mailmessage * mailmsg = 0; 267 mailmessage * mailmsg = 0;
267 int err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); 268 int err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg);
268 err = mailmessage_fetch(mailmsg,&target,&length); 269 err = mailmessage_fetch(mailmsg,&target,&length);
269 if (mailmsg) 270 if (mailmsg)
270 mailmessage_free(mailmsg); 271 mailmessage_free(mailmsg);
271 if (target) { 272 if (target) {
272 res = new encodedString(target,length); 273 res = new encodedString(target,length);
273 } 274 }
274 return res; 275 return res;
275} 276}
276 277
277MAILLIB::ATYPE NNTPwrapper::getType()const { 278MAILLIB::ATYPE NNTPwrapper::getType()const {
278 return account->getType(); 279 return account->getType();
279} 280}
280 281
281const QString&NNTPwrapper::getName()const{ 282const QString&NNTPwrapper::getName()const{
282 return account->getAccountName(); 283 return account->getAccountName();
283} 284}
284 285
285void NNTPwrapper::deleteMail(const RecMailP&) { 286void NNTPwrapper::deleteMail(const RecMailP&) {
286} 287}
287 288
288int NNTPwrapper::deleteAllMail(const FolderP&) { 289int NNTPwrapper::deleteAllMail(const FolderP&) {
289} 290}
diff --git a/kmicromail/libmailwrapper/nntpwrapper.h b/kmicromail/libmailwrapper/nntpwrapper.h
index 2fb82f2..5d4e5ce 100644
--- a/kmicromail/libmailwrapper/nntpwrapper.h
+++ b/kmicromail/libmailwrapper/nntpwrapper.h
@@ -1,48 +1,49 @@
1// CHANGED 2004-09-31 Lutz Rogowski
1#ifndef __NNTPWRAPPER 2#ifndef __NNTPWRAPPER
2#define __NNTPWRAPPER 3#define __NNTPWRAPPER
3 4
4#include "mailwrapper.h" 5#include "mailwrapper.h"
5#include "genericwrapper.h" 6#include "genericwrapper.h"
6#include <qstring.h> 7#include <qstring.h>
7#include <libetpan/clist.h> 8#include <libetpan/clist.h>
8 9
9class encodedString; 10class encodedString;
10struct mailstorage; 11struct mailstorage;
11struct mailfolder; 12struct mailfolder;
12 13
13class NNTPwrapper : public Genericwrapper 14class NNTPwrapper : public Genericwrapper
14{ 15{
15 16
16 Q_OBJECT 17 Q_OBJECT
17 18
18public: 19public:
19 NNTPwrapper( NNTPaccount *a ); 20 NNTPwrapper( NNTPaccount *a );
20 virtual ~NNTPwrapper(); 21 virtual ~NNTPwrapper();
21 22
22 /* mailbox will be ignored */ 23 /* mailbox will be ignored */
23 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ); 24 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 );
24 /* should only get the subscribed one */ 25 /* should only get the subscribed one */
25 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 26 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
26 /* mailbox will be ignored */ 27 /* mailbox will be ignored */
27 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
28 QStringList listAllNewsgroups(const QString&mask = QString::null); 29 QStringList listAllNewsgroups(const QString&mask = QString::null);
29 virtual void deleteMail(const RecMailP&mail); 30 virtual void deleteMail(const RecMailP&mail);
30 virtual void answeredMail(const RecMailP&mail); 31 virtual void answeredMail(const RecMailP&mail);
31 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); 32 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&);
32 33
33 virtual RecBodyP fetchBody( const RecMailP &mail ); 34 virtual RecBodyP fetchBody( const RecMailP &mail );
34 virtual encodedString* fetchRawBody(const RecMailP&mail); 35 virtual encodedString* fetchRawBody(const RecMailP&mail);
35 virtual void logout(); 36 virtual void logout();
36 virtual MAILLIB::ATYPE getType()const; 37 virtual MAILLIB::ATYPE getType()const;
37 virtual const QString&getName()const; 38 virtual const QString&getName()const;
38 static void nntp_progress( size_t current, size_t maximum ); 39 static void nntp_progress( size_t current, size_t maximum );
39 40
40protected: 41protected:
41 void login(); 42 void login();
42 NNTPaccount *account; 43 NNTPaccount *account;
43 mailstorage* m_nntp; 44 mailstorage* m_nntp;
44 45
45 46
46}; 47};
47 48
48#endif 49#endif
diff --git a/kmicromail/libmailwrapper/pop3wrapper.cpp b/kmicromail/libmailwrapper/pop3wrapper.cpp
index e5d083a..7a84b30 100644
--- a/kmicromail/libmailwrapper/pop3wrapper.cpp
+++ b/kmicromail/libmailwrapper/pop3wrapper.cpp
@@ -1,265 +1,282 @@
1// CHANGED 2004-09-31 Lutz Rogowski
1#include <stdlib.h> 2#include <stdlib.h>
2#include "pop3wrapper.h" 3#include "pop3wrapper.h"
3#include "mailtypes.h" 4#include "mailtypes.h"
4#include "logindialog.h" 5#include "logindialog.h"
5#include <libetpan/libetpan.h> 6#include <libetpan/libetpan.h>
6 7
7 8
8#include <qpe/global.h> 9#include <qpe/global.h>
9#include <qfile.h> 10#include <qfile.h>
10 11
11/* we don't fetch messages larger than 5 MB */ 12/* we don't fetch messages larger than 5 MB */
12#define HARD_MSG_SIZE_LIMIT 5242880 13#define HARD_MSG_SIZE_LIMIT 5242880
13 14
14using namespace Opie::Core; 15using namespace Opie::Core;
15POP3wrapper::POP3wrapper( POP3account *a ) 16POP3wrapper::POP3wrapper( POP3account *a )
16: Genericwrapper() { 17: Genericwrapper() {
17 account = a; 18 account = a;
18 m_pop3 = NULL; 19 m_pop3 = NULL;
19 msgTempName = a->getFileName()+"_msg_cache"; 20 msgTempName = a->getFileName()+"_msg_cache";
20 last_msg_id = 0; 21 last_msg_id = 0;
21} 22}
22 23
23POP3wrapper::~POP3wrapper() { 24POP3wrapper::~POP3wrapper() {
24 logout(); 25 logout();
25 QFile msg_cache(msgTempName); 26 QFile msg_cache(msgTempName);
26 if (msg_cache.exists()) { 27 if (msg_cache.exists()) {
27 msg_cache.remove(); 28 msg_cache.remove();
28 } 29 }
29} 30}
30 31
31void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { 32void POP3wrapper::pop3_progress( size_t current, size_t maximum ) {
32 ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; 33 ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl;
33} 34}
34 35
35RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { 36RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) {
36 int err = MAILPOP3_NO_ERROR; 37 int err = MAILPOP3_NO_ERROR;
37 char *message = 0; 38 char *message = 0;
38 size_t length = 0; 39 size_t length = 0;
39 40
40 RecBodyP body = new RecBody(); 41 RecBodyP body = new RecBody();
41 42
42 login(); 43 login();
43 if ( !m_pop3 ) { 44 if ( !m_pop3 ) {
44 return body; 45 return body;
45 } 46 }
46 47
47 mailmessage * mailmsg; 48 mailmessage * mailmsg;
48 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { 49 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) {
49 ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl; 50 ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl;
50 return body; 51 return body;
51 } 52 }
52 53
53 QFile msg_cache(msgTempName); 54 QFile msg_cache(msgTempName);
54 55
55 cleanMimeCache(); 56 cleanMimeCache();
56 57
57 if (mail->getNumber()!=last_msg_id) { 58 if (mail->getNumber()!=last_msg_id) {
58 if (msg_cache.exists()) { 59 if (msg_cache.exists()) {
59 msg_cache.remove(); 60 msg_cache.remove();
60 } 61 }
61 msg_cache.open(IO_ReadWrite|IO_Truncate); 62 msg_cache.open(IO_ReadWrite|IO_Truncate);
62 last_msg_id = mail->getNumber(); 63 last_msg_id = mail->getNumber();
63 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 64 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
64 err = mailmessage_fetch(mailmsg,&message,&length); 65 err = mailmessage_fetch(mailmsg,&message,&length);
65 msg_cache.writeBlock(message,length); 66 msg_cache.writeBlock(message,length);
66 } else { 67 } else {
67 QString msg=""; 68 QString msg="";
68 msg_cache.open(IO_ReadOnly); 69 msg_cache.open(IO_ReadOnly);
69 message = new char[4096]; 70 message = new char[4096];
70 memset(message,0,4096); 71 memset(message,0,4096);
71 while (msg_cache.readBlock(message,4095)>0) { 72 while (msg_cache.readBlock(message,4095)>0) {
72 msg+=message; 73 msg+=message;
73 memset(message,0,4096); 74 memset(message,0,4096);
74 } 75 }
75 delete message; 76 delete message;
76 message = (char*)malloc(msg.length()+1*sizeof(char)); 77 message = (char*)malloc(msg.length()+1*sizeof(char));
77 memset(message,0,msg.length()+1); 78 memset(message,0,msg.length()+1);
78 memcpy(message,msg.latin1(),msg.length()); 79 memcpy(message,msg.latin1(),msg.length());
79 /* transform to libetpan stuff */ 80 /* transform to libetpan stuff */
80 mailmsg = mailmessage_new(); 81 mailmsg = mailmessage_new();
81 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 82 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
82 generic_message_t * msg_data; 83 generic_message_t * msg_data;
83 msg_data = (generic_message_t *)mailmsg->msg_data; 84 msg_data = (generic_message_t *)mailmsg->msg_data;
84 msg_data->msg_fetched = 1; 85 msg_data->msg_fetched = 1;
85 msg_data->msg_message = message; 86 msg_data->msg_message = message;
86 msg_data->msg_length = strlen(message); 87 msg_data->msg_length = strlen(message);
87 } 88 }
88 body = parseMail(mailmsg); 89 body = parseMail(mailmsg);
89 90
90 /* clean up */ 91 /* clean up */
91 if (mailmsg) 92 if (mailmsg)
92 mailmessage_free(mailmsg); 93 mailmessage_free(mailmsg);
93 if (message) 94 if (message)
94 free(message); 95 free(message);
95 96
96 return body; 97 return body;
97} 98}
98 99
99void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) 100void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb )
100{ 101{
101 login(); 102 login();
102 if (!m_pop3) 103 if (!m_pop3)
103 return; 104 return;
104 uint32_t res_messages,res_recent,res_unseen; 105 uint32_t res_messages,res_recent,res_unseen;
105 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); 106 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen);
106 parseList(target,m_pop3->sto_session,"INBOX"); 107 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb);
107 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); 108 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
108} 109}
109 110
110void POP3wrapper::login() 111void POP3wrapper::login()
111{ 112{
112 if (account->getOffline()) 113 if (account->getOffline())
113 return; 114 return;
114 /* we'll hold the line */ 115 /* we'll hold the line */
115 if ( m_pop3 != NULL ) 116 if ( m_pop3 != NULL )
116 return; 117 return;
117 118
118 const char *server, *user, *pass; 119 const char *server, *user, *pass;
119 uint16_t port; 120 uint16_t port;
120 int err = MAILPOP3_NO_ERROR; 121 int err = MAILPOP3_NO_ERROR;
121 122
122 server = account->getServer().latin1(); 123 server = account->getServer().latin1();
123 port = account->getPort().toUInt(); 124 port = account->getPort().toUInt();
124 125
125 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 126 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
126 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 127 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
127 login.show(); 128 login.show();
128 if ( QDialog::Accepted == login.exec() ) { 129 if ( QDialog::Accepted == login.exec() ) {
129 // ok 130 // ok
130 user = login.getUser().latin1(); 131 user = login.getUser().latin1();
131 pass = login.getPassword().latin1(); 132 pass = login.getPassword().latin1();
132 } else { 133 } else {
133 // cancel 134 // cancel
134 ; // odebug << "POP3: Login canceled" << oendl; 135 ; // odebug << "POP3: Login canceled" << oendl;
135 return; 136 return;
136 } 137 }
137 } else { 138 } else {
138 user = account->getUser().latin1(); 139 user = account->getUser().latin1();
139 pass = account->getPassword().latin1(); 140 pass = account->getPassword().latin1();
140 } 141 }
141 142
142 // bool ssl = account->getSSL(); 143 // bool ssl = account->getSSL();
143 144
144 m_pop3=mailstorage_new(NULL); 145 m_pop3=mailstorage_new(NULL);
145 146
146 int conntypeset = account->ConnectionType(); 147 int conntypeset = account->ConnectionType();
147 int conntype = 0; 148 int conntype = 0;
148 if ( conntypeset == 3 ) { 149 if ( conntypeset == 3 ) {
149 conntype = CONNECTION_TYPE_COMMAND; 150 conntype = CONNECTION_TYPE_COMMAND;
150 } else if ( conntypeset == 2 ) { 151 } else if ( conntypeset == 2 ) {
151 conntype = CONNECTION_TYPE_TLS; 152 conntype = CONNECTION_TYPE_TLS;
152 } else if ( conntypeset == 1 ) { 153 } else if ( conntypeset == 1 ) {
153 conntype = CONNECTION_TYPE_STARTTLS; 154 conntype = CONNECTION_TYPE_STARTTLS;
154 } else if ( conntypeset == 0 ) { 155 } else if ( conntypeset == 0 ) {
155 conntype = CONNECTION_TYPE_TRY_STARTTLS; 156 conntype = CONNECTION_TYPE_TRY_STARTTLS;
156 } 157 }
157 158
158 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); 159 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN);
159 160
160 pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, 161 pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN,
161 (char*)user,(char*)pass,0,0,0); 162 (char*)user,(char*)pass,0,0,0);
162 163
163 164
164 err = mailstorage_connect(m_pop3); 165 err = mailstorage_connect(m_pop3);
165 if (err != MAIL_NO_ERROR) { 166 if (err != MAIL_NO_ERROR) {
166 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; 167 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl;
167 Global::statusMessage(tr("Error initializing folder")); 168 Global::statusMessage(tr("Error initializing folder"));
168 mailstorage_free(m_pop3); 169 mailstorage_free(m_pop3);
169 m_pop3 = 0; 170 m_pop3 = 0;
170 } else { 171 } else {
171 mailsession * session = m_pop3->sto_session; 172 mailsession * session = m_pop3->sto_session;
172 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; 173 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session;
173 if (mail) { 174 if (mail) {
174 mail->pop3_progr_fun = &pop3_progress; 175 mail->pop3_progr_fun = &pop3_progress;
175 } 176 }
176 } 177 }
177} 178}
178 179
179void POP3wrapper::logout() 180void POP3wrapper::logout()
180{ 181{
181 if ( m_pop3 == NULL ) 182 if ( m_pop3 == NULL )
182 return; 183 return;
183 mailstorage_free(m_pop3); 184 mailstorage_free(m_pop3);
184 m_pop3 = 0; 185 m_pop3 = 0;
185} 186}
186 187
187 188
188QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { 189QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() {
189 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); 190 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>();
190 FolderP inb=new Folder("INBOX","/"); 191 FolderP inb=new Folder("INBOX","/");
191 folders->append(inb); 192 folders->append(inb);
192 return folders; 193 return folders;
193} 194}
194 195
196void POP3wrapper::deleteMailList(QValueList<RecMailP>&target)
197{
198 login();
199 if (!m_pop3)
200 return;
201 int iii = 0;
202 int count = target.count();
203 while (iii < count ) {
204 RecMailP mail = (*target.at( iii ));
205 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
206 if (err != MAIL_NO_ERROR) {
207 Global::statusMessage(tr("error deleting mail"));
208 }
209 ++iii;
210 }
211}
195void POP3wrapper::deleteMail(const RecMailP&mail) { 212void POP3wrapper::deleteMail(const RecMailP&mail) {
196 login(); 213 login();
197 if (!m_pop3) 214 if (!m_pop3)
198 return; 215 return;
199 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); 216 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
200 if (err != MAIL_NO_ERROR) { 217 if (err != MAIL_NO_ERROR) {
201 Global::statusMessage(tr("error deleting mail")); 218 Global::statusMessage(tr("error deleting mail"));
202 } 219 }
203} 220}
204 221
205void POP3wrapper::answeredMail(const RecMailP&) {} 222void POP3wrapper::answeredMail(const RecMailP&) {}
206 223
207int POP3wrapper::deleteAllMail(const FolderP&) { 224int POP3wrapper::deleteAllMail(const FolderP&) {
208 login(); 225 login();
209 if (!m_pop3) 226 if (!m_pop3)
210 return 0; 227 return 0;
211 int res = 1; 228 int res = 1;
212 229
213 uint32_t result = 0; 230 uint32_t result = 0;
214 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); 231 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result);
215 if (err != MAIL_NO_ERROR) { 232 if (err != MAIL_NO_ERROR) {
216 Global::statusMessage(tr("Error getting folder info")); 233 Global::statusMessage(tr("Error getting folder info"));
217 return 0; 234 return 0;
218 } 235 }
219 for (unsigned int i = 0; i < result; ++i) { 236 for (unsigned int i = 0; i < result; ++i) {
220 err = mailsession_remove_message(m_pop3->sto_session,i+1); 237 err = mailsession_remove_message(m_pop3->sto_session,i+1);
221 if (err != MAIL_NO_ERROR) { 238 if (err != MAIL_NO_ERROR) {
222 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 239 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
223 res=0; 240 res=0;
224 } 241 }
225 break; 242 break;
226 } 243 }
227 return res; 244 return res;
228} 245}
229 246
230void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { 247void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) {
231 login(); 248 login();
232 target_stat.message_count = 0; 249 target_stat.message_count = 0;
233 target_stat.message_unseen = 0; 250 target_stat.message_unseen = 0;
234 target_stat.message_recent = 0; 251 target_stat.message_recent = 0;
235 if (!m_pop3) 252 if (!m_pop3)
236 return; 253 return;
237 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, 254 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count,
238 &target_stat.message_recent,&target_stat.message_unseen); 255 &target_stat.message_recent,&target_stat.message_unseen);
239 if (r != MAIL_NO_ERROR) { 256 if (r != MAIL_NO_ERROR) {
240 ; // odebug << "error getting folter status." << oendl; 257 ; // odebug << "error getting folter status." << oendl;
241 } 258 }
242} 259}
243 260
244encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { 261encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) {
245 char*target=0; 262 char*target=0;
246 size_t length=0; 263 size_t length=0;
247 encodedString*res = 0; 264 encodedString*res = 0;
248 mailmessage * mailmsg = 0; 265 mailmessage * mailmsg = 0;
249 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 266 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
250 err = mailmessage_fetch(mailmsg,&target,&length); 267 err = mailmessage_fetch(mailmsg,&target,&length);
251 if (mailmsg) 268 if (mailmsg)
252 mailmessage_free(mailmsg); 269 mailmessage_free(mailmsg);
253 if (target) { 270 if (target) {
254 res = new encodedString(target,length); 271 res = new encodedString(target,length);
255 } 272 }
256 return res; 273 return res;
257} 274}
258 275
259MAILLIB::ATYPE POP3wrapper::getType()const { 276MAILLIB::ATYPE POP3wrapper::getType()const {
260 return account->getType(); 277 return account->getType();
261} 278}
262 279
263const QString&POP3wrapper::getName()const{ 280const QString&POP3wrapper::getName()const{
264 return account->getAccountName(); 281 return account->getAccountName();
265} 282}
diff --git a/kmicromail/libmailwrapper/pop3wrapper.h b/kmicromail/libmailwrapper/pop3wrapper.h
index 5101fa5..ee754a4 100644
--- a/kmicromail/libmailwrapper/pop3wrapper.h
+++ b/kmicromail/libmailwrapper/pop3wrapper.h
@@ -1,42 +1,44 @@
1// CHANGED 2004-09-31 Lutz Rogowski
1#ifndef __POP3WRAPPER 2#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 3#define __POP3WRAPPER
3 4
4#include "mailwrapper.h" 5#include "mailwrapper.h"
5#include "genericwrapper.h" 6#include "genericwrapper.h"
6#include <qstring.h> 7#include <qstring.h>
7 8
8class encodedString; 9class encodedString;
9struct mailstorage; 10struct mailstorage;
10struct mailfolder; 11struct mailfolder;
11 12
12class POP3wrapper : public Genericwrapper 13class POP3wrapper : public Genericwrapper
13{ 14{
14 Q_OBJECT 15 Q_OBJECT
15 16
16public: 17public:
17 POP3wrapper( POP3account *a ); 18 POP3wrapper( POP3account *a );
18 virtual ~POP3wrapper(); 19 virtual ~POP3wrapper();
19 /* mailbox will be ignored */ 20 /* mailbox will be ignored */
20 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ); 21 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 );
21 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 22 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
22 /* mailbox will be ignored */ 23 /* mailbox will be ignored */
23 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
24 25
25 virtual void deleteMail(const RecMailP&mail); 26 virtual void deleteMail(const RecMailP&mail);
26 virtual void answeredMail(const RecMailP&mail); 27 virtual void answeredMail(const RecMailP&mail);
28 virtual void deleteMailList(QValueList<RecMailP>&target);
27 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); 29 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&);
28 30
29 virtual RecBodyP fetchBody( const RecMailP &mail ); 31 virtual RecBodyP fetchBody( const RecMailP &mail );
30 virtual encodedString* fetchRawBody(const RecMailP&mail); 32 virtual encodedString* fetchRawBody(const RecMailP&mail);
31 virtual void logout(); 33 virtual void logout();
32 virtual MAILLIB::ATYPE getType()const; 34 virtual MAILLIB::ATYPE getType()const;
33 virtual const QString&getName()const; 35 virtual const QString&getName()const;
34 static void pop3_progress( size_t current, size_t maximum ); 36 static void pop3_progress( size_t current, size_t maximum );
35 37
36protected: 38protected:
37 void login(); 39 void login();
38 POP3account *account; 40 POP3account *account;
39 mailstorage*m_pop3; 41 mailstorage*m_pop3;
40}; 42};
41 43
42#endif 44#endif