Diffstat (limited to 'noncore/net/mail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.h | 9 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 124 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.h | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.cpp | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.h | 11 |
5 files changed, 134 insertions, 18 deletions
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h index 509b68e..b609aa7 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.h +++ b/noncore/net/mail/libmailwrapper/abstractmail.h | |||
@@ -19,24 +19,33 @@ public: | |||
19 | AbstractMail(){}; | 19 | AbstractMail(){}; |
20 | virtual ~AbstractMail(){} | 20 | virtual ~AbstractMail(){} |
21 | virtual QList<Folder>* listFolders()=0; | 21 | virtual QList<Folder>* listFolders()=0; |
22 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; | 22 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; |
23 | virtual RecBody fetchBody(const RecMail&mail)=0; | 23 | virtual RecBody fetchBody(const RecMail&mail)=0; |
24 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; | 24 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; |
25 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; | 25 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; |
26 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; | 26 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; |
27 | 27 | ||
28 | virtual void deleteMail(const RecMail&mail)=0; | 28 | virtual void deleteMail(const RecMail&mail)=0; |
29 | virtual void answeredMail(const RecMail&mail)=0; | 29 | virtual void answeredMail(const RecMail&mail)=0; |
30 | virtual void cleanMimeCache(){}; | 30 | virtual void cleanMimeCache(){}; |
31 | virtual int deleteAllMail(const Folder*){return 1;} | ||
32 | |||
33 | /* mail box methods */ | ||
34 | /* parameter is the box to create. | ||
35 | * if the implementing subclass has prefixes, | ||
36 | * them has to be appended automatic. | ||
37 | */ | ||
38 | virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false){return 0;} | ||
39 | virtual int deleteMbox(const Folder*){return 1;} | ||
31 | 40 | ||
32 | static AbstractMail* getWrapper(IMAPaccount *a); | 41 | static AbstractMail* getWrapper(IMAPaccount *a); |
33 | static AbstractMail* getWrapper(POP3account *a); | 42 | static AbstractMail* getWrapper(POP3account *a); |
34 | /* mbox only! */ | 43 | /* mbox only! */ |
35 | static AbstractMail* getWrapper(const QString&a); | 44 | static AbstractMail* getWrapper(const QString&a); |
36 | 45 | ||
37 | protected: | 46 | protected: |
38 | static encodedString*decode_String(const encodedString*text,const QString&enc); | 47 | static encodedString*decode_String(const encodedString*text,const QString&enc); |
39 | static QString convert_String(const char*text); | 48 | static QString convert_String(const char*text); |
40 | static QString gen_attachment_id(); | 49 | static QString gen_attachment_id(); |
41 | }; | 50 | }; |
42 | #endif | 51 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index ab20249..406c57c 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,16 +1,15 @@ | |||
1 | |||
2 | #include <stdlib.h> | 1 | #include <stdlib.h> |
3 | |||
4 | #include <libetpan/libetpan.h> | 2 | #include <libetpan/libetpan.h> |
3 | #include <qpe/global.h> | ||
5 | 4 | ||
6 | #include "imapwrapper.h" | 5 | #include "imapwrapper.h" |
7 | #include "mailtypes.h" | 6 | #include "mailtypes.h" |
8 | #include "logindialog.h" | 7 | #include "logindialog.h" |
9 | 8 | ||
10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 9 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
11 | : AbstractMail() | 10 | : AbstractMail() |
12 | { | 11 | { |
13 | account = a; | 12 | account = a; |
14 | m_imap = 0; | 13 | m_imap = 0; |
15 | } | 14 | } |
16 | 15 | ||
@@ -62,34 +61,34 @@ void IMAPwrapper::login() | |||
62 | 61 | ||
63 | m_imap = mailimap_new( 20, &imap_progress ); | 62 | m_imap = mailimap_new( 20, &imap_progress ); |
64 | /* connect */ | 63 | /* connect */ |
65 | if (account->getSSL()) { | 64 | if (account->getSSL()) { |
66 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 65 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
67 | } else { | 66 | } else { |
68 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 67 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
69 | } | 68 | } |
70 | 69 | ||
71 | if ( err != MAILIMAP_NO_ERROR && | 70 | if ( err != MAILIMAP_NO_ERROR && |
72 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 71 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
73 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 72 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
74 | qDebug("error connecting server: %s",m_imap->imap_response); | 73 | Global::statusMessage(tr("error connecting imap server: %1").arg(m_imap->imap_response)); |
75 | mailimap_free( m_imap ); | 74 | mailimap_free( m_imap ); |
76 | m_imap = 0; | 75 | m_imap = 0; |
77 | return; | 76 | return; |
78 | } | 77 | } |
79 | 78 | ||
80 | /* login */ | 79 | /* login */ |
81 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 80 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
82 | if ( err != MAILIMAP_NO_ERROR ) { | 81 | if ( err != MAILIMAP_NO_ERROR ) { |
83 | qDebug("error logging in imap: %s",m_imap->imap_response); | 82 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); |
84 | err = mailimap_close( m_imap ); | 83 | err = mailimap_close( m_imap ); |
85 | mailimap_free( m_imap ); | 84 | mailimap_free( m_imap ); |
86 | m_imap = 0; | 85 | m_imap = 0; |
87 | } | 86 | } |
88 | } | 87 | } |
89 | 88 | ||
90 | void IMAPwrapper::logout() | 89 | void IMAPwrapper::logout() |
91 | { | 90 | { |
92 | int err = MAILIMAP_NO_ERROR; | 91 | int err = MAILIMAP_NO_ERROR; |
93 | if (!m_imap) return; | 92 | if (!m_imap) return; |
94 | err = mailimap_logout( m_imap ); | 93 | err = mailimap_logout( m_imap ); |
95 | err = mailimap_close( m_imap ); | 94 | err = mailimap_close( m_imap ); |
@@ -106,33 +105,35 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | |||
106 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; | 105 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; |
107 | mailimap_fetch_type *fetchType = 0; | 106 | mailimap_fetch_type *fetchType = 0; |
108 | mailimap_set *set = 0; | 107 | mailimap_set *set = 0; |
109 | 108 | ||
110 | mb = mailbox.latin1(); | 109 | mb = mailbox.latin1(); |
111 | login(); | 110 | login(); |
112 | if (!m_imap) { | 111 | if (!m_imap) { |
113 | return; | 112 | return; |
114 | } | 113 | } |
115 | /* select mailbox READONLY for operations */ | 114 | /* select mailbox READONLY for operations */ |
116 | err = mailimap_examine( m_imap, (char*)mb); | 115 | err = mailimap_examine( m_imap, (char*)mb); |
117 | if ( err != MAILIMAP_NO_ERROR ) { | 116 | if ( err != MAILIMAP_NO_ERROR ) { |
118 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 117 | Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); |
119 | return; | 118 | return; |
120 | } | 119 | } |
121 | 120 | ||
122 | int last = m_imap->imap_selection_info->sel_exists; | 121 | int last = m_imap->imap_selection_info->sel_exists; |
123 | 122 | ||
124 | if (last == 0) { | 123 | if (last == 0) { |
125 | qDebug("mailbox has no mails"); | 124 | Global::statusMessage(tr("Mailbox has no mails")); |
126 | return; | 125 | return; |
126 | } else { | ||
127 | Global::statusMessage(tr("Mailbox has %1 mails").arg(last)); | ||
127 | } | 128 | } |
128 | 129 | ||
129 | /* the range has to start at 1!!! not with 0!!!! */ | 130 | /* the range has to start at 1!!! not with 0!!!! */ |
130 | set = mailimap_set_new_interval( 1, last ); | 131 | set = mailimap_set_new_interval( 1, last ); |
131 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 132 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
132 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 133 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
133 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 134 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
134 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 135 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
135 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 136 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
136 | 137 | ||
137 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 138 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
138 | mailimap_set_free( set ); | 139 | mailimap_set_free( set ); |
@@ -146,96 +147,113 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | |||
146 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 147 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
147 | ++i; | 148 | ++i; |
148 | msg_att = (mailimap_msg_att*)current->data; | 149 | msg_att = (mailimap_msg_att*)current->data; |
149 | RecMail*m = parse_list_result(msg_att); | 150 | RecMail*m = parse_list_result(msg_att); |
150 | if (m) { | 151 | if (m) { |
151 | m->setNumber(i); | 152 | m->setNumber(i); |
152 | m->setMbox(mailbox); | 153 | m->setMbox(mailbox); |
153 | m->setWrapper(this); | 154 | m->setWrapper(this); |
154 | target.append(m); | 155 | target.append(m); |
155 | } | 156 | } |
156 | } | 157 | } |
157 | } else { | 158 | } else { |
158 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 159 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); |
159 | } | 160 | } |
160 | if (result) mailimap_fetch_list_free(result); | 161 | if (result) mailimap_fetch_list_free(result); |
161 | } | 162 | } |
162 | 163 | ||
163 | QList<Folder>* IMAPwrapper::listFolders() | 164 | QList<Folder>* IMAPwrapper::listFolders() |
164 | { | 165 | { |
165 | const char *path, *mask; | 166 | const char *path, *mask; |
166 | int err = MAILIMAP_NO_ERROR; | 167 | int err = MAILIMAP_NO_ERROR; |
167 | clist *result = 0; | 168 | clist *result = 0; |
168 | clistcell *current = 0; | 169 | clistcell *current = 0; |
170 | clistcell*cur_flag = 0; | ||
171 | mailimap_mbx_list_flags*bflags = 0; | ||
169 | 172 | ||
170 | QList<Folder> * folders = new QList<Folder>(); | 173 | QList<Folder> * folders = new QList<Folder>(); |
171 | folders->setAutoDelete( false ); | 174 | folders->setAutoDelete( false ); |
172 | login(); | 175 | login(); |
173 | if (!m_imap) { | 176 | if (!m_imap) { |
174 | return folders; | 177 | return folders; |
175 | } | 178 | } |
176 | 179 | ||
177 | /* | 180 | /* |
178 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 181 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
179 | * We must not forget to filter them out in next loop! | 182 | * We must not forget to filter them out in next loop! |
180 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 183 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
181 | */ | 184 | */ |
182 | QString temp; | 185 | QString temp; |
183 | mask = "INBOX" ; | 186 | mask = "INBOX" ; |
184 | mailimap_mailbox_list *list; | 187 | mailimap_mailbox_list *list; |
185 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 188 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
186 | QString del; | 189 | QString del; |
190 | bool selectable = true; | ||
191 | bool no_inferiors = false; | ||
187 | if ( err == MAILIMAP_NO_ERROR ) { | 192 | if ( err == MAILIMAP_NO_ERROR ) { |
188 | current = result->first; | 193 | current = result->first; |
189 | for ( int i = result->count; i > 0; i-- ) { | 194 | for ( int i = result->count; i > 0; i-- ) { |
190 | list = (mailimap_mailbox_list *) current->data; | 195 | list = (mailimap_mailbox_list *) current->data; |
191 | // it is better use the deep copy mechanism of qt itself | 196 | // it is better use the deep copy mechanism of qt itself |
192 | // instead of using strdup! | 197 | // instead of using strdup! |
193 | temp = list->mb_name; | 198 | temp = list->mb_name; |
194 | del = list->mb_delimiter; | 199 | del = list->mb_delimiter; |
195 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); | ||
196 | current = current->next; | 200 | current = current->next; |
201 | if ( (bflags = list->mb_flag) ) { | ||
202 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | ||
203 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | ||
204 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | ||
205 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | ||
206 | no_inferiors = true; | ||
207 | } | ||
208 | } | ||
209 | } | ||
210 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | ||
197 | } | 211 | } |
198 | } else { | 212 | } else { |
199 | qDebug("error fetching folders: %s",m_imap->imap_response); | 213 | qDebug("error fetching folders: %s",m_imap->imap_response); |
200 | } | 214 | } |
201 | mailimap_list_result_free( result ); | 215 | mailimap_list_result_free( result ); |
202 | 216 | ||
203 | /* | 217 | /* |
204 | * second stage - get the other then inbox folders | 218 | * second stage - get the other then inbox folders |
205 | */ | 219 | */ |
206 | mask = "*" ; | 220 | mask = "*" ; |
207 | path = account->getPrefix().latin1(); | 221 | path = account->getPrefix().latin1(); |
208 | if (!path) path = ""; | 222 | if (!path) path = ""; |
209 | qDebug(path); | 223 | qDebug(path); |
210 | bool selectable = true; | ||
211 | mailimap_mbx_list_flags*bflags; | ||
212 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 224 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
213 | if ( err == MAILIMAP_NO_ERROR ) { | 225 | if ( err == MAILIMAP_NO_ERROR ) { |
214 | current = result->first; | 226 | current = result->first; |
215 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 227 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
228 | no_inferiors = false; | ||
216 | list = (mailimap_mailbox_list *) current->data; | 229 | list = (mailimap_mailbox_list *) current->data; |
217 | // it is better use the deep copy mechanism of qt itself | 230 | // it is better use the deep copy mechanism of qt itself |
218 | // instead of using strdup! | 231 | // instead of using strdup! |
219 | temp = list->mb_name; | 232 | temp = list->mb_name; |
220 | if (temp.lower()=="inbox") | 233 | if (temp.lower()=="inbox") |
221 | continue; | 234 | continue; |
222 | if (temp.lower()==account->getPrefix().lower()) | 235 | if (temp.lower()==account->getPrefix().lower()) |
223 | continue; | 236 | continue; |
224 | if ( (bflags = list->mb_flag) ) { | 237 | if ( (bflags = list->mb_flag) ) { |
225 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 238 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
226 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 239 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
240 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | ||
241 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | ||
242 | no_inferiors = true; | ||
243 | } | ||
244 | } | ||
227 | } | 245 | } |
228 | del = list->mb_delimiter; | 246 | del = list->mb_delimiter; |
229 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); | 247 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
230 | } | 248 | } |
231 | } else { | 249 | } else { |
232 | qDebug("error fetching folders %s",m_imap->imap_response); | 250 | qDebug("error fetching folders %s",m_imap->imap_response); |
233 | } | 251 | } |
234 | if (result) mailimap_list_result_free( result ); | 252 | if (result) mailimap_list_result_free( result ); |
235 | return folders; | 253 | return folders; |
236 | } | 254 | } |
237 | 255 | ||
238 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 256 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
239 | { | 257 | { |
240 | RecMail * m = 0; | 258 | RecMail * m = 0; |
241 | mailimap_msg_att_item *item=0; | 259 | mailimap_msg_att_item *item=0; |
@@ -809,12 +827,96 @@ QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | |||
809 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) | 827 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) |
810 | { | 828 | { |
811 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); | 829 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); |
812 | encodedString*r = decode_String(res,part.Encoding()); | 830 | encodedString*r = decode_String(res,part.Encoding()); |
813 | delete res; | 831 | delete res; |
814 | return r; | 832 | return r; |
815 | } | 833 | } |
816 | 834 | ||
817 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) | 835 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) |
818 | { | 836 | { |
819 | return fetchRawPart(mail,part.Positionlist(),false); | 837 | return fetchRawPart(mail,part.Positionlist(),false); |
820 | } | 838 | } |
839 | |||
840 | int IMAPwrapper::deleteAllMail(const Folder*folder) | ||
841 | { | ||
842 | login(); | ||
843 | if (!m_imap) { | ||
844 | return 0; | ||
845 | } | ||
846 | mailimap_flag_list*flist; | ||
847 | mailimap_set *set; | ||
848 | mailimap_store_att_flags * store_flags; | ||
849 | int err = mailimap_select( m_imap, folder->getName().latin1()); | ||
850 | if ( err != MAILIMAP_NO_ERROR ) { | ||
851 | Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); | ||
852 | return 0; | ||
853 | } | ||
854 | int last = m_imap->imap_selection_info->sel_exists; | ||
855 | if (last == 0) { | ||
856 | Global::statusMessage(tr("Mailbox has no mails!")); | ||
857 | return 0; | ||
858 | } | ||
859 | flist = mailimap_flag_list_new_empty(); | ||
860 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | ||
861 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | ||
862 | set = mailimap_set_new_interval( 1, last ); | ||
863 | err = mailimap_store(m_imap,set,store_flags); | ||
864 | mailimap_set_free( set ); | ||
865 | mailimap_store_att_flags_free(store_flags); | ||
866 | if (err != MAILIMAP_NO_ERROR) { | ||
867 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | ||
868 | return 0; | ||
869 | } | ||
870 | qDebug("deleting mail: %s",m_imap->imap_response); | ||
871 | /* should we realy do that at this moment? */ | ||
872 | err = mailimap_expunge(m_imap); | ||
873 | if (err != MAILIMAP_NO_ERROR) { | ||
874 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | ||
875 | return 0; | ||
876 | } | ||
877 | qDebug("Delete successfull %s",m_imap->imap_response); | ||
878 | return 1; | ||
879 | } | ||
880 | |||
881 | int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) | ||
882 | { | ||
883 | if (folder.length()==0) return 0; | ||
884 | login(); | ||
885 | if (!m_imap) {return 0;} | ||
886 | QString pre = account->getPrefix(); | ||
887 | if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { | ||
888 | pre+=delemiter; | ||
889 | } | ||
890 | if (parentfolder) { | ||
891 | pre += parentfolder->getDisplayName()+delemiter; | ||
892 | } | ||
893 | pre+=folder; | ||
894 | if (getsubfolder) { | ||
895 | if (delemiter.length()>0) { | ||
896 | pre+=delemiter; | ||
897 | } else { | ||
898 | Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); | ||
899 | return 0; | ||
900 | } | ||
901 | } | ||
902 | qDebug("Creating %s",pre.latin1()); | ||
903 | int res = mailimap_create(m_imap,pre.latin1()); | ||
904 | if (res != MAILIMAP_NO_ERROR) { | ||
905 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | ||
906 | return 0; | ||
907 | } | ||
908 | return 1; | ||
909 | } | ||
910 | |||
911 | int IMAPwrapper::deleteMbox(const Folder*folder) | ||
912 | { | ||
913 | if (!folder) return 0; | ||
914 | login(); | ||
915 | if (!m_imap) {return 0;} | ||
916 | int res = mailimap_delete(m_imap,folder->getName()); | ||
917 | if (res != MAILIMAP_NO_ERROR) { | ||
918 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | ||
919 | return 0; | ||
920 | } | ||
921 | return 1; | ||
922 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h index f046297..9b20288 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.h +++ b/noncore/net/mail/libmailwrapper/imapwrapper.h | |||
@@ -18,30 +18,34 @@ class encodedString; | |||
18 | 18 | ||
19 | class IMAPwrapper : public AbstractMail | 19 | class IMAPwrapper : public AbstractMail |
20 | { | 20 | { |
21 | Q_OBJECT | 21 | Q_OBJECT |
22 | public: | 22 | public: |
23 | IMAPwrapper( IMAPaccount *a ); | 23 | IMAPwrapper( IMAPaccount *a ); |
24 | virtual ~IMAPwrapper(); | 24 | virtual ~IMAPwrapper(); |
25 | virtual QList<Folder>* listFolders(); | 25 | virtual QList<Folder>* listFolders(); |
26 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); | 26 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); |
27 | 27 | ||
28 | virtual void deleteMail(const RecMail&mail); | 28 | virtual void deleteMail(const RecMail&mail); |
29 | virtual void answeredMail(const RecMail&mail); | 29 | virtual void answeredMail(const RecMail&mail); |
30 | virtual int deleteAllMail(const Folder*folder); | ||
30 | 31 | ||
31 | virtual RecBody fetchBody(const RecMail&mail); | 32 | virtual RecBody fetchBody(const RecMail&mail); |
32 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); | 33 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); |
33 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); | 34 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); |
34 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); | 35 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); |
35 | 36 | ||
37 | virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); | ||
38 | virtual int deleteMbox(const Folder*folder); | ||
39 | |||
36 | static void imap_progress( size_t current, size_t maximum ); | 40 | static void imap_progress( size_t current, size_t maximum ); |
37 | 41 | ||
38 | protected: | 42 | protected: |
39 | RecMail*parse_list_result(mailimap_msg_att*); | 43 | RecMail*parse_list_result(mailimap_msg_att*); |
40 | void login(); | 44 | void login(); |
41 | void logout(); | 45 | void logout(); |
42 | 46 | ||
43 | virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); | 47 | virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); |
44 | virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); | 48 | virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); |
45 | 49 | ||
46 | void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); | 50 | void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); |
47 | void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); | 51 | void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); |
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp index 6479783..9398823 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp | |||
@@ -19,26 +19,26 @@ Attachment::Attachment( DocLnk lnk ) | |||
19 | Folder::Folder(const QString&tmp_name, const QString&sep ) | 19 | Folder::Folder(const QString&tmp_name, const QString&sep ) |
20 | { | 20 | { |
21 | name = tmp_name; | 21 | name = tmp_name; |
22 | nameDisplay = name; | 22 | nameDisplay = name; |
23 | separator = sep; | 23 | separator = sep; |
24 | } | 24 | } |
25 | 25 | ||
26 | const QString& Folder::Separator()const | 26 | const QString& Folder::Separator()const |
27 | { | 27 | { |
28 | return separator; | 28 | return separator; |
29 | } | 29 | } |
30 | 30 | ||
31 | IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix ) | 31 | IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&prefix ) |
32 | : Folder( name,sep ),m_MaySelect(select) | 32 | : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf) |
33 | { | 33 | { |
34 | // Decode IMAP foldername | 34 | // Decode IMAP foldername |
35 | nameDisplay = IMAPFolder::decodeFolderName( name ); | 35 | nameDisplay = IMAPFolder::decodeFolderName( name ); |
36 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); | 36 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); |
37 | 37 | ||
38 | if (prefix.length()>0) { | 38 | if (prefix.length()>0) { |
39 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { | 39 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { |
40 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); | 40 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); |
41 | } | 41 | } |
42 | } | 42 | } |
43 | } | 43 | } |
44 | 44 | ||
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h index 8fd886f..a60777d 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.h +++ b/noncore/net/mail/libmailwrapper/mailwrapper.h | |||
@@ -60,32 +60,33 @@ private: | |||
60 | QList<Attachment> attList; | 60 | QList<Attachment> attList; |
61 | QString name, mail, to, cc, bcc, reply, subject, message; | 61 | QString name, mail, to, cc, bcc, reply, subject, message; |
62 | }; | 62 | }; |
63 | 63 | ||
64 | class Folder : public QObject | 64 | class Folder : public QObject |
65 | { | 65 | { |
66 | Q_OBJECT | 66 | Q_OBJECT |
67 | 67 | ||
68 | public: | 68 | public: |
69 | Folder( const QString&init_name,const QString&sep ); | 69 | Folder( const QString&init_name,const QString&sep ); |
70 | const QString&getDisplayName()const { return nameDisplay; } | 70 | const QString&getDisplayName()const { return nameDisplay; } |
71 | const QString&getName()const { return name; } | 71 | const QString&getName()const { return name; } |
72 | virtual bool may_select()const{return true;}; | 72 | virtual bool may_select()const{return true;} |
73 | virtual bool no_inferior()const{return true;} | ||
73 | const QString&Separator()const; | 74 | const QString&Separator()const; |
74 | 75 | ||
75 | protected: | 76 | protected: |
76 | QString nameDisplay, name, separator; | 77 | QString nameDisplay, name, separator; |
77 | 78 | ||
78 | }; | 79 | }; |
79 | 80 | ||
80 | class IMAPFolder : public Folder | 81 | class IMAPFolder : public Folder |
81 | { | 82 | { |
82 | public: | 83 | public: |
83 | IMAPFolder(const QString&name, const QString&sep, bool select=true,const QString&prefix="" ); | 84 | IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" ); |
84 | virtual bool may_select()const{return m_MaySelect;} | 85 | virtual bool may_select()const{return m_MaySelect;} |
86 | virtual bool no_inferior()const{return m_NoInferior;} | ||
85 | private: | 87 | private: |
86 | static QString decodeFolderName( const QString &name ); | 88 | static QString decodeFolderName( const QString &name ); |
87 | bool m_MaySelect; | 89 | bool m_MaySelect,m_NoInferior; |
88 | |||
89 | }; | 90 | }; |
90 | 91 | ||
91 | #endif | 92 | #endif |