-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 17 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.h | 2 |
2 files changed, 13 insertions, 6 deletions
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index 93fb7de..09e52b8 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp | |||
@@ -102,49 +102,49 @@ bool IMAPwrapper::start_tls(bool force_tls) | |||
102 | err = mailimap_starttls(m_imap); | 102 | err = mailimap_starttls(m_imap); |
103 | if (err != MAILIMAP_NO_ERROR && force_tls) { | 103 | if (err != MAILIMAP_NO_ERROR && force_tls) { |
104 | Global::statusMessage(i18n("Server has no TLS support!")); | 104 | Global::statusMessage(i18n("Server has no TLS support!")); |
105 | try_tls = false; | 105 | try_tls = false; |
106 | } else { | 106 | } else { |
107 | mailstream_low * low; | 107 | mailstream_low * low; |
108 | mailstream_low * new_low; | 108 | mailstream_low * new_low; |
109 | low = mailstream_get_low(m_imap->imap_stream); | 109 | low = mailstream_get_low(m_imap->imap_stream); |
110 | if (!low) { | 110 | if (!low) { |
111 | try_tls = false; | 111 | try_tls = false; |
112 | } else { | 112 | } else { |
113 | int fd = mailstream_low_get_fd(low); | 113 | int fd = mailstream_low_get_fd(low); |
114 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 114 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
115 | mailstream_low_free(low); | 115 | mailstream_low_free(low); |
116 | mailstream_set_low(m_imap->imap_stream, new_low); | 116 | mailstream_set_low(m_imap->imap_stream, new_low); |
117 | } else { | 117 | } else { |
118 | try_tls = false; | 118 | try_tls = false; |
119 | } | 119 | } |
120 | } | 120 | } |
121 | } | 121 | } |
122 | } | 122 | } |
123 | return try_tls; | 123 | return try_tls; |
124 | } | 124 | } |
125 | 125 | ||
126 | void IMAPwrapper::login() | 126 | void IMAPwrapper::login(bool tryTLS) // = true) |
127 | { | 127 | { |
128 | QString server, user, pass; | 128 | QString server, user, pass; |
129 | uint16_t port; | 129 | uint16_t port; |
130 | int err = MAILIMAP_NO_ERROR; | 130 | int err = MAILIMAP_NO_ERROR; |
131 | 131 | ||
132 | if (account->getOffline()) return; | 132 | if (account->getOffline()) return; |
133 | /* we are connected this moment */ | 133 | /* we are connected this moment */ |
134 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 134 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
135 | if (m_imap) { | 135 | if (m_imap) { |
136 | err = mailimap_noop(m_imap); | 136 | err = mailimap_noop(m_imap); |
137 | if (err!=MAILIMAP_NO_ERROR) { | 137 | if (err!=MAILIMAP_NO_ERROR) { |
138 | logout(); | 138 | logout(); |
139 | } else { | 139 | } else { |
140 | mailstream_flush(m_imap->imap_stream); | 140 | mailstream_flush(m_imap->imap_stream); |
141 | return; | 141 | return; |
142 | } | 142 | } |
143 | } | 143 | } |
144 | server = account->getServer(); | 144 | server = account->getServer(); |
145 | port = account->getPort().toUInt(); | 145 | port = account->getPort().toUInt(); |
146 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 146 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
147 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 147 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
148 | login.show(); | 148 | login.show(); |
149 | if ( QDialog::Accepted == login.exec() ) { | 149 | if ( QDialog::Accepted == login.exec() ) { |
150 | // ok | 150 | // ok |
@@ -174,65 +174,72 @@ void IMAPwrapper::login() | |||
174 | } | 174 | } |
175 | 175 | ||
176 | if ( ssl ) { | 176 | if ( ssl ) { |
177 | qDebug("using ssl "); | 177 | qDebug("using ssl "); |
178 | err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); | 178 | err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); |
179 | qDebug("back "); | 179 | qDebug("back "); |
180 | } else { | 180 | } else { |
181 | err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); | 181 | err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); |
182 | } | 182 | } |
183 | 183 | ||
184 | if ( err != MAILIMAP_NO_ERROR && | 184 | if ( err != MAILIMAP_NO_ERROR && |
185 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 185 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
186 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 186 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
187 | QString failure = ""; | 187 | QString failure = ""; |
188 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 188 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
189 | failure="Connection refused"; | 189 | failure="Connection refused"; |
190 | } else { | 190 | } else { |
191 | failure="Unknown failure"; | 191 | failure="Unknown failure"; |
192 | } | 192 | } |
193 | Global::statusMessage(i18n("error connecting imap server: %1").arg(failure)); | 193 | Global::statusMessage(i18n("error connecting imap server: %1").arg(failure)); |
194 | mailimap_free( m_imap ); | 194 | mailimap_free( m_imap ); |
195 | m_imap = 0; | 195 | m_imap = 0; |
196 | return; | 196 | return; |
197 | } | 197 | } |
198 | 198 | if ( tryTLS ) { | |
199 | if (!ssl) { | 199 | if (!ssl) { |
200 | try_tls = start_tls(force_tls); | 200 | try_tls = start_tls(force_tls); |
201 | } | ||
201 | } | 202 | } |
202 | |||
203 | bool ok = true; | 203 | bool ok = true; |
204 | if (force_tls && !try_tls) { | 204 | if (force_tls && !try_tls) { |
205 | Global::statusMessage(i18n("Server has no TLS support!")); | 205 | Global::statusMessage(i18n("Server has no TLS support!")); |
206 | ok = false; | 206 | ok = false; |
207 | } | 207 | } |
208 | 208 | ||
209 | 209 | ||
210 | /* login */ | 210 | /* login */ |
211 | 211 | ||
212 | if (ok) { | 212 | if (ok) { |
213 | err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); | 213 | err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); |
214 | if ( err != MAILIMAP_NO_ERROR ) { | 214 | if ( err != MAILIMAP_NO_ERROR ) { |
215 | if ( tryTLS && !force_tls && !try_tls ) { | ||
216 | err = mailimap_close( m_imap ); | ||
217 | mailimap_free( m_imap ); | ||
218 | m_imap = 0; | ||
219 | login( false ); | ||
220 | return; | ||
221 | } | ||
215 | Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response)); | 222 | Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response)); |
216 | ok = false; | 223 | ok = false; |
217 | } | 224 | } |
218 | } | 225 | } |
219 | if (!ok) { | 226 | if (!ok) { |
220 | err = mailimap_close( m_imap ); | 227 | err = mailimap_close( m_imap ); |
221 | mailimap_free( m_imap ); | 228 | mailimap_free( m_imap ); |
222 | m_imap = 0; | 229 | m_imap = 0; |
223 | } | 230 | } |
224 | } | 231 | } |
225 | 232 | ||
226 | void IMAPwrapper::logout() | 233 | void IMAPwrapper::logout() |
227 | { | 234 | { |
228 | int err = MAILIMAP_NO_ERROR; | 235 | int err = MAILIMAP_NO_ERROR; |
229 | if (!m_imap) return; | 236 | if (!m_imap) return; |
230 | err = mailimap_logout( m_imap ); | 237 | err = mailimap_logout( m_imap ); |
231 | err = mailimap_close( m_imap ); | 238 | err = mailimap_close( m_imap ); |
232 | mailimap_free( m_imap ); | 239 | mailimap_free( m_imap ); |
233 | m_imap = 0; | 240 | m_imap = 0; |
234 | m_Lastmbox = ""; | 241 | m_Lastmbox = ""; |
235 | } | 242 | } |
236 | 243 | ||
237 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) | 244 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) |
238 | { | 245 | { |
diff --git a/kmicromail/libmailwrapper/imapwrapper.h b/kmicromail/libmailwrapper/imapwrapper.h index 5535d8d..31c60a8 100644 --- a/kmicromail/libmailwrapper/imapwrapper.h +++ b/kmicromail/libmailwrapper/imapwrapper.h | |||
@@ -35,49 +35,49 @@ public: | |||
35 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | 35 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); |
36 | virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, | 36 | virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, |
37 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit,int sizeInKb = 0); | 37 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit,int sizeInKb = 0); |
38 | virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | 38 | virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); |
39 | 39 | ||
40 | virtual RecBodyP fetchBody(const RecMailP&mail); | 40 | virtual RecBodyP fetchBody(const RecMailP&mail); |
41 | virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part); | 41 | virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part); |
42 | virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part); | 42 | virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part); |
43 | virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part); | 43 | virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part); |
44 | virtual encodedString* fetchRawBody(const RecMailP&mail); | 44 | virtual encodedString* fetchRawBody(const RecMailP&mail); |
45 | 45 | ||
46 | virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0, | 46 | virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0, |
47 | const QString& delemiter="/",bool getsubfolder=false); | 47 | const QString& delemiter="/",bool getsubfolder=false); |
48 | virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&folder); | 48 | virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&folder); |
49 | 49 | ||
50 | static void imap_progress( size_t current, size_t maximum ); | 50 | static void imap_progress( size_t current, size_t maximum ); |
51 | 51 | ||
52 | virtual void logout(); | 52 | virtual void logout(); |
53 | virtual MAILLIB::ATYPE getType()const; | 53 | virtual MAILLIB::ATYPE getType()const; |
54 | virtual const QString&getName()const; | 54 | virtual const QString&getName()const; |
55 | virtual Account* getAccount() { return account; }; | 55 | virtual Account* getAccount() { return account; }; |
56 | 56 | ||
57 | protected: | 57 | protected: |
58 | RecMail*parse_list_result(mailimap_msg_att*); | 58 | RecMail*parse_list_result(mailimap_msg_att*); |
59 | void login(); | 59 | void login(bool tryTLS = true); |
60 | bool start_tls(bool force=true); | 60 | bool start_tls(bool force=true); |
61 | 61 | ||
62 | virtual QString fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); | 62 | virtual QString fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); |
63 | virtual encodedString*fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call); | 63 | virtual encodedString*fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call); |
64 | int selectMbox(const QString&mbox); | 64 | int selectMbox(const QString&mbox); |
65 | 65 | ||
66 | void fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description); | 66 | void fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description); |
67 | void fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which); | 67 | void fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which); |
68 | void fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which); | 68 | void fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which); |
69 | void fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which); | 69 | void fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which); |
70 | void fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which); | 70 | void fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which); |
71 | void traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,int current_recursion,QValueList<int>recList,int current_count=1); | 71 | void traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,int current_recursion,QValueList<int>recList,int current_count=1); |
72 | 72 | ||
73 | /* just helpers */ | 73 | /* just helpers */ |
74 | static void fillBodyFields(RecPartP&target_part,mailimap_body_fields*which); | 74 | static void fillBodyFields(RecPartP&target_part,mailimap_body_fields*which); |
75 | static QStringList address_list_to_stringlist(clist*list); | 75 | static QStringList address_list_to_stringlist(clist*list); |
76 | 76 | ||
77 | static void progress(QString mess = QString::null); | 77 | static void progress(QString mess = QString::null); |
78 | static int mCurrent; | 78 | static int mCurrent; |
79 | static int mMax; | 79 | static int mMax; |
80 | IMAPaccount *account; | 80 | IMAPaccount *account; |
81 | mailimap *m_imap; | 81 | mailimap *m_imap; |
82 | QString m_Lastmbox; | 82 | QString m_Lastmbox; |
83 | }; | 83 | }; |