author | zautrix <zautrix> | 2004-09-10 16:47:36 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-10 16:47:36 (UTC) |
commit | 157120031b77a3d9f10d780a66b6441dac1399fa (patch) (unidiff) | |
tree | fe756e71b5290940d2824d06c11e5f887a6f00e2 /kmicromail | |
parent | 3b3e910d97287f6a538c114458d97800d430799a (diff) | |
download | kdepimpi-157120031b77a3d9f10d780a66b6441dac1399fa.zip kdepimpi-157120031b77a3d9f10d780a66b6441dac1399fa.tar.gz kdepimpi-157120031b77a3d9f10d780a66b6441dac1399fa.tar.bz2 |
Fixes in password dislog handling
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 18 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/nntpwrapper.cpp | 25 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/pop3wrapper.cpp | 18 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/smtpwrapper.cpp | 19 |
4 files changed, 34 insertions, 46 deletions
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index 11d3343..021633b 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp | |||
@@ -3,277 +3,277 @@ | |||
3 | #include <libetpan/libetpan.h> | 3 | #include <libetpan/libetpan.h> |
4 | #include <qpe/global.h> | 4 | #include <qpe/global.h> |
5 | #include <qapplication.h> | 5 | #include <qapplication.h> |
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 | #include <qprogressbar.h> | 9 | #include <qprogressbar.h> |
10 | 10 | ||
11 | using namespace Opie::Core; | 11 | using namespace Opie::Core; |
12 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 12 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
13 | : AbstractMail() | 13 | : AbstractMail() |
14 | { | 14 | { |
15 | account = a; | 15 | account = a; |
16 | m_imap = 0; | 16 | m_imap = 0; |
17 | m_Lastmbox = ""; | 17 | m_Lastmbox = ""; |
18 | } | 18 | } |
19 | 19 | ||
20 | IMAPwrapper::~IMAPwrapper() | 20 | IMAPwrapper::~IMAPwrapper() |
21 | { | 21 | { |
22 | logout(); | 22 | logout(); |
23 | } | 23 | } |
24 | 24 | ||
25 | /* to avoid to often select statements in loops etc. | 25 | /* to avoid to often select statements in loops etc. |
26 | we trust that we are logged in and connection is established!*/ | 26 | we trust that we are logged in and connection is established!*/ |
27 | int IMAPwrapper::selectMbox(const QString&mbox) | 27 | int IMAPwrapper::selectMbox(const QString&mbox) |
28 | { | 28 | { |
29 | if (mbox == m_Lastmbox) { | 29 | if (mbox == m_Lastmbox) { |
30 | return MAILIMAP_NO_ERROR; | 30 | return MAILIMAP_NO_ERROR; |
31 | } | 31 | } |
32 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); | 32 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); |
33 | if ( err != MAILIMAP_NO_ERROR ) { | 33 | if ( err != MAILIMAP_NO_ERROR ) { |
34 | m_Lastmbox = ""; | 34 | m_Lastmbox = ""; |
35 | return err; | 35 | return err; |
36 | } | 36 | } |
37 | m_Lastmbox = mbox; | 37 | m_Lastmbox = mbox; |
38 | return err; | 38 | return err; |
39 | } | 39 | } |
40 | 40 | ||
41 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 41 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
42 | { | 42 | { |
43 | qApp->processEvents(); | 43 | qApp->processEvents(); |
44 | qDebug("imap progress %d of %d ",current,maximum ); | 44 | qDebug("imap progress %d of %d ",current,maximum ); |
45 | } | 45 | } |
46 | 46 | ||
47 | bool IMAPwrapper::start_tls(bool force_tls) | 47 | bool IMAPwrapper::start_tls(bool force_tls) |
48 | { | 48 | { |
49 | int err; | 49 | int err; |
50 | bool try_tls; | 50 | bool try_tls; |
51 | mailimap_capability_data * cap_data = 0; | 51 | mailimap_capability_data * cap_data = 0; |
52 | 52 | ||
53 | err = mailimap_capability(m_imap,&cap_data); | 53 | err = mailimap_capability(m_imap,&cap_data); |
54 | if (err != MAILIMAP_NO_ERROR) { | 54 | if (err != MAILIMAP_NO_ERROR) { |
55 | Global::statusMessage("error getting capabilities!"); | 55 | Global::statusMessage("error getting capabilities!"); |
56 | return false; | 56 | return false; |
57 | } | 57 | } |
58 | clistiter * cur; | 58 | clistiter * cur; |
59 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { | 59 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { |
60 | struct mailimap_capability * cap; | 60 | struct mailimap_capability * cap; |
61 | cap = (struct mailimap_capability *)clist_content(cur); | 61 | cap = (struct mailimap_capability *)clist_content(cur); |
62 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { | 62 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { |
63 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { | 63 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { |
64 | try_tls = true; | 64 | try_tls = true; |
65 | break; | 65 | break; |
66 | } | 66 | } |
67 | } | 67 | } |
68 | } | 68 | } |
69 | if (cap_data) { | 69 | if (cap_data) { |
70 | mailimap_capability_data_free(cap_data); | 70 | mailimap_capability_data_free(cap_data); |
71 | } | 71 | } |
72 | if (try_tls) { | 72 | if (try_tls) { |
73 | err = mailimap_starttls(m_imap); | 73 | err = mailimap_starttls(m_imap); |
74 | if (err != MAILIMAP_NO_ERROR && force_tls) { | 74 | if (err != MAILIMAP_NO_ERROR && force_tls) { |
75 | Global::statusMessage(tr("Server has no TLS support!")); | 75 | Global::statusMessage(tr("Server has no TLS support!")); |
76 | try_tls = false; | 76 | try_tls = false; |
77 | } else { | 77 | } else { |
78 | mailstream_low * low; | 78 | mailstream_low * low; |
79 | mailstream_low * new_low; | 79 | mailstream_low * new_low; |
80 | low = mailstream_get_low(m_imap->imap_stream); | 80 | low = mailstream_get_low(m_imap->imap_stream); |
81 | if (!low) { | 81 | if (!low) { |
82 | try_tls = false; | 82 | try_tls = false; |
83 | } else { | 83 | } else { |
84 | int fd = mailstream_low_get_fd(low); | 84 | int fd = mailstream_low_get_fd(low); |
85 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 85 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
86 | mailstream_low_free(low); | 86 | mailstream_low_free(low); |
87 | mailstream_set_low(m_imap->imap_stream, new_low); | 87 | mailstream_set_low(m_imap->imap_stream, new_low); |
88 | } else { | 88 | } else { |
89 | try_tls = false; | 89 | try_tls = false; |
90 | } | 90 | } |
91 | } | 91 | } |
92 | } | 92 | } |
93 | } | 93 | } |
94 | return try_tls; | 94 | return try_tls; |
95 | } | 95 | } |
96 | 96 | ||
97 | void IMAPwrapper::login() | 97 | void IMAPwrapper::login() |
98 | { | 98 | { |
99 | const char *server, *user, *pass; | 99 | QString server, user, pass; |
100 | uint16_t port; | 100 | uint16_t port; |
101 | int err = MAILIMAP_NO_ERROR; | 101 | int err = MAILIMAP_NO_ERROR; |
102 | 102 | ||
103 | if (account->getOffline()) return; | 103 | if (account->getOffline()) return; |
104 | /* we are connected this moment */ | 104 | /* we are connected this moment */ |
105 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 105 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
106 | if (m_imap) { | 106 | if (m_imap) { |
107 | err = mailimap_noop(m_imap); | 107 | err = mailimap_noop(m_imap); |
108 | if (err!=MAILIMAP_NO_ERROR) { | 108 | if (err!=MAILIMAP_NO_ERROR) { |
109 | logout(); | 109 | logout(); |
110 | } else { | 110 | } else { |
111 | mailstream_flush(m_imap->imap_stream); | 111 | mailstream_flush(m_imap->imap_stream); |
112 | return; | 112 | return; |
113 | } | 113 | } |
114 | } | 114 | } |
115 | server = account->getServer().latin1(); | 115 | server = account->getServer(); |
116 | port = account->getPort().toUInt(); | 116 | port = account->getPort().toUInt(); |
117 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 117 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
118 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 118 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
119 | login.show(); | 119 | login.show(); |
120 | if ( QDialog::Accepted == login.exec() ) { | 120 | if ( QDialog::Accepted == login.exec() ) { |
121 | // ok | 121 | // ok |
122 | user = login.getUser().latin1(); | 122 | user = login.getUser(); |
123 | pass = login.getPassword().latin1(); | 123 | pass = login.getPassword(); |
124 | } else { | 124 | } else { |
125 | // cancel | 125 | // cancel |
126 | return; | 126 | return; |
127 | } | 127 | } |
128 | } else { | 128 | } else { |
129 | user = account->getUser().latin1(); | 129 | user = account->getUser(); |
130 | pass = account->getPassword().latin1(); | 130 | pass = account->getPassword(); |
131 | } | 131 | } |
132 | 132 | ||
133 | m_imap = mailimap_new( 20, &imap_progress ); | 133 | m_imap = mailimap_new( 20, &imap_progress ); |
134 | 134 | ||
135 | /* connect */ | 135 | /* connect */ |
136 | bool ssl = false; | 136 | bool ssl = false; |
137 | bool try_tls = false; | 137 | bool try_tls = false; |
138 | bool force_tls = false; | 138 | bool force_tls = false; |
139 | 139 | ||
140 | if ( account->ConnectionType() == 2 ) { | 140 | if ( account->ConnectionType() == 2 ) { |
141 | ssl = true; | 141 | ssl = true; |
142 | } | 142 | } |
143 | if (account->ConnectionType()==1) { | 143 | if (account->ConnectionType()==1) { |
144 | force_tls = true; | 144 | force_tls = true; |
145 | } | 145 | } |
146 | 146 | ||
147 | if ( ssl ) { | 147 | if ( ssl ) { |
148 | qDebug("using ssl "); | 148 | qDebug("using ssl "); |
149 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 149 | err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); |
150 | } else { | 150 | } else { |
151 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 151 | err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); |
152 | } | 152 | } |
153 | 153 | ||
154 | if ( err != MAILIMAP_NO_ERROR && | 154 | if ( err != MAILIMAP_NO_ERROR && |
155 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 155 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
156 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 156 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
157 | QString failure = ""; | 157 | QString failure = ""; |
158 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 158 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
159 | failure="Connection refused"; | 159 | failure="Connection refused"; |
160 | } else { | 160 | } else { |
161 | failure="Unknown failure"; | 161 | failure="Unknown failure"; |
162 | } | 162 | } |
163 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); | 163 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); |
164 | mailimap_free( m_imap ); | 164 | mailimap_free( m_imap ); |
165 | m_imap = 0; | 165 | m_imap = 0; |
166 | return; | 166 | return; |
167 | } | 167 | } |
168 | 168 | ||
169 | if (!ssl) { | 169 | if (!ssl) { |
170 | try_tls = start_tls(force_tls); | 170 | try_tls = start_tls(force_tls); |
171 | } | 171 | } |
172 | 172 | ||
173 | bool ok = true; | 173 | bool ok = true; |
174 | if (force_tls && !try_tls) { | 174 | if (force_tls && !try_tls) { |
175 | Global::statusMessage(tr("Server has no TLS support!")); | 175 | Global::statusMessage(tr("Server has no TLS support!")); |
176 | ok = false; | 176 | ok = false; |
177 | } | 177 | } |
178 | 178 | ||
179 | 179 | ||
180 | /* login */ | 180 | /* login */ |
181 | 181 | ||
182 | if (ok) { | 182 | if (ok) { |
183 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 183 | err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); |
184 | if ( err != MAILIMAP_NO_ERROR ) { | 184 | if ( err != MAILIMAP_NO_ERROR ) { |
185 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); | 185 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); |
186 | ok = false; | 186 | ok = false; |
187 | } | 187 | } |
188 | } | 188 | } |
189 | if (!ok) { | 189 | if (!ok) { |
190 | err = mailimap_close( m_imap ); | 190 | err = mailimap_close( m_imap ); |
191 | mailimap_free( m_imap ); | 191 | mailimap_free( m_imap ); |
192 | m_imap = 0; | 192 | m_imap = 0; |
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
196 | void IMAPwrapper::logout() | 196 | void IMAPwrapper::logout() |
197 | { | 197 | { |
198 | int err = MAILIMAP_NO_ERROR; | 198 | int err = MAILIMAP_NO_ERROR; |
199 | if (!m_imap) return; | 199 | if (!m_imap) return; |
200 | err = mailimap_logout( m_imap ); | 200 | err = mailimap_logout( m_imap ); |
201 | err = mailimap_close( m_imap ); | 201 | err = mailimap_close( m_imap ); |
202 | mailimap_free( m_imap ); | 202 | mailimap_free( m_imap ); |
203 | m_imap = 0; | 203 | m_imap = 0; |
204 | m_Lastmbox = ""; | 204 | m_Lastmbox = ""; |
205 | } | 205 | } |
206 | 206 | ||
207 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) | 207 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) |
208 | { | 208 | { |
209 | int err = MAILIMAP_NO_ERROR; | 209 | int err = MAILIMAP_NO_ERROR; |
210 | clist *result = 0; | 210 | clist *result = 0; |
211 | clistcell *current; | 211 | clistcell *current; |
212 | mailimap_fetch_type *fetchType = 0; | 212 | mailimap_fetch_type *fetchType = 0; |
213 | mailimap_set *set = 0; | 213 | mailimap_set *set = 0; |
214 | 214 | ||
215 | login(); | 215 | login(); |
216 | if (!m_imap) { | 216 | if (!m_imap) { |
217 | return; | 217 | return; |
218 | } | 218 | } |
219 | /* select mailbox READONLY for operations */ | 219 | /* select mailbox READONLY for operations */ |
220 | err = selectMbox(mailbox); | 220 | err = selectMbox(mailbox); |
221 | if ( err != MAILIMAP_NO_ERROR ) { | 221 | if ( err != MAILIMAP_NO_ERROR ) { |
222 | return; | 222 | return; |
223 | } | 223 | } |
224 | 224 | ||
225 | int last = m_imap->imap_selection_info->sel_exists; | 225 | int last = m_imap->imap_selection_info->sel_exists; |
226 | 226 | ||
227 | if (last == 0) { | 227 | if (last == 0) { |
228 | Global::statusMessage(tr("Mailbox has no mails")); | 228 | Global::statusMessage(tr("Mailbox has no mails")); |
229 | return; | 229 | return; |
230 | } else { | 230 | } else { |
231 | } | 231 | } |
232 | 232 | ||
233 | /* the range has to start at 1!!! not with 0!!!! */ | 233 | /* the range has to start at 1!!! not with 0!!!! */ |
234 | set = mailimap_set_new_interval( 1, last ); | 234 | set = mailimap_set_new_interval( 1, last ); |
235 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 235 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
236 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 236 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
237 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 237 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
238 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 238 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
239 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 239 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
240 | 240 | ||
241 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 241 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
242 | mailimap_set_free( set ); | 242 | mailimap_set_free( set ); |
243 | mailimap_fetch_type_free( fetchType ); | 243 | mailimap_fetch_type_free( fetchType ); |
244 | 244 | ||
245 | QString date,subject,from; | 245 | QString date,subject,from; |
246 | 246 | ||
247 | if ( err == MAILIMAP_NO_ERROR ) { | 247 | if ( err == MAILIMAP_NO_ERROR ) { |
248 | mailimap_msg_att * msg_att; | 248 | mailimap_msg_att * msg_att; |
249 | int i = 0; | 249 | int i = 0; |
250 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 250 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
251 | ++i; | 251 | ++i; |
252 | msg_att = (mailimap_msg_att*)current->data; | 252 | msg_att = (mailimap_msg_att*)current->data; |
253 | RecMail*m = parse_list_result(msg_att); | 253 | RecMail*m = parse_list_result(msg_att); |
254 | if (m) { | 254 | if (m) { |
255 | if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) { | 255 | if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) { |
256 | m->setNumber(i); | 256 | m->setNumber(i); |
257 | m->setMbox(mailbox); | 257 | m->setMbox(mailbox); |
258 | m->setWrapper(this); | 258 | m->setWrapper(this); |
259 | target.append(m); | 259 | target.append(m); |
260 | } | 260 | } |
261 | } | 261 | } |
262 | } | 262 | } |
263 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); | 263 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); |
264 | } else { | 264 | } else { |
265 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); | 265 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); |
266 | } | 266 | } |
267 | if (result) mailimap_fetch_list_free(result); | 267 | if (result) mailimap_fetch_list_free(result); |
268 | } | 268 | } |
269 | 269 | ||
270 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() | 270 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() |
271 | { | 271 | { |
272 | const char *path, *mask; | 272 | const char *path, *mask; |
273 | int err = MAILIMAP_NO_ERROR; | 273 | int err = MAILIMAP_NO_ERROR; |
274 | clist *result = 0; | 274 | clist *result = 0; |
275 | clistcell *current = 0; | 275 | clistcell *current = 0; |
276 | clistcell*cur_flag = 0; | 276 | clistcell*cur_flag = 0; |
277 | mailimap_mbx_list_flags*bflags = 0; | 277 | mailimap_mbx_list_flags*bflags = 0; |
278 | 278 | ||
279 | QValueList<FolderP>* folders = new QValueList<FolderP>(); | 279 | QValueList<FolderP>* folders = new QValueList<FolderP>(); |
diff --git a/kmicromail/libmailwrapper/nntpwrapper.cpp b/kmicromail/libmailwrapper/nntpwrapper.cpp index f5d7f16..93cd2b5 100644 --- a/kmicromail/libmailwrapper/nntpwrapper.cpp +++ b/kmicromail/libmailwrapper/nntpwrapper.cpp | |||
@@ -24,244 +24,235 @@ NNTPwrapper::NNTPwrapper( NNTPaccount *a ) | |||
24 | 24 | ||
25 | NNTPwrapper::~NNTPwrapper() { | 25 | NNTPwrapper::~NNTPwrapper() { |
26 | logout(); | 26 | logout(); |
27 | QFile msg_cache(msgTempName); | 27 | QFile msg_cache(msgTempName); |
28 | if (msg_cache.exists()) { | 28 | if (msg_cache.exists()) { |
29 | msg_cache.remove(); | 29 | msg_cache.remove(); |
30 | } | 30 | } |
31 | } | 31 | } |
32 | 32 | ||
33 | void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) { | 33 | void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) { |
34 | ; // << "NNTP: " << current << " of " << maximum << "" << oendl; | 34 | ; // << "NNTP: " << current << " of " << maximum << "" << oendl; |
35 | } | 35 | } |
36 | 36 | ||
37 | 37 | ||
38 | RecBodyP NNTPwrapper::fetchBody( const RecMailP &mail ) { | 38 | RecBodyP NNTPwrapper::fetchBody( const RecMailP &mail ) { |
39 | int err = NEWSNNTP_NO_ERROR; | 39 | int err = NEWSNNTP_NO_ERROR; |
40 | char *message = 0; | 40 | char *message = 0; |
41 | size_t length = 0; | 41 | size_t length = 0; |
42 | 42 | ||
43 | RecBodyP body = new RecBody(); | 43 | RecBodyP body = new RecBody(); |
44 | login(); | 44 | login(); |
45 | if ( !m_nntp ) { | 45 | if ( !m_nntp ) { |
46 | return body; | 46 | return body; |
47 | } | 47 | } |
48 | 48 | ||
49 | mailmessage * mailmsg; | 49 | mailmessage * mailmsg; |
50 | if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { | 50 | if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { |
51 | ; // << "Message to large: " << mail->Msgsize() << "" << oendl; | 51 | ; // << "Message to large: " << mail->Msgsize() << "" << oendl; |
52 | return body; | 52 | return body; |
53 | } | 53 | } |
54 | 54 | ||
55 | QFile msg_cache(msgTempName); | 55 | QFile msg_cache(msgTempName); |
56 | 56 | ||
57 | cleanMimeCache(); | 57 | cleanMimeCache(); |
58 | 58 | ||
59 | if (mail->getNumber()!=last_msg_id) { | 59 | if (mail->getNumber()!=last_msg_id) { |
60 | if (msg_cache.exists()) { | 60 | if (msg_cache.exists()) { |
61 | msg_cache.remove(); | 61 | msg_cache.remove(); |
62 | } | 62 | } |
63 | msg_cache.open(IO_ReadWrite|IO_Truncate); | 63 | msg_cache.open(IO_ReadWrite|IO_Truncate); |
64 | last_msg_id = mail->getNumber(); | 64 | last_msg_id = mail->getNumber(); |
65 | err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); | 65 | err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); |
66 | err = mailmessage_fetch(mailmsg,&message,&length); | 66 | err = mailmessage_fetch(mailmsg,&message,&length); |
67 | msg_cache.writeBlock(message,length); | 67 | msg_cache.writeBlock(message,length); |
68 | } else { | 68 | } else { |
69 | QString msg=""; | 69 | QString msg=""; |
70 | msg_cache.open(IO_ReadOnly); | 70 | msg_cache.open(IO_ReadOnly); |
71 | message = new char[4096]; | 71 | message = new char[4096]; |
72 | memset(message,0,4096); | 72 | memset(message,0,4096); |
73 | while (msg_cache.readBlock(message,4095)>0) { | 73 | while (msg_cache.readBlock(message,4095)>0) { |
74 | msg+=message; | 74 | msg+=message; |
75 | memset(message,0,4096); | 75 | memset(message,0,4096); |
76 | } | 76 | } |
77 | delete message; | 77 | delete message; |
78 | message = (char*)malloc(msg.length()+1*sizeof(char)); | 78 | message = (char*)malloc(msg.length()+1*sizeof(char)); |
79 | memset(message,0,msg.length()+1); | 79 | memset(message,0,msg.length()+1); |
80 | memcpy(message,msg.latin1(),msg.length()); | 80 | memcpy(message,msg.latin1(),msg.length()); |
81 | /* transform to libetpan stuff */ | 81 | /* transform to libetpan stuff */ |
82 | mailmsg = mailmessage_new(); | 82 | mailmsg = mailmessage_new(); |
83 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); | 83 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); |
84 | generic_message_t * msg_data; | 84 | generic_message_t * msg_data; |
85 | msg_data = (generic_message_t *)mailmsg->msg_data; | 85 | msg_data = (generic_message_t *)mailmsg->msg_data; |
86 | msg_data->msg_fetched = 1; | 86 | msg_data->msg_fetched = 1; |
87 | msg_data->msg_message = message; | 87 | msg_data->msg_message = message; |
88 | msg_data->msg_length = strlen(message); | 88 | msg_data->msg_length = strlen(message); |
89 | } | 89 | } |
90 | body = parseMail(mailmsg); | 90 | body = parseMail(mailmsg); |
91 | 91 | ||
92 | /* clean up */ | 92 | /* clean up */ |
93 | if (mailmsg) | 93 | if (mailmsg) |
94 | mailmessage_free(mailmsg); | 94 | mailmessage_free(mailmsg); |
95 | if (message) | 95 | if (message) |
96 | free(message); | 96 | free(message); |
97 | 97 | ||
98 | return body; | 98 | return body; |
99 | } | 99 | } |
100 | 100 | ||
101 | 101 | ||
102 | void NNTPwrapper::listMessages(const QString & which, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb) | 102 | void NNTPwrapper::listMessages(const QString & which, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb) |
103 | { | 103 | { |
104 | login(); | 104 | login(); |
105 | if (!m_nntp) | 105 | if (!m_nntp) |
106 | return; | 106 | return; |
107 | uint32_t res_messages,res_recent,res_unseen; | 107 | uint32_t res_messages,res_recent,res_unseen; |
108 | mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen); | 108 | mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen); |
109 | parseList(target,m_nntp->sto_session,which,true, maxSizeInKb); | 109 | parseList(target,m_nntp->sto_session,which,true, maxSizeInKb); |
110 | } | 110 | } |
111 | 111 | ||
112 | void NNTPwrapper::login() | 112 | void NNTPwrapper::login() |
113 | { | 113 | { |
114 | if (account->getOffline()) | 114 | if (account->getOffline()) |
115 | return; | 115 | return; |
116 | /* we'll hold the line */ | 116 | /* we'll hold the line */ |
117 | if ( m_nntp != NULL ) | 117 | if ( m_nntp != NULL ) |
118 | return; | 118 | return; |
119 | 119 | ||
120 | const char *server, *user, *pass; | 120 | QString server; |
121 | QString User,Pass; | 121 | QString User,Pass; |
122 | uint16_t port; | 122 | uint16_t port; |
123 | int err = NEWSNNTP_NO_ERROR; | 123 | int err = NEWSNNTP_NO_ERROR; |
124 | 124 | ||
125 | server = account->getServer().latin1(); | 125 | server = account->getServer(); |
126 | port = account->getPort().toUInt(); | 126 | port = account->getPort().toUInt(); |
127 | 127 | ||
128 | user = pass = 0; | ||
129 | |||
130 | if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) { | 128 | if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) { |
131 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 129 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
132 | login.show(); | 130 | login.show(); |
133 | if ( QDialog::Accepted == login.exec() ) { | 131 | if ( QDialog::Accepted == login.exec() ) { |
134 | // ok | 132 | // ok |
135 | User = login.getUser().latin1(); | 133 | User = login.getUser(); |
136 | Pass = login.getPassword().latin1(); | 134 | Pass = login.getPassword(); |
137 | } else { | 135 | } else { |
138 | // cancel | 136 | // cancel |
139 | ; // << "NNTP: Login canceled" << oendl; | 137 | ; // << "NNTP: Login canceled" << oendl; |
140 | return; | 138 | return; |
141 | } | 139 | } |
142 | } else { | 140 | } else { |
143 | User = account->getUser().latin1(); | 141 | User = account->getUser(); |
144 | Pass = account->getPassword().latin1(); | 142 | Pass = account->getPassword(); |
145 | } | 143 | } |
146 | 144 | ||
147 | if (User.isEmpty()) { | ||
148 | user=0; | ||
149 | pass = 0; | ||
150 | } else { | ||
151 | user=User.latin1(); | ||
152 | pass=Pass.latin1(); | ||
153 | } | ||
154 | // bool ssl = account->getSSL(); | 145 | // bool ssl = account->getSSL(); |
155 | 146 | ||
156 | m_nntp=mailstorage_new(NULL); | 147 | m_nntp=mailstorage_new(NULL); |
157 | 148 | ||
158 | int conntypeset = account->ConnectionType(); | 149 | int conntypeset = account->ConnectionType(); |
159 | int conntype = 0; | 150 | int conntype = 0; |
160 | if ( conntypeset == 3 ) { | 151 | if ( conntypeset == 3 ) { |
161 | conntype = CONNECTION_TYPE_COMMAND; | 152 | conntype = CONNECTION_TYPE_COMMAND; |
162 | } else if ( conntypeset == 2 ) { | 153 | } else if ( conntypeset == 2 ) { |
163 | conntype = CONNECTION_TYPE_TLS; | 154 | conntype = CONNECTION_TYPE_TLS; |
164 | } else if ( conntypeset == 1 ) { | 155 | } else if ( conntypeset == 1 ) { |
165 | conntype = CONNECTION_TYPE_STARTTLS; | 156 | conntype = CONNECTION_TYPE_STARTTLS; |
166 | } else if ( conntypeset == 0 ) { | 157 | } else if ( conntypeset == 0 ) { |
167 | conntype = CONNECTION_TYPE_TRY_STARTTLS; | 158 | conntype = CONNECTION_TYPE_TRY_STARTTLS; |
168 | } | 159 | } |
169 | 160 | ||
170 | nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN, | 161 | nntp_mailstorage_init(m_nntp,(char*)server.latin1(), port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN, |
171 | (char*)user,(char*)pass,0,0,0); | 162 | (char*)User.latin1(),(char*)Pass.latin1(),0,0,0); |
172 | 163 | ||
173 | err = mailstorage_connect( m_nntp ); | 164 | err = mailstorage_connect( m_nntp ); |
174 | 165 | ||
175 | if (err != NEWSNNTP_NO_ERROR) { | 166 | if (err != NEWSNNTP_NO_ERROR) { |
176 | ; // << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; | 167 | ; // << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; |
177 | // Global::statusMessage(tr("Error initializing folder")); | 168 | // Global::statusMessage(tr("Error initializing folder")); |
178 | mailstorage_free(m_nntp); | 169 | mailstorage_free(m_nntp); |
179 | m_nntp = 0; | 170 | m_nntp = 0; |
180 | 171 | ||
181 | } else { | 172 | } else { |
182 | mailsession * session = m_nntp->sto_session; | 173 | mailsession * session = m_nntp->sto_session; |
183 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; | 174 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; |
184 | news->nntp_progr_fun = &nntp_progress; | 175 | news->nntp_progr_fun = &nntp_progress; |
185 | } | 176 | } |
186 | 177 | ||
187 | } | 178 | } |
188 | 179 | ||
189 | void NNTPwrapper::logout() | 180 | void NNTPwrapper::logout() |
190 | { | 181 | { |
191 | int err = NEWSNNTP_NO_ERROR; | 182 | int err = NEWSNNTP_NO_ERROR; |
192 | if ( m_nntp == NULL ) | 183 | if ( m_nntp == NULL ) |
193 | return; | 184 | return; |
194 | mailstorage_free(m_nntp); | 185 | mailstorage_free(m_nntp); |
195 | m_nntp = 0; | 186 | m_nntp = 0; |
196 | } | 187 | } |
197 | 188 | ||
198 | QValueList<Opie::Core::OSmartPointer<Folder> >* NNTPwrapper::listFolders() { | 189 | QValueList<Opie::Core::OSmartPointer<Folder> >* NNTPwrapper::listFolders() { |
199 | 190 | ||
200 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); | 191 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); |
201 | QStringList groups; | 192 | QStringList groups; |
202 | if (account) { | 193 | if (account) { |
203 | groups = account->getGroups(); | 194 | groups = account->getGroups(); |
204 | } | 195 | } |
205 | for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) { | 196 | for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) { |
206 | folders->append(new Folder((*it),".")); | 197 | folders->append(new Folder((*it),".")); |
207 | } | 198 | } |
208 | return folders; | 199 | return folders; |
209 | } | 200 | } |
210 | 201 | ||
211 | /* we made this method in raw nntp access of etpan and not via generic interface | 202 | /* we made this method in raw nntp access of etpan and not via generic interface |
212 | * 'cause in that case there will be doubled copy operations. eg. the etpan would | 203 | * 'cause in that case there will be doubled copy operations. eg. the etpan would |
213 | * copy that stuff into its own structures and we must copy it into useable c++ | 204 | * copy that stuff into its own structures and we must copy it into useable c++ |
214 | * structures for our frontend. this would not make sense, so it is better to reimplement | 205 | * structures for our frontend. this would not make sense, so it is better to reimplement |
215 | * the stuff from generic interface of etpan but copy it direct to qt classes. | 206 | * the stuff from generic interface of etpan but copy it direct to qt classes. |
216 | */ | 207 | */ |
217 | QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) { | 208 | QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) { |
218 | login(); | 209 | login(); |
219 | QStringList res; | 210 | QStringList res; |
220 | clist *result = 0; | 211 | clist *result = 0; |
221 | clistcell *current = 0; | 212 | clistcell *current = 0; |
222 | newsnntp_group_description *group; | 213 | newsnntp_group_description *group; |
223 | 214 | ||
224 | if ( m_nntp ) { | 215 | if ( m_nntp ) { |
225 | mailsession * session = m_nntp->sto_session; | 216 | mailsession * session = m_nntp->sto_session; |
226 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; | 217 | newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; |
227 | int err = NEWSNNTP_NO_ERROR; | 218 | int err = NEWSNNTP_NO_ERROR; |
228 | if (mask.isEmpty()) { | 219 | if (mask.isEmpty()) { |
229 | err = newsnntp_list(news, &result); | 220 | err = newsnntp_list(news, &result); |
230 | } else { | 221 | } else { |
231 | /* taken from generic wrapper of etpan */ | 222 | /* taken from generic wrapper of etpan */ |
232 | QString nmask = mask+".*"; | 223 | QString nmask = mask+".*"; |
233 | err = newsnntp_list_active(news, nmask.latin1(), &result); | 224 | err = newsnntp_list_active(news, nmask.latin1(), &result); |
234 | } | 225 | } |
235 | if ( err == NEWSNNTP_NO_ERROR && result) { | 226 | if ( err == NEWSNNTP_NO_ERROR && result) { |
236 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) { | 227 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) { |
237 | group = ( newsnntp_group_description* ) current->data; | 228 | group = ( newsnntp_group_description* ) current->data; |
238 | if (!group||!group->grp_name||strlen(group->grp_name)==0) continue; | 229 | if (!group||!group->grp_name||strlen(group->grp_name)==0) continue; |
239 | res.append(group->grp_name); | 230 | res.append(group->grp_name); |
240 | } | 231 | } |
241 | } | 232 | } |
242 | } | 233 | } |
243 | if (result) { | 234 | if (result) { |
244 | newsnntp_list_free(result); | 235 | newsnntp_list_free(result); |
245 | } | 236 | } |
246 | return res; | 237 | return res; |
247 | } | 238 | } |
248 | 239 | ||
249 | void NNTPwrapper::answeredMail(const RecMailP&) {} | 240 | void NNTPwrapper::answeredMail(const RecMailP&) {} |
250 | 241 | ||
251 | void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { | 242 | void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { |
252 | login(); | 243 | login(); |
253 | target_stat.message_count = 0; | 244 | target_stat.message_count = 0; |
254 | target_stat.message_unseen = 0; | 245 | target_stat.message_unseen = 0; |
255 | target_stat.message_recent = 0; | 246 | target_stat.message_recent = 0; |
256 | if (!m_nntp) | 247 | if (!m_nntp) |
257 | return; | 248 | return; |
258 | int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, | 249 | int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, |
259 | &target_stat.message_recent,&target_stat.message_unseen); | 250 | &target_stat.message_recent,&target_stat.message_unseen); |
260 | } | 251 | } |
261 | 252 | ||
262 | 253 | ||
263 | encodedString* NNTPwrapper::fetchRawBody(const RecMailP&mail) { | 254 | encodedString* NNTPwrapper::fetchRawBody(const RecMailP&mail) { |
264 | char*target=0; | 255 | char*target=0; |
265 | size_t length=0; | 256 | size_t length=0; |
266 | encodedString*res = 0; | 257 | encodedString*res = 0; |
267 | mailmessage * mailmsg = 0; | 258 | mailmessage * mailmsg = 0; |
diff --git a/kmicromail/libmailwrapper/pop3wrapper.cpp b/kmicromail/libmailwrapper/pop3wrapper.cpp index 0e6612c..f430121 100644 --- a/kmicromail/libmailwrapper/pop3wrapper.cpp +++ b/kmicromail/libmailwrapper/pop3wrapper.cpp | |||
@@ -25,237 +25,235 @@ POP3wrapper::POP3wrapper( POP3account *a ) | |||
25 | 25 | ||
26 | POP3wrapper::~POP3wrapper() { | 26 | POP3wrapper::~POP3wrapper() { |
27 | logout(); | 27 | logout(); |
28 | QFile msg_cache(msgTempName); | 28 | QFile msg_cache(msgTempName); |
29 | if (msg_cache.exists()) { | 29 | if (msg_cache.exists()) { |
30 | msg_cache.remove(); | 30 | msg_cache.remove(); |
31 | } | 31 | } |
32 | } | 32 | } |
33 | 33 | ||
34 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { | 34 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { |
35 | ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; | 35 | ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; |
36 | } | 36 | } |
37 | 37 | ||
38 | RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { | 38 | RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { |
39 | int err = MAILPOP3_NO_ERROR; | 39 | int err = MAILPOP3_NO_ERROR; |
40 | char *message = 0; | 40 | char *message = 0; |
41 | size_t length = 0; | 41 | size_t length = 0; |
42 | 42 | ||
43 | RecBodyP body = new RecBody(); | 43 | RecBodyP body = new RecBody(); |
44 | 44 | ||
45 | login(); | 45 | login(); |
46 | if ( !m_pop3 ) { | 46 | if ( !m_pop3 ) { |
47 | return body; | 47 | return body; |
48 | } | 48 | } |
49 | 49 | ||
50 | mailmessage * mailmsg; | 50 | mailmessage * mailmsg; |
51 | if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { | 51 | if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { |
52 | ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl; | 52 | ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl; |
53 | return body; | 53 | return body; |
54 | } | 54 | } |
55 | 55 | ||
56 | QFile msg_cache(msgTempName); | 56 | QFile msg_cache(msgTempName); |
57 | 57 | ||
58 | cleanMimeCache(); | 58 | cleanMimeCache(); |
59 | 59 | ||
60 | if (mail->getNumber()!=last_msg_id) { | 60 | if (mail->getNumber()!=last_msg_id) { |
61 | if (msg_cache.exists()) { | 61 | if (msg_cache.exists()) { |
62 | msg_cache.remove(); | 62 | msg_cache.remove(); |
63 | } | 63 | } |
64 | msg_cache.open(IO_ReadWrite|IO_Truncate); | 64 | msg_cache.open(IO_ReadWrite|IO_Truncate); |
65 | last_msg_id = mail->getNumber(); | 65 | last_msg_id = mail->getNumber(); |
66 | err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); | 66 | err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); |
67 | err = mailmessage_fetch(mailmsg,&message,&length); | 67 | err = mailmessage_fetch(mailmsg,&message,&length); |
68 | msg_cache.writeBlock(message,length); | 68 | msg_cache.writeBlock(message,length); |
69 | } else { | 69 | } else { |
70 | QString msg=""; | 70 | QString msg=""; |
71 | msg_cache.open(IO_ReadOnly); | 71 | msg_cache.open(IO_ReadOnly); |
72 | message = new char[4096]; | 72 | message = new char[4096]; |
73 | memset(message,0,4096); | 73 | memset(message,0,4096); |
74 | while (msg_cache.readBlock(message,4095)>0) { | 74 | while (msg_cache.readBlock(message,4095)>0) { |
75 | msg+=message; | 75 | msg+=message; |
76 | memset(message,0,4096); | 76 | memset(message,0,4096); |
77 | } | 77 | } |
78 | delete message; | 78 | delete message; |
79 | message = (char*)malloc(msg.length()+1*sizeof(char)); | 79 | message = (char*)malloc(msg.length()+1*sizeof(char)); |
80 | memset(message,0,msg.length()+1); | 80 | memset(message,0,msg.length()+1); |
81 | memcpy(message,msg.latin1(),msg.length()); | 81 | memcpy(message,msg.latin1(),msg.length()); |
82 | /* transform to libetpan stuff */ | 82 | /* transform to libetpan stuff */ |
83 | mailmsg = mailmessage_new(); | 83 | mailmsg = mailmessage_new(); |
84 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); | 84 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); |
85 | generic_message_t * msg_data; | 85 | generic_message_t * msg_data; |
86 | msg_data = (generic_message_t *)mailmsg->msg_data; | 86 | msg_data = (generic_message_t *)mailmsg->msg_data; |
87 | msg_data->msg_fetched = 1; | 87 | msg_data->msg_fetched = 1; |
88 | msg_data->msg_message = message; | 88 | msg_data->msg_message = message; |
89 | msg_data->msg_length = strlen(message); | 89 | msg_data->msg_length = strlen(message); |
90 | } | 90 | } |
91 | body = parseMail(mailmsg); | 91 | body = parseMail(mailmsg); |
92 | 92 | ||
93 | /* clean up */ | 93 | /* clean up */ |
94 | if (mailmsg) | 94 | if (mailmsg) |
95 | mailmessage_free(mailmsg); | 95 | mailmessage_free(mailmsg); |
96 | if (message) | 96 | if (message) |
97 | free(message); | 97 | free(message); |
98 | 98 | ||
99 | return body; | 99 | return body; |
100 | } | 100 | } |
101 | 101 | ||
102 | void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) | 102 | void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) |
103 | { | 103 | { |
104 | login(); | 104 | login(); |
105 | if (!m_pop3) | 105 | if (!m_pop3) |
106 | return; | 106 | return; |
107 | uint32_t res_messages,res_recent,res_unseen; | 107 | uint32_t res_messages,res_recent,res_unseen; |
108 | mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); | 108 | mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); |
109 | parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb); | 109 | parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb); |
110 | Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); | 110 | Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); |
111 | } | 111 | } |
112 | 112 | ||
113 | void POP3wrapper::login() | 113 | void POP3wrapper::login() |
114 | { | 114 | { |
115 | if (account->getOffline()) | 115 | if (account->getOffline()) |
116 | return; | 116 | return; |
117 | /* we'll hold the line */ | 117 | /* we'll hold the line */ |
118 | if ( m_pop3 != NULL ) | 118 | if ( m_pop3 != NULL ) |
119 | return; | 119 | return; |
120 | 120 | ||
121 | const char *server, *user, *pass; | 121 | QString server,user, pass; |
122 | uint16_t port; | 122 | uint16_t port; |
123 | int err = MAILPOP3_NO_ERROR; | 123 | int err = MAILPOP3_NO_ERROR; |
124 | 124 | ||
125 | server = account->getServer().latin1(); | 125 | server = account->getServer().latin1(); |
126 | port = account->getPort().toUInt(); | 126 | port = account->getPort().toUInt(); |
127 | 127 | ||
128 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 128 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
129 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 129 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
130 | login.show(); | 130 | login.show(); |
131 | if ( QDialog::Accepted == login.exec() ) { | 131 | if ( QDialog::Accepted == login.exec() ) { |
132 | // ok | 132 | // ok |
133 | user = login.getUser().latin1(); | 133 | qDebug("ok "); |
134 | pass = login.getPassword().latin1(); | 134 | user = login.getUser(); |
135 | pass = login.getPassword(); | ||
135 | } else { | 136 | } else { |
136 | // cancel | 137 | // cancel |
137 | ; // odebug << "POP3: Login canceled" << oendl; | 138 | ; // odebug << "POP3: Login canceled" << oendl; |
138 | return; | 139 | return; |
139 | } | 140 | } |
140 | } else { | 141 | } else { |
141 | user = account->getUser().latin1(); | 142 | user = account->getUser(); |
142 | pass = account->getPassword().latin1(); | 143 | pass = account->getPassword(); |
143 | } | 144 | } |
144 | |||
145 | // bool ssl = account->getSSL(); | 145 | // bool ssl = account->getSSL(); |
146 | 146 | ||
147 | m_pop3=mailstorage_new(NULL); | 147 | m_pop3=mailstorage_new(NULL); |
148 | |||
149 | int conntypeset = account->ConnectionType(); | 148 | int conntypeset = account->ConnectionType(); |
150 | int conntype = 0; | 149 | int conntype = 0; |
151 | if ( conntypeset == 3 ) { | 150 | if ( conntypeset == 3 ) { |
152 | conntype = CONNECTION_TYPE_COMMAND; | 151 | conntype = CONNECTION_TYPE_COMMAND; |
153 | } else if ( conntypeset == 2 ) { | 152 | } else if ( conntypeset == 2 ) { |
154 | conntype = CONNECTION_TYPE_TLS; | 153 | conntype = CONNECTION_TYPE_TLS; |
155 | } else if ( conntypeset == 1 ) { | 154 | } else if ( conntypeset == 1 ) { |
156 | conntype = CONNECTION_TYPE_STARTTLS; | 155 | conntype = CONNECTION_TYPE_STARTTLS; |
157 | } else if ( conntypeset == 0 ) { | 156 | } else if ( conntypeset == 0 ) { |
158 | conntype = CONNECTION_TYPE_TRY_STARTTLS; | 157 | conntype = CONNECTION_TYPE_TRY_STARTTLS; |
159 | } | 158 | } |
160 | 159 | ||
161 | //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); | 160 | //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); |
162 | 161 | ||
163 | pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, | 162 | pop3_mailstorage_init(m_pop3,(char*)server.latin1(), port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, |
164 | (char*)user,(char*)pass,0,0,0); | 163 | (char*)user.latin1(),(char*)pass.latin1(),0,0,0); |
165 | |||
166 | 164 | ||
167 | err = mailstorage_connect(m_pop3); | 165 | err = mailstorage_connect(m_pop3); |
168 | if (err != MAIL_NO_ERROR) { | 166 | if (err != MAIL_NO_ERROR) { |
169 | ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; | 167 | ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; |
170 | Global::statusMessage(tr("Error initializing folder")); | 168 | Global::statusMessage(tr("Error initializing folder")); |
171 | mailstorage_free(m_pop3); | 169 | mailstorage_free(m_pop3); |
172 | m_pop3 = 0; | 170 | m_pop3 = 0; |
173 | } else { | 171 | } else { |
174 | mailsession * session = m_pop3->sto_session; | 172 | mailsession * session = m_pop3->sto_session; |
175 | mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; | 173 | mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; |
176 | if (mail) { | 174 | if (mail) { |
177 | mail->pop3_progr_fun = &pop3_progress; | 175 | mail->pop3_progr_fun = &pop3_progress; |
178 | } | 176 | } |
179 | } | 177 | } |
180 | } | 178 | } |
181 | 179 | ||
182 | void POP3wrapper::logout() | 180 | void POP3wrapper::logout() |
183 | { | 181 | { |
184 | if ( m_pop3 == NULL ) | 182 | if ( m_pop3 == NULL ) |
185 | return; | 183 | return; |
186 | mailstorage_free(m_pop3); | 184 | mailstorage_free(m_pop3); |
187 | m_pop3 = 0; | 185 | m_pop3 = 0; |
188 | } | 186 | } |
189 | 187 | ||
190 | 188 | ||
191 | QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { | 189 | QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { |
192 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); | 190 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); |
193 | FolderP inb=new Folder("INBOX","/"); | 191 | FolderP inb=new Folder("INBOX","/"); |
194 | folders->append(inb); | 192 | folders->append(inb); |
195 | return folders; | 193 | return folders; |
196 | } | 194 | } |
197 | 195 | ||
198 | void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target) | 196 | void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target) |
199 | { | 197 | { |
200 | login(); | 198 | login(); |
201 | if (!m_pop3) | 199 | if (!m_pop3) |
202 | return; | 200 | return; |
203 | int iii = 0; | 201 | int iii = 0; |
204 | int count = target.count(); | 202 | int count = target.count(); |
205 | QProgressBar bar( count,0 ); | 203 | QProgressBar bar( count,0 ); |
206 | bar.setCaption (("Removing mails - close to abort!") ); | 204 | bar.setCaption (("Removing mails - close to abort!") ); |
207 | int w = 300; | 205 | int w = 300; |
208 | if ( QApplication::desktop()->width() < 320 ) | 206 | if ( QApplication::desktop()->width() < 320 ) |
209 | w = 220; | 207 | w = 220; |
210 | int h = bar.sizeHint().height() ; | 208 | int h = bar.sizeHint().height() ; |
211 | int dw = QApplication::desktop()->width(); | 209 | int dw = QApplication::desktop()->width(); |
212 | int dh = QApplication::desktop()->height(); | 210 | int dh = QApplication::desktop()->height(); |
213 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 211 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
214 | bar.show(); | 212 | bar.show(); |
215 | int modulo = (count/10)+1; | 213 | int modulo = (count/10)+1; |
216 | int incCounter = 0; | 214 | int incCounter = 0; |
217 | while (iii < count ) { | 215 | while (iii < count ) { |
218 | if ( ! bar.isVisible() ) | 216 | if ( ! bar.isVisible() ) |
219 | return ; | 217 | return ; |
220 | if ( incCounter % modulo == 0 ) | 218 | if ( incCounter % modulo == 0 ) |
221 | bar.setProgress( incCounter ); | 219 | bar.setProgress( incCounter ); |
222 | ++incCounter; | 220 | ++incCounter; |
223 | qApp->processEvents(); | 221 | qApp->processEvents(); |
224 | //qDebug("delete "); | 222 | //qDebug("delete "); |
225 | RecMailP mail = (*target.at( iii )); | 223 | RecMailP mail = (*target.at( iii )); |
226 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); | 224 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); |
227 | if (err != MAIL_NO_ERROR) { | 225 | if (err != MAIL_NO_ERROR) { |
228 | Global::statusMessage(tr("Error deleting mail")); | 226 | Global::statusMessage(tr("Error deleting mail")); |
229 | } | 227 | } |
230 | ++iii; | 228 | ++iii; |
231 | } | 229 | } |
232 | } | 230 | } |
233 | void POP3wrapper::deleteMail(const RecMailP&mail) { | 231 | void POP3wrapper::deleteMail(const RecMailP&mail) { |
234 | login(); | 232 | login(); |
235 | if (!m_pop3) | 233 | if (!m_pop3) |
236 | return; | 234 | return; |
237 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); | 235 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); |
238 | if (err != MAIL_NO_ERROR) { | 236 | if (err != MAIL_NO_ERROR) { |
239 | Global::statusMessage(tr("error deleting mail")); | 237 | Global::statusMessage(tr("error deleting mail")); |
240 | } | 238 | } |
241 | } | 239 | } |
242 | 240 | ||
243 | void POP3wrapper::answeredMail(const RecMailP&) {} | 241 | void POP3wrapper::answeredMail(const RecMailP&) {} |
244 | 242 | ||
245 | int POP3wrapper::deleteAllMail(const FolderP&) { | 243 | int POP3wrapper::deleteAllMail(const FolderP&) { |
246 | login(); | 244 | login(); |
247 | if (!m_pop3) | 245 | if (!m_pop3) |
248 | return 0; | 246 | return 0; |
249 | int res = 1; | 247 | int res = 1; |
250 | 248 | ||
251 | uint32_t result = 0; | 249 | uint32_t result = 0; |
252 | int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); | 250 | int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); |
253 | if (err != MAIL_NO_ERROR) { | 251 | if (err != MAIL_NO_ERROR) { |
254 | Global::statusMessage(tr("Error getting folder info")); | 252 | Global::statusMessage(tr("Error getting folder info")); |
255 | return 0; | 253 | return 0; |
256 | } | 254 | } |
257 | QProgressBar bar( result,0 ); | 255 | QProgressBar bar( result,0 ); |
258 | bar.setCaption (("Deleting mails - close to abort!") ); | 256 | bar.setCaption (("Deleting mails - close to abort!") ); |
259 | int w = 300; | 257 | int w = 300; |
260 | if ( QApplication::desktop()->width() < 320 ) | 258 | if ( QApplication::desktop()->width() < 320 ) |
261 | w = 220; | 259 | w = 220; |
diff --git a/kmicromail/libmailwrapper/smtpwrapper.cpp b/kmicromail/libmailwrapper/smtpwrapper.cpp index 6a1b505..d5a528c 100644 --- a/kmicromail/libmailwrapper/smtpwrapper.cpp +++ b/kmicromail/libmailwrapper/smtpwrapper.cpp | |||
@@ -89,281 +89,280 @@ void SMTPwrapper::progress( size_t current, size_t maximum ) { | |||
89 | if (SMTPwrapper::sendProgress) { | 89 | if (SMTPwrapper::sendProgress) { |
90 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | 90 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); |
91 | qApp->processEvents(); | 91 | qApp->processEvents(); |
92 | } | 92 | } |
93 | } | 93 | } |
94 | 94 | ||
95 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { | 95 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { |
96 | if (!mail) | 96 | if (!mail) |
97 | return; | 97 | return; |
98 | QString localfolders = AbstractMail::defaultLocalfolder(); | 98 | QString localfolders = AbstractMail::defaultLocalfolder(); |
99 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 99 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
100 | wrap->createMbox(box); | 100 | wrap->createMbox(box); |
101 | wrap->storeMessage(mail,length,box); | 101 | wrap->storeMessage(mail,length,box); |
102 | delete wrap; | 102 | delete wrap; |
103 | } | 103 | } |
104 | 104 | ||
105 | bool SMTPwrapper::smtpSend( mailmime *mail,bool later) { | 105 | bool SMTPwrapper::smtpSend( mailmime *mail,bool later) { |
106 | clist *rcpts = 0; | 106 | clist *rcpts = 0; |
107 | char *from, *data; | 107 | char *from, *data; |
108 | size_t size; | 108 | size_t size; |
109 | 109 | ||
110 | from = data = 0; | 110 | from = data = 0; |
111 | 111 | ||
112 | mailmessage * msg = 0; | 112 | mailmessage * msg = 0; |
113 | msg = mime_message_init(mail); | 113 | msg = mime_message_init(mail); |
114 | mime_message_set_tmpdir(msg,getenv( "HOME" )); | 114 | mime_message_set_tmpdir(msg,getenv( "HOME" )); |
115 | int r = mailmessage_fetch(msg,&data,&size); | 115 | int r = mailmessage_fetch(msg,&data,&size); |
116 | mime_message_detach_mime(msg); | 116 | mime_message_detach_mime(msg); |
117 | mailmessage_free(msg); | 117 | mailmessage_free(msg); |
118 | if (r != MAIL_NO_ERROR || !data) { | 118 | if (r != MAIL_NO_ERROR || !data) { |
119 | if (data) | 119 | if (data) |
120 | free(data); | 120 | free(data); |
121 | qDebug("Error fetching mime... "); | 121 | qDebug("Error fetching mime... "); |
122 | return false; | 122 | return false; |
123 | } | 123 | } |
124 | msg = 0; | 124 | msg = 0; |
125 | if (later) { | 125 | if (later) { |
126 | storeMail(data,size,"Outgoing"); | 126 | storeMail(data,size,"Outgoing"); |
127 | if (data) | 127 | if (data) |
128 | free( data ); | 128 | free( data ); |
129 | Config cfg( "mail" ); | 129 | Config cfg( "mail" ); |
130 | cfg.setGroup( "Status" ); | 130 | cfg.setGroup( "Status" ); |
131 | cfg.writeEntry( "outgoing", ++m_queuedMail ); | 131 | cfg.writeEntry( "outgoing", ++m_queuedMail ); |
132 | emit queuedMails( m_queuedMail ); | 132 | emit queuedMails( m_queuedMail ); |
133 | return true; | 133 | return true; |
134 | } | 134 | } |
135 | from = getFrom( mail ); | 135 | from = getFrom( mail ); |
136 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 136 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
137 | bool result = smtpSend(from,rcpts,data,size); | 137 | bool result = smtpSend(from,rcpts,data,size); |
138 | if (data) { | 138 | if (data) { |
139 | free(data); | 139 | free(data); |
140 | } | 140 | } |
141 | if (from) { | 141 | if (from) { |
142 | free(from); | 142 | free(from); |
143 | } | 143 | } |
144 | if (rcpts) | 144 | if (rcpts) |
145 | smtp_address_list_free( rcpts ); | 145 | smtp_address_list_free( rcpts ); |
146 | return result; | 146 | return result; |
147 | } | 147 | } |
148 | 148 | ||
149 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) | 149 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) |
150 | { | 150 | { |
151 | if (data) { | 151 | if (data) { |
152 | storeMail(data,size,"Sendfailed"); | 152 | storeMail(data,size,"Sendfailed"); |
153 | } | 153 | } |
154 | if (failuremessage) { | 154 | if (failuremessage) { |
155 | QMessageBox::critical(0,tr("Error sending mail"), | 155 | QMessageBox::critical(0,tr("Error sending mail"), |
156 | tr("<center>%1</center>").arg(failuremessage)); | 156 | tr("<center>%1</center>").arg(failuremessage)); |
157 | } | 157 | } |
158 | } | 158 | } |
159 | 159 | ||
160 | int SMTPwrapper::start_smtp_tls() | 160 | int SMTPwrapper::start_smtp_tls() |
161 | { | 161 | { |
162 | if (!m_smtp) { | 162 | if (!m_smtp) { |
163 | return MAILSMTP_ERROR_IN_PROCESSING; | 163 | return MAILSMTP_ERROR_IN_PROCESSING; |
164 | } | 164 | } |
165 | int err = mailesmtp_starttls(m_smtp); | 165 | int err = mailesmtp_starttls(m_smtp); |
166 | if (err != MAILSMTP_NO_ERROR) return err; | 166 | if (err != MAILSMTP_NO_ERROR) return err; |
167 | mailstream_low * low; | 167 | mailstream_low * low; |
168 | mailstream_low * new_low; | 168 | mailstream_low * new_low; |
169 | low = mailstream_get_low(m_smtp->stream); | 169 | low = mailstream_get_low(m_smtp->stream); |
170 | if (!low) { | 170 | if (!low) { |
171 | return MAILSMTP_ERROR_IN_PROCESSING; | 171 | return MAILSMTP_ERROR_IN_PROCESSING; |
172 | } | 172 | } |
173 | int fd = mailstream_low_get_fd(low); | 173 | int fd = mailstream_low_get_fd(low); |
174 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 174 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
175 | mailstream_low_free(low); | 175 | mailstream_low_free(low); |
176 | mailstream_set_low(m_smtp->stream, new_low); | 176 | mailstream_set_low(m_smtp->stream, new_low); |
177 | } else { | 177 | } else { |
178 | return MAILSMTP_ERROR_IN_PROCESSING; | 178 | return MAILSMTP_ERROR_IN_PROCESSING; |
179 | } | 179 | } |
180 | return err; | 180 | return err; |
181 | } | 181 | } |
182 | 182 | ||
183 | void SMTPwrapper::connect_server() | 183 | void SMTPwrapper::connect_server() |
184 | { | 184 | { |
185 | const char *server, *user, *pass; | 185 | QString server, user, pass; |
186 | bool ssl; | 186 | bool ssl; |
187 | uint16_t port; | 187 | uint16_t port; |
188 | ssl = false; | 188 | ssl = false; |
189 | bool try_tls = true; | 189 | bool try_tls = true; |
190 | bool force_tls=false; | 190 | bool force_tls=false; |
191 | server = user = pass = 0; | ||
192 | QString failuretext = ""; | 191 | QString failuretext = ""; |
193 | 192 | ||
194 | if (m_smtp || !m_SmtpAccount) { | 193 | if (m_smtp || !m_SmtpAccount) { |
195 | return; | 194 | return; |
196 | } | 195 | } |
197 | server = m_SmtpAccount->getServer().latin1(); | 196 | server = m_SmtpAccount->getServer(); |
198 | if ( m_SmtpAccount->ConnectionType() == 2 ) { | 197 | if ( m_SmtpAccount->ConnectionType() == 2 ) { |
199 | ssl = true; | 198 | ssl = true; |
200 | try_tls = false; | 199 | try_tls = false; |
201 | } else if (m_SmtpAccount->ConnectionType() == 1) { | 200 | } else if (m_SmtpAccount->ConnectionType() == 1) { |
202 | force_tls = true; | 201 | force_tls = true; |
203 | } | 202 | } |
204 | int result = 1; | 203 | int result = 1; |
205 | port = m_SmtpAccount->getPort().toUInt(); | 204 | port = m_SmtpAccount->getPort().toUInt(); |
206 | 205 | ||
207 | m_smtp = mailsmtp_new( 20, &progress ); | 206 | m_smtp = mailsmtp_new( 20, &progress ); |
208 | if ( m_smtp == NULL ) { | 207 | if ( m_smtp == NULL ) { |
209 | /* no failure message cause this happens when problems with memory - than we | 208 | /* no failure message cause this happens when problems with memory - than we |
210 | we can not display any messagebox */ | 209 | we can not display any messagebox */ |
211 | return; | 210 | return; |
212 | } | 211 | } |
213 | 212 | ||
214 | int err = MAILSMTP_NO_ERROR; | 213 | int err = MAILSMTP_NO_ERROR; |
215 | ; // odebug << "Servername " << server << " at port " << port << "" << oendl; | 214 | ; // odebug << "Servername " << server << " at port " << port << "" << oendl; |
216 | if ( ssl ) { | 215 | if ( ssl ) { |
217 | ; // odebug << "SSL session" << oendl; | 216 | ; // odebug << "SSL session" << oendl; |
218 | err = mailsmtp_ssl_connect( m_smtp, server, port ); | 217 | err = mailsmtp_ssl_connect( m_smtp, server.latin1(), port ); |
219 | } else { | 218 | } else { |
220 | ; // odebug << "No SSL session" << oendl; | 219 | ; // odebug << "No SSL session" << oendl; |
221 | err = mailsmtp_socket_connect( m_smtp, server, port ); | 220 | err = mailsmtp_socket_connect( m_smtp, server.latin1(), port ); |
222 | } | 221 | } |
223 | if ( err != MAILSMTP_NO_ERROR ) { | 222 | if ( err != MAILSMTP_NO_ERROR ) { |
224 | ; // odebug << "Error init connection" << oendl; | 223 | ; // odebug << "Error init connection" << oendl; |
225 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); | 224 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); |
226 | result = 0; | 225 | result = 0; |
227 | } | 226 | } |
228 | 227 | ||
229 | /* switch to tls after init 'cause there it will send the ehlo */ | 228 | /* switch to tls after init 'cause there it will send the ehlo */ |
230 | if (result) { | 229 | if (result) { |
231 | err = mailsmtp_init( m_smtp ); | 230 | err = mailsmtp_init( m_smtp ); |
232 | if (err != MAILSMTP_NO_ERROR) { | 231 | if (err != MAILSMTP_NO_ERROR) { |
233 | result = 0; | 232 | result = 0; |
234 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); | 233 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); |
235 | } | 234 | } |
236 | } | 235 | } |
237 | 236 | ||
238 | if (try_tls) { | 237 | if (try_tls) { |
239 | err = start_smtp_tls(); | 238 | err = start_smtp_tls(); |
240 | if (err != MAILSMTP_NO_ERROR) { | 239 | if (err != MAILSMTP_NO_ERROR) { |
241 | try_tls = false; | 240 | try_tls = false; |
242 | } else { | 241 | } else { |
243 | err = mailesmtp_ehlo(m_smtp); | 242 | err = mailesmtp_ehlo(m_smtp); |
244 | } | 243 | } |
245 | } | 244 | } |
246 | 245 | ||
247 | if (!try_tls && force_tls) { | 246 | if (!try_tls && force_tls) { |
248 | result = 0; | 247 | result = 0; |
249 | failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); | 248 | failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); |
250 | } | 249 | } |
251 | 250 | ||
252 | if (result==1 && m_SmtpAccount->getLogin() ) { | 251 | if (result==1 && m_SmtpAccount->getLogin() ) { |
253 | ; // odebug << "smtp with auth" << oendl; | 252 | ; // odebug << "smtp with auth" << oendl; |
254 | if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { | 253 | if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { |
255 | // get'em | 254 | // get'em |
256 | LoginDialog login( m_SmtpAccount->getUser(), | 255 | LoginDialog login( m_SmtpAccount->getUser(), |
257 | m_SmtpAccount->getPassword(), NULL, 0, true ); | 256 | m_SmtpAccount->getPassword(), NULL, 0, true ); |
258 | login.show(); | 257 | login.show(); |
259 | if ( QDialog::Accepted == login.exec() ) { | 258 | if ( QDialog::Accepted == login.exec() ) { |
260 | // ok | 259 | // ok |
261 | user = login.getUser().latin1(); | 260 | user = login.getUser(); |
262 | pass = login.getPassword().latin1(); | 261 | pass = login.getPassword(); |
263 | } else { | 262 | } else { |
264 | result = 0; | 263 | result = 0; |
265 | failuretext=tr("Login aborted - storing mail to localfolder"); | 264 | failuretext=tr("Login aborted - storing mail to localfolder"); |
266 | } | 265 | } |
267 | } else { | 266 | } else { |
268 | user = m_SmtpAccount->getUser().latin1(); | 267 | user = m_SmtpAccount->getUser(); |
269 | pass = m_SmtpAccount->getPassword().latin1(); | 268 | pass = m_SmtpAccount->getPassword(); |
270 | } | 269 | } |
271 | ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl; | 270 | ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl; |
272 | if (result) { | 271 | if (result) { |
273 | err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass ); | 272 | err = mailsmtp_auth( m_smtp, (char*)user.latin1(), (char*)pass.latin1() ); |
274 | if ( err == MAILSMTP_NO_ERROR ) { | 273 | if ( err == MAILSMTP_NO_ERROR ) { |
275 | ; // odebug << "auth ok" << oendl; | 274 | ; // odebug << "auth ok" << oendl; |
276 | } else { | 275 | } else { |
277 | failuretext = tr("Authentification failed"); | 276 | failuretext = tr("Authentification failed"); |
278 | result = 0; | 277 | result = 0; |
279 | } | 278 | } |
280 | } | 279 | } |
281 | } | 280 | } |
282 | } | 281 | } |
283 | 282 | ||
284 | void SMTPwrapper::disc_server() | 283 | void SMTPwrapper::disc_server() |
285 | { | 284 | { |
286 | if (m_smtp) { | 285 | if (m_smtp) { |
287 | mailsmtp_quit( m_smtp ); | 286 | mailsmtp_quit( m_smtp ); |
288 | mailsmtp_free( m_smtp ); | 287 | mailsmtp_free( m_smtp ); |
289 | m_smtp = 0; | 288 | m_smtp = 0; |
290 | } | 289 | } |
291 | } | 290 | } |
292 | 291 | ||
293 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) | 292 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) |
294 | { | 293 | { |
295 | int err,result; | 294 | int err,result; |
296 | QString failuretext = ""; | 295 | QString failuretext = ""; |
297 | 296 | ||
298 | connect_server(); | 297 | connect_server(); |
299 | 298 | ||
300 | result = 1; | 299 | result = 1; |
301 | if (m_smtp) { | 300 | if (m_smtp) { |
302 | err = mailsmtp_send( m_smtp, from, rcpts, data, size ); | 301 | err = mailsmtp_send( m_smtp, from, rcpts, data, size ); |
303 | if ( err != MAILSMTP_NO_ERROR ) { | 302 | if ( err != MAILSMTP_NO_ERROR ) { |
304 | failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); | 303 | failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); |
305 | result = 0; | 304 | result = 0; |
306 | } | 305 | } |
307 | } else { | 306 | } else { |
308 | result = 0; | 307 | result = 0; |
309 | } | 308 | } |
310 | 309 | ||
311 | if (!result) { | 310 | if (!result) { |
312 | storeFailedMail(data,size,failuretext); | 311 | storeFailedMail(data,size,failuretext); |
313 | } else { | 312 | } else { |
314 | ; // odebug << "Mail sent." << oendl; | 313 | ; // odebug << "Mail sent." << oendl; |
315 | storeMail(data,size,"Sent"); | 314 | storeMail(data,size,"Sent"); |
316 | } | 315 | } |
317 | return result; | 316 | return result; |
318 | } | 317 | } |
319 | 318 | ||
320 | bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) | 319 | bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) |
321 | { | 320 | { |
322 | mailmime * mimeMail; | 321 | mailmime * mimeMail; |
323 | bool result = true; | 322 | bool result = true; |
324 | mimeMail = createMimeMail(mail ); | 323 | mimeMail = createMimeMail(mail ); |
325 | if ( mimeMail == 0 ) { | 324 | if ( mimeMail == 0 ) { |
326 | qDebug("SMTP wrapper:Error creating mail! "); | 325 | qDebug("SMTP wrapper:Error creating mail! "); |
327 | return false; | 326 | return false; |
328 | } else { | 327 | } else { |
329 | sendProgress = new progressMailSend(); | 328 | sendProgress = new progressMailSend(); |
330 | sendProgress->show(); | 329 | sendProgress->show(); |
331 | sendProgress->setMaxMails(1); | 330 | sendProgress->setMaxMails(1); |
332 | result = smtpSend( mimeMail,later); | 331 | result = smtpSend( mimeMail,later); |
333 | ; // odebug << "Clean up done" << oendl; | 332 | ; // odebug << "Clean up done" << oendl; |
334 | sendProgress->hide(); | 333 | sendProgress->hide(); |
335 | delete sendProgress; | 334 | delete sendProgress; |
336 | sendProgress = 0; | 335 | sendProgress = 0; |
337 | mailmime_free( mimeMail ); | 336 | mailmime_free( mimeMail ); |
338 | } | 337 | } |
339 | return result; | 338 | return result; |
340 | } | 339 | } |
341 | 340 | ||
342 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { | 341 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { |
343 | size_t curTok = 0; | 342 | size_t curTok = 0; |
344 | mailimf_fields *fields = 0; | 343 | mailimf_fields *fields = 0; |
345 | mailimf_field*ffrom = 0; | 344 | mailimf_field*ffrom = 0; |
346 | clist *rcpts = 0; | 345 | clist *rcpts = 0; |
347 | char*from = 0; | 346 | char*from = 0; |
348 | int res = 0; | 347 | int res = 0; |
349 | 348 | ||
350 | encodedString * data = wrap->fetchRawBody(which); | 349 | encodedString * data = wrap->fetchRawBody(which); |
351 | if (!data) | 350 | if (!data) |
352 | return 0; | 351 | return 0; |
353 | int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); | 352 | int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); |
354 | if (err != MAILIMF_NO_ERROR) { | 353 | if (err != MAILIMF_NO_ERROR) { |
355 | delete data; | 354 | delete data; |
356 | delete wrap; | 355 | delete wrap; |
357 | return 0; | 356 | return 0; |
358 | } | 357 | } |
359 | 358 | ||
360 | rcpts = createRcptList( fields ); | 359 | rcpts = createRcptList( fields ); |
361 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); | 360 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); |
362 | from = getFrom(ffrom); | 361 | from = getFrom(ffrom); |
363 | 362 | ||
364 | if (rcpts && from) { | 363 | if (rcpts && from) { |
365 | res = smtpSend(from,rcpts,data->Content(),data->Length()); | 364 | res = smtpSend(from,rcpts,data->Content(),data->Length()); |
366 | } | 365 | } |
367 | if (fields) { | 366 | if (fields) { |
368 | mailimf_fields_free(fields); | 367 | mailimf_fields_free(fields); |
369 | fields = 0; | 368 | fields = 0; |