-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.cpp | 156 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.h | 12 | ||||
-rw-r--r-- | noncore/net/mail/mail.pro | 1 | ||||
-rw-r--r-- | noncore/net/mail/mailwrapper.cpp | 156 | ||||
-rw-r--r-- | noncore/net/mail/mailwrapper.h | 12 |
5 files changed, 168 insertions, 169 deletions
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp index 17bed65..13a3fd9 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp | |||
@@ -1,643 +1,643 @@ | |||
1 | #include <qfileinfo.h> | 1 | #include <qfileinfo.h> |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <sys/stat.h> | 3 | #include <sys/stat.h> |
4 | #include <sys/types.h> | 4 | #include <sys/types.h> |
5 | #include <unistd.h> | 5 | #include <unistd.h> |
6 | #include <fcntl.h> | 6 | #include <fcntl.h> |
7 | #include <string.h> | 7 | #include <string.h> |
8 | #include <qdir.h> | 8 | #include <qdir.h> |
9 | #include <qtextstream.h> | 9 | #include <qtextstream.h> |
10 | 10 | ||
11 | #include "mailwrapper.h" | 11 | #include "mailwrapper.h" |
12 | #include "logindialog.h" | 12 | #include "logindialog.h" |
13 | #include "mail.h" | 13 | //#include "mail.h" |
14 | #include "defines.h" | 14 | #include "defines.h" |
15 | 15 | ||
16 | Attachment::Attachment( DocLnk lnk ) | 16 | Attachment::Attachment( DocLnk lnk ) |
17 | { | 17 | { |
18 | doc = lnk; | 18 | doc = lnk; |
19 | size = QFileInfo( doc.file() ).size(); | 19 | size = QFileInfo( doc.file() ).size(); |
20 | } | 20 | } |
21 | 21 | ||
22 | Folder::Folder(const QString&tmp_name ) | 22 | Folder::Folder(const QString&tmp_name ) |
23 | { | 23 | { |
24 | name = tmp_name; | 24 | name = tmp_name; |
25 | nameDisplay = name; | 25 | nameDisplay = name; |
26 | 26 | ||
27 | for ( int pos = nameDisplay.find( '&' ); pos != -1; | 27 | for ( int pos = nameDisplay.find( '&' ); pos != -1; |
28 | pos = nameDisplay.find( '&' ) ) { | 28 | pos = nameDisplay.find( '&' ) ) { |
29 | int end = nameDisplay.find( '-' ); | 29 | int end = nameDisplay.find( '-' ); |
30 | if ( end == -1 || end <= pos ) break; | 30 | if ( end == -1 || end <= pos ) break; |
31 | QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 ); | 31 | QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 ); |
32 | // TODO: do real base64 decoding here ! | 32 | // TODO: do real base64 decoding here ! |
33 | if ( str64.compare( "APw" ) == 0 ) { | 33 | if ( str64.compare( "APw" ) == 0 ) { |
34 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" ); | 34 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" ); |
35 | } else if ( str64.compare( "APY" ) == 0 ) { | 35 | } else if ( str64.compare( "APY" ) == 0 ) { |
36 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" ); | 36 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" ); |
37 | } | 37 | } |
38 | } | 38 | } |
39 | 39 | ||
40 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); | 40 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); |
41 | } | 41 | } |
42 | 42 | ||
43 | MailWrapper::MailWrapper( Settings *s ) | 43 | MailWrapper::MailWrapper( Settings *s ) |
44 | : QObject() | 44 | : QObject() |
45 | { | 45 | { |
46 | settings = s; | 46 | settings = s; |
47 | } | 47 | } |
48 | 48 | ||
49 | QString MailWrapper::mailsmtpError( int errnum ) | 49 | QString MailWrapper::mailsmtpError( int errnum ) |
50 | { | 50 | { |
51 | switch ( errnum ) { | 51 | switch ( errnum ) { |
52 | case MAILSMTP_NO_ERROR: | 52 | case MAILSMTP_NO_ERROR: |
53 | return tr( "No error" ); | 53 | return tr( "No error" ); |
54 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 54 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
55 | return tr( "Unexpected error code" ); | 55 | return tr( "Unexpected error code" ); |
56 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 56 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
57 | return tr( "Service not available" ); | 57 | return tr( "Service not available" ); |
58 | case MAILSMTP_ERROR_STREAM: | 58 | case MAILSMTP_ERROR_STREAM: |
59 | return tr( "Stream error" ); | 59 | return tr( "Stream error" ); |
60 | case MAILSMTP_ERROR_HOSTNAME: | 60 | case MAILSMTP_ERROR_HOSTNAME: |
61 | return tr( "gethostname() failed" ); | 61 | return tr( "gethostname() failed" ); |
62 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 62 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
63 | return tr( "Not implemented" ); | 63 | return tr( "Not implemented" ); |
64 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 64 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
65 | return tr( "Error, action not taken" ); | 65 | return tr( "Error, action not taken" ); |
66 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 66 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
67 | return tr( "Data exceeds storage allocation" ); | 67 | return tr( "Data exceeds storage allocation" ); |
68 | case MAILSMTP_ERROR_IN_PROCESSING: | 68 | case MAILSMTP_ERROR_IN_PROCESSING: |
69 | return tr( "Error in processing" ); | 69 | return tr( "Error in processing" ); |
70 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 70 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
71 | // return tr( "Insufficient system storage" ); | 71 | // return tr( "Insufficient system storage" ); |
72 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 72 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
73 | return tr( "Mailbox unavailable" ); | 73 | return tr( "Mailbox unavailable" ); |
74 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 74 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
75 | return tr( "Mailbox name not allowed" ); | 75 | return tr( "Mailbox name not allowed" ); |
76 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 76 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
77 | return tr( "Bad command sequence" ); | 77 | return tr( "Bad command sequence" ); |
78 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 78 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
79 | return tr( "User not local" ); | 79 | return tr( "User not local" ); |
80 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 80 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
81 | return tr( "Transaction failed" ); | 81 | return tr( "Transaction failed" ); |
82 | case MAILSMTP_ERROR_MEMORY: | 82 | case MAILSMTP_ERROR_MEMORY: |
83 | return tr( "Memory error" ); | 83 | return tr( "Memory error" ); |
84 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 84 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
85 | return tr( "Connection refused" ); | 85 | return tr( "Connection refused" ); |
86 | default: | 86 | default: |
87 | return tr( "Unknown error code" ); | 87 | return tr( "Unknown error code" ); |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) | 91 | mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) |
92 | { | 92 | { |
93 | return mailimf_mailbox_new( strdup( name.latin1() ), | 93 | return mailimf_mailbox_new( strdup( name.latin1() ), |
94 | strdup( mail.latin1() ) ); | 94 | strdup( mail.latin1() ) ); |
95 | } | 95 | } |
96 | 96 | ||
97 | mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) | 97 | mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) |
98 | { | 98 | { |
99 | mailimf_address_list *addresses; | 99 | mailimf_address_list *addresses; |
100 | 100 | ||
101 | if ( addr.isEmpty() ) return NULL; | 101 | if ( addr.isEmpty() ) return NULL; |
102 | 102 | ||
103 | addresses = mailimf_address_list_new_empty(); | 103 | addresses = mailimf_address_list_new_empty(); |
104 | 104 | ||
105 | QStringList list = QStringList::split( ',', addr ); | 105 | QStringList list = QStringList::split( ',', addr ); |
106 | QStringList::Iterator it; | 106 | QStringList::Iterator it; |
107 | for ( it = list.begin(); it != list.end(); it++ ) { | 107 | for ( it = list.begin(); it != list.end(); it++ ) { |
108 | char *str = strdup( (*it).latin1() ); | 108 | char *str = strdup( (*it).latin1() ); |
109 | int err = mailimf_address_list_add_parse( addresses, str ); | 109 | int err = mailimf_address_list_add_parse( addresses, str ); |
110 | if ( err != MAILIMF_NO_ERROR ) { | 110 | if ( err != MAILIMF_NO_ERROR ) { |
111 | qDebug( "Error parsing" ); | 111 | qDebug( "Error parsing" ); |
112 | qDebug( *it ); | 112 | qDebug( *it ); |
113 | free( str ); | 113 | free( str ); |
114 | } else { | 114 | } else { |
115 | qDebug( "Parse success! :)" ); | 115 | qDebug( "Parse success! :)" ); |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | return addresses; | 119 | return addresses; |
120 | } | 120 | } |
121 | 121 | ||
122 | mailimf_fields *MailWrapper::createImfFields( Mail *mail ) | 122 | mailimf_fields *MailWrapper::createImfFields( Mail *mail ) |
123 | { | 123 | { |
124 | mailimf_fields *fields; | 124 | mailimf_fields *fields; |
125 | mailimf_field *xmailer; | 125 | mailimf_field *xmailer; |
126 | mailimf_mailbox *sender, *fromBox; | 126 | mailimf_mailbox *sender, *fromBox; |
127 | mailimf_mailbox_list *from; | 127 | mailimf_mailbox_list *from; |
128 | mailimf_address_list *to, *cc, *bcc, *reply; | 128 | mailimf_address_list *to, *cc, *bcc, *reply; |
129 | char *subject = strdup( mail->getSubject().latin1() ); | 129 | char *subject = strdup( mail->getSubject().latin1() ); |
130 | int err; | 130 | int err; |
131 | 131 | ||
132 | sender = newMailbox( mail->getName(), mail->getMail() ); | 132 | sender = newMailbox( mail->getName(), mail->getMail() ); |
133 | if ( sender == NULL ) goto err_free; | 133 | if ( sender == NULL ) goto err_free; |
134 | 134 | ||
135 | fromBox = newMailbox( mail->getName(), mail->getMail() ); | 135 | fromBox = newMailbox( mail->getName(), mail->getMail() ); |
136 | if ( fromBox == NULL ) goto err_free_sender; | 136 | if ( fromBox == NULL ) goto err_free_sender; |
137 | 137 | ||
138 | from = mailimf_mailbox_list_new_empty(); | 138 | from = mailimf_mailbox_list_new_empty(); |
139 | if ( from == NULL ) goto err_free_fromBox; | 139 | if ( from == NULL ) goto err_free_fromBox; |
140 | 140 | ||
141 | err = mailimf_mailbox_list_add( from, fromBox ); | 141 | err = mailimf_mailbox_list_add( from, fromBox ); |
142 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; | 142 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; |
143 | 143 | ||
144 | to = parseAddresses( mail->getTo() ); | 144 | to = parseAddresses( mail->getTo() ); |
145 | if ( to == NULL ) goto err_free_from; | 145 | if ( to == NULL ) goto err_free_from; |
146 | 146 | ||
147 | cc = parseAddresses( mail->getCC() ); | 147 | cc = parseAddresses( mail->getCC() ); |
148 | bcc = parseAddresses( mail->getBCC() ); | 148 | bcc = parseAddresses( mail->getBCC() ); |
149 | reply = parseAddresses( mail->getReply() ); | 149 | reply = parseAddresses( mail->getReply() ); |
150 | 150 | ||
151 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | 151 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, |
152 | NULL, NULL, subject ); | 152 | NULL, NULL, subject ); |
153 | if ( fields == NULL ) goto err_free_reply; | 153 | if ( fields == NULL ) goto err_free_reply; |
154 | 154 | ||
155 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 155 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), |
156 | strdup( USER_AGENT ) ); | 156 | strdup( USER_AGENT ) ); |
157 | if ( xmailer == NULL ) goto err_free_fields; | 157 | if ( xmailer == NULL ) goto err_free_fields; |
158 | 158 | ||
159 | err = mailimf_fields_add( fields, xmailer ); | 159 | err = mailimf_fields_add( fields, xmailer ); |
160 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; | 160 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; |
161 | 161 | ||
162 | return fields; // Success :) | 162 | return fields; // Success :) |
163 | 163 | ||
164 | err_free_xmailer: | 164 | err_free_xmailer: |
165 | mailimf_field_free( xmailer ); | 165 | mailimf_field_free( xmailer ); |
166 | err_free_fields: | 166 | err_free_fields: |
167 | mailimf_fields_free( fields ); | 167 | mailimf_fields_free( fields ); |
168 | err_free_reply: | 168 | err_free_reply: |
169 | mailimf_address_list_free( reply ); | 169 | mailimf_address_list_free( reply ); |
170 | mailimf_address_list_free( bcc ); | 170 | mailimf_address_list_free( bcc ); |
171 | mailimf_address_list_free( cc ); | 171 | mailimf_address_list_free( cc ); |
172 | mailimf_address_list_free( to ); | 172 | mailimf_address_list_free( to ); |
173 | err_free_from: | 173 | err_free_from: |
174 | mailimf_mailbox_list_free( from ); | 174 | mailimf_mailbox_list_free( from ); |
175 | err_free_fromBox: | 175 | err_free_fromBox: |
176 | mailimf_mailbox_free( fromBox ); | 176 | mailimf_mailbox_free( fromBox ); |
177 | err_free_sender: | 177 | err_free_sender: |
178 | mailimf_mailbox_free( sender ); | 178 | mailimf_mailbox_free( sender ); |
179 | err_free: | 179 | err_free: |
180 | free( subject ); | 180 | free( subject ); |
181 | qDebug( "createImfFields - error" ); | 181 | qDebug( "createImfFields - error" ); |
182 | 182 | ||
183 | return NULL; // Error :( | 183 | return NULL; // Error :( |
184 | } | 184 | } |
185 | 185 | ||
186 | mailmime *MailWrapper::buildTxtPart( QString str ) | 186 | mailmime *MailWrapper::buildTxtPart( QString str ) |
187 | { | 187 | { |
188 | mailmime *txtPart; | 188 | mailmime *txtPart; |
189 | mailmime_fields *fields; | 189 | mailmime_fields *fields; |
190 | mailmime_content *content; | 190 | mailmime_content *content; |
191 | mailmime_parameter *param; | 191 | mailmime_parameter *param; |
192 | char *txt = strdup( str.latin1() ); | 192 | char *txt = strdup( str.latin1() ); |
193 | int err; | 193 | int err; |
194 | 194 | ||
195 | param = mailmime_parameter_new( strdup( "charset" ), | 195 | param = mailmime_parameter_new( strdup( "charset" ), |
196 | strdup( "iso-8859-1" ) ); | 196 | strdup( "iso-8859-1" ) ); |
197 | if ( param == NULL ) goto err_free; | 197 | if ( param == NULL ) goto err_free; |
198 | 198 | ||
199 | content = mailmime_content_new_with_str( "text/plain" ); | 199 | content = mailmime_content_new_with_str( "text/plain" ); |
200 | if ( content == NULL ) goto err_free_param; | 200 | if ( content == NULL ) goto err_free_param; |
201 | 201 | ||
202 | err = clist_append( content->parameters, param ); | 202 | err = clist_append( content->parameters, param ); |
203 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | 203 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; |
204 | 204 | ||
205 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); | 205 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); |
206 | if ( fields == NULL ) goto err_free_content; | 206 | if ( fields == NULL ) goto err_free_content; |
207 | 207 | ||
208 | txtPart = mailmime_new_empty( content, fields ); | 208 | txtPart = mailmime_new_empty( content, fields ); |
209 | if ( txtPart == NULL ) goto err_free_fields; | 209 | if ( txtPart == NULL ) goto err_free_fields; |
210 | 210 | ||
211 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); | 211 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); |
212 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 212 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
213 | 213 | ||
214 | return txtPart; // Success :) | 214 | return txtPart; // Success :) |
215 | 215 | ||
216 | err_free_txtPart: | 216 | err_free_txtPart: |
217 | mailmime_free( txtPart ); | 217 | mailmime_free( txtPart ); |
218 | err_free_fields: | 218 | err_free_fields: |
219 | mailmime_fields_free( fields ); | 219 | mailmime_fields_free( fields ); |
220 | err_free_content: | 220 | err_free_content: |
221 | mailmime_content_free( content ); | 221 | mailmime_content_free( content ); |
222 | err_free_param: | 222 | err_free_param: |
223 | mailmime_parameter_free( param ); | 223 | mailmime_parameter_free( param ); |
224 | err_free: | 224 | err_free: |
225 | free( txt ); | 225 | free( txt ); |
226 | qDebug( "buildTxtPart - error" ); | 226 | qDebug( "buildTxtPart - error" ); |
227 | 227 | ||
228 | return NULL; // Error :( | 228 | return NULL; // Error :( |
229 | } | 229 | } |
230 | 230 | ||
231 | mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) | 231 | mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) |
232 | { | 232 | { |
233 | mailmime * filePart; | 233 | mailmime * filePart; |
234 | mailmime_fields * fields; | 234 | mailmime_fields * fields; |
235 | mailmime_content * content; | 235 | mailmime_content * content; |
236 | mailmime_parameter * param = NULL; | 236 | mailmime_parameter * param = NULL; |
237 | int err; | 237 | int err; |
238 | 238 | ||
239 | int pos = filename.findRev( '/' ); | 239 | int pos = filename.findRev( '/' ); |
240 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 240 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
241 | char *name = strdup( tmp.latin1() ); // just filename | 241 | char *name = strdup( tmp.latin1() ); // just filename |
242 | char *file = strdup( filename.latin1() ); // full name with path | 242 | char *file = strdup( filename.latin1() ); // full name with path |
243 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain | 243 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain |
244 | 244 | ||
245 | fields = mailmime_fields_new_filename( | 245 | fields = mailmime_fields_new_filename( |
246 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, | 246 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, |
247 | MAILMIME_MECHANISM_BASE64 ); | 247 | MAILMIME_MECHANISM_BASE64 ); |
248 | if ( fields == NULL ) goto err_free; | 248 | if ( fields == NULL ) goto err_free; |
249 | 249 | ||
250 | content = mailmime_content_new_with_str( mime ); | 250 | content = mailmime_content_new_with_str( mime ); |
251 | if ( content == NULL ) goto err_free_fields; | 251 | if ( content == NULL ) goto err_free_fields; |
252 | 252 | ||
253 | if ( mimetype.compare( "text/plain" ) == 0 ) { | 253 | if ( mimetype.compare( "text/plain" ) == 0 ) { |
254 | param = mailmime_parameter_new( strdup( "charset" ), | 254 | param = mailmime_parameter_new( strdup( "charset" ), |
255 | strdup( "iso-8859-1" ) ); | 255 | strdup( "iso-8859-1" ) ); |
256 | if ( param == NULL ) goto err_free_content; | 256 | if ( param == NULL ) goto err_free_content; |
257 | 257 | ||
258 | err = clist_append( content->parameters, param ); | 258 | err = clist_append( content->parameters, param ); |
259 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; | 259 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; |
260 | } | 260 | } |
261 | 261 | ||
262 | filePart = mailmime_new_empty( content, fields ); | 262 | filePart = mailmime_new_empty( content, fields ); |
263 | if ( filePart == NULL ) goto err_free_param; | 263 | if ( filePart == NULL ) goto err_free_param; |
264 | 264 | ||
265 | err = mailmime_set_body_file( filePart, file ); | 265 | err = mailmime_set_body_file( filePart, file ); |
266 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 266 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; |
267 | 267 | ||
268 | return filePart; // Success :) | 268 | return filePart; // Success :) |
269 | 269 | ||
270 | err_free_filePart: | 270 | err_free_filePart: |
271 | mailmime_free( filePart ); | 271 | mailmime_free( filePart ); |
272 | err_free_param: | 272 | err_free_param: |
273 | if ( param != NULL ) mailmime_parameter_free( param ); | 273 | if ( param != NULL ) mailmime_parameter_free( param ); |
274 | err_free_content: | 274 | err_free_content: |
275 | mailmime_content_free( content ); | 275 | mailmime_content_free( content ); |
276 | err_free_fields: | 276 | err_free_fields: |
277 | mailmime_fields_free( fields ); | 277 | mailmime_fields_free( fields ); |
278 | err_free: | 278 | err_free: |
279 | free( name ); | 279 | free( name ); |
280 | free( mime ); | 280 | free( mime ); |
281 | free( file ); | 281 | free( file ); |
282 | qDebug( "buildFilePart - error" ); | 282 | qDebug( "buildFilePart - error" ); |
283 | 283 | ||
284 | return NULL; // Error :( | 284 | return NULL; // Error :( |
285 | } | 285 | } |
286 | 286 | ||
287 | void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) | 287 | void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) |
288 | { | 288 | { |
289 | Attachment *it; | 289 | Attachment *it; |
290 | for ( it = files.first(); it; it = files.next() ) { | 290 | for ( it = files.first(); it; it = files.next() ) { |
291 | qDebug( "Adding file" ); | 291 | qDebug( "Adding file" ); |
292 | mailmime *filePart; | 292 | mailmime *filePart; |
293 | int err; | 293 | int err; |
294 | 294 | ||
295 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); | 295 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); |
296 | if ( filePart == NULL ) goto err_free; | 296 | if ( filePart == NULL ) goto err_free; |
297 | 297 | ||
298 | err = mailmime_smart_add_part( message, filePart ); | 298 | err = mailmime_smart_add_part( message, filePart ); |
299 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 299 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; |
300 | 300 | ||
301 | continue; // Success :) | 301 | continue; // Success :) |
302 | 302 | ||
303 | err_free_filePart: | 303 | err_free_filePart: |
304 | mailmime_free( filePart ); | 304 | mailmime_free( filePart ); |
305 | err_free: | 305 | err_free: |
306 | qDebug( "addFileParts: error adding file:" ); | 306 | qDebug( "addFileParts: error adding file:" ); |
307 | qDebug( it->getFileName() ); | 307 | qDebug( it->getFileName() ); |
308 | } | 308 | } |
309 | } | 309 | } |
310 | 310 | ||
311 | mailmime *MailWrapper::createMimeMail( Mail *mail ) | 311 | mailmime *MailWrapper::createMimeMail( Mail *mail ) |
312 | { | 312 | { |
313 | mailmime *message, *txtPart; | 313 | mailmime *message, *txtPart; |
314 | mailimf_fields *fields; | 314 | mailimf_fields *fields; |
315 | int err; | 315 | int err; |
316 | 316 | ||
317 | fields = createImfFields( mail ); | 317 | fields = createImfFields( mail ); |
318 | if ( fields == NULL ) goto err_free; | 318 | if ( fields == NULL ) goto err_free; |
319 | 319 | ||
320 | message = mailmime_new_message_data( NULL ); | 320 | message = mailmime_new_message_data( NULL ); |
321 | if ( message == NULL ) goto err_free_fields; | 321 | if ( message == NULL ) goto err_free_fields; |
322 | 322 | ||
323 | mailmime_set_imf_fields( message, fields ); | 323 | mailmime_set_imf_fields( message, fields ); |
324 | 324 | ||
325 | txtPart = buildTxtPart( mail->getMessage() ); | 325 | txtPart = buildTxtPart( mail->getMessage() ); |
326 | if ( txtPart == NULL ) goto err_free_message; | 326 | if ( txtPart == NULL ) goto err_free_message; |
327 | 327 | ||
328 | err = mailmime_smart_add_part( message, txtPart ); | 328 | err = mailmime_smart_add_part( message, txtPart ); |
329 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 329 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
330 | 330 | ||
331 | addFileParts( message, mail->getAttachments() ); | 331 | addFileParts( message, mail->getAttachments() ); |
332 | 332 | ||
333 | return message; // Success :) | 333 | return message; // Success :) |
334 | 334 | ||
335 | err_free_txtPart: | 335 | err_free_txtPart: |
336 | mailmime_free( txtPart ); | 336 | mailmime_free( txtPart ); |
337 | err_free_message: | 337 | err_free_message: |
338 | mailmime_free( message ); | 338 | mailmime_free( message ); |
339 | err_free_fields: | 339 | err_free_fields: |
340 | mailimf_fields_free( fields ); | 340 | mailimf_fields_free( fields ); |
341 | err_free: | 341 | err_free: |
342 | qDebug( "createMimeMail: error" ); | 342 | qDebug( "createMimeMail: error" ); |
343 | 343 | ||
344 | return NULL; // Error :( | 344 | return NULL; // Error :( |
345 | } | 345 | } |
346 | 346 | ||
347 | mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) | 347 | mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) |
348 | { | 348 | { |
349 | mailimf_field *field; | 349 | mailimf_field *field; |
350 | clistiter *it; | 350 | clistiter *it; |
351 | 351 | ||
352 | it = clist_begin( fields->list ); | 352 | it = clist_begin( fields->list ); |
353 | while ( it ) { | 353 | while ( it ) { |
354 | field = (mailimf_field *) it->data; | 354 | field = (mailimf_field *) it->data; |
355 | if ( field->type == type ) { | 355 | if ( field->type == type ) { |
356 | return field; | 356 | return field; |
357 | } | 357 | } |
358 | it = it->next; | 358 | it = it->next; |
359 | } | 359 | } |
360 | 360 | ||
361 | return NULL; | 361 | return NULL; |
362 | } | 362 | } |
363 | 363 | ||
364 | static void addRcpts( clist *list, mailimf_address_list *addr_list ) | 364 | static void addRcpts( clist *list, mailimf_address_list *addr_list ) |
365 | { | 365 | { |
366 | clistiter *it, *it2; | 366 | clistiter *it, *it2; |
367 | 367 | ||
368 | for ( it = clist_begin( addr_list->list ); it; it = it->next ) { | 368 | for ( it = clist_begin( addr_list->list ); it; it = it->next ) { |
369 | mailimf_address *addr; | 369 | mailimf_address *addr; |
370 | addr = (mailimf_address *) it->data; | 370 | addr = (mailimf_address *) it->data; |
371 | 371 | ||
372 | if ( addr->type == MAILIMF_ADDRESS_MAILBOX ) { | 372 | if ( addr->type == MAILIMF_ADDRESS_MAILBOX ) { |
373 | esmtp_address_list_add( list, addr->mailbox->addr_spec, 0, NULL ); | 373 | esmtp_address_list_add( list, addr->mailbox->addr_spec, 0, NULL ); |
374 | } else if ( addr->type == MAILIMF_ADDRESS_GROUP ) { | 374 | } else if ( addr->type == MAILIMF_ADDRESS_GROUP ) { |
375 | clist *l = addr->group->mb_list->list; | 375 | clist *l = addr->group->mb_list->list; |
376 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | 376 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { |
377 | mailimf_mailbox *mbox; | 377 | mailimf_mailbox *mbox; |
378 | mbox = (mailimf_mailbox *) it2->data; | 378 | mbox = (mailimf_mailbox *) it2->data; |
379 | esmtp_address_list_add( list, mbox->addr_spec, 0, NULL ); | 379 | esmtp_address_list_add( list, mbox->addr_spec, 0, NULL ); |
380 | } | 380 | } |
381 | } | 381 | } |
382 | } | 382 | } |
383 | } | 383 | } |
384 | 384 | ||
385 | clist *MailWrapper::createRcptList( mailimf_fields *fields ) | 385 | clist *MailWrapper::createRcptList( mailimf_fields *fields ) |
386 | { | 386 | { |
387 | clist *rcptList; | 387 | clist *rcptList; |
388 | mailimf_field *field; | 388 | mailimf_field *field; |
389 | 389 | ||
390 | rcptList = esmtp_address_list_new(); | 390 | rcptList = esmtp_address_list_new(); |
391 | 391 | ||
392 | field = getField( fields, MAILIMF_FIELD_TO ); | 392 | field = getField( fields, MAILIMF_FIELD_TO ); |
393 | if ( field && (field->type == MAILIMF_FIELD_TO) | 393 | if ( field && (field->type == MAILIMF_FIELD_TO) |
394 | && field->field.to->addr_list ) { | 394 | && field->field.to->addr_list ) { |
395 | addRcpts( rcptList, field->field.to->addr_list ); | 395 | addRcpts( rcptList, field->field.to->addr_list ); |
396 | } | 396 | } |
397 | 397 | ||
398 | field = getField( fields, MAILIMF_FIELD_CC ); | 398 | field = getField( fields, MAILIMF_FIELD_CC ); |
399 | if ( field && (field->type == MAILIMF_FIELD_CC) | 399 | if ( field && (field->type == MAILIMF_FIELD_CC) |
400 | && field->field.cc->addr_list ) { | 400 | && field->field.cc->addr_list ) { |
401 | addRcpts( rcptList, field->field.cc->addr_list ); | 401 | addRcpts( rcptList, field->field.cc->addr_list ); |
402 | } | 402 | } |
403 | 403 | ||
404 | field = getField( fields, MAILIMF_FIELD_BCC ); | 404 | field = getField( fields, MAILIMF_FIELD_BCC ); |
405 | if ( field && (field->type == MAILIMF_FIELD_BCC) | 405 | if ( field && (field->type == MAILIMF_FIELD_BCC) |
406 | && field->field.bcc->addr_list ) { | 406 | && field->field.bcc->addr_list ) { |
407 | addRcpts( rcptList, field->field.bcc->addr_list ); | 407 | addRcpts( rcptList, field->field.bcc->addr_list ); |
408 | } | 408 | } |
409 | 409 | ||
410 | return rcptList; | 410 | return rcptList; |
411 | } | 411 | } |
412 | 412 | ||
413 | char *MailWrapper::getFrom( mailmime *mail ) | 413 | char *MailWrapper::getFrom( mailmime *mail ) |
414 | { | 414 | { |
415 | char *from = NULL; | 415 | char *from = NULL; |
416 | 416 | ||
417 | mailimf_field *ffrom; | 417 | mailimf_field *ffrom; |
418 | ffrom = getField( mail->fields, MAILIMF_FIELD_FROM ); | 418 | ffrom = getField( mail->fields, MAILIMF_FIELD_FROM ); |
419 | if ( ffrom && (ffrom->type == MAILIMF_FIELD_FROM) | 419 | if ( ffrom && (ffrom->type == MAILIMF_FIELD_FROM) |
420 | && ffrom->field.from->mb_list && ffrom->field.from->mb_list->list ) { | 420 | && ffrom->field.from->mb_list && ffrom->field.from->mb_list->list ) { |
421 | clist *cl = ffrom->field.from->mb_list->list; | 421 | clist *cl = ffrom->field.from->mb_list->list; |
422 | clistiter *it; | 422 | clistiter *it; |
423 | for ( it = clist_begin( cl ); it; it = it->next ) { | 423 | for ( it = clist_begin( cl ); it; it = it->next ) { |
424 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 424 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
425 | from = strdup( mb->addr_spec ); | 425 | from = strdup( mb->addr_spec ); |
426 | } | 426 | } |
427 | } | 427 | } |
428 | 428 | ||
429 | return from; | 429 | return from; |
430 | } | 430 | } |
431 | 431 | ||
432 | SMTPaccount *MailWrapper::getAccount( QString from ) | 432 | SMTPaccount *MailWrapper::getAccount( QString from ) |
433 | { | 433 | { |
434 | SMTPaccount *smtp; | 434 | SMTPaccount *smtp; |
435 | 435 | ||
436 | QList<Account> list = settings->getAccounts(); | 436 | QList<Account> list = settings->getAccounts(); |
437 | Account *it; | 437 | Account *it; |
438 | for ( it = list.first(); it; it = list.next() ) { | 438 | for ( it = list.first(); it; it = list.next() ) { |
439 | if ( it->getType().compare( "SMTP" ) == 0 ) { | 439 | if ( it->getType().compare( "SMTP" ) == 0 ) { |
440 | smtp = static_cast<SMTPaccount *>(it); | 440 | smtp = static_cast<SMTPaccount *>(it); |
441 | if ( smtp->getMail().compare( from ) == 0 ) { | 441 | if ( smtp->getMail().compare( from ) == 0 ) { |
442 | qDebug( "SMTPaccount found for" ); | 442 | qDebug( "SMTPaccount found for" ); |
443 | qDebug( from ); | 443 | qDebug( from ); |
444 | return smtp; | 444 | return smtp; |
445 | } | 445 | } |
446 | } | 446 | } |
447 | } | 447 | } |
448 | 448 | ||
449 | return NULL; | 449 | return NULL; |
450 | } | 450 | } |
451 | 451 | ||
452 | QString MailWrapper::getTmpFile() { | 452 | QString MailWrapper::getTmpFile() { |
453 | int num = 0; | 453 | int num = 0; |
454 | QString unique; | 454 | QString unique; |
455 | 455 | ||
456 | QDir dir( "/tmp" ); | 456 | QDir dir( "/tmp" ); |
457 | QStringList::Iterator it; | 457 | QStringList::Iterator it; |
458 | 458 | ||
459 | QStringList list = dir.entryList( "opiemail-tmp-*" ); | 459 | QStringList list = dir.entryList( "opiemail-tmp-*" ); |
460 | do { | 460 | do { |
461 | unique.setNum( num++ ); | 461 | unique.setNum( num++ ); |
462 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); | 462 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); |
463 | 463 | ||
464 | return "/tmp/opiemail-tmp-" + unique; | 464 | return "/tmp/opiemail-tmp-" + unique; |
465 | } | 465 | } |
466 | 466 | ||
467 | void MailWrapper::writeToFile( QString file, mailmime *mail ) | 467 | void MailWrapper::writeToFile( QString file, mailmime *mail ) |
468 | { | 468 | { |
469 | FILE *f; | 469 | FILE *f; |
470 | int err, col = 0; | 470 | int err, col = 0; |
471 | 471 | ||
472 | f = fopen( file.latin1(), "w" ); | 472 | f = fopen( file.latin1(), "w" ); |
473 | if ( f == NULL ) { | 473 | if ( f == NULL ) { |
474 | qDebug( "writeToFile: error opening file" ); | 474 | qDebug( "writeToFile: error opening file" ); |
475 | return; | 475 | return; |
476 | } | 476 | } |
477 | 477 | ||
478 | err = mailmime_write( f, &col, mail ); | 478 | err = mailmime_write( f, &col, mail ); |
479 | if ( err != MAILIMF_NO_ERROR ) { | 479 | if ( err != MAILIMF_NO_ERROR ) { |
480 | fclose( f ); | 480 | fclose( f ); |
481 | qDebug( "writeToFile: error writing mailmime" ); | 481 | qDebug( "writeToFile: error writing mailmime" ); |
482 | return; | 482 | return; |
483 | } | 483 | } |
484 | 484 | ||
485 | fclose( f ); | 485 | fclose( f ); |
486 | } | 486 | } |
487 | 487 | ||
488 | void MailWrapper::readFromFile( QString file, char **data, size_t *size ) | 488 | void MailWrapper::readFromFile( QString file, char **data, size_t *size ) |
489 | { | 489 | { |
490 | char *buf; | 490 | char *buf; |
491 | struct stat st; | 491 | struct stat st; |
492 | int fd, count = 0, total = 0; | 492 | int fd, count = 0, total = 0; |
493 | 493 | ||
494 | fd = open( file.latin1(), O_RDONLY, 0 ); | 494 | fd = open( file.latin1(), O_RDONLY, 0 ); |
495 | if ( fd == -1 ) return; | 495 | if ( fd == -1 ) return; |
496 | 496 | ||
497 | if ( fstat( fd, &st ) != 0 ) goto err_close; | 497 | if ( fstat( fd, &st ) != 0 ) goto err_close; |
498 | if ( !st.st_size ) goto err_close; | 498 | if ( !st.st_size ) goto err_close; |
499 | 499 | ||
500 | buf = (char *) malloc( st.st_size ); | 500 | buf = (char *) malloc( st.st_size ); |
501 | if ( !buf ) goto err_close; | 501 | if ( !buf ) goto err_close; |
502 | 502 | ||
503 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { | 503 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { |
504 | count = read( fd, buf + total, st.st_size - total ); | 504 | count = read( fd, buf + total, st.st_size - total ); |
505 | total += count; | 505 | total += count; |
506 | } | 506 | } |
507 | if ( count < 0 ) goto err_free; | 507 | if ( count < 0 ) goto err_free; |
508 | 508 | ||
509 | *data = buf; | 509 | *data = buf; |
510 | *size = st.st_size; | 510 | *size = st.st_size; |
511 | 511 | ||
512 | close( fd ); | 512 | close( fd ); |
513 | 513 | ||
514 | return; // Success :) | 514 | return; // Success :) |
515 | 515 | ||
516 | err_free: | 516 | err_free: |
517 | free( buf ); | 517 | free( buf ); |
518 | err_close: | 518 | err_close: |
519 | close( fd ); | 519 | close( fd ); |
520 | } | 520 | } |
521 | 521 | ||
522 | void progress( size_t current, size_t maximum ) | 522 | void progress( size_t current, size_t maximum ) |
523 | { | 523 | { |
524 | qDebug( "Current: %i of %i", current, maximum ); | 524 | qDebug( "Current: %i of %i", current, maximum ); |
525 | } | 525 | } |
526 | 526 | ||
527 | void MailWrapper::smtpSend( mailmime *mail ) | 527 | void MailWrapper::smtpSend( mailmime *mail ) |
528 | { | 528 | { |
529 | mailsmtp *session; | 529 | mailsmtp *session; |
530 | clist *rcpts; | 530 | clist *rcpts; |
531 | char *from, *data, *server, *user = NULL, *pass = NULL; | 531 | char *from, *data, *server, *user = NULL, *pass = NULL; |
532 | size_t size; | 532 | size_t size; |
533 | int err; | 533 | int err; |
534 | bool ssl; | 534 | bool ssl; |
535 | uint16_t port; | 535 | uint16_t port; |
536 | 536 | ||
537 | 537 | ||
538 | from = getFrom( mail ); | 538 | from = getFrom( mail ); |
539 | SMTPaccount *smtp = getAccount( from ); | 539 | SMTPaccount *smtp = getAccount( from ); |
540 | if ( smtp == NULL ) { | 540 | if ( smtp == NULL ) { |
541 | free(from); | 541 | free(from); |
542 | return; | 542 | return; |
543 | } | 543 | } |
544 | server = strdup( smtp->getServer().latin1() ); | 544 | server = strdup( smtp->getServer().latin1() ); |
545 | ssl = smtp->getSSL(); | 545 | ssl = smtp->getSSL(); |
546 | port = smtp->getPort().toUInt(); | 546 | port = smtp->getPort().toUInt(); |
547 | rcpts = createRcptList( mail->fields ); | 547 | rcpts = createRcptList( mail->fields ); |
548 | 548 | ||
549 | QString file = getTmpFile(); | 549 | QString file = getTmpFile(); |
550 | writeToFile( file, mail ); | 550 | writeToFile( file, mail ); |
551 | readFromFile( file, &data, &size ); | 551 | readFromFile( file, &data, &size ); |
552 | QFile f( file ); | 552 | QFile f( file ); |
553 | f.remove(); | 553 | f.remove(); |
554 | 554 | ||
555 | session = mailsmtp_new( 20, &progress ); | 555 | session = mailsmtp_new( 20, &progress ); |
556 | if ( session == NULL ) goto free_mem; | 556 | if ( session == NULL ) goto free_mem; |
557 | 557 | ||
558 | qDebug( "Servername %s at port %i", server, port ); | 558 | qDebug( "Servername %s at port %i", server, port ); |
559 | if ( ssl ) { | 559 | if ( ssl ) { |
560 | qDebug( "SSL session" ); | 560 | qDebug( "SSL session" ); |
561 | err = mailsmtp_ssl_connect( session, server, port ); | 561 | err = mailsmtp_ssl_connect( session, server, port ); |
562 | } else { | 562 | } else { |
563 | qDebug( "No SSL session" ); | 563 | qDebug( "No SSL session" ); |
564 | err = mailsmtp_socket_connect( session, server, port ); | 564 | err = mailsmtp_socket_connect( session, server, port ); |
565 | } | 565 | } |
566 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; | 566 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; |
567 | 567 | ||
568 | err = mailsmtp_init( session ); | 568 | err = mailsmtp_init( session ); |
569 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 569 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; |
570 | 570 | ||
571 | qDebug( "INIT OK" ); | 571 | qDebug( "INIT OK" ); |
572 | 572 | ||
573 | if ( smtp->getLogin() ) { | 573 | if ( smtp->getLogin() ) { |
574 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | 574 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { |
575 | // get'em | 575 | // get'em |
576 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | 576 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); |
577 | login.show(); | 577 | login.show(); |
578 | if ( QDialog::Accepted == login.exec() ) { | 578 | if ( QDialog::Accepted == login.exec() ) { |
579 | // ok | 579 | // ok |
580 | user = strdup( login.getUser().latin1() ); | 580 | user = strdup( login.getUser().latin1() ); |
581 | pass = strdup( login.getPassword().latin1() ); | 581 | pass = strdup( login.getPassword().latin1() ); |
582 | } else { | 582 | } else { |
583 | goto free_con_session; | 583 | goto free_con_session; |
584 | } | 584 | } |
585 | } else { | 585 | } else { |
586 | user = strdup( smtp->getUser().latin1() ); | 586 | user = strdup( smtp->getUser().latin1() ); |
587 | pass = strdup( smtp->getPassword().latin1() ); | 587 | pass = strdup( smtp->getPassword().latin1() ); |
588 | } | 588 | } |
589 | qDebug( "session->auth: %i", session->auth); | 589 | qDebug( "session->auth: %i", session->auth); |
590 | err = mailsmtp_auth( session, user, pass ); | 590 | err = mailsmtp_auth( session, user, pass ); |
591 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); | 591 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); |
592 | qDebug( "Done auth!" ); | 592 | qDebug( "Done auth!" ); |
593 | } | 593 | } |
594 | 594 | ||
595 | err = mailsmtp_send( session, from, rcpts, data, size ); | 595 | err = mailsmtp_send( session, from, rcpts, data, size ); |
596 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 596 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; |
597 | 597 | ||
598 | qDebug( "Mail sent." ); | 598 | qDebug( "Mail sent." ); |
599 | 599 | ||
600 | free_con_session: | 600 | free_con_session: |
601 | mailsmtp_quit( session ); | 601 | mailsmtp_quit( session ); |
602 | free_mem_session: | 602 | free_mem_session: |
603 | mailsmtp_free( session ); | 603 | mailsmtp_free( session ); |
604 | free_mem: | 604 | free_mem: |
605 | smtp_address_list_free( rcpts ); | 605 | smtp_address_list_free( rcpts ); |
606 | free( data ); | 606 | free( data ); |
607 | free( server ); | 607 | free( server ); |
608 | if ( smtp->getLogin() ) { | 608 | if ( smtp->getLogin() ) { |
609 | free( user ); | 609 | free( user ); |
610 | free( pass ); | 610 | free( pass ); |
611 | } | 611 | } |
612 | free( from ); | 612 | free( from ); |
613 | } | 613 | } |
614 | 614 | ||
615 | void MailWrapper::sendMail( Mail mail ) | 615 | void MailWrapper::sendMail( Mail mail ) |
616 | { | 616 | { |
617 | mailmime *mimeMail; | 617 | mailmime *mimeMail; |
618 | 618 | ||
619 | mimeMail = createMimeMail( &mail ); | 619 | mimeMail = createMimeMail( &mail ); |
620 | if ( mimeMail == NULL ) { | 620 | if ( mimeMail == NULL ) { |
621 | qDebug( "sendMail: error creating mime mail" ); | 621 | qDebug( "sendMail: error creating mime mail" ); |
622 | } else { | 622 | } else { |
623 | smtpSend( mimeMail ); | 623 | smtpSend( mimeMail ); |
624 | mailmime_free( mimeMail ); | 624 | mailmime_free( mimeMail ); |
625 | } | 625 | } |
626 | } | 626 | } |
627 | 627 | ||
628 | Mail::Mail() | 628 | Mail::Mail() |
629 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") | 629 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") |
630 | { | 630 | { |
631 | } | 631 | } |
632 | 632 | ||
633 | RecMail::RecMail() | 633 | RecMail::RecMail() |
634 | :subject(""),date(""),msg_number(0),msg_flags(7) | 634 | :subject(""),date(""),msg_number(0),msg_flags(7) |
635 | { | 635 | { |
636 | } | 636 | } |
637 | 637 | ||
638 | #if 0 | 638 | #if 0 |
639 | void RecMail::setDate(const QString&aDate) | 639 | void RecMail::setDate(const QString&aDate) |
640 | { | 640 | { |
641 | mDate = QDateTime::fromString(aDate); | 641 | mDate = QDateTime::fromString(aDate); |
642 | } | 642 | } |
643 | #endif | 643 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h index 3de28a0..f45eab7 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.h +++ b/noncore/net/mail/libmailwrapper/mailwrapper.h | |||
@@ -1,183 +1,183 @@ | |||
1 | #ifndef MAILWRAPPER_H | 1 | #ifndef MAILWRAPPER_H |
2 | #define MAILWRAPPER_H | 2 | #define MAILWRAPPER_H |
3 | 3 | ||
4 | #include <qpe/applnk.h> | 4 | #include <qpe/applnk.h> |
5 | 5 | ||
6 | #include <mailmime.h> | 6 | #include <libetpan/mailmime.h> |
7 | #include <mailimf.h> | 7 | #include <libetpan/mailimf.h> |
8 | #include <mailsmtp.h> | 8 | #include <libetpan/mailsmtp.h> |
9 | #include <mailimap.h> | 9 | #include <libetpan/mailimap.h> |
10 | #include <mailstorage.h> | 10 | #include <libetpan/mailstorage.h> |
11 | #include <maildriver.h> | 11 | #include <libetpan/maildriver.h> |
12 | #include <qbitarray.h> | 12 | #include <qbitarray.h> |
13 | #include <qdatetime.h> | 13 | #include <qdatetime.h> |
14 | 14 | ||
15 | #include "settings.h" | 15 | #include "settings.h" |
16 | 16 | ||
17 | class Attachment | 17 | class Attachment |
18 | { | 18 | { |
19 | public: | 19 | public: |
20 | Attachment( DocLnk lnk ); | 20 | Attachment( DocLnk lnk ); |
21 | virtual ~Attachment(){} | 21 | virtual ~Attachment(){} |
22 | const QString getFileName()const{ return doc.file(); } | 22 | const QString getFileName()const{ return doc.file(); } |
23 | const QString getName()const{ return doc.name(); } | 23 | const QString getName()const{ return doc.name(); } |
24 | const QString getMimeType()const{ return doc.type(); } | 24 | const QString getMimeType()const{ return doc.type(); } |
25 | const QPixmap getPixmap()const{ return doc.pixmap(); } | 25 | const QPixmap getPixmap()const{ return doc.pixmap(); } |
26 | const int getSize()const { return size; } | 26 | const int getSize()const { return size; } |
27 | DocLnk getDocLnk() { return doc; } | 27 | DocLnk getDocLnk() { return doc; } |
28 | 28 | ||
29 | protected: | 29 | protected: |
30 | DocLnk doc; | 30 | DocLnk doc; |
31 | int size; | 31 | int size; |
32 | 32 | ||
33 | }; | 33 | }; |
34 | 34 | ||
35 | #define FLAG_ANSWERED 0 | 35 | #define FLAG_ANSWERED 0 |
36 | #define FLAG_FLAGGED 1 | 36 | #define FLAG_FLAGGED 1 |
37 | #define FLAG_DELETED 2 | 37 | #define FLAG_DELETED 2 |
38 | #define FLAG_SEEN 3 | 38 | #define FLAG_SEEN 3 |
39 | #define FLAG_DRAFT 4 | 39 | #define FLAG_DRAFT 4 |
40 | #define FLAG_RECENT 5 | 40 | #define FLAG_RECENT 5 |
41 | 41 | ||
42 | /* a class to describe mails in a mailbox */ | 42 | /* a class to describe mails in a mailbox */ |
43 | class RecMail | 43 | class RecMail |
44 | { | 44 | { |
45 | public: | 45 | public: |
46 | RecMail(); | 46 | RecMail(); |
47 | virtual ~RecMail(){} | 47 | virtual ~RecMail(){} |
48 | 48 | ||
49 | const int getNumber()const{return msg_number;} | 49 | const int getNumber()const{return msg_number;} |
50 | void setNumber(int number){msg_number=number;} | 50 | void setNumber(int number){msg_number=number;} |
51 | const QString&getDate()const{ return date; } | 51 | const QString&getDate()const{ return date; } |
52 | void setDate( const QString&a ) { date = a; } | 52 | void setDate( const QString&a ) { date = a; } |
53 | const QString&getFrom()const{ return from; } | 53 | const QString&getFrom()const{ return from; } |
54 | void setFrom( const QString&a ) { from = a; } | 54 | void setFrom( const QString&a ) { from = a; } |
55 | const QString&getSubject()const { return subject; } | 55 | const QString&getSubject()const { return subject; } |
56 | void setSubject( const QString&s ) { subject = s; } | 56 | void setSubject( const QString&s ) { subject = s; } |
57 | void setFlags(const QBitArray&flags){msg_flags = flags;} | 57 | void setFlags(const QBitArray&flags){msg_flags = flags;} |
58 | const QBitArray&getFlags()const{return msg_flags;} | 58 | const QBitArray&getFlags()const{return msg_flags;} |
59 | 59 | ||
60 | #if 0 | 60 | #if 0 |
61 | void setDate(const QString&dstring); | 61 | void setDate(const QString&dstring); |
62 | void setDate(const QDateTime&date){mDate = date;} | 62 | void setDate(const QDateTime&date){mDate = date;} |
63 | QString getDate()const{return mDate.toString();} | 63 | QString getDate()const{return mDate.toString();} |
64 | #endif | 64 | #endif |
65 | protected: | 65 | protected: |
66 | QString subject,date,from; | 66 | QString subject,date,from; |
67 | int msg_number; | 67 | int msg_number; |
68 | QBitArray msg_flags; | 68 | QBitArray msg_flags; |
69 | #if 0 | 69 | #if 0 |
70 | QDateTime mDate; | 70 | QDateTime mDate; |
71 | #endif | 71 | #endif |
72 | }; | 72 | }; |
73 | 73 | ||
74 | typedef QList<RecMail> Maillist; | 74 | typedef QList<RecMail> Maillist; |
75 | 75 | ||
76 | class Mail | 76 | class Mail |
77 | { | 77 | { |
78 | public: | 78 | public: |
79 | Mail(); | 79 | Mail(); |
80 | /* Possible that this destructor must not be declared virtual | 80 | /* Possible that this destructor must not be declared virtual |
81 | * 'cause it seems that it will never have some child classes. | 81 | * 'cause it seems that it will never have some child classes. |
82 | * in this case this object will not get a virtual table -> memory and | 82 | * in this case this object will not get a virtual table -> memory and |
83 | * speed will be a little bit better? | 83 | * speed will be a little bit better? |
84 | */ | 84 | */ |
85 | virtual ~Mail(){} | 85 | virtual ~Mail(){} |
86 | void addAttachment( Attachment *att ) { attList.append( att ); } | 86 | void addAttachment( Attachment *att ) { attList.append( att ); } |
87 | const QList<Attachment>& getAttachments()const { return attList; } | 87 | const QList<Attachment>& getAttachments()const { return attList; } |
88 | void removeAttachment( Attachment *att ) { attList.remove( att ); } | 88 | void removeAttachment( Attachment *att ) { attList.remove( att ); } |
89 | const QString&getName()const { return name; } | 89 | const QString&getName()const { return name; } |
90 | void setName( QString s ) { name = s; } | 90 | void setName( QString s ) { name = s; } |
91 | const QString&getMail()const{ return mail; } | 91 | const QString&getMail()const{ return mail; } |
92 | void setMail( const QString&s ) { mail = s; } | 92 | void setMail( const QString&s ) { mail = s; } |
93 | const QString&getTo()const{ return to; } | 93 | const QString&getTo()const{ return to; } |
94 | void setTo( const QString&s ) { to = s; } | 94 | void setTo( const QString&s ) { to = s; } |
95 | const QString&getCC()const{ return cc; } | 95 | const QString&getCC()const{ return cc; } |
96 | void setCC( const QString&s ) { cc = s; } | 96 | void setCC( const QString&s ) { cc = s; } |
97 | const QString&getBCC()const { return bcc; } | 97 | const QString&getBCC()const { return bcc; } |
98 | void setBCC( const QString&s ) { bcc = s; } | 98 | void setBCC( const QString&s ) { bcc = s; } |
99 | const QString&getMessage()const { return message; } | 99 | const QString&getMessage()const { return message; } |
100 | void setMessage( const QString&s ) { message = s; } | 100 | void setMessage( const QString&s ) { message = s; } |
101 | const QString&getSubject()const { return subject; } | 101 | const QString&getSubject()const { return subject; } |
102 | void setSubject( const QString&s ) { subject = s; } | 102 | void setSubject( const QString&s ) { subject = s; } |
103 | const QString&getReply()const{ return reply; } | 103 | const QString&getReply()const{ return reply; } |
104 | void setReply( const QString&a ) { reply = a; } | 104 | void setReply( const QString&a ) { reply = a; } |
105 | 105 | ||
106 | private: | 106 | private: |
107 | QList<Attachment> attList; | 107 | QList<Attachment> attList; |
108 | QString name, mail, to, cc, bcc, reply, subject, message; | 108 | QString name, mail, to, cc, bcc, reply, subject, message; |
109 | }; | 109 | }; |
110 | 110 | ||
111 | class Folder : public QObject | 111 | class Folder : public QObject |
112 | { | 112 | { |
113 | Q_OBJECT | 113 | Q_OBJECT |
114 | 114 | ||
115 | public: | 115 | public: |
116 | Folder( const QString&init_name ); | 116 | Folder( const QString&init_name ); |
117 | const QString&getDisplayName()const { return nameDisplay; } | 117 | const QString&getDisplayName()const { return nameDisplay; } |
118 | const QString&getName()const { return name; } | 118 | const QString&getName()const { return name; } |
119 | virtual bool may_select()const{return true;}; | 119 | virtual bool may_select()const{return true;}; |
120 | 120 | ||
121 | private: | 121 | private: |
122 | QString nameDisplay, name; | 122 | QString nameDisplay, name; |
123 | 123 | ||
124 | }; | 124 | }; |
125 | 125 | ||
126 | class IMAPFolder : public Folder | 126 | class IMAPFolder : public Folder |
127 | { | 127 | { |
128 | public: | 128 | public: |
129 | IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} | 129 | IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} |
130 | virtual bool may_select()const{return m_MaySelect;} | 130 | virtual bool may_select()const{return m_MaySelect;} |
131 | private: | 131 | private: |
132 | bool m_MaySelect; | 132 | bool m_MaySelect; |
133 | }; | 133 | }; |
134 | 134 | ||
135 | class MailWrapper : public QObject | 135 | class MailWrapper : public QObject |
136 | { | 136 | { |
137 | Q_OBJECT | 137 | Q_OBJECT |
138 | 138 | ||
139 | public: | 139 | public: |
140 | MailWrapper( Settings *s ); | 140 | MailWrapper( Settings *s ); |
141 | void sendMail( Mail mail ); | 141 | void sendMail( Mail mail ); |
142 | 142 | ||
143 | private: | 143 | private: |
144 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | 144 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); |
145 | mailimf_address_list *parseAddresses(const QString&addr ); | 145 | mailimf_address_list *parseAddresses(const QString&addr ); |
146 | mailimf_fields *createImfFields( Mail *mail ); | 146 | mailimf_fields *createImfFields( Mail *mail ); |
147 | mailmime *buildTxtPart( QString str ); | 147 | mailmime *buildTxtPart( QString str ); |
148 | mailmime *buildFilePart( QString filename, QString mimetype ); | 148 | mailmime *buildFilePart( QString filename, QString mimetype ); |
149 | void addFileParts( mailmime *message, QList<Attachment> files ); | 149 | void addFileParts( mailmime *message, QList<Attachment> files ); |
150 | mailmime *createMimeMail( Mail *mail ); | 150 | mailmime *createMimeMail( Mail *mail ); |
151 | void smtpSend( mailmime *mail ); | 151 | void smtpSend( mailmime *mail ); |
152 | mailimf_field *getField( mailimf_fields *fields, int type ); | 152 | mailimf_field *getField( mailimf_fields *fields, int type ); |
153 | clist *createRcptList( mailimf_fields *fields ); | 153 | clist *createRcptList( mailimf_fields *fields ); |
154 | char *getFrom( mailmime *mail ); | 154 | char *getFrom( mailmime *mail ); |
155 | SMTPaccount *getAccount( QString from ); | 155 | SMTPaccount *getAccount( QString from ); |
156 | void writeToFile( QString file, mailmime *mail ); | 156 | void writeToFile( QString file, mailmime *mail ); |
157 | void readFromFile( QString file, char **data, size_t *size ); | 157 | void readFromFile( QString file, char **data, size_t *size ); |
158 | static QString mailsmtpError( int err ); | 158 | static QString mailsmtpError( int err ); |
159 | static QString getTmpFile(); | 159 | static QString getTmpFile(); |
160 | 160 | ||
161 | Settings *settings; | 161 | Settings *settings; |
162 | 162 | ||
163 | }; | 163 | }; |
164 | 164 | ||
165 | class IMAPwrapper : public QObject | 165 | class IMAPwrapper : public QObject |
166 | { | 166 | { |
167 | Q_OBJECT | 167 | Q_OBJECT |
168 | 168 | ||
169 | public: | 169 | public: |
170 | IMAPwrapper( IMAPaccount *a ); | 170 | IMAPwrapper( IMAPaccount *a ); |
171 | QList<IMAPFolder>* listFolders(); | 171 | QList<IMAPFolder>* listFolders(); |
172 | void listMessages(const QString & mailbox,Maillist&target ); | 172 | void listMessages(const QString & mailbox,Maillist&target ); |
173 | QString fetchBody(const QString & mailbox,const RecMail&mail); | 173 | QString fetchBody(const QString & mailbox,const RecMail&mail); |
174 | 174 | ||
175 | protected: | 175 | protected: |
176 | RecMail*parse_list_result(mailimap_msg_att*); | 176 | RecMail*parse_list_result(mailimap_msg_att*); |
177 | 177 | ||
178 | private: | 178 | private: |
179 | IMAPaccount *account; | 179 | IMAPaccount *account; |
180 | 180 | ||
181 | }; | 181 | }; |
182 | 182 | ||
183 | #endif | 183 | #endif |
diff --git a/noncore/net/mail/mail.pro b/noncore/net/mail/mail.pro index c913826..46a476d 100644 --- a/noncore/net/mail/mail.pro +++ b/noncore/net/mail/mail.pro | |||
@@ -1,40 +1,39 @@ | |||
1 | CONFIG += qt warn_on debug quick-app | 1 | CONFIG += qt warn_on debug quick-app |
2 | 2 | ||
3 | HEADERS = defines.h \ | 3 | HEADERS = defines.h \ |
4 | logindialog.h \ | 4 | logindialog.h \ |
5 | settings.h \ | 5 | settings.h \ |
6 | editaccounts.h \ | 6 | editaccounts.h \ |
7 | mailwrapper.h \ | 7 | mailwrapper.h \ |
8 | composemail.h \ | 8 | composemail.h \ |
9 | accountview.h \ | 9 | accountview.h \ |
10 | mainwindow.h \ | 10 | mainwindow.h \ |
11 | opiemail.h | 11 | opiemail.h |
12 | 12 | ||
13 | SOURCES = main.cpp \ | 13 | SOURCES = main.cpp \ |
14 | opiemail.cpp \ | 14 | opiemail.cpp \ |
15 | mainwindow.cpp \ | 15 | mainwindow.cpp \ |
16 | accountview.cpp \ | 16 | accountview.cpp \ |
17 | composemail.cpp \ | 17 | composemail.cpp \ |
18 | mailwrapper.cpp \ | 18 | mailwrapper.cpp \ |
19 | imapwrapper.cpp \ | 19 | imapwrapper.cpp \ |
20 | addresspicker.cpp \ | 20 | addresspicker.cpp \ |
21 | editaccounts.cpp \ | 21 | editaccounts.cpp \ |
22 | logindialog.cpp \ | 22 | logindialog.cpp \ |
23 | settings.cpp | 23 | settings.cpp |
24 | 24 | ||
25 | INTERFACES = editaccountsui.ui \ | 25 | INTERFACES = editaccountsui.ui \ |
26 | selectmailtypeui.ui \ | 26 | selectmailtypeui.ui \ |
27 | imapconfigui.ui \ | 27 | imapconfigui.ui \ |
28 | pop3configui.ui \ | 28 | pop3configui.ui \ |
29 | nntpconfigui.ui \ | 29 | nntpconfigui.ui \ |
30 | smtpconfigui.ui \ | 30 | smtpconfigui.ui \ |
31 | addresspickerui.ui \ | 31 | addresspickerui.ui \ |
32 | logindialogui.ui \ | 32 | logindialogui.ui \ |
33 | composemailui.ui | 33 | composemailui.ui |
34 | 34 | ||
35 | INCLUDEPATH += $(OPIEDIR)/include | 35 | INCLUDEPATH += $(OPIEDIR)/include |
36 | INCLUDEPATH += $(OPIEDIR)/include/libetpan | ||
37 | LIBS += -lqpe -lopie -letpan -lssl -lcrypto -ldb | 36 | LIBS += -lqpe -lopie -letpan -lssl -lcrypto -ldb |
38 | TARGET = opiemail | 37 | TARGET = opiemail |
39 | 38 | ||
40 | include ( $(OPIEDIR)/include.pro ) | 39 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp index 17bed65..13a3fd9 100644 --- a/noncore/net/mail/mailwrapper.cpp +++ b/noncore/net/mail/mailwrapper.cpp | |||
@@ -1,643 +1,643 @@ | |||
1 | #include <qfileinfo.h> | 1 | #include <qfileinfo.h> |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <sys/stat.h> | 3 | #include <sys/stat.h> |
4 | #include <sys/types.h> | 4 | #include <sys/types.h> |
5 | #include <unistd.h> | 5 | #include <unistd.h> |
6 | #include <fcntl.h> | 6 | #include <fcntl.h> |
7 | #include <string.h> | 7 | #include <string.h> |
8 | #include <qdir.h> | 8 | #include <qdir.h> |
9 | #include <qtextstream.h> | 9 | #include <qtextstream.h> |
10 | 10 | ||
11 | #include "mailwrapper.h" | 11 | #include "mailwrapper.h" |
12 | #include "logindialog.h" | 12 | #include "logindialog.h" |
13 | #include "mail.h" | 13 | //#include "mail.h" |
14 | #include "defines.h" | 14 | #include "defines.h" |
15 | 15 | ||
16 | Attachment::Attachment( DocLnk lnk ) | 16 | Attachment::Attachment( DocLnk lnk ) |
17 | { | 17 | { |
18 | doc = lnk; | 18 | doc = lnk; |
19 | size = QFileInfo( doc.file() ).size(); | 19 | size = QFileInfo( doc.file() ).size(); |
20 | } | 20 | } |
21 | 21 | ||
22 | Folder::Folder(const QString&tmp_name ) | 22 | Folder::Folder(const QString&tmp_name ) |
23 | { | 23 | { |
24 | name = tmp_name; | 24 | name = tmp_name; |
25 | nameDisplay = name; | 25 | nameDisplay = name; |
26 | 26 | ||
27 | for ( int pos = nameDisplay.find( '&' ); pos != -1; | 27 | for ( int pos = nameDisplay.find( '&' ); pos != -1; |
28 | pos = nameDisplay.find( '&' ) ) { | 28 | pos = nameDisplay.find( '&' ) ) { |
29 | int end = nameDisplay.find( '-' ); | 29 | int end = nameDisplay.find( '-' ); |
30 | if ( end == -1 || end <= pos ) break; | 30 | if ( end == -1 || end <= pos ) break; |
31 | QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 ); | 31 | QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 ); |
32 | // TODO: do real base64 decoding here ! | 32 | // TODO: do real base64 decoding here ! |
33 | if ( str64.compare( "APw" ) == 0 ) { | 33 | if ( str64.compare( "APw" ) == 0 ) { |
34 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" ); | 34 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" ); |
35 | } else if ( str64.compare( "APY" ) == 0 ) { | 35 | } else if ( str64.compare( "APY" ) == 0 ) { |
36 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" ); | 36 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" ); |
37 | } | 37 | } |
38 | } | 38 | } |
39 | 39 | ||
40 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); | 40 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); |
41 | } | 41 | } |
42 | 42 | ||
43 | MailWrapper::MailWrapper( Settings *s ) | 43 | MailWrapper::MailWrapper( Settings *s ) |
44 | : QObject() | 44 | : QObject() |
45 | { | 45 | { |
46 | settings = s; | 46 | settings = s; |
47 | } | 47 | } |
48 | 48 | ||
49 | QString MailWrapper::mailsmtpError( int errnum ) | 49 | QString MailWrapper::mailsmtpError( int errnum ) |
50 | { | 50 | { |
51 | switch ( errnum ) { | 51 | switch ( errnum ) { |
52 | case MAILSMTP_NO_ERROR: | 52 | case MAILSMTP_NO_ERROR: |
53 | return tr( "No error" ); | 53 | return tr( "No error" ); |
54 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 54 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
55 | return tr( "Unexpected error code" ); | 55 | return tr( "Unexpected error code" ); |
56 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 56 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
57 | return tr( "Service not available" ); | 57 | return tr( "Service not available" ); |
58 | case MAILSMTP_ERROR_STREAM: | 58 | case MAILSMTP_ERROR_STREAM: |
59 | return tr( "Stream error" ); | 59 | return tr( "Stream error" ); |
60 | case MAILSMTP_ERROR_HOSTNAME: | 60 | case MAILSMTP_ERROR_HOSTNAME: |
61 | return tr( "gethostname() failed" ); | 61 | return tr( "gethostname() failed" ); |
62 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 62 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
63 | return tr( "Not implemented" ); | 63 | return tr( "Not implemented" ); |
64 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 64 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
65 | return tr( "Error, action not taken" ); | 65 | return tr( "Error, action not taken" ); |
66 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 66 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
67 | return tr( "Data exceeds storage allocation" ); | 67 | return tr( "Data exceeds storage allocation" ); |
68 | case MAILSMTP_ERROR_IN_PROCESSING: | 68 | case MAILSMTP_ERROR_IN_PROCESSING: |
69 | return tr( "Error in processing" ); | 69 | return tr( "Error in processing" ); |
70 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 70 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
71 | // return tr( "Insufficient system storage" ); | 71 | // return tr( "Insufficient system storage" ); |
72 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 72 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
73 | return tr( "Mailbox unavailable" ); | 73 | return tr( "Mailbox unavailable" ); |
74 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 74 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
75 | return tr( "Mailbox name not allowed" ); | 75 | return tr( "Mailbox name not allowed" ); |
76 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 76 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
77 | return tr( "Bad command sequence" ); | 77 | return tr( "Bad command sequence" ); |
78 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 78 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
79 | return tr( "User not local" ); | 79 | return tr( "User not local" ); |
80 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 80 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
81 | return tr( "Transaction failed" ); | 81 | return tr( "Transaction failed" ); |
82 | case MAILSMTP_ERROR_MEMORY: | 82 | case MAILSMTP_ERROR_MEMORY: |
83 | return tr( "Memory error" ); | 83 | return tr( "Memory error" ); |
84 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 84 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
85 | return tr( "Connection refused" ); | 85 | return tr( "Connection refused" ); |
86 | default: | 86 | default: |
87 | return tr( "Unknown error code" ); | 87 | return tr( "Unknown error code" ); |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) | 91 | mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) |
92 | { | 92 | { |
93 | return mailimf_mailbox_new( strdup( name.latin1() ), | 93 | return mailimf_mailbox_new( strdup( name.latin1() ), |
94 | strdup( mail.latin1() ) ); | 94 | strdup( mail.latin1() ) ); |
95 | } | 95 | } |
96 | 96 | ||
97 | mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) | 97 | mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) |
98 | { | 98 | { |
99 | mailimf_address_list *addresses; | 99 | mailimf_address_list *addresses; |
100 | 100 | ||
101 | if ( addr.isEmpty() ) return NULL; | 101 | if ( addr.isEmpty() ) return NULL; |
102 | 102 | ||
103 | addresses = mailimf_address_list_new_empty(); | 103 | addresses = mailimf_address_list_new_empty(); |
104 | 104 | ||
105 | QStringList list = QStringList::split( ',', addr ); | 105 | QStringList list = QStringList::split( ',', addr ); |
106 | QStringList::Iterator it; | 106 | QStringList::Iterator it; |
107 | for ( it = list.begin(); it != list.end(); it++ ) { | 107 | for ( it = list.begin(); it != list.end(); it++ ) { |
108 | char *str = strdup( (*it).latin1() ); | 108 | char *str = strdup( (*it).latin1() ); |
109 | int err = mailimf_address_list_add_parse( addresses, str ); | 109 | int err = mailimf_address_list_add_parse( addresses, str ); |
110 | if ( err != MAILIMF_NO_ERROR ) { | 110 | if ( err != MAILIMF_NO_ERROR ) { |
111 | qDebug( "Error parsing" ); | 111 | qDebug( "Error parsing" ); |
112 | qDebug( *it ); | 112 | qDebug( *it ); |
113 | free( str ); | 113 | free( str ); |
114 | } else { | 114 | } else { |
115 | qDebug( "Parse success! :)" ); | 115 | qDebug( "Parse success! :)" ); |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | return addresses; | 119 | return addresses; |
120 | } | 120 | } |
121 | 121 | ||
122 | mailimf_fields *MailWrapper::createImfFields( Mail *mail ) | 122 | mailimf_fields *MailWrapper::createImfFields( Mail *mail ) |
123 | { | 123 | { |
124 | mailimf_fields *fields; | 124 | mailimf_fields *fields; |
125 | mailimf_field *xmailer; | 125 | mailimf_field *xmailer; |
126 | mailimf_mailbox *sender, *fromBox; | 126 | mailimf_mailbox *sender, *fromBox; |
127 | mailimf_mailbox_list *from; | 127 | mailimf_mailbox_list *from; |
128 | mailimf_address_list *to, *cc, *bcc, *reply; | 128 | mailimf_address_list *to, *cc, *bcc, *reply; |
129 | char *subject = strdup( mail->getSubject().latin1() ); | 129 | char *subject = strdup( mail->getSubject().latin1() ); |
130 | int err; | 130 | int err; |
131 | 131 | ||
132 | sender = newMailbox( mail->getName(), mail->getMail() ); | 132 | sender = newMailbox( mail->getName(), mail->getMail() ); |
133 | if ( sender == NULL ) goto err_free; | 133 | if ( sender == NULL ) goto err_free; |
134 | 134 | ||
135 | fromBox = newMailbox( mail->getName(), mail->getMail() ); | 135 | fromBox = newMailbox( mail->getName(), mail->getMail() ); |
136 | if ( fromBox == NULL ) goto err_free_sender; | 136 | if ( fromBox == NULL ) goto err_free_sender; |
137 | 137 | ||
138 | from = mailimf_mailbox_list_new_empty(); | 138 | from = mailimf_mailbox_list_new_empty(); |
139 | if ( from == NULL ) goto err_free_fromBox; | 139 | if ( from == NULL ) goto err_free_fromBox; |
140 | 140 | ||
141 | err = mailimf_mailbox_list_add( from, fromBox ); | 141 | err = mailimf_mailbox_list_add( from, fromBox ); |
142 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; | 142 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; |
143 | 143 | ||
144 | to = parseAddresses( mail->getTo() ); | 144 | to = parseAddresses( mail->getTo() ); |
145 | if ( to == NULL ) goto err_free_from; | 145 | if ( to == NULL ) goto err_free_from; |
146 | 146 | ||
147 | cc = parseAddresses( mail->getCC() ); | 147 | cc = parseAddresses( mail->getCC() ); |
148 | bcc = parseAddresses( mail->getBCC() ); | 148 | bcc = parseAddresses( mail->getBCC() ); |
149 | reply = parseAddresses( mail->getReply() ); | 149 | reply = parseAddresses( mail->getReply() ); |
150 | 150 | ||
151 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | 151 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, |
152 | NULL, NULL, subject ); | 152 | NULL, NULL, subject ); |
153 | if ( fields == NULL ) goto err_free_reply; | 153 | if ( fields == NULL ) goto err_free_reply; |
154 | 154 | ||
155 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 155 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), |
156 | strdup( USER_AGENT ) ); | 156 | strdup( USER_AGENT ) ); |
157 | if ( xmailer == NULL ) goto err_free_fields; | 157 | if ( xmailer == NULL ) goto err_free_fields; |
158 | 158 | ||
159 | err = mailimf_fields_add( fields, xmailer ); | 159 | err = mailimf_fields_add( fields, xmailer ); |
160 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; | 160 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; |
161 | 161 | ||
162 | return fields; // Success :) | 162 | return fields; // Success :) |
163 | 163 | ||
164 | err_free_xmailer: | 164 | err_free_xmailer: |
165 | mailimf_field_free( xmailer ); | 165 | mailimf_field_free( xmailer ); |
166 | err_free_fields: | 166 | err_free_fields: |
167 | mailimf_fields_free( fields ); | 167 | mailimf_fields_free( fields ); |
168 | err_free_reply: | 168 | err_free_reply: |
169 | mailimf_address_list_free( reply ); | 169 | mailimf_address_list_free( reply ); |
170 | mailimf_address_list_free( bcc ); | 170 | mailimf_address_list_free( bcc ); |
171 | mailimf_address_list_free( cc ); | 171 | mailimf_address_list_free( cc ); |
172 | mailimf_address_list_free( to ); | 172 | mailimf_address_list_free( to ); |
173 | err_free_from: | 173 | err_free_from: |
174 | mailimf_mailbox_list_free( from ); | 174 | mailimf_mailbox_list_free( from ); |
175 | err_free_fromBox: | 175 | err_free_fromBox: |
176 | mailimf_mailbox_free( fromBox ); | 176 | mailimf_mailbox_free( fromBox ); |
177 | err_free_sender: | 177 | err_free_sender: |
178 | mailimf_mailbox_free( sender ); | 178 | mailimf_mailbox_free( sender ); |
179 | err_free: | 179 | err_free: |
180 | free( subject ); | 180 | free( subject ); |
181 | qDebug( "createImfFields - error" ); | 181 | qDebug( "createImfFields - error" ); |
182 | 182 | ||
183 | return NULL; // Error :( | 183 | return NULL; // Error :( |
184 | } | 184 | } |
185 | 185 | ||
186 | mailmime *MailWrapper::buildTxtPart( QString str ) | 186 | mailmime *MailWrapper::buildTxtPart( QString str ) |
187 | { | 187 | { |
188 | mailmime *txtPart; | 188 | mailmime *txtPart; |
189 | mailmime_fields *fields; | 189 | mailmime_fields *fields; |
190 | mailmime_content *content; | 190 | mailmime_content *content; |
191 | mailmime_parameter *param; | 191 | mailmime_parameter *param; |
192 | char *txt = strdup( str.latin1() ); | 192 | char *txt = strdup( str.latin1() ); |
193 | int err; | 193 | int err; |
194 | 194 | ||
195 | param = mailmime_parameter_new( strdup( "charset" ), | 195 | param = mailmime_parameter_new( strdup( "charset" ), |
196 | strdup( "iso-8859-1" ) ); | 196 | strdup( "iso-8859-1" ) ); |
197 | if ( param == NULL ) goto err_free; | 197 | if ( param == NULL ) goto err_free; |
198 | 198 | ||
199 | content = mailmime_content_new_with_str( "text/plain" ); | 199 | content = mailmime_content_new_with_str( "text/plain" ); |
200 | if ( content == NULL ) goto err_free_param; | 200 | if ( content == NULL ) goto err_free_param; |
201 | 201 | ||
202 | err = clist_append( content->parameters, param ); | 202 | err = clist_append( content->parameters, param ); |
203 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | 203 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; |
204 | 204 | ||
205 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); | 205 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); |
206 | if ( fields == NULL ) goto err_free_content; | 206 | if ( fields == NULL ) goto err_free_content; |
207 | 207 | ||
208 | txtPart = mailmime_new_empty( content, fields ); | 208 | txtPart = mailmime_new_empty( content, fields ); |
209 | if ( txtPart == NULL ) goto err_free_fields; | 209 | if ( txtPart == NULL ) goto err_free_fields; |
210 | 210 | ||
211 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); | 211 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); |
212 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 212 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
213 | 213 | ||
214 | return txtPart; // Success :) | 214 | return txtPart; // Success :) |
215 | 215 | ||
216 | err_free_txtPart: | 216 | err_free_txtPart: |
217 | mailmime_free( txtPart ); | 217 | mailmime_free( txtPart ); |
218 | err_free_fields: | 218 | err_free_fields: |
219 | mailmime_fields_free( fields ); | 219 | mailmime_fields_free( fields ); |
220 | err_free_content: | 220 | err_free_content: |
221 | mailmime_content_free( content ); | 221 | mailmime_content_free( content ); |
222 | err_free_param: | 222 | err_free_param: |
223 | mailmime_parameter_free( param ); | 223 | mailmime_parameter_free( param ); |
224 | err_free: | 224 | err_free: |
225 | free( txt ); | 225 | free( txt ); |
226 | qDebug( "buildTxtPart - error" ); | 226 | qDebug( "buildTxtPart - error" ); |
227 | 227 | ||
228 | return NULL; // Error :( | 228 | return NULL; // Error :( |
229 | } | 229 | } |
230 | 230 | ||
231 | mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) | 231 | mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) |
232 | { | 232 | { |
233 | mailmime * filePart; | 233 | mailmime * filePart; |
234 | mailmime_fields * fields; | 234 | mailmime_fields * fields; |
235 | mailmime_content * content; | 235 | mailmime_content * content; |
236 | mailmime_parameter * param = NULL; | 236 | mailmime_parameter * param = NULL; |
237 | int err; | 237 | int err; |
238 | 238 | ||
239 | int pos = filename.findRev( '/' ); | 239 | int pos = filename.findRev( '/' ); |
240 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 240 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
241 | char *name = strdup( tmp.latin1() ); // just filename | 241 | char *name = strdup( tmp.latin1() ); // just filename |
242 | char *file = strdup( filename.latin1() ); // full name with path | 242 | char *file = strdup( filename.latin1() ); // full name with path |
243 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain | 243 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain |
244 | 244 | ||
245 | fields = mailmime_fields_new_filename( | 245 | fields = mailmime_fields_new_filename( |
246 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, | 246 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, |
247 | MAILMIME_MECHANISM_BASE64 ); | 247 | MAILMIME_MECHANISM_BASE64 ); |
248 | if ( fields == NULL ) goto err_free; | 248 | if ( fields == NULL ) goto err_free; |
249 | 249 | ||
250 | content = mailmime_content_new_with_str( mime ); | 250 | content = mailmime_content_new_with_str( mime ); |
251 | if ( content == NULL ) goto err_free_fields; | 251 | if ( content == NULL ) goto err_free_fields; |
252 | 252 | ||
253 | if ( mimetype.compare( "text/plain" ) == 0 ) { | 253 | if ( mimetype.compare( "text/plain" ) == 0 ) { |
254 | param = mailmime_parameter_new( strdup( "charset" ), | 254 | param = mailmime_parameter_new( strdup( "charset" ), |
255 | strdup( "iso-8859-1" ) ); | 255 | strdup( "iso-8859-1" ) ); |
256 | if ( param == NULL ) goto err_free_content; | 256 | if ( param == NULL ) goto err_free_content; |
257 | 257 | ||
258 | err = clist_append( content->parameters, param ); | 258 | err = clist_append( content->parameters, param ); |
259 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; | 259 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; |
260 | } | 260 | } |
261 | 261 | ||
262 | filePart = mailmime_new_empty( content, fields ); | 262 | filePart = mailmime_new_empty( content, fields ); |
263 | if ( filePart == NULL ) goto err_free_param; | 263 | if ( filePart == NULL ) goto err_free_param; |
264 | 264 | ||
265 | err = mailmime_set_body_file( filePart, file ); | 265 | err = mailmime_set_body_file( filePart, file ); |
266 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 266 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; |
267 | 267 | ||
268 | return filePart; // Success :) | 268 | return filePart; // Success :) |
269 | 269 | ||
270 | err_free_filePart: | 270 | err_free_filePart: |
271 | mailmime_free( filePart ); | 271 | mailmime_free( filePart ); |
272 | err_free_param: | 272 | err_free_param: |
273 | if ( param != NULL ) mailmime_parameter_free( param ); | 273 | if ( param != NULL ) mailmime_parameter_free( param ); |
274 | err_free_content: | 274 | err_free_content: |
275 | mailmime_content_free( content ); | 275 | mailmime_content_free( content ); |
276 | err_free_fields: | 276 | err_free_fields: |
277 | mailmime_fields_free( fields ); | 277 | mailmime_fields_free( fields ); |
278 | err_free: | 278 | err_free: |
279 | free( name ); | 279 | free( name ); |
280 | free( mime ); | 280 | free( mime ); |
281 | free( file ); | 281 | free( file ); |
282 | qDebug( "buildFilePart - error" ); | 282 | qDebug( "buildFilePart - error" ); |
283 | 283 | ||
284 | return NULL; // Error :( | 284 | return NULL; // Error :( |
285 | } | 285 | } |
286 | 286 | ||
287 | void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) | 287 | void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) |
288 | { | 288 | { |
289 | Attachment *it; | 289 | Attachment *it; |
290 | for ( it = files.first(); it; it = files.next() ) { | 290 | for ( it = files.first(); it; it = files.next() ) { |
291 | qDebug( "Adding file" ); | 291 | qDebug( "Adding file" ); |
292 | mailmime *filePart; | 292 | mailmime *filePart; |
293 | int err; | 293 | int err; |
294 | 294 | ||
295 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); | 295 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); |
296 | if ( filePart == NULL ) goto err_free; | 296 | if ( filePart == NULL ) goto err_free; |
297 | 297 | ||
298 | err = mailmime_smart_add_part( message, filePart ); | 298 | err = mailmime_smart_add_part( message, filePart ); |
299 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 299 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; |
300 | 300 | ||
301 | continue; // Success :) | 301 | continue; // Success :) |
302 | 302 | ||
303 | err_free_filePart: | 303 | err_free_filePart: |
304 | mailmime_free( filePart ); | 304 | mailmime_free( filePart ); |
305 | err_free: | 305 | err_free: |
306 | qDebug( "addFileParts: error adding file:" ); | 306 | qDebug( "addFileParts: error adding file:" ); |
307 | qDebug( it->getFileName() ); | 307 | qDebug( it->getFileName() ); |
308 | } | 308 | } |
309 | } | 309 | } |
310 | 310 | ||
311 | mailmime *MailWrapper::createMimeMail( Mail *mail ) | 311 | mailmime *MailWrapper::createMimeMail( Mail *mail ) |
312 | { | 312 | { |
313 | mailmime *message, *txtPart; | 313 | mailmime *message, *txtPart; |
314 | mailimf_fields *fields; | 314 | mailimf_fields *fields; |
315 | int err; | 315 | int err; |
316 | 316 | ||
317 | fields = createImfFields( mail ); | 317 | fields = createImfFields( mail ); |
318 | if ( fields == NULL ) goto err_free; | 318 | if ( fields == NULL ) goto err_free; |
319 | 319 | ||
320 | message = mailmime_new_message_data( NULL ); | 320 | message = mailmime_new_message_data( NULL ); |
321 | if ( message == NULL ) goto err_free_fields; | 321 | if ( message == NULL ) goto err_free_fields; |
322 | 322 | ||
323 | mailmime_set_imf_fields( message, fields ); | 323 | mailmime_set_imf_fields( message, fields ); |
324 | 324 | ||
325 | txtPart = buildTxtPart( mail->getMessage() ); | 325 | txtPart = buildTxtPart( mail->getMessage() ); |
326 | if ( txtPart == NULL ) goto err_free_message; | 326 | if ( txtPart == NULL ) goto err_free_message; |
327 | 327 | ||
328 | err = mailmime_smart_add_part( message, txtPart ); | 328 | err = mailmime_smart_add_part( message, txtPart ); |
329 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 329 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
330 | 330 | ||
331 | addFileParts( message, mail->getAttachments() ); | 331 | addFileParts( message, mail->getAttachments() ); |
332 | 332 | ||
333 | return message; // Success :) | 333 | return message; // Success :) |
334 | 334 | ||
335 | err_free_txtPart: | 335 | err_free_txtPart: |
336 | mailmime_free( txtPart ); | 336 | mailmime_free( txtPart ); |
337 | err_free_message: | 337 | err_free_message: |
338 | mailmime_free( message ); | 338 | mailmime_free( message ); |
339 | err_free_fields: | 339 | err_free_fields: |
340 | mailimf_fields_free( fields ); | 340 | mailimf_fields_free( fields ); |
341 | err_free: | 341 | err_free: |
342 | qDebug( "createMimeMail: error" ); | 342 | qDebug( "createMimeMail: error" ); |
343 | 343 | ||
344 | return NULL; // Error :( | 344 | return NULL; // Error :( |
345 | } | 345 | } |
346 | 346 | ||
347 | mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) | 347 | mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) |
348 | { | 348 | { |
349 | mailimf_field *field; | 349 | mailimf_field *field; |
350 | clistiter *it; | 350 | clistiter *it; |
351 | 351 | ||
352 | it = clist_begin( fields->list ); | 352 | it = clist_begin( fields->list ); |
353 | while ( it ) { | 353 | while ( it ) { |
354 | field = (mailimf_field *) it->data; | 354 | field = (mailimf_field *) it->data; |
355 | if ( field->type == type ) { | 355 | if ( field->type == type ) { |
356 | return field; | 356 | return field; |
357 | } | 357 | } |
358 | it = it->next; | 358 | it = it->next; |
359 | } | 359 | } |
360 | 360 | ||
361 | return NULL; | 361 | return NULL; |
362 | } | 362 | } |
363 | 363 | ||
364 | static void addRcpts( clist *list, mailimf_address_list *addr_list ) | 364 | static void addRcpts( clist *list, mailimf_address_list *addr_list ) |
365 | { | 365 | { |
366 | clistiter *it, *it2; | 366 | clistiter *it, *it2; |
367 | 367 | ||
368 | for ( it = clist_begin( addr_list->list ); it; it = it->next ) { | 368 | for ( it = clist_begin( addr_list->list ); it; it = it->next ) { |
369 | mailimf_address *addr; | 369 | mailimf_address *addr; |
370 | addr = (mailimf_address *) it->data; | 370 | addr = (mailimf_address *) it->data; |
371 | 371 | ||
372 | if ( addr->type == MAILIMF_ADDRESS_MAILBOX ) { | 372 | if ( addr->type == MAILIMF_ADDRESS_MAILBOX ) { |
373 | esmtp_address_list_add( list, addr->mailbox->addr_spec, 0, NULL ); | 373 | esmtp_address_list_add( list, addr->mailbox->addr_spec, 0, NULL ); |
374 | } else if ( addr->type == MAILIMF_ADDRESS_GROUP ) { | 374 | } else if ( addr->type == MAILIMF_ADDRESS_GROUP ) { |
375 | clist *l = addr->group->mb_list->list; | 375 | clist *l = addr->group->mb_list->list; |
376 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | 376 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { |
377 | mailimf_mailbox *mbox; | 377 | mailimf_mailbox *mbox; |
378 | mbox = (mailimf_mailbox *) it2->data; | 378 | mbox = (mailimf_mailbox *) it2->data; |
379 | esmtp_address_list_add( list, mbox->addr_spec, 0, NULL ); | 379 | esmtp_address_list_add( list, mbox->addr_spec, 0, NULL ); |
380 | } | 380 | } |
381 | } | 381 | } |
382 | } | 382 | } |
383 | } | 383 | } |
384 | 384 | ||
385 | clist *MailWrapper::createRcptList( mailimf_fields *fields ) | 385 | clist *MailWrapper::createRcptList( mailimf_fields *fields ) |
386 | { | 386 | { |
387 | clist *rcptList; | 387 | clist *rcptList; |
388 | mailimf_field *field; | 388 | mailimf_field *field; |
389 | 389 | ||
390 | rcptList = esmtp_address_list_new(); | 390 | rcptList = esmtp_address_list_new(); |
391 | 391 | ||
392 | field = getField( fields, MAILIMF_FIELD_TO ); | 392 | field = getField( fields, MAILIMF_FIELD_TO ); |
393 | if ( field && (field->type == MAILIMF_FIELD_TO) | 393 | if ( field && (field->type == MAILIMF_FIELD_TO) |
394 | && field->field.to->addr_list ) { | 394 | && field->field.to->addr_list ) { |
395 | addRcpts( rcptList, field->field.to->addr_list ); | 395 | addRcpts( rcptList, field->field.to->addr_list ); |
396 | } | 396 | } |
397 | 397 | ||
398 | field = getField( fields, MAILIMF_FIELD_CC ); | 398 | field = getField( fields, MAILIMF_FIELD_CC ); |
399 | if ( field && (field->type == MAILIMF_FIELD_CC) | 399 | if ( field && (field->type == MAILIMF_FIELD_CC) |
400 | && field->field.cc->addr_list ) { | 400 | && field->field.cc->addr_list ) { |
401 | addRcpts( rcptList, field->field.cc->addr_list ); | 401 | addRcpts( rcptList, field->field.cc->addr_list ); |
402 | } | 402 | } |
403 | 403 | ||
404 | field = getField( fields, MAILIMF_FIELD_BCC ); | 404 | field = getField( fields, MAILIMF_FIELD_BCC ); |
405 | if ( field && (field->type == MAILIMF_FIELD_BCC) | 405 | if ( field && (field->type == MAILIMF_FIELD_BCC) |
406 | && field->field.bcc->addr_list ) { | 406 | && field->field.bcc->addr_list ) { |
407 | addRcpts( rcptList, field->field.bcc->addr_list ); | 407 | addRcpts( rcptList, field->field.bcc->addr_list ); |
408 | } | 408 | } |
409 | 409 | ||
410 | return rcptList; | 410 | return rcptList; |
411 | } | 411 | } |
412 | 412 | ||
413 | char *MailWrapper::getFrom( mailmime *mail ) | 413 | char *MailWrapper::getFrom( mailmime *mail ) |
414 | { | 414 | { |
415 | char *from = NULL; | 415 | char *from = NULL; |
416 | 416 | ||
417 | mailimf_field *ffrom; | 417 | mailimf_field *ffrom; |
418 | ffrom = getField( mail->fields, MAILIMF_FIELD_FROM ); | 418 | ffrom = getField( mail->fields, MAILIMF_FIELD_FROM ); |
419 | if ( ffrom && (ffrom->type == MAILIMF_FIELD_FROM) | 419 | if ( ffrom && (ffrom->type == MAILIMF_FIELD_FROM) |
420 | && ffrom->field.from->mb_list && ffrom->field.from->mb_list->list ) { | 420 | && ffrom->field.from->mb_list && ffrom->field.from->mb_list->list ) { |
421 | clist *cl = ffrom->field.from->mb_list->list; | 421 | clist *cl = ffrom->field.from->mb_list->list; |
422 | clistiter *it; | 422 | clistiter *it; |
423 | for ( it = clist_begin( cl ); it; it = it->next ) { | 423 | for ( it = clist_begin( cl ); it; it = it->next ) { |
424 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 424 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
425 | from = strdup( mb->addr_spec ); | 425 | from = strdup( mb->addr_spec ); |
426 | } | 426 | } |
427 | } | 427 | } |
428 | 428 | ||
429 | return from; | 429 | return from; |
430 | } | 430 | } |
431 | 431 | ||
432 | SMTPaccount *MailWrapper::getAccount( QString from ) | 432 | SMTPaccount *MailWrapper::getAccount( QString from ) |
433 | { | 433 | { |
434 | SMTPaccount *smtp; | 434 | SMTPaccount *smtp; |
435 | 435 | ||
436 | QList<Account> list = settings->getAccounts(); | 436 | QList<Account> list = settings->getAccounts(); |
437 | Account *it; | 437 | Account *it; |
438 | for ( it = list.first(); it; it = list.next() ) { | 438 | for ( it = list.first(); it; it = list.next() ) { |
439 | if ( it->getType().compare( "SMTP" ) == 0 ) { | 439 | if ( it->getType().compare( "SMTP" ) == 0 ) { |
440 | smtp = static_cast<SMTPaccount *>(it); | 440 | smtp = static_cast<SMTPaccount *>(it); |
441 | if ( smtp->getMail().compare( from ) == 0 ) { | 441 | if ( smtp->getMail().compare( from ) == 0 ) { |
442 | qDebug( "SMTPaccount found for" ); | 442 | qDebug( "SMTPaccount found for" ); |
443 | qDebug( from ); | 443 | qDebug( from ); |
444 | return smtp; | 444 | return smtp; |
445 | } | 445 | } |
446 | } | 446 | } |
447 | } | 447 | } |
448 | 448 | ||
449 | return NULL; | 449 | return NULL; |
450 | } | 450 | } |
451 | 451 | ||
452 | QString MailWrapper::getTmpFile() { | 452 | QString MailWrapper::getTmpFile() { |
453 | int num = 0; | 453 | int num = 0; |
454 | QString unique; | 454 | QString unique; |
455 | 455 | ||
456 | QDir dir( "/tmp" ); | 456 | QDir dir( "/tmp" ); |
457 | QStringList::Iterator it; | 457 | QStringList::Iterator it; |
458 | 458 | ||
459 | QStringList list = dir.entryList( "opiemail-tmp-*" ); | 459 | QStringList list = dir.entryList( "opiemail-tmp-*" ); |
460 | do { | 460 | do { |
461 | unique.setNum( num++ ); | 461 | unique.setNum( num++ ); |
462 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); | 462 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); |
463 | 463 | ||
464 | return "/tmp/opiemail-tmp-" + unique; | 464 | return "/tmp/opiemail-tmp-" + unique; |
465 | } | 465 | } |
466 | 466 | ||
467 | void MailWrapper::writeToFile( QString file, mailmime *mail ) | 467 | void MailWrapper::writeToFile( QString file, mailmime *mail ) |
468 | { | 468 | { |
469 | FILE *f; | 469 | FILE *f; |
470 | int err, col = 0; | 470 | int err, col = 0; |
471 | 471 | ||
472 | f = fopen( file.latin1(), "w" ); | 472 | f = fopen( file.latin1(), "w" ); |
473 | if ( f == NULL ) { | 473 | if ( f == NULL ) { |
474 | qDebug( "writeToFile: error opening file" ); | 474 | qDebug( "writeToFile: error opening file" ); |
475 | return; | 475 | return; |
476 | } | 476 | } |
477 | 477 | ||
478 | err = mailmime_write( f, &col, mail ); | 478 | err = mailmime_write( f, &col, mail ); |
479 | if ( err != MAILIMF_NO_ERROR ) { | 479 | if ( err != MAILIMF_NO_ERROR ) { |
480 | fclose( f ); | 480 | fclose( f ); |
481 | qDebug( "writeToFile: error writing mailmime" ); | 481 | qDebug( "writeToFile: error writing mailmime" ); |
482 | return; | 482 | return; |
483 | } | 483 | } |
484 | 484 | ||
485 | fclose( f ); | 485 | fclose( f ); |
486 | } | 486 | } |
487 | 487 | ||
488 | void MailWrapper::readFromFile( QString file, char **data, size_t *size ) | 488 | void MailWrapper::readFromFile( QString file, char **data, size_t *size ) |
489 | { | 489 | { |
490 | char *buf; | 490 | char *buf; |
491 | struct stat st; | 491 | struct stat st; |
492 | int fd, count = 0, total = 0; | 492 | int fd, count = 0, total = 0; |
493 | 493 | ||
494 | fd = open( file.latin1(), O_RDONLY, 0 ); | 494 | fd = open( file.latin1(), O_RDONLY, 0 ); |
495 | if ( fd == -1 ) return; | 495 | if ( fd == -1 ) return; |
496 | 496 | ||
497 | if ( fstat( fd, &st ) != 0 ) goto err_close; | 497 | if ( fstat( fd, &st ) != 0 ) goto err_close; |
498 | if ( !st.st_size ) goto err_close; | 498 | if ( !st.st_size ) goto err_close; |
499 | 499 | ||
500 | buf = (char *) malloc( st.st_size ); | 500 | buf = (char *) malloc( st.st_size ); |
501 | if ( !buf ) goto err_close; | 501 | if ( !buf ) goto err_close; |
502 | 502 | ||
503 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { | 503 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { |
504 | count = read( fd, buf + total, st.st_size - total ); | 504 | count = read( fd, buf + total, st.st_size - total ); |
505 | total += count; | 505 | total += count; |
506 | } | 506 | } |
507 | if ( count < 0 ) goto err_free; | 507 | if ( count < 0 ) goto err_free; |
508 | 508 | ||
509 | *data = buf; | 509 | *data = buf; |
510 | *size = st.st_size; | 510 | *size = st.st_size; |
511 | 511 | ||
512 | close( fd ); | 512 | close( fd ); |
513 | 513 | ||
514 | return; // Success :) | 514 | return; // Success :) |
515 | 515 | ||
516 | err_free: | 516 | err_free: |
517 | free( buf ); | 517 | free( buf ); |
518 | err_close: | 518 | err_close: |
519 | close( fd ); | 519 | close( fd ); |
520 | } | 520 | } |
521 | 521 | ||
522 | void progress( size_t current, size_t maximum ) | 522 | void progress( size_t current, size_t maximum ) |
523 | { | 523 | { |
524 | qDebug( "Current: %i of %i", current, maximum ); | 524 | qDebug( "Current: %i of %i", current, maximum ); |
525 | } | 525 | } |
526 | 526 | ||
527 | void MailWrapper::smtpSend( mailmime *mail ) | 527 | void MailWrapper::smtpSend( mailmime *mail ) |
528 | { | 528 | { |
529 | mailsmtp *session; | 529 | mailsmtp *session; |
530 | clist *rcpts; | 530 | clist *rcpts; |
531 | char *from, *data, *server, *user = NULL, *pass = NULL; | 531 | char *from, *data, *server, *user = NULL, *pass = NULL; |
532 | size_t size; | 532 | size_t size; |
533 | int err; | 533 | int err; |
534 | bool ssl; | 534 | bool ssl; |
535 | uint16_t port; | 535 | uint16_t port; |
536 | 536 | ||
537 | 537 | ||
538 | from = getFrom( mail ); | 538 | from = getFrom( mail ); |
539 | SMTPaccount *smtp = getAccount( from ); | 539 | SMTPaccount *smtp = getAccount( from ); |
540 | if ( smtp == NULL ) { | 540 | if ( smtp == NULL ) { |
541 | free(from); | 541 | free(from); |
542 | return; | 542 | return; |
543 | } | 543 | } |
544 | server = strdup( smtp->getServer().latin1() ); | 544 | server = strdup( smtp->getServer().latin1() ); |
545 | ssl = smtp->getSSL(); | 545 | ssl = smtp->getSSL(); |
546 | port = smtp->getPort().toUInt(); | 546 | port = smtp->getPort().toUInt(); |
547 | rcpts = createRcptList( mail->fields ); | 547 | rcpts = createRcptList( mail->fields ); |
548 | 548 | ||
549 | QString file = getTmpFile(); | 549 | QString file = getTmpFile(); |
550 | writeToFile( file, mail ); | 550 | writeToFile( file, mail ); |
551 | readFromFile( file, &data, &size ); | 551 | readFromFile( file, &data, &size ); |
552 | QFile f( file ); | 552 | QFile f( file ); |
553 | f.remove(); | 553 | f.remove(); |
554 | 554 | ||
555 | session = mailsmtp_new( 20, &progress ); | 555 | session = mailsmtp_new( 20, &progress ); |
556 | if ( session == NULL ) goto free_mem; | 556 | if ( session == NULL ) goto free_mem; |
557 | 557 | ||
558 | qDebug( "Servername %s at port %i", server, port ); | 558 | qDebug( "Servername %s at port %i", server, port ); |
559 | if ( ssl ) { | 559 | if ( ssl ) { |
560 | qDebug( "SSL session" ); | 560 | qDebug( "SSL session" ); |
561 | err = mailsmtp_ssl_connect( session, server, port ); | 561 | err = mailsmtp_ssl_connect( session, server, port ); |
562 | } else { | 562 | } else { |
563 | qDebug( "No SSL session" ); | 563 | qDebug( "No SSL session" ); |
564 | err = mailsmtp_socket_connect( session, server, port ); | 564 | err = mailsmtp_socket_connect( session, server, port ); |
565 | } | 565 | } |
566 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; | 566 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; |
567 | 567 | ||
568 | err = mailsmtp_init( session ); | 568 | err = mailsmtp_init( session ); |
569 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 569 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; |
570 | 570 | ||
571 | qDebug( "INIT OK" ); | 571 | qDebug( "INIT OK" ); |
572 | 572 | ||
573 | if ( smtp->getLogin() ) { | 573 | if ( smtp->getLogin() ) { |
574 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | 574 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { |
575 | // get'em | 575 | // get'em |
576 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | 576 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); |
577 | login.show(); | 577 | login.show(); |
578 | if ( QDialog::Accepted == login.exec() ) { | 578 | if ( QDialog::Accepted == login.exec() ) { |
579 | // ok | 579 | // ok |
580 | user = strdup( login.getUser().latin1() ); | 580 | user = strdup( login.getUser().latin1() ); |
581 | pass = strdup( login.getPassword().latin1() ); | 581 | pass = strdup( login.getPassword().latin1() ); |
582 | } else { | 582 | } else { |
583 | goto free_con_session; | 583 | goto free_con_session; |
584 | } | 584 | } |
585 | } else { | 585 | } else { |
586 | user = strdup( smtp->getUser().latin1() ); | 586 | user = strdup( smtp->getUser().latin1() ); |
587 | pass = strdup( smtp->getPassword().latin1() ); | 587 | pass = strdup( smtp->getPassword().latin1() ); |
588 | } | 588 | } |
589 | qDebug( "session->auth: %i", session->auth); | 589 | qDebug( "session->auth: %i", session->auth); |
590 | err = mailsmtp_auth( session, user, pass ); | 590 | err = mailsmtp_auth( session, user, pass ); |
591 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); | 591 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); |
592 | qDebug( "Done auth!" ); | 592 | qDebug( "Done auth!" ); |
593 | } | 593 | } |
594 | 594 | ||
595 | err = mailsmtp_send( session, from, rcpts, data, size ); | 595 | err = mailsmtp_send( session, from, rcpts, data, size ); |
596 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 596 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; |
597 | 597 | ||
598 | qDebug( "Mail sent." ); | 598 | qDebug( "Mail sent." ); |
599 | 599 | ||
600 | free_con_session: | 600 | free_con_session: |
601 | mailsmtp_quit( session ); | 601 | mailsmtp_quit( session ); |
602 | free_mem_session: | 602 | free_mem_session: |
603 | mailsmtp_free( session ); | 603 | mailsmtp_free( session ); |
604 | free_mem: | 604 | free_mem: |
605 | smtp_address_list_free( rcpts ); | 605 | smtp_address_list_free( rcpts ); |
606 | free( data ); | 606 | free( data ); |
607 | free( server ); | 607 | free( server ); |
608 | if ( smtp->getLogin() ) { | 608 | if ( smtp->getLogin() ) { |
609 | free( user ); | 609 | free( user ); |
610 | free( pass ); | 610 | free( pass ); |
611 | } | 611 | } |
612 | free( from ); | 612 | free( from ); |
613 | } | 613 | } |
614 | 614 | ||
615 | void MailWrapper::sendMail( Mail mail ) | 615 | void MailWrapper::sendMail( Mail mail ) |
616 | { | 616 | { |
617 | mailmime *mimeMail; | 617 | mailmime *mimeMail; |
618 | 618 | ||
619 | mimeMail = createMimeMail( &mail ); | 619 | mimeMail = createMimeMail( &mail ); |
620 | if ( mimeMail == NULL ) { | 620 | if ( mimeMail == NULL ) { |
621 | qDebug( "sendMail: error creating mime mail" ); | 621 | qDebug( "sendMail: error creating mime mail" ); |
622 | } else { | 622 | } else { |
623 | smtpSend( mimeMail ); | 623 | smtpSend( mimeMail ); |
624 | mailmime_free( mimeMail ); | 624 | mailmime_free( mimeMail ); |
625 | } | 625 | } |
626 | } | 626 | } |
627 | 627 | ||
628 | Mail::Mail() | 628 | Mail::Mail() |
629 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") | 629 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") |
630 | { | 630 | { |
631 | } | 631 | } |
632 | 632 | ||
633 | RecMail::RecMail() | 633 | RecMail::RecMail() |
634 | :subject(""),date(""),msg_number(0),msg_flags(7) | 634 | :subject(""),date(""),msg_number(0),msg_flags(7) |
635 | { | 635 | { |
636 | } | 636 | } |
637 | 637 | ||
638 | #if 0 | 638 | #if 0 |
639 | void RecMail::setDate(const QString&aDate) | 639 | void RecMail::setDate(const QString&aDate) |
640 | { | 640 | { |
641 | mDate = QDateTime::fromString(aDate); | 641 | mDate = QDateTime::fromString(aDate); |
642 | } | 642 | } |
643 | #endif | 643 | #endif |
diff --git a/noncore/net/mail/mailwrapper.h b/noncore/net/mail/mailwrapper.h index 3de28a0..f45eab7 100644 --- a/noncore/net/mail/mailwrapper.h +++ b/noncore/net/mail/mailwrapper.h | |||
@@ -1,183 +1,183 @@ | |||
1 | #ifndef MAILWRAPPER_H | 1 | #ifndef MAILWRAPPER_H |
2 | #define MAILWRAPPER_H | 2 | #define MAILWRAPPER_H |
3 | 3 | ||
4 | #include <qpe/applnk.h> | 4 | #include <qpe/applnk.h> |
5 | 5 | ||
6 | #include <mailmime.h> | 6 | #include <libetpan/mailmime.h> |
7 | #include <mailimf.h> | 7 | #include <libetpan/mailimf.h> |
8 | #include <mailsmtp.h> | 8 | #include <libetpan/mailsmtp.h> |
9 | #include <mailimap.h> | 9 | #include <libetpan/mailimap.h> |
10 | #include <mailstorage.h> | 10 | #include <libetpan/mailstorage.h> |
11 | #include <maildriver.h> | 11 | #include <libetpan/maildriver.h> |
12 | #include <qbitarray.h> | 12 | #include <qbitarray.h> |
13 | #include <qdatetime.h> | 13 | #include <qdatetime.h> |
14 | 14 | ||
15 | #include "settings.h" | 15 | #include "settings.h" |
16 | 16 | ||
17 | class Attachment | 17 | class Attachment |
18 | { | 18 | { |
19 | public: | 19 | public: |
20 | Attachment( DocLnk lnk ); | 20 | Attachment( DocLnk lnk ); |
21 | virtual ~Attachment(){} | 21 | virtual ~Attachment(){} |
22 | const QString getFileName()const{ return doc.file(); } | 22 | const QString getFileName()const{ return doc.file(); } |
23 | const QString getName()const{ return doc.name(); } | 23 | const QString getName()const{ return doc.name(); } |
24 | const QString getMimeType()const{ return doc.type(); } | 24 | const QString getMimeType()const{ return doc.type(); } |
25 | const QPixmap getPixmap()const{ return doc.pixmap(); } | 25 | const QPixmap getPixmap()const{ return doc.pixmap(); } |
26 | const int getSize()const { return size; } | 26 | const int getSize()const { return size; } |
27 | DocLnk getDocLnk() { return doc; } | 27 | DocLnk getDocLnk() { return doc; } |
28 | 28 | ||
29 | protected: | 29 | protected: |
30 | DocLnk doc; | 30 | DocLnk doc; |
31 | int size; | 31 | int size; |
32 | 32 | ||
33 | }; | 33 | }; |
34 | 34 | ||
35 | #define FLAG_ANSWERED 0 | 35 | #define FLAG_ANSWERED 0 |
36 | #define FLAG_FLAGGED 1 | 36 | #define FLAG_FLAGGED 1 |
37 | #define FLAG_DELETED 2 | 37 | #define FLAG_DELETED 2 |
38 | #define FLAG_SEEN 3 | 38 | #define FLAG_SEEN 3 |
39 | #define FLAG_DRAFT 4 | 39 | #define FLAG_DRAFT 4 |
40 | #define FLAG_RECENT 5 | 40 | #define FLAG_RECENT 5 |
41 | 41 | ||
42 | /* a class to describe mails in a mailbox */ | 42 | /* a class to describe mails in a mailbox */ |
43 | class RecMail | 43 | class RecMail |
44 | { | 44 | { |
45 | public: | 45 | public: |
46 | RecMail(); | 46 | RecMail(); |
47 | virtual ~RecMail(){} | 47 | virtual ~RecMail(){} |
48 | 48 | ||
49 | const int getNumber()const{return msg_number;} | 49 | const int getNumber()const{return msg_number;} |
50 | void setNumber(int number){msg_number=number;} | 50 | void setNumber(int number){msg_number=number;} |
51 | const QString&getDate()const{ return date; } | 51 | const QString&getDate()const{ return date; } |
52 | void setDate( const QString&a ) { date = a; } | 52 | void setDate( const QString&a ) { date = a; } |
53 | const QString&getFrom()const{ return from; } | 53 | const QString&getFrom()const{ return from; } |
54 | void setFrom( const QString&a ) { from = a; } | 54 | void setFrom( const QString&a ) { from = a; } |
55 | const QString&getSubject()const { return subject; } | 55 | const QString&getSubject()const { return subject; } |
56 | void setSubject( const QString&s ) { subject = s; } | 56 | void setSubject( const QString&s ) { subject = s; } |
57 | void setFlags(const QBitArray&flags){msg_flags = flags;} | 57 | void setFlags(const QBitArray&flags){msg_flags = flags;} |
58 | const QBitArray&getFlags()const{return msg_flags;} | 58 | const QBitArray&getFlags()const{return msg_flags;} |
59 | 59 | ||
60 | #if 0 | 60 | #if 0 |
61 | void setDate(const QString&dstring); | 61 | void setDate(const QString&dstring); |
62 | void setDate(const QDateTime&date){mDate = date;} | 62 | void setDate(const QDateTime&date){mDate = date;} |
63 | QString getDate()const{return mDate.toString();} | 63 | QString getDate()const{return mDate.toString();} |
64 | #endif | 64 | #endif |
65 | protected: | 65 | protected: |
66 | QString subject,date,from; | 66 | QString subject,date,from; |
67 | int msg_number; | 67 | int msg_number; |
68 | QBitArray msg_flags; | 68 | QBitArray msg_flags; |
69 | #if 0 | 69 | #if 0 |
70 | QDateTime mDate; | 70 | QDateTime mDate; |
71 | #endif | 71 | #endif |
72 | }; | 72 | }; |
73 | 73 | ||
74 | typedef QList<RecMail> Maillist; | 74 | typedef QList<RecMail> Maillist; |
75 | 75 | ||
76 | class Mail | 76 | class Mail |
77 | { | 77 | { |
78 | public: | 78 | public: |
79 | Mail(); | 79 | Mail(); |
80 | /* Possible that this destructor must not be declared virtual | 80 | /* Possible that this destructor must not be declared virtual |
81 | * 'cause it seems that it will never have some child classes. | 81 | * 'cause it seems that it will never have some child classes. |
82 | * in this case this object will not get a virtual table -> memory and | 82 | * in this case this object will not get a virtual table -> memory and |
83 | * speed will be a little bit better? | 83 | * speed will be a little bit better? |
84 | */ | 84 | */ |
85 | virtual ~Mail(){} | 85 | virtual ~Mail(){} |
86 | void addAttachment( Attachment *att ) { attList.append( att ); } | 86 | void addAttachment( Attachment *att ) { attList.append( att ); } |
87 | const QList<Attachment>& getAttachments()const { return attList; } | 87 | const QList<Attachment>& getAttachments()const { return attList; } |
88 | void removeAttachment( Attachment *att ) { attList.remove( att ); } | 88 | void removeAttachment( Attachment *att ) { attList.remove( att ); } |
89 | const QString&getName()const { return name; } | 89 | const QString&getName()const { return name; } |
90 | void setName( QString s ) { name = s; } | 90 | void setName( QString s ) { name = s; } |
91 | const QString&getMail()const{ return mail; } | 91 | const QString&getMail()const{ return mail; } |
92 | void setMail( const QString&s ) { mail = s; } | 92 | void setMail( const QString&s ) { mail = s; } |
93 | const QString&getTo()const{ return to; } | 93 | const QString&getTo()const{ return to; } |
94 | void setTo( const QString&s ) { to = s; } | 94 | void setTo( const QString&s ) { to = s; } |
95 | const QString&getCC()const{ return cc; } | 95 | const QString&getCC()const{ return cc; } |
96 | void setCC( const QString&s ) { cc = s; } | 96 | void setCC( const QString&s ) { cc = s; } |
97 | const QString&getBCC()const { return bcc; } | 97 | const QString&getBCC()const { return bcc; } |
98 | void setBCC( const QString&s ) { bcc = s; } | 98 | void setBCC( const QString&s ) { bcc = s; } |
99 | const QString&getMessage()const { return message; } | 99 | const QString&getMessage()const { return message; } |
100 | void setMessage( const QString&s ) { message = s; } | 100 | void setMessage( const QString&s ) { message = s; } |
101 | const QString&getSubject()const { return subject; } | 101 | const QString&getSubject()const { return subject; } |
102 | void setSubject( const QString&s ) { subject = s; } | 102 | void setSubject( const QString&s ) { subject = s; } |
103 | const QString&getReply()const{ return reply; } | 103 | const QString&getReply()const{ return reply; } |
104 | void setReply( const QString&a ) { reply = a; } | 104 | void setReply( const QString&a ) { reply = a; } |
105 | 105 | ||
106 | private: | 106 | private: |
107 | QList<Attachment> attList; | 107 | QList<Attachment> attList; |
108 | QString name, mail, to, cc, bcc, reply, subject, message; | 108 | QString name, mail, to, cc, bcc, reply, subject, message; |
109 | }; | 109 | }; |
110 | 110 | ||
111 | class Folder : public QObject | 111 | class Folder : public QObject |
112 | { | 112 | { |
113 | Q_OBJECT | 113 | Q_OBJECT |
114 | 114 | ||
115 | public: | 115 | public: |
116 | Folder( const QString&init_name ); | 116 | Folder( const QString&init_name ); |
117 | const QString&getDisplayName()const { return nameDisplay; } | 117 | const QString&getDisplayName()const { return nameDisplay; } |
118 | const QString&getName()const { return name; } | 118 | const QString&getName()const { return name; } |
119 | virtual bool may_select()const{return true;}; | 119 | virtual bool may_select()const{return true;}; |
120 | 120 | ||
121 | private: | 121 | private: |
122 | QString nameDisplay, name; | 122 | QString nameDisplay, name; |
123 | 123 | ||
124 | }; | 124 | }; |
125 | 125 | ||
126 | class IMAPFolder : public Folder | 126 | class IMAPFolder : public Folder |
127 | { | 127 | { |
128 | public: | 128 | public: |
129 | IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} | 129 | IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} |
130 | virtual bool may_select()const{return m_MaySelect;} | 130 | virtual bool may_select()const{return m_MaySelect;} |
131 | private: | 131 | private: |
132 | bool m_MaySelect; | 132 | bool m_MaySelect; |
133 | }; | 133 | }; |
134 | 134 | ||
135 | class MailWrapper : public QObject | 135 | class MailWrapper : public QObject |
136 | { | 136 | { |
137 | Q_OBJECT | 137 | Q_OBJECT |
138 | 138 | ||
139 | public: | 139 | public: |
140 | MailWrapper( Settings *s ); | 140 | MailWrapper( Settings *s ); |
141 | void sendMail( Mail mail ); | 141 | void sendMail( Mail mail ); |
142 | 142 | ||
143 | private: | 143 | private: |
144 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | 144 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); |
145 | mailimf_address_list *parseAddresses(const QString&addr ); | 145 | mailimf_address_list *parseAddresses(const QString&addr ); |
146 | mailimf_fields *createImfFields( Mail *mail ); | 146 | mailimf_fields *createImfFields( Mail *mail ); |
147 | mailmime *buildTxtPart( QString str ); | 147 | mailmime *buildTxtPart( QString str ); |
148 | mailmime *buildFilePart( QString filename, QString mimetype ); | 148 | mailmime *buildFilePart( QString filename, QString mimetype ); |
149 | void addFileParts( mailmime *message, QList<Attachment> files ); | 149 | void addFileParts( mailmime *message, QList<Attachment> files ); |
150 | mailmime *createMimeMail( Mail *mail ); | 150 | mailmime *createMimeMail( Mail *mail ); |
151 | void smtpSend( mailmime *mail ); | 151 | void smtpSend( mailmime *mail ); |
152 | mailimf_field *getField( mailimf_fields *fields, int type ); | 152 | mailimf_field *getField( mailimf_fields *fields, int type ); |
153 | clist *createRcptList( mailimf_fields *fields ); | 153 | clist *createRcptList( mailimf_fields *fields ); |
154 | char *getFrom( mailmime *mail ); | 154 | char *getFrom( mailmime *mail ); |
155 | SMTPaccount *getAccount( QString from ); | 155 | SMTPaccount *getAccount( QString from ); |
156 | void writeToFile( QString file, mailmime *mail ); | 156 | void writeToFile( QString file, mailmime *mail ); |
157 | void readFromFile( QString file, char **data, size_t *size ); | 157 | void readFromFile( QString file, char **data, size_t *size ); |
158 | static QString mailsmtpError( int err ); | 158 | static QString mailsmtpError( int err ); |
159 | static QString getTmpFile(); | 159 | static QString getTmpFile(); |
160 | 160 | ||
161 | Settings *settings; | 161 | Settings *settings; |
162 | 162 | ||
163 | }; | 163 | }; |
164 | 164 | ||
165 | class IMAPwrapper : public QObject | 165 | class IMAPwrapper : public QObject |
166 | { | 166 | { |
167 | Q_OBJECT | 167 | Q_OBJECT |
168 | 168 | ||
169 | public: | 169 | public: |
170 | IMAPwrapper( IMAPaccount *a ); | 170 | IMAPwrapper( IMAPaccount *a ); |
171 | QList<IMAPFolder>* listFolders(); | 171 | QList<IMAPFolder>* listFolders(); |
172 | void listMessages(const QString & mailbox,Maillist&target ); | 172 | void listMessages(const QString & mailbox,Maillist&target ); |
173 | QString fetchBody(const QString & mailbox,const RecMail&mail); | 173 | QString fetchBody(const QString & mailbox,const RecMail&mail); |
174 | 174 | ||
175 | protected: | 175 | protected: |
176 | RecMail*parse_list_result(mailimap_msg_att*); | 176 | RecMail*parse_list_result(mailimap_msg_att*); |
177 | 177 | ||
178 | private: | 178 | private: |
179 | IMAPaccount *account; | 179 | IMAPaccount *account; |
180 | 180 | ||
181 | }; | 181 | }; |
182 | 182 | ||
183 | #endif | 183 | #endif |