39 files changed, 6775 insertions, 0 deletions
diff --git a/kmicromail/libmailwrapper/.cvsignore b/kmicromail/libmailwrapper/.cvsignore new file mode 100644 index 0000000..581c299 --- a/dev/null +++ b/kmicromail/libmailwrapper/.cvsignore | |||
@@ -0,0 +1,6 @@ | |||
1 | logindialogui.cpp | ||
2 | logindialogui.h | ||
3 | sendmailprogressui.cpp | ||
4 | sendmailprogressui.h | ||
5 | .moc | ||
6 | Makefile | ||
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp new file mode 100644 index 0000000..128a7c0 --- a/dev/null +++ b/kmicromail/libmailwrapper/abstractmail.cpp | |||
@@ -0,0 +1,172 @@ | |||
1 | #include "abstractmail.h" | ||
2 | #include "imapwrapper.h" | ||
3 | #include "pop3wrapper.h" | ||
4 | #include "nntpwrapper.h" | ||
5 | #include "mhwrapper.h" | ||
6 | #include "mailtypes.h" | ||
7 | |||
8 | |||
9 | |||
10 | #include <kdecore/kstandarddirs.h> | ||
11 | #include <qfile.h> | ||
12 | #include <qtextstream.h> | ||
13 | #include <stdlib.h> | ||
14 | #include <libetpan/mailmime_content.h> | ||
15 | #include <libetpan/mailmime.h> | ||
16 | |||
17 | using namespace Opie::Core; | ||
18 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) | ||
19 | { | ||
20 | return new IMAPwrapper(a); | ||
21 | } | ||
22 | |||
23 | AbstractMail* AbstractMail::getWrapper(POP3account *a) | ||
24 | { | ||
25 | return new POP3wrapper(a); | ||
26 | } | ||
27 | |||
28 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) | ||
29 | { | ||
30 | return new NNTPwrapper(a); | ||
31 | } | ||
32 | |||
33 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) | ||
34 | { | ||
35 | return new MHwrapper(a,name); | ||
36 | } | ||
37 | |||
38 | AbstractMail* AbstractMail::getWrapper(Account*a) | ||
39 | { | ||
40 | if (!a) return 0; | ||
41 | switch (a->getType()) { | ||
42 | case MAILLIB::A_IMAP: | ||
43 | return new IMAPwrapper((IMAPaccount*)a); | ||
44 | break; | ||
45 | case MAILLIB::A_POP3: | ||
46 | return new POP3wrapper((POP3account*)a); | ||
47 | break; | ||
48 | case MAILLIB::A_NNTP: | ||
49 | return new NNTPwrapper((NNTPaccount*)a); | ||
50 | break; | ||
51 | default: | ||
52 | return 0; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) | ||
57 | { | ||
58 | // odebug << "Decode string start" << oendl; | ||
59 | char*result_text; | ||
60 | size_t index = 0; | ||
61 | /* reset for recursive use! */ | ||
62 | size_t target_length = 0; | ||
63 | result_text = 0; | ||
64 | int mimetype = MAILMIME_MECHANISM_7BIT; | ||
65 | if (enc.lower()=="quoted-printable") { | ||
66 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | ||
67 | } else if (enc.lower()=="base64") { | ||
68 | mimetype = MAILMIME_MECHANISM_BASE64; | ||
69 | } else if (enc.lower()=="8bit") { | ||
70 | mimetype = MAILMIME_MECHANISM_8BIT; | ||
71 | } else if (enc.lower()=="binary") { | ||
72 | mimetype = MAILMIME_MECHANISM_BINARY; | ||
73 | } | ||
74 | |||
75 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, | ||
76 | &result_text,&target_length); | ||
77 | |||
78 | encodedString* result = new encodedString(); | ||
79 | if (err == MAILIMF_NO_ERROR) { | ||
80 | result->setContent(result_text,target_length); | ||
81 | } | ||
82 | //odebug << "Decode string finished" << oendl; | ||
83 | return result; | ||
84 | } | ||
85 | |||
86 | QString AbstractMail::convert_String(const char*text) | ||
87 | { | ||
88 | //size_t index = 0; | ||
89 | char*res = 0; | ||
90 | int err = MAILIMF_NO_ERROR; | ||
91 | |||
92 | QString result(text); | ||
93 | |||
94 | /* due a bug in libetpan it isn't usable this moment */ | ||
95 | /* int err = mailmime_encoded_phrase_parse("iso-8859-1", | ||
96 | text, strlen(text),&index, "iso-8859-1",&res);*/ | ||
97 | //odebug << "Input: " << text << "" << oendl; | ||
98 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { | ||
99 | // result = QString(res); | ||
100 | // odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl; | ||
101 | } | ||
102 | if (res) free(res); | ||
103 | return result; | ||
104 | } | ||
105 | |||
106 | /* cp & paste from launcher */ | ||
107 | QString AbstractMail::gen_attachment_id() | ||
108 | { | ||
109 | QFile file( "/proc/sys/kernel/random/uuid" ); | ||
110 | if (!file.open(IO_ReadOnly ) ) | ||
111 | return QString::null; | ||
112 | |||
113 | QTextStream stream(&file); | ||
114 | |||
115 | return "{" + stream.read().stripWhiteSpace() + "}"; | ||
116 | } | ||
117 | |||
118 | int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) | ||
119 | { | ||
120 | return 0; | ||
121 | } | ||
122 | |||
123 | QString AbstractMail::defaultLocalfolder() | ||
124 | { | ||
125 | // QString f = getenv( "HOME" ); | ||
126 | QString f = locateLocal( "data", "kmicromail/localmail"); | ||
127 | // f += "/Applications/opiemail/localmail"; | ||
128 | return f; | ||
129 | } | ||
130 | |||
131 | QString AbstractMail::draftFolder() | ||
132 | { | ||
133 | return QString("Drafts"); | ||
134 | } | ||
135 | |||
136 | /* temporary - will be removed when implemented in all classes */ | ||
137 | void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) | ||
138 | { | ||
139 | } | ||
140 | |||
141 | void AbstractMail::mvcpAllMails(const FolderP&fromFolder, | ||
142 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | ||
143 | { | ||
144 | QValueList<RecMailP> t; | ||
145 | listMessages(fromFolder->getName(),t); | ||
146 | encodedString*st = 0; | ||
147 | while (t.count()>0) { | ||
148 | RecMailP r = (*t.begin()); | ||
149 | st = fetchRawBody(r); | ||
150 | if (st) { | ||
151 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); | ||
152 | delete st; | ||
153 | } | ||
154 | t.remove(t.begin()); | ||
155 | } | ||
156 | if (moveit) { | ||
157 | deleteAllMail(fromFolder); | ||
158 | } | ||
159 | } | ||
160 | |||
161 | void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | ||
162 | { | ||
163 | encodedString*st = 0; | ||
164 | st = fetchRawBody(mail); | ||
165 | if (st) { | ||
166 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); | ||
167 | delete st; | ||
168 | } | ||
169 | if (moveit) { | ||
170 | deleteMail(mail); | ||
171 | } | ||
172 | } | ||
diff --git a/kmicromail/libmailwrapper/abstractmail.h b/kmicromail/libmailwrapper/abstractmail.h new file mode 100644 index 0000000..e5d64a6 --- a/dev/null +++ b/kmicromail/libmailwrapper/abstractmail.h | |||
@@ -0,0 +1,72 @@ | |||
1 | #ifndef __abstract_mail_ | ||
2 | #define __abstract_mail_ | ||
3 | |||
4 | #include "maildefines.h" | ||
5 | |||
6 | #include "settings.h" | ||
7 | |||
8 | #include <qobject.h> | ||
9 | #include <opie2/osmartpointer.h> | ||
10 | #include "mailtypes.h" | ||
11 | |||
12 | class IMAPwrapper; | ||
13 | class POP3wrapper; | ||
14 | class Folder; | ||
15 | class encodedString; | ||
16 | struct folderStat; | ||
17 | |||
18 | class AbstractMail:public QObject | ||
19 | { | ||
20 | Q_OBJECT | ||
21 | public: | ||
22 | AbstractMail(){}; | ||
23 | virtual ~AbstractMail(){} | ||
24 | virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders()=0; | ||
25 | virtual void listMessages(const QString & mailbox,QValueList<RecMailP>&target )=0; | ||
26 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0; | ||
27 | virtual RecBodyP fetchBody(const RecMailP&mail)=0; | ||
28 | virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part)=0; | ||
29 | virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part)=0; | ||
30 | virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part)=0; | ||
31 | virtual encodedString* fetchRawBody(const RecMailP&mail)=0; | ||
32 | |||
33 | virtual void deleteMail(const RecMailP&mail)=0; | ||
34 | virtual void answeredMail(const RecMailP&mail)=0; | ||
35 | virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&)=0; | ||
36 | virtual void deleteMails(const QString & FolderName,const QValueList<Opie::Core::OSmartPointer<RecMail> >&target); | ||
37 | virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&)=0; | ||
38 | virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0; | ||
39 | |||
40 | virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, | ||
41 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | ||
42 | virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | ||
43 | |||
44 | virtual void cleanMimeCache(){}; | ||
45 | /* mail box methods */ | ||
46 | /* parameter is the box to create. | ||
47 | * if the implementing subclass has prefixes, | ||
48 | * them has to be appended automatic. | ||
49 | */ | ||
50 | virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0, | ||
51 | const QString& delemiter="/",bool getsubfolder=false); | ||
52 | virtual void logout()=0; | ||
53 | |||
54 | static AbstractMail* getWrapper(IMAPaccount *a); | ||
55 | static AbstractMail* getWrapper(POP3account *a); | ||
56 | static AbstractMail* getWrapper(NNTPaccount *a); | ||
57 | /* mbox only! */ | ||
58 | static AbstractMail* getWrapper(const QString&a,const QString&name="Local Folders"); | ||
59 | static AbstractMail* getWrapper(Account*a); | ||
60 | |||
61 | static QString defaultLocalfolder(); | ||
62 | static QString draftFolder(); | ||
63 | |||
64 | virtual MAILLIB::ATYPE getType()const=0; | ||
65 | virtual const QString&getName()const=0; | ||
66 | |||
67 | protected: | ||
68 | static encodedString*decode_String(const encodedString*text,const QString&enc); | ||
69 | static QString convert_String(const char*text); | ||
70 | static QString gen_attachment_id(); | ||
71 | }; | ||
72 | #endif | ||
diff --git a/kmicromail/libmailwrapper/config.in b/kmicromail/libmailwrapper/config.in new file mode 100644 index 0000000..7da4a05 --- a/dev/null +++ b/kmicromail/libmailwrapper/config.in | |||
@@ -0,0 +1,4 @@ | |||
1 | config LIBMAILWRAPPER | ||
2 | boolean "libmailwrapper (libetpan wrapper library)" | ||
3 | default "y" | ||
4 | depends ( LIBQPE || LIBQPE-X11 ) && LIBETPAN_DEP | ||
diff --git a/kmicromail/libmailwrapper/generatemail.cpp b/kmicromail/libmailwrapper/generatemail.cpp new file mode 100644 index 0000000..49315ba --- a/dev/null +++ b/kmicromail/libmailwrapper/generatemail.cpp | |||
@@ -0,0 +1,460 @@ | |||
1 | #include "generatemail.h" | ||
2 | #include "mailwrapper.h" | ||
3 | |||
4 | #include <libetpan/libetpan.h> | ||
5 | |||
6 | //#include <qt.h> | ||
7 | |||
8 | #include <stdlib.h> | ||
9 | #include <qfileinfo.h> | ||
10 | |||
11 | using namespace Opie::Core; | ||
12 | const char* Generatemail::USER_AGENT="OpieMail v0.6"; | ||
13 | |||
14 | Generatemail::Generatemail() | ||
15 | { | ||
16 | } | ||
17 | |||
18 | Generatemail::~Generatemail() | ||
19 | { | ||
20 | } | ||
21 | |||
22 | void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) { | ||
23 | clistiter *it, *it2; | ||
24 | |||
25 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | ||
26 | mailimf_address *addr; | ||
27 | addr = (mailimf_address *) it->data; | ||
28 | |||
29 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | ||
30 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | ||
31 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { | ||
32 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | ||
33 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | ||
34 | mailimf_mailbox *mbox; | ||
35 | mbox = (mailimf_mailbox *) it2->data; | ||
36 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | ||
37 | } | ||
38 | } | ||
39 | } | ||
40 | } | ||
41 | |||
42 | char *Generatemail::getFrom( mailimf_field *ffrom) { | ||
43 | char *from = NULL; | ||
44 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | ||
45 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | ||
46 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | ||
47 | clistiter *it; | ||
48 | for ( it = clist_begin( cl ); it; it = it->next ) { | ||
49 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | ||
50 | from = strdup( mb->mb_addr_spec ); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | return from; | ||
55 | } | ||
56 | |||
57 | char *Generatemail::getFrom( mailmime *mail ) { | ||
58 | /* no need to delete - its just a pointer to structure content */ | ||
59 | mailimf_field *ffrom = 0; | ||
60 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | ||
61 | return getFrom(ffrom); | ||
62 | } | ||
63 | |||
64 | mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) { | ||
65 | mailimf_field *field; | ||
66 | clistiter *it; | ||
67 | |||
68 | it = clist_begin( fields->fld_list ); | ||
69 | while ( it ) { | ||
70 | field = (mailimf_field *) it->data; | ||
71 | if ( field->fld_type == type ) { | ||
72 | return field; | ||
73 | } | ||
74 | it = it->next; | ||
75 | } | ||
76 | |||
77 | return NULL; | ||
78 | } | ||
79 | |||
80 | mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) { | ||
81 | mailimf_address_list *addresses; | ||
82 | |||
83 | if ( addr.isEmpty() ) | ||
84 | return NULL; | ||
85 | |||
86 | addresses = mailimf_address_list_new_empty(); | ||
87 | |||
88 | bool literal_open = false; | ||
89 | unsigned int startpos = 0; | ||
90 | QStringList list; | ||
91 | QString s; | ||
92 | unsigned int i = 0; | ||
93 | for (; i < addr.length();++i) { | ||
94 | switch (addr[i]) { | ||
95 | case '\"': | ||
96 | literal_open = !literal_open; | ||
97 | break; | ||
98 | case ',': | ||
99 | if (!literal_open) { | ||
100 | s = addr.mid(startpos,i-startpos); | ||
101 | if (!s.isEmpty()) { | ||
102 | list.append(s); | ||
103 | } | ||
104 | // !!!! this is a MUST BE! | ||
105 | startpos = ++i; | ||
106 | } | ||
107 | break; | ||
108 | default: | ||
109 | break; | ||
110 | } | ||
111 | } | ||
112 | s = addr.mid(startpos,i-startpos); | ||
113 | if (!s.isEmpty()) { | ||
114 | list.append(s); | ||
115 | } | ||
116 | QStringList::Iterator it; | ||
117 | for ( it = list.begin(); it != list.end(); it++ ) { | ||
118 | int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); | ||
119 | if ( err != MAILIMF_NO_ERROR ) { | ||
120 | qDebug(" Error parsing"); // *it | ||
121 | } else { | ||
122 | } | ||
123 | } | ||
124 | return addresses; | ||
125 | } | ||
126 | |||
127 | mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { | ||
128 | mailmime * filePart = 0; | ||
129 | mailmime_fields * fields = 0; | ||
130 | mailmime_content * content = 0; | ||
131 | mailmime_parameter * param = 0; | ||
132 | char*name = 0; | ||
133 | char*file = 0; | ||
134 | int err; | ||
135 | |||
136 | int pos = filename.findRev( '/' ); | ||
137 | |||
138 | if (filename.length()>0) { | ||
139 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | ||
140 | name = strdup( tmp.latin1() ); // just filename | ||
141 | file = strdup( filename.latin1() ); // full name with path | ||
142 | } | ||
143 | |||
144 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; | ||
145 | int mechanism = MAILMIME_MECHANISM_BASE64; | ||
146 | |||
147 | if ( mimetype.startsWith( "text/" ) ) { | ||
148 | param = mailmime_parameter_new( strdup( "charset" ), | ||
149 | strdup( "iso-8859-1" ) ); | ||
150 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | ||
151 | } | ||
152 | |||
153 | fields = mailmime_fields_new_filename( | ||
154 | disptype, name, | ||
155 | mechanism ); | ||
156 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); | ||
157 | if (content!=0 && fields != 0) { | ||
158 | if (param) { | ||
159 | clist_append(content->ct_parameters,param); | ||
160 | param = 0; | ||
161 | } | ||
162 | if (filename.length()>0) { | ||
163 | QFileInfo f(filename); | ||
164 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); | ||
165 | clist_append(content->ct_parameters,param); | ||
166 | param = 0; | ||
167 | } | ||
168 | filePart = mailmime_new_empty( content, fields ); | ||
169 | } | ||
170 | if (filePart) { | ||
171 | if (filename.length()>0) { | ||
172 | err = mailmime_set_body_file( filePart, file ); | ||
173 | } else { | ||
174 | err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); | ||
175 | } | ||
176 | if (err != MAILIMF_NO_ERROR) { | ||
177 | qDebug("Error setting body with file "); | ||
178 | mailmime_free( filePart ); | ||
179 | filePart = 0; | ||
180 | } | ||
181 | } | ||
182 | |||
183 | if (!filePart) { | ||
184 | if ( param != NULL ) { | ||
185 | mailmime_parameter_free( param ); | ||
186 | } | ||
187 | if (content) { | ||
188 | mailmime_content_free( content ); | ||
189 | } | ||
190 | if (fields) { | ||
191 | mailmime_fields_free( fields ); | ||
192 | } else { | ||
193 | if (name) { | ||
194 | free( name ); | ||
195 | } | ||
196 | if (file) { | ||
197 | free( file ); | ||
198 | } | ||
199 | } | ||
200 | } | ||
201 | return filePart; // Success :) | ||
202 | |||
203 | } | ||
204 | |||
205 | void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) { | ||
206 | const Attachment *it; | ||
207 | unsigned int count = files.count(); | ||
208 | for ( unsigned int i = 0; i < count; ++i ) { | ||
209 | mailmime *filePart; | ||
210 | int err; | ||
211 | it = ((QList<Attachment>)files).at(i); | ||
212 | |||
213 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); | ||
214 | if ( filePart == NULL ) { | ||
215 | continue; | ||
216 | } | ||
217 | err = mailmime_smart_add_part( message, filePart ); | ||
218 | if ( err != MAILIMF_NO_ERROR ) { | ||
219 | mailmime_free( filePart ); | ||
220 | } | ||
221 | } | ||
222 | } | ||
223 | |||
224 | mailmime *Generatemail::buildTxtPart(const QString&str ) { | ||
225 | mailmime *txtPart; | ||
226 | mailmime_fields *fields; | ||
227 | mailmime_content *content; | ||
228 | mailmime_parameter *param; | ||
229 | int err; | ||
230 | |||
231 | param = mailmime_parameter_new( strdup( "charset" ), | ||
232 | strdup( "iso-8859-1" ) ); | ||
233 | if ( param == NULL ) | ||
234 | goto err_free; | ||
235 | |||
236 | content = mailmime_content_new_with_str( "text/plain" ); | ||
237 | if ( content == NULL ) | ||
238 | goto err_free_param; | ||
239 | |||
240 | err = clist_append( content->ct_parameters, param ); | ||
241 | if ( err != MAILIMF_NO_ERROR ) | ||
242 | goto err_free_content; | ||
243 | |||
244 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); | ||
245 | if ( fields == NULL ) | ||
246 | goto err_free_content; | ||
247 | |||
248 | txtPart = mailmime_new_empty( content, fields ); | ||
249 | if ( txtPart == NULL ) | ||
250 | goto err_free_fields; | ||
251 | |||
252 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); | ||
253 | if ( err != MAILIMF_NO_ERROR ) | ||
254 | goto err_free_txtPart; | ||
255 | |||
256 | return txtPart; // Success :) | ||
257 | |||
258 | err_free_txtPart: | ||
259 | mailmime_free( txtPart ); | ||
260 | err_free_fields: | ||
261 | mailmime_fields_free( fields ); | ||
262 | err_free_content: | ||
263 | mailmime_content_free( content ); | ||
264 | err_free_param: | ||
265 | mailmime_parameter_free( param ); | ||
266 | err_free: | ||
267 | ; | ||
268 | |||
269 | return NULL; // Error :( | ||
270 | } | ||
271 | |||
272 | mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { | ||
273 | return mailimf_mailbox_new( strdup( name.latin1() ), | ||
274 | strdup( mail.latin1() ) ); | ||
275 | } | ||
276 | |||
277 | mailimf_fields *Generatemail::createImfFields(const Opie::Core::OSmartPointer<Mail>&mail ) | ||
278 | { | ||
279 | mailimf_fields *fields = NULL; | ||
280 | mailimf_field *xmailer = NULL; | ||
281 | mailimf_mailbox *sender=0,*fromBox=0; | ||
282 | mailimf_mailbox_list *from=0; | ||
283 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; | ||
284 | clist*in_reply_to = 0; | ||
285 | char *subject = strdup( mail->getSubject().latin1() ); | ||
286 | int err; | ||
287 | int res = 1; | ||
288 | |||
289 | sender = newMailbox( mail->getName(), mail->getMail() ); | ||
290 | if ( sender == NULL ) { | ||
291 | res = 0; | ||
292 | } | ||
293 | |||
294 | if (res) { | ||
295 | fromBox = newMailbox( mail->getName(), mail->getMail() ); | ||
296 | } | ||
297 | if ( fromBox == NULL ) { | ||
298 | res = 0; | ||
299 | } | ||
300 | |||
301 | if (res) { | ||
302 | from = mailimf_mailbox_list_new_empty(); | ||
303 | } | ||
304 | if ( from == NULL ) { | ||
305 | res = 0; | ||
306 | } | ||
307 | |||
308 | if (res && from) { | ||
309 | err = mailimf_mailbox_list_add( from, fromBox ); | ||
310 | if ( err != MAILIMF_NO_ERROR ) { | ||
311 | res = 0; | ||
312 | } | ||
313 | } | ||
314 | |||
315 | if (res) to = parseAddresses( mail->getTo() ); | ||
316 | if (res) cc = parseAddresses( mail->getCC() ); | ||
317 | if (res) bcc = parseAddresses( mail->getBCC() ); | ||
318 | if (res) reply = parseAddresses( mail->getReply() ); | ||
319 | |||
320 | if (res && mail->Inreply().count()>0) { | ||
321 | in_reply_to = clist_new(); | ||
322 | char*c_reply; | ||
323 | unsigned int nsize = 0; | ||
324 | for (QStringList::ConstIterator it=mail->Inreply().begin(); | ||
325 | it != mail->Inreply().end();++it) { | ||
326 | if ((*it).isEmpty()) | ||
327 | continue; | ||
328 | QString h((*it)); | ||
329 | while (h.length()>0 && h[0]=='<') { | ||
330 | h.remove(0,1); | ||
331 | } | ||
332 | while (h.length()>0 && h[h.length()-1]=='>') { | ||
333 | h.remove(h.length()-1,1); | ||
334 | } | ||
335 | if (h.isEmpty()) continue; | ||
336 | nsize = strlen(h.latin1()); | ||
337 | /* yes! must be malloc! */ | ||
338 | c_reply = (char*)malloc( (nsize+1)*sizeof(char)); | ||
339 | memset(c_reply,0,nsize+1); | ||
340 | memcpy(c_reply,h.latin1(),nsize); | ||
341 | clist_append(in_reply_to,c_reply); | ||
342 | } | ||
343 | } | ||
344 | |||
345 | if (res) { | ||
346 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | ||
347 | in_reply_to, NULL, subject ); | ||
348 | if ( fields == NULL ) { | ||
349 | res = 0; | ||
350 | } | ||
351 | } | ||
352 | if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | ||
353 | strdup( USER_AGENT ) ); | ||
354 | if ( xmailer == NULL ) { | ||
355 | res = 0; | ||
356 | } else { | ||
357 | err = mailimf_fields_add( fields, xmailer ); | ||
358 | if ( err != MAILIMF_NO_ERROR ) { | ||
359 | res = 0; | ||
360 | } | ||
361 | } | ||
362 | if (!res ) { | ||
363 | if (xmailer) { | ||
364 | mailimf_field_free( xmailer ); | ||
365 | xmailer = NULL; | ||
366 | } | ||
367 | if (fields) { | ||
368 | mailimf_fields_free( fields ); | ||
369 | fields = NULL; | ||
370 | } else { | ||
371 | if (reply) | ||
372 | mailimf_address_list_free( reply ); | ||
373 | if (bcc) | ||
374 | mailimf_address_list_free( bcc ); | ||
375 | if (cc) | ||
376 | mailimf_address_list_free( cc ); | ||
377 | if (to) | ||
378 | mailimf_address_list_free( to ); | ||
379 | if (fromBox) { | ||
380 | mailimf_mailbox_free( fromBox ); | ||
381 | } else if (from) { | ||
382 | mailimf_mailbox_list_free( from ); | ||
383 | } | ||
384 | if (sender) { | ||
385 | mailimf_mailbox_free( sender ); | ||
386 | } | ||
387 | if (subject) { | ||
388 | free( subject ); | ||
389 | } | ||
390 | } | ||
391 | } | ||
392 | return fields; | ||
393 | } | ||
394 | |||
395 | mailmime *Generatemail::createMimeMail(const Opie::Core::OSmartPointer<Mail> &mail ) { | ||
396 | mailmime *message, *txtPart; | ||
397 | mailimf_fields *fields; | ||
398 | int err; | ||
399 | |||
400 | fields = createImfFields( mail ); | ||
401 | if ( fields == NULL ) | ||
402 | goto err_free; | ||
403 | |||
404 | message = mailmime_new_message_data( NULL ); | ||
405 | if ( message == NULL ) | ||
406 | goto err_free_fields; | ||
407 | |||
408 | mailmime_set_imf_fields( message, fields ); | ||
409 | |||
410 | txtPart = buildTxtPart( mail->getMessage() ); | ||
411 | |||
412 | if ( txtPart == NULL ) | ||
413 | goto err_free_message; | ||
414 | |||
415 | err = mailmime_smart_add_part( message, txtPart ); | ||
416 | if ( err != MAILIMF_NO_ERROR ) | ||
417 | goto err_free_txtPart; | ||
418 | |||
419 | addFileParts( message, mail->getAttachments() ); | ||
420 | |||
421 | return message; // Success :) | ||
422 | |||
423 | err_free_txtPart: | ||
424 | mailmime_free( txtPart ); | ||
425 | err_free_message: | ||
426 | mailmime_free( message ); | ||
427 | err_free_fields: | ||
428 | mailimf_fields_free( fields ); | ||
429 | err_free: | ||
430 | ; | ||
431 | |||
432 | return NULL; // Error :( | ||
433 | } | ||
434 | |||
435 | clist *Generatemail::createRcptList( mailimf_fields *fields ) { | ||
436 | clist *rcptList; | ||
437 | mailimf_field *field; | ||
438 | |||
439 | rcptList = esmtp_address_list_new(); | ||
440 | |||
441 | field = getField( fields, MAILIMF_FIELD_TO ); | ||
442 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) | ||
443 | && field->fld_data.fld_to->to_addr_list ) { | ||
444 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); | ||
445 | } | ||
446 | |||
447 | field = getField( fields, MAILIMF_FIELD_CC ); | ||
448 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) | ||
449 | && field->fld_data.fld_cc->cc_addr_list ) { | ||
450 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); | ||
451 | } | ||
452 | |||
453 | field = getField( fields, MAILIMF_FIELD_BCC ); | ||
454 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) | ||
455 | && field->fld_data.fld_bcc->bcc_addr_list ) { | ||
456 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); | ||
457 | } | ||
458 | |||
459 | return rcptList; | ||
460 | } | ||
diff --git a/kmicromail/libmailwrapper/generatemail.h b/kmicromail/libmailwrapper/generatemail.h new file mode 100644 index 0000000..a767b61 --- a/dev/null +++ b/kmicromail/libmailwrapper/generatemail.h | |||
@@ -0,0 +1,46 @@ | |||
1 | #ifndef __GENERATE_MAIL_H | ||
2 | #define __GENERATE_MAIL_H | ||
3 | |||
4 | #include <qpe/applnk.h> | ||
5 | |||
6 | #include <qobject.h> | ||
7 | #include <libetpan/clist.h> | ||
8 | |||
9 | #include <opie2/osmartpointer.h> | ||
10 | |||
11 | class Mail; | ||
12 | class RecMail; | ||
13 | class Attachment; | ||
14 | struct mailimf_fields; | ||
15 | struct mailimf_field; | ||
16 | struct mailimf_mailbox; | ||
17 | struct mailmime; | ||
18 | struct mailimf_address_list; | ||
19 | class progressMailSend; | ||
20 | struct mailsmtp; | ||
21 | |||
22 | class Generatemail : public QObject | ||
23 | { | ||
24 | Q_OBJECT | ||
25 | public: | ||
26 | Generatemail(); | ||
27 | virtual ~Generatemail(); | ||
28 | |||
29 | protected: | ||
30 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); | ||
31 | static char *getFrom( mailmime *mail ); | ||
32 | static char *getFrom( mailimf_field *ffrom); | ||
33 | static mailimf_field *getField( mailimf_fields *fields, int type ); | ||
34 | mailimf_address_list *parseAddresses(const QString&addr ); | ||
35 | void addFileParts( mailmime *message,const QList<Attachment>&files ); | ||
36 | mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); | ||
37 | mailmime *buildTxtPart(const QString&str ); | ||
38 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | ||
39 | mailimf_fields *createImfFields(const Opie::Core::OSmartPointer<Mail> &mail ); | ||
40 | mailmime *createMimeMail(const Opie::Core::OSmartPointer<Mail>&mail ); | ||
41 | clist *createRcptList( mailimf_fields *fields ); | ||
42 | |||
43 | static const char* USER_AGENT; | ||
44 | }; | ||
45 | |||
46 | #endif | ||
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp new file mode 100644 index 0000000..f804e44 --- a/dev/null +++ b/kmicromail/libmailwrapper/genericwrapper.cpp | |||
@@ -0,0 +1,480 @@ | |||
1 | #include "genericwrapper.h" | ||
2 | #include <libetpan/libetpan.h> | ||
3 | #include "mailtypes.h" | ||
4 | |||
5 | |||
6 | |||
7 | using namespace Opie::Core; | ||
8 | Genericwrapper::Genericwrapper() | ||
9 | : AbstractMail() | ||
10 | { | ||
11 | bodyCache.clear(); | ||
12 | m_storage = 0; | ||
13 | m_folder = 0; | ||
14 | } | ||
15 | |||
16 | Genericwrapper::~Genericwrapper() | ||
17 | { | ||
18 | if (m_folder) { | ||
19 | mailfolder_free(m_folder); | ||
20 | } | ||
21 | if (m_storage) { | ||
22 | mailstorage_free(m_storage); | ||
23 | } | ||
24 | cleanMimeCache(); | ||
25 | } | ||
26 | |||
27 | void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) | ||
28 | { | ||
29 | if (!mime) { | ||
30 | return; | ||
31 | } | ||
32 | mailmime_field*field = 0; | ||
33 | mailmime_single_fields fields; | ||
34 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | ||
35 | if (mime->mm_mime_fields != NULL) { | ||
36 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, | ||
37 | mime->mm_content_type); | ||
38 | } | ||
39 | |||
40 | mailmime_content*type = fields.fld_content; | ||
41 | clistcell*current; | ||
42 | if (!type) { | ||
43 | target->setType("text"); | ||
44 | target->setSubtype("plain"); | ||
45 | } else { | ||
46 | target->setSubtype(type->ct_subtype); | ||
47 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { | ||
48 | case MAILMIME_DISCRETE_TYPE_TEXT: | ||
49 | target->setType("text"); | ||
50 | break; | ||
51 | case MAILMIME_DISCRETE_TYPE_IMAGE: | ||
52 | target->setType("image"); | ||
53 | break; | ||
54 | case MAILMIME_DISCRETE_TYPE_AUDIO: | ||
55 | target->setType("audio"); | ||
56 | break; | ||
57 | case MAILMIME_DISCRETE_TYPE_VIDEO: | ||
58 | target->setType("video"); | ||
59 | break; | ||
60 | case MAILMIME_DISCRETE_TYPE_APPLICATION: | ||
61 | target->setType("application"); | ||
62 | break; | ||
63 | case MAILMIME_DISCRETE_TYPE_EXTENSION: | ||
64 | default: | ||
65 | 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 | } | ||
68 | break; | ||
69 | } | ||
70 | if (type->ct_parameters) { | ||
71 | fillParameters(target,type->ct_parameters); | ||
72 | } | ||
73 | } | ||
74 | 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 | field = (mailmime_field*)current->data; | ||
77 | switch(field->fld_type) { | ||
78 | case MAILMIME_FIELD_TRANSFER_ENCODING: | ||
79 | target->setEncoding(getencoding(field->fld_data.fld_encoding)); | ||
80 | break; | ||
81 | case MAILMIME_FIELD_ID: | ||
82 | target->setIdentifier(field->fld_data.fld_id); | ||
83 | break; | ||
84 | case MAILMIME_FIELD_DESCRIPTION: | ||
85 | target->setDescription(field->fld_data.fld_description); | ||
86 | break; | ||
87 | default: | ||
88 | break; | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | |||
94 | void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) | ||
95 | { | ||
96 | if (!parameters) {return;} | ||
97 | clistcell*current=0; | ||
98 | mailmime_parameter*param; | ||
99 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { | ||
100 | param = (mailmime_parameter*)current->data; | ||
101 | if (param) { | ||
102 | target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | ||
103 | } | ||
104 | } | ||
105 | } | ||
106 | |||
107 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) | ||
108 | { | ||
109 | QString enc="7bit"; | ||
110 | if (!aEnc) return enc; | ||
111 | switch(aEnc->enc_type) { | ||
112 | case MAILMIME_MECHANISM_7BIT: | ||
113 | enc = "7bit"; | ||
114 | break; | ||
115 | case MAILMIME_MECHANISM_8BIT: | ||
116 | enc = "8bit"; | ||
117 | break; | ||
118 | case MAILMIME_MECHANISM_BINARY: | ||
119 | enc = "binary"; | ||
120 | break; | ||
121 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: | ||
122 | enc = "quoted-printable"; | ||
123 | break; | ||
124 | case MAILMIME_MECHANISM_BASE64: | ||
125 | enc = "base64"; | ||
126 | break; | ||
127 | case MAILMIME_MECHANISM_TOKEN: | ||
128 | default: | ||
129 | if (aEnc->enc_token) { | ||
130 | enc = QString(aEnc->enc_token); | ||
131 | } | ||
132 | break; | ||
133 | } | ||
134 | return enc; | ||
135 | } | ||
136 | |||
137 | void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) | ||
138 | { | ||
139 | if (current_rec >= 10) { | ||
140 | ; // odebug << "too deep recursion!" << oendl; | ||
141 | } | ||
142 | if (!message || !mime) { | ||
143 | return; | ||
144 | } | ||
145 | int r; | ||
146 | char*data = 0; | ||
147 | size_t len; | ||
148 | clistiter * cur = 0; | ||
149 | QString b; | ||
150 | RecPartP part = new RecPart(); | ||
151 | |||
152 | switch (mime->mm_type) { | ||
153 | case MAILMIME_SINGLE: | ||
154 | { | ||
155 | QValueList<int>countlist = recList; | ||
156 | countlist.append(current_count); | ||
157 | r = mailmessage_fetch_section(message,mime,&data,&len); | ||
158 | part->setSize(len); | ||
159 | part->setPositionlist(countlist); | ||
160 | b = gen_attachment_id(); | ||
161 | part->setIdentifier(b); | ||
162 | fillSingleBody(part,message,mime); | ||
163 | if (part->Type()=="text" && target->Bodytext().isNull()) { | ||
164 | encodedString*rs = new encodedString(); | ||
165 | rs->setContent(data,len); | ||
166 | encodedString*res = decode_String(rs,part->Encoding()); | ||
167 | if (countlist.count()>2) { | ||
168 | bodyCache[b]=rs; | ||
169 | target->addPart(part); | ||
170 | } else { | ||
171 | delete rs; | ||
172 | } | ||
173 | b = QString(res->Content()); | ||
174 | delete res; | ||
175 | target->setBodytext(b); | ||
176 | target->setDescription(part); | ||
177 | } else { | ||
178 | bodyCache[b]=new encodedString(data,len); | ||
179 | target->addPart(part); | ||
180 | } | ||
181 | } | ||
182 | break; | ||
183 | case MAILMIME_MULTIPLE: | ||
184 | { | ||
185 | unsigned int ccount = 1; | ||
186 | mailmime*cbody=0; | ||
187 | QValueList<int>countlist = recList; | ||
188 | 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 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | ||
191 | RecPartP targetPart = new RecPart(); | ||
192 | targetPart->setType("multipart"); | ||
193 | countlist.append(current_count); | ||
194 | targetPart->setPositionlist(countlist); | ||
195 | target->addPart(targetPart); | ||
196 | } | ||
197 | traverseBody(target,message, cbody,countlist,current_rec+1,ccount); | ||
198 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | ||
199 | countlist = recList; | ||
200 | } | ||
201 | ++ccount; | ||
202 | } | ||
203 | } | ||
204 | break; | ||
205 | case MAILMIME_MESSAGE: | ||
206 | { | ||
207 | QValueList<int>countlist = recList; | ||
208 | countlist.append(current_count); | ||
209 | /* the own header is always at recursion 0 - we don't need that */ | ||
210 | if (current_rec > 0) { | ||
211 | part->setPositionlist(countlist); | ||
212 | r = mailmessage_fetch_section(message,mime,&data,&len); | ||
213 | part->setSize(len); | ||
214 | part->setPositionlist(countlist); | ||
215 | b = gen_attachment_id(); | ||
216 | part->setIdentifier(b); | ||
217 | part->setType("message"); | ||
218 | part->setSubtype("rfc822"); | ||
219 | bodyCache[b]=new encodedString(data,len); | ||
220 | target->addPart(part); | ||
221 | } | ||
222 | 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 | } | ||
225 | } | ||
226 | break; | ||
227 | } | ||
228 | } | ||
229 | |||
230 | RecBodyP Genericwrapper::parseMail( mailmessage * msg ) | ||
231 | { | ||
232 | int err = MAILIMF_NO_ERROR; | ||
233 | mailmime_single_fields fields; | ||
234 | /* is bound to msg and will be freed there */ | ||
235 | mailmime * mime=0; | ||
236 | RecBodyP body = new RecBody(); | ||
237 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | ||
238 | err = mailmessage_get_bodystructure(msg,&mime); | ||
239 | QValueList<int>recList; | ||
240 | traverseBody(body,msg,mime,recList); | ||
241 | return body; | ||
242 | } | ||
243 | |||
244 | QString Genericwrapper::parseDateTime( mailimf_date_time *date ) | ||
245 | { | ||
246 | char tmp[23]; | ||
247 | |||
248 | // 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 | 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 | |||
253 | return QString( tmp ); | ||
254 | } | ||
255 | |||
256 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) | ||
257 | { | ||
258 | QString result( "" ); | ||
259 | |||
260 | bool first = true; | ||
261 | if (list == 0) return result; | ||
262 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | ||
263 | mailimf_address *addr = (mailimf_address *) current->data; | ||
264 | |||
265 | if ( !first ) { | ||
266 | result.append( "," ); | ||
267 | } else { | ||
268 | first = false; | ||
269 | } | ||
270 | |||
271 | switch ( addr->ad_type ) { | ||
272 | case MAILIMF_ADDRESS_MAILBOX: | ||
273 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | ||
274 | break; | ||
275 | case MAILIMF_ADDRESS_GROUP: | ||
276 | result.append( parseGroup( addr->ad_data.ad_group ) ); | ||
277 | break; | ||
278 | default: | ||
279 | ; // odebug << "Generic: unkown mailimf address type" << oendl; | ||
280 | break; | ||
281 | } | ||
282 | } | ||
283 | |||
284 | return result; | ||
285 | } | ||
286 | |||
287 | QString Genericwrapper::parseGroup( mailimf_group *group ) | ||
288 | { | ||
289 | QString result( "" ); | ||
290 | |||
291 | result.append( group->grp_display_name ); | ||
292 | result.append( ": " ); | ||
293 | |||
294 | if ( group->grp_mb_list != NULL ) { | ||
295 | result.append( parseMailboxList( group->grp_mb_list ) ); | ||
296 | } | ||
297 | |||
298 | result.append( ";" ); | ||
299 | |||
300 | return result; | ||
301 | } | ||
302 | |||
303 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) | ||
304 | { | ||
305 | QString result( "" ); | ||
306 | |||
307 | if ( box->mb_display_name == NULL ) { | ||
308 | result.append( box->mb_addr_spec ); | ||
309 | } else { | ||
310 | result.append( convert_String(box->mb_display_name).latin1() ); | ||
311 | result.append( " <" ); | ||
312 | result.append( box->mb_addr_spec ); | ||
313 | result.append( ">" ); | ||
314 | } | ||
315 | |||
316 | return result; | ||
317 | } | ||
318 | |||
319 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) | ||
320 | { | ||
321 | QString result( "" ); | ||
322 | |||
323 | bool first = true; | ||
324 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { | ||
325 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | ||
326 | |||
327 | if ( !first ) { | ||
328 | result.append( "," ); | ||
329 | } else { | ||
330 | first = false; | ||
331 | } | ||
332 | |||
333 | result.append( parseMailbox( box ) ); | ||
334 | } | ||
335 | |||
336 | return result; | ||
337 | } | ||
338 | |||
339 | encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) | ||
340 | { | ||
341 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); | ||
342 | if (it==bodyCache.end()) return new encodedString(); | ||
343 | encodedString*t = decode_String(it.data(),part->Encoding()); | ||
344 | return t; | ||
345 | } | ||
346 | |||
347 | encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) | ||
348 | { | ||
349 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); | ||
350 | if (it==bodyCache.end()) return new encodedString(); | ||
351 | encodedString*t = it.data(); | ||
352 | return t; | ||
353 | } | ||
354 | |||
355 | QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) | ||
356 | { | ||
357 | encodedString*t = fetchDecodedPart(mail,part); | ||
358 | QString text=t->Content(); | ||
359 | delete t; | ||
360 | return text; | ||
361 | } | ||
362 | |||
363 | void Genericwrapper::cleanMimeCache() | ||
364 | { | ||
365 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); | ||
366 | for (;it!=bodyCache.end();++it) { | ||
367 | encodedString*t = it.data(); | ||
368 | //it.setValue(0); | ||
369 | if (t) delete t; | ||
370 | } | ||
371 | bodyCache.clear(); | ||
372 | ; // odebug << "Genericwrapper: cache cleaned" << oendl; | ||
373 | } | ||
374 | |||
375 | QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) | ||
376 | { | ||
377 | QStringList res; | ||
378 | if (!in_replies || !in_replies->mid_list) return res; | ||
379 | clistiter * current = 0; | ||
380 | for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { | ||
381 | QString h((char*)current->data); | ||
382 | while (h.length()>0 && h[0]=='<') { | ||
383 | h.remove(0,1); | ||
384 | } | ||
385 | while (h.length()>0 && h[h.length()-1]=='>') { | ||
386 | h.remove(h.length()-1,1); | ||
387 | } | ||
388 | if (h.length()>0) { | ||
389 | res.append(h); | ||
390 | } | ||
391 | } | ||
392 | return res; | ||
393 | } | ||
394 | |||
395 | void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to) | ||
396 | { | ||
397 | int r; | ||
398 | mailmessage_list * env_list = 0; | ||
399 | r = mailsession_get_messages_list(session,&env_list); | ||
400 | if (r != MAIL_NO_ERROR) { | ||
401 | ; // odebug << "Error message list" << oendl; | ||
402 | return; | ||
403 | } | ||
404 | r = mailsession_get_envelopes_list(session, env_list); | ||
405 | if (r != MAIL_NO_ERROR) { | ||
406 | ; // odebug << "Error filling message list" << oendl; | ||
407 | if (env_list) { | ||
408 | mailmessage_list_free(env_list); | ||
409 | } | ||
410 | return; | ||
411 | } | ||
412 | mailimf_references * refs = 0; | ||
413 | mailimf_in_reply_to * in_replies = 0; | ||
414 | uint32_t i = 0; | ||
415 | for(; i < carray_count(env_list->msg_tab) ; ++i) { | ||
416 | mailmessage * msg; | ||
417 | QBitArray mFlags(7); | ||
418 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | ||
419 | if (msg->msg_fields == NULL) { | ||
420 | //; // odebug << "could not fetch envelope of message " << i << "" << oendl; | ||
421 | continue; | ||
422 | } | ||
423 | RecMailP mail = new RecMail(); | ||
424 | mail->setWrapper(this); | ||
425 | mail_flags * flag_result = 0; | ||
426 | r = mailmessage_get_flags(msg,&flag_result); | ||
427 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | ||
428 | mFlags.setBit(FLAG_SEEN); | ||
429 | } | ||
430 | mailimf_single_fields single_fields; | ||
431 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | ||
432 | mail->setMsgsize(msg->msg_size); | ||
433 | mail->setFlags(mFlags); | ||
434 | mail->setMbox(mailbox); | ||
435 | mail->setNumber(msg->msg_index); | ||
436 | if (single_fields.fld_subject) | ||
437 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | ||
438 | if (single_fields.fld_from) | ||
439 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); | ||
440 | if (!mbox_as_to) { | ||
441 | if (single_fields.fld_to) | ||
442 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); | ||
443 | } else { | ||
444 | mail->setTo(mailbox); | ||
445 | } | ||
446 | if (single_fields.fld_cc) | ||
447 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); | ||
448 | if (single_fields.fld_bcc) | ||
449 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); | ||
450 | if (single_fields.fld_orig_date) | ||
451 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); | ||
452 | // crashes when accessing pop3 account? | ||
453 | if (single_fields.fld_message_id->mid_value) { | ||
454 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | ||
455 | ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; | ||
456 | } | ||
457 | |||
458 | if (single_fields.fld_reply_to) { | ||
459 | QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); | ||
460 | if (t.count()>0) { | ||
461 | mail->setReplyto(t[0]); | ||
462 | } | ||
463 | } | ||
464 | #if 0 | ||
465 | refs = single_fields.fld_references; | ||
466 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | ||
467 | char * text = (char*)refs->mid_list->first->data; | ||
468 | mail->setReplyto(QString(text)); | ||
469 | } | ||
470 | #endif | ||
471 | 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 | mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); | ||
474 | } | ||
475 | target.append(mail); | ||
476 | } | ||
477 | if (env_list) { | ||
478 | mailmessage_list_free(env_list); | ||
479 | } | ||
480 | } | ||
diff --git a/kmicromail/libmailwrapper/genericwrapper.h b/kmicromail/libmailwrapper/genericwrapper.h new file mode 100644 index 0000000..8be9212 --- a/dev/null +++ b/kmicromail/libmailwrapper/genericwrapper.h | |||
@@ -0,0 +1,67 @@ | |||
1 | #ifndef __GENERIC_WRAPPER_H | ||
2 | #define __GENERIC_WRAPPER_H | ||
3 | |||
4 | #include "abstractmail.h" | ||
5 | #include <qmap.h> | ||
6 | #include <qstring.h> | ||
7 | #include <libetpan/clist.h> | ||
8 | |||
9 | class RecMail; | ||
10 | class RecBody; | ||
11 | class encodedString; | ||
12 | struct mailpop3; | ||
13 | struct mailmessage; | ||
14 | struct mailmime; | ||
15 | struct mailmime_mechanism; | ||
16 | struct mailimf_mailbox_list; | ||
17 | struct mailimf_mailbox; | ||
18 | struct mailimf_date_time; | ||
19 | struct mailimf_group; | ||
20 | struct mailimf_address_list; | ||
21 | struct mailsession; | ||
22 | struct mailstorage; | ||
23 | struct mailfolder; | ||
24 | struct mailimf_in_reply_to; | ||
25 | |||
26 | /* this class hold just the funs shared between | ||
27 | * mbox and pop3 (later mh, too) mail access. | ||
28 | * it is not desigend to make a instance of it! | ||
29 | */ | ||
30 | class Genericwrapper : public AbstractMail | ||
31 | { | ||
32 | Q_OBJECT | ||
33 | public: | ||
34 | Genericwrapper(); | ||
35 | virtual ~Genericwrapper(); | ||
36 | |||
37 | virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part); | ||
38 | virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part); | ||
39 | virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part); | ||
40 | virtual void cleanMimeCache(); | ||
41 | virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&){return 1;} | ||
42 | virtual void logout(){}; | ||
43 | virtual void storeMessage(const char*msg,size_t length, const QString&folder){}; | ||
44 | |||
45 | protected: | ||
46 | RecBodyP parseMail( mailmessage * msg ); | ||
47 | QString parseMailboxList( mailimf_mailbox_list *list ); | ||
48 | QString parseMailbox( mailimf_mailbox *box ); | ||
49 | QString parseGroup( mailimf_group *group ); | ||
50 | QString parseAddressList( mailimf_address_list *list ); | ||
51 | QString parseDateTime( mailimf_date_time *date ); | ||
52 | |||
53 | 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 fillParameters(RecPartP&target,clist*parameters); | ||
56 | 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 | QStringList parseInreplies(mailimf_in_reply_to * in_replies); | ||
59 | |||
60 | QString msgTempName; | ||
61 | unsigned int last_msg_id; | ||
62 | QMap<QString,encodedString*> bodyCache; | ||
63 | mailstorage * m_storage; | ||
64 | mailfolder*m_folder; | ||
65 | }; | ||
66 | |||
67 | #endif | ||
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp new file mode 100644 index 0000000..e0fb6f9 --- a/dev/null +++ b/kmicromail/libmailwrapper/imapwrapper.cpp | |||
@@ -0,0 +1,1182 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <libetpan/libetpan.h> | ||
3 | #include <qpe/global.h> | ||
4 | #include <qapplication.h> | ||
5 | #include "imapwrapper.h" | ||
6 | #include "mailtypes.h" | ||
7 | #include "logindialog.h" | ||
8 | |||
9 | using namespace Opie::Core; | ||
10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | ||
11 | : AbstractMail() | ||
12 | { | ||
13 | account = a; | ||
14 | m_imap = 0; | ||
15 | m_Lastmbox = ""; | ||
16 | } | ||
17 | |||
18 | IMAPwrapper::~IMAPwrapper() | ||
19 | { | ||
20 | logout(); | ||
21 | } | ||
22 | |||
23 | /* to avoid to often select statements in loops etc. | ||
24 | we trust that we are logged in and connection is established!*/ | ||
25 | int IMAPwrapper::selectMbox(const QString&mbox) | ||
26 | { | ||
27 | if (mbox == m_Lastmbox) { | ||
28 | return MAILIMAP_NO_ERROR; | ||
29 | } | ||
30 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); | ||
31 | if ( err != MAILIMAP_NO_ERROR ) { | ||
32 | m_Lastmbox = ""; | ||
33 | return err; | ||
34 | } | ||
35 | m_Lastmbox = mbox; | ||
36 | return err; | ||
37 | } | ||
38 | |||
39 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | ||
40 | { | ||
41 | qApp->processEvents(); | ||
42 | qDebug("imap progress %d of %d ",current,maximum ); | ||
43 | } | ||
44 | |||
45 | bool IMAPwrapper::start_tls(bool force_tls) | ||
46 | { | ||
47 | int err; | ||
48 | bool try_tls; | ||
49 | mailimap_capability_data * cap_data = 0; | ||
50 | |||
51 | err = mailimap_capability(m_imap,&cap_data); | ||
52 | if (err != MAILIMAP_NO_ERROR) { | ||
53 | Global::statusMessage("error getting capabilities!"); | ||
54 | return false; | ||
55 | } | ||
56 | clistiter * cur; | ||
57 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { | ||
58 | struct mailimap_capability * cap; | ||
59 | cap = (struct mailimap_capability *)clist_content(cur); | ||
60 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { | ||
61 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { | ||
62 | try_tls = true; | ||
63 | break; | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | if (cap_data) { | ||
68 | mailimap_capability_data_free(cap_data); | ||
69 | } | ||
70 | if (try_tls) { | ||
71 | err = mailimap_starttls(m_imap); | ||
72 | if (err != MAILIMAP_NO_ERROR && force_tls) { | ||
73 | Global::statusMessage(tr("Server has no TLS support!")); | ||
74 | try_tls = false; | ||
75 | } else { | ||
76 | mailstream_low * low; | ||
77 | mailstream_low * new_low; | ||
78 | low = mailstream_get_low(m_imap->imap_stream); | ||
79 | if (!low) { | ||
80 | try_tls = false; | ||
81 | } else { | ||
82 | int fd = mailstream_low_get_fd(low); | ||
83 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | ||
84 | mailstream_low_free(low); | ||
85 | mailstream_set_low(m_imap->imap_stream, new_low); | ||
86 | } else { | ||
87 | try_tls = false; | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | return try_tls; | ||
93 | } | ||
94 | |||
95 | void IMAPwrapper::login() | ||
96 | { | ||
97 | const char *server, *user, *pass; | ||
98 | uint16_t port; | ||
99 | int err = MAILIMAP_NO_ERROR; | ||
100 | |||
101 | if (account->getOffline()) return; | ||
102 | /* we are connected this moment */ | ||
103 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | ||
104 | if (m_imap) { | ||
105 | err = mailimap_noop(m_imap); | ||
106 | if (err!=MAILIMAP_NO_ERROR) { | ||
107 | logout(); | ||
108 | } else { | ||
109 | mailstream_flush(m_imap->imap_stream); | ||
110 | return; | ||
111 | } | ||
112 | } | ||
113 | server = account->getServer().latin1(); | ||
114 | port = account->getPort().toUInt(); | ||
115 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | ||
116 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | ||
117 | login.show(); | ||
118 | if ( QDialog::Accepted == login.exec() ) { | ||
119 | // ok | ||
120 | user = login.getUser().latin1(); | ||
121 | pass = login.getPassword().latin1(); | ||
122 | } else { | ||
123 | // cancel | ||
124 | return; | ||
125 | } | ||
126 | } else { | ||
127 | user = account->getUser().latin1(); | ||
128 | pass = account->getPassword().latin1(); | ||
129 | } | ||
130 | |||
131 | m_imap = mailimap_new( 20, &imap_progress ); | ||
132 | |||
133 | /* connect */ | ||
134 | bool ssl = false; | ||
135 | bool try_tls = false; | ||
136 | bool force_tls = false; | ||
137 | |||
138 | if ( account->ConnectionType() == 2 ) { | ||
139 | ssl = true; | ||
140 | } | ||
141 | if (account->ConnectionType()==1) { | ||
142 | force_tls = true; | ||
143 | } | ||
144 | |||
145 | if ( ssl ) { | ||
146 | qDebug("using ssl "); | ||
147 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | ||
148 | } else { | ||
149 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | ||
150 | } | ||
151 | |||
152 | if ( err != MAILIMAP_NO_ERROR && | ||
153 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | ||
154 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | ||
155 | QString failure = ""; | ||
156 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | ||
157 | failure="Connection refused"; | ||
158 | } else { | ||
159 | failure="Unknown failure"; | ||
160 | } | ||
161 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); | ||
162 | mailimap_free( m_imap ); | ||
163 | m_imap = 0; | ||
164 | return; | ||
165 | } | ||
166 | |||
167 | if (!ssl) { | ||
168 | try_tls = start_tls(force_tls); | ||
169 | } | ||
170 | |||
171 | bool ok = true; | ||
172 | if (force_tls && !try_tls) { | ||
173 | Global::statusMessage(tr("Server has no TLS support!")); | ||
174 | ok = false; | ||
175 | } | ||
176 | |||
177 | |||
178 | /* login */ | ||
179 | |||
180 | if (ok) { | ||
181 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | ||
182 | if ( err != MAILIMAP_NO_ERROR ) { | ||
183 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); | ||
184 | ok = false; | ||
185 | } | ||
186 | } | ||
187 | if (!ok) { | ||
188 | err = mailimap_close( m_imap ); | ||
189 | mailimap_free( m_imap ); | ||
190 | m_imap = 0; | ||
191 | } | ||
192 | } | ||
193 | |||
194 | void IMAPwrapper::logout() | ||
195 | { | ||
196 | int err = MAILIMAP_NO_ERROR; | ||
197 | if (!m_imap) return; | ||
198 | err = mailimap_logout( m_imap ); | ||
199 | err = mailimap_close( m_imap ); | ||
200 | mailimap_free( m_imap ); | ||
201 | m_imap = 0; | ||
202 | m_Lastmbox = ""; | ||
203 | } | ||
204 | |||
205 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) | ||
206 | { | ||
207 | int err = MAILIMAP_NO_ERROR; | ||
208 | clist *result = 0; | ||
209 | clistcell *current; | ||
210 | mailimap_fetch_type *fetchType = 0; | ||
211 | mailimap_set *set = 0; | ||
212 | |||
213 | login(); | ||
214 | if (!m_imap) { | ||
215 | return; | ||
216 | } | ||
217 | /* select mailbox READONLY for operations */ | ||
218 | err = selectMbox(mailbox); | ||
219 | if ( err != MAILIMAP_NO_ERROR ) { | ||
220 | return; | ||
221 | } | ||
222 | |||
223 | int last = m_imap->imap_selection_info->sel_exists; | ||
224 | |||
225 | if (last == 0) { | ||
226 | Global::statusMessage(tr("Mailbox has no mails")); | ||
227 | return; | ||
228 | } else { | ||
229 | } | ||
230 | |||
231 | /* the range has to start at 1!!! not with 0!!!! */ | ||
232 | set = mailimap_set_new_interval( 1, last ); | ||
233 | 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_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_rfc822_size()); | ||
238 | |||
239 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | ||
240 | mailimap_set_free( set ); | ||
241 | mailimap_fetch_type_free( fetchType ); | ||
242 | |||
243 | QString date,subject,from; | ||
244 | |||
245 | if ( err == MAILIMAP_NO_ERROR ) { | ||
246 | mailimap_msg_att * msg_att; | ||
247 | int i = 0; | ||
248 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | ||
249 | ++i; | ||
250 | msg_att = (mailimap_msg_att*)current->data; | ||
251 | RecMail*m = parse_list_result(msg_att); | ||
252 | if (m) { | ||
253 | m->setNumber(i); | ||
254 | m->setMbox(mailbox); | ||
255 | m->setWrapper(this); | ||
256 | target.append(m); | ||
257 | } | ||
258 | } | ||
259 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); | ||
260 | } else { | ||
261 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); | ||
262 | } | ||
263 | if (result) mailimap_fetch_list_free(result); | ||
264 | } | ||
265 | |||
266 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() | ||
267 | { | ||
268 | const char *path, *mask; | ||
269 | int err = MAILIMAP_NO_ERROR; | ||
270 | clist *result = 0; | ||
271 | clistcell *current = 0; | ||
272 | clistcell*cur_flag = 0; | ||
273 | mailimap_mbx_list_flags*bflags = 0; | ||
274 | |||
275 | QValueList<FolderP>* folders = new QValueList<FolderP>(); | ||
276 | login(); | ||
277 | if (!m_imap) { | ||
278 | return folders; | ||
279 | } | ||
280 | |||
281 | /* | ||
282 | * 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! | ||
284 | * it seems like ugly code. and yes - it is ugly code. but the best way. | ||
285 | */ | ||
286 | QString temp; | ||
287 | mask = "INBOX" ; | ||
288 | mailimap_mailbox_list *list; | ||
289 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | ||
290 | QString del; | ||
291 | bool selectable = true; | ||
292 | bool no_inferiors = false; | ||
293 | if ( err == MAILIMAP_NO_ERROR ) { | ||
294 | current = result->first; | ||
295 | for ( int i = result->count; i > 0; i-- ) { | ||
296 | list = (mailimap_mailbox_list *) current->data; | ||
297 | // it is better use the deep copy mechanism of qt itself | ||
298 | // instead of using strdup! | ||
299 | temp = list->mb_name; | ||
300 | del = list->mb_delimiter; | ||
301 | current = current->next; | ||
302 | if ( (bflags = list->mb_flag) ) { | ||
303 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | ||
304 | 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)) { | ||
306 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | ||
307 | no_inferiors = true; | ||
308 | } | ||
309 | } | ||
310 | } | ||
311 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | ||
312 | } | ||
313 | } else { | ||
314 | qDebug("error fetching folders: "); | ||
315 | |||
316 | } | ||
317 | mailimap_list_result_free( result ); | ||
318 | |||
319 | /* | ||
320 | * second stage - get the other then inbox folders | ||
321 | */ | ||
322 | mask = "*" ; | ||
323 | path = account->getPrefix().latin1(); | ||
324 | if (!path) path = ""; | ||
325 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | ||
326 | if ( err == MAILIMAP_NO_ERROR ) { | ||
327 | current = result->first; | ||
328 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | ||
329 | no_inferiors = false; | ||
330 | list = (mailimap_mailbox_list *) current->data; | ||
331 | // it is better use the deep copy mechanism of qt itself | ||
332 | // instead of using strdup! | ||
333 | temp = list->mb_name; | ||
334 | if (temp.lower()=="inbox") | ||
335 | continue; | ||
336 | if (temp.lower()==account->getPrefix().lower()) | ||
337 | continue; | ||
338 | if ( (bflags = list->mb_flag) ) { | ||
339 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | ||
340 | 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)) { | ||
342 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | ||
343 | no_inferiors = true; | ||
344 | } | ||
345 | } | ||
346 | } | ||
347 | del = list->mb_delimiter; | ||
348 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | ||
349 | } | ||
350 | } else { | ||
351 | qDebug("error fetching folders "); | ||
352 | |||
353 | } | ||
354 | if (result) mailimap_list_result_free( result ); | ||
355 | return folders; | ||
356 | } | ||
357 | |||
358 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | ||
359 | { | ||
360 | RecMail * m = 0; | ||
361 | mailimap_msg_att_item *item=0; | ||
362 | clistcell *current,*c,*cf; | ||
363 | mailimap_msg_att_dynamic*flist; | ||
364 | mailimap_flag_fetch*cflag; | ||
365 | int size; | ||
366 | QBitArray mFlags(7); | ||
367 | QStringList addresslist; | ||
368 | |||
369 | if (!m_att) { | ||
370 | return m; | ||
371 | } | ||
372 | m = new RecMail(); | ||
373 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | ||
374 | current = c; | ||
375 | size = 0; | ||
376 | item = (mailimap_msg_att_item*)current->data; | ||
377 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | ||
378 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | ||
379 | if (!flist->att_list) { | ||
380 | continue; | ||
381 | } | ||
382 | cf = flist->att_list->first; | ||
383 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | ||
384 | cflag = (mailimap_flag_fetch*)cf->data; | ||
385 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | ||
386 | switch (cflag->fl_flag->fl_type) { | ||
387 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | ||
388 | mFlags.setBit(FLAG_ANSWERED); | ||
389 | break; | ||
390 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | ||
391 | mFlags.setBit(FLAG_FLAGGED); | ||
392 | break; | ||
393 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | ||
394 | mFlags.setBit(FLAG_DELETED); | ||
395 | break; | ||
396 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | ||
397 | mFlags.setBit(FLAG_SEEN); | ||
398 | break; | ||
399 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | ||
400 | mFlags.setBit(FLAG_DRAFT); | ||
401 | break; | ||
402 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | ||
403 | break; | ||
404 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | ||
405 | break; | ||
406 | default: | ||
407 | break; | ||
408 | } | ||
409 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | ||
410 | mFlags.setBit(FLAG_RECENT); | ||
411 | } | ||
412 | } | ||
413 | continue; | ||
414 | } | ||
415 | 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; | ||
417 | m->setDate(head->env_date); | ||
418 | m->setSubject(convert_String((const char*)head->env_subject)); | ||
419 | //m->setSubject(head->env_subject); | ||
420 | if (head->env_from!=NULL) { | ||
421 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | ||
422 | if (addresslist.count()) { | ||
423 | m->setFrom(addresslist.first()); | ||
424 | } | ||
425 | } | ||
426 | if (head->env_to!=NULL) { | ||
427 | addresslist = address_list_to_stringlist(head->env_to->to_list); | ||
428 | m->setTo(addresslist); | ||
429 | } | ||
430 | if (head->env_cc!=NULL) { | ||
431 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | ||
432 | m->setCC(addresslist); | ||
433 | } | ||
434 | if (head->env_bcc!=NULL) { | ||
435 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | ||
436 | m->setBcc(addresslist); | ||
437 | } | ||
438 | /* reply to address, eg. email. */ | ||
439 | if (head->env_reply_to!=NULL) { | ||
440 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | ||
441 | if (addresslist.count()) { | ||
442 | m->setReplyto(addresslist.first()); | ||
443 | } | ||
444 | } | ||
445 | if (head->env_in_reply_to!=NULL) { | ||
446 | QString h(head->env_in_reply_to); | ||
447 | while (h.length()>0 && h[0]=='<') { | ||
448 | h.remove(0,1); | ||
449 | } | ||
450 | while (h.length()>0 && h[h.length()-1]=='>') { | ||
451 | h.remove(h.length()-1,1); | ||
452 | } | ||
453 | if (h.length()>0) { | ||
454 | m->setInreply(QStringList(h)); | ||
455 | } | ||
456 | } | ||
457 | if (head->env_message_id) { | ||
458 | m->setMsgid(QString(head->env_message_id)); | ||
459 | } | ||
460 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | ||
461 | #if 0 | ||
462 | 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)); | ||
464 | //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; | ||
466 | #endif | ||
467 | } 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; | ||
469 | } | ||
470 | } | ||
471 | /* msg is already deleted */ | ||
472 | if (mFlags.testBit(FLAG_DELETED) && m) { | ||
473 | delete m; | ||
474 | m = 0; | ||
475 | } | ||
476 | if (m) { | ||
477 | m->setFlags(mFlags); | ||
478 | m->setMsgsize(size); | ||
479 | } | ||
480 | return m; | ||
481 | } | ||
482 | |||
483 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) | ||
484 | { | ||
485 | RecBodyP body = new RecBody(); | ||
486 | const char *mb; | ||
487 | int err = MAILIMAP_NO_ERROR; | ||
488 | clist *result = 0; | ||
489 | clistcell *current; | ||
490 | mailimap_fetch_att *fetchAtt = 0; | ||
491 | mailimap_fetch_type *fetchType = 0; | ||
492 | mailimap_set *set = 0; | ||
493 | mailimap_body*body_desc = 0; | ||
494 | |||
495 | mb = mail->getMbox().latin1(); | ||
496 | |||
497 | login(); | ||
498 | if (!m_imap) { | ||
499 | return body; | ||
500 | } | ||
501 | err = selectMbox(mail->getMbox()); | ||
502 | if ( err != MAILIMAP_NO_ERROR ) { | ||
503 | return body; | ||
504 | } | ||
505 | |||
506 | /* the range has to start at 1!!! not with 0!!!! */ | ||
507 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); | ||
508 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | ||
509 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | ||
510 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | ||
511 | mailimap_set_free( set ); | ||
512 | mailimap_fetch_type_free( fetchType ); | ||
513 | |||
514 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | ||
515 | mailimap_msg_att * msg_att; | ||
516 | msg_att = (mailimap_msg_att*)current->data; | ||
517 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | ||
518 | QValueList<int> path; | ||
519 | body_desc = item->att_data.att_static->att_data.att_body; | ||
520 | traverseBody(mail,body_desc,body,0,path); | ||
521 | } else { | ||
522 | //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; | ||
523 | } | ||
524 | if (result) mailimap_fetch_list_free(result); | ||
525 | return body; | ||
526 | } | ||
527 | |||
528 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | ||
529 | { | ||
530 | QStringList l; | ||
531 | QString from; | ||
532 | bool named_from; | ||
533 | clistcell *current = NULL; | ||
534 | mailimap_address * current_address=NULL; | ||
535 | if (!list) { | ||
536 | return l; | ||
537 | } | ||
538 | unsigned int count = 0; | ||
539 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | ||
540 | from = ""; | ||
541 | named_from = false; | ||
542 | current_address=(mailimap_address*)current->data; | ||
543 | if (current_address->ad_personal_name){ | ||
544 | from+=convert_String((const char*)current_address->ad_personal_name); | ||
545 | from+=" "; | ||
546 | named_from = true; | ||
547 | } | ||
548 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | ||
549 | from+="<"; | ||
550 | } | ||
551 | if (current_address->ad_mailbox_name) { | ||
552 | from+=QString(current_address->ad_mailbox_name); | ||
553 | from+="@"; | ||
554 | } | ||
555 | if (current_address->ad_host_name) { | ||
556 | from+=QString(current_address->ad_host_name); | ||
557 | } | ||
558 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | ||
559 | from+=">"; | ||
560 | } | ||
561 | l.append(QString(from)); | ||
562 | if (++count > 99) { | ||
563 | break; | ||
564 | } | ||
565 | } | ||
566 | return l; | ||
567 | } | ||
568 | |||
569 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) | ||
570 | { | ||
571 | encodedString*res=new encodedString; | ||
572 | int err; | ||
573 | mailimap_fetch_type *fetchType; | ||
574 | mailimap_set *set; | ||
575 | clistcell*current,*cur; | ||
576 | mailimap_section_part * section_part = 0; | ||
577 | mailimap_section_spec * section_spec = 0; | ||
578 | mailimap_section * section = 0; | ||
579 | mailimap_fetch_att * fetch_att = 0; | ||
580 | |||
581 | login(); | ||
582 | if (!m_imap) { | ||
583 | return res; | ||
584 | } | ||
585 | if (!internal_call) { | ||
586 | err = selectMbox(mail->getMbox()); | ||
587 | if ( err != MAILIMAP_NO_ERROR ) { | ||
588 | return res; | ||
589 | } | ||
590 | } | ||
591 | set = mailimap_set_new_single(mail->getNumber()); | ||
592 | |||
593 | clist*id_list = 0; | ||
594 | |||
595 | /* if path == empty then its a request for the whole rfc822 mail and generates | ||
596 | a "fetch <id> (body[])" statement on imap server */ | ||
597 | if (path.count()>0 ) { | ||
598 | id_list = clist_new(); | ||
599 | for (unsigned j=0; j < path.count();++j) { | ||
600 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | ||
601 | *p_id = path[j]; | ||
602 | clist_append(id_list,p_id); | ||
603 | } | ||
604 | section_part = mailimap_section_part_new(id_list); | ||
605 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | ||
606 | } | ||
607 | |||
608 | section = mailimap_section_new(section_spec); | ||
609 | fetch_att = mailimap_fetch_att_new_body_section(section); | ||
610 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | ||
611 | |||
612 | clist*result = 0; | ||
613 | |||
614 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | ||
615 | mailimap_set_free( set ); | ||
616 | mailimap_fetch_type_free( fetchType ); | ||
617 | |||
618 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | ||
619 | mailimap_msg_att * msg_att; | ||
620 | msg_att = (mailimap_msg_att*)current->data; | ||
621 | mailimap_msg_att_item*msg_att_item; | ||
622 | 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); | ||
624 | 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) { | ||
626 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | ||
627 | /* detach - we take over the content */ | ||
628 | 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); | ||
630 | } | ||
631 | } | ||
632 | } | ||
633 | } else { | ||
634 | ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; | ||
635 | } | ||
636 | if (result) mailimap_fetch_list_free(result); | ||
637 | return res; | ||
638 | } | ||
639 | |||
640 | /* current_recursion is for recursive calls. | ||
641 | current_count means the position inside the internal loop! */ | ||
642 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, | ||
643 | int current_recursion,QValueList<int>recList,int current_count) | ||
644 | { | ||
645 | if (!body || current_recursion>=10) { | ||
646 | return; | ||
647 | } | ||
648 | switch (body->bd_type) { | ||
649 | case MAILIMAP_BODY_1PART: | ||
650 | { | ||
651 | QValueList<int>countlist = recList; | ||
652 | countlist.append(current_count); | ||
653 | RecPartP currentPart = new RecPart(); | ||
654 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; | ||
655 | QString id(""); | ||
656 | currentPart->setPositionlist(countlist); | ||
657 | for (unsigned int j = 0; j < countlist.count();++j) { | ||
658 | id+=(j>0?" ":""); | ||
659 | id+=QString("%1").arg(countlist[j]); | ||
660 | } | ||
661 | //odebug << "ID = " << id.latin1() << "" << oendl; | ||
662 | currentPart->setIdentifier(id); | ||
663 | fillSinglePart(currentPart,part1); | ||
664 | /* 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 */ | ||
666 | 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()); | ||
668 | target_body->setDescription(currentPart); | ||
669 | target_body->setBodytext(body_text); | ||
670 | if (countlist.count()>1) { | ||
671 | target_body->addPart(currentPart); | ||
672 | } | ||
673 | } else { | ||
674 | target_body->addPart(currentPart); | ||
675 | } | ||
676 | 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); | ||
678 | } | ||
679 | } | ||
680 | break; | ||
681 | case MAILIMAP_BODY_MPART: | ||
682 | { | ||
683 | QValueList<int>countlist = recList; | ||
684 | clistcell*current=0; | ||
685 | mailimap_body*current_body=0; | ||
686 | unsigned int ccount = 1; | ||
687 | 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)) { | ||
689 | current_body = (mailimap_body*)current->data; | ||
690 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | ||
691 | RecPartP targetPart = new RecPart(); | ||
692 | targetPart->setType("multipart"); | ||
693 | fillMultiPart(targetPart,mailDescription); | ||
694 | countlist.append(current_count); | ||
695 | targetPart->setPositionlist(countlist); | ||
696 | target_body->addPart(targetPart); | ||
697 | QString id(""); | ||
698 | for (unsigned int j = 0; j < countlist.count();++j) { | ||
699 | id+=(j>0?" ":""); | ||
700 | id+=QString("%1").arg(countlist[j]); | ||
701 | } | ||
702 | // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; | ||
703 | } | ||
704 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); | ||
705 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | ||
706 | countlist = recList; | ||
707 | } | ||
708 | ++ccount; | ||
709 | } | ||
710 | } | ||
711 | break; | ||
712 | default: | ||
713 | break; | ||
714 | } | ||
715 | } | ||
716 | |||
717 | void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) | ||
718 | { | ||
719 | if (!Description) { | ||
720 | return; | ||
721 | } | ||
722 | switch (Description->bd_type) { | ||
723 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | ||
724 | target_part->setType("text"); | ||
725 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | ||
726 | break; | ||
727 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | ||
728 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | ||
729 | break; | ||
730 | case MAILIMAP_BODY_TYPE_1PART_MSG: | ||
731 | target_part->setType("message"); | ||
732 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | ||
733 | break; | ||
734 | default: | ||
735 | break; | ||
736 | } | ||
737 | } | ||
738 | |||
739 | void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) | ||
740 | { | ||
741 | if (!which) { | ||
742 | return; | ||
743 | } | ||
744 | QString sub; | ||
745 | sub = which->bd_media_text; | ||
746 | //odebug << "Type= text/" << which->bd_media_text << "" << oendl; | ||
747 | target_part->setSubtype(sub.lower()); | ||
748 | target_part->setLines(which->bd_lines); | ||
749 | fillBodyFields(target_part,which->bd_fields); | ||
750 | } | ||
751 | |||
752 | void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) | ||
753 | { | ||
754 | if (!which) { | ||
755 | return; | ||
756 | } | ||
757 | target_part->setSubtype("rfc822"); | ||
758 | //odebug << "Message part" << oendl; | ||
759 | /* we set this type to text/plain */ | ||
760 | target_part->setLines(which->bd_lines); | ||
761 | fillBodyFields(target_part,which->bd_fields); | ||
762 | } | ||
763 | |||
764 | void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) | ||
765 | { | ||
766 | if (!which) return; | ||
767 | QString sub = which->bd_media_subtype; | ||
768 | 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) { | ||
770 | clistcell*cur = 0; | ||
771 | 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)) { | ||
773 | param = (mailimap_single_body_fld_param*)cur->data; | ||
774 | if (param) { | ||
775 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | ||
776 | } | ||
777 | } | ||
778 | } | ||
779 | } | ||
780 | |||
781 | void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) | ||
782 | { | ||
783 | if (!which) { | ||
784 | return; | ||
785 | } | ||
786 | QString type,sub; | ||
787 | switch (which->bd_media_basic->med_type) { | ||
788 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | ||
789 | type = "application"; | ||
790 | break; | ||
791 | case MAILIMAP_MEDIA_BASIC_AUDIO: | ||
792 | type = "audio"; | ||
793 | break; | ||
794 | case MAILIMAP_MEDIA_BASIC_IMAGE: | ||
795 | type = "image"; | ||
796 | break; | ||
797 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | ||
798 | type = "message"; | ||
799 | break; | ||
800 | case MAILIMAP_MEDIA_BASIC_VIDEO: | ||
801 | type = "video"; | ||
802 | break; | ||
803 | case MAILIMAP_MEDIA_BASIC_OTHER: | ||
804 | default: | ||
805 | if (which->bd_media_basic->med_basic_type) { | ||
806 | type = which->bd_media_basic->med_basic_type; | ||
807 | } else { | ||
808 | type = ""; | ||
809 | } | ||
810 | break; | ||
811 | } | ||
812 | if (which->bd_media_basic->med_subtype) { | ||
813 | sub = which->bd_media_basic->med_subtype; | ||
814 | } else { | ||
815 | sub = ""; | ||
816 | } | ||
817 | // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; | ||
818 | target_part->setType(type.lower()); | ||
819 | target_part->setSubtype(sub.lower()); | ||
820 | fillBodyFields(target_part,which->bd_fields); | ||
821 | } | ||
822 | |||
823 | void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) | ||
824 | { | ||
825 | if (!which) return; | ||
826 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | ||
827 | clistcell*cur; | ||
828 | mailimap_single_body_fld_param*param=0; | ||
829 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | ||
830 | param = (mailimap_single_body_fld_param*)cur->data; | ||
831 | if (param) { | ||
832 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | ||
833 | } | ||
834 | } | ||
835 | } | ||
836 | mailimap_body_fld_enc*enc = which->bd_encoding; | ||
837 | QString encoding(""); | ||
838 | switch (enc->enc_type) { | ||
839 | case MAILIMAP_BODY_FLD_ENC_7BIT: | ||
840 | encoding = "7bit"; | ||
841 | break; | ||
842 | case MAILIMAP_BODY_FLD_ENC_8BIT: | ||
843 | encoding = "8bit"; | ||
844 | break; | ||
845 | case MAILIMAP_BODY_FLD_ENC_BINARY: | ||
846 | encoding="binary"; | ||
847 | break; | ||
848 | case MAILIMAP_BODY_FLD_ENC_BASE64: | ||
849 | encoding="base64"; | ||
850 | break; | ||
851 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | ||
852 | encoding="quoted-printable"; | ||
853 | break; | ||
854 | case MAILIMAP_BODY_FLD_ENC_OTHER: | ||
855 | default: | ||
856 | if (enc->enc_value) { | ||
857 | char*t=enc->enc_value; | ||
858 | encoding=QString(enc->enc_value); | ||
859 | enc->enc_value=0L; | ||
860 | free(t); | ||
861 | } | ||
862 | } | ||
863 | if (which->bd_description) { | ||
864 | target_part->setDescription(QString(which->bd_description)); | ||
865 | } | ||
866 | target_part->setEncoding(encoding); | ||
867 | target_part->setSize(which->bd_size); | ||
868 | } | ||
869 | |||
870 | void IMAPwrapper::deleteMail(const RecMailP&mail) | ||
871 | { | ||
872 | mailimap_flag_list*flist; | ||
873 | mailimap_set *set; | ||
874 | mailimap_store_att_flags * store_flags; | ||
875 | int err; | ||
876 | login(); | ||
877 | if (!m_imap) { | ||
878 | return; | ||
879 | } | ||
880 | err = selectMbox(mail->getMbox()); | ||
881 | if ( err != MAILIMAP_NO_ERROR ) { | ||
882 | return; | ||
883 | } | ||
884 | flist = mailimap_flag_list_new_empty(); | ||
885 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | ||
886 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | ||
887 | set = mailimap_set_new_single(mail->getNumber()); | ||
888 | err = mailimap_store(m_imap,set,store_flags); | ||
889 | mailimap_set_free( set ); | ||
890 | mailimap_store_att_flags_free(store_flags); | ||
891 | |||
892 | if (err != MAILIMAP_NO_ERROR) { | ||
893 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | ||
894 | return; | ||
895 | } | ||
896 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | ||
897 | /* should we realy do that at this moment? */ | ||
898 | err = mailimap_expunge(m_imap); | ||
899 | if (err != MAILIMAP_NO_ERROR) { | ||
900 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | ||
901 | } | ||
902 | // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; | ||
903 | } | ||
904 | |||
905 | void IMAPwrapper::answeredMail(const RecMailP&mail) | ||
906 | { | ||
907 | mailimap_flag_list*flist; | ||
908 | mailimap_set *set; | ||
909 | mailimap_store_att_flags * store_flags; | ||
910 | int err; | ||
911 | login(); | ||
912 | if (!m_imap) { | ||
913 | return; | ||
914 | } | ||
915 | err = selectMbox(mail->getMbox()); | ||
916 | if ( err != MAILIMAP_NO_ERROR ) { | ||
917 | return; | ||
918 | } | ||
919 | flist = mailimap_flag_list_new_empty(); | ||
920 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | ||
921 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | ||
922 | set = mailimap_set_new_single(mail->getNumber()); | ||
923 | err = mailimap_store(m_imap,set,store_flags); | ||
924 | mailimap_set_free( set ); | ||
925 | mailimap_store_att_flags_free(store_flags); | ||
926 | |||
927 | if (err != MAILIMAP_NO_ERROR) { | ||
928 | // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; | ||
929 | return; | ||
930 | } | ||
931 | } | ||
932 | |||
933 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | ||
934 | { | ||
935 | QString body(""); | ||
936 | encodedString*res = fetchRawPart(mail,path,internal_call); | ||
937 | encodedString*r = decode_String(res,enc); | ||
938 | delete res; | ||
939 | if (r) { | ||
940 | if (r->Length()>0) { | ||
941 | body = r->Content(); | ||
942 | } | ||
943 | delete r; | ||
944 | } | ||
945 | return body; | ||
946 | } | ||
947 | |||
948 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) | ||
949 | { | ||
950 | return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); | ||
951 | } | ||
952 | |||
953 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) | ||
954 | { | ||
955 | encodedString*res = fetchRawPart(mail,part->Positionlist(),false); | ||
956 | encodedString*r = decode_String(res,part->Encoding()); | ||
957 | delete res; | ||
958 | return r; | ||
959 | } | ||
960 | |||
961 | encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) | ||
962 | { | ||
963 | return fetchRawPart(mail,part->Positionlist(),false); | ||
964 | } | ||
965 | |||
966 | int IMAPwrapper::deleteAllMail(const FolderP&folder) | ||
967 | { | ||
968 | login(); | ||
969 | if (!m_imap) { | ||
970 | return 0; | ||
971 | } | ||
972 | mailimap_flag_list*flist; | ||
973 | mailimap_set *set; | ||
974 | mailimap_store_att_flags * store_flags; | ||
975 | int err = selectMbox(folder->getName()); | ||
976 | if ( err != MAILIMAP_NO_ERROR ) { | ||
977 | return 0; | ||
978 | } | ||
979 | |||
980 | int last = m_imap->imap_selection_info->sel_exists; | ||
981 | if (last == 0) { | ||
982 | Global::statusMessage(tr("Mailbox has no mails!")); | ||
983 | return 0; | ||
984 | } | ||
985 | flist = mailimap_flag_list_new_empty(); | ||
986 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | ||
987 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | ||
988 | set = mailimap_set_new_interval( 1, last ); | ||
989 | err = mailimap_store(m_imap,set,store_flags); | ||
990 | mailimap_set_free( set ); | ||
991 | mailimap_store_att_flags_free(store_flags); | ||
992 | if (err != MAILIMAP_NO_ERROR) { | ||
993 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | ||
994 | return 0; | ||
995 | } | ||
996 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | ||
997 | /* should we realy do that at this moment? */ | ||
998 | err = mailimap_expunge(m_imap); | ||
999 | if (err != MAILIMAP_NO_ERROR) { | ||
1000 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | ||
1001 | return 0; | ||
1002 | } | ||
1003 | // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; | ||
1004 | return 1; | ||
1005 | } | ||
1006 | |||
1007 | int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) | ||
1008 | { | ||
1009 | if (folder.length()==0) return 0; | ||
1010 | login(); | ||
1011 | if (!m_imap) {return 0;} | ||
1012 | QString pre = account->getPrefix(); | ||
1013 | if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { | ||
1014 | pre+=delemiter; | ||
1015 | } | ||
1016 | if (parentfolder) { | ||
1017 | pre += parentfolder->getDisplayName()+delemiter; | ||
1018 | } | ||
1019 | pre+=folder; | ||
1020 | if (getsubfolder) { | ||
1021 | if (delemiter.length()>0) { | ||
1022 | pre+=delemiter; | ||
1023 | } else { | ||
1024 | Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); | ||
1025 | return 0; | ||
1026 | } | ||
1027 | } | ||
1028 | // odebug << "Creating " << pre.latin1() << "" << oendl; | ||
1029 | int res = mailimap_create(m_imap,pre.latin1()); | ||
1030 | if (res != MAILIMAP_NO_ERROR) { | ||
1031 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | ||
1032 | return 0; | ||
1033 | } | ||
1034 | return 1; | ||
1035 | } | ||
1036 | |||
1037 | int IMAPwrapper::deleteMbox(const FolderP&folder) | ||
1038 | { | ||
1039 | if (!folder) return 0; | ||
1040 | login(); | ||
1041 | if (!m_imap) {return 0;} | ||
1042 | int res = mailimap_delete(m_imap,folder->getName()); | ||
1043 | if (res != MAILIMAP_NO_ERROR) { | ||
1044 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | ||
1045 | return 0; | ||
1046 | } | ||
1047 | return 1; | ||
1048 | } | ||
1049 | |||
1050 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | ||
1051 | { | ||
1052 | mailimap_status_att_list * att_list =0; | ||
1053 | mailimap_mailbox_data_status * status=0; | ||
1054 | clistiter * cur = 0; | ||
1055 | int r = 0; | ||
1056 | target_stat.message_count = 0; | ||
1057 | target_stat.message_unseen = 0; | ||
1058 | target_stat.message_recent = 0; | ||
1059 | login(); | ||
1060 | if (!m_imap) { | ||
1061 | return; | ||
1062 | } | ||
1063 | att_list = mailimap_status_att_list_new_empty(); | ||
1064 | if (!att_list) return; | ||
1065 | 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); | ||
1067 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); | ||
1068 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); | ||
1069 | if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { | ||
1070 | for (cur = clist_begin(status->st_info_list); | ||
1071 | cur != NULL ; cur = clist_next(cur)) { | ||
1072 | mailimap_status_info * status_info; | ||
1073 | status_info = (mailimap_status_info *)clist_content(cur); | ||
1074 | switch (status_info->st_att) { | ||
1075 | case MAILIMAP_STATUS_ATT_MESSAGES: | ||
1076 | target_stat.message_count = status_info->st_value; | ||
1077 | break; | ||
1078 | case MAILIMAP_STATUS_ATT_RECENT: | ||
1079 | target_stat.message_recent = status_info->st_value; | ||
1080 | break; | ||
1081 | case MAILIMAP_STATUS_ATT_UNSEEN: | ||
1082 | target_stat.message_unseen = status_info->st_value; | ||
1083 | break; | ||
1084 | } | ||
1085 | } | ||
1086 | } else { | ||
1087 | // odebug << "Error retrieving status" << oendl; | ||
1088 | } | ||
1089 | if (status) mailimap_mailbox_data_status_free(status); | ||
1090 | if (att_list) mailimap_status_att_list_free(att_list); | ||
1091 | } | ||
1092 | |||
1093 | void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | ||
1094 | { | ||
1095 | login(); | ||
1096 | if (!m_imap) return; | ||
1097 | if (!msg) return; | ||
1098 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); | ||
1099 | if (r != MAILIMAP_NO_ERROR) { | ||
1100 | Global::statusMessage("Error storing mail!"); | ||
1101 | } | ||
1102 | } | ||
1103 | |||
1104 | MAILLIB::ATYPE IMAPwrapper::getType()const | ||
1105 | { | ||
1106 | return account->getType(); | ||
1107 | } | ||
1108 | |||
1109 | const QString&IMAPwrapper::getName()const | ||
1110 | { | ||
1111 | // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; | ||
1112 | return account->getAccountName(); | ||
1113 | } | ||
1114 | |||
1115 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) | ||
1116 | { | ||
1117 | // dummy | ||
1118 | QValueList<int> path; | ||
1119 | return fetchRawPart(mail,path,false); | ||
1120 | } | ||
1121 | |||
1122 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, | ||
1123 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | ||
1124 | { | ||
1125 | if (targetWrapper != this) { | ||
1126 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); | ||
1127 | // odebug << "Using generic" << oendl; | ||
1128 | return; | ||
1129 | } | ||
1130 | mailimap_set *set = 0; | ||
1131 | login(); | ||
1132 | if (!m_imap) { | ||
1133 | return; | ||
1134 | } | ||
1135 | int err = selectMbox(fromFolder->getName()); | ||
1136 | if ( err != MAILIMAP_NO_ERROR ) { | ||
1137 | return; | ||
1138 | } | ||
1139 | int last = m_imap->imap_selection_info->sel_exists; | ||
1140 | set = mailimap_set_new_interval( 1, last ); | ||
1141 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | ||
1142 | mailimap_set_free( set ); | ||
1143 | if ( err != MAILIMAP_NO_ERROR ) { | ||
1144 | QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); | ||
1145 | Global::statusMessage(error_msg); | ||
1146 | // odebug << error_msg << oendl; | ||
1147 | return; | ||
1148 | } | ||
1149 | if (moveit) { | ||
1150 | deleteAllMail(fromFolder); | ||
1151 | } | ||
1152 | } | ||
1153 | |||
1154 | void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | ||
1155 | { | ||
1156 | if (targetWrapper != this) { | ||
1157 | // odebug << "Using generic" << oendl; | ||
1158 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); | ||
1159 | return; | ||
1160 | } | ||
1161 | mailimap_set *set = 0; | ||
1162 | login(); | ||
1163 | if (!m_imap) { | ||
1164 | return; | ||
1165 | } | ||
1166 | int err = selectMbox(mail->getMbox()); | ||
1167 | if ( err != MAILIMAP_NO_ERROR ) { | ||
1168 | return; | ||
1169 | } | ||
1170 | set = mailimap_set_new_single(mail->getNumber()); | ||
1171 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | ||
1172 | mailimap_set_free( set ); | ||
1173 | if ( err != MAILIMAP_NO_ERROR ) { | ||
1174 | QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); | ||
1175 | Global::statusMessage(error_msg); | ||
1176 | // odebug << error_msg << oendl; | ||
1177 | return; | ||
1178 | } | ||
1179 | if (moveit) { | ||
1180 | deleteMail(mail); | ||
1181 | } | ||
1182 | } | ||
diff --git a/kmicromail/libmailwrapper/imapwrapper.h b/kmicromail/libmailwrapper/imapwrapper.h new file mode 100644 index 0000000..e56605a --- a/dev/null +++ b/kmicromail/libmailwrapper/imapwrapper.h | |||
@@ -0,0 +1,80 @@ | |||
1 | #ifndef __IMAPWRAPPER | ||
2 | #define __IMAPWRAPPER | ||
3 | |||
4 | #include <qlist.h> | ||
5 | #include "mailwrapper.h" | ||
6 | #include "abstractmail.h" | ||
7 | #include <libetpan/clist.h> | ||
8 | |||
9 | struct mailimap; | ||
10 | struct mailimap_body; | ||
11 | struct mailimap_body_type_1part; | ||
12 | struct mailimap_body_type_text; | ||
13 | struct mailimap_body_type_basic; | ||
14 | struct mailimap_body_type_msg; | ||
15 | struct mailimap_body_type_mpart; | ||
16 | struct mailimap_body_fields; | ||
17 | struct mailimap_msg_att; | ||
18 | class encodedString; | ||
19 | |||
20 | class IMAPwrapper : public AbstractMail | ||
21 | { | ||
22 | Q_OBJECT | ||
23 | public: | ||
24 | IMAPwrapper( IMAPaccount *a ); | ||
25 | virtual ~IMAPwrapper(); | ||
26 | virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); | ||
27 | virtual void listMessages(const QString & mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> >&target ); | ||
28 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | ||
29 | |||
30 | virtual void deleteMail(const RecMailP&mail); | ||
31 | virtual void answeredMail(const RecMailP&mail); | ||
32 | virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&folder); | ||
33 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | ||
34 | virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, | ||
35 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | ||
36 | virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | ||
37 | |||
38 | virtual RecBodyP fetchBody(const RecMailP&mail); | ||
39 | virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part); | ||
40 | virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part); | ||
41 | virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part); | ||
42 | virtual encodedString* fetchRawBody(const RecMailP&mail); | ||
43 | |||
44 | virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0, | ||
45 | const QString& delemiter="/",bool getsubfolder=false); | ||
46 | virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&folder); | ||
47 | |||
48 | static void imap_progress( size_t current, size_t maximum ); | ||
49 | |||
50 | virtual void logout(); | ||
51 | virtual MAILLIB::ATYPE getType()const; | ||
52 | virtual const QString&getName()const; | ||
53 | |||
54 | protected: | ||
55 | RecMail*parse_list_result(mailimap_msg_att*); | ||
56 | void login(); | ||
57 | bool start_tls(bool force=true); | ||
58 | |||
59 | 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); | ||
61 | int selectMbox(const QString&mbox); | ||
62 | |||
63 | void fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description); | ||
64 | void fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which); | ||
65 | void fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which); | ||
66 | void fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which); | ||
67 | 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); | ||
69 | |||
70 | /* just helpers */ | ||
71 | static void fillBodyFields(RecPartP&target_part,mailimap_body_fields*which); | ||
72 | static QStringList address_list_to_stringlist(clist*list); | ||
73 | |||
74 | |||
75 | IMAPaccount *account; | ||
76 | mailimap *m_imap; | ||
77 | QString m_Lastmbox; | ||
78 | }; | ||
79 | |||
80 | #endif | ||
diff --git a/kmicromail/libmailwrapper/libmailwrapper.control b/kmicromail/libmailwrapper/libmailwrapper.control new file mode 100644 index 0000000..ec55bb3 --- a/dev/null +++ b/kmicromail/libmailwrapper/libmailwrapper.control | |||
@@ -0,0 +1,10 @@ | |||
1 | Package: libmailwrapper | ||
2 | Files: lib/libmailwrapper.so* | ||
3 | Priority: optional | ||
4 | Section: libs | ||
5 | Maintainer: Rajko Albrecht <alwin@handhelds.org>, Juergen Graf <jgf@handhelds.org>, Maximilian Reiß <harlekin@handhelds.org> | ||
6 | Architecture: arm | ||
7 | Version: 0.6-$SUB_VERSION | ||
8 | Depends: task-opie-minimal, libopiecore2, libopieui2, libetpan (>= 0.33pre) | ||
9 | Description: wrapper lib needed by Opie's mailer | ||
10 | License: LGPL | ||
diff --git a/kmicromail/libmailwrapper/libmailwrapperE.pro b/kmicromail/libmailwrapper/libmailwrapperE.pro new file mode 100644 index 0000000..a53b022 --- a/dev/null +++ b/kmicromail/libmailwrapper/libmailwrapperE.pro | |||
@@ -0,0 +1,49 @@ | |||
1 | TEMPLATE = lib | ||
2 | CONFIG += qt warn_on | ||
3 | |||
4 | HEADERS = mailwrapper.h \ | ||
5 | imapwrapper.h \ | ||
6 | mailtypes.h \ | ||
7 | pop3wrapper.h \ | ||
8 | abstractmail.h \ | ||
9 | smtpwrapper.h \ | ||
10 | genericwrapper.h \ | ||
11 | mboxwrapper.h \ | ||
12 | settings.h \ | ||
13 | logindialog.h \ | ||
14 | sendmailprogress.h \ | ||
15 | statusmail.h \ | ||
16 | mhwrapper.h \ | ||
17 | nntpwrapper.h \ | ||
18 | generatemail.h \ | ||
19 | storemail.h | ||
20 | |||
21 | SOURCES = imapwrapper.cpp \ | ||
22 | mailwrapper.cpp \ | ||
23 | mailtypes.cpp \ | ||
24 | pop3wrapper.cpp \ | ||
25 | abstractmail.cpp \ | ||
26 | smtpwrapper.cpp \ | ||
27 | genericwrapper.cpp \ | ||
28 | mboxwrapper.cpp \ | ||
29 | settings.cpp \ | ||
30 | logindialog.cpp \ | ||
31 | sendmailprogress.cpp \ | ||
32 | statusmail.cpp \ | ||
33 | mhwrapper.cpp \ | ||
34 | nntpwrapper.cpp \ | ||
35 | generatemail.cpp \ | ||
36 | storemail.cpp | ||
37 | |||
38 | INTERFACES = logindialogui.ui \ | ||
39 | sendmailprogressui.ui | ||
40 | |||
41 | INCLUDEPATH += ../../microkde ../../microkde/kdecore ../libetpan/include $(QPEDIR)/include | ||
42 | LIBS += -lssl -lcrypto | ||
43 | |||
44 | #-lqpe -letpan | ||
45 | |||
46 | DESTDIR = $(QPEDIR)/lib | ||
47 | OBJECTS_DIR = obj/$(PLATFORM) | ||
48 | MOC_DIR = moc/$(PLATFORM) | ||
49 | TARGET = kmicromailwrapper | ||
diff --git a/kmicromail/libmailwrapper/logindialog.cpp b/kmicromail/libmailwrapper/logindialog.cpp new file mode 100644 index 0000000..31b75d0 --- a/dev/null +++ b/kmicromail/libmailwrapper/logindialog.cpp | |||
@@ -0,0 +1,33 @@ | |||
1 | #include <qlineedit.h> | ||
2 | |||
3 | #include "logindialog.h" | ||
4 | |||
5 | |||
6 | |||
7 | //using namespace Opie::Core; | ||
8 | |||
9 | LoginDialog::LoginDialog(const QString&user,const QString&pass, QWidget *parent, const char *name, bool modal, WFlags flags ) | ||
10 | : LoginDialogUI( parent, name, modal, flags ) | ||
11 | { | ||
12 | userLine->setText( (user.isEmpty()?QString(""):user) ); | ||
13 | passLine->setText( (pass.isEmpty()?QString(""):pass) ); | ||
14 | _user = user; | ||
15 | _pass = pass; | ||
16 | |||
17 | if ( user.isEmpty() ) { | ||
18 | userLine->setFocus(); | ||
19 | } else { | ||
20 | passLine->setFocus(); | ||
21 | } | ||
22 | } | ||
23 | |||
24 | void LoginDialog::accept() | ||
25 | { | ||
26 | //_user.replace( 0, _user.length(), userLine->text() ); | ||
27 | //_pass.replace( 0, _pass.length(), passLine->text() ); | ||
28 | _user = userLine->text(); | ||
29 | _pass = passLine->text(); | ||
30 | |||
31 | //odebug << "User im accept: |" << _user.latin1() << "|" << oendl; | ||
32 | QDialog::accept(); | ||
33 | } | ||
diff --git a/kmicromail/libmailwrapper/logindialog.h b/kmicromail/libmailwrapper/logindialog.h new file mode 100644 index 0000000..f406f2c --- a/dev/null +++ b/kmicromail/libmailwrapper/logindialog.h | |||
@@ -0,0 +1,23 @@ | |||
1 | #ifndef LOGINDIALOG_H | ||
2 | #define LOGINDIALOG_H | ||
3 | |||
4 | #include "logindialogui.h" | ||
5 | |||
6 | class LoginDialog : public LoginDialogUI | ||
7 | { | ||
8 | Q_OBJECT | ||
9 | |||
10 | public: | ||
11 | LoginDialog(const QString&user,const QString&pass, QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags flags = 0 ); | ||
12 | QString getUser() { return _user; } | ||
13 | QString getPassword() { return _pass; } | ||
14 | |||
15 | protected slots: | ||
16 | void accept(); | ||
17 | |||
18 | private: | ||
19 | QString _user, _pass; | ||
20 | |||
21 | }; | ||
22 | |||
23 | #endif | ||
diff --git a/kmicromail/libmailwrapper/logindialogui.ui b/kmicromail/libmailwrapper/logindialogui.ui new file mode 100644 index 0000000..565f777 --- a/dev/null +++ b/kmicromail/libmailwrapper/logindialogui.ui | |||
@@ -0,0 +1,83 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>LoginDialogUI</class> | ||
3 | <widget> | ||
4 | <class>QDialog</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>LoginDialogUI</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>196</width> | ||
15 | <height>110</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Login</string> | ||
21 | </property> | ||
22 | <property> | ||
23 | <name>layoutMargin</name> | ||
24 | </property> | ||
25 | <property> | ||
26 | <name>layoutSpacing</name> | ||
27 | </property> | ||
28 | <grid> | ||
29 | <property stdset="1"> | ||
30 | <name>margin</name> | ||
31 | <number>4</number> | ||
32 | </property> | ||
33 | <property stdset="1"> | ||
34 | <name>spacing</name> | ||
35 | <number>3</number> | ||
36 | </property> | ||
37 | <widget row="0" column="0" > | ||
38 | <class>QLabel</class> | ||
39 | <property stdset="1"> | ||
40 | <name>name</name> | ||
41 | <cstring>userLabel</cstring> | ||
42 | </property> | ||
43 | <property stdset="1"> | ||
44 | <name>text</name> | ||
45 | <string>User</string> | ||
46 | </property> | ||
47 | </widget> | ||
48 | <widget row="1" column="0" > | ||
49 | <class>QLineEdit</class> | ||
50 | <property stdset="1"> | ||
51 | <name>name</name> | ||
52 | <cstring>userLine</cstring> | ||
53 | </property> | ||
54 | </widget> | ||
55 | <widget row="3" column="0" > | ||
56 | <class>QLineEdit</class> | ||
57 | <property stdset="1"> | ||
58 | <name>name</name> | ||
59 | <cstring>passLine</cstring> | ||
60 | </property> | ||
61 | <property stdset="1"> | ||
62 | <name>echoMode</name> | ||
63 | <enum>Password</enum> | ||
64 | </property> | ||
65 | </widget> | ||
66 | <widget row="2" column="0" > | ||
67 | <class>QLabel</class> | ||
68 | <property stdset="1"> | ||
69 | <name>name</name> | ||
70 | <cstring>passLabel</cstring> | ||
71 | </property> | ||
72 | <property stdset="1"> | ||
73 | <name>text</name> | ||
74 | <string>Password</string> | ||
75 | </property> | ||
76 | </widget> | ||
77 | </grid> | ||
78 | </widget> | ||
79 | <tabstops> | ||
80 | <tabstop>userLine</tabstop> | ||
81 | <tabstop>passLine</tabstop> | ||
82 | </tabstops> | ||
83 | </UI> | ||
diff --git a/kmicromail/libmailwrapper/maildefines.h b/kmicromail/libmailwrapper/maildefines.h new file mode 100644 index 0000000..431f9ea --- a/dev/null +++ b/kmicromail/libmailwrapper/maildefines.h | |||
@@ -0,0 +1,16 @@ | |||
1 | #ifndef __MAILDEFINES_H | ||
2 | #define __MAILDEFINES_H | ||
3 | |||
4 | namespace MAILLIB { | ||
5 | enum ATYPE { | ||
6 | A_UNDEFINED, | ||
7 | A_IMAP, | ||
8 | A_POP3, | ||
9 | A_SMTP, | ||
10 | A_MH, | ||
11 | A_MBOX, | ||
12 | A_NNTP, | ||
13 | }; | ||
14 | } | ||
15 | |||
16 | #endif | ||
diff --git a/kmicromail/libmailwrapper/mailtypes.cpp b/kmicromail/libmailwrapper/mailtypes.cpp new file mode 100644 index 0000000..d43bdc6 --- a/dev/null +++ b/kmicromail/libmailwrapper/mailtypes.cpp | |||
@@ -0,0 +1,399 @@ | |||
1 | #include "mailtypes.h" | ||
2 | |||
3 | //#include <opie2/odebug.h> | ||
4 | |||
5 | #include <stdlib.h> | ||
6 | |||
7 | using namespace Opie::Core; | ||
8 | RecMail::RecMail() | ||
9 | :Opie::Core::ORefCount(),subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) | ||
10 | { | ||
11 | init(); | ||
12 | } | ||
13 | |||
14 | RecMail::RecMail(const RecMail&old) | ||
15 | :Opie::Core::ORefCount(),subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) | ||
16 | { | ||
17 | init(); | ||
18 | copy_old(old); | ||
19 | // odebug << "Copy constructor RecMail" << oendl; | ||
20 | } | ||
21 | |||
22 | RecMail::~RecMail() | ||
23 | { | ||
24 | wrapper = 0; | ||
25 | } | ||
26 | |||
27 | void RecMail::copy_old(const RecMail&old) | ||
28 | { | ||
29 | subject = old.subject; | ||
30 | date = old.date; | ||
31 | mbox = old.mbox; | ||
32 | msg_id = old.msg_id; | ||
33 | msg_size = old.msg_size; | ||
34 | msg_number = old.msg_number; | ||
35 | from = old.from; | ||
36 | msg_flags = old.msg_flags; | ||
37 | to = old.to; | ||
38 | cc = old.cc; | ||
39 | bcc = old.bcc; | ||
40 | wrapper = old.wrapper; | ||
41 | in_reply_to = old.in_reply_to; | ||
42 | references = old.references; | ||
43 | replyto = old.replyto; | ||
44 | } | ||
45 | |||
46 | void RecMail::init() | ||
47 | { | ||
48 | to.clear(); | ||
49 | cc.clear(); | ||
50 | bcc.clear(); | ||
51 | in_reply_to.clear(); | ||
52 | references.clear(); | ||
53 | wrapper = 0; | ||
54 | } | ||
55 | |||
56 | void RecMail::setWrapper(AbstractMail*awrapper) | ||
57 | { | ||
58 | wrapper = awrapper; | ||
59 | } | ||
60 | |||
61 | AbstractMail* RecMail::Wrapper() | ||
62 | { | ||
63 | return wrapper; | ||
64 | } | ||
65 | |||
66 | void RecMail::setTo(const QStringList&list) | ||
67 | { | ||
68 | to = list; | ||
69 | } | ||
70 | |||
71 | const QStringList&RecMail::To()const | ||
72 | { | ||
73 | return to; | ||
74 | } | ||
75 | |||
76 | void RecMail::setCC(const QStringList&list) | ||
77 | { | ||
78 | cc = list; | ||
79 | } | ||
80 | |||
81 | const QStringList&RecMail::CC()const | ||
82 | { | ||
83 | return cc; | ||
84 | } | ||
85 | |||
86 | void RecMail::setBcc(const QStringList&list) | ||
87 | { | ||
88 | bcc = list; | ||
89 | } | ||
90 | |||
91 | const QStringList& RecMail::Bcc()const | ||
92 | { | ||
93 | return bcc; | ||
94 | } | ||
95 | |||
96 | void RecMail::setInreply(const QStringList&list) | ||
97 | { | ||
98 | in_reply_to = list; | ||
99 | } | ||
100 | |||
101 | const QStringList& RecMail::Inreply()const | ||
102 | { | ||
103 | return in_reply_to; | ||
104 | } | ||
105 | |||
106 | void RecMail::setReferences(const QStringList&list) | ||
107 | { | ||
108 | references = list; | ||
109 | } | ||
110 | |||
111 | const QStringList& RecMail::References()const | ||
112 | { | ||
113 | return references; | ||
114 | } | ||
115 | |||
116 | RecPart::RecPart() | ||
117 | : Opie::Core::ORefCount(), | ||
118 | m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) | ||
119 | { | ||
120 | m_Parameters.clear(); | ||
121 | m_poslist.clear(); | ||
122 | } | ||
123 | |||
124 | RecPart::RecPart(const RecPart&old) | ||
125 | : Opie::Core::ORefCount(), | ||
126 | m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) | ||
127 | { | ||
128 | m_type = old.m_type; | ||
129 | m_subtype = old.m_subtype; | ||
130 | m_identifier = old.m_identifier; | ||
131 | m_encoding = old.m_encoding; | ||
132 | m_description = old.m_description; | ||
133 | m_lines = old.m_lines; | ||
134 | m_size = old.m_size; | ||
135 | m_Parameters = old.m_Parameters; | ||
136 | m_poslist = old.m_poslist; | ||
137 | // odebug << "RecPart copy constructor" << oendl; | ||
138 | } | ||
139 | |||
140 | RecPart::~RecPart() | ||
141 | { | ||
142 | } | ||
143 | |||
144 | void RecPart::setSize(unsigned int size) | ||
145 | { | ||
146 | m_size = size; | ||
147 | } | ||
148 | |||
149 | const unsigned int RecPart::Size()const | ||
150 | { | ||
151 | return m_size; | ||
152 | } | ||
153 | |||
154 | void RecPart::setLines(unsigned int lines) | ||
155 | { | ||
156 | m_lines = lines; | ||
157 | } | ||
158 | |||
159 | const unsigned int RecPart::Lines()const | ||
160 | { | ||
161 | return m_lines; | ||
162 | } | ||
163 | |||
164 | const QString& RecPart::Type()const | ||
165 | { | ||
166 | return m_type; | ||
167 | } | ||
168 | |||
169 | void RecPart::setType(const QString&type) | ||
170 | { | ||
171 | m_type = type; | ||
172 | } | ||
173 | |||
174 | const QString& RecPart::Subtype()const | ||
175 | { | ||
176 | return m_subtype; | ||
177 | } | ||
178 | |||
179 | void RecPart::setSubtype(const QString&subtype) | ||
180 | { | ||
181 | m_subtype = subtype; | ||
182 | } | ||
183 | |||
184 | const QString& RecPart::Identifier()const | ||
185 | { | ||
186 | return m_identifier; | ||
187 | } | ||
188 | |||
189 | void RecPart::setIdentifier(const QString&identifier) | ||
190 | { | ||
191 | m_identifier = identifier; | ||
192 | } | ||
193 | |||
194 | const QString& RecPart::Encoding()const | ||
195 | { | ||
196 | return m_encoding; | ||
197 | } | ||
198 | |||
199 | void RecPart::setEncoding(const QString&encoding) | ||
200 | { | ||
201 | m_encoding = encoding; | ||
202 | } | ||
203 | |||
204 | const QString& RecPart::Description()const | ||
205 | { | ||
206 | return m_description; | ||
207 | } | ||
208 | |||
209 | void RecPart::setDescription(const QString&desc) | ||
210 | { | ||
211 | m_description = desc; | ||
212 | } | ||
213 | |||
214 | void RecPart::setParameters(const part_plist_t&list) | ||
215 | { | ||
216 | m_Parameters = list; | ||
217 | } | ||
218 | |||
219 | const part_plist_t& RecPart::Parameters()const | ||
220 | { | ||
221 | return m_Parameters; | ||
222 | } | ||
223 | |||
224 | void RecPart::addParameter(const QString&key,const QString&value) | ||
225 | { | ||
226 | m_Parameters[key]=value; | ||
227 | } | ||
228 | |||
229 | const QString RecPart::searchParamter(const QString&key)const | ||
230 | { | ||
231 | QString value(""); | ||
232 | part_plist_t::ConstIterator it = m_Parameters.find(key); | ||
233 | if (it != m_Parameters.end()) { | ||
234 | value = it.data(); | ||
235 | } | ||
236 | return value; | ||
237 | } | ||
238 | |||
239 | void RecPart::setPositionlist(const QValueList<int>&poslist) | ||
240 | { | ||
241 | m_poslist = poslist; | ||
242 | } | ||
243 | |||
244 | const QValueList<int>& RecPart::Positionlist()const | ||
245 | { | ||
246 | return m_poslist; | ||
247 | } | ||
248 | |||
249 | RecBody::RecBody() | ||
250 | : Opie::Core::ORefCount(),m_BodyText(),m_description(new RecPart()) | ||
251 | { | ||
252 | m_PartsList.clear(); | ||
253 | } | ||
254 | |||
255 | RecBody::RecBody(const RecBody&old) | ||
256 | :Opie::Core::ORefCount(),m_BodyText(),m_PartsList(),m_description(new RecPart()) | ||
257 | { | ||
258 | m_BodyText = old.m_BodyText; | ||
259 | m_PartsList = old.m_PartsList; | ||
260 | m_description = old.m_description; | ||
261 | // odebug << "Recbody copy constructor" << oendl; | ||
262 | } | ||
263 | |||
264 | RecBody::~RecBody() | ||
265 | { | ||
266 | } | ||
267 | |||
268 | void RecBody::setBodytext(const QString&bodyText) | ||
269 | { | ||
270 | m_BodyText = bodyText; | ||
271 | } | ||
272 | |||
273 | const QString& RecBody::Bodytext()const | ||
274 | { | ||
275 | return m_BodyText; | ||
276 | } | ||
277 | |||
278 | void RecBody::setParts(const QValueList<RecPartP>&parts) | ||
279 | { | ||
280 | m_PartsList.clear(); | ||
281 | m_PartsList = parts; | ||
282 | } | ||
283 | |||
284 | const QValueList<RecPartP>& RecBody::Parts()const | ||
285 | { | ||
286 | return m_PartsList; | ||
287 | } | ||
288 | |||
289 | void RecBody::addPart(const RecPartP& part) | ||
290 | { | ||
291 | m_PartsList.append(part); | ||
292 | } | ||
293 | |||
294 | void RecBody::setDescription(const RecPartP&des) | ||
295 | { | ||
296 | m_description = des; | ||
297 | } | ||
298 | |||
299 | const RecPartP& RecBody::Description()const | ||
300 | { | ||
301 | return m_description; | ||
302 | } | ||
303 | |||
304 | /* handling encoded content */ | ||
305 | encodedString::encodedString() | ||
306 | { | ||
307 | init(); | ||
308 | } | ||
309 | |||
310 | encodedString::encodedString(const char*nContent,unsigned int nSize) | ||
311 | { | ||
312 | init(); | ||
313 | setContent(nContent,nSize); | ||
314 | } | ||
315 | |||
316 | encodedString::encodedString(char*nContent,unsigned int nSize) | ||
317 | { | ||
318 | init(); | ||
319 | setContent(nContent,nSize); | ||
320 | } | ||
321 | |||
322 | encodedString::encodedString(const encodedString&old) | ||
323 | { | ||
324 | init(); | ||
325 | copy_old(old); | ||
326 | // odebug << "encodedeString: copy constructor!" << oendl; | ||
327 | } | ||
328 | |||
329 | encodedString& encodedString::operator=(const encodedString&old) | ||
330 | { | ||
331 | init(); | ||
332 | copy_old(old); | ||
333 | // odebug << "encodedString: assign operator!" << oendl; | ||
334 | return *this; | ||
335 | } | ||
336 | |||
337 | encodedString::~encodedString() | ||
338 | { | ||
339 | clean(); | ||
340 | } | ||
341 | |||
342 | void encodedString::init() | ||
343 | { | ||
344 | content = 0; | ||
345 | size = 0; | ||
346 | } | ||
347 | |||
348 | void encodedString::clean() | ||
349 | { | ||
350 | if (content) { | ||
351 | free(content); | ||
352 | } | ||
353 | content = 0; | ||
354 | size = 0; | ||
355 | } | ||
356 | |||
357 | void encodedString::copy_old(const encodedString&old) | ||
358 | { | ||
359 | clean(); | ||
360 | if (old.size>0 && old.content) { | ||
361 | content = (char*)malloc(old.size*sizeof(char)); | ||
362 | memcpy(content,old.content,size); | ||
363 | size = old.size; | ||
364 | } | ||
365 | } | ||
366 | |||
367 | const char*encodedString::Content()const | ||
368 | { | ||
369 | return content; | ||
370 | } | ||
371 | |||
372 | const int encodedString::Length()const | ||
373 | { | ||
374 | return size; | ||
375 | } | ||
376 | |||
377 | void encodedString::setContent(const char*nContent,int nSize) | ||
378 | { | ||
379 | if (nSize>0 && nContent) { | ||
380 | content = (char*)malloc(nSize*sizeof(char)); | ||
381 | memcpy(content,nContent,nSize); | ||
382 | size = nSize; | ||
383 | } | ||
384 | } | ||
385 | |||
386 | void encodedString::setContent(char*nContent,int nSize) | ||
387 | { | ||
388 | content = nContent; | ||
389 | size = nSize; | ||
390 | } | ||
391 | |||
392 | folderStat&folderStat::operator=(const folderStat&old) | ||
393 | { | ||
394 | message_count = old.message_count; | ||
395 | message_unseen = old.message_unseen; | ||
396 | message_recent = old.message_recent; | ||
397 | return *this; | ||
398 | } | ||
399 | |||
diff --git a/kmicromail/libmailwrapper/mailtypes.h b/kmicromail/libmailwrapper/mailtypes.h new file mode 100644 index 0000000..c317880 --- a/dev/null +++ b/kmicromail/libmailwrapper/mailtypes.h | |||
@@ -0,0 +1,206 @@ | |||
1 | #ifndef __MAIL_TYPES_H | ||
2 | #define __MAIL_TYPES_H | ||
3 | |||
4 | #define FLAG_ANSWERED 0 | ||
5 | #define FLAG_FLAGGED 1 | ||
6 | #define FLAG_DELETED 2 | ||
7 | #define FLAG_SEEN 3 | ||
8 | #define FLAG_DRAFT 4 | ||
9 | #define FLAG_RECENT 5 | ||
10 | |||
11 | #include <opie2/osmartpointer.h> | ||
12 | |||
13 | #include <qbitarray.h> | ||
14 | #include <qstring.h> | ||
15 | #include <qstringlist.h> | ||
16 | #include <qmap.h> | ||
17 | #include <qvaluelist.h> | ||
18 | |||
19 | class AbstractMail; | ||
20 | /* a class to describe mails in a mailbox */ | ||
21 | /* Attention! | ||
22 | From programmers point of view it would make sense to | ||
23 | store the mail body into this class, too. | ||
24 | But: not from the point of view of the device. | ||
25 | Mailbodies can be real large. So we request them when | ||
26 | needed from the mail-wrapper class direct from the server itself | ||
27 | (imap) or from a file-based cache (pop3?) | ||
28 | So there is no interface "const QString&body()" but you should | ||
29 | make a request to the mailwrapper with this class as parameter to | ||
30 | get the body. Same words for the attachments. | ||
31 | */ | ||
32 | class RecMail:public Opie::Core::ORefCount | ||
33 | { | ||
34 | public: | ||
35 | RecMail(); | ||
36 | RecMail(const RecMail&old); | ||
37 | virtual ~RecMail(); | ||
38 | |||
39 | const unsigned int getNumber()const{return msg_number;} | ||
40 | void setNumber(unsigned int number){msg_number=number;} | ||
41 | const QString&getDate()const{ return date; } | ||
42 | void setDate( const QString&a ) { date = a; } | ||
43 | const QString&getFrom()const{ return from; } | ||
44 | void setFrom( const QString&a ) { from = a; } | ||
45 | const QString&getSubject()const { return subject; } | ||
46 | void setSubject( const QString&s ) { subject = s; } | ||
47 | const QString&getMbox()const{return mbox;} | ||
48 | void setMbox(const QString&box){mbox = box;} | ||
49 | void setMsgid(const QString&id){msg_id=id;} | ||
50 | const QString&Msgid()const{return msg_id;} | ||
51 | void setReplyto(const QString&reply){replyto=reply;} | ||
52 | const QString&Replyto()const{return replyto;} | ||
53 | void setMsgsize(unsigned int size){msg_size = size;} | ||
54 | const unsigned int Msgsize()const{return msg_size;} | ||
55 | |||
56 | |||
57 | void setTo(const QStringList&list); | ||
58 | const QStringList&To()const; | ||
59 | void setCC(const QStringList&list); | ||
60 | const QStringList&CC()const; | ||
61 | void setBcc(const QStringList&list); | ||
62 | const QStringList&Bcc()const; | ||
63 | void setInreply(const QStringList&list); | ||
64 | const QStringList&Inreply()const; | ||
65 | void setReferences(const QStringList&list); | ||
66 | const QStringList&References()const; | ||
67 | |||
68 | const QBitArray&getFlags()const{return msg_flags;} | ||
69 | void setFlags(const QBitArray&flags){msg_flags = flags;} | ||
70 | |||
71 | void setWrapper(AbstractMail*wrapper); | ||
72 | AbstractMail* Wrapper(); | ||
73 | |||
74 | protected: | ||
75 | QString subject,date,from,mbox,msg_id,replyto; | ||
76 | unsigned int msg_number,msg_size; | ||
77 | QBitArray msg_flags; | ||
78 | QStringList to,cc,bcc,in_reply_to,references; | ||
79 | AbstractMail*wrapper; | ||
80 | void init(); | ||
81 | void copy_old(const RecMail&old); | ||
82 | }; | ||
83 | |||
84 | typedef Opie::Core::OSmartPointer<RecMail> RecMailP; | ||
85 | typedef QMap<QString,QString> part_plist_t; | ||
86 | |||
87 | class RecPart:public Opie::Core::ORefCount | ||
88 | { | ||
89 | protected: | ||
90 | QString m_type,m_subtype,m_identifier,m_encoding,m_description; | ||
91 | unsigned int m_lines,m_size; | ||
92 | part_plist_t m_Parameters; | ||
93 | /* describes the position in the mail */ | ||
94 | QValueList<int> m_poslist; | ||
95 | |||
96 | public: | ||
97 | RecPart(); | ||
98 | RecPart(const RecPart&); | ||
99 | virtual ~RecPart(); | ||
100 | |||
101 | const QString&Type()const; | ||
102 | void setType(const QString&type); | ||
103 | const QString&Subtype()const; | ||
104 | void setSubtype(const QString&subtype); | ||
105 | const QString&Identifier()const; | ||
106 | void setIdentifier(const QString&identifier); | ||
107 | const QString&Encoding()const; | ||
108 | void setEncoding(const QString&encoding); | ||
109 | const QString&Description()const; | ||
110 | void setDescription(const QString&desc); | ||
111 | void setLines(unsigned int lines); | ||
112 | const unsigned int Lines()const; | ||
113 | void setSize(unsigned int size); | ||
114 | const unsigned int Size()const; | ||
115 | |||
116 | |||
117 | void setParameters(const part_plist_t&list); | ||
118 | const part_plist_t&Parameters()const; | ||
119 | void addParameter(const QString&key,const QString&value); | ||
120 | const QString searchParamter(const QString&key)const; | ||
121 | void setPositionlist(const QValueList<int>&poslist); | ||
122 | const QValueList<int>& Positionlist()const; | ||
123 | }; | ||
124 | |||
125 | typedef Opie::Core::OSmartPointer<RecPart> RecPartP; | ||
126 | |||
127 | class RecBody:public Opie::Core::ORefCount | ||
128 | { | ||
129 | protected: | ||
130 | QString m_BodyText; | ||
131 | QValueList<RecPartP> m_PartsList; | ||
132 | RecPartP m_description; | ||
133 | |||
134 | public: | ||
135 | RecBody(); | ||
136 | RecBody(const RecBody&old); | ||
137 | virtual ~RecBody(); | ||
138 | void setBodytext(const QString&); | ||
139 | const QString& Bodytext()const; | ||
140 | |||
141 | void setDescription(const RecPartP&des); | ||
142 | const RecPartP& Description()const; | ||
143 | |||
144 | void setParts(const QValueList<RecPartP>&parts); | ||
145 | const QValueList<RecPartP>& Parts()const; | ||
146 | void addPart(const RecPartP&part); | ||
147 | }; | ||
148 | |||
149 | typedef Opie::Core::OSmartPointer<RecBody> RecBodyP; | ||
150 | |||
151 | class encodedString | ||
152 | { | ||
153 | public: | ||
154 | encodedString(); | ||
155 | /* | ||
156 | creates an new content string. | ||
157 | it makes a deep copy of it! | ||
158 | */ | ||
159 | encodedString(const char*nContent,unsigned int length); | ||
160 | /* | ||
161 | Take over the nContent. Means: it will just copy the pointer, not the content. | ||
162 | so make sure: No one else frees the string, the string has allocated with | ||
163 | malloc for compatibility with c-based libs | ||
164 | */ | ||
165 | encodedString(char*nContent,unsigned int nSize); | ||
166 | /* copy construkor - makes ALWAYS a deep copy!!!! */ | ||
167 | encodedString(const encodedString&old); | ||
168 | /* assign operator - makes ALWAYS a deep copy!!!! */ | ||
169 | encodedString& operator=(const encodedString&old); | ||
170 | /* destructor - cleans the content */ | ||
171 | virtual ~encodedString(); | ||
172 | |||
173 | /* returns a pointer to the content - do not delete yoursel! */ | ||
174 | const char*Content()const; | ||
175 | /* returns the lengths of the content 'cause it must not be a null-terminated string! */ | ||
176 | const int Length()const; | ||
177 | |||
178 | /* | ||
179 | makes a deep copy of nContent! | ||
180 | */ | ||
181 | void setContent(const char*nContent,int nSize); | ||
182 | /* | ||
183 | Take over the nContent. Means: it will just copy the pointer, not the content. | ||
184 | so make sure: No one else frees the string, the string has allocated with | ||
185 | malloc for compatibility with c-based libs | ||
186 | */ | ||
187 | void setContent(char*nContent,int nSize); | ||
188 | |||
189 | protected: | ||
190 | char * content; | ||
191 | unsigned int size; | ||
192 | |||
193 | void init(); | ||
194 | void copy_old(const encodedString&old); | ||
195 | void clean(); | ||
196 | }; | ||
197 | |||
198 | struct folderStat | ||
199 | { | ||
200 | unsigned int message_count; | ||
201 | unsigned int message_unseen; | ||
202 | unsigned int message_recent; | ||
203 | folderStat&operator=(const folderStat&old); | ||
204 | }; | ||
205 | |||
206 | #endif | ||
diff --git a/kmicromail/libmailwrapper/mailwrapper.cpp b/kmicromail/libmailwrapper/mailwrapper.cpp new file mode 100644 index 0000000..9400649 --- a/dev/null +++ b/kmicromail/libmailwrapper/mailwrapper.cpp | |||
@@ -0,0 +1,180 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <sys/stat.h> | ||
3 | #include <sys/types.h> | ||
4 | #include <unistd.h> | ||
5 | #include <fcntl.h> | ||
6 | #include <string.h> | ||
7 | #include <qdir.h> | ||
8 | |||
9 | #include "mailwrapper.h" | ||
10 | //#include "logindialog.h" | ||
11 | //#include "defines.h" | ||
12 | |||
13 | #define UNDEFINED 64 | ||
14 | #define MAXLINE 76 | ||
15 | #define UTF16MASK 0x03FFUL | ||
16 | #define UTF16SHIFT 10 | ||
17 | #define UTF16BASE 0x10000UL | ||
18 | #define UTF16HIGHSTART 0xD800UL | ||
19 | #define UTF16HIGHEND 0xDBFFUL | ||
20 | #define UTF16LOSTART 0xDC00UL | ||
21 | #define UTF16LOEND 0xDFFFUL | ||
22 | |||
23 | |||
24 | using namespace Opie::Core; | ||
25 | Attachment::Attachment( QString lnk ) | ||
26 | { | ||
27 | doc = lnk; | ||
28 | size = QFileInfo( doc ).size(); | ||
29 | mPix = SmallIcon( "files" ); | ||
30 | } | ||
31 | |||
32 | Folder::Folder(const QString&tmp_name, const QString&sep ) | ||
33 | { | ||
34 | name = tmp_name; | ||
35 | nameDisplay = name; | ||
36 | separator = sep; | ||
37 | prefix = ""; | ||
38 | } | ||
39 | |||
40 | Folder::~Folder() | ||
41 | { | ||
42 | } | ||
43 | |||
44 | const QString& Folder::Separator()const | ||
45 | { | ||
46 | return separator; | ||
47 | } | ||
48 | |||
49 | IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&aprefix ) | ||
50 | : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf) | ||
51 | { | ||
52 | // Decode IMAP foldername | ||
53 | nameDisplay = IMAPFolder::decodeFolderName( name ); | ||
54 | /* | ||
55 | odebug << "folder " + name + " - displayed as " + nameDisplay << oendl; | ||
56 | */ | ||
57 | prefix = aprefix; | ||
58 | |||
59 | if (prefix.length()>0) { | ||
60 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { | ||
61 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | |||
66 | IMAPFolder::~IMAPFolder() | ||
67 | { | ||
68 | } | ||
69 | |||
70 | static unsigned char base64chars[] = | ||
71 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; | ||
72 | |||
73 | /** | ||
74 | * Decodes base64 encoded parts of the imapfolder name | ||
75 | * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc | ||
76 | */ | ||
77 | QString IMAPFolder::decodeFolderName( const QString &name ) | ||
78 | { | ||
79 | unsigned char c, i, bitcount; | ||
80 | unsigned long ucs4, utf16, bitbuf; | ||
81 | unsigned char base64[256], utf8[6]; | ||
82 | unsigned long srcPtr = 0; | ||
83 | QCString dst = ""; | ||
84 | QCString src = name.ascii(); | ||
85 | |||
86 | /* initialize modified base64 decoding table */ | ||
87 | memset(base64, UNDEFINED, sizeof(base64)); | ||
88 | for (i = 0; i < sizeof(base64chars); ++i) { | ||
89 | base64[(int)base64chars[i]] = i; | ||
90 | } | ||
91 | |||
92 | /* loop until end of string */ | ||
93 | while (srcPtr < src.length ()) { | ||
94 | c = src[srcPtr++]; | ||
95 | /* deal with literal characters and &- */ | ||
96 | if (c != '&' || src[srcPtr] == '-') { | ||
97 | /* encode literally */ | ||
98 | dst += c; | ||
99 | /* skip over the '-' if this is an &- sequence */ | ||
100 | if (c == '&') | ||
101 | srcPtr++; | ||
102 | } else { | ||
103 | /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ | ||
104 | bitbuf = 0; | ||
105 | bitcount = 0; | ||
106 | ucs4 = 0; | ||
107 | while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { | ||
108 | ++srcPtr; | ||
109 | bitbuf = (bitbuf << 6) | c; | ||
110 | bitcount += 6; | ||
111 | /* enough bits for a UTF-16 character? */ | ||
112 | if (bitcount >= 16) { | ||
113 | bitcount -= 16; | ||
114 | utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; | ||
115 | /* convert UTF16 to UCS4 */ | ||
116 | if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { | ||
117 | ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; | ||
118 | continue; | ||
119 | } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { | ||
120 | ucs4 += utf16 - UTF16LOSTART + UTF16BASE; | ||
121 | } else { | ||
122 | ucs4 = utf16; | ||
123 | } | ||
124 | /* convert UTF-16 range of UCS4 to UTF-8 */ | ||
125 | if (ucs4 <= 0x7fUL) { | ||
126 | utf8[0] = ucs4; | ||
127 | i = 1; | ||
128 | } else if (ucs4 <= 0x7ffUL) { | ||
129 | utf8[0] = 0xc0 | (ucs4 >> 6); | ||
130 | utf8[1] = 0x80 | (ucs4 & 0x3f); | ||
131 | i = 2; | ||
132 | } else if (ucs4 <= 0xffffUL) { | ||
133 | utf8[0] = 0xe0 | (ucs4 >> 12); | ||
134 | utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); | ||
135 | utf8[2] = 0x80 | (ucs4 & 0x3f); | ||
136 | i = 3; | ||
137 | } else { | ||
138 | utf8[0] = 0xf0 | (ucs4 >> 18); | ||
139 | utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); | ||
140 | utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); | ||
141 | utf8[3] = 0x80 | (ucs4 & 0x3f); | ||
142 | i = 4; | ||
143 | } | ||
144 | /* copy it */ | ||
145 | for (c = 0; c < i; ++c) { | ||
146 | dst += utf8[c]; | ||
147 | } | ||
148 | } | ||
149 | } | ||
150 | /* skip over trailing '-' in modified UTF-7 encoding */ | ||
151 | if (src[srcPtr] == '-') | ||
152 | ++srcPtr; | ||
153 | } | ||
154 | } | ||
155 | |||
156 | return QString::fromUtf8( dst.data() ); | ||
157 | } | ||
158 | |||
159 | Mail::Mail() | ||
160 | :Opie::Core::ORefCount(),name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") | ||
161 | { | ||
162 | } | ||
163 | |||
164 | MHFolder::MHFolder(const QString&disp_name,const QString&mbox) | ||
165 | : Folder( disp_name,"/" ) | ||
166 | { | ||
167 | separator = "/"; | ||
168 | name = mbox; | ||
169 | if (!disp_name.startsWith("/") && disp_name.length()>0) | ||
170 | name+="/"; | ||
171 | name+=disp_name; | ||
172 | if (disp_name.length()==0) { | ||
173 | nameDisplay = separator; | ||
174 | } | ||
175 | prefix = mbox; | ||
176 | } | ||
177 | |||
178 | MHFolder::~MHFolder() | ||
179 | { | ||
180 | } | ||
diff --git a/kmicromail/libmailwrapper/mailwrapper.h b/kmicromail/libmailwrapper/mailwrapper.h new file mode 100644 index 0000000..adfac6a --- a/dev/null +++ b/kmicromail/libmailwrapper/mailwrapper.h | |||
@@ -0,0 +1,128 @@ | |||
1 | #ifndef MAILWRAPPER_H | ||
2 | #define MAILWRAPPER_H | ||
3 | |||
4 | #include <qpe/applnk.h> | ||
5 | |||
6 | #include <qbitarray.h> | ||
7 | #include <qdatetime.h> | ||
8 | #include <qfileinfo.h> | ||
9 | #include <kiconloader.h> | ||
10 | |||
11 | #include "settings.h" | ||
12 | |||
13 | #include <opie2/osmartpointer.h> | ||
14 | /* | ||
15 | class Attachment | ||
16 | { | ||
17 | public: | ||
18 | Attachment( DocLnk lnk ); | ||
19 | virtual ~Attachment(){} | ||
20 | const QString getFileName()const{ return doc.file(); } | ||
21 | const QString getName()const{ return doc.name(); } | ||
22 | const QString getMimeType()const{ return doc.type(); } | ||
23 | const QPixmap getPixmap()const{ return doc.pixmap(); } | ||
24 | const int getSize()const { return size; } | ||
25 | DocLnk getDocLnk() { return doc; } | ||
26 | |||
27 | protected: | ||
28 | DocLnk doc; | ||
29 | int size; | ||
30 | |||
31 | }; | ||
32 | */ | ||
33 | |||
34 | class Attachment | ||
35 | { | ||
36 | public: | ||
37 | Attachment( QString lnk ); | ||
38 | virtual ~Attachment(){} | ||
39 | const QString getFileName()const{ return QFileInfo( doc ).fileName (); } | ||
40 | const QString getName()const{ return QFileInfo( doc ).baseName (); } | ||
41 | const QString getMimeType()const{ return QFileInfo( doc ).extension(false); } | ||
42 | const QPixmap getPixmap()const{ return mPix; } | ||
43 | const int getSize()const { return size; } | ||
44 | QString getDocLnk() { return doc; } | ||
45 | |||
46 | protected: | ||
47 | QPixmap mPix; | ||
48 | QString doc; | ||
49 | int size; | ||
50 | |||
51 | }; | ||
52 | |||
53 | class Mail:public Opie::Core::ORefCount | ||
54 | { | ||
55 | public: | ||
56 | Mail(); | ||
57 | /* Possible that this destructor must not be declared virtual | ||
58 | * 'cause it seems that it will never have some child classes. | ||
59 | * in this case this object will not get a virtual table -> memory and | ||
60 | * speed will be a little bit better? | ||
61 | */ | ||
62 | virtual ~Mail(){} | ||
63 | void addAttachment( Attachment *att ) { attList.append( att ); } | ||
64 | const QList<Attachment>& getAttachments()const { return attList; } | ||
65 | void removeAttachment( Attachment *att ) { attList.remove( att ); } | ||
66 | const QString&getName()const { return name; } | ||
67 | void setName( QString s ) { name = s; } | ||
68 | const QString&getMail()const{ return mail; } | ||
69 | void setMail( const QString&s ) { mail = s; } | ||
70 | const QString&getTo()const{ return to; } | ||
71 | void setTo( const QString&s ) { to = s; } | ||
72 | const QString&getCC()const{ return cc; } | ||
73 | void setCC( const QString&s ) { cc = s; } | ||
74 | const QString&getBCC()const { return bcc; } | ||
75 | void setBCC( const QString&s ) { bcc = s; } | ||
76 | const QString&getMessage()const { return message; } | ||
77 | void setMessage( const QString&s ) { message = s; } | ||
78 | const QString&getSubject()const { return subject; } | ||
79 | void setSubject( const QString&s ) { subject = s; } | ||
80 | const QString&getReply()const{ return reply; } | ||
81 | void setReply( const QString&a ) { reply = a; } | ||
82 | void setInreply(const QStringList&list){m_in_reply_to = list;} | ||
83 | const QStringList&Inreply()const{return m_in_reply_to;} | ||
84 | |||
85 | private: | ||
86 | QList<Attachment> attList; | ||
87 | QString name, mail, to, cc, bcc, reply, subject, message; | ||
88 | QStringList m_in_reply_to; | ||
89 | }; | ||
90 | |||
91 | class Folder:public Opie::Core::ORefCount | ||
92 | { | ||
93 | public: | ||
94 | Folder( const QString&init_name,const QString&sep ); | ||
95 | virtual ~Folder(); | ||
96 | const QString&getDisplayName()const { return nameDisplay; } | ||
97 | const QString&getName()const { return name; } | ||
98 | const QString&getPrefix()const{return prefix; } | ||
99 | virtual bool may_select()const{return true;} | ||
100 | virtual bool no_inferior()const{return true;} | ||
101 | const QString&Separator()const; | ||
102 | |||
103 | protected: | ||
104 | QString nameDisplay, name, separator,prefix; | ||
105 | }; | ||
106 | |||
107 | typedef Opie::Core::OSmartPointer<Folder> FolderP; | ||
108 | |||
109 | class MHFolder : public Folder | ||
110 | { | ||
111 | public: | ||
112 | MHFolder(const QString&disp_name,const QString&mbox); | ||
113 | virtual ~MHFolder(); | ||
114 | }; | ||
115 | |||
116 | class IMAPFolder : public Folder | ||
117 | { | ||
118 | public: | ||
119 | IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" ); | ||
120 | virtual ~IMAPFolder(); | ||
121 | virtual bool may_select()const{return m_MaySelect;} | ||
122 | virtual bool no_inferior()const{return m_NoInferior;} | ||
123 | private: | ||
124 | static QString decodeFolderName( const QString &name ); | ||
125 | bool m_MaySelect,m_NoInferior; | ||
126 | }; | ||
127 | |||
128 | #endif | ||
diff --git a/kmicromail/libmailwrapper/mboxwrapper.cpp b/kmicromail/libmailwrapper/mboxwrapper.cpp new file mode 100644 index 0000000..39dd156 --- a/dev/null +++ b/kmicromail/libmailwrapper/mboxwrapper.cpp | |||
@@ -0,0 +1,338 @@ | |||
1 | #include "mboxwrapper.h" | ||
2 | #include "mailtypes.h" | ||
3 | #include "mailwrapper.h" | ||
4 | #include <libetpan/libetpan.h> | ||
5 | #include <qdir.h> | ||
6 | #include <stdlib.h> | ||
7 | |||
8 | |||
9 | #include <qpe/global.h> | ||
10 | |||
11 | using namespace Opie::Core; | ||
12 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name) | ||
13 | : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name) | ||
14 | { | ||
15 | QDir dir(MBOXPath); | ||
16 | if (!dir.exists()) { | ||
17 | dir.mkdir(MBOXPath); | ||
18 | } | ||
19 | } | ||
20 | |||
21 | MBOXwrapper::~MBOXwrapper() | ||
22 | { | ||
23 | } | ||
24 | |||
25 | void MBOXwrapper::listMessages(const QString & mailbox, QValueList<RecMailP> &target ) | ||
26 | { | ||
27 | mailstorage*storage = mailstorage_new(NULL); | ||
28 | QString p = MBOXPath+"/"; | ||
29 | p+=mailbox; | ||
30 | |||
31 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | ||
32 | mailfolder*folder; | ||
33 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | ||
34 | r = mailfolder_connect(folder); | ||
35 | if (r != MAIL_NO_ERROR) { | ||
36 | //odebug << "Error initializing mbox" << oendl; | ||
37 | mailfolder_free(folder); | ||
38 | mailstorage_free(storage); | ||
39 | return; | ||
40 | } | ||
41 | |||
42 | parseList(target,folder->fld_session,mailbox); | ||
43 | |||
44 | mailfolder_disconnect(folder); | ||
45 | mailfolder_free(folder); | ||
46 | mailstorage_free(storage); | ||
47 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); | ||
48 | } | ||
49 | |||
50 | QValueList<Opie::Core::OSmartPointer<Folder> >* MBOXwrapper::listFolders() | ||
51 | { | ||
52 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); | ||
53 | QDir dir(MBOXPath); | ||
54 | if (!dir.exists()) return folders; | ||
55 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); | ||
56 | QStringList entries = dir.entryList(); | ||
57 | QStringList::ConstIterator it = entries.begin(); | ||
58 | for (;it!=entries.end();++it) { | ||
59 | FolderP inb=new Folder(*it,"/"); | ||
60 | folders->append(inb); | ||
61 | } | ||
62 | return folders; | ||
63 | } | ||
64 | |||
65 | void MBOXwrapper::deleteMail(const RecMailP & mail) | ||
66 | { | ||
67 | mailstorage*storage = mailstorage_new(NULL); | ||
68 | QString p = MBOXPath+"/"; | ||
69 | p+=mail->getMbox(); | ||
70 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | ||
71 | mailfolder*folder; | ||
72 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | ||
73 | r = mailfolder_connect(folder); | ||
74 | if (r != MAIL_NO_ERROR) { | ||
75 | ; // << "Error initializing mbox" << oendl; | ||
76 | mailfolder_free(folder); | ||
77 | mailstorage_free(storage); | ||
78 | return; | ||
79 | } | ||
80 | r = mailsession_remove_message(folder->fld_session,mail->getNumber()); | ||
81 | if (r != MAIL_NO_ERROR) { | ||
82 | ; // << "error deleting mail" << oendl; | ||
83 | } | ||
84 | mailfolder_free(folder); | ||
85 | mailstorage_free(storage); | ||
86 | } | ||
87 | |||
88 | void MBOXwrapper::answeredMail(const RecMailP&) | ||
89 | { | ||
90 | } | ||
91 | |||
92 | RecBodyP MBOXwrapper::fetchBody( const RecMailP &mail ) | ||
93 | { | ||
94 | RecBodyP body = new RecBody(); | ||
95 | mailstorage*storage = mailstorage_new(NULL); | ||
96 | QString p = MBOXPath+"/"; | ||
97 | p+=mail->getMbox(); | ||
98 | mailmessage * msg; | ||
99 | char*data=0; | ||
100 | size_t size; | ||
101 | |||
102 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | ||
103 | mailfolder*folder; | ||
104 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | ||
105 | r = mailfolder_connect(folder); | ||
106 | if (r != MAIL_NO_ERROR) { | ||
107 | ; // << "Error initializing mbox" << oendl; | ||
108 | mailfolder_free(folder); | ||
109 | mailstorage_free(storage); | ||
110 | return body; | ||
111 | } | ||
112 | r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); | ||
113 | if (r != MAIL_NO_ERROR) { | ||
114 | ; // << "Error fetching mail " << mail->getNumber() << "" << oendl; | ||
115 | mailfolder_free(folder); | ||
116 | mailstorage_free(storage); | ||
117 | return body; | ||
118 | } | ||
119 | r = mailmessage_fetch(msg,&data,&size); | ||
120 | if (r != MAIL_NO_ERROR) { | ||
121 | ; // << "Error fetching mail " << mail->getNumber() << "" << oendl; | ||
122 | mailfolder_free(folder); | ||
123 | mailstorage_free(storage); | ||
124 | mailmessage_free(msg); | ||
125 | return body; | ||
126 | } | ||
127 | body = parseMail(msg); | ||
128 | mailmessage_fetch_result_free(msg,data); | ||
129 | mailfolder_free(folder); | ||
130 | mailstorage_free(storage); | ||
131 | |||
132 | return body; | ||
133 | } | ||
134 | |||
135 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) | ||
136 | { | ||
137 | ; // << "MBOX " << current << " von " << maximum << "" << oendl; | ||
138 | } | ||
139 | |||
140 | int MBOXwrapper::createMbox(const QString&folder,const FolderP&,const QString&,bool ) | ||
141 | { | ||
142 | QString p = MBOXPath+"/"; | ||
143 | p+=folder; | ||
144 | QFileInfo fi(p); | ||
145 | if (fi.exists()) { | ||
146 | Global::statusMessage(tr("Mailbox exists.")); | ||
147 | return 0; | ||
148 | } | ||
149 | mailmbox_folder*f = 0; | ||
150 | if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { | ||
151 | Global::statusMessage(tr("Error init folder")); | ||
152 | return 0; | ||
153 | } | ||
154 | if (f) mailmbox_done(f); | ||
155 | return 1; | ||
156 | } | ||
157 | |||
158 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | ||
159 | { | ||
160 | QString p = MBOXPath+"/"; | ||
161 | p+=folder; | ||
162 | mailmbox_folder*f = 0; | ||
163 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | ||
164 | if (r != MAIL_NO_ERROR) { | ||
165 | Global::statusMessage(tr("Error init folder")); | ||
166 | return; | ||
167 | } | ||
168 | r = mailmbox_append_message(f,msg,length); | ||
169 | if (r != MAIL_NO_ERROR) { | ||
170 | Global::statusMessage(tr("Error writing to message folder")); | ||
171 | } | ||
172 | mailmbox_done(f); | ||
173 | } | ||
174 | |||
175 | encodedString* MBOXwrapper::fetchRawBody(const RecMailP&mail) | ||
176 | { | ||
177 | RecBody body; | ||
178 | mailstorage*storage = mailstorage_new(NULL); | ||
179 | QString p = MBOXPath+"/"; | ||
180 | p+=mail->getMbox(); | ||
181 | mailmessage * msg; | ||
182 | char*data=0; | ||
183 | size_t size; | ||
184 | |||
185 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | ||
186 | mailfolder*folder; | ||
187 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | ||
188 | r = mailfolder_connect(folder); | ||
189 | if (r != MAIL_NO_ERROR) { | ||
190 | Global::statusMessage(tr("Error initializing mbox")); | ||
191 | mailfolder_free(folder); | ||
192 | mailstorage_free(storage); | ||
193 | return 0; | ||
194 | } | ||
195 | r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); | ||
196 | if (r != MAIL_NO_ERROR) { | ||
197 | Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); | ||
198 | mailfolder_free(folder); | ||
199 | mailstorage_free(storage); | ||
200 | return 0; | ||
201 | } | ||
202 | r = mailmessage_fetch(msg,&data,&size); | ||
203 | if (r != MAIL_NO_ERROR) { | ||
204 | Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); | ||
205 | mailfolder_free(folder); | ||
206 | mailstorage_free(storage); | ||
207 | mailmessage_free(msg); | ||
208 | return 0; | ||
209 | } | ||
210 | encodedString*result = new encodedString(data,size); | ||
211 | |||
212 | mailfolder_free(folder); | ||
213 | mailstorage_free(storage); | ||
214 | mailmessage_free(msg); | ||
215 | return result; | ||
216 | } | ||
217 | |||
218 | void MBOXwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) | ||
219 | { | ||
220 | QString p = MBOXPath+"/"; | ||
221 | p+=mailbox; | ||
222 | mailmbox_folder*f = 0; | ||
223 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | ||
224 | if (r != MAIL_NO_ERROR) { | ||
225 | ; // << "Error init folder" << oendl; | ||
226 | return; | ||
227 | } | ||
228 | deleteMails(f,target); | ||
229 | mailmbox_done(f); | ||
230 | } | ||
231 | |||
232 | void MBOXwrapper::deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target) | ||
233 | { | ||
234 | if (!f) return; | ||
235 | int r; | ||
236 | QValueList<RecMailP>::ConstIterator it; | ||
237 | for (it=target.begin(); it != target.end();++it) { | ||
238 | r = mailmbox_delete_msg(f,(*it)->getNumber()); | ||
239 | if (r!=MAILMBOX_NO_ERROR) { | ||
240 | ; // << "error delete mail" << oendl; | ||
241 | } | ||
242 | } | ||
243 | r = mailmbox_expunge(f); | ||
244 | if (r != MAILMBOX_NO_ERROR) { | ||
245 | ; // << "error expunge mailbox" << oendl; | ||
246 | } | ||
247 | } | ||
248 | |||
249 | int MBOXwrapper::deleteAllMail(const FolderP&tfolder) | ||
250 | { | ||
251 | if (!tfolder) return 0; | ||
252 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); | ||
253 | int res = 1; | ||
254 | |||
255 | mailfolder*folder = 0; | ||
256 | mailmessage_list*l=0; | ||
257 | mailstorage*storage = mailstorage_new(NULL); | ||
258 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | ||
259 | if (r != MAIL_NO_ERROR) { | ||
260 | Global::statusMessage(tr("Error initializing mbox")); | ||
261 | res = 0; | ||
262 | } | ||
263 | if (res) { | ||
264 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | ||
265 | r = mailfolder_connect(folder); | ||
266 | if (r != MAIL_NO_ERROR) { | ||
267 | Global::statusMessage(tr("Error initializing mbox")); | ||
268 | res = 0; | ||
269 | } | ||
270 | } | ||
271 | if (res) { | ||
272 | r = mailsession_get_messages_list(folder->fld_session,&l); | ||
273 | if (r != MAIL_NO_ERROR) { | ||
274 | ; // << "Error message list" << oendl; | ||
275 | res=0; | ||
276 | } | ||
277 | } | ||
278 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | ||
279 | r = mailsession_remove_message(folder->fld_session,i+1); | ||
280 | if (r != MAIL_NO_ERROR) { | ||
281 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | ||
282 | res = 0; | ||
283 | break; | ||
284 | } | ||
285 | } | ||
286 | if (l) mailmessage_list_free(l); | ||
287 | if (folder) mailfolder_free(folder); | ||
288 | if (storage) mailstorage_free(storage); | ||
289 | return res; | ||
290 | } | ||
291 | |||
292 | int MBOXwrapper::deleteMbox(const FolderP&tfolder) | ||
293 | { | ||
294 | if (!tfolder) return 0; | ||
295 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); | ||
296 | QFile fi(p); | ||
297 | if (!fi.exists()) { | ||
298 | Global::statusMessage(tr("Mailbox doesn't exist.")); | ||
299 | return 0; | ||
300 | } | ||
301 | if (!fi.remove()) { | ||
302 | Global::statusMessage(tr("Error deleting Mailbox.")); | ||
303 | return 0; | ||
304 | } | ||
305 | return 1; | ||
306 | } | ||
307 | |||
308 | void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | ||
309 | { | ||
310 | mailfolder*folder = 0; | ||
311 | mailstorage*storage = mailstorage_new(NULL); | ||
312 | target_stat.message_count = 0; | ||
313 | target_stat.message_unseen = 0; | ||
314 | target_stat.message_recent = 0; | ||
315 | QString p = MBOXPath+"/"+mailbox; | ||
316 | QFile fi(p); | ||
317 | if (!fi.exists()) { | ||
318 | Global::statusMessage(tr("Mailbox doesn't exist.")); | ||
319 | return; | ||
320 | } | ||
321 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | ||
322 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | ||
323 | r = mailfolder_connect(folder); | ||
324 | r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, | ||
325 | &target_stat.message_recent,&target_stat.message_unseen); | ||
326 | if (folder) mailfolder_free(folder); | ||
327 | if (storage) mailstorage_free(storage); | ||
328 | } | ||
329 | |||
330 | MAILLIB::ATYPE MBOXwrapper::getType()const | ||
331 | { | ||
332 | return MAILLIB::A_MBOX; | ||
333 | } | ||
334 | |||
335 | const QString&MBOXwrapper::getName()const | ||
336 | { | ||
337 | return MBOXName; | ||
338 | } | ||
diff --git a/kmicromail/libmailwrapper/mboxwrapper.h b/kmicromail/libmailwrapper/mboxwrapper.h new file mode 100644 index 0000000..9731b85 --- a/dev/null +++ b/kmicromail/libmailwrapper/mboxwrapper.h | |||
@@ -0,0 +1,46 @@ | |||
1 | #ifndef __MBOX_WRAPPER_H | ||
2 | #define __MBOX_WRAPPER_H | ||
3 | |||
4 | #include "genericwrapper.h" | ||
5 | #include <qstring.h> | ||
6 | |||
7 | class encodedString; | ||
8 | struct mailmbox_folder; | ||
9 | |||
10 | class MBOXwrapper : public Genericwrapper | ||
11 | { | ||
12 | Q_OBJECT | ||
13 | |||
14 | public: | ||
15 | MBOXwrapper(const QString & dir,const QString&name); | ||
16 | virtual ~MBOXwrapper(); | ||
17 | |||
18 | virtual void listMessages(const QString & mailbox, QValueList<RecMailP>&target ); | ||
19 | virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); | ||
20 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | ||
21 | |||
22 | virtual void deleteMail(const RecMailP&mail); | ||
23 | virtual void answeredMail(const RecMailP&mail); | ||
24 | |||
25 | virtual int createMbox(const QString&folder,const Opie::Core::OSmartPointer<Folder>&f=0, | ||
26 | const QString&d="",bool s=false); | ||
27 | virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&); | ||
28 | |||
29 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | ||
30 | |||
31 | virtual RecBodyP fetchBody( const RecMailP &mail ); | ||
32 | static void mbox_progress( size_t current, size_t maximum ); | ||
33 | |||
34 | virtual encodedString* fetchRawBody(const RecMailP&mail); | ||
35 | virtual void deleteMails(const QString & FolderName,const QValueList<RecMailP> &target); | ||
36 | virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); | ||
37 | virtual MAILLIB::ATYPE getType()const; | ||
38 | virtual const QString&getName()const; | ||
39 | |||
40 | protected: | ||
41 | static void deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target); | ||
42 | QString MBOXPath; | ||
43 | QString MBOXName; | ||
44 | }; | ||
45 | |||
46 | #endif | ||
diff --git a/kmicromail/libmailwrapper/mhwrapper.cpp b/kmicromail/libmailwrapper/mhwrapper.cpp new file mode 100644 index 0000000..7ef9b32 --- a/dev/null +++ b/kmicromail/libmailwrapper/mhwrapper.cpp | |||
@@ -0,0 +1,446 @@ | |||
1 | #include "mhwrapper.h" | ||
2 | #include "mailtypes.h" | ||
3 | #include "mailwrapper.h" | ||
4 | #include <libetpan/libetpan.h> | ||
5 | #include <qdir.h> | ||
6 | #include <qmessagebox.h> | ||
7 | #include <stdlib.h> | ||
8 | #include <qpe/global.h> | ||
9 | #include <oprocess.h> | ||
10 | //#include <opie2/odebug.h> | ||
11 | |||
12 | using namespace Opie::Core; | ||
13 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) | ||
14 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) | ||
15 | { | ||
16 | if (MHPath.length()>0) { | ||
17 | if (MHPath[MHPath.length()-1]=='/') { | ||
18 | MHPath=MHPath.left(MHPath.length()-1); | ||
19 | } | ||
20 | //odebug << MHPath << oendl; | ||
21 | QDir dir(MHPath); | ||
22 | if (!dir.exists()) { | ||
23 | dir.mkdir(MHPath); | ||
24 | } | ||
25 | init_storage(); | ||
26 | } | ||
27 | } | ||
28 | |||
29 | void MHwrapper::init_storage() | ||
30 | { | ||
31 | int r; | ||
32 | QString pre = MHPath; | ||
33 | if (!m_storage) { | ||
34 | m_storage = mailstorage_new(NULL); | ||
35 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); | ||
36 | if (r != MAIL_NO_ERROR) { | ||
37 | qDebug(" error init storage "); | ||
38 | mailstorage_free(m_storage); | ||
39 | m_storage = 0; | ||
40 | return; | ||
41 | } | ||
42 | } | ||
43 | r = mailstorage_connect(m_storage); | ||
44 | if (r!=MAIL_NO_ERROR) { | ||
45 | qDebug("error connecting storage "); | ||
46 | mailstorage_free(m_storage); | ||
47 | m_storage = 0; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | void MHwrapper::clean_storage() | ||
52 | { | ||
53 | if (m_storage) { | ||
54 | mailstorage_disconnect(m_storage); | ||
55 | mailstorage_free(m_storage); | ||
56 | m_storage = 0; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | MHwrapper::~MHwrapper() | ||
61 | { | ||
62 | clean_storage(); | ||
63 | } | ||
64 | |||
65 | void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) | ||
66 | { | ||
67 | init_storage(); | ||
68 | if (!m_storage) { | ||
69 | return; | ||
70 | } | ||
71 | QString f = buildPath(mailbox); | ||
72 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | ||
73 | if (r!=MAIL_NO_ERROR) { | ||
74 | qDebug("listMessages: error selecting folder! "); | ||
75 | return; | ||
76 | } | ||
77 | parseList(target,m_storage->sto_session,f); | ||
78 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); | ||
79 | } | ||
80 | |||
81 | QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() | ||
82 | { | ||
83 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); | ||
84 | /* this is needed! */ | ||
85 | if (m_storage) mailstorage_disconnect(m_storage); | ||
86 | init_storage(); | ||
87 | if (!m_storage) { | ||
88 | return folders; | ||
89 | } | ||
90 | mail_list*flist = 0; | ||
91 | clistcell*current=0; | ||
92 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); | ||
93 | if (r != MAIL_NO_ERROR || !flist) { | ||
94 | qDebug("error getting folder list "); | ||
95 | return folders; | ||
96 | } | ||
97 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { | ||
98 | QString t = (char*)current->data; | ||
99 | t.replace(0,MHPath.length(),""); | ||
100 | folders->append(new MHFolder(t,MHPath)); | ||
101 | } | ||
102 | mail_list_free(flist); | ||
103 | return folders; | ||
104 | } | ||
105 | |||
106 | void MHwrapper::deleteMail(const RecMailP&mail) | ||
107 | { | ||
108 | init_storage(); | ||
109 | if (!m_storage) { | ||
110 | return; | ||
111 | } | ||
112 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | ||
113 | if (r!=MAIL_NO_ERROR) { | ||
114 | qDebug("error selecting folder! "); | ||
115 | return; | ||
116 | } | ||
117 | r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); | ||
118 | if (r != MAIL_NO_ERROR) { | ||
119 | qDebug("error deleting mail "); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | void MHwrapper::answeredMail(const RecMailP&) | ||
124 | { | ||
125 | } | ||
126 | |||
127 | RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) | ||
128 | { | ||
129 | RecBodyP body = new RecBody(); | ||
130 | init_storage(); | ||
131 | if (!m_storage) { | ||
132 | return body; | ||
133 | } | ||
134 | mailmessage * msg; | ||
135 | char*data=0; | ||
136 | |||
137 | /* mail should hold the complete path! */ | ||
138 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | ||
139 | if (r != MAIL_NO_ERROR) { | ||
140 | return body; | ||
141 | } | ||
142 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); | ||
143 | if (r != MAIL_NO_ERROR) { | ||
144 | qDebug("Error fetching mail "); | ||
145 | |||
146 | return body; | ||
147 | } | ||
148 | body = parseMail(msg); | ||
149 | mailmessage_fetch_result_free(msg,data); | ||
150 | return body; | ||
151 | } | ||
152 | |||
153 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) | ||
154 | { | ||
155 | qDebug("MBox Progress %d of %d",current,maximum ); | ||
156 | //odebug << "MH " << current << " von " << maximum << "" << oendl; | ||
157 | } | ||
158 | |||
159 | QString MHwrapper::buildPath(const QString&p) | ||
160 | { | ||
161 | QString f=""; | ||
162 | if (p.length()==0||p=="/") | ||
163 | return MHPath; | ||
164 | if (!p.startsWith(MHPath)) { | ||
165 | f+=MHPath; | ||
166 | } | ||
167 | if (!p.startsWith("/")) { | ||
168 | f+="/"; | ||
169 | } | ||
170 | f+=p; | ||
171 | return f; | ||
172 | } | ||
173 | |||
174 | int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) | ||
175 | { | ||
176 | init_storage(); | ||
177 | if (!m_storage) { | ||
178 | return 0; | ||
179 | } | ||
180 | QString f; | ||
181 | if (!pfolder) { | ||
182 | // toplevel folder | ||
183 | f = buildPath(folder); | ||
184 | } else { | ||
185 | f = pfolder->getName(); | ||
186 | f+="/"; | ||
187 | f+=folder; | ||
188 | } | ||
189 | |||
190 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); | ||
191 | if (r != MAIL_NO_ERROR) { | ||
192 | qDebug("error creating folder "); | ||
193 | return 0; | ||
194 | } | ||
195 | qDebug("Folder created "); | ||
196 | return 1; | ||
197 | } | ||
198 | |||
199 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) | ||
200 | { | ||
201 | init_storage(); | ||
202 | if (!m_storage) { | ||
203 | return; | ||
204 | } | ||
205 | QString f = buildPath(Folder); | ||
206 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | ||
207 | if (r!=MAIL_NO_ERROR) { | ||
208 | qDebug("error selecting folder! "); | ||
209 | return; | ||
210 | } | ||
211 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); | ||
212 | if (r!=MAIL_NO_ERROR) { | ||
213 | qDebug("error storing mail "); | ||
214 | } | ||
215 | return; | ||
216 | } | ||
217 | |||
218 | encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) | ||
219 | { | ||
220 | encodedString*result = 0; | ||
221 | init_storage(); | ||
222 | if (!m_storage) { | ||
223 | return result; | ||
224 | } | ||
225 | mailmessage * msg = 0; | ||
226 | char*data=0; | ||
227 | size_t size; | ||
228 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | ||
229 | if (r!=MAIL_NO_ERROR) { | ||
230 | qDebug("error selecting folder! "); | ||
231 | return result; | ||
232 | } | ||
233 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); | ||
234 | if (r != MAIL_NO_ERROR) { | ||
235 | Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); | ||
236 | return 0; | ||
237 | } | ||
238 | r = mailmessage_fetch(msg,&data,&size); | ||
239 | if (r != MAIL_NO_ERROR) { | ||
240 | Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); | ||
241 | if (msg) mailmessage_free(msg); | ||
242 | return 0; | ||
243 | } | ||
244 | result = new encodedString(data,size); | ||
245 | if (msg) mailmessage_free(msg); | ||
246 | return result; | ||
247 | } | ||
248 | |||
249 | void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) | ||
250 | { | ||
251 | QString f = buildPath(mailbox); | ||
252 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | ||
253 | if (r!=MAIL_NO_ERROR) { | ||
254 | qDebug("deleteMails: error selecting folder! "); | ||
255 | return; | ||
256 | } | ||
257 | QValueList<RecMailP>::ConstIterator it; | ||
258 | for (it=target.begin(); it!=target.end();++it) { | ||
259 | r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); | ||
260 | if (r != MAIL_NO_ERROR) { | ||
261 | qDebug("error deleting mail "); | ||
262 | break; | ||
263 | } | ||
264 | } | ||
265 | } | ||
266 | |||
267 | int MHwrapper::deleteAllMail(const FolderP&tfolder) | ||
268 | { | ||
269 | init_storage(); | ||
270 | if (!m_storage) { | ||
271 | return 0; | ||
272 | } | ||
273 | int res = 1; | ||
274 | if (!tfolder) return 0; | ||
275 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | ||
276 | if (r!=MAIL_NO_ERROR) { | ||
277 | qDebug("error selecting folder! "); | ||
278 | return 0; | ||
279 | } | ||
280 | mailmessage_list*l=0; | ||
281 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | ||
282 | if (r != MAIL_NO_ERROR) { | ||
283 | qDebug("Error message list "); | ||
284 | res = 0; | ||
285 | } | ||
286 | unsigned j = 0; | ||
287 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | ||
288 | mailmessage * msg; | ||
289 | msg = (mailmessage*)carray_get(l->msg_tab, i); | ||
290 | j = msg->msg_index; | ||
291 | r = mailsession_remove_message(m_storage->sto_session,j); | ||
292 | if (r != MAIL_NO_ERROR) { | ||
293 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | ||
294 | res = 0; | ||
295 | break; | ||
296 | } | ||
297 | } | ||
298 | if (l) mailmessage_list_free(l); | ||
299 | return res; | ||
300 | } | ||
301 | |||
302 | int MHwrapper::deleteMbox(const FolderP&tfolder) | ||
303 | { | ||
304 | init_storage(); | ||
305 | if (!m_storage) { | ||
306 | return 0; | ||
307 | } | ||
308 | if (!tfolder) return 0; | ||
309 | if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; | ||
310 | |||
311 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | ||
312 | |||
313 | if (r != MAIL_NO_ERROR) { | ||
314 | qDebug("error deleting mail box "); | ||
315 | return 0; | ||
316 | } | ||
317 | QString cmd = "rm -rf "+tfolder->getName(); | ||
318 | QStringList command; | ||
319 | command << "/bin/sh"; | ||
320 | command << "-c"; | ||
321 | command << cmd.latin1(); | ||
322 | OProcess *process = new OProcess(); | ||
323 | |||
324 | connect(process, SIGNAL(processExited(Opie::Core::OProcess*)), | ||
325 | this, SLOT( processEnded(Opie::Core::OProcess*))); | ||
326 | connect(process, SIGNAL( receivedStderr(Opie::Core::OProcess*,char*,int)), | ||
327 | this, SLOT( oprocessStderr(Opie::Core::OProcess*,char*,int))); | ||
328 | |||
329 | *process << command; | ||
330 | removeMboxfailed = false; | ||
331 | if(!process->start(OProcess::Block, OProcess::All) ) { | ||
332 | qDebug("could not start process "); | ||
333 | return 0; | ||
334 | } | ||
335 | qDebug("mail box deleted "); | ||
336 | return 1; | ||
337 | } | ||
338 | |||
339 | void MHwrapper::processEnded(OProcess *p) | ||
340 | { | ||
341 | if (p) delete p; | ||
342 | } | ||
343 | |||
344 | void MHwrapper::oprocessStderr(OProcess*, char *buffer, int ) | ||
345 | { | ||
346 | QString lineStr = buffer; | ||
347 | QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") ); | ||
348 | removeMboxfailed = true; | ||
349 | } | ||
350 | |||
351 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | ||
352 | { | ||
353 | init_storage(); | ||
354 | if (!m_storage) { | ||
355 | return; | ||
356 | } | ||
357 | target_stat.message_count = 0; | ||
358 | target_stat.message_unseen = 0; | ||
359 | target_stat.message_recent = 0; | ||
360 | QString f = buildPath(mailbox); | ||
361 | 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 | if (r != MAIL_NO_ERROR) { | ||
364 | Global::statusMessage(tr("Error retrieving status")); | ||
365 | } | ||
366 | } | ||
367 | |||
368 | MAILLIB::ATYPE MHwrapper::getType()const | ||
369 | { | ||
370 | return MAILLIB::A_MH; | ||
371 | } | ||
372 | |||
373 | const QString&MHwrapper::getName()const | ||
374 | { | ||
375 | return MHName; | ||
376 | } | ||
377 | void MHwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | ||
378 | { | ||
379 | init_storage(); | ||
380 | if (!m_storage) { | ||
381 | return; | ||
382 | } | ||
383 | if (targetWrapper != this) { | ||
384 | qDebug("Using generic "); | ||
385 | Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); | ||
386 | return; | ||
387 | } | ||
388 | qDebug("Using internal routines for move/copy "); | ||
389 | QString tf = buildPath(targetFolder); | ||
390 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | ||
391 | if (r != MAIL_NO_ERROR) { | ||
392 | qDebug("Error selecting source mailbox "); | ||
393 | return; | ||
394 | } | ||
395 | if (moveit) { | ||
396 | r = mailsession_move_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); | ||
397 | } else { | ||
398 | r = mailsession_copy_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); | ||
399 | } | ||
400 | if (r != MAIL_NO_ERROR) { | ||
401 | qDebug("Error copy/moving mail internal "); | ||
402 | } | ||
403 | } | ||
404 | |||
405 | void MHwrapper::mvcpAllMails(const FolderP&fromFolder, | ||
406 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | ||
407 | { | ||
408 | init_storage(); | ||
409 | if (!m_storage) { | ||
410 | return; | ||
411 | } | ||
412 | if (targetWrapper != this) { | ||
413 | qDebug("Using generic "); | ||
414 | Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); | ||
415 | return; | ||
416 | } | ||
417 | if (!fromFolder) return; | ||
418 | int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1()); | ||
419 | if (r!=MAIL_NO_ERROR) { | ||
420 | qDebug("error selecting source folder! "); | ||
421 | return; | ||
422 | } | ||
423 | QString tf = buildPath(targetFolder); | ||
424 | mailmessage_list*l=0; | ||
425 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | ||
426 | if (r != MAIL_NO_ERROR) { | ||
427 | qDebug("Error message list "); | ||
428 | } | ||
429 | unsigned j = 0; | ||
430 | for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) { | ||
431 | mailmessage * msg; | ||
432 | msg = (mailmessage*)carray_get(l->msg_tab, i); | ||
433 | j = msg->msg_index; | ||
434 | if (moveit) { | ||
435 | r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1()); | ||
436 | } else { | ||
437 | r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1()); | ||
438 | } | ||
439 | if (r != MAIL_NO_ERROR) { | ||
440 | qDebug("Error copy/moving mail interna "); | ||
441 | |||
442 | break; | ||
443 | } | ||
444 | } | ||
445 | if (l) mailmessage_list_free(l); | ||
446 | } | ||
diff --git a/kmicromail/libmailwrapper/mhwrapper.h b/kmicromail/libmailwrapper/mhwrapper.h new file mode 100644 index 0000000..4310c84 --- a/dev/null +++ b/kmicromail/libmailwrapper/mhwrapper.h | |||
@@ -0,0 +1,60 @@ | |||
1 | #ifndef __MH_WRAPPER_H | ||
2 | #define __MH_WRAPPER_H | ||
3 | |||
4 | #include "maildefines.h" | ||
5 | |||
6 | #include "genericwrapper.h" | ||
7 | #include <qstring.h> | ||
8 | |||
9 | class encodedString; | ||
10 | struct mailmbox_folder; | ||
11 | namespace Opie {namespace Core {class OProcess;}} | ||
12 | |||
13 | class MHwrapper : public Genericwrapper | ||
14 | { | ||
15 | Q_OBJECT | ||
16 | public: | ||
17 | MHwrapper(const QString & dir,const QString&name); | ||
18 | virtual ~MHwrapper(); | ||
19 | |||
20 | virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ); | ||
21 | virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); | ||
22 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | ||
23 | |||
24 | virtual void deleteMail(const RecMailP&mail); | ||
25 | virtual void answeredMail(const RecMailP&mail); | ||
26 | virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | ||
27 | virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, | ||
28 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | ||
29 | |||
30 | virtual int createMbox(const QString&folder,const Opie::Core::OSmartPointer<Folder>&f=0, | ||
31 | const QString&d="",bool s=false); | ||
32 | virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&); | ||
33 | |||
34 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | ||
35 | |||
36 | virtual RecBodyP fetchBody( const RecMailP &mail ); | ||
37 | static void mbox_progress( size_t current, size_t maximum ); | ||
38 | |||
39 | virtual encodedString* fetchRawBody(const RecMailP&mail); | ||
40 | virtual void deleteMails(const QString & FolderName,const QValueList<Opie::Core::OSmartPointer<RecMail> > &target); | ||
41 | virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); | ||
42 | virtual MAILLIB::ATYPE getType()const; | ||
43 | virtual const QString&getName()const; | ||
44 | |||
45 | public slots: | ||
46 | /* for deleting maildirs we are using a system call */ | ||
47 | virtual void oprocessStderr(Opie::Core::OProcess*, char *buffer, int ); | ||
48 | virtual void processEnded(Opie::Core::OProcess *); | ||
49 | protected: | ||
50 | QString buildPath(const QString&p); | ||
51 | QString MHPath; | ||
52 | QString MHName; | ||
53 | |||
54 | void init_storage(); | ||
55 | void clean_storage(); | ||
56 | |||
57 | bool removeMboxfailed; | ||
58 | }; | ||
59 | |||
60 | #endif | ||
diff --git a/kmicromail/libmailwrapper/nntpwrapper.cpp b/kmicromail/libmailwrapper/nntpwrapper.cpp new file mode 100644 index 0000000..daa128e --- a/dev/null +++ b/kmicromail/libmailwrapper/nntpwrapper.cpp | |||
@@ -0,0 +1,289 @@ | |||
1 | #include "nntpwrapper.h" | ||
2 | #include "logindialog.h" | ||
3 | #include "mailtypes.h" | ||
4 | |||
5 | #include <qfile.h> | ||
6 | |||
7 | #include <stdlib.h> | ||
8 | |||
9 | #include <libetpan/libetpan.h> | ||
10 | |||
11 | |||
12 | |||
13 | #define HARD_MSG_SIZE_LIMIT 5242880 | ||
14 | |||
15 | using namespace Opie::Core; | ||
16 | NNTPwrapper::NNTPwrapper( NNTPaccount *a ) | ||
17 | : Genericwrapper() { | ||
18 | account = a; | ||
19 | m_nntp = NULL; | ||
20 | msgTempName = a->getFileName()+"_msg_cache"; | ||
21 | last_msg_id = 0; | ||
22 | } | ||
23 | |||
24 | NNTPwrapper::~NNTPwrapper() { | ||
25 | logout(); | ||
26 | QFile msg_cache(msgTempName); | ||
27 | if (msg_cache.exists()) { | ||
28 | msg_cache.remove(); | ||
29 | } | ||
30 | } | ||
31 | |||
32 | void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) { | ||
33 | ; // << "NNTP: " << current << " of " << maximum << "" << oendl; | ||
34 | } | ||
35 | |||
36 | |||
37 | RecBodyP NNTPwrapper::fetchBody( const RecMailP &mail ) { | ||
38 | int err = NEWSNNTP_NO_ERROR; | ||
39 | char *message = 0; | ||
40 | size_t length = 0; | ||
41 | |||
42 | RecBodyP body = new RecBody(); | ||
43 | login(); | ||
44 | if ( !m_nntp ) { | ||
45 | return body; | ||
46 | } | ||
47 | |||
48 | mailmessage * mailmsg; | ||
49 | if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { | ||
50 | ; // << "Message to large: " << mail->Msgsize() << "" << oendl; | ||
51 | return body; | ||
52 | } | ||
53 | |||
54 | QFile msg_cache(msgTempName); | ||
55 | |||
56 | cleanMimeCache(); | ||
57 | |||
58 | if (mail->getNumber()!=last_msg_id) { | ||
59 | if (msg_cache.exists()) { | ||
60 | msg_cache.remove(); | ||
61 | } | ||
62 | msg_cache.open(IO_ReadWrite|IO_Truncate); | ||
63 | last_msg_id = mail->getNumber(); | ||
64 | err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); | ||
65 | err = mailmessage_fetch(mailmsg,&message,&length); | ||
66 | msg_cache.writeBlock(message,length); | ||
67 | } else { | ||
68 | QString msg=""; | ||
69 | msg_cache.open(IO_ReadOnly); | ||
70 | message = new char[4096]; | ||
71 | memset(message,0,4096); | ||
72 | while (msg_cache.readBlock(message,4095)>0) { | ||
73 | msg+=message; | ||
74 | memset(message,0,4096); | ||
75 | } | ||
76 | delete message; | ||
77 | message = (char*)malloc(msg.length()+1*sizeof(char)); | ||
78 | memset(message,0,msg.length()+1); | ||
79 | memcpy(message,msg.latin1(),msg.length()); | ||
80 | /* transform to libetpan stuff */ | ||
81 | mailmsg = mailmessage_new(); | ||
82 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); | ||
83 | generic_message_t * msg_data; | ||
84 | msg_data = (generic_message_t *)mailmsg->msg_data; | ||
85 | msg_data->msg_fetched = 1; | ||
86 | msg_data->msg_message = message; | ||
87 | msg_data->msg_length = strlen(message); | ||
88 | } | ||
89 | body = parseMail(mailmsg); | ||
90 | |||
91 | /* clean up */ | ||
92 | if (mailmsg) | ||
93 | mailmessage_free(mailmsg); | ||
94 | if (message) | ||
95 | free(message); | ||
96 | |||
97 | return body; | ||
98 | } | ||
99 | |||
100 | |||
101 | void NNTPwrapper::listMessages(const QString & which, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) | ||
102 | { | ||
103 | login(); | ||
104 | if (!m_nntp) | ||
105 | return; | ||
106 | 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 | parseList(target,m_nntp->sto_session,which,true); | ||
109 | } | ||
110 | |||
111 | void NNTPwrapper::login() | ||
112 | { | ||
113 | if (account->getOffline()) | ||
114 | return; | ||
115 | /* we'll hold the line */ | ||
116 | if ( m_nntp != NULL ) | ||
117 | return; | ||
118 | |||
119 | const char *server, *user, *pass; | ||
120 | QString User,Pass; | ||
121 | uint16_t port; | ||
122 | int err = NEWSNNTP_NO_ERROR; | ||
123 | |||
124 | server = account->getServer().latin1(); | ||
125 | port = account->getPort().toUInt(); | ||
126 | |||
127 | user = pass = 0; | ||
128 | |||
129 | if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) { | ||
130 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | ||
131 | login.show(); | ||
132 | if ( QDialog::Accepted == login.exec() ) { | ||
133 | // ok | ||
134 | User = login.getUser().latin1(); | ||
135 | Pass = login.getPassword().latin1(); | ||
136 | } else { | ||
137 | // cancel | ||
138 | ; // << "NNTP: Login canceled" << oendl; | ||
139 | return; | ||
140 | } | ||
141 | } else { | ||
142 | User = account->getUser().latin1(); | ||
143 | Pass = account->getPassword().latin1(); | ||
144 | } | ||
145 | |||
146 | if (User.isEmpty()) { | ||
147 | user=0; | ||
148 | pass = 0; | ||
149 | } else { | ||
150 | user=User.latin1(); | ||
151 | pass=Pass.latin1(); | ||
152 | } | ||
153 | // bool ssl = account->getSSL(); | ||
154 | |||
155 | m_nntp=mailstorage_new(NULL); | ||
156 | |||
157 | int conntypeset = account->ConnectionType(); | ||
158 | int conntype = 0; | ||
159 | if ( conntypeset == 3 ) { | ||
160 | conntype = CONNECTION_TYPE_COMMAND; | ||
161 | } else if ( conntypeset == 2 ) { | ||
162 | conntype = CONNECTION_TYPE_TLS; | ||
163 | } else if ( conntypeset == 1 ) { | ||
164 | conntype = CONNECTION_TYPE_STARTTLS; | ||
165 | } else if ( conntypeset == 0 ) { | ||
166 | conntype = CONNECTION_TYPE_TRY_STARTTLS; | ||
167 | } | ||
168 | |||
169 | 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 | |||
172 | err = mailstorage_connect( m_nntp ); | ||
173 | |||
174 | if (err != NEWSNNTP_NO_ERROR) { | ||
175 | ; // << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; | ||
176 | // Global::statusMessage(tr("Error initializing folder")); | ||
177 | mailstorage_free(m_nntp); | ||
178 | m_nntp = 0; | ||
179 | |||
180 | } else { | ||
181 | mailsession * session = m_nntp->sto_session; | ||
182 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; | ||
183 | news->nntp_progr_fun = &nntp_progress; | ||
184 | } | ||
185 | |||
186 | } | ||
187 | |||
188 | void NNTPwrapper::logout() | ||
189 | { | ||
190 | int err = NEWSNNTP_NO_ERROR; | ||
191 | if ( m_nntp == NULL ) | ||
192 | return; | ||
193 | mailstorage_free(m_nntp); | ||
194 | m_nntp = 0; | ||
195 | } | ||
196 | |||
197 | QValueList<Opie::Core::OSmartPointer<Folder> >* NNTPwrapper::listFolders() { | ||
198 | |||
199 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); | ||
200 | QStringList groups; | ||
201 | if (account) { | ||
202 | groups = account->getGroups(); | ||
203 | } | ||
204 | for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) { | ||
205 | folders->append(new Folder((*it),".")); | ||
206 | } | ||
207 | return folders; | ||
208 | } | ||
209 | |||
210 | /* 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 | * 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 | * the stuff from generic interface of etpan but copy it direct to qt classes. | ||
215 | */ | ||
216 | QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) { | ||
217 | login(); | ||
218 | QStringList res; | ||
219 | clist *result = 0; | ||
220 | clistcell *current = 0; | ||
221 | newsnntp_group_description *group; | ||
222 | |||
223 | if ( m_nntp ) { | ||
224 | mailsession * session = m_nntp->sto_session; | ||
225 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; | ||
226 | int err = NEWSNNTP_NO_ERROR; | ||
227 | if (mask.isEmpty()) { | ||
228 | err = newsnntp_list(news, &result); | ||
229 | } else { | ||
230 | /* taken from generic wrapper of etpan */ | ||
231 | QString nmask = mask+".*"; | ||
232 | err = newsnntp_list_active(news, nmask.latin1(), &result); | ||
233 | } | ||
234 | if ( err == NEWSNNTP_NO_ERROR && result) { | ||
235 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) { | ||
236 | group = ( newsnntp_group_description* ) current->data; | ||
237 | if (!group||!group->grp_name||strlen(group->grp_name)==0) continue; | ||
238 | res.append(group->grp_name); | ||
239 | } | ||
240 | } | ||
241 | } | ||
242 | if (result) { | ||
243 | newsnntp_list_free(result); | ||
244 | } | ||
245 | return res; | ||
246 | } | ||
247 | |||
248 | void NNTPwrapper::answeredMail(const RecMailP&) {} | ||
249 | |||
250 | void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { | ||
251 | login(); | ||
252 | target_stat.message_count = 0; | ||
253 | target_stat.message_unseen = 0; | ||
254 | target_stat.message_recent = 0; | ||
255 | if (!m_nntp) | ||
256 | return; | ||
257 | int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, | ||
258 | &target_stat.message_recent,&target_stat.message_unseen); | ||
259 | } | ||
260 | |||
261 | |||
262 | encodedString* NNTPwrapper::fetchRawBody(const RecMailP&mail) { | ||
263 | char*target=0; | ||
264 | size_t length=0; | ||
265 | encodedString*res = 0; | ||
266 | mailmessage * mailmsg = 0; | ||
267 | int err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); | ||
268 | err = mailmessage_fetch(mailmsg,&target,&length); | ||
269 | if (mailmsg) | ||
270 | mailmessage_free(mailmsg); | ||
271 | if (target) { | ||
272 | res = new encodedString(target,length); | ||
273 | } | ||
274 | return res; | ||
275 | } | ||
276 | |||
277 | MAILLIB::ATYPE NNTPwrapper::getType()const { | ||
278 | return account->getType(); | ||
279 | } | ||
280 | |||
281 | const QString&NNTPwrapper::getName()const{ | ||
282 | return account->getAccountName(); | ||
283 | } | ||
284 | |||
285 | void NNTPwrapper::deleteMail(const RecMailP&) { | ||
286 | } | ||
287 | |||
288 | int NNTPwrapper::deleteAllMail(const FolderP&) { | ||
289 | } | ||
diff --git a/kmicromail/libmailwrapper/nntpwrapper.h b/kmicromail/libmailwrapper/nntpwrapper.h new file mode 100644 index 0000000..2fb82f2 --- a/dev/null +++ b/kmicromail/libmailwrapper/nntpwrapper.h | |||
@@ -0,0 +1,48 @@ | |||
1 | #ifndef __NNTPWRAPPER | ||
2 | #define __NNTPWRAPPER | ||
3 | |||
4 | #include "mailwrapper.h" | ||
5 | #include "genericwrapper.h" | ||
6 | #include <qstring.h> | ||
7 | #include <libetpan/clist.h> | ||
8 | |||
9 | class encodedString; | ||
10 | struct mailstorage; | ||
11 | struct mailfolder; | ||
12 | |||
13 | class NNTPwrapper : public Genericwrapper | ||
14 | { | ||
15 | |||
16 | Q_OBJECT | ||
17 | |||
18 | public: | ||
19 | NNTPwrapper( NNTPaccount *a ); | ||
20 | virtual ~NNTPwrapper(); | ||
21 | |||
22 | /* mailbox will be ignored */ | ||
23 | virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ); | ||
24 | /* should only get the subscribed one */ | ||
25 | virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); | ||
26 | /* mailbox will be ignored */ | ||
27 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | ||
28 | QStringList listAllNewsgroups(const QString&mask = QString::null); | ||
29 | virtual void deleteMail(const RecMailP&mail); | ||
30 | virtual void answeredMail(const RecMailP&mail); | ||
31 | virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); | ||
32 | |||
33 | virtual RecBodyP fetchBody( const RecMailP &mail ); | ||
34 | virtual encodedString* fetchRawBody(const RecMailP&mail); | ||
35 | virtual void logout(); | ||
36 | virtual MAILLIB::ATYPE getType()const; | ||
37 | virtual const QString&getName()const; | ||
38 | static void nntp_progress( size_t current, size_t maximum ); | ||
39 | |||
40 | protected: | ||
41 | void login(); | ||
42 | NNTPaccount *account; | ||
43 | mailstorage* m_nntp; | ||
44 | |||
45 | |||
46 | }; | ||
47 | |||
48 | #endif | ||
diff --git a/kmicromail/libmailwrapper/pop3wrapper.cpp b/kmicromail/libmailwrapper/pop3wrapper.cpp new file mode 100644 index 0000000..e5d083a --- a/dev/null +++ b/kmicromail/libmailwrapper/pop3wrapper.cpp | |||
@@ -0,0 +1,265 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include "pop3wrapper.h" | ||
3 | #include "mailtypes.h" | ||
4 | #include "logindialog.h" | ||
5 | #include <libetpan/libetpan.h> | ||
6 | |||
7 | |||
8 | #include <qpe/global.h> | ||
9 | #include <qfile.h> | ||
10 | |||
11 | /* we don't fetch messages larger than 5 MB */ | ||
12 | #define HARD_MSG_SIZE_LIMIT 5242880 | ||
13 | |||
14 | using namespace Opie::Core; | ||
15 | POP3wrapper::POP3wrapper( POP3account *a ) | ||
16 | : Genericwrapper() { | ||
17 | account = a; | ||
18 | m_pop3 = NULL; | ||
19 | msgTempName = a->getFileName()+"_msg_cache"; | ||
20 | last_msg_id = 0; | ||
21 | } | ||
22 | |||
23 | POP3wrapper::~POP3wrapper() { | ||
24 | logout(); | ||
25 | QFile msg_cache(msgTempName); | ||
26 | if (msg_cache.exists()) { | ||
27 | msg_cache.remove(); | ||
28 | } | ||
29 | } | ||
30 | |||
31 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { | ||
32 | ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; | ||
33 | } | ||
34 | |||
35 | RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { | ||
36 | int err = MAILPOP3_NO_ERROR; | ||
37 | char *message = 0; | ||
38 | size_t length = 0; | ||
39 | |||
40 | RecBodyP body = new RecBody(); | ||
41 | |||
42 | login(); | ||
43 | if ( !m_pop3 ) { | ||
44 | return body; | ||
45 | } | ||
46 | |||
47 | mailmessage * mailmsg; | ||
48 | if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { | ||
49 | ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl; | ||
50 | return body; | ||
51 | } | ||
52 | |||
53 | QFile msg_cache(msgTempName); | ||
54 | |||
55 | cleanMimeCache(); | ||
56 | |||
57 | if (mail->getNumber()!=last_msg_id) { | ||
58 | if (msg_cache.exists()) { | ||
59 | msg_cache.remove(); | ||
60 | } | ||
61 | msg_cache.open(IO_ReadWrite|IO_Truncate); | ||
62 | last_msg_id = mail->getNumber(); | ||
63 | err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); | ||
64 | err = mailmessage_fetch(mailmsg,&message,&length); | ||
65 | msg_cache.writeBlock(message,length); | ||
66 | } else { | ||
67 | QString msg=""; | ||
68 | msg_cache.open(IO_ReadOnly); | ||
69 | message = new char[4096]; | ||
70 | memset(message,0,4096); | ||
71 | while (msg_cache.readBlock(message,4095)>0) { | ||
72 | msg+=message; | ||
73 | memset(message,0,4096); | ||
74 | } | ||
75 | delete message; | ||
76 | message = (char*)malloc(msg.length()+1*sizeof(char)); | ||
77 | memset(message,0,msg.length()+1); | ||
78 | memcpy(message,msg.latin1(),msg.length()); | ||
79 | /* transform to libetpan stuff */ | ||
80 | mailmsg = mailmessage_new(); | ||
81 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); | ||
82 | generic_message_t * msg_data; | ||
83 | msg_data = (generic_message_t *)mailmsg->msg_data; | ||
84 | msg_data->msg_fetched = 1; | ||
85 | msg_data->msg_message = message; | ||
86 | msg_data->msg_length = strlen(message); | ||
87 | } | ||
88 | body = parseMail(mailmsg); | ||
89 | |||
90 | /* clean up */ | ||
91 | if (mailmsg) | ||
92 | mailmessage_free(mailmsg); | ||
93 | if (message) | ||
94 | free(message); | ||
95 | |||
96 | return body; | ||
97 | } | ||
98 | |||
99 | void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) | ||
100 | { | ||
101 | login(); | ||
102 | if (!m_pop3) | ||
103 | return; | ||
104 | uint32_t res_messages,res_recent,res_unseen; | ||
105 | mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); | ||
106 | parseList(target,m_pop3->sto_session,"INBOX"); | ||
107 | Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); | ||
108 | } | ||
109 | |||
110 | void POP3wrapper::login() | ||
111 | { | ||
112 | if (account->getOffline()) | ||
113 | return; | ||
114 | /* we'll hold the line */ | ||
115 | if ( m_pop3 != NULL ) | ||
116 | return; | ||
117 | |||
118 | const char *server, *user, *pass; | ||
119 | uint16_t port; | ||
120 | int err = MAILPOP3_NO_ERROR; | ||
121 | |||
122 | server = account->getServer().latin1(); | ||
123 | port = account->getPort().toUInt(); | ||
124 | |||
125 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | ||
126 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | ||
127 | login.show(); | ||
128 | if ( QDialog::Accepted == login.exec() ) { | ||
129 | // ok | ||
130 | user = login.getUser().latin1(); | ||
131 | pass = login.getPassword().latin1(); | ||
132 | } else { | ||
133 | // cancel | ||
134 | ; // odebug << "POP3: Login canceled" << oendl; | ||
135 | return; | ||
136 | } | ||
137 | } else { | ||
138 | user = account->getUser().latin1(); | ||
139 | pass = account->getPassword().latin1(); | ||
140 | } | ||
141 | |||
142 | // bool ssl = account->getSSL(); | ||
143 | |||
144 | m_pop3=mailstorage_new(NULL); | ||
145 | |||
146 | int conntypeset = account->ConnectionType(); | ||
147 | int conntype = 0; | ||
148 | if ( conntypeset == 3 ) { | ||
149 | conntype = CONNECTION_TYPE_COMMAND; | ||
150 | } else if ( conntypeset == 2 ) { | ||
151 | conntype = CONNECTION_TYPE_TLS; | ||
152 | } else if ( conntypeset == 1 ) { | ||
153 | conntype = CONNECTION_TYPE_STARTTLS; | ||
154 | } else if ( conntypeset == 0 ) { | ||
155 | conntype = CONNECTION_TYPE_TRY_STARTTLS; | ||
156 | } | ||
157 | |||
158 | //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); | ||
159 | |||
160 | pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, | ||
161 | (char*)user,(char*)pass,0,0,0); | ||
162 | |||
163 | |||
164 | err = mailstorage_connect(m_pop3); | ||
165 | if (err != MAIL_NO_ERROR) { | ||
166 | ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; | ||
167 | Global::statusMessage(tr("Error initializing folder")); | ||
168 | mailstorage_free(m_pop3); | ||
169 | m_pop3 = 0; | ||
170 | } else { | ||
171 | mailsession * session = m_pop3->sto_session; | ||
172 | mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; | ||
173 | if (mail) { | ||
174 | mail->pop3_progr_fun = &pop3_progress; | ||
175 | } | ||
176 | } | ||
177 | } | ||
178 | |||
179 | void POP3wrapper::logout() | ||
180 | { | ||
181 | if ( m_pop3 == NULL ) | ||
182 | return; | ||
183 | mailstorage_free(m_pop3); | ||
184 | m_pop3 = 0; | ||
185 | } | ||
186 | |||
187 | |||
188 | QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { | ||
189 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); | ||
190 | FolderP inb=new Folder("INBOX","/"); | ||
191 | folders->append(inb); | ||
192 | return folders; | ||
193 | } | ||
194 | |||
195 | void POP3wrapper::deleteMail(const RecMailP&mail) { | ||
196 | login(); | ||
197 | if (!m_pop3) | ||
198 | return; | ||
199 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); | ||
200 | if (err != MAIL_NO_ERROR) { | ||
201 | Global::statusMessage(tr("error deleting mail")); | ||
202 | } | ||
203 | } | ||
204 | |||
205 | void POP3wrapper::answeredMail(const RecMailP&) {} | ||
206 | |||
207 | int POP3wrapper::deleteAllMail(const FolderP&) { | ||
208 | login(); | ||
209 | if (!m_pop3) | ||
210 | return 0; | ||
211 | int res = 1; | ||
212 | |||
213 | uint32_t result = 0; | ||
214 | int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); | ||
215 | if (err != MAIL_NO_ERROR) { | ||
216 | Global::statusMessage(tr("Error getting folder info")); | ||
217 | return 0; | ||
218 | } | ||
219 | for (unsigned int i = 0; i < result; ++i) { | ||
220 | err = mailsession_remove_message(m_pop3->sto_session,i+1); | ||
221 | if (err != MAIL_NO_ERROR) { | ||
222 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | ||
223 | res=0; | ||
224 | } | ||
225 | break; | ||
226 | } | ||
227 | return res; | ||
228 | } | ||
229 | |||
230 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { | ||
231 | login(); | ||
232 | target_stat.message_count = 0; | ||
233 | target_stat.message_unseen = 0; | ||
234 | target_stat.message_recent = 0; | ||
235 | if (!m_pop3) | ||
236 | return; | ||
237 | int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, | ||
238 | &target_stat.message_recent,&target_stat.message_unseen); | ||
239 | if (r != MAIL_NO_ERROR) { | ||
240 | ; // odebug << "error getting folter status." << oendl; | ||
241 | } | ||
242 | } | ||
243 | |||
244 | encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { | ||
245 | char*target=0; | ||
246 | size_t length=0; | ||
247 | encodedString*res = 0; | ||
248 | mailmessage * mailmsg = 0; | ||
249 | int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); | ||
250 | err = mailmessage_fetch(mailmsg,&target,&length); | ||
251 | if (mailmsg) | ||
252 | mailmessage_free(mailmsg); | ||
253 | if (target) { | ||
254 | res = new encodedString(target,length); | ||
255 | } | ||
256 | return res; | ||
257 | } | ||
258 | |||
259 | MAILLIB::ATYPE POP3wrapper::getType()const { | ||
260 | return account->getType(); | ||
261 | } | ||
262 | |||
263 | const QString&POP3wrapper::getName()const{ | ||
264 | return account->getAccountName(); | ||
265 | } | ||
diff --git a/kmicromail/libmailwrapper/pop3wrapper.h b/kmicromail/libmailwrapper/pop3wrapper.h new file mode 100644 index 0000000..5101fa5 --- a/dev/null +++ b/kmicromail/libmailwrapper/pop3wrapper.h | |||
@@ -0,0 +1,42 @@ | |||
1 | #ifndef __POP3WRAPPER | ||
2 | #define __POP3WRAPPER | ||
3 | |||
4 | #include "mailwrapper.h" | ||
5 | #include "genericwrapper.h" | ||
6 | #include <qstring.h> | ||
7 | |||
8 | class encodedString; | ||
9 | struct mailstorage; | ||
10 | struct mailfolder; | ||
11 | |||
12 | class POP3wrapper : public Genericwrapper | ||
13 | { | ||
14 | Q_OBJECT | ||
15 | |||
16 | public: | ||
17 | POP3wrapper( POP3account *a ); | ||
18 | virtual ~POP3wrapper(); | ||
19 | /* mailbox will be ignored */ | ||
20 | virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target ); | ||
21 | virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); | ||
22 | /* mailbox will be ignored */ | ||
23 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | ||
24 | |||
25 | virtual void deleteMail(const RecMailP&mail); | ||
26 | virtual void answeredMail(const RecMailP&mail); | ||
27 | virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); | ||
28 | |||
29 | virtual RecBodyP fetchBody( const RecMailP &mail ); | ||
30 | virtual encodedString* fetchRawBody(const RecMailP&mail); | ||
31 | virtual void logout(); | ||
32 | virtual MAILLIB::ATYPE getType()const; | ||
33 | virtual const QString&getName()const; | ||
34 | static void pop3_progress( size_t current, size_t maximum ); | ||
35 | |||
36 | protected: | ||
37 | void login(); | ||
38 | POP3account *account; | ||
39 | mailstorage*m_pop3; | ||
40 | }; | ||
41 | |||
42 | #endif | ||
diff --git a/kmicromail/libmailwrapper/sendmailprogress.cpp b/kmicromail/libmailwrapper/sendmailprogress.cpp new file mode 100644 index 0000000..dc0c75a --- a/dev/null +++ b/kmicromail/libmailwrapper/sendmailprogress.cpp | |||
@@ -0,0 +1,47 @@ | |||
1 | #include "sendmailprogress.h" | ||
2 | #include <qprogressbar.h> | ||
3 | #include <qlabel.h> | ||
4 | |||
5 | progressMailSend::progressMailSend(QWidget*parent, const char * name) | ||
6 | :progressMailSendUI(parent,name,true),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0) | ||
7 | { | ||
8 | } | ||
9 | |||
10 | progressMailSend::~progressMailSend() | ||
11 | { | ||
12 | } | ||
13 | |||
14 | void progressMailSend::setMaxMails(unsigned int aMaxMails) | ||
15 | { | ||
16 | m_max_mail = aMaxMails; | ||
17 | allMailProgressBar->setTotalSteps(aMaxMails); | ||
18 | setMails(); | ||
19 | } | ||
20 | |||
21 | void progressMailSend::setCurrentMails(unsigned int aCurrent) | ||
22 | { | ||
23 | m_current_mail = aCurrent; | ||
24 | allMailProgressBar->setProgress(aCurrent); | ||
25 | setMails(); | ||
26 | } | ||
27 | |||
28 | void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax) | ||
29 | { | ||
30 | m_current_single = aCurrent; | ||
31 | m_max_single = aMax; | ||
32 | setSingle(); | ||
33 | } | ||
34 | |||
35 | void progressMailSend::setSingle() | ||
36 | { | ||
37 | QString text = QString(tr("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single); | ||
38 | singleMailLabel->setText(text); | ||
39 | singleMailProgressBar->setTotalSteps(m_max_single); | ||
40 | singleMailProgressBar->setProgress(m_current_single); | ||
41 | } | ||
42 | |||
43 | void progressMailSend::setMails() | ||
44 | { | ||
45 | QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_mail+1).arg(m_max_mail); | ||
46 | allMailLabel->setText(text); | ||
47 | } | ||
diff --git a/kmicromail/libmailwrapper/sendmailprogress.h b/kmicromail/libmailwrapper/sendmailprogress.h new file mode 100644 index 0000000..5b7d33b --- a/dev/null +++ b/kmicromail/libmailwrapper/sendmailprogress.h | |||
@@ -0,0 +1,19 @@ | |||
1 | #include "sendmailprogressui.h" | ||
2 | |||
3 | class progressMailSend:public progressMailSendUI | ||
4 | { | ||
5 | Q_OBJECT | ||
6 | public: | ||
7 | progressMailSend(QWidget*parent = 0, const char * name = 0); | ||
8 | ~progressMailSend(); | ||
9 | |||
10 | void setMaxMails(unsigned int aMaxMails); | ||
11 | void setCurrentMails(unsigned int aCurrent); | ||
12 | |||
13 | void setSingleMail(unsigned int aCurrent,unsigned int aMax); | ||
14 | |||
15 | protected: | ||
16 | unsigned m_current_mail,m_current_single,m_max_mail,m_max_single; | ||
17 | void setSingle(); | ||
18 | void setMails(); | ||
19 | }; | ||
diff --git a/kmicromail/libmailwrapper/sendmailprogressui.ui b/kmicromail/libmailwrapper/sendmailprogressui.ui new file mode 100644 index 0000000..287ab5e --- a/dev/null +++ b/kmicromail/libmailwrapper/sendmailprogressui.ui | |||
@@ -0,0 +1,110 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>progressMailSendUI</class> | ||
3 | <widget> | ||
4 | <class>QDialog</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>progressMailSendUI</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>221</width> | ||
15 | <height>127</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Sending mail</string> | ||
21 | </property> | ||
22 | <property> | ||
23 | <name>layoutMargin</name> | ||
24 | </property> | ||
25 | <property> | ||
26 | <name>layoutSpacing</name> | ||
27 | </property> | ||
28 | <vbox> | ||
29 | <property stdset="1"> | ||
30 | <name>margin</name> | ||
31 | <number>4</number> | ||
32 | </property> | ||
33 | <property stdset="1"> | ||
34 | <name>spacing</name> | ||
35 | <number>2</number> | ||
36 | </property> | ||
37 | <widget> | ||
38 | <class>QLabel</class> | ||
39 | <property stdset="1"> | ||
40 | <name>name</name> | ||
41 | <cstring>singleMailLabel</cstring> | ||
42 | </property> | ||
43 | <property stdset="1"> | ||
44 | <name>text</name> | ||
45 | <string>Progress of mail</string> | ||
46 | </property> | ||
47 | <property stdset="1"> | ||
48 | <name>alignment</name> | ||
49 | <set>AlignCenter</set> | ||
50 | </property> | ||
51 | <property> | ||
52 | <name>hAlign</name> | ||
53 | </property> | ||
54 | </widget> | ||
55 | <widget> | ||
56 | <class>QProgressBar</class> | ||
57 | <property stdset="1"> | ||
58 | <name>name</name> | ||
59 | <cstring>singleMailProgressBar</cstring> | ||
60 | </property> | ||
61 | </widget> | ||
62 | <widget> | ||
63 | <class>QLabel</class> | ||
64 | <property stdset="1"> | ||
65 | <name>name</name> | ||
66 | <cstring>allMailLabel</cstring> | ||
67 | </property> | ||
68 | <property stdset="1"> | ||
69 | <name>text</name> | ||
70 | <string>Sending mail</string> | ||
71 | </property> | ||
72 | <property stdset="1"> | ||
73 | <name>alignment</name> | ||
74 | <set>AlignCenter</set> | ||
75 | </property> | ||
76 | <property> | ||
77 | <name>hAlign</name> | ||
78 | </property> | ||
79 | </widget> | ||
80 | <widget> | ||
81 | <class>QProgressBar</class> | ||
82 | <property stdset="1"> | ||
83 | <name>name</name> | ||
84 | <cstring>allMailProgressBar</cstring> | ||
85 | </property> | ||
86 | </widget> | ||
87 | <spacer> | ||
88 | <property> | ||
89 | <name>name</name> | ||
90 | <cstring>Spacer6</cstring> | ||
91 | </property> | ||
92 | <property stdset="1"> | ||
93 | <name>orientation</name> | ||
94 | <enum>Vertical</enum> | ||
95 | </property> | ||
96 | <property stdset="1"> | ||
97 | <name>sizeType</name> | ||
98 | <enum>Expanding</enum> | ||
99 | </property> | ||
100 | <property> | ||
101 | <name>sizeHint</name> | ||
102 | <size> | ||
103 | <width>20</width> | ||
104 | <height>20</height> | ||
105 | </size> | ||
106 | </property> | ||
107 | </spacer> | ||
108 | </vbox> | ||
109 | </widget> | ||
110 | </UI> | ||
diff --git a/kmicromail/libmailwrapper/settings.cpp b/kmicromail/libmailwrapper/settings.cpp new file mode 100644 index 0000000..bdb2a25 --- a/dev/null +++ b/kmicromail/libmailwrapper/settings.cpp | |||
@@ -0,0 +1,440 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <qdir.h> | ||
3 | |||
4 | //#include <opie2/odebug.h> | ||
5 | #include <qpe/config.h> | ||
6 | |||
7 | #include <kstandarddirs.h> | ||
8 | #include "settings.h" | ||
9 | //#include "defines.h" | ||
10 | |||
11 | #define IMAP_PORT "143" | ||
12 | #define IMAP_SSL_PORT "993" | ||
13 | #define SMTP_PORT "25" | ||
14 | #define SMTP_SSL_PORT "465" | ||
15 | #define POP3_PORT "110" | ||
16 | #define POP3_SSL_PORT "995" | ||
17 | #define NNTP_PORT "119" | ||
18 | #define NNTP_SSL_PORT "563" | ||
19 | |||
20 | |||
21 | Settings::Settings() | ||
22 | : QObject() | ||
23 | { | ||
24 | updateAccounts(); | ||
25 | } | ||
26 | |||
27 | void Settings::checkDirectory() | ||
28 | { | ||
29 | qDebug("Settings::checkDirectory() "); | ||
30 | return; | ||
31 | locateLocal("data", "kmicromail" ); | ||
32 | /* | ||
33 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { | ||
34 | system( "mkdir -p $HOME/Applications/opiemail" ); | ||
35 | qDebug("$HOME/Applications/opiemail created "); | ||
36 | } | ||
37 | */ | ||
38 | } | ||
39 | |||
40 | QList<Account> Settings::getAccounts() | ||
41 | { | ||
42 | return accounts; | ||
43 | } | ||
44 | |||
45 | void Settings::addAccount( Account *account ) | ||
46 | { | ||
47 | accounts.append( account ); | ||
48 | } | ||
49 | |||
50 | void Settings::delAccount( Account *account ) | ||
51 | { | ||
52 | accounts.remove( account ); | ||
53 | account->remove(); | ||
54 | } | ||
55 | |||
56 | void Settings::updateAccounts() | ||
57 | { | ||
58 | accounts.clear(); | ||
59 | QDir dir( locateLocal("data", "kmicromail" ) ); | ||
60 | QStringList::Iterator it; | ||
61 | |||
62 | QStringList imap = dir.entryList( "imap-*" ); | ||
63 | for ( it = imap.begin(); it != imap.end(); it++ ) { | ||
64 | IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); | ||
65 | accounts.append( account ); | ||
66 | } | ||
67 | |||
68 | QStringList pop3 = dir.entryList( "pop3-*" ); | ||
69 | for ( it = pop3.begin(); it != pop3.end(); it++ ) { | ||
70 | POP3account *account = new POP3account( (*it).replace(0, 5, "") ); | ||
71 | accounts.append( account ); | ||
72 | } | ||
73 | |||
74 | QStringList smtp = dir.entryList( "smtp-*" ); | ||
75 | for ( it = smtp.begin(); it != smtp.end(); it++ ) { | ||
76 | SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); | ||
77 | accounts.append( account ); | ||
78 | } | ||
79 | |||
80 | QStringList nntp = dir.entryList( "nntp-*" ); | ||
81 | for ( it = nntp.begin(); it != nntp.end(); it++ ) { | ||
82 | NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); | ||
83 | accounts.append( account ); | ||
84 | } | ||
85 | |||
86 | readAccounts(); | ||
87 | } | ||
88 | |||
89 | void Settings::saveAccounts() | ||
90 | { | ||
91 | checkDirectory(); | ||
92 | Account *it; | ||
93 | |||
94 | for ( it = accounts.first(); it; it = accounts.next() ) { | ||
95 | it->save(); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | void Settings::readAccounts() | ||
100 | { | ||
101 | checkDirectory(); | ||
102 | Account *it; | ||
103 | |||
104 | for ( it = accounts.first(); it; it = accounts.next() ) { | ||
105 | it->read(); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | Account::Account() | ||
110 | { | ||
111 | accountName = "changeMe"; | ||
112 | type = MAILLIB::A_UNDEFINED; | ||
113 | ssl = false; | ||
114 | connectionType = 1; | ||
115 | offline = false; | ||
116 | } | ||
117 | |||
118 | void Account::remove() | ||
119 | { | ||
120 | QFile file( getFileName() ); | ||
121 | file.remove(); | ||
122 | } | ||
123 | |||
124 | IMAPaccount::IMAPaccount() | ||
125 | : Account() | ||
126 | { | ||
127 | file = IMAPaccount::getUniqueFileName(); | ||
128 | accountName = "New IMAP Account"; | ||
129 | ssl = false; | ||
130 | connectionType = 1; | ||
131 | type = MAILLIB::A_IMAP; | ||
132 | port = IMAP_PORT; | ||
133 | } | ||
134 | |||
135 | IMAPaccount::IMAPaccount( QString filename ) | ||
136 | : Account() | ||
137 | { | ||
138 | file = filename; | ||
139 | accountName = "New IMAP Account"; | ||
140 | ssl = false; | ||
141 | connectionType = 1; | ||
142 | type = MAILLIB::A_IMAP; | ||
143 | port = IMAP_PORT; | ||
144 | } | ||
145 | |||
146 | QString IMAPaccount::getUniqueFileName() | ||
147 | { | ||
148 | int num = 0; | ||
149 | QString unique; | ||
150 | |||
151 | QDir dir( locateLocal("data", "kmicromail" ) ); | ||
152 | |||
153 | QStringList imap = dir.entryList( "imap-*" ); | ||
154 | do { | ||
155 | unique.setNum( num++ ); | ||
156 | } while ( imap.contains( "imap-" + unique ) > 0 ); | ||
157 | |||
158 | return unique; | ||
159 | } | ||
160 | |||
161 | void IMAPaccount::read() | ||
162 | { | ||
163 | Config *conf = new Config( getFileName(), Config::File ); | ||
164 | conf->setGroup( "IMAP Account" ); | ||
165 | accountName = conf->readEntry( "Account","" ); | ||
166 | if (accountName.isNull()) accountName = ""; | ||
167 | server = conf->readEntry( "Server","" ); | ||
168 | if (server.isNull()) server=""; | ||
169 | port = conf->readEntry( "Port","" ); | ||
170 | if (port.isNull()) port="143"; | ||
171 | connectionType = conf->readNumEntry( "ConnectionType" ); | ||
172 | ssl = conf->readBoolEntry( "SSL",false ); | ||
173 | user = conf->readEntry( "User","" ); | ||
174 | if (user.isNull()) user = ""; | ||
175 | password = conf->readEntryCrypt( "Password","" ); | ||
176 | if (password.isNull()) password = ""; | ||
177 | prefix = conf->readEntry("MailPrefix",""); | ||
178 | if (prefix.isNull()) prefix = ""; | ||
179 | offline = conf->readBoolEntry("Offline",false); | ||
180 | delete conf; | ||
181 | } | ||
182 | |||
183 | void IMAPaccount::save() | ||
184 | { | ||
185 | qDebug("saving %s ",getFileName().latin1() ); | ||
186 | Settings::checkDirectory(); | ||
187 | |||
188 | Config *conf = new Config( getFileName(), Config::File ); | ||
189 | conf->setGroup( "IMAP Account" ); | ||
190 | conf->writeEntry( "Account", accountName ); | ||
191 | conf->writeEntry( "Server", server ); | ||
192 | conf->writeEntry( "Port", port ); | ||
193 | conf->writeEntry( "SSL", ssl ); | ||
194 | conf->writeEntry( "ConnectionType", connectionType ); | ||
195 | conf->writeEntry( "User", user ); | ||
196 | conf->writeEntryCrypt( "Password", password ); | ||
197 | conf->writeEntry( "MailPrefix",prefix); | ||
198 | conf->writeEntry( "Offline",offline); | ||
199 | conf->write(); | ||
200 | delete conf; | ||
201 | } | ||
202 | |||
203 | |||
204 | QString IMAPaccount::getFileName() | ||
205 | { | ||
206 | return locateLocal("data", "kmicromail" ) +"/imap-" + file; | ||
207 | } | ||
208 | |||
209 | POP3account::POP3account() | ||
210 | : Account() | ||
211 | { | ||
212 | file = POP3account::getUniqueFileName(); | ||
213 | accountName = "New POP3 Account"; | ||
214 | ssl = false; | ||
215 | connectionType = 1; | ||
216 | type = MAILLIB::A_POP3; | ||
217 | port = POP3_PORT; | ||
218 | } | ||
219 | |||
220 | POP3account::POP3account( QString filename ) | ||
221 | : Account() | ||
222 | { | ||
223 | file = filename; | ||
224 | accountName = "New POP3 Account"; | ||
225 | ssl = false; | ||
226 | connectionType = 1; | ||
227 | type = MAILLIB::A_POP3; | ||
228 | port = POP3_PORT; | ||
229 | } | ||
230 | |||
231 | QString POP3account::getUniqueFileName() | ||
232 | { | ||
233 | int num = 0; | ||
234 | QString unique; | ||
235 | |||
236 | QDir dir( locateLocal("data", "kmicromail" ) ); | ||
237 | |||
238 | QStringList imap = dir.entryList( "pop3-*" ); | ||
239 | do { | ||
240 | unique.setNum( num++ ); | ||
241 | } while ( imap.contains( "pop3-" + unique ) > 0 ); | ||
242 | |||
243 | return unique; | ||
244 | } | ||
245 | |||
246 | void POP3account::read() | ||
247 | { | ||
248 | Config *conf = new Config( getFileName(), Config::File ); | ||
249 | conf->setGroup( "POP3 Account" ); | ||
250 | accountName = conf->readEntry( "Account" ); | ||
251 | server = conf->readEntry( "Server" ); | ||
252 | port = conf->readEntry( "Port" ); | ||
253 | ssl = conf->readBoolEntry( "SSL" ); | ||
254 | connectionType = conf->readNumEntry( "ConnectionType" ); | ||
255 | user = conf->readEntry( "User" ); | ||
256 | password = conf->readEntryCrypt( "Password" ); | ||
257 | offline = conf->readBoolEntry("Offline",false); | ||
258 | delete conf; | ||
259 | } | ||
260 | |||
261 | void POP3account::save() | ||
262 | { | ||
263 | Settings::checkDirectory(); | ||
264 | |||
265 | Config *conf = new Config( getFileName(), Config::File ); | ||
266 | conf->setGroup( "POP3 Account" ); | ||
267 | conf->writeEntry( "Account", accountName ); | ||
268 | conf->writeEntry( "Server", server ); | ||
269 | conf->writeEntry( "Port", port ); | ||
270 | conf->writeEntry( "SSL", ssl ); | ||
271 | conf->writeEntry( "ConnectionType", connectionType ); | ||
272 | conf->writeEntry( "User", user ); | ||
273 | conf->writeEntryCrypt( "Password", password ); | ||
274 | conf->writeEntry( "Offline",offline); | ||
275 | conf->write(); | ||
276 | delete conf; | ||
277 | } | ||
278 | |||
279 | |||
280 | QString POP3account::getFileName() | ||
281 | { | ||
282 | return locateLocal("data", "kmicromail" ) +"/pop3-" + file; | ||
283 | } | ||
284 | |||
285 | SMTPaccount::SMTPaccount() | ||
286 | : Account() | ||
287 | { | ||
288 | file = SMTPaccount::getUniqueFileName(); | ||
289 | accountName = "New SMTP Account"; | ||
290 | ssl = false; | ||
291 | connectionType = 1; | ||
292 | login = false; | ||
293 | useCC = false; | ||
294 | useBCC = false; | ||
295 | useReply = false; | ||
296 | type = MAILLIB::A_SMTP; | ||
297 | port = SMTP_PORT; | ||
298 | } | ||
299 | |||
300 | SMTPaccount::SMTPaccount( QString filename ) | ||
301 | : Account() | ||
302 | { | ||
303 | file = filename; | ||
304 | accountName = "New SMTP Account"; | ||
305 | ssl = false; | ||
306 | connectionType = 1; | ||
307 | login = false; | ||
308 | type = MAILLIB::A_SMTP; | ||
309 | port = SMTP_PORT; | ||
310 | } | ||
311 | |||
312 | QString SMTPaccount::getUniqueFileName() | ||
313 | { | ||
314 | int num = 0; | ||
315 | QString unique; | ||
316 | |||
317 | QDir dir( locateLocal("data", "kmicromail" ) ); | ||
318 | |||
319 | QStringList imap = dir.entryList( "smtp-*" ); | ||
320 | do { | ||
321 | unique.setNum( num++ ); | ||
322 | } while ( imap.contains( "smtp-" + unique ) > 0 ); | ||
323 | |||
324 | return unique; | ||
325 | } | ||
326 | |||
327 | void SMTPaccount::read() | ||
328 | { | ||
329 | Config *conf = new Config( getFileName(), Config::File ); | ||
330 | conf->setGroup( "SMTP Account" ); | ||
331 | accountName = conf->readEntry( "Account" ); | ||
332 | server = conf->readEntry( "Server" ); | ||
333 | port = conf->readEntry( "Port" ); | ||
334 | ssl = conf->readBoolEntry( "SSL" ); | ||
335 | connectionType = conf->readNumEntry( "ConnectionType" ); | ||
336 | login = conf->readBoolEntry( "Login" ); | ||
337 | user = conf->readEntry( "User" ); | ||
338 | password = conf->readEntryCrypt( "Password" ); | ||
339 | delete conf; | ||
340 | } | ||
341 | |||
342 | void SMTPaccount::save() | ||
343 | { | ||
344 | Settings::checkDirectory(); | ||
345 | |||
346 | Config *conf = new Config( getFileName(), Config::File ); | ||
347 | conf->setGroup( "SMTP Account" ); | ||
348 | conf->writeEntry( "Account", accountName ); | ||
349 | conf->writeEntry( "Server", server ); | ||
350 | conf->writeEntry( "Port", port ); | ||
351 | conf->writeEntry( "SSL", ssl ); | ||
352 | conf->writeEntry( "ConnectionType", connectionType ); | ||
353 | conf->writeEntry( "Login", login ); | ||
354 | conf->writeEntry( "User", user ); | ||
355 | conf->writeEntryCrypt( "Password", password ); | ||
356 | conf->write(); | ||
357 | delete conf; | ||
358 | } | ||
359 | |||
360 | |||
361 | QString SMTPaccount::getFileName() | ||
362 | { | ||
363 | return locateLocal("data", "kmicromail" ) +"/smtp-" + file; | ||
364 | } | ||
365 | |||
366 | NNTPaccount::NNTPaccount() | ||
367 | : Account() | ||
368 | { | ||
369 | file = NNTPaccount::getUniqueFileName(); | ||
370 | accountName = "New NNTP Account"; | ||
371 | ssl = false; | ||
372 | login = false; | ||
373 | type = MAILLIB::A_NNTP; | ||
374 | port = NNTP_PORT; | ||
375 | } | ||
376 | |||
377 | NNTPaccount::NNTPaccount( QString filename ) | ||
378 | : Account() | ||
379 | { | ||
380 | file = filename; | ||
381 | accountName = "New NNTP Account"; | ||
382 | ssl = false; | ||
383 | login = false; | ||
384 | type = MAILLIB::A_NNTP; | ||
385 | port = NNTP_PORT; | ||
386 | } | ||
387 | |||
388 | QString NNTPaccount::getUniqueFileName() | ||
389 | { | ||
390 | int num = 0; | ||
391 | QString unique; | ||
392 | |||
393 | QDir dir( locateLocal("data", "kmicromail" ) ); | ||
394 | |||
395 | QStringList imap = dir.entryList( "nntp-*" ); | ||
396 | do { | ||
397 | unique.setNum( num++ ); | ||
398 | } while ( imap.contains( "nntp-" + unique ) > 0 ); | ||
399 | |||
400 | return unique; | ||
401 | } | ||
402 | |||
403 | void NNTPaccount::read() | ||
404 | { | ||
405 | Config *conf = new Config( getFileName(), Config::File ); | ||
406 | conf->setGroup( "NNTP Account" ); | ||
407 | accountName = conf->readEntry( "Account" ); | ||
408 | server = conf->readEntry( "Server" ); | ||
409 | port = conf->readEntry( "Port" ); | ||
410 | ssl = conf->readBoolEntry( "SSL" ); | ||
411 | login = conf->readBoolEntry( "Login" ); | ||
412 | user = conf->readEntry( "User" ); | ||
413 | password = conf->readEntryCrypt( "Password" ); | ||
414 | subscribedGroups = conf->readListEntry( "Subscribed", ',' ); | ||
415 | delete conf; | ||
416 | } | ||
417 | |||
418 | void NNTPaccount::save() | ||
419 | { | ||
420 | Settings::checkDirectory(); | ||
421 | |||
422 | Config *conf = new Config( getFileName(), Config::File ); | ||
423 | conf->setGroup( "NNTP Account" ); | ||
424 | conf->writeEntry( "Account", accountName ); | ||
425 | conf->writeEntry( "Server", server ); | ||
426 | conf->writeEntry( "Port", port ); | ||
427 | conf->writeEntry( "SSL", ssl ); | ||
428 | conf->writeEntry( "Login", login ); | ||
429 | conf->writeEntry( "User", user ); | ||
430 | conf->writeEntryCrypt( "Password", password ); | ||
431 | conf->writeEntry( "Subscribed" , subscribedGroups, ',' ); | ||
432 | conf->write(); | ||
433 | delete conf; | ||
434 | } | ||
435 | |||
436 | |||
437 | QString NNTPaccount::getFileName() | ||
438 | { | ||
439 | return locateLocal("data", "kmicromail" ) +"/nntp-" + file; | ||
440 | } | ||
diff --git a/kmicromail/libmailwrapper/settings.h b/kmicromail/libmailwrapper/settings.h new file mode 100644 index 0000000..ba3ec89 --- a/dev/null +++ b/kmicromail/libmailwrapper/settings.h | |||
@@ -0,0 +1,164 @@ | |||
1 | #ifndef SETTINGS_H | ||
2 | #define SETTINGS_H | ||
3 | |||
4 | #include "maildefines.h" | ||
5 | |||
6 | /* OPIE */ | ||
7 | |||
8 | /* QT */ | ||
9 | #include <qobject.h> | ||
10 | #include <qlist.h> | ||
11 | |||
12 | class Account | ||
13 | { | ||
14 | |||
15 | public: | ||
16 | Account(); | ||
17 | virtual ~Account() {} | ||
18 | |||
19 | void remove(); | ||
20 | void setAccountName( QString name ) { accountName = name; } | ||
21 | const QString&getAccountName()const{ return accountName; } | ||
22 | MAILLIB::ATYPE getType()const{ return type; } | ||
23 | |||
24 | void setServer(const QString&str){ server = str; } | ||
25 | const QString&getServer()const{ return server; } | ||
26 | |||
27 | void setPort(const QString&str) { port = str; } | ||
28 | const QString&getPort()const{ return port; } | ||
29 | |||
30 | void setUser(const QString&str){ user = str; } | ||
31 | const QString&getUser()const{ return user; } | ||
32 | |||
33 | void setPassword(const QString&str) { password = str; } | ||
34 | const QString&getPassword()const { return password; } | ||
35 | |||
36 | void setSSL( bool b ) { ssl = b; } | ||
37 | bool getSSL() { return ssl; } | ||
38 | |||
39 | void setConnectionType( int x ) { connectionType = x; } | ||
40 | int ConnectionType() { return connectionType; } | ||
41 | |||
42 | |||
43 | void setOffline(bool b) {offline = b;} | ||
44 | bool getOffline()const{return offline;} | ||
45 | |||
46 | virtual QString getFileName() { return accountName; } | ||
47 | virtual void read() { ; } | ||
48 | virtual void save() { ; } | ||
49 | |||
50 | protected: | ||
51 | QString accountName, server, port, user, password; | ||
52 | bool ssl; | ||
53 | int connectionType; | ||
54 | bool offline; | ||
55 | MAILLIB::ATYPE type; | ||
56 | }; | ||
57 | |||
58 | class IMAPaccount : public Account | ||
59 | { | ||
60 | |||
61 | public: | ||
62 | IMAPaccount(); | ||
63 | IMAPaccount( QString filename ); | ||
64 | |||
65 | static QString getUniqueFileName(); | ||
66 | |||
67 | virtual void read(); | ||
68 | virtual void save(); | ||
69 | virtual QString getFileName(); | ||
70 | |||
71 | void setPrefix(const QString&str) {prefix=str;} | ||
72 | const QString&getPrefix()const{return prefix;} | ||
73 | |||
74 | private: | ||
75 | QString file,prefix; | ||
76 | |||
77 | }; | ||
78 | |||
79 | class POP3account : public Account | ||
80 | { | ||
81 | |||
82 | public: | ||
83 | POP3account(); | ||
84 | POP3account( QString filename ); | ||
85 | |||
86 | static QString getUniqueFileName(); | ||
87 | |||
88 | virtual void read(); | ||
89 | virtual void save(); | ||
90 | virtual QString getFileName(); | ||
91 | |||
92 | private: | ||
93 | QString file; | ||
94 | |||
95 | }; | ||
96 | |||
97 | class SMTPaccount : public Account | ||
98 | { | ||
99 | |||
100 | public: | ||
101 | SMTPaccount(); | ||
102 | SMTPaccount( QString filename ); | ||
103 | |||
104 | static QString getUniqueFileName(); | ||
105 | |||
106 | virtual void read(); | ||
107 | virtual void save(); | ||
108 | virtual QString getFileName(); | ||
109 | |||
110 | void setLogin( bool b ) { login = b; } | ||
111 | bool getLogin() { return login; } | ||
112 | |||
113 | private: | ||
114 | QString file, name, mail, org, cc, bcc, reply, signature; | ||
115 | bool useCC, useBCC, useReply, login; | ||
116 | |||
117 | }; | ||
118 | |||
119 | class NNTPaccount : public Account | ||
120 | { | ||
121 | |||
122 | public: | ||
123 | NNTPaccount(); | ||
124 | NNTPaccount( QString filename ); | ||
125 | |||
126 | static QString getUniqueFileName(); | ||
127 | |||
128 | virtual void read(); | ||
129 | virtual void save(); | ||
130 | virtual QString getFileName(); | ||
131 | |||
132 | void setLogin( bool b ) { login = b; } | ||
133 | bool getLogin() { return login; } | ||
134 | |||
135 | void setGroups( QStringList list ) { subscribedGroups = list; } | ||
136 | QStringList getGroups() { return subscribedGroups; } | ||
137 | |||
138 | private: | ||
139 | QString file; | ||
140 | bool login; | ||
141 | QStringList subscribedGroups; | ||
142 | |||
143 | }; | ||
144 | |||
145 | class Settings : public QObject | ||
146 | { | ||
147 | Q_OBJECT | ||
148 | |||
149 | public: | ||
150 | Settings(); | ||
151 | QList<Account> getAccounts(); | ||
152 | void addAccount(Account *account); | ||
153 | void delAccount(Account *account); | ||
154 | void saveAccounts(); | ||
155 | void readAccounts(); | ||
156 | static void checkDirectory(); | ||
157 | |||
158 | private: | ||
159 | void updateAccounts(); | ||
160 | QList<Account> accounts; | ||
161 | |||
162 | }; | ||
163 | |||
164 | #endif | ||
diff --git a/kmicromail/libmailwrapper/smtpwrapper.cpp b/kmicromail/libmailwrapper/smtpwrapper.cpp new file mode 100644 index 0000000..04a21ea --- a/dev/null +++ b/kmicromail/libmailwrapper/smtpwrapper.cpp | |||
@@ -0,0 +1,458 @@ | |||
1 | #include "smtpwrapper.h" | ||
2 | #include "mailwrapper.h" | ||
3 | #include "abstractmail.h" | ||
4 | #include "logindialog.h" | ||
5 | #include "mailtypes.h" | ||
6 | #include "sendmailprogress.h" | ||
7 | |||
8 | //#include <opie2/odebug.h> | ||
9 | //#include <qt.h> | ||
10 | #include <qapplication.h> | ||
11 | #include <qmessagebox.h> | ||
12 | #include <stdlib.h> | ||
13 | #include <qpe/config.h> | ||
14 | #include <qpe/qcopenvelope_qws.h> | ||
15 | |||
16 | #include <libetpan/libetpan.h> | ||
17 | |||
18 | |||
19 | using namespace Opie::Core; | ||
20 | progressMailSend*SMTPwrapper::sendProgress = 0; | ||
21 | |||
22 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) | ||
23 | : Generatemail() | ||
24 | { | ||
25 | m_SmtpAccount = aSmtp; | ||
26 | Config cfg( "mail" ); | ||
27 | cfg.setGroup( "Status" ); | ||
28 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); | ||
29 | emit queuedMails( m_queuedMail ); | ||
30 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); | ||
31 | m_smtp = 0; | ||
32 | } | ||
33 | |||
34 | SMTPwrapper::~SMTPwrapper() | ||
35 | { | ||
36 | disc_server(); | ||
37 | } | ||
38 | |||
39 | void SMTPwrapper::emitQCop( int queued ) { | ||
40 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); | ||
41 | env << queued; | ||
42 | } | ||
43 | |||
44 | QString SMTPwrapper::mailsmtpError( int errnum ) { | ||
45 | switch ( errnum ) { | ||
46 | case MAILSMTP_NO_ERROR: | ||
47 | return tr( "No error" ); | ||
48 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | ||
49 | return tr( "Unexpected error code" ); | ||
50 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | ||
51 | return tr( "Service not available" ); | ||
52 | case MAILSMTP_ERROR_STREAM: | ||
53 | return tr( "Stream error" ); | ||
54 | case MAILSMTP_ERROR_HOSTNAME: | ||
55 | return tr( "gethostname() failed" ); | ||
56 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | ||
57 | return tr( "Not implemented" ); | ||
58 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | ||
59 | return tr( "Error, action not taken" ); | ||
60 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | ||
61 | return tr( "Data exceeds storage allocation" ); | ||
62 | case MAILSMTP_ERROR_IN_PROCESSING: | ||
63 | return tr( "Error in processing" ); | ||
64 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: | ||
65 | return tr( "Starttls not supported" ); | ||
66 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | ||
67 | // return tr( "Insufficient system storage" ); | ||
68 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | ||
69 | return tr( "Mailbox unavailable" ); | ||
70 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | ||
71 | return tr( "Mailbox name not allowed" ); | ||
72 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | ||
73 | return tr( "Bad command sequence" ); | ||
74 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | ||
75 | return tr( "User not local" ); | ||
76 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | ||
77 | return tr( "Transaction failed" ); | ||
78 | case MAILSMTP_ERROR_MEMORY: | ||
79 | return tr( "Memory error" ); | ||
80 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | ||
81 | return tr( "Connection refused" ); | ||
82 | default: | ||
83 | return tr( "Unknown error code" ); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | |||
88 | void SMTPwrapper::progress( size_t current, size_t maximum ) { | ||
89 | if (SMTPwrapper::sendProgress) { | ||
90 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | ||
91 | qApp->processEvents(); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { | ||
96 | if (!mail) | ||
97 | return; | ||
98 | QString localfolders = AbstractMail::defaultLocalfolder(); | ||
99 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | ||
100 | wrap->createMbox(box); | ||
101 | wrap->storeMessage(mail,length,box); | ||
102 | delete wrap; | ||
103 | } | ||
104 | |||
105 | void SMTPwrapper::smtpSend( mailmime *mail,bool later) { | ||
106 | clist *rcpts = 0; | ||
107 | char *from, *data; | ||
108 | size_t size; | ||
109 | |||
110 | from = data = 0; | ||
111 | |||
112 | mailmessage * msg = 0; | ||
113 | msg = mime_message_init(mail); | ||
114 | mime_message_set_tmpdir(msg,getenv( "HOME" )); | ||
115 | int r = mailmessage_fetch(msg,&data,&size); | ||
116 | mime_message_detach_mime(msg); | ||
117 | mailmessage_free(msg); | ||
118 | if (r != MAIL_NO_ERROR || !data) { | ||
119 | if (data) | ||
120 | free(data); | ||
121 | ; // odebug << "Error fetching mime..." << oendl; | ||
122 | return; | ||
123 | } | ||
124 | msg = 0; | ||
125 | if (later) { | ||
126 | storeMail(data,size,"Outgoing"); | ||
127 | if (data) | ||
128 | free( data ); | ||
129 | Config cfg( "mail" ); | ||
130 | cfg.setGroup( "Status" ); | ||
131 | cfg.writeEntry( "outgoing", ++m_queuedMail ); | ||
132 | emit queuedMails( m_queuedMail ); | ||
133 | return; | ||
134 | } | ||
135 | from = getFrom( mail ); | ||
136 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | ||
137 | smtpSend(from,rcpts,data,size); | ||
138 | if (data) { | ||
139 | free(data); | ||
140 | } | ||
141 | if (from) { | ||
142 | free(from); | ||
143 | } | ||
144 | if (rcpts) | ||
145 | smtp_address_list_free( rcpts ); | ||
146 | } | ||
147 | |||
148 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) | ||
149 | { | ||
150 | if (data) { | ||
151 | storeMail(data,size,"Sendfailed"); | ||
152 | } | ||
153 | if (failuremessage) { | ||
154 | QMessageBox::critical(0,tr("Error sending mail"), | ||
155 | tr("<center>%1</center>").arg(failuremessage)); | ||
156 | } | ||
157 | } | ||
158 | |||
159 | int SMTPwrapper::start_smtp_tls() | ||
160 | { | ||
161 | if (!m_smtp) { | ||
162 | return MAILSMTP_ERROR_IN_PROCESSING; | ||
163 | } | ||
164 | int err = mailesmtp_starttls(m_smtp); | ||
165 | if (err != MAILSMTP_NO_ERROR) return err; | ||
166 | mailstream_low * low; | ||
167 | mailstream_low * new_low; | ||
168 | low = mailstream_get_low(m_smtp->stream); | ||
169 | if (!low) { | ||
170 | return MAILSMTP_ERROR_IN_PROCESSING; | ||
171 | } | ||
172 | int fd = mailstream_low_get_fd(low); | ||
173 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | ||
174 | mailstream_low_free(low); | ||
175 | mailstream_set_low(m_smtp->stream, new_low); | ||
176 | } else { | ||
177 | return MAILSMTP_ERROR_IN_PROCESSING; | ||
178 | } | ||
179 | return err; | ||
180 | } | ||
181 | |||
182 | void SMTPwrapper::connect_server() | ||
183 | { | ||
184 | const char *server, *user, *pass; | ||
185 | bool ssl; | ||
186 | uint16_t port; | ||
187 | ssl = false; | ||
188 | bool try_tls = true; | ||
189 | bool force_tls=false; | ||
190 | server = user = pass = 0; | ||
191 | QString failuretext = ""; | ||
192 | |||
193 | if (m_smtp || !m_SmtpAccount) { | ||
194 | return; | ||
195 | } | ||
196 | server = m_SmtpAccount->getServer().latin1(); | ||
197 | if ( m_SmtpAccount->ConnectionType() == 2 ) { | ||
198 | ssl = true; | ||
199 | try_tls = false; | ||
200 | } else if (m_SmtpAccount->ConnectionType() == 1) { | ||
201 | force_tls = true; | ||
202 | } | ||
203 | int result = 1; | ||
204 | port = m_SmtpAccount->getPort().toUInt(); | ||
205 | |||
206 | m_smtp = mailsmtp_new( 20, &progress ); | ||
207 | if ( m_smtp == NULL ) { | ||
208 | /* no failure message cause this happens when problems with memory - than we | ||
209 | we can not display any messagebox */ | ||
210 | return; | ||
211 | } | ||
212 | |||
213 | int err = MAILSMTP_NO_ERROR; | ||
214 | ; // odebug << "Servername " << server << " at port " << port << "" << oendl; | ||
215 | if ( ssl ) { | ||
216 | ; // odebug << "SSL session" << oendl; | ||
217 | err = mailsmtp_ssl_connect( m_smtp, server, port ); | ||
218 | } else { | ||
219 | ; // odebug << "No SSL session" << oendl; | ||
220 | err = mailsmtp_socket_connect( m_smtp, server, port ); | ||
221 | } | ||
222 | if ( err != MAILSMTP_NO_ERROR ) { | ||
223 | ; // odebug << "Error init connection" << oendl; | ||
224 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); | ||
225 | result = 0; | ||
226 | } | ||
227 | |||
228 | /* switch to tls after init 'cause there it will send the ehlo */ | ||
229 | if (result) { | ||
230 | err = mailsmtp_init( m_smtp ); | ||
231 | if (err != MAILSMTP_NO_ERROR) { | ||
232 | result = 0; | ||
233 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); | ||
234 | } | ||
235 | } | ||
236 | |||
237 | if (try_tls) { | ||
238 | err = start_smtp_tls(); | ||
239 | if (err != MAILSMTP_NO_ERROR) { | ||
240 | try_tls = false; | ||
241 | } else { | ||
242 | err = mailesmtp_ehlo(m_smtp); | ||
243 | } | ||
244 | } | ||
245 | |||
246 | if (!try_tls && force_tls) { | ||
247 | result = 0; | ||
248 | failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); | ||
249 | } | ||
250 | |||
251 | if (result==1 && m_SmtpAccount->getLogin() ) { | ||
252 | ; // odebug << "smtp with auth" << oendl; | ||
253 | if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { | ||
254 | // get'em | ||
255 | LoginDialog login( m_SmtpAccount->getUser(), | ||
256 | m_SmtpAccount->getPassword(), NULL, 0, true ); | ||
257 | login.show(); | ||
258 | if ( QDialog::Accepted == login.exec() ) { | ||
259 | // ok | ||
260 | user = login.getUser().latin1(); | ||
261 | pass = login.getPassword().latin1(); | ||
262 | } else { | ||
263 | result = 0; | ||
264 | failuretext=tr("Login aborted - storing mail to localfolder"); | ||
265 | } | ||
266 | } else { | ||
267 | user = m_SmtpAccount->getUser().latin1(); | ||
268 | pass = m_SmtpAccount->getPassword().latin1(); | ||
269 | } | ||
270 | ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl; | ||
271 | if (result) { | ||
272 | err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass ); | ||
273 | if ( err == MAILSMTP_NO_ERROR ) { | ||
274 | ; // odebug << "auth ok" << oendl; | ||
275 | } else { | ||
276 | failuretext = tr("Authentification failed"); | ||
277 | result = 0; | ||
278 | } | ||
279 | } | ||
280 | } | ||
281 | } | ||
282 | |||
283 | void SMTPwrapper::disc_server() | ||
284 | { | ||
285 | if (m_smtp) { | ||
286 | mailsmtp_quit( m_smtp ); | ||
287 | mailsmtp_free( m_smtp ); | ||
288 | m_smtp = 0; | ||
289 | } | ||
290 | } | ||
291 | |||
292 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) | ||
293 | { | ||
294 | int err,result; | ||
295 | QString failuretext = ""; | ||
296 | |||
297 | connect_server(); | ||
298 | |||
299 | result = 1; | ||
300 | if (m_smtp) { | ||
301 | err = mailsmtp_send( m_smtp, from, rcpts, data, size ); | ||
302 | if ( err != MAILSMTP_NO_ERROR ) { | ||
303 | failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); | ||
304 | result = 0; | ||
305 | } | ||
306 | } else { | ||
307 | result = 0; | ||
308 | } | ||
309 | |||
310 | if (!result) { | ||
311 | storeFailedMail(data,size,failuretext); | ||
312 | } else { | ||
313 | ; // odebug << "Mail sent." << oendl; | ||
314 | storeMail(data,size,"Sent"); | ||
315 | } | ||
316 | return result; | ||
317 | } | ||
318 | |||
319 | void SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) | ||
320 | { | ||
321 | mailmime * mimeMail; | ||
322 | |||
323 | mimeMail = createMimeMail(mail ); | ||
324 | if ( mimeMail == NULL ) { | ||
325 | ; // odebug << "sendMail: error creating mime mail" << oendl; | ||
326 | } else { | ||
327 | sendProgress = new progressMailSend(); | ||
328 | sendProgress->show(); | ||
329 | sendProgress->setMaxMails(1); | ||
330 | smtpSend( mimeMail,later); | ||
331 | ; // odebug << "Clean up done" << oendl; | ||
332 | sendProgress->hide(); | ||
333 | delete sendProgress; | ||
334 | sendProgress = 0; | ||
335 | mailmime_free( mimeMail ); | ||
336 | } | ||
337 | } | ||
338 | |||
339 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { | ||
340 | size_t curTok = 0; | ||
341 | mailimf_fields *fields = 0; | ||
342 | mailimf_field*ffrom = 0; | ||
343 | clist *rcpts = 0; | ||
344 | char*from = 0; | ||
345 | int res = 0; | ||
346 | |||
347 | encodedString * data = wrap->fetchRawBody(which); | ||
348 | if (!data) | ||
349 | return 0; | ||
350 | int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); | ||
351 | if (err != MAILIMF_NO_ERROR) { | ||
352 | delete data; | ||
353 | delete wrap; | ||
354 | return 0; | ||
355 | } | ||
356 | |||
357 | rcpts = createRcptList( fields ); | ||
358 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); | ||
359 | from = getFrom(ffrom); | ||
360 | |||
361 | if (rcpts && from) { | ||
362 | res = smtpSend(from,rcpts,data->Content(),data->Length()); | ||
363 | } | ||
364 | if (fields) { | ||
365 | mailimf_fields_free(fields); | ||
366 | fields = 0; | ||
367 | } | ||
368 | if (data) { | ||
369 | delete data; | ||
370 | } | ||
371 | if (from) { | ||
372 | free(from); | ||
373 | } | ||
374 | if (rcpts) { | ||
375 | smtp_address_list_free( rcpts ); | ||
376 | } | ||
377 | return res; | ||
378 | } | ||
379 | |||
380 | /* this is a special fun */ | ||
381 | bool SMTPwrapper::flushOutbox() { | ||
382 | bool returnValue = true; | ||
383 | |||
384 | ; // odebug << "Sending the queue" << oendl; | ||
385 | if (!m_SmtpAccount) { | ||
386 | ; // odebug << "No smtp account given" << oendl; | ||
387 | return false; | ||
388 | } | ||
389 | |||
390 | bool reset_user_value = false; | ||
391 | QString localfolders = AbstractMail::defaultLocalfolder(); | ||
392 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | ||
393 | if (!wrap) { | ||
394 | ; // odebug << "memory error" << oendl; | ||
395 | return false; | ||
396 | } | ||
397 | QString oldPw, oldUser; | ||
398 | QValueList<RecMailP> mailsToSend; | ||
399 | QValueList<RecMailP> mailsToRemove; | ||
400 | QString mbox("Outgoing"); | ||
401 | wrap->listMessages(mbox,mailsToSend); | ||
402 | if (mailsToSend.count()==0) { | ||
403 | delete wrap; | ||
404 | ; // odebug << "No mails to send" << oendl; | ||
405 | return false; | ||
406 | } | ||
407 | |||
408 | oldPw = m_SmtpAccount->getPassword(); | ||
409 | oldUser = m_SmtpAccount->getUser(); | ||
410 | if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { | ||
411 | // get'em | ||
412 | QString user,pass; | ||
413 | LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); | ||
414 | login.show(); | ||
415 | if ( QDialog::Accepted == login.exec() ) { | ||
416 | // ok | ||
417 | user = login.getUser().latin1(); | ||
418 | pass = login.getPassword().latin1(); | ||
419 | reset_user_value = true; | ||
420 | m_SmtpAccount->setUser(user); | ||
421 | m_SmtpAccount->setPassword(pass); | ||
422 | } else { | ||
423 | return true; | ||
424 | } | ||
425 | } | ||
426 | |||
427 | |||
428 | sendProgress = new progressMailSend(); | ||
429 | sendProgress->show(); | ||
430 | sendProgress->setMaxMails(mailsToSend.count()); | ||
431 | |||
432 | while (mailsToSend.count()>0) { | ||
433 | if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) { | ||
434 | QMessageBox::critical(0,tr("Error sending mail"), | ||
435 | tr("Error sending queued mail - breaking")); | ||
436 | returnValue = false; | ||
437 | break; | ||
438 | } | ||
439 | mailsToRemove.append((*mailsToSend.begin())); | ||
440 | mailsToSend.remove(mailsToSend.begin()); | ||
441 | sendProgress->setCurrentMails(mailsToRemove.count()); | ||
442 | } | ||
443 | if (reset_user_value) { | ||
444 | m_SmtpAccount->setUser(oldUser); | ||
445 | m_SmtpAccount->setPassword(oldPw); | ||
446 | } | ||
447 | Config cfg( "mail" ); | ||
448 | cfg.setGroup( "Status" ); | ||
449 | m_queuedMail = 0; | ||
450 | cfg.writeEntry( "outgoing", m_queuedMail ); | ||
451 | emit queuedMails( m_queuedMail ); | ||
452 | sendProgress->hide(); | ||
453 | delete sendProgress; | ||
454 | sendProgress = 0; | ||
455 | wrap->deleteMails(mbox,mailsToRemove); | ||
456 | delete wrap; | ||
457 | return returnValue; | ||
458 | } | ||
diff --git a/kmicromail/libmailwrapper/smtpwrapper.h b/kmicromail/libmailwrapper/smtpwrapper.h new file mode 100644 index 0000000..6c5bbe8 --- a/dev/null +++ b/kmicromail/libmailwrapper/smtpwrapper.h | |||
@@ -0,0 +1,63 @@ | |||
1 | // -*- Mode: C++; -*- | ||
2 | #ifndef SMTPwrapper_H | ||
3 | #define SMTPwrapper_H | ||
4 | |||
5 | #include <qpe/applnk.h> | ||
6 | |||
7 | #include <qbitarray.h> | ||
8 | #include <qdatetime.h> | ||
9 | #include <libetpan/clist.h> | ||
10 | |||
11 | #include "settings.h" | ||
12 | #include "generatemail.h" | ||
13 | |||
14 | #include <opie2/osmartpointer.h> | ||
15 | |||
16 | class SMTPaccount; | ||
17 | class AbstractMail; | ||
18 | |||
19 | class SMTPwrapper : public Generatemail | ||
20 | { | ||
21 | Q_OBJECT | ||
22 | |||
23 | public: | ||
24 | SMTPwrapper(SMTPaccount * aSmtp); | ||
25 | virtual ~SMTPwrapper(); | ||
26 | void sendMail(const Opie::Core::OSmartPointer<Mail>& mail,bool later=false ); | ||
27 | bool flushOutbox(); | ||
28 | |||
29 | static progressMailSend*sendProgress; | ||
30 | |||
31 | signals: | ||
32 | void queuedMails( int ); | ||
33 | |||
34 | protected: | ||
35 | mailsmtp *m_smtp; | ||
36 | SMTPaccount * m_SmtpAccount; | ||
37 | |||
38 | void connect_server(); | ||
39 | void disc_server(); | ||
40 | int start_smtp_tls(); | ||
41 | |||
42 | |||
43 | void smtpSend( mailmime *mail,bool later); | ||
44 | |||
45 | static void storeMail(const char*mail, size_t length, const QString&box); | ||
46 | static QString mailsmtpError( int err ); | ||
47 | static void progress( size_t current, size_t maximum ); | ||
48 | |||
49 | int smtpSend(char*from,clist*rcpts,const char*data,size_t size); | ||
50 | |||
51 | void storeMail(mailmime*mail, const QString&box); | ||
52 | |||
53 | int sendQueuedMail(AbstractMail*wrap,const Opie::Core::OSmartPointer<RecMail>&which); | ||
54 | void storeFailedMail(const char*data,unsigned int size, const char*failuremessage); | ||
55 | |||
56 | int m_queuedMail; | ||
57 | |||
58 | protected slots: | ||
59 | void emitQCop( int queued ); | ||
60 | |||
61 | }; | ||
62 | |||
63 | #endif | ||
diff --git a/kmicromail/libmailwrapper/statusmail.cpp b/kmicromail/libmailwrapper/statusmail.cpp new file mode 100644 index 0000000..90c9233 --- a/dev/null +++ b/kmicromail/libmailwrapper/statusmail.cpp | |||
@@ -0,0 +1,94 @@ | |||
1 | #include "statusmail.h" | ||
2 | |||
3 | |||
4 | |||
5 | using namespace Opie::Core; | ||
6 | |||
7 | StatusMail::StatusMail(QList<Account>&list) | ||
8 | { | ||
9 | currentImapStat.message_count=0; | ||
10 | currentImapStat.message_unseen=0; | ||
11 | currentImapStat.message_recent=0; | ||
12 | lastPop3Stat = currentImapStat; | ||
13 | currentPop3Stat = currentImapStat; | ||
14 | connectionList.setAutoDelete(true); | ||
15 | connectionList.clear(); | ||
16 | initAccounts(list); | ||
17 | } | ||
18 | |||
19 | StatusMail::~StatusMail() | ||
20 | { | ||
21 | } | ||
22 | |||
23 | void StatusMail::initAccounts(QList<Account>&accounts) | ||
24 | { | ||
25 | |||
26 | Account *it; | ||
27 | folderStat currentStat; | ||
28 | AbstractMail * current = 0; | ||
29 | currentPop3Stat.message_count=0; | ||
30 | currentPop3Stat.message_recent=0; | ||
31 | currentPop3Stat.message_unseen=0; | ||
32 | for ( it = accounts.first(); it; it = accounts.next() ) { | ||
33 | if ( it->getType()==MAILLIB::A_IMAP && !it->getOffline() ) { | ||
34 | IMAPaccount*ima = static_cast<IMAPaccount *>(it); | ||
35 | current = AbstractMail::getWrapper(ima); | ||
36 | connectionList.append(current); | ||
37 | current->statusFolder(currentStat); | ||
38 | currentImapStat.message_count+=currentStat.message_unseen; | ||
39 | currentImapStat.message_count+=currentStat.message_recent; | ||
40 | currentImapStat.message_count+=currentStat.message_count; | ||
41 | } else if ( it->getType() == MAILLIB::A_POP3 && !it->getOffline() ) { | ||
42 | POP3account *pop3 = static_cast<POP3account *>(it); | ||
43 | current = AbstractMail::getWrapper(pop3); | ||
44 | connectionList.append(current); | ||
45 | current->statusFolder(currentStat); | ||
46 | currentPop3Stat.message_count+=currentStat.message_count; | ||
47 | } | ||
48 | current->logout(); | ||
49 | } | ||
50 | ; // << "Pop3 init count: " << currentPop3Stat.message_count << "" << oendl; | ||
51 | currentPop3Stat.message_recent = currentPop3Stat.message_unseen = 0; | ||
52 | lastPop3Stat.message_unseen = currentPop3Stat.message_unseen; | ||
53 | lastPop3Stat.message_recent = currentPop3Stat.message_recent; | ||
54 | lastPop3Stat.message_count = currentPop3Stat.message_count; | ||
55 | } | ||
56 | |||
57 | void StatusMail::reset_status() | ||
58 | { | ||
59 | lastPop3Stat = currentPop3Stat; | ||
60 | } | ||
61 | |||
62 | void StatusMail::check_current_stat(folderStat&targetStat) | ||
63 | { | ||
64 | AbstractMail*it = 0; | ||
65 | folderStat currentStat; | ||
66 | currentPop3Stat.message_recent = 0; | ||
67 | currentPop3Stat.message_count = 0; | ||
68 | currentPop3Stat.message_unseen = 0; | ||
69 | currentImapStat = currentPop3Stat; | ||
70 | for ( it = connectionList.first(); it; it = connectionList.next() ) { | ||
71 | it->statusFolder(currentStat); | ||
72 | it->logout(); | ||
73 | if (it->getType() == MAILLIB::A_IMAP) { | ||
74 | currentImapStat.message_unseen+=currentStat.message_unseen; | ||
75 | currentImapStat.message_recent+=currentStat.message_recent; | ||
76 | currentImapStat.message_count+=currentStat.message_count; | ||
77 | } else if (it->getType() == MAILLIB::A_POP3) { | ||
78 | currentPop3Stat.message_count+=currentStat.message_count; | ||
79 | ; // << "Pop3 count: " << currentPop3Stat.message_count << "" << oendl; | ||
80 | } | ||
81 | } | ||
82 | ; // << "Pop3 last: " << lastPop3Stat.message_count << "" << oendl; | ||
83 | if (currentPop3Stat.message_count > lastPop3Stat.message_count) { | ||
84 | currentPop3Stat.message_recent = currentPop3Stat.message_count - lastPop3Stat.message_count; | ||
85 | currentPop3Stat.message_unseen = currentPop3Stat.message_recent; | ||
86 | } else { | ||
87 | lastPop3Stat.message_count = currentPop3Stat.message_count; | ||
88 | currentPop3Stat.message_recent = currentPop3Stat.message_unseen = 0; | ||
89 | } | ||
90 | targetStat = currentImapStat; | ||
91 | targetStat.message_unseen+=currentPop3Stat.message_unseen; | ||
92 | targetStat.message_recent+=currentPop3Stat.message_recent; | ||
93 | targetStat.message_count+=currentPop3Stat.message_count; | ||
94 | } | ||
diff --git a/kmicromail/libmailwrapper/statusmail.h b/kmicromail/libmailwrapper/statusmail.h new file mode 100644 index 0000000..2637232 --- a/dev/null +++ b/kmicromail/libmailwrapper/statusmail.h | |||
@@ -0,0 +1,31 @@ | |||
1 | #ifndef __MAIL_STATUS_H | ||
2 | #define __MAIL_STATUS_H | ||
3 | |||
4 | #include "settings.h" | ||
5 | #include "abstractmail.h" | ||
6 | #include "mailtypes.h" | ||
7 | |||
8 | class StatusMail | ||
9 | { | ||
10 | public: | ||
11 | StatusMail(QList<Account>&list); | ||
12 | virtual ~StatusMail(); | ||
13 | |||
14 | /* this should be called if opiemail is starte or a mailbox touched - may be trough | ||
15 | a qcop signal or if tab on the taskbar applet*/ | ||
16 | virtual void reset_status(); | ||
17 | virtual void check_current_stat(folderStat&targetStat); | ||
18 | |||
19 | protected: | ||
20 | void initAccounts(QList<Account>&accounts); | ||
21 | /* this must be cause we have to calculate the recent for pop3*/ | ||
22 | folderStat currentImapStat; | ||
23 | /* currentPop3Stat is the sum of messages in POP3 accounts in CURRENT loop | ||
24 | the recent are calculated to the difference of the LAST loop */ | ||
25 | folderStat currentPop3Stat; | ||
26 | /* lastPop3Stat is the sum of messages in LAST loop */ | ||
27 | folderStat lastPop3Stat; | ||
28 | QList<AbstractMail> connectionList; | ||
29 | }; | ||
30 | |||
31 | #endif | ||
diff --git a/kmicromail/libmailwrapper/storemail.cpp b/kmicromail/libmailwrapper/storemail.cpp new file mode 100644 index 0000000..ed1d44a --- a/dev/null +++ b/kmicromail/libmailwrapper/storemail.cpp | |||
@@ -0,0 +1,90 @@ | |||
1 | #include "storemail.h" | ||
2 | #include "mailwrapper.h" | ||
3 | #include "settings.h" | ||
4 | #include "abstractmail.h" | ||
5 | |||
6 | #include <libetpan/libetpan.h> | ||
7 | #include <qstring.h> | ||
8 | |||
9 | #include <stdlib.h> | ||
10 | |||
11 | using namespace Opie::Core; | ||
12 | Storemail::Storemail(Account*aAccount,const QString&aFolder) | ||
13 | : Generatemail() | ||
14 | { | ||
15 | wrapper = 0; | ||
16 | m_Account = aAccount; | ||
17 | m_tfolder = aFolder; | ||
18 | wrapper = AbstractMail::getWrapper(m_Account); | ||
19 | if (wrapper) { | ||
20 | wrapper->createMbox(m_tfolder); | ||
21 | } | ||
22 | } | ||
23 | |||
24 | Storemail::Storemail(const QString&dir,const QString&aFolder) | ||
25 | : Generatemail() | ||
26 | { | ||
27 | wrapper = 0; | ||
28 | m_Account = 0; | ||
29 | m_tfolder = aFolder; | ||
30 | wrapper = AbstractMail::getWrapper(dir); | ||
31 | if (wrapper) { | ||
32 | wrapper->createMbox(m_tfolder); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | Storemail::Storemail(const QString&aFolder) | ||
37 | : Generatemail() | ||
38 | { | ||
39 | wrapper = 0; | ||
40 | m_Account = 0; | ||
41 | m_tfolder = aFolder; | ||
42 | wrapper = AbstractMail::getWrapper(AbstractMail::defaultLocalfolder()); | ||
43 | if (wrapper) { | ||
44 | wrapper->createMbox(m_tfolder); | ||
45 | } | ||
46 | } | ||
47 | |||
48 | Storemail::~Storemail() | ||
49 | { | ||
50 | } | ||
51 | |||
52 | int Storemail::storeMail(const Opie::Core::OSmartPointer<Mail>&mail) | ||
53 | { | ||
54 | if (!wrapper) return 0; | ||
55 | int ret = 1; | ||
56 | |||
57 | mailmime * mimeMail = 0; | ||
58 | mimeMail = createMimeMail(mail ); | ||
59 | if ( mimeMail == NULL ) { | ||
60 | qDebug("storeMail: error creating mime mail "); | ||
61 | return 0; | ||
62 | } | ||
63 | char *data; | ||
64 | size_t size; | ||
65 | data = 0; | ||
66 | |||
67 | mailmessage * msg = 0; | ||
68 | msg = mime_message_init(mimeMail); | ||
69 | mime_message_set_tmpdir(msg,getenv( "HOME" )); | ||
70 | int r = mailmessage_fetch(msg,&data,&size); | ||
71 | mime_message_detach_mime(msg); | ||
72 | mailmessage_free(msg); | ||
73 | msg = 0; | ||
74 | if (r != MAIL_NO_ERROR || !data) { | ||
75 | qDebug("Error fetching mime... "); | ||
76 | ret = 0; | ||
77 | } | ||
78 | |||
79 | if (ret) { | ||
80 | wrapper->storeMessage(data,size,m_tfolder); | ||
81 | } | ||
82 | |||
83 | if (data) { | ||
84 | free(data); | ||
85 | } | ||
86 | if (mimeMail) { | ||
87 | mailmime_free( mimeMail ); | ||
88 | } | ||
89 | return ret; | ||
90 | } | ||
diff --git a/kmicromail/libmailwrapper/storemail.h b/kmicromail/libmailwrapper/storemail.h new file mode 100644 index 0000000..4433de0 --- a/dev/null +++ b/kmicromail/libmailwrapper/storemail.h | |||
@@ -0,0 +1,29 @@ | |||
1 | #ifndef __STORE_MAIL_H | ||
2 | #define __STORE_MAIL_H | ||
3 | |||
4 | #include <qpe/applnk.h> | ||
5 | |||
6 | #include "generatemail.h" | ||
7 | |||
8 | class Account; | ||
9 | class Mail; | ||
10 | class AbstractMail; | ||
11 | |||
12 | class Storemail : public Generatemail | ||
13 | { | ||
14 | Q_OBJECT | ||
15 | public: | ||
16 | Storemail(Account*aAccount,const QString&aFolder); | ||
17 | Storemail(const QString&dir,const QString&aFolder); | ||
18 | Storemail(const QString&aFolder); | ||
19 | virtual ~Storemail(); | ||
20 | |||
21 | int storeMail(const Opie::Core::OSmartPointer<Mail>&mail); | ||
22 | |||
23 | protected: | ||
24 | Account* m_Account; | ||
25 | QString m_tfolder; | ||
26 | AbstractMail*wrapper; | ||
27 | }; | ||
28 | |||
29 | #endif | ||