author | alwin <alwin> | 2003-12-25 20:10:26 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-25 20:10:26 (UTC) |
commit | bde1302aed8a0e2506684eaae7c2d2d823de42c6 (patch) (unidiff) | |
tree | 24b16fc0f0c969df001615a00ac08a8bd4acd2df | |
parent | 67d7f0b0fc79377fba216e556785f6c630c437ad (diff) | |
download | opie-bde1302aed8a0e2506684eaae7c2d2d823de42c6.zip opie-bde1302aed8a0e2506684eaae7c2d2d823de42c6.tar.gz opie-bde1302aed8a0e2506684eaae7c2d2d823de42c6.tar.bz2 |
try to resolve timeouts via NOOP statement in login
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 9 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 9 |
2 files changed, 14 insertions, 4 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index 89ec7ab..ab20249 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -1,229 +1,234 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | 5 | ||
6 | #include "imapwrapper.h" | 6 | #include "imapwrapper.h" |
7 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
8 | #include "logindialog.h" | 8 | #include "logindialog.h" |
9 | 9 | ||
10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
11 | : AbstractMail() | 11 | : AbstractMail() |
12 | { | 12 | { |
13 | account = a; | 13 | account = a; |
14 | m_imap = 0; | 14 | m_imap = 0; |
15 | } | 15 | } |
16 | 16 | ||
17 | IMAPwrapper::~IMAPwrapper() | 17 | IMAPwrapper::~IMAPwrapper() |
18 | { | 18 | { |
19 | logout(); | 19 | logout(); |
20 | } | 20 | } |
21 | 21 | ||
22 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 22 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
23 | { | 23 | { |
24 | qDebug( "IMAP: %i of %i", current, maximum ); | 24 | qDebug( "IMAP: %i of %i", current, maximum ); |
25 | } | 25 | } |
26 | 26 | ||
27 | void IMAPwrapper::login() | 27 | void IMAPwrapper::login() |
28 | { | 28 | { |
29 | const char *server, *user, *pass; | 29 | const char *server, *user, *pass; |
30 | uint16_t port; | 30 | uint16_t port; |
31 | int err = MAILIMAP_NO_ERROR; | 31 | int err = MAILIMAP_NO_ERROR; |
32 | 32 | ||
33 | /* we are connected this moment */ | 33 | /* we are connected this moment */ |
34 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 34 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
35 | if (m_imap) { | 35 | if (m_imap) { |
36 | mailstream_flush(m_imap->imap_stream); | 36 | err = mailimap_noop(m_imap); |
37 | return; | 37 | if (err!=MAILIMAP_NO_ERROR) { |
38 | logout(); | ||
39 | } else { | ||
40 | mailstream_flush(m_imap->imap_stream); | ||
41 | return; | ||
42 | } | ||
38 | } | 43 | } |
39 | server = account->getServer().latin1(); | 44 | server = account->getServer().latin1(); |
40 | port = account->getPort().toUInt(); | 45 | port = account->getPort().toUInt(); |
41 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 46 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
42 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 47 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
43 | login.show(); | 48 | login.show(); |
44 | if ( QDialog::Accepted == login.exec() ) { | 49 | if ( QDialog::Accepted == login.exec() ) { |
45 | // ok | 50 | // ok |
46 | user = strdup( login.getUser().latin1() ); | 51 | user = strdup( login.getUser().latin1() ); |
47 | pass = strdup( login.getPassword().latin1() ); | 52 | pass = strdup( login.getPassword().latin1() ); |
48 | } else { | 53 | } else { |
49 | // cancel | 54 | // cancel |
50 | qDebug( "IMAP: Login canceled" ); | 55 | qDebug( "IMAP: Login canceled" ); |
51 | return; | 56 | return; |
52 | } | 57 | } |
53 | } else { | 58 | } else { |
54 | user = account->getUser().latin1(); | 59 | user = account->getUser().latin1(); |
55 | pass = account->getPassword().latin1(); | 60 | pass = account->getPassword().latin1(); |
56 | } | 61 | } |
57 | 62 | ||
58 | m_imap = mailimap_new( 20, &imap_progress ); | 63 | m_imap = mailimap_new( 20, &imap_progress ); |
59 | /* connect */ | 64 | /* connect */ |
60 | if (account->getSSL()) { | 65 | if (account->getSSL()) { |
61 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 66 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
62 | } else { | 67 | } else { |
63 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 68 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
64 | } | 69 | } |
65 | 70 | ||
66 | if ( err != MAILIMAP_NO_ERROR && | 71 | if ( err != MAILIMAP_NO_ERROR && |
67 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 72 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
68 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 73 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
69 | qDebug("error connecting server: %s",m_imap->imap_response); | 74 | qDebug("error connecting server: %s",m_imap->imap_response); |
70 | mailimap_free( m_imap ); | 75 | mailimap_free( m_imap ); |
71 | m_imap = 0; | 76 | m_imap = 0; |
72 | return; | 77 | return; |
73 | } | 78 | } |
74 | 79 | ||
75 | /* login */ | 80 | /* login */ |
76 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 81 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
77 | if ( err != MAILIMAP_NO_ERROR ) { | 82 | if ( err != MAILIMAP_NO_ERROR ) { |
78 | qDebug("error logging in imap: %s",m_imap->imap_response); | 83 | qDebug("error logging in imap: %s",m_imap->imap_response); |
79 | err = mailimap_close( m_imap ); | 84 | err = mailimap_close( m_imap ); |
80 | mailimap_free( m_imap ); | 85 | mailimap_free( m_imap ); |
81 | m_imap = 0; | 86 | m_imap = 0; |
82 | } | 87 | } |
83 | } | 88 | } |
84 | 89 | ||
85 | void IMAPwrapper::logout() | 90 | void IMAPwrapper::logout() |
86 | { | 91 | { |
87 | int err = MAILIMAP_NO_ERROR; | 92 | int err = MAILIMAP_NO_ERROR; |
88 | if (!m_imap) return; | 93 | if (!m_imap) return; |
89 | err = mailimap_logout( m_imap ); | 94 | err = mailimap_logout( m_imap ); |
90 | err = mailimap_close( m_imap ); | 95 | err = mailimap_close( m_imap ); |
91 | mailimap_free( m_imap ); | 96 | mailimap_free( m_imap ); |
92 | m_imap = 0; | 97 | m_imap = 0; |
93 | } | 98 | } |
94 | 99 | ||
95 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 100 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
96 | { | 101 | { |
97 | const char *mb = 0; | 102 | const char *mb = 0; |
98 | int err = MAILIMAP_NO_ERROR; | 103 | int err = MAILIMAP_NO_ERROR; |
99 | clist *result = 0; | 104 | clist *result = 0; |
100 | clistcell *current; | 105 | clistcell *current; |
101 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; | 106 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; |
102 | mailimap_fetch_type *fetchType = 0; | 107 | mailimap_fetch_type *fetchType = 0; |
103 | mailimap_set *set = 0; | 108 | mailimap_set *set = 0; |
104 | 109 | ||
105 | mb = mailbox.latin1(); | 110 | mb = mailbox.latin1(); |
106 | login(); | 111 | login(); |
107 | if (!m_imap) { | 112 | if (!m_imap) { |
108 | return; | 113 | return; |
109 | } | 114 | } |
110 | /* select mailbox READONLY for operations */ | 115 | /* select mailbox READONLY for operations */ |
111 | err = mailimap_examine( m_imap, (char*)mb); | 116 | err = mailimap_examine( m_imap, (char*)mb); |
112 | if ( err != MAILIMAP_NO_ERROR ) { | 117 | if ( err != MAILIMAP_NO_ERROR ) { |
113 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 118 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
114 | return; | 119 | return; |
115 | } | 120 | } |
116 | 121 | ||
117 | int last = m_imap->imap_selection_info->sel_exists; | 122 | int last = m_imap->imap_selection_info->sel_exists; |
118 | 123 | ||
119 | if (last == 0) { | 124 | if (last == 0) { |
120 | qDebug("mailbox has no mails"); | 125 | qDebug("mailbox has no mails"); |
121 | return; | 126 | return; |
122 | } | 127 | } |
123 | 128 | ||
124 | /* the range has to start at 1!!! not with 0!!!! */ | 129 | /* the range has to start at 1!!! not with 0!!!! */ |
125 | set = mailimap_set_new_interval( 1, last ); | 130 | set = mailimap_set_new_interval( 1, last ); |
126 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 131 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
127 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 132 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
128 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 133 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
129 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 134 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
130 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 135 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
131 | 136 | ||
132 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 137 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
133 | mailimap_set_free( set ); | 138 | mailimap_set_free( set ); |
134 | mailimap_fetch_type_free( fetchType ); | 139 | mailimap_fetch_type_free( fetchType ); |
135 | 140 | ||
136 | QString date,subject,from; | 141 | QString date,subject,from; |
137 | 142 | ||
138 | if ( err == MAILIMAP_NO_ERROR ) { | 143 | if ( err == MAILIMAP_NO_ERROR ) { |
139 | mailimap_msg_att * msg_att; | 144 | mailimap_msg_att * msg_att; |
140 | int i = 0; | 145 | int i = 0; |
141 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 146 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
142 | ++i; | 147 | ++i; |
143 | msg_att = (mailimap_msg_att*)current->data; | 148 | msg_att = (mailimap_msg_att*)current->data; |
144 | RecMail*m = parse_list_result(msg_att); | 149 | RecMail*m = parse_list_result(msg_att); |
145 | if (m) { | 150 | if (m) { |
146 | m->setNumber(i); | 151 | m->setNumber(i); |
147 | m->setMbox(mailbox); | 152 | m->setMbox(mailbox); |
148 | m->setWrapper(this); | 153 | m->setWrapper(this); |
149 | target.append(m); | 154 | target.append(m); |
150 | } | 155 | } |
151 | } | 156 | } |
152 | } else { | 157 | } else { |
153 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 158 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
154 | } | 159 | } |
155 | if (result) mailimap_fetch_list_free(result); | 160 | if (result) mailimap_fetch_list_free(result); |
156 | } | 161 | } |
157 | 162 | ||
158 | QList<Folder>* IMAPwrapper::listFolders() | 163 | QList<Folder>* IMAPwrapper::listFolders() |
159 | { | 164 | { |
160 | const char *path, *mask; | 165 | const char *path, *mask; |
161 | int err = MAILIMAP_NO_ERROR; | 166 | int err = MAILIMAP_NO_ERROR; |
162 | clist *result = 0; | 167 | clist *result = 0; |
163 | clistcell *current = 0; | 168 | clistcell *current = 0; |
164 | 169 | ||
165 | QList<Folder> * folders = new QList<Folder>(); | 170 | QList<Folder> * folders = new QList<Folder>(); |
166 | folders->setAutoDelete( false ); | 171 | folders->setAutoDelete( false ); |
167 | login(); | 172 | login(); |
168 | if (!m_imap) { | 173 | if (!m_imap) { |
169 | return folders; | 174 | return folders; |
170 | } | 175 | } |
171 | 176 | ||
172 | /* | 177 | /* |
173 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 178 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
174 | * We must not forget to filter them out in next loop! | 179 | * We must not forget to filter them out in next loop! |
175 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 180 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
176 | */ | 181 | */ |
177 | QString temp; | 182 | QString temp; |
178 | mask = "INBOX" ; | 183 | mask = "INBOX" ; |
179 | mailimap_mailbox_list *list; | 184 | mailimap_mailbox_list *list; |
180 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 185 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
181 | QString del; | 186 | QString del; |
182 | if ( err == MAILIMAP_NO_ERROR ) { | 187 | if ( err == MAILIMAP_NO_ERROR ) { |
183 | current = result->first; | 188 | current = result->first; |
184 | for ( int i = result->count; i > 0; i-- ) { | 189 | for ( int i = result->count; i > 0; i-- ) { |
185 | list = (mailimap_mailbox_list *) current->data; | 190 | list = (mailimap_mailbox_list *) current->data; |
186 | // it is better use the deep copy mechanism of qt itself | 191 | // it is better use the deep copy mechanism of qt itself |
187 | // instead of using strdup! | 192 | // instead of using strdup! |
188 | temp = list->mb_name; | 193 | temp = list->mb_name; |
189 | del = list->mb_delimiter; | 194 | del = list->mb_delimiter; |
190 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); | 195 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); |
191 | current = current->next; | 196 | current = current->next; |
192 | } | 197 | } |
193 | } else { | 198 | } else { |
194 | qDebug("error fetching folders: %s",m_imap->imap_response); | 199 | qDebug("error fetching folders: %s",m_imap->imap_response); |
195 | } | 200 | } |
196 | mailimap_list_result_free( result ); | 201 | mailimap_list_result_free( result ); |
197 | 202 | ||
198 | /* | 203 | /* |
199 | * second stage - get the other then inbox folders | 204 | * second stage - get the other then inbox folders |
200 | */ | 205 | */ |
201 | mask = "*" ; | 206 | mask = "*" ; |
202 | path = account->getPrefix().latin1(); | 207 | path = account->getPrefix().latin1(); |
203 | if (!path) path = ""; | 208 | if (!path) path = ""; |
204 | qDebug(path); | 209 | qDebug(path); |
205 | bool selectable = true; | 210 | bool selectable = true; |
206 | mailimap_mbx_list_flags*bflags; | 211 | mailimap_mbx_list_flags*bflags; |
207 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 212 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
208 | if ( err == MAILIMAP_NO_ERROR ) { | 213 | if ( err == MAILIMAP_NO_ERROR ) { |
209 | current = result->first; | 214 | current = result->first; |
210 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 215 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
211 | list = (mailimap_mailbox_list *) current->data; | 216 | list = (mailimap_mailbox_list *) current->data; |
212 | // it is better use the deep copy mechanism of qt itself | 217 | // it is better use the deep copy mechanism of qt itself |
213 | // instead of using strdup! | 218 | // instead of using strdup! |
214 | temp = list->mb_name; | 219 | temp = list->mb_name; |
215 | if (temp.lower()=="inbox") | 220 | if (temp.lower()=="inbox") |
216 | continue; | 221 | continue; |
217 | if (temp.lower()==account->getPrefix().lower()) | 222 | if (temp.lower()==account->getPrefix().lower()) |
218 | continue; | 223 | continue; |
219 | if ( (bflags = list->mb_flag) ) { | 224 | if ( (bflags = list->mb_flag) ) { |
220 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 225 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
221 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 226 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
222 | } | 227 | } |
223 | del = list->mb_delimiter; | 228 | del = list->mb_delimiter; |
224 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); | 229 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); |
225 | } | 230 | } |
226 | } else { | 231 | } else { |
227 | qDebug("error fetching folders %s",m_imap->imap_response); | 232 | qDebug("error fetching folders %s",m_imap->imap_response); |
228 | } | 233 | } |
229 | if (result) mailimap_list_result_free( result ); | 234 | if (result) mailimap_list_result_free( result ); |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 89ec7ab..ab20249 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,229 +1,234 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | 5 | ||
6 | #include "imapwrapper.h" | 6 | #include "imapwrapper.h" |
7 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
8 | #include "logindialog.h" | 8 | #include "logindialog.h" |
9 | 9 | ||
10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
11 | : AbstractMail() | 11 | : AbstractMail() |
12 | { | 12 | { |
13 | account = a; | 13 | account = a; |
14 | m_imap = 0; | 14 | m_imap = 0; |
15 | } | 15 | } |
16 | 16 | ||
17 | IMAPwrapper::~IMAPwrapper() | 17 | IMAPwrapper::~IMAPwrapper() |
18 | { | 18 | { |
19 | logout(); | 19 | logout(); |
20 | } | 20 | } |
21 | 21 | ||
22 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 22 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
23 | { | 23 | { |
24 | qDebug( "IMAP: %i of %i", current, maximum ); | 24 | qDebug( "IMAP: %i of %i", current, maximum ); |
25 | } | 25 | } |
26 | 26 | ||
27 | void IMAPwrapper::login() | 27 | void IMAPwrapper::login() |
28 | { | 28 | { |
29 | const char *server, *user, *pass; | 29 | const char *server, *user, *pass; |
30 | uint16_t port; | 30 | uint16_t port; |
31 | int err = MAILIMAP_NO_ERROR; | 31 | int err = MAILIMAP_NO_ERROR; |
32 | 32 | ||
33 | /* we are connected this moment */ | 33 | /* we are connected this moment */ |
34 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 34 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
35 | if (m_imap) { | 35 | if (m_imap) { |
36 | mailstream_flush(m_imap->imap_stream); | 36 | err = mailimap_noop(m_imap); |
37 | return; | 37 | if (err!=MAILIMAP_NO_ERROR) { |
38 | logout(); | ||
39 | } else { | ||
40 | mailstream_flush(m_imap->imap_stream); | ||
41 | return; | ||
42 | } | ||
38 | } | 43 | } |
39 | server = account->getServer().latin1(); | 44 | server = account->getServer().latin1(); |
40 | port = account->getPort().toUInt(); | 45 | port = account->getPort().toUInt(); |
41 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 46 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
42 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 47 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
43 | login.show(); | 48 | login.show(); |
44 | if ( QDialog::Accepted == login.exec() ) { | 49 | if ( QDialog::Accepted == login.exec() ) { |
45 | // ok | 50 | // ok |
46 | user = strdup( login.getUser().latin1() ); | 51 | user = strdup( login.getUser().latin1() ); |
47 | pass = strdup( login.getPassword().latin1() ); | 52 | pass = strdup( login.getPassword().latin1() ); |
48 | } else { | 53 | } else { |
49 | // cancel | 54 | // cancel |
50 | qDebug( "IMAP: Login canceled" ); | 55 | qDebug( "IMAP: Login canceled" ); |
51 | return; | 56 | return; |
52 | } | 57 | } |
53 | } else { | 58 | } else { |
54 | user = account->getUser().latin1(); | 59 | user = account->getUser().latin1(); |
55 | pass = account->getPassword().latin1(); | 60 | pass = account->getPassword().latin1(); |
56 | } | 61 | } |
57 | 62 | ||
58 | m_imap = mailimap_new( 20, &imap_progress ); | 63 | m_imap = mailimap_new( 20, &imap_progress ); |
59 | /* connect */ | 64 | /* connect */ |
60 | if (account->getSSL()) { | 65 | if (account->getSSL()) { |
61 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 66 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
62 | } else { | 67 | } else { |
63 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 68 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
64 | } | 69 | } |
65 | 70 | ||
66 | if ( err != MAILIMAP_NO_ERROR && | 71 | if ( err != MAILIMAP_NO_ERROR && |
67 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 72 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
68 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 73 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
69 | qDebug("error connecting server: %s",m_imap->imap_response); | 74 | qDebug("error connecting server: %s",m_imap->imap_response); |
70 | mailimap_free( m_imap ); | 75 | mailimap_free( m_imap ); |
71 | m_imap = 0; | 76 | m_imap = 0; |
72 | return; | 77 | return; |
73 | } | 78 | } |
74 | 79 | ||
75 | /* login */ | 80 | /* login */ |
76 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 81 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
77 | if ( err != MAILIMAP_NO_ERROR ) { | 82 | if ( err != MAILIMAP_NO_ERROR ) { |
78 | qDebug("error logging in imap: %s",m_imap->imap_response); | 83 | qDebug("error logging in imap: %s",m_imap->imap_response); |
79 | err = mailimap_close( m_imap ); | 84 | err = mailimap_close( m_imap ); |
80 | mailimap_free( m_imap ); | 85 | mailimap_free( m_imap ); |
81 | m_imap = 0; | 86 | m_imap = 0; |
82 | } | 87 | } |
83 | } | 88 | } |
84 | 89 | ||
85 | void IMAPwrapper::logout() | 90 | void IMAPwrapper::logout() |
86 | { | 91 | { |
87 | int err = MAILIMAP_NO_ERROR; | 92 | int err = MAILIMAP_NO_ERROR; |
88 | if (!m_imap) return; | 93 | if (!m_imap) return; |
89 | err = mailimap_logout( m_imap ); | 94 | err = mailimap_logout( m_imap ); |
90 | err = mailimap_close( m_imap ); | 95 | err = mailimap_close( m_imap ); |
91 | mailimap_free( m_imap ); | 96 | mailimap_free( m_imap ); |
92 | m_imap = 0; | 97 | m_imap = 0; |
93 | } | 98 | } |
94 | 99 | ||
95 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 100 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
96 | { | 101 | { |
97 | const char *mb = 0; | 102 | const char *mb = 0; |
98 | int err = MAILIMAP_NO_ERROR; | 103 | int err = MAILIMAP_NO_ERROR; |
99 | clist *result = 0; | 104 | clist *result = 0; |
100 | clistcell *current; | 105 | clistcell *current; |
101 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; | 106 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; |
102 | mailimap_fetch_type *fetchType = 0; | 107 | mailimap_fetch_type *fetchType = 0; |
103 | mailimap_set *set = 0; | 108 | mailimap_set *set = 0; |
104 | 109 | ||
105 | mb = mailbox.latin1(); | 110 | mb = mailbox.latin1(); |
106 | login(); | 111 | login(); |
107 | if (!m_imap) { | 112 | if (!m_imap) { |
108 | return; | 113 | return; |
109 | } | 114 | } |
110 | /* select mailbox READONLY for operations */ | 115 | /* select mailbox READONLY for operations */ |
111 | err = mailimap_examine( m_imap, (char*)mb); | 116 | err = mailimap_examine( m_imap, (char*)mb); |
112 | if ( err != MAILIMAP_NO_ERROR ) { | 117 | if ( err != MAILIMAP_NO_ERROR ) { |
113 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 118 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
114 | return; | 119 | return; |
115 | } | 120 | } |
116 | 121 | ||
117 | int last = m_imap->imap_selection_info->sel_exists; | 122 | int last = m_imap->imap_selection_info->sel_exists; |
118 | 123 | ||
119 | if (last == 0) { | 124 | if (last == 0) { |
120 | qDebug("mailbox has no mails"); | 125 | qDebug("mailbox has no mails"); |
121 | return; | 126 | return; |
122 | } | 127 | } |
123 | 128 | ||
124 | /* the range has to start at 1!!! not with 0!!!! */ | 129 | /* the range has to start at 1!!! not with 0!!!! */ |
125 | set = mailimap_set_new_interval( 1, last ); | 130 | set = mailimap_set_new_interval( 1, last ); |
126 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 131 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
127 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 132 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
128 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 133 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
129 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 134 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
130 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 135 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
131 | 136 | ||
132 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 137 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
133 | mailimap_set_free( set ); | 138 | mailimap_set_free( set ); |
134 | mailimap_fetch_type_free( fetchType ); | 139 | mailimap_fetch_type_free( fetchType ); |
135 | 140 | ||
136 | QString date,subject,from; | 141 | QString date,subject,from; |
137 | 142 | ||
138 | if ( err == MAILIMAP_NO_ERROR ) { | 143 | if ( err == MAILIMAP_NO_ERROR ) { |
139 | mailimap_msg_att * msg_att; | 144 | mailimap_msg_att * msg_att; |
140 | int i = 0; | 145 | int i = 0; |
141 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 146 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
142 | ++i; | 147 | ++i; |
143 | msg_att = (mailimap_msg_att*)current->data; | 148 | msg_att = (mailimap_msg_att*)current->data; |
144 | RecMail*m = parse_list_result(msg_att); | 149 | RecMail*m = parse_list_result(msg_att); |
145 | if (m) { | 150 | if (m) { |
146 | m->setNumber(i); | 151 | m->setNumber(i); |
147 | m->setMbox(mailbox); | 152 | m->setMbox(mailbox); |
148 | m->setWrapper(this); | 153 | m->setWrapper(this); |
149 | target.append(m); | 154 | target.append(m); |
150 | } | 155 | } |
151 | } | 156 | } |
152 | } else { | 157 | } else { |
153 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 158 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
154 | } | 159 | } |
155 | if (result) mailimap_fetch_list_free(result); | 160 | if (result) mailimap_fetch_list_free(result); |
156 | } | 161 | } |
157 | 162 | ||
158 | QList<Folder>* IMAPwrapper::listFolders() | 163 | QList<Folder>* IMAPwrapper::listFolders() |
159 | { | 164 | { |
160 | const char *path, *mask; | 165 | const char *path, *mask; |
161 | int err = MAILIMAP_NO_ERROR; | 166 | int err = MAILIMAP_NO_ERROR; |
162 | clist *result = 0; | 167 | clist *result = 0; |
163 | clistcell *current = 0; | 168 | clistcell *current = 0; |
164 | 169 | ||
165 | QList<Folder> * folders = new QList<Folder>(); | 170 | QList<Folder> * folders = new QList<Folder>(); |
166 | folders->setAutoDelete( false ); | 171 | folders->setAutoDelete( false ); |
167 | login(); | 172 | login(); |
168 | if (!m_imap) { | 173 | if (!m_imap) { |
169 | return folders; | 174 | return folders; |
170 | } | 175 | } |
171 | 176 | ||
172 | /* | 177 | /* |
173 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 178 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
174 | * We must not forget to filter them out in next loop! | 179 | * We must not forget to filter them out in next loop! |
175 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 180 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
176 | */ | 181 | */ |
177 | QString temp; | 182 | QString temp; |
178 | mask = "INBOX" ; | 183 | mask = "INBOX" ; |
179 | mailimap_mailbox_list *list; | 184 | mailimap_mailbox_list *list; |
180 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 185 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
181 | QString del; | 186 | QString del; |
182 | if ( err == MAILIMAP_NO_ERROR ) { | 187 | if ( err == MAILIMAP_NO_ERROR ) { |
183 | current = result->first; | 188 | current = result->first; |
184 | for ( int i = result->count; i > 0; i-- ) { | 189 | for ( int i = result->count; i > 0; i-- ) { |
185 | list = (mailimap_mailbox_list *) current->data; | 190 | list = (mailimap_mailbox_list *) current->data; |
186 | // it is better use the deep copy mechanism of qt itself | 191 | // it is better use the deep copy mechanism of qt itself |
187 | // instead of using strdup! | 192 | // instead of using strdup! |
188 | temp = list->mb_name; | 193 | temp = list->mb_name; |
189 | del = list->mb_delimiter; | 194 | del = list->mb_delimiter; |
190 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); | 195 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); |
191 | current = current->next; | 196 | current = current->next; |
192 | } | 197 | } |
193 | } else { | 198 | } else { |
194 | qDebug("error fetching folders: %s",m_imap->imap_response); | 199 | qDebug("error fetching folders: %s",m_imap->imap_response); |
195 | } | 200 | } |
196 | mailimap_list_result_free( result ); | 201 | mailimap_list_result_free( result ); |
197 | 202 | ||
198 | /* | 203 | /* |
199 | * second stage - get the other then inbox folders | 204 | * second stage - get the other then inbox folders |
200 | */ | 205 | */ |
201 | mask = "*" ; | 206 | mask = "*" ; |
202 | path = account->getPrefix().latin1(); | 207 | path = account->getPrefix().latin1(); |
203 | if (!path) path = ""; | 208 | if (!path) path = ""; |
204 | qDebug(path); | 209 | qDebug(path); |
205 | bool selectable = true; | 210 | bool selectable = true; |
206 | mailimap_mbx_list_flags*bflags; | 211 | mailimap_mbx_list_flags*bflags; |
207 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 212 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
208 | if ( err == MAILIMAP_NO_ERROR ) { | 213 | if ( err == MAILIMAP_NO_ERROR ) { |
209 | current = result->first; | 214 | current = result->first; |
210 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 215 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
211 | list = (mailimap_mailbox_list *) current->data; | 216 | list = (mailimap_mailbox_list *) current->data; |
212 | // it is better use the deep copy mechanism of qt itself | 217 | // it is better use the deep copy mechanism of qt itself |
213 | // instead of using strdup! | 218 | // instead of using strdup! |
214 | temp = list->mb_name; | 219 | temp = list->mb_name; |
215 | if (temp.lower()=="inbox") | 220 | if (temp.lower()=="inbox") |
216 | continue; | 221 | continue; |
217 | if (temp.lower()==account->getPrefix().lower()) | 222 | if (temp.lower()==account->getPrefix().lower()) |
218 | continue; | 223 | continue; |
219 | if ( (bflags = list->mb_flag) ) { | 224 | if ( (bflags = list->mb_flag) ) { |
220 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 225 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
221 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 226 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
222 | } | 227 | } |
223 | del = list->mb_delimiter; | 228 | del = list->mb_delimiter; |
224 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); | 229 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); |
225 | } | 230 | } |
226 | } else { | 231 | } else { |
227 | qDebug("error fetching folders %s",m_imap->imap_response); | 232 | qDebug("error fetching folders %s",m_imap->imap_response); |
228 | } | 233 | } |
229 | if (result) mailimap_list_result_free( result ); | 234 | if (result) mailimap_list_result_free( result ); |