author | alwin <alwin> | 2003-12-14 19:36:09 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-14 19:36:09 (UTC) |
commit | aa2c19611a347a3945d403e20bcef01977d68b6a (patch) (unidiff) | |
tree | 669bf39c587f9ee22e17fe2c61ed0fec78f356d3 | |
parent | 353e1da81b235d7798763bce76428fb473108fb6 (diff) | |
download | opie-aa2c19611a347a3945d403e20bcef01977d68b6a.zip opie-aa2c19611a347a3945d403e20bcef01977d68b6a.tar.gz opie-aa2c19611a347a3945d403e20bcef01977d68b6a.tar.bz2 |
if a mailbox-prefix is set than it will not displayed in folderview
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.cpp | 12 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.h | 4 | ||||
-rw-r--r-- | noncore/net/mail/mailwrapper.cpp | 12 | ||||
-rw-r--r-- | noncore/net/mail/mailwrapper.h | 4 |
6 files changed, 32 insertions, 8 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index b253b49..0ce2c6c 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -1,771 +1,773 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include "imapwrapper.h" | 4 | #include "imapwrapper.h" |
5 | #include "mailtypes.h" | 5 | #include "mailtypes.h" |
6 | #include <libetpan/mailimap.h> | 6 | #include <libetpan/mailimap.h> |
7 | 7 | ||
8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
9 | : AbstractMail() | 9 | : AbstractMail() |
10 | { | 10 | { |
11 | account = a; | 11 | account = a; |
12 | m_imap = 0; | 12 | m_imap = 0; |
13 | } | 13 | } |
14 | 14 | ||
15 | IMAPwrapper::~IMAPwrapper() | 15 | IMAPwrapper::~IMAPwrapper() |
16 | { | 16 | { |
17 | logout(); | 17 | logout(); |
18 | } | 18 | } |
19 | 19 | ||
20 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 20 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
21 | { | 21 | { |
22 | qDebug( "IMAP: %i of %i", current, maximum ); | 22 | qDebug( "IMAP: %i of %i", current, maximum ); |
23 | } | 23 | } |
24 | 24 | ||
25 | void IMAPwrapper::login() | 25 | void IMAPwrapper::login() |
26 | { | 26 | { |
27 | const char *server, *user, *pass; | 27 | const char *server, *user, *pass; |
28 | uint16_t port; | 28 | uint16_t port; |
29 | int err = MAILIMAP_NO_ERROR; | 29 | int err = MAILIMAP_NO_ERROR; |
30 | 30 | ||
31 | /* we are connected this moment */ | 31 | /* we are connected this moment */ |
32 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 32 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
33 | if (m_imap) { | 33 | if (m_imap) { |
34 | mailstream_flush(m_imap->imap_stream); | 34 | mailstream_flush(m_imap->imap_stream); |
35 | return; | 35 | return; |
36 | } | 36 | } |
37 | server = account->getServer().latin1(); | 37 | server = account->getServer().latin1(); |
38 | port = account->getPort().toUInt(); | 38 | port = account->getPort().toUInt(); |
39 | user = account->getUser().latin1(); | 39 | user = account->getUser().latin1(); |
40 | pass = account->getPassword().latin1(); | 40 | pass = account->getPassword().latin1(); |
41 | 41 | ||
42 | m_imap = mailimap_new( 20, &imap_progress ); | 42 | m_imap = mailimap_new( 20, &imap_progress ); |
43 | /* connect */ | 43 | /* connect */ |
44 | if (account->getSSL()) { | 44 | if (account->getSSL()) { |
45 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 45 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
46 | } else { | 46 | } else { |
47 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 47 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
48 | } | 48 | } |
49 | 49 | ||
50 | if ( err != MAILIMAP_NO_ERROR && | 50 | if ( err != MAILIMAP_NO_ERROR && |
51 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 51 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
52 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 52 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
53 | qDebug("error connecting server: %s",m_imap->imap_response); | 53 | qDebug("error connecting server: %s",m_imap->imap_response); |
54 | mailimap_free( m_imap ); | 54 | mailimap_free( m_imap ); |
55 | m_imap = 0; | 55 | m_imap = 0; |
56 | return; | 56 | return; |
57 | } | 57 | } |
58 | 58 | ||
59 | /* login */ | 59 | /* login */ |
60 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 60 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
61 | if ( err != MAILIMAP_NO_ERROR ) { | 61 | if ( err != MAILIMAP_NO_ERROR ) { |
62 | qDebug("error logging in imap: %s",m_imap->imap_response); | 62 | qDebug("error logging in imap: %s",m_imap->imap_response); |
63 | err = mailimap_close( m_imap ); | 63 | err = mailimap_close( m_imap ); |
64 | mailimap_free( m_imap ); | 64 | mailimap_free( m_imap ); |
65 | m_imap = 0; | 65 | m_imap = 0; |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | void IMAPwrapper::logout() | 69 | void IMAPwrapper::logout() |
70 | { | 70 | { |
71 | int err = MAILIMAP_NO_ERROR; | 71 | int err = MAILIMAP_NO_ERROR; |
72 | if (!m_imap) return; | 72 | if (!m_imap) return; |
73 | err = mailimap_logout( m_imap ); | 73 | err = mailimap_logout( m_imap ); |
74 | err = mailimap_close( m_imap ); | 74 | err = mailimap_close( m_imap ); |
75 | mailimap_free( m_imap ); | 75 | mailimap_free( m_imap ); |
76 | m_imap = 0; | 76 | m_imap = 0; |
77 | } | 77 | } |
78 | 78 | ||
79 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 79 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
80 | { | 80 | { |
81 | const char *mb; | 81 | const char *mb; |
82 | int err = MAILIMAP_NO_ERROR; | 82 | int err = MAILIMAP_NO_ERROR; |
83 | clist *result; | 83 | clist *result; |
84 | clistcell *current; | 84 | clistcell *current; |
85 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; | 85 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; |
86 | mailimap_fetch_type *fetchType; | 86 | mailimap_fetch_type *fetchType; |
87 | mailimap_set *set; | 87 | mailimap_set *set; |
88 | 88 | ||
89 | mb = mailbox.latin1(); | 89 | mb = mailbox.latin1(); |
90 | login(); | 90 | login(); |
91 | if (!m_imap) { | 91 | if (!m_imap) { |
92 | return; | 92 | return; |
93 | } | 93 | } |
94 | /* select mailbox READONLY for operations */ | 94 | /* select mailbox READONLY for operations */ |
95 | err = mailimap_examine( m_imap, (char*)mb); | 95 | err = mailimap_examine( m_imap, (char*)mb); |
96 | if ( err != MAILIMAP_NO_ERROR ) { | 96 | if ( err != MAILIMAP_NO_ERROR ) { |
97 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 97 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
98 | return; | 98 | return; |
99 | } | 99 | } |
100 | 100 | ||
101 | int last = m_imap->imap_selection_info->sel_exists; | 101 | int last = m_imap->imap_selection_info->sel_exists; |
102 | 102 | ||
103 | if (last == 0) { | 103 | if (last == 0) { |
104 | qDebug("mailbox has no mails"); | 104 | qDebug("mailbox has no mails"); |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | 107 | ||
108 | result = clist_new(); | 108 | result = clist_new(); |
109 | /* the range has to start at 1!!! not with 0!!!! */ | 109 | /* the range has to start at 1!!! not with 0!!!! */ |
110 | set = mailimap_set_new_interval( 1, last ); | 110 | set = mailimap_set_new_interval( 1, last ); |
111 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 111 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
114 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 114 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
115 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 115 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
116 | 116 | ||
117 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 117 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
118 | mailimap_set_free( set ); | 118 | mailimap_set_free( set ); |
119 | mailimap_fetch_type_free( fetchType ); | 119 | mailimap_fetch_type_free( fetchType ); |
120 | 120 | ||
121 | QString date,subject,from; | 121 | QString date,subject,from; |
122 | 122 | ||
123 | if ( err == MAILIMAP_NO_ERROR ) { | 123 | if ( err == MAILIMAP_NO_ERROR ) { |
124 | 124 | ||
125 | mailimap_msg_att * msg_att; | 125 | mailimap_msg_att * msg_att; |
126 | int i = 0; | 126 | int i = 0; |
127 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 127 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
128 | ++i; | 128 | ++i; |
129 | msg_att = (mailimap_msg_att*)current->data; | 129 | msg_att = (mailimap_msg_att*)current->data; |
130 | RecMail*m = parse_list_result(msg_att); | 130 | RecMail*m = parse_list_result(msg_att); |
131 | if (m) { | 131 | if (m) { |
132 | m->setNumber(i); | 132 | m->setNumber(i); |
133 | m->setMbox(mailbox); | 133 | m->setMbox(mailbox); |
134 | m->setWrapper(this); | 134 | m->setWrapper(this); |
135 | target.append(m); | 135 | target.append(m); |
136 | } | 136 | } |
137 | } | 137 | } |
138 | } else { | 138 | } else { |
139 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 139 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
140 | } | 140 | } |
141 | mailimap_fetch_list_free(result); | 141 | mailimap_fetch_list_free(result); |
142 | } | 142 | } |
143 | 143 | ||
144 | QList<Folder>* IMAPwrapper::listFolders() | 144 | QList<Folder>* IMAPwrapper::listFolders() |
145 | { | 145 | { |
146 | const char *path, *mask; | 146 | const char *path, *mask; |
147 | int err = MAILIMAP_NO_ERROR; | 147 | int err = MAILIMAP_NO_ERROR; |
148 | clist *result; | 148 | clist *result; |
149 | clistcell *current; | 149 | clistcell *current; |
150 | 150 | ||
151 | QList<Folder> * folders = new QList<Folder>(); | 151 | QList<Folder> * folders = new QList<Folder>(); |
152 | folders->setAutoDelete( false ); | 152 | folders->setAutoDelete( false ); |
153 | login(); | 153 | login(); |
154 | if (!m_imap) { | 154 | if (!m_imap) { |
155 | return folders; | 155 | return folders; |
156 | } | 156 | } |
157 | 157 | ||
158 | /* | 158 | /* |
159 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 159 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
160 | * We must not forget to filter them out in next loop! | 160 | * We must not forget to filter them out in next loop! |
161 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 161 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
162 | */ | 162 | */ |
163 | QString temp; | 163 | QString temp; |
164 | mask = "INBOX" ; | 164 | mask = "INBOX" ; |
165 | result = clist_new(); | 165 | result = clist_new(); |
166 | mailimap_mailbox_list *list; | 166 | mailimap_mailbox_list *list; |
167 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 167 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
168 | if ( err == MAILIMAP_NO_ERROR ) { | 168 | if ( err == MAILIMAP_NO_ERROR ) { |
169 | current = result->first; | 169 | current = result->first; |
170 | for ( int i = result->count; i > 0; i-- ) { | 170 | for ( int i = result->count; i > 0; i-- ) { |
171 | list = (mailimap_mailbox_list *) current->data; | 171 | list = (mailimap_mailbox_list *) current->data; |
172 | // it is better use the deep copy mechanism of qt itself | 172 | // it is better use the deep copy mechanism of qt itself |
173 | // instead of using strdup! | 173 | // instead of using strdup! |
174 | temp = list->mb_name; | 174 | temp = list->mb_name; |
175 | folders->append( new IMAPFolder(temp)); | 175 | folders->append( new IMAPFolder(temp)); |
176 | current = current->next; | 176 | current = current->next; |
177 | } | 177 | } |
178 | } else { | 178 | } else { |
179 | qDebug("error fetching folders: %s",m_imap->imap_response); | 179 | qDebug("error fetching folders: %s",m_imap->imap_response); |
180 | } | 180 | } |
181 | mailimap_list_result_free( result ); | 181 | mailimap_list_result_free( result ); |
182 | 182 | ||
183 | /* | 183 | /* |
184 | * second stage - get the other then inbox folders | 184 | * second stage - get the other then inbox folders |
185 | */ | 185 | */ |
186 | mask = "*" ; | 186 | mask = "*" ; |
187 | path = account->getPrefix().latin1(); | 187 | path = account->getPrefix().latin1(); |
188 | if (!path) path = ""; | 188 | if (!path) path = ""; |
189 | result = clist_new(); | 189 | result = clist_new(); |
190 | qDebug(path); | 190 | qDebug(path); |
191 | bool selectable = true; | 191 | bool selectable = true; |
192 | mailimap_mbx_list_flags*bflags; | 192 | mailimap_mbx_list_flags*bflags; |
193 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 193 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
194 | if ( err == MAILIMAP_NO_ERROR ) { | 194 | if ( err == MAILIMAP_NO_ERROR ) { |
195 | current = result->first; | 195 | current = result->first; |
196 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 196 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
197 | list = (mailimap_mailbox_list *) current->data; | 197 | list = (mailimap_mailbox_list *) current->data; |
198 | // it is better use the deep copy mechanism of qt itself | 198 | // it is better use the deep copy mechanism of qt itself |
199 | // instead of using strdup! | 199 | // instead of using strdup! |
200 | temp = list->mb_name; | 200 | temp = list->mb_name; |
201 | if (temp.lower()=="inbox") | 201 | if (temp.lower()=="inbox") |
202 | continue; | 202 | continue; |
203 | if (temp.lower()==account->getPrefix().lower()) | ||
204 | continue; | ||
203 | if ( (bflags = list->mb_flag) ) { | 205 | if ( (bflags = list->mb_flag) ) { |
204 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 206 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
205 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 207 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
206 | } | 208 | } |
207 | folders->append(new IMAPFolder(temp,selectable)); | 209 | folders->append(new IMAPFolder(temp,selectable,account->getPrefix())); |
208 | } | 210 | } |
209 | } else { | 211 | } else { |
210 | qDebug("error fetching folders %s",m_imap->imap_response); | 212 | qDebug("error fetching folders %s",m_imap->imap_response); |
211 | } | 213 | } |
212 | mailimap_list_result_free( result ); | 214 | mailimap_list_result_free( result ); |
213 | return folders; | 215 | return folders; |
214 | } | 216 | } |
215 | 217 | ||
216 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 218 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
217 | { | 219 | { |
218 | RecMail * m = 0; | 220 | RecMail * m = 0; |
219 | mailimap_msg_att_item *item=0; | 221 | mailimap_msg_att_item *item=0; |
220 | clistcell *current,*c,*cf; | 222 | clistcell *current,*c,*cf; |
221 | mailimap_msg_att_dynamic*flist; | 223 | mailimap_msg_att_dynamic*flist; |
222 | mailimap_flag_fetch*cflag; | 224 | mailimap_flag_fetch*cflag; |
223 | int size; | 225 | int size; |
224 | QBitArray mFlags(7); | 226 | QBitArray mFlags(7); |
225 | QStringList addresslist; | 227 | QStringList addresslist; |
226 | 228 | ||
227 | if (!m_att) { | 229 | if (!m_att) { |
228 | return m; | 230 | return m; |
229 | } | 231 | } |
230 | m = new RecMail(); | 232 | m = new RecMail(); |
231 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 233 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
232 | current = c; | 234 | current = c; |
233 | size = 0; | 235 | size = 0; |
234 | item = (mailimap_msg_att_item*)current->data; | 236 | item = (mailimap_msg_att_item*)current->data; |
235 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 237 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
236 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 238 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
237 | if (!flist->att_list) { | 239 | if (!flist->att_list) { |
238 | continue; | 240 | continue; |
239 | } | 241 | } |
240 | cf = flist->att_list->first; | 242 | cf = flist->att_list->first; |
241 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 243 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
242 | cflag = (mailimap_flag_fetch*)cf->data; | 244 | cflag = (mailimap_flag_fetch*)cf->data; |
243 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 245 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
244 | switch (cflag->fl_flag->fl_type) { | 246 | switch (cflag->fl_flag->fl_type) { |
245 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 247 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
246 | mFlags.setBit(FLAG_ANSWERED); | 248 | mFlags.setBit(FLAG_ANSWERED); |
247 | break; | 249 | break; |
248 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 250 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
249 | mFlags.setBit(FLAG_FLAGGED); | 251 | mFlags.setBit(FLAG_FLAGGED); |
250 | break; | 252 | break; |
251 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 253 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
252 | mFlags.setBit(FLAG_DELETED); | 254 | mFlags.setBit(FLAG_DELETED); |
253 | break; | 255 | break; |
254 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 256 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
255 | mFlags.setBit(FLAG_SEEN); | 257 | mFlags.setBit(FLAG_SEEN); |
256 | break; | 258 | break; |
257 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 259 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
258 | mFlags.setBit(FLAG_DRAFT); | 260 | mFlags.setBit(FLAG_DRAFT); |
259 | break; | 261 | break; |
260 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 262 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
261 | break; | 263 | break; |
262 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 264 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
263 | break; | 265 | break; |
264 | default: | 266 | default: |
265 | break; | 267 | break; |
266 | } | 268 | } |
267 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 269 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
268 | mFlags.setBit(FLAG_RECENT); | 270 | mFlags.setBit(FLAG_RECENT); |
269 | } | 271 | } |
270 | } | 272 | } |
271 | continue; | 273 | continue; |
272 | } | 274 | } |
273 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 275 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
274 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 276 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
275 | m->setDate(head->env_date); | 277 | m->setDate(head->env_date); |
276 | m->setSubject(head->env_subject); | 278 | m->setSubject(head->env_subject); |
277 | if (head->env_from!=NULL) { | 279 | if (head->env_from!=NULL) { |
278 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 280 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
279 | if (addresslist.count()) { | 281 | if (addresslist.count()) { |
280 | m->setFrom(addresslist.first()); | 282 | m->setFrom(addresslist.first()); |
281 | } | 283 | } |
282 | } | 284 | } |
283 | if (head->env_to!=NULL) { | 285 | if (head->env_to!=NULL) { |
284 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 286 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
285 | m->setTo(addresslist); | 287 | m->setTo(addresslist); |
286 | } | 288 | } |
287 | if (head->env_cc!=NULL) { | 289 | if (head->env_cc!=NULL) { |
288 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 290 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
289 | m->setCC(addresslist); | 291 | m->setCC(addresslist); |
290 | } | 292 | } |
291 | if (head->env_bcc!=NULL) { | 293 | if (head->env_bcc!=NULL) { |
292 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 294 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
293 | m->setBcc(addresslist); | 295 | m->setBcc(addresslist); |
294 | } | 296 | } |
295 | if (head->env_reply_to!=NULL) { | 297 | if (head->env_reply_to!=NULL) { |
296 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 298 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
297 | if (addresslist.count()) { | 299 | if (addresslist.count()) { |
298 | m->setReplyto(addresslist.first()); | 300 | m->setReplyto(addresslist.first()); |
299 | } | 301 | } |
300 | } | 302 | } |
301 | m->setMsgid(QString(head->env_message_id)); | 303 | m->setMsgid(QString(head->env_message_id)); |
302 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 304 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
303 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 305 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
304 | #if 0 | 306 | #if 0 |
305 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 307 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
306 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); | 308 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); |
307 | qDebug(da.toString()); | 309 | qDebug(da.toString()); |
308 | #endif | 310 | #endif |
309 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 311 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
310 | size = item->att_data.att_static->att_data.att_rfc822_size; | 312 | size = item->att_data.att_static->att_data.att_rfc822_size; |
311 | } | 313 | } |
312 | } | 314 | } |
313 | /* msg is already deleted */ | 315 | /* msg is already deleted */ |
314 | if (mFlags.testBit(FLAG_DELETED) && m) { | 316 | if (mFlags.testBit(FLAG_DELETED) && m) { |
315 | delete m; | 317 | delete m; |
316 | m = 0; | 318 | m = 0; |
317 | } | 319 | } |
318 | if (m) { | 320 | if (m) { |
319 | m->setFlags(mFlags); | 321 | m->setFlags(mFlags); |
320 | m->setMsgsize(size); | 322 | m->setMsgsize(size); |
321 | } | 323 | } |
322 | return m; | 324 | return m; |
323 | } | 325 | } |
324 | 326 | ||
325 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 327 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
326 | { | 328 | { |
327 | RecBody body; | 329 | RecBody body; |
328 | const char *mb; | 330 | const char *mb; |
329 | int err = MAILIMAP_NO_ERROR; | 331 | int err = MAILIMAP_NO_ERROR; |
330 | clist *result; | 332 | clist *result; |
331 | clistcell *current; | 333 | clistcell *current; |
332 | mailimap_fetch_att *fetchAtt; | 334 | mailimap_fetch_att *fetchAtt; |
333 | mailimap_fetch_type *fetchType; | 335 | mailimap_fetch_type *fetchType; |
334 | mailimap_set *set; | 336 | mailimap_set *set; |
335 | mailimap_body*body_desc; | 337 | mailimap_body*body_desc; |
336 | 338 | ||
337 | mb = mail.getMbox().latin1(); | 339 | mb = mail.getMbox().latin1(); |
338 | 340 | ||
339 | login(); | 341 | login(); |
340 | if (!m_imap) { | 342 | if (!m_imap) { |
341 | return body; | 343 | return body; |
342 | } | 344 | } |
343 | 345 | ||
344 | err = mailimap_select( m_imap, (char*)mb); | 346 | err = mailimap_select( m_imap, (char*)mb); |
345 | if ( err != MAILIMAP_NO_ERROR ) { | 347 | if ( err != MAILIMAP_NO_ERROR ) { |
346 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 348 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
347 | return body; | 349 | return body; |
348 | } | 350 | } |
349 | 351 | ||
350 | result = clist_new(); | 352 | result = clist_new(); |
351 | /* the range has to start at 1!!! not with 0!!!! */ | 353 | /* the range has to start at 1!!! not with 0!!!! */ |
352 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 354 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
353 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 355 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
354 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 356 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
355 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 357 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
356 | mailimap_set_free( set ); | 358 | mailimap_set_free( set ); |
357 | mailimap_fetch_type_free( fetchType ); | 359 | mailimap_fetch_type_free( fetchType ); |
358 | 360 | ||
359 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 361 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
360 | mailimap_msg_att * msg_att; | 362 | mailimap_msg_att * msg_att; |
361 | msg_att = (mailimap_msg_att*)current->data; | 363 | msg_att = (mailimap_msg_att*)current->data; |
362 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 364 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
363 | body_desc = item->att_data.att_static->att_data.att_body; | 365 | body_desc = item->att_data.att_static->att_data.att_body; |
364 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 366 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
365 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 367 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
366 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | 368 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
367 | qDebug("Mulitpart mail"); | 369 | qDebug("Mulitpart mail"); |
368 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | 370 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); |
369 | } | 371 | } |
370 | } else { | 372 | } else { |
371 | qDebug("error fetching body: %s",m_imap->imap_response); | 373 | qDebug("error fetching body: %s",m_imap->imap_response); |
372 | } | 374 | } |
373 | mailimap_fetch_list_free(result); | 375 | mailimap_fetch_list_free(result); |
374 | return body; | 376 | return body; |
375 | } | 377 | } |
376 | 378 | ||
377 | /* this routine is just called when the mail has only ONE part. | 379 | /* this routine is just called when the mail has only ONE part. |
378 | for filling the parts of a multi-part-message there are other | 380 | for filling the parts of a multi-part-message there are other |
379 | routines 'cause we can not simply fetch the whole body. */ | 381 | routines 'cause we can not simply fetch the whole body. */ |
380 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 382 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
381 | { | 383 | { |
382 | if (!mailDescription) { | 384 | if (!mailDescription) { |
383 | return; | 385 | return; |
384 | } | 386 | } |
385 | QString sub,body_text; | 387 | QString sub,body_text; |
386 | RecPart singlePart; | 388 | RecPart singlePart; |
387 | QValueList<int> path; | 389 | QValueList<int> path; |
388 | fillSinglePart(singlePart,mailDescription); | 390 | fillSinglePart(singlePart,mailDescription); |
389 | switch (mailDescription->bd_type) { | 391 | switch (mailDescription->bd_type) { |
390 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 392 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
391 | path.append(1); | 393 | path.append(1); |
392 | body_text = fetchPart(mail,path,true); | 394 | body_text = fetchPart(mail,path,true); |
393 | target_body.setBodytext(body_text); | 395 | target_body.setBodytext(body_text); |
394 | target_body.setDescription(singlePart); | 396 | target_body.setDescription(singlePart); |
395 | break; | 397 | break; |
396 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 398 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
397 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | 399 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); |
398 | path.append(1); | 400 | path.append(1); |
399 | body_text = fetchPart(mail,path,true); | 401 | body_text = fetchPart(mail,path,true); |
400 | target_body.setBodytext(body_text); | 402 | target_body.setBodytext(body_text); |
401 | target_body.setDescription(singlePart); | 403 | target_body.setDescription(singlePart); |
402 | break; | 404 | break; |
403 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 405 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
404 | qDebug("Single attachment"); | 406 | qDebug("Single attachment"); |
405 | target_body.setBodytext(""); | 407 | target_body.setBodytext(""); |
406 | target_body.addPart(singlePart); | 408 | target_body.addPart(singlePart); |
407 | break; | 409 | break; |
408 | default: | 410 | default: |
409 | break; | 411 | break; |
410 | } | 412 | } |
411 | 413 | ||
412 | return; | 414 | return; |
413 | } | 415 | } |
414 | 416 | ||
415 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 417 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
416 | { | 418 | { |
417 | QStringList l; | 419 | QStringList l; |
418 | QString from; | 420 | QString from; |
419 | bool named_from; | 421 | bool named_from; |
420 | clistcell *current = NULL; | 422 | clistcell *current = NULL; |
421 | mailimap_address * current_address=NULL; | 423 | mailimap_address * current_address=NULL; |
422 | if (!list) { | 424 | if (!list) { |
423 | return l; | 425 | return l; |
424 | } | 426 | } |
425 | unsigned int count = 0; | 427 | unsigned int count = 0; |
426 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 428 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
427 | from = ""; | 429 | from = ""; |
428 | named_from = false; | 430 | named_from = false; |
429 | current_address=(mailimap_address*)current->data; | 431 | current_address=(mailimap_address*)current->data; |
430 | if (current_address->ad_personal_name){ | 432 | if (current_address->ad_personal_name){ |
431 | from+=QString(current_address->ad_personal_name); | 433 | from+=QString(current_address->ad_personal_name); |
432 | from+=" "; | 434 | from+=" "; |
433 | named_from = true; | 435 | named_from = true; |
434 | } | 436 | } |
435 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 437 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
436 | from+="<"; | 438 | from+="<"; |
437 | } | 439 | } |
438 | if (current_address->ad_mailbox_name) { | 440 | if (current_address->ad_mailbox_name) { |
439 | from+=QString(current_address->ad_mailbox_name); | 441 | from+=QString(current_address->ad_mailbox_name); |
440 | from+="@"; | 442 | from+="@"; |
441 | } | 443 | } |
442 | if (current_address->ad_host_name) { | 444 | if (current_address->ad_host_name) { |
443 | from+=QString(current_address->ad_host_name); | 445 | from+=QString(current_address->ad_host_name); |
444 | } | 446 | } |
445 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 447 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
446 | from+=">"; | 448 | from+=">"; |
447 | } | 449 | } |
448 | l.append(QString(from)); | 450 | l.append(QString(from)); |
449 | if (++count > 99) { | 451 | if (++count > 99) { |
450 | break; | 452 | break; |
451 | } | 453 | } |
452 | } | 454 | } |
453 | return l; | 455 | return l; |
454 | } | 456 | } |
455 | 457 | ||
456 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 458 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
457 | { | 459 | { |
458 | QString body(""); | 460 | QString body(""); |
459 | const char*mb; | 461 | const char*mb; |
460 | int err; | 462 | int err; |
461 | mailimap_fetch_type *fetchType; | 463 | mailimap_fetch_type *fetchType; |
462 | mailimap_set *set; | 464 | mailimap_set *set; |
463 | clistcell*current,*cur; | 465 | clistcell*current,*cur; |
464 | 466 | ||
465 | login(); | 467 | login(); |
466 | if (!m_imap) { | 468 | if (!m_imap) { |
467 | return body; | 469 | return body; |
468 | } | 470 | } |
469 | if (!internal_call) { | 471 | if (!internal_call) { |
470 | mb = mail.getMbox().latin1(); | 472 | mb = mail.getMbox().latin1(); |
471 | err = mailimap_select( m_imap, (char*)mb); | 473 | err = mailimap_select( m_imap, (char*)mb); |
472 | if ( err != MAILIMAP_NO_ERROR ) { | 474 | if ( err != MAILIMAP_NO_ERROR ) { |
473 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 475 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
474 | return body; | 476 | return body; |
475 | } | 477 | } |
476 | } | 478 | } |
477 | set = mailimap_set_new_single(mail.getNumber()); | 479 | set = mailimap_set_new_single(mail.getNumber()); |
478 | clist*id_list=clist_new(); | 480 | clist*id_list=clist_new(); |
479 | for (unsigned j=0; j < path.count();++j) { | 481 | for (unsigned j=0; j < path.count();++j) { |
480 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 482 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
481 | *p_id = path[j]; | 483 | *p_id = path[j]; |
482 | clist_append(id_list,p_id); | 484 | clist_append(id_list,p_id); |
483 | } | 485 | } |
484 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 486 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
485 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 487 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
486 | mailimap_section * section = mailimap_section_new(section_spec); | 488 | mailimap_section * section = mailimap_section_new(section_spec); |
487 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 489 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
488 | 490 | ||
489 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 491 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
490 | 492 | ||
491 | clist*result = clist_new(); | 493 | clist*result = clist_new(); |
492 | 494 | ||
493 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 495 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
494 | mailimap_set_free( set ); | 496 | mailimap_set_free( set ); |
495 | mailimap_fetch_type_free( fetchType ); | 497 | mailimap_fetch_type_free( fetchType ); |
496 | 498 | ||
497 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 499 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
498 | mailimap_msg_att * msg_att; | 500 | mailimap_msg_att * msg_att; |
499 | msg_att = (mailimap_msg_att*)current->data; | 501 | msg_att = (mailimap_msg_att*)current->data; |
500 | mailimap_msg_att_item*msg_att_item; | 502 | mailimap_msg_att_item*msg_att_item; |
501 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 503 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
502 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 504 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
503 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 505 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
504 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 506 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
505 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 507 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
506 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 508 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
507 | if (text) { | 509 | if (text) { |
508 | body = QString(text); | 510 | body = QString(text); |
509 | free(text); | 511 | free(text); |
510 | } else { | 512 | } else { |
511 | body = ""; | 513 | body = ""; |
512 | } | 514 | } |
513 | } | 515 | } |
514 | } | 516 | } |
515 | } | 517 | } |
516 | 518 | ||
517 | } else { | 519 | } else { |
518 | qDebug("error fetching text: %s",m_imap->imap_response); | 520 | qDebug("error fetching text: %s",m_imap->imap_response); |
519 | } | 521 | } |
520 | mailimap_fetch_list_free(result); | 522 | mailimap_fetch_list_free(result); |
521 | return body; | 523 | return body; |
522 | } | 524 | } |
523 | 525 | ||
524 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 526 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
525 | { | 527 | { |
526 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 528 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
527 | if (!mailDescription||current_recursion==10) { | 529 | if (!mailDescription||current_recursion==10) { |
528 | return; | 530 | return; |
529 | } | 531 | } |
530 | clistcell*current; | 532 | clistcell*current; |
531 | mailimap_body*current_body; | 533 | mailimap_body*current_body; |
532 | unsigned int count = 0; | 534 | unsigned int count = 0; |
533 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 535 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
534 | /* the point in the message */ | 536 | /* the point in the message */ |
535 | ++count; | 537 | ++count; |
536 | current_body = (mailimap_body*)current->data; | 538 | current_body = (mailimap_body*)current->data; |
537 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 539 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
538 | QValueList<int>clist = recList; | 540 | QValueList<int>clist = recList; |
539 | clist.append(count); | 541 | clist.append(count); |
540 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); | 542 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); |
541 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 543 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ |
542 | RecPart currentPart; | 544 | RecPart currentPart; |
543 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 545 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
544 | QValueList<int>clist = recList; | 546 | QValueList<int>clist = recList; |
545 | clist.append(count); | 547 | clist.append(count); |
546 | /* important: Check for is NULL 'cause a body can be empty! */ | 548 | /* important: Check for is NULL 'cause a body can be empty! */ |
547 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 549 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
548 | QString body_text = fetchPart(mail,clist,true); | 550 | QString body_text = fetchPart(mail,clist,true); |
549 | target_body.setDescription(currentPart); | 551 | target_body.setDescription(currentPart); |
550 | target_body.setBodytext(body_text); | 552 | target_body.setBodytext(body_text); |
551 | } else { | 553 | } else { |
552 | QString id(""); | 554 | QString id(""); |
553 | for (unsigned int j = 0; j < clist.count();++j) { | 555 | for (unsigned int j = 0; j < clist.count();++j) { |
554 | id+=(j>0?" ":""); | 556 | id+=(j>0?" ":""); |
555 | id+=QString("%1").arg(clist[j]); | 557 | id+=QString("%1").arg(clist[j]); |
556 | } | 558 | } |
557 | qDebug("ID= %s",id.latin1()); | 559 | qDebug("ID= %s",id.latin1()); |
558 | currentPart.setIdentifier(id); | 560 | currentPart.setIdentifier(id); |
559 | currentPart.setPositionlist(clist); | 561 | currentPart.setPositionlist(clist); |
560 | target_body.addPart(currentPart); | 562 | target_body.addPart(currentPart); |
561 | } | 563 | } |
562 | } | 564 | } |
563 | } | 565 | } |
564 | } | 566 | } |
565 | 567 | ||
566 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 568 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
567 | { | 569 | { |
568 | if (!Description) { | 570 | if (!Description) { |
569 | return; | 571 | return; |
570 | } | 572 | } |
571 | switch (Description->bd_type) { | 573 | switch (Description->bd_type) { |
572 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 574 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
573 | target_part.setType("text"); | 575 | target_part.setType("text"); |
574 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 576 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
575 | break; | 577 | break; |
576 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 578 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
577 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 579 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
578 | break; | 580 | break; |
579 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 581 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
580 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 582 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
581 | break; | 583 | break; |
582 | default: | 584 | default: |
583 | break; | 585 | break; |
584 | } | 586 | } |
585 | } | 587 | } |
586 | 588 | ||
587 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 589 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
588 | { | 590 | { |
589 | if (!which) { | 591 | if (!which) { |
590 | return; | 592 | return; |
591 | } | 593 | } |
592 | QString sub; | 594 | QString sub; |
593 | sub = which->bd_media_text; | 595 | sub = which->bd_media_text; |
594 | target_part.setSubtype(sub.lower()); | 596 | target_part.setSubtype(sub.lower()); |
595 | target_part.setLines(which->bd_lines); | 597 | target_part.setLines(which->bd_lines); |
596 | fillBodyFields(target_part,which->bd_fields); | 598 | fillBodyFields(target_part,which->bd_fields); |
597 | } | 599 | } |
598 | 600 | ||
599 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 601 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
600 | { | 602 | { |
601 | if (!which) { | 603 | if (!which) { |
602 | return; | 604 | return; |
603 | } | 605 | } |
604 | // QString sub; | 606 | // QString sub; |
605 | // sub = which->bd_media_text; | 607 | // sub = which->bd_media_text; |
606 | // target_part.setSubtype(sub.lower()); | 608 | // target_part.setSubtype(sub.lower()); |
607 | qDebug("Message part"); | 609 | qDebug("Message part"); |
608 | /* we set this type to text/plain */ | 610 | /* we set this type to text/plain */ |
609 | target_part.setType("text"); | 611 | target_part.setType("text"); |
610 | target_part.setSubtype("plain"); | 612 | target_part.setSubtype("plain"); |
611 | target_part.setLines(which->bd_lines); | 613 | target_part.setLines(which->bd_lines); |
612 | fillBodyFields(target_part,which->bd_fields); | 614 | fillBodyFields(target_part,which->bd_fields); |
613 | } | 615 | } |
614 | 616 | ||
615 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 617 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
616 | { | 618 | { |
617 | if (!which) { | 619 | if (!which) { |
618 | return; | 620 | return; |
619 | } | 621 | } |
620 | QString type,sub; | 622 | QString type,sub; |
621 | switch (which->bd_media_basic->med_type) { | 623 | switch (which->bd_media_basic->med_type) { |
622 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 624 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
623 | type = "application"; | 625 | type = "application"; |
624 | break; | 626 | break; |
625 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 627 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
626 | type = "audio"; | 628 | type = "audio"; |
627 | break; | 629 | break; |
628 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 630 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
629 | type = "image"; | 631 | type = "image"; |
630 | break; | 632 | break; |
631 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 633 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
632 | type = "message"; | 634 | type = "message"; |
633 | break; | 635 | break; |
634 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 636 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
635 | type = "video"; | 637 | type = "video"; |
636 | break; | 638 | break; |
637 | case MAILIMAP_MEDIA_BASIC_OTHER: | 639 | case MAILIMAP_MEDIA_BASIC_OTHER: |
638 | default: | 640 | default: |
639 | if (which->bd_media_basic->med_basic_type) { | 641 | if (which->bd_media_basic->med_basic_type) { |
640 | type = which->bd_media_basic->med_basic_type; | 642 | type = which->bd_media_basic->med_basic_type; |
641 | } else { | 643 | } else { |
642 | type = ""; | 644 | type = ""; |
643 | } | 645 | } |
644 | break; | 646 | break; |
645 | } | 647 | } |
646 | if (which->bd_media_basic->med_subtype) { | 648 | if (which->bd_media_basic->med_subtype) { |
647 | sub = which->bd_media_basic->med_subtype; | 649 | sub = which->bd_media_basic->med_subtype; |
648 | } else { | 650 | } else { |
649 | sub = ""; | 651 | sub = ""; |
650 | } | 652 | } |
651 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | 653 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); |
652 | target_part.setType(type.lower()); | 654 | target_part.setType(type.lower()); |
653 | target_part.setSubtype(sub.lower()); | 655 | target_part.setSubtype(sub.lower()); |
654 | fillBodyFields(target_part,which->bd_fields); | 656 | fillBodyFields(target_part,which->bd_fields); |
655 | } | 657 | } |
656 | 658 | ||
657 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 659 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) |
658 | { | 660 | { |
659 | if (!which) return; | 661 | if (!which) return; |
660 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 662 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
661 | clistcell*cur; | 663 | clistcell*cur; |
662 | mailimap_single_body_fld_param*param=0; | 664 | mailimap_single_body_fld_param*param=0; |
663 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 665 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
664 | param = (mailimap_single_body_fld_param*)cur->data; | 666 | param = (mailimap_single_body_fld_param*)cur->data; |
665 | if (param) { | 667 | if (param) { |
666 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 668 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
667 | } | 669 | } |
668 | } | 670 | } |
669 | } | 671 | } |
670 | mailimap_body_fld_enc*enc = which->bd_encoding; | 672 | mailimap_body_fld_enc*enc = which->bd_encoding; |
671 | QString encoding(""); | 673 | QString encoding(""); |
672 | switch (enc->enc_type) { | 674 | switch (enc->enc_type) { |
673 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 675 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
674 | encoding = "7bit"; | 676 | encoding = "7bit"; |
675 | break; | 677 | break; |
676 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 678 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
677 | encoding = "8bit"; | 679 | encoding = "8bit"; |
678 | break; | 680 | break; |
679 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 681 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
680 | encoding="binary"; | 682 | encoding="binary"; |
681 | break; | 683 | break; |
682 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 684 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
683 | encoding="base64"; | 685 | encoding="base64"; |
684 | break; | 686 | break; |
685 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 687 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
686 | encoding="quoted-printable"; | 688 | encoding="quoted-printable"; |
687 | break; | 689 | break; |
688 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 690 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
689 | default: | 691 | default: |
690 | if (enc->enc_value) { | 692 | if (enc->enc_value) { |
691 | char*t=enc->enc_value; | 693 | char*t=enc->enc_value; |
692 | encoding=QString(enc->enc_value); | 694 | encoding=QString(enc->enc_value); |
693 | enc->enc_value=0L; | 695 | enc->enc_value=0L; |
694 | free(t); | 696 | free(t); |
695 | } | 697 | } |
696 | } | 698 | } |
697 | target_part.setEncoding(encoding); | 699 | target_part.setEncoding(encoding); |
698 | target_part.setSize(which->bd_size); | 700 | target_part.setSize(which->bd_size); |
699 | } | 701 | } |
700 | 702 | ||
701 | QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) | 703 | QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) |
702 | { | 704 | { |
703 | return fetchPart(mail,part.Positionlist(),false); | 705 | return fetchPart(mail,part.Positionlist(),false); |
704 | } | 706 | } |
705 | 707 | ||
706 | void IMAPwrapper::deleteMail(const RecMail&mail) | 708 | void IMAPwrapper::deleteMail(const RecMail&mail) |
707 | { | 709 | { |
708 | mailimap_flag_list*flist; | 710 | mailimap_flag_list*flist; |
709 | mailimap_set *set; | 711 | mailimap_set *set; |
710 | mailimap_store_att_flags * store_flags; | 712 | mailimap_store_att_flags * store_flags; |
711 | int err; | 713 | int err; |
712 | login(); | 714 | login(); |
713 | if (!m_imap) { | 715 | if (!m_imap) { |
714 | return; | 716 | return; |
715 | } | 717 | } |
716 | const char *mb = mail.getMbox().latin1(); | 718 | const char *mb = mail.getMbox().latin1(); |
717 | err = mailimap_select( m_imap, (char*)mb); | 719 | err = mailimap_select( m_imap, (char*)mb); |
718 | if ( err != MAILIMAP_NO_ERROR ) { | 720 | if ( err != MAILIMAP_NO_ERROR ) { |
719 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); | 721 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); |
720 | return; | 722 | return; |
721 | } | 723 | } |
722 | flist = mailimap_flag_list_new_empty(); | 724 | flist = mailimap_flag_list_new_empty(); |
723 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 725 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
724 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 726 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
725 | set = mailimap_set_new_single(mail.getNumber()); | 727 | set = mailimap_set_new_single(mail.getNumber()); |
726 | err = mailimap_store(m_imap,set,store_flags); | 728 | err = mailimap_store(m_imap,set,store_flags); |
727 | mailimap_set_free( set ); | 729 | mailimap_set_free( set ); |
728 | mailimap_store_att_flags_free(store_flags); | 730 | mailimap_store_att_flags_free(store_flags); |
729 | 731 | ||
730 | if (err != MAILIMAP_NO_ERROR) { | 732 | if (err != MAILIMAP_NO_ERROR) { |
731 | qDebug("error deleting mail: %s",m_imap->imap_response); | 733 | qDebug("error deleting mail: %s",m_imap->imap_response); |
732 | return; | 734 | return; |
733 | } | 735 | } |
734 | qDebug("deleting mail: %s",m_imap->imap_response); | 736 | qDebug("deleting mail: %s",m_imap->imap_response); |
735 | /* should we realy do that at this moment? */ | 737 | /* should we realy do that at this moment? */ |
736 | err = mailimap_expunge(m_imap); | 738 | err = mailimap_expunge(m_imap); |
737 | if (err != MAILIMAP_NO_ERROR) { | 739 | if (err != MAILIMAP_NO_ERROR) { |
738 | qDebug("error deleting mail: %s",m_imap->imap_response); | 740 | qDebug("error deleting mail: %s",m_imap->imap_response); |
739 | } | 741 | } |
740 | qDebug("Delete successfull %s",m_imap->imap_response); | 742 | qDebug("Delete successfull %s",m_imap->imap_response); |
741 | } | 743 | } |
742 | 744 | ||
743 | void IMAPwrapper::answeredMail(const RecMail&mail) | 745 | void IMAPwrapper::answeredMail(const RecMail&mail) |
744 | { | 746 | { |
745 | mailimap_flag_list*flist; | 747 | mailimap_flag_list*flist; |
746 | mailimap_set *set; | 748 | mailimap_set *set; |
747 | mailimap_store_att_flags * store_flags; | 749 | mailimap_store_att_flags * store_flags; |
748 | int err; | 750 | int err; |
749 | login(); | 751 | login(); |
750 | if (!m_imap) { | 752 | if (!m_imap) { |
751 | return; | 753 | return; |
752 | } | 754 | } |
753 | const char *mb = mail.getMbox().latin1(); | 755 | const char *mb = mail.getMbox().latin1(); |
754 | err = mailimap_select( m_imap, (char*)mb); | 756 | err = mailimap_select( m_imap, (char*)mb); |
755 | if ( err != MAILIMAP_NO_ERROR ) { | 757 | if ( err != MAILIMAP_NO_ERROR ) { |
756 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); | 758 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); |
757 | return; | 759 | return; |
758 | } | 760 | } |
759 | flist = mailimap_flag_list_new_empty(); | 761 | flist = mailimap_flag_list_new_empty(); |
760 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 762 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
761 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 763 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
762 | set = mailimap_set_new_single(mail.getNumber()); | 764 | set = mailimap_set_new_single(mail.getNumber()); |
763 | err = mailimap_store(m_imap,set,store_flags); | 765 | err = mailimap_store(m_imap,set,store_flags); |
764 | mailimap_set_free( set ); | 766 | mailimap_set_free( set ); |
765 | mailimap_store_att_flags_free(store_flags); | 767 | mailimap_store_att_flags_free(store_flags); |
766 | 768 | ||
767 | if (err != MAILIMAP_NO_ERROR) { | 769 | if (err != MAILIMAP_NO_ERROR) { |
768 | qDebug("error marking mail: %s",m_imap->imap_response); | 770 | qDebug("error marking mail: %s",m_imap->imap_response); |
769 | return; | 771 | return; |
770 | } | 772 | } |
771 | } | 773 | } |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index b253b49..0ce2c6c 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,771 +1,773 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include "imapwrapper.h" | 4 | #include "imapwrapper.h" |
5 | #include "mailtypes.h" | 5 | #include "mailtypes.h" |
6 | #include <libetpan/mailimap.h> | 6 | #include <libetpan/mailimap.h> |
7 | 7 | ||
8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
9 | : AbstractMail() | 9 | : AbstractMail() |
10 | { | 10 | { |
11 | account = a; | 11 | account = a; |
12 | m_imap = 0; | 12 | m_imap = 0; |
13 | } | 13 | } |
14 | 14 | ||
15 | IMAPwrapper::~IMAPwrapper() | 15 | IMAPwrapper::~IMAPwrapper() |
16 | { | 16 | { |
17 | logout(); | 17 | logout(); |
18 | } | 18 | } |
19 | 19 | ||
20 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 20 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
21 | { | 21 | { |
22 | qDebug( "IMAP: %i of %i", current, maximum ); | 22 | qDebug( "IMAP: %i of %i", current, maximum ); |
23 | } | 23 | } |
24 | 24 | ||
25 | void IMAPwrapper::login() | 25 | void IMAPwrapper::login() |
26 | { | 26 | { |
27 | const char *server, *user, *pass; | 27 | const char *server, *user, *pass; |
28 | uint16_t port; | 28 | uint16_t port; |
29 | int err = MAILIMAP_NO_ERROR; | 29 | int err = MAILIMAP_NO_ERROR; |
30 | 30 | ||
31 | /* we are connected this moment */ | 31 | /* we are connected this moment */ |
32 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 32 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
33 | if (m_imap) { | 33 | if (m_imap) { |
34 | mailstream_flush(m_imap->imap_stream); | 34 | mailstream_flush(m_imap->imap_stream); |
35 | return; | 35 | return; |
36 | } | 36 | } |
37 | server = account->getServer().latin1(); | 37 | server = account->getServer().latin1(); |
38 | port = account->getPort().toUInt(); | 38 | port = account->getPort().toUInt(); |
39 | user = account->getUser().latin1(); | 39 | user = account->getUser().latin1(); |
40 | pass = account->getPassword().latin1(); | 40 | pass = account->getPassword().latin1(); |
41 | 41 | ||
42 | m_imap = mailimap_new( 20, &imap_progress ); | 42 | m_imap = mailimap_new( 20, &imap_progress ); |
43 | /* connect */ | 43 | /* connect */ |
44 | if (account->getSSL()) { | 44 | if (account->getSSL()) { |
45 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 45 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
46 | } else { | 46 | } else { |
47 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 47 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
48 | } | 48 | } |
49 | 49 | ||
50 | if ( err != MAILIMAP_NO_ERROR && | 50 | if ( err != MAILIMAP_NO_ERROR && |
51 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 51 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
52 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 52 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
53 | qDebug("error connecting server: %s",m_imap->imap_response); | 53 | qDebug("error connecting server: %s",m_imap->imap_response); |
54 | mailimap_free( m_imap ); | 54 | mailimap_free( m_imap ); |
55 | m_imap = 0; | 55 | m_imap = 0; |
56 | return; | 56 | return; |
57 | } | 57 | } |
58 | 58 | ||
59 | /* login */ | 59 | /* login */ |
60 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 60 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
61 | if ( err != MAILIMAP_NO_ERROR ) { | 61 | if ( err != MAILIMAP_NO_ERROR ) { |
62 | qDebug("error logging in imap: %s",m_imap->imap_response); | 62 | qDebug("error logging in imap: %s",m_imap->imap_response); |
63 | err = mailimap_close( m_imap ); | 63 | err = mailimap_close( m_imap ); |
64 | mailimap_free( m_imap ); | 64 | mailimap_free( m_imap ); |
65 | m_imap = 0; | 65 | m_imap = 0; |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | void IMAPwrapper::logout() | 69 | void IMAPwrapper::logout() |
70 | { | 70 | { |
71 | int err = MAILIMAP_NO_ERROR; | 71 | int err = MAILIMAP_NO_ERROR; |
72 | if (!m_imap) return; | 72 | if (!m_imap) return; |
73 | err = mailimap_logout( m_imap ); | 73 | err = mailimap_logout( m_imap ); |
74 | err = mailimap_close( m_imap ); | 74 | err = mailimap_close( m_imap ); |
75 | mailimap_free( m_imap ); | 75 | mailimap_free( m_imap ); |
76 | m_imap = 0; | 76 | m_imap = 0; |
77 | } | 77 | } |
78 | 78 | ||
79 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 79 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
80 | { | 80 | { |
81 | const char *mb; | 81 | const char *mb; |
82 | int err = MAILIMAP_NO_ERROR; | 82 | int err = MAILIMAP_NO_ERROR; |
83 | clist *result; | 83 | clist *result; |
84 | clistcell *current; | 84 | clistcell *current; |
85 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; | 85 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; |
86 | mailimap_fetch_type *fetchType; | 86 | mailimap_fetch_type *fetchType; |
87 | mailimap_set *set; | 87 | mailimap_set *set; |
88 | 88 | ||
89 | mb = mailbox.latin1(); | 89 | mb = mailbox.latin1(); |
90 | login(); | 90 | login(); |
91 | if (!m_imap) { | 91 | if (!m_imap) { |
92 | return; | 92 | return; |
93 | } | 93 | } |
94 | /* select mailbox READONLY for operations */ | 94 | /* select mailbox READONLY for operations */ |
95 | err = mailimap_examine( m_imap, (char*)mb); | 95 | err = mailimap_examine( m_imap, (char*)mb); |
96 | if ( err != MAILIMAP_NO_ERROR ) { | 96 | if ( err != MAILIMAP_NO_ERROR ) { |
97 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 97 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
98 | return; | 98 | return; |
99 | } | 99 | } |
100 | 100 | ||
101 | int last = m_imap->imap_selection_info->sel_exists; | 101 | int last = m_imap->imap_selection_info->sel_exists; |
102 | 102 | ||
103 | if (last == 0) { | 103 | if (last == 0) { |
104 | qDebug("mailbox has no mails"); | 104 | qDebug("mailbox has no mails"); |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | 107 | ||
108 | result = clist_new(); | 108 | result = clist_new(); |
109 | /* the range has to start at 1!!! not with 0!!!! */ | 109 | /* the range has to start at 1!!! not with 0!!!! */ |
110 | set = mailimap_set_new_interval( 1, last ); | 110 | set = mailimap_set_new_interval( 1, last ); |
111 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 111 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
114 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 114 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
115 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 115 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
116 | 116 | ||
117 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 117 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
118 | mailimap_set_free( set ); | 118 | mailimap_set_free( set ); |
119 | mailimap_fetch_type_free( fetchType ); | 119 | mailimap_fetch_type_free( fetchType ); |
120 | 120 | ||
121 | QString date,subject,from; | 121 | QString date,subject,from; |
122 | 122 | ||
123 | if ( err == MAILIMAP_NO_ERROR ) { | 123 | if ( err == MAILIMAP_NO_ERROR ) { |
124 | 124 | ||
125 | mailimap_msg_att * msg_att; | 125 | mailimap_msg_att * msg_att; |
126 | int i = 0; | 126 | int i = 0; |
127 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 127 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
128 | ++i; | 128 | ++i; |
129 | msg_att = (mailimap_msg_att*)current->data; | 129 | msg_att = (mailimap_msg_att*)current->data; |
130 | RecMail*m = parse_list_result(msg_att); | 130 | RecMail*m = parse_list_result(msg_att); |
131 | if (m) { | 131 | if (m) { |
132 | m->setNumber(i); | 132 | m->setNumber(i); |
133 | m->setMbox(mailbox); | 133 | m->setMbox(mailbox); |
134 | m->setWrapper(this); | 134 | m->setWrapper(this); |
135 | target.append(m); | 135 | target.append(m); |
136 | } | 136 | } |
137 | } | 137 | } |
138 | } else { | 138 | } else { |
139 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 139 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
140 | } | 140 | } |
141 | mailimap_fetch_list_free(result); | 141 | mailimap_fetch_list_free(result); |
142 | } | 142 | } |
143 | 143 | ||
144 | QList<Folder>* IMAPwrapper::listFolders() | 144 | QList<Folder>* IMAPwrapper::listFolders() |
145 | { | 145 | { |
146 | const char *path, *mask; | 146 | const char *path, *mask; |
147 | int err = MAILIMAP_NO_ERROR; | 147 | int err = MAILIMAP_NO_ERROR; |
148 | clist *result; | 148 | clist *result; |
149 | clistcell *current; | 149 | clistcell *current; |
150 | 150 | ||
151 | QList<Folder> * folders = new QList<Folder>(); | 151 | QList<Folder> * folders = new QList<Folder>(); |
152 | folders->setAutoDelete( false ); | 152 | folders->setAutoDelete( false ); |
153 | login(); | 153 | login(); |
154 | if (!m_imap) { | 154 | if (!m_imap) { |
155 | return folders; | 155 | return folders; |
156 | } | 156 | } |
157 | 157 | ||
158 | /* | 158 | /* |
159 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 159 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
160 | * We must not forget to filter them out in next loop! | 160 | * We must not forget to filter them out in next loop! |
161 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 161 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
162 | */ | 162 | */ |
163 | QString temp; | 163 | QString temp; |
164 | mask = "INBOX" ; | 164 | mask = "INBOX" ; |
165 | result = clist_new(); | 165 | result = clist_new(); |
166 | mailimap_mailbox_list *list; | 166 | mailimap_mailbox_list *list; |
167 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 167 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
168 | if ( err == MAILIMAP_NO_ERROR ) { | 168 | if ( err == MAILIMAP_NO_ERROR ) { |
169 | current = result->first; | 169 | current = result->first; |
170 | for ( int i = result->count; i > 0; i-- ) { | 170 | for ( int i = result->count; i > 0; i-- ) { |
171 | list = (mailimap_mailbox_list *) current->data; | 171 | list = (mailimap_mailbox_list *) current->data; |
172 | // it is better use the deep copy mechanism of qt itself | 172 | // it is better use the deep copy mechanism of qt itself |
173 | // instead of using strdup! | 173 | // instead of using strdup! |
174 | temp = list->mb_name; | 174 | temp = list->mb_name; |
175 | folders->append( new IMAPFolder(temp)); | 175 | folders->append( new IMAPFolder(temp)); |
176 | current = current->next; | 176 | current = current->next; |
177 | } | 177 | } |
178 | } else { | 178 | } else { |
179 | qDebug("error fetching folders: %s",m_imap->imap_response); | 179 | qDebug("error fetching folders: %s",m_imap->imap_response); |
180 | } | 180 | } |
181 | mailimap_list_result_free( result ); | 181 | mailimap_list_result_free( result ); |
182 | 182 | ||
183 | /* | 183 | /* |
184 | * second stage - get the other then inbox folders | 184 | * second stage - get the other then inbox folders |
185 | */ | 185 | */ |
186 | mask = "*" ; | 186 | mask = "*" ; |
187 | path = account->getPrefix().latin1(); | 187 | path = account->getPrefix().latin1(); |
188 | if (!path) path = ""; | 188 | if (!path) path = ""; |
189 | result = clist_new(); | 189 | result = clist_new(); |
190 | qDebug(path); | 190 | qDebug(path); |
191 | bool selectable = true; | 191 | bool selectable = true; |
192 | mailimap_mbx_list_flags*bflags; | 192 | mailimap_mbx_list_flags*bflags; |
193 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 193 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
194 | if ( err == MAILIMAP_NO_ERROR ) { | 194 | if ( err == MAILIMAP_NO_ERROR ) { |
195 | current = result->first; | 195 | current = result->first; |
196 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 196 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
197 | list = (mailimap_mailbox_list *) current->data; | 197 | list = (mailimap_mailbox_list *) current->data; |
198 | // it is better use the deep copy mechanism of qt itself | 198 | // it is better use the deep copy mechanism of qt itself |
199 | // instead of using strdup! | 199 | // instead of using strdup! |
200 | temp = list->mb_name; | 200 | temp = list->mb_name; |
201 | if (temp.lower()=="inbox") | 201 | if (temp.lower()=="inbox") |
202 | continue; | 202 | continue; |
203 | if (temp.lower()==account->getPrefix().lower()) | ||
204 | continue; | ||
203 | if ( (bflags = list->mb_flag) ) { | 205 | if ( (bflags = list->mb_flag) ) { |
204 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 206 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
205 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 207 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
206 | } | 208 | } |
207 | folders->append(new IMAPFolder(temp,selectable)); | 209 | folders->append(new IMAPFolder(temp,selectable,account->getPrefix())); |
208 | } | 210 | } |
209 | } else { | 211 | } else { |
210 | qDebug("error fetching folders %s",m_imap->imap_response); | 212 | qDebug("error fetching folders %s",m_imap->imap_response); |
211 | } | 213 | } |
212 | mailimap_list_result_free( result ); | 214 | mailimap_list_result_free( result ); |
213 | return folders; | 215 | return folders; |
214 | } | 216 | } |
215 | 217 | ||
216 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 218 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
217 | { | 219 | { |
218 | RecMail * m = 0; | 220 | RecMail * m = 0; |
219 | mailimap_msg_att_item *item=0; | 221 | mailimap_msg_att_item *item=0; |
220 | clistcell *current,*c,*cf; | 222 | clistcell *current,*c,*cf; |
221 | mailimap_msg_att_dynamic*flist; | 223 | mailimap_msg_att_dynamic*flist; |
222 | mailimap_flag_fetch*cflag; | 224 | mailimap_flag_fetch*cflag; |
223 | int size; | 225 | int size; |
224 | QBitArray mFlags(7); | 226 | QBitArray mFlags(7); |
225 | QStringList addresslist; | 227 | QStringList addresslist; |
226 | 228 | ||
227 | if (!m_att) { | 229 | if (!m_att) { |
228 | return m; | 230 | return m; |
229 | } | 231 | } |
230 | m = new RecMail(); | 232 | m = new RecMail(); |
231 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 233 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
232 | current = c; | 234 | current = c; |
233 | size = 0; | 235 | size = 0; |
234 | item = (mailimap_msg_att_item*)current->data; | 236 | item = (mailimap_msg_att_item*)current->data; |
235 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 237 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
236 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 238 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
237 | if (!flist->att_list) { | 239 | if (!flist->att_list) { |
238 | continue; | 240 | continue; |
239 | } | 241 | } |
240 | cf = flist->att_list->first; | 242 | cf = flist->att_list->first; |
241 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 243 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
242 | cflag = (mailimap_flag_fetch*)cf->data; | 244 | cflag = (mailimap_flag_fetch*)cf->data; |
243 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 245 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
244 | switch (cflag->fl_flag->fl_type) { | 246 | switch (cflag->fl_flag->fl_type) { |
245 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 247 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
246 | mFlags.setBit(FLAG_ANSWERED); | 248 | mFlags.setBit(FLAG_ANSWERED); |
247 | break; | 249 | break; |
248 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 250 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
249 | mFlags.setBit(FLAG_FLAGGED); | 251 | mFlags.setBit(FLAG_FLAGGED); |
250 | break; | 252 | break; |
251 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 253 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
252 | mFlags.setBit(FLAG_DELETED); | 254 | mFlags.setBit(FLAG_DELETED); |
253 | break; | 255 | break; |
254 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 256 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
255 | mFlags.setBit(FLAG_SEEN); | 257 | mFlags.setBit(FLAG_SEEN); |
256 | break; | 258 | break; |
257 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 259 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
258 | mFlags.setBit(FLAG_DRAFT); | 260 | mFlags.setBit(FLAG_DRAFT); |
259 | break; | 261 | break; |
260 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 262 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
261 | break; | 263 | break; |
262 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 264 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
263 | break; | 265 | break; |
264 | default: | 266 | default: |
265 | break; | 267 | break; |
266 | } | 268 | } |
267 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 269 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
268 | mFlags.setBit(FLAG_RECENT); | 270 | mFlags.setBit(FLAG_RECENT); |
269 | } | 271 | } |
270 | } | 272 | } |
271 | continue; | 273 | continue; |
272 | } | 274 | } |
273 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 275 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
274 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 276 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
275 | m->setDate(head->env_date); | 277 | m->setDate(head->env_date); |
276 | m->setSubject(head->env_subject); | 278 | m->setSubject(head->env_subject); |
277 | if (head->env_from!=NULL) { | 279 | if (head->env_from!=NULL) { |
278 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 280 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
279 | if (addresslist.count()) { | 281 | if (addresslist.count()) { |
280 | m->setFrom(addresslist.first()); | 282 | m->setFrom(addresslist.first()); |
281 | } | 283 | } |
282 | } | 284 | } |
283 | if (head->env_to!=NULL) { | 285 | if (head->env_to!=NULL) { |
284 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 286 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
285 | m->setTo(addresslist); | 287 | m->setTo(addresslist); |
286 | } | 288 | } |
287 | if (head->env_cc!=NULL) { | 289 | if (head->env_cc!=NULL) { |
288 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 290 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
289 | m->setCC(addresslist); | 291 | m->setCC(addresslist); |
290 | } | 292 | } |
291 | if (head->env_bcc!=NULL) { | 293 | if (head->env_bcc!=NULL) { |
292 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 294 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
293 | m->setBcc(addresslist); | 295 | m->setBcc(addresslist); |
294 | } | 296 | } |
295 | if (head->env_reply_to!=NULL) { | 297 | if (head->env_reply_to!=NULL) { |
296 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 298 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
297 | if (addresslist.count()) { | 299 | if (addresslist.count()) { |
298 | m->setReplyto(addresslist.first()); | 300 | m->setReplyto(addresslist.first()); |
299 | } | 301 | } |
300 | } | 302 | } |
301 | m->setMsgid(QString(head->env_message_id)); | 303 | m->setMsgid(QString(head->env_message_id)); |
302 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 304 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
303 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 305 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
304 | #if 0 | 306 | #if 0 |
305 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 307 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
306 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); | 308 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); |
307 | qDebug(da.toString()); | 309 | qDebug(da.toString()); |
308 | #endif | 310 | #endif |
309 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 311 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
310 | size = item->att_data.att_static->att_data.att_rfc822_size; | 312 | size = item->att_data.att_static->att_data.att_rfc822_size; |
311 | } | 313 | } |
312 | } | 314 | } |
313 | /* msg is already deleted */ | 315 | /* msg is already deleted */ |
314 | if (mFlags.testBit(FLAG_DELETED) && m) { | 316 | if (mFlags.testBit(FLAG_DELETED) && m) { |
315 | delete m; | 317 | delete m; |
316 | m = 0; | 318 | m = 0; |
317 | } | 319 | } |
318 | if (m) { | 320 | if (m) { |
319 | m->setFlags(mFlags); | 321 | m->setFlags(mFlags); |
320 | m->setMsgsize(size); | 322 | m->setMsgsize(size); |
321 | } | 323 | } |
322 | return m; | 324 | return m; |
323 | } | 325 | } |
324 | 326 | ||
325 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 327 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
326 | { | 328 | { |
327 | RecBody body; | 329 | RecBody body; |
328 | const char *mb; | 330 | const char *mb; |
329 | int err = MAILIMAP_NO_ERROR; | 331 | int err = MAILIMAP_NO_ERROR; |
330 | clist *result; | 332 | clist *result; |
331 | clistcell *current; | 333 | clistcell *current; |
332 | mailimap_fetch_att *fetchAtt; | 334 | mailimap_fetch_att *fetchAtt; |
333 | mailimap_fetch_type *fetchType; | 335 | mailimap_fetch_type *fetchType; |
334 | mailimap_set *set; | 336 | mailimap_set *set; |
335 | mailimap_body*body_desc; | 337 | mailimap_body*body_desc; |
336 | 338 | ||
337 | mb = mail.getMbox().latin1(); | 339 | mb = mail.getMbox().latin1(); |
338 | 340 | ||
339 | login(); | 341 | login(); |
340 | if (!m_imap) { | 342 | if (!m_imap) { |
341 | return body; | 343 | return body; |
342 | } | 344 | } |
343 | 345 | ||
344 | err = mailimap_select( m_imap, (char*)mb); | 346 | err = mailimap_select( m_imap, (char*)mb); |
345 | if ( err != MAILIMAP_NO_ERROR ) { | 347 | if ( err != MAILIMAP_NO_ERROR ) { |
346 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 348 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
347 | return body; | 349 | return body; |
348 | } | 350 | } |
349 | 351 | ||
350 | result = clist_new(); | 352 | result = clist_new(); |
351 | /* the range has to start at 1!!! not with 0!!!! */ | 353 | /* the range has to start at 1!!! not with 0!!!! */ |
352 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 354 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
353 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 355 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
354 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 356 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
355 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 357 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
356 | mailimap_set_free( set ); | 358 | mailimap_set_free( set ); |
357 | mailimap_fetch_type_free( fetchType ); | 359 | mailimap_fetch_type_free( fetchType ); |
358 | 360 | ||
359 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 361 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
360 | mailimap_msg_att * msg_att; | 362 | mailimap_msg_att * msg_att; |
361 | msg_att = (mailimap_msg_att*)current->data; | 363 | msg_att = (mailimap_msg_att*)current->data; |
362 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 364 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
363 | body_desc = item->att_data.att_static->att_data.att_body; | 365 | body_desc = item->att_data.att_static->att_data.att_body; |
364 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 366 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
365 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 367 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
366 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | 368 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
367 | qDebug("Mulitpart mail"); | 369 | qDebug("Mulitpart mail"); |
368 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | 370 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); |
369 | } | 371 | } |
370 | } else { | 372 | } else { |
371 | qDebug("error fetching body: %s",m_imap->imap_response); | 373 | qDebug("error fetching body: %s",m_imap->imap_response); |
372 | } | 374 | } |
373 | mailimap_fetch_list_free(result); | 375 | mailimap_fetch_list_free(result); |
374 | return body; | 376 | return body; |
375 | } | 377 | } |
376 | 378 | ||
377 | /* this routine is just called when the mail has only ONE part. | 379 | /* this routine is just called when the mail has only ONE part. |
378 | for filling the parts of a multi-part-message there are other | 380 | for filling the parts of a multi-part-message there are other |
379 | routines 'cause we can not simply fetch the whole body. */ | 381 | routines 'cause we can not simply fetch the whole body. */ |
380 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 382 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
381 | { | 383 | { |
382 | if (!mailDescription) { | 384 | if (!mailDescription) { |
383 | return; | 385 | return; |
384 | } | 386 | } |
385 | QString sub,body_text; | 387 | QString sub,body_text; |
386 | RecPart singlePart; | 388 | RecPart singlePart; |
387 | QValueList<int> path; | 389 | QValueList<int> path; |
388 | fillSinglePart(singlePart,mailDescription); | 390 | fillSinglePart(singlePart,mailDescription); |
389 | switch (mailDescription->bd_type) { | 391 | switch (mailDescription->bd_type) { |
390 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 392 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
391 | path.append(1); | 393 | path.append(1); |
392 | body_text = fetchPart(mail,path,true); | 394 | body_text = fetchPart(mail,path,true); |
393 | target_body.setBodytext(body_text); | 395 | target_body.setBodytext(body_text); |
394 | target_body.setDescription(singlePart); | 396 | target_body.setDescription(singlePart); |
395 | break; | 397 | break; |
396 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 398 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
397 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | 399 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); |
398 | path.append(1); | 400 | path.append(1); |
399 | body_text = fetchPart(mail,path,true); | 401 | body_text = fetchPart(mail,path,true); |
400 | target_body.setBodytext(body_text); | 402 | target_body.setBodytext(body_text); |
401 | target_body.setDescription(singlePart); | 403 | target_body.setDescription(singlePart); |
402 | break; | 404 | break; |
403 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 405 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
404 | qDebug("Single attachment"); | 406 | qDebug("Single attachment"); |
405 | target_body.setBodytext(""); | 407 | target_body.setBodytext(""); |
406 | target_body.addPart(singlePart); | 408 | target_body.addPart(singlePart); |
407 | break; | 409 | break; |
408 | default: | 410 | default: |
409 | break; | 411 | break; |
410 | } | 412 | } |
411 | 413 | ||
412 | return; | 414 | return; |
413 | } | 415 | } |
414 | 416 | ||
415 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 417 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
416 | { | 418 | { |
417 | QStringList l; | 419 | QStringList l; |
418 | QString from; | 420 | QString from; |
419 | bool named_from; | 421 | bool named_from; |
420 | clistcell *current = NULL; | 422 | clistcell *current = NULL; |
421 | mailimap_address * current_address=NULL; | 423 | mailimap_address * current_address=NULL; |
422 | if (!list) { | 424 | if (!list) { |
423 | return l; | 425 | return l; |
424 | } | 426 | } |
425 | unsigned int count = 0; | 427 | unsigned int count = 0; |
426 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 428 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
427 | from = ""; | 429 | from = ""; |
428 | named_from = false; | 430 | named_from = false; |
429 | current_address=(mailimap_address*)current->data; | 431 | current_address=(mailimap_address*)current->data; |
430 | if (current_address->ad_personal_name){ | 432 | if (current_address->ad_personal_name){ |
431 | from+=QString(current_address->ad_personal_name); | 433 | from+=QString(current_address->ad_personal_name); |
432 | from+=" "; | 434 | from+=" "; |
433 | named_from = true; | 435 | named_from = true; |
434 | } | 436 | } |
435 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 437 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
436 | from+="<"; | 438 | from+="<"; |
437 | } | 439 | } |
438 | if (current_address->ad_mailbox_name) { | 440 | if (current_address->ad_mailbox_name) { |
439 | from+=QString(current_address->ad_mailbox_name); | 441 | from+=QString(current_address->ad_mailbox_name); |
440 | from+="@"; | 442 | from+="@"; |
441 | } | 443 | } |
442 | if (current_address->ad_host_name) { | 444 | if (current_address->ad_host_name) { |
443 | from+=QString(current_address->ad_host_name); | 445 | from+=QString(current_address->ad_host_name); |
444 | } | 446 | } |
445 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 447 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
446 | from+=">"; | 448 | from+=">"; |
447 | } | 449 | } |
448 | l.append(QString(from)); | 450 | l.append(QString(from)); |
449 | if (++count > 99) { | 451 | if (++count > 99) { |
450 | break; | 452 | break; |
451 | } | 453 | } |
452 | } | 454 | } |
453 | return l; | 455 | return l; |
454 | } | 456 | } |
455 | 457 | ||
456 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 458 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
457 | { | 459 | { |
458 | QString body(""); | 460 | QString body(""); |
459 | const char*mb; | 461 | const char*mb; |
460 | int err; | 462 | int err; |
461 | mailimap_fetch_type *fetchType; | 463 | mailimap_fetch_type *fetchType; |
462 | mailimap_set *set; | 464 | mailimap_set *set; |
463 | clistcell*current,*cur; | 465 | clistcell*current,*cur; |
464 | 466 | ||
465 | login(); | 467 | login(); |
466 | if (!m_imap) { | 468 | if (!m_imap) { |
467 | return body; | 469 | return body; |
468 | } | 470 | } |
469 | if (!internal_call) { | 471 | if (!internal_call) { |
470 | mb = mail.getMbox().latin1(); | 472 | mb = mail.getMbox().latin1(); |
471 | err = mailimap_select( m_imap, (char*)mb); | 473 | err = mailimap_select( m_imap, (char*)mb); |
472 | if ( err != MAILIMAP_NO_ERROR ) { | 474 | if ( err != MAILIMAP_NO_ERROR ) { |
473 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 475 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
474 | return body; | 476 | return body; |
475 | } | 477 | } |
476 | } | 478 | } |
477 | set = mailimap_set_new_single(mail.getNumber()); | 479 | set = mailimap_set_new_single(mail.getNumber()); |
478 | clist*id_list=clist_new(); | 480 | clist*id_list=clist_new(); |
479 | for (unsigned j=0; j < path.count();++j) { | 481 | for (unsigned j=0; j < path.count();++j) { |
480 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 482 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
481 | *p_id = path[j]; | 483 | *p_id = path[j]; |
482 | clist_append(id_list,p_id); | 484 | clist_append(id_list,p_id); |
483 | } | 485 | } |
484 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 486 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
485 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 487 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
486 | mailimap_section * section = mailimap_section_new(section_spec); | 488 | mailimap_section * section = mailimap_section_new(section_spec); |
487 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 489 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
488 | 490 | ||
489 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 491 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
490 | 492 | ||
491 | clist*result = clist_new(); | 493 | clist*result = clist_new(); |
492 | 494 | ||
493 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 495 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
494 | mailimap_set_free( set ); | 496 | mailimap_set_free( set ); |
495 | mailimap_fetch_type_free( fetchType ); | 497 | mailimap_fetch_type_free( fetchType ); |
496 | 498 | ||
497 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 499 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
498 | mailimap_msg_att * msg_att; | 500 | mailimap_msg_att * msg_att; |
499 | msg_att = (mailimap_msg_att*)current->data; | 501 | msg_att = (mailimap_msg_att*)current->data; |
500 | mailimap_msg_att_item*msg_att_item; | 502 | mailimap_msg_att_item*msg_att_item; |
501 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 503 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
502 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 504 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
503 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 505 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
504 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 506 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
505 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 507 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
506 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 508 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
507 | if (text) { | 509 | if (text) { |
508 | body = QString(text); | 510 | body = QString(text); |
509 | free(text); | 511 | free(text); |
510 | } else { | 512 | } else { |
511 | body = ""; | 513 | body = ""; |
512 | } | 514 | } |
513 | } | 515 | } |
514 | } | 516 | } |
515 | } | 517 | } |
516 | 518 | ||
517 | } else { | 519 | } else { |
518 | qDebug("error fetching text: %s",m_imap->imap_response); | 520 | qDebug("error fetching text: %s",m_imap->imap_response); |
519 | } | 521 | } |
520 | mailimap_fetch_list_free(result); | 522 | mailimap_fetch_list_free(result); |
521 | return body; | 523 | return body; |
522 | } | 524 | } |
523 | 525 | ||
524 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 526 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
525 | { | 527 | { |
526 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 528 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
527 | if (!mailDescription||current_recursion==10) { | 529 | if (!mailDescription||current_recursion==10) { |
528 | return; | 530 | return; |
529 | } | 531 | } |
530 | clistcell*current; | 532 | clistcell*current; |
531 | mailimap_body*current_body; | 533 | mailimap_body*current_body; |
532 | unsigned int count = 0; | 534 | unsigned int count = 0; |
533 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 535 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
534 | /* the point in the message */ | 536 | /* the point in the message */ |
535 | ++count; | 537 | ++count; |
536 | current_body = (mailimap_body*)current->data; | 538 | current_body = (mailimap_body*)current->data; |
537 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 539 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
538 | QValueList<int>clist = recList; | 540 | QValueList<int>clist = recList; |
539 | clist.append(count); | 541 | clist.append(count); |
540 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); | 542 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); |
541 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 543 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ |
542 | RecPart currentPart; | 544 | RecPart currentPart; |
543 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 545 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
544 | QValueList<int>clist = recList; | 546 | QValueList<int>clist = recList; |
545 | clist.append(count); | 547 | clist.append(count); |
546 | /* important: Check for is NULL 'cause a body can be empty! */ | 548 | /* important: Check for is NULL 'cause a body can be empty! */ |
547 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 549 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
548 | QString body_text = fetchPart(mail,clist,true); | 550 | QString body_text = fetchPart(mail,clist,true); |
549 | target_body.setDescription(currentPart); | 551 | target_body.setDescription(currentPart); |
550 | target_body.setBodytext(body_text); | 552 | target_body.setBodytext(body_text); |
551 | } else { | 553 | } else { |
552 | QString id(""); | 554 | QString id(""); |
553 | for (unsigned int j = 0; j < clist.count();++j) { | 555 | for (unsigned int j = 0; j < clist.count();++j) { |
554 | id+=(j>0?" ":""); | 556 | id+=(j>0?" ":""); |
555 | id+=QString("%1").arg(clist[j]); | 557 | id+=QString("%1").arg(clist[j]); |
556 | } | 558 | } |
557 | qDebug("ID= %s",id.latin1()); | 559 | qDebug("ID= %s",id.latin1()); |
558 | currentPart.setIdentifier(id); | 560 | currentPart.setIdentifier(id); |
559 | currentPart.setPositionlist(clist); | 561 | currentPart.setPositionlist(clist); |
560 | target_body.addPart(currentPart); | 562 | target_body.addPart(currentPart); |
561 | } | 563 | } |
562 | } | 564 | } |
563 | } | 565 | } |
564 | } | 566 | } |
565 | 567 | ||
566 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 568 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
567 | { | 569 | { |
568 | if (!Description) { | 570 | if (!Description) { |
569 | return; | 571 | return; |
570 | } | 572 | } |
571 | switch (Description->bd_type) { | 573 | switch (Description->bd_type) { |
572 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 574 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
573 | target_part.setType("text"); | 575 | target_part.setType("text"); |
574 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 576 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
575 | break; | 577 | break; |
576 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 578 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
577 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 579 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
578 | break; | 580 | break; |
579 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 581 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
580 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 582 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
581 | break; | 583 | break; |
582 | default: | 584 | default: |
583 | break; | 585 | break; |
584 | } | 586 | } |
585 | } | 587 | } |
586 | 588 | ||
587 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 589 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
588 | { | 590 | { |
589 | if (!which) { | 591 | if (!which) { |
590 | return; | 592 | return; |
591 | } | 593 | } |
592 | QString sub; | 594 | QString sub; |
593 | sub = which->bd_media_text; | 595 | sub = which->bd_media_text; |
594 | target_part.setSubtype(sub.lower()); | 596 | target_part.setSubtype(sub.lower()); |
595 | target_part.setLines(which->bd_lines); | 597 | target_part.setLines(which->bd_lines); |
596 | fillBodyFields(target_part,which->bd_fields); | 598 | fillBodyFields(target_part,which->bd_fields); |
597 | } | 599 | } |
598 | 600 | ||
599 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 601 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
600 | { | 602 | { |
601 | if (!which) { | 603 | if (!which) { |
602 | return; | 604 | return; |
603 | } | 605 | } |
604 | // QString sub; | 606 | // QString sub; |
605 | // sub = which->bd_media_text; | 607 | // sub = which->bd_media_text; |
606 | // target_part.setSubtype(sub.lower()); | 608 | // target_part.setSubtype(sub.lower()); |
607 | qDebug("Message part"); | 609 | qDebug("Message part"); |
608 | /* we set this type to text/plain */ | 610 | /* we set this type to text/plain */ |
609 | target_part.setType("text"); | 611 | target_part.setType("text"); |
610 | target_part.setSubtype("plain"); | 612 | target_part.setSubtype("plain"); |
611 | target_part.setLines(which->bd_lines); | 613 | target_part.setLines(which->bd_lines); |
612 | fillBodyFields(target_part,which->bd_fields); | 614 | fillBodyFields(target_part,which->bd_fields); |
613 | } | 615 | } |
614 | 616 | ||
615 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 617 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
616 | { | 618 | { |
617 | if (!which) { | 619 | if (!which) { |
618 | return; | 620 | return; |
619 | } | 621 | } |
620 | QString type,sub; | 622 | QString type,sub; |
621 | switch (which->bd_media_basic->med_type) { | 623 | switch (which->bd_media_basic->med_type) { |
622 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 624 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
623 | type = "application"; | 625 | type = "application"; |
624 | break; | 626 | break; |
625 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 627 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
626 | type = "audio"; | 628 | type = "audio"; |
627 | break; | 629 | break; |
628 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 630 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
629 | type = "image"; | 631 | type = "image"; |
630 | break; | 632 | break; |
631 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 633 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
632 | type = "message"; | 634 | type = "message"; |
633 | break; | 635 | break; |
634 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 636 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
635 | type = "video"; | 637 | type = "video"; |
636 | break; | 638 | break; |
637 | case MAILIMAP_MEDIA_BASIC_OTHER: | 639 | case MAILIMAP_MEDIA_BASIC_OTHER: |
638 | default: | 640 | default: |
639 | if (which->bd_media_basic->med_basic_type) { | 641 | if (which->bd_media_basic->med_basic_type) { |
640 | type = which->bd_media_basic->med_basic_type; | 642 | type = which->bd_media_basic->med_basic_type; |
641 | } else { | 643 | } else { |
642 | type = ""; | 644 | type = ""; |
643 | } | 645 | } |
644 | break; | 646 | break; |
645 | } | 647 | } |
646 | if (which->bd_media_basic->med_subtype) { | 648 | if (which->bd_media_basic->med_subtype) { |
647 | sub = which->bd_media_basic->med_subtype; | 649 | sub = which->bd_media_basic->med_subtype; |
648 | } else { | 650 | } else { |
649 | sub = ""; | 651 | sub = ""; |
650 | } | 652 | } |
651 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | 653 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); |
652 | target_part.setType(type.lower()); | 654 | target_part.setType(type.lower()); |
653 | target_part.setSubtype(sub.lower()); | 655 | target_part.setSubtype(sub.lower()); |
654 | fillBodyFields(target_part,which->bd_fields); | 656 | fillBodyFields(target_part,which->bd_fields); |
655 | } | 657 | } |
656 | 658 | ||
657 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 659 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) |
658 | { | 660 | { |
659 | if (!which) return; | 661 | if (!which) return; |
660 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 662 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
661 | clistcell*cur; | 663 | clistcell*cur; |
662 | mailimap_single_body_fld_param*param=0; | 664 | mailimap_single_body_fld_param*param=0; |
663 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 665 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
664 | param = (mailimap_single_body_fld_param*)cur->data; | 666 | param = (mailimap_single_body_fld_param*)cur->data; |
665 | if (param) { | 667 | if (param) { |
666 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 668 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
667 | } | 669 | } |
668 | } | 670 | } |
669 | } | 671 | } |
670 | mailimap_body_fld_enc*enc = which->bd_encoding; | 672 | mailimap_body_fld_enc*enc = which->bd_encoding; |
671 | QString encoding(""); | 673 | QString encoding(""); |
672 | switch (enc->enc_type) { | 674 | switch (enc->enc_type) { |
673 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 675 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
674 | encoding = "7bit"; | 676 | encoding = "7bit"; |
675 | break; | 677 | break; |
676 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 678 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
677 | encoding = "8bit"; | 679 | encoding = "8bit"; |
678 | break; | 680 | break; |
679 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 681 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
680 | encoding="binary"; | 682 | encoding="binary"; |
681 | break; | 683 | break; |
682 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 684 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
683 | encoding="base64"; | 685 | encoding="base64"; |
684 | break; | 686 | break; |
685 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 687 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
686 | encoding="quoted-printable"; | 688 | encoding="quoted-printable"; |
687 | break; | 689 | break; |
688 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 690 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
689 | default: | 691 | default: |
690 | if (enc->enc_value) { | 692 | if (enc->enc_value) { |
691 | char*t=enc->enc_value; | 693 | char*t=enc->enc_value; |
692 | encoding=QString(enc->enc_value); | 694 | encoding=QString(enc->enc_value); |
693 | enc->enc_value=0L; | 695 | enc->enc_value=0L; |
694 | free(t); | 696 | free(t); |
695 | } | 697 | } |
696 | } | 698 | } |
697 | target_part.setEncoding(encoding); | 699 | target_part.setEncoding(encoding); |
698 | target_part.setSize(which->bd_size); | 700 | target_part.setSize(which->bd_size); |
699 | } | 701 | } |
700 | 702 | ||
701 | QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) | 703 | QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) |
702 | { | 704 | { |
703 | return fetchPart(mail,part.Positionlist(),false); | 705 | return fetchPart(mail,part.Positionlist(),false); |
704 | } | 706 | } |
705 | 707 | ||
706 | void IMAPwrapper::deleteMail(const RecMail&mail) | 708 | void IMAPwrapper::deleteMail(const RecMail&mail) |
707 | { | 709 | { |
708 | mailimap_flag_list*flist; | 710 | mailimap_flag_list*flist; |
709 | mailimap_set *set; | 711 | mailimap_set *set; |
710 | mailimap_store_att_flags * store_flags; | 712 | mailimap_store_att_flags * store_flags; |
711 | int err; | 713 | int err; |
712 | login(); | 714 | login(); |
713 | if (!m_imap) { | 715 | if (!m_imap) { |
714 | return; | 716 | return; |
715 | } | 717 | } |
716 | const char *mb = mail.getMbox().latin1(); | 718 | const char *mb = mail.getMbox().latin1(); |
717 | err = mailimap_select( m_imap, (char*)mb); | 719 | err = mailimap_select( m_imap, (char*)mb); |
718 | if ( err != MAILIMAP_NO_ERROR ) { | 720 | if ( err != MAILIMAP_NO_ERROR ) { |
719 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); | 721 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); |
720 | return; | 722 | return; |
721 | } | 723 | } |
722 | flist = mailimap_flag_list_new_empty(); | 724 | flist = mailimap_flag_list_new_empty(); |
723 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 725 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
724 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 726 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
725 | set = mailimap_set_new_single(mail.getNumber()); | 727 | set = mailimap_set_new_single(mail.getNumber()); |
726 | err = mailimap_store(m_imap,set,store_flags); | 728 | err = mailimap_store(m_imap,set,store_flags); |
727 | mailimap_set_free( set ); | 729 | mailimap_set_free( set ); |
728 | mailimap_store_att_flags_free(store_flags); | 730 | mailimap_store_att_flags_free(store_flags); |
729 | 731 | ||
730 | if (err != MAILIMAP_NO_ERROR) { | 732 | if (err != MAILIMAP_NO_ERROR) { |
731 | qDebug("error deleting mail: %s",m_imap->imap_response); | 733 | qDebug("error deleting mail: %s",m_imap->imap_response); |
732 | return; | 734 | return; |
733 | } | 735 | } |
734 | qDebug("deleting mail: %s",m_imap->imap_response); | 736 | qDebug("deleting mail: %s",m_imap->imap_response); |
735 | /* should we realy do that at this moment? */ | 737 | /* should we realy do that at this moment? */ |
736 | err = mailimap_expunge(m_imap); | 738 | err = mailimap_expunge(m_imap); |
737 | if (err != MAILIMAP_NO_ERROR) { | 739 | if (err != MAILIMAP_NO_ERROR) { |
738 | qDebug("error deleting mail: %s",m_imap->imap_response); | 740 | qDebug("error deleting mail: %s",m_imap->imap_response); |
739 | } | 741 | } |
740 | qDebug("Delete successfull %s",m_imap->imap_response); | 742 | qDebug("Delete successfull %s",m_imap->imap_response); |
741 | } | 743 | } |
742 | 744 | ||
743 | void IMAPwrapper::answeredMail(const RecMail&mail) | 745 | void IMAPwrapper::answeredMail(const RecMail&mail) |
744 | { | 746 | { |
745 | mailimap_flag_list*flist; | 747 | mailimap_flag_list*flist; |
746 | mailimap_set *set; | 748 | mailimap_set *set; |
747 | mailimap_store_att_flags * store_flags; | 749 | mailimap_store_att_flags * store_flags; |
748 | int err; | 750 | int err; |
749 | login(); | 751 | login(); |
750 | if (!m_imap) { | 752 | if (!m_imap) { |
751 | return; | 753 | return; |
752 | } | 754 | } |
753 | const char *mb = mail.getMbox().latin1(); | 755 | const char *mb = mail.getMbox().latin1(); |
754 | err = mailimap_select( m_imap, (char*)mb); | 756 | err = mailimap_select( m_imap, (char*)mb); |
755 | if ( err != MAILIMAP_NO_ERROR ) { | 757 | if ( err != MAILIMAP_NO_ERROR ) { |
756 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); | 758 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); |
757 | return; | 759 | return; |
758 | } | 760 | } |
759 | flist = mailimap_flag_list_new_empty(); | 761 | flist = mailimap_flag_list_new_empty(); |
760 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 762 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
761 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 763 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
762 | set = mailimap_set_new_single(mail.getNumber()); | 764 | set = mailimap_set_new_single(mail.getNumber()); |
763 | err = mailimap_store(m_imap,set,store_flags); | 765 | err = mailimap_store(m_imap,set,store_flags); |
764 | mailimap_set_free( set ); | 766 | mailimap_set_free( set ); |
765 | mailimap_store_att_flags_free(store_flags); | 767 | mailimap_store_att_flags_free(store_flags); |
766 | 768 | ||
767 | if (err != MAILIMAP_NO_ERROR) { | 769 | if (err != MAILIMAP_NO_ERROR) { |
768 | qDebug("error marking mail: %s",m_imap->imap_response); | 770 | qDebug("error marking mail: %s",m_imap->imap_response); |
769 | return; | 771 | return; |
770 | } | 772 | } |
771 | } | 773 | } |
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp index 3ffc274..96602c2 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp | |||
@@ -1,629 +1,639 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
3 | #include <sys/types.h> | 3 | #include <sys/types.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <fcntl.h> | 5 | #include <fcntl.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | 8 | ||
9 | #include "mailwrapper.h" | 9 | #include "mailwrapper.h" |
10 | #include "logindialog.h" | 10 | #include "logindialog.h" |
11 | //#include "mail.h" | 11 | //#include "mail.h" |
12 | #include "defines.h" | 12 | #include "defines.h" |
13 | 13 | ||
14 | Attachment::Attachment( DocLnk lnk ) | 14 | Attachment::Attachment( DocLnk lnk ) |
15 | { | 15 | { |
16 | doc = lnk; | 16 | doc = lnk; |
17 | size = QFileInfo( doc.file() ).size(); | 17 | size = QFileInfo( doc.file() ).size(); |
18 | } | 18 | } |
19 | 19 | ||
20 | Folder::Folder(const QString&tmp_name ) | 20 | Folder::Folder(const QString&tmp_name ) |
21 | { | 21 | { |
22 | name = tmp_name; | 22 | name = tmp_name; |
23 | nameDisplay = name; | 23 | nameDisplay = name; |
24 | 24 | ||
25 | for ( int pos = nameDisplay.find( '&' ); pos != -1; | 25 | for ( int pos = nameDisplay.find( '&' ); pos != -1; |
26 | pos = nameDisplay.find( '&' ) ) { | 26 | pos = nameDisplay.find( '&' ) ) { |
27 | int end = nameDisplay.find( '-' ); | 27 | int end = nameDisplay.find( '-' ); |
28 | if ( end == -1 || end <= pos ) break; | 28 | if ( end == -1 || end <= pos ) break; |
29 | QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 ); | 29 | QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 ); |
30 | // TODO: do real base64 decoding here ! | 30 | // TODO: do real base64 decoding here ! |
31 | if ( str64.compare( "APw" ) == 0 ) { | 31 | if ( str64.compare( "APw" ) == 0 ) { |
32 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" ); | 32 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" ); |
33 | } else if ( str64.compare( "APY" ) == 0 ) { | 33 | } else if ( str64.compare( "APY" ) == 0 ) { |
34 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" ); | 34 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" ); |
35 | } | 35 | } |
36 | } | 36 | } |
37 | |||
38 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); | 37 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); |
39 | } | 38 | } |
40 | 39 | ||
40 | |||
41 | IMAPFolder::IMAPFolder(const QString&name,bool select,const QString&prefix ) | ||
42 | : Folder( name ),m_MaySelect(select) | ||
43 | { | ||
44 | if (prefix.length()>0) { | ||
45 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { | ||
46 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); | ||
47 | } | ||
48 | } | ||
49 | } | ||
50 | |||
41 | MailWrapper::MailWrapper( Settings *s ) | 51 | MailWrapper::MailWrapper( Settings *s ) |
42 | : QObject() | 52 | : QObject() |
43 | { | 53 | { |
44 | settings = s; | 54 | settings = s; |
45 | } | 55 | } |
46 | 56 | ||
47 | QString MailWrapper::mailsmtpError( int errnum ) | 57 | QString MailWrapper::mailsmtpError( int errnum ) |
48 | { | 58 | { |
49 | switch ( errnum ) { | 59 | switch ( errnum ) { |
50 | case MAILSMTP_NO_ERROR: | 60 | case MAILSMTP_NO_ERROR: |
51 | return tr( "No error" ); | 61 | return tr( "No error" ); |
52 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 62 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
53 | return tr( "Unexpected error code" ); | 63 | return tr( "Unexpected error code" ); |
54 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 64 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
55 | return tr( "Service not available" ); | 65 | return tr( "Service not available" ); |
56 | case MAILSMTP_ERROR_STREAM: | 66 | case MAILSMTP_ERROR_STREAM: |
57 | return tr( "Stream error" ); | 67 | return tr( "Stream error" ); |
58 | case MAILSMTP_ERROR_HOSTNAME: | 68 | case MAILSMTP_ERROR_HOSTNAME: |
59 | return tr( "gethostname() failed" ); | 69 | return tr( "gethostname() failed" ); |
60 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 70 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
61 | return tr( "Not implemented" ); | 71 | return tr( "Not implemented" ); |
62 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 72 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
63 | return tr( "Error, action not taken" ); | 73 | return tr( "Error, action not taken" ); |
64 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 74 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
65 | return tr( "Data exceeds storage allocation" ); | 75 | return tr( "Data exceeds storage allocation" ); |
66 | case MAILSMTP_ERROR_IN_PROCESSING: | 76 | case MAILSMTP_ERROR_IN_PROCESSING: |
67 | return tr( "Error in processing" ); | 77 | return tr( "Error in processing" ); |
68 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 78 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
69 | // return tr( "Insufficient system storage" ); | 79 | // return tr( "Insufficient system storage" ); |
70 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 80 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
71 | return tr( "Mailbox unavailable" ); | 81 | return tr( "Mailbox unavailable" ); |
72 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 82 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
73 | return tr( "Mailbox name not allowed" ); | 83 | return tr( "Mailbox name not allowed" ); |
74 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 84 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
75 | return tr( "Bad command sequence" ); | 85 | return tr( "Bad command sequence" ); |
76 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 86 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
77 | return tr( "User not local" ); | 87 | return tr( "User not local" ); |
78 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 88 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
79 | return tr( "Transaction failed" ); | 89 | return tr( "Transaction failed" ); |
80 | case MAILSMTP_ERROR_MEMORY: | 90 | case MAILSMTP_ERROR_MEMORY: |
81 | return tr( "Memory error" ); | 91 | return tr( "Memory error" ); |
82 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 92 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
83 | return tr( "Connection refused" ); | 93 | return tr( "Connection refused" ); |
84 | default: | 94 | default: |
85 | return tr( "Unknown error code" ); | 95 | return tr( "Unknown error code" ); |
86 | } | 96 | } |
87 | } | 97 | } |
88 | 98 | ||
89 | mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) | 99 | mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) |
90 | { | 100 | { |
91 | return mailimf_mailbox_new( strdup( name.latin1() ), | 101 | return mailimf_mailbox_new( strdup( name.latin1() ), |
92 | strdup( mail.latin1() ) ); | 102 | strdup( mail.latin1() ) ); |
93 | } | 103 | } |
94 | 104 | ||
95 | mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) | 105 | mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) |
96 | { | 106 | { |
97 | mailimf_address_list *addresses; | 107 | mailimf_address_list *addresses; |
98 | 108 | ||
99 | if ( addr.isEmpty() ) return NULL; | 109 | if ( addr.isEmpty() ) return NULL; |
100 | 110 | ||
101 | addresses = mailimf_address_list_new_empty(); | 111 | addresses = mailimf_address_list_new_empty(); |
102 | 112 | ||
103 | QStringList list = QStringList::split( ',', addr ); | 113 | QStringList list = QStringList::split( ',', addr ); |
104 | QStringList::Iterator it; | 114 | QStringList::Iterator it; |
105 | for ( it = list.begin(); it != list.end(); it++ ) { | 115 | for ( it = list.begin(); it != list.end(); it++ ) { |
106 | char *str = strdup( (*it).latin1() ); | 116 | char *str = strdup( (*it).latin1() ); |
107 | int err = mailimf_address_list_add_parse( addresses, str ); | 117 | int err = mailimf_address_list_add_parse( addresses, str ); |
108 | if ( err != MAILIMF_NO_ERROR ) { | 118 | if ( err != MAILIMF_NO_ERROR ) { |
109 | qDebug( "Error parsing" ); | 119 | qDebug( "Error parsing" ); |
110 | qDebug( *it ); | 120 | qDebug( *it ); |
111 | free( str ); | 121 | free( str ); |
112 | } else { | 122 | } else { |
113 | qDebug( "Parse success! :)" ); | 123 | qDebug( "Parse success! :)" ); |
114 | } | 124 | } |
115 | } | 125 | } |
116 | 126 | ||
117 | return addresses; | 127 | return addresses; |
118 | } | 128 | } |
119 | 129 | ||
120 | mailimf_fields *MailWrapper::createImfFields( Mail *mail ) | 130 | mailimf_fields *MailWrapper::createImfFields( Mail *mail ) |
121 | { | 131 | { |
122 | mailimf_fields *fields; | 132 | mailimf_fields *fields; |
123 | mailimf_field *xmailer; | 133 | mailimf_field *xmailer; |
124 | mailimf_mailbox *sender, *fromBox; | 134 | mailimf_mailbox *sender, *fromBox; |
125 | mailimf_mailbox_list *from; | 135 | mailimf_mailbox_list *from; |
126 | mailimf_address_list *to, *cc, *bcc, *reply; | 136 | mailimf_address_list *to, *cc, *bcc, *reply; |
127 | char *subject = strdup( mail->getSubject().latin1() ); | 137 | char *subject = strdup( mail->getSubject().latin1() ); |
128 | int err; | 138 | int err; |
129 | 139 | ||
130 | sender = newMailbox( mail->getName(), mail->getMail() ); | 140 | sender = newMailbox( mail->getName(), mail->getMail() ); |
131 | if ( sender == NULL ) goto err_free; | 141 | if ( sender == NULL ) goto err_free; |
132 | 142 | ||
133 | fromBox = newMailbox( mail->getName(), mail->getMail() ); | 143 | fromBox = newMailbox( mail->getName(), mail->getMail() ); |
134 | if ( fromBox == NULL ) goto err_free_sender; | 144 | if ( fromBox == NULL ) goto err_free_sender; |
135 | 145 | ||
136 | from = mailimf_mailbox_list_new_empty(); | 146 | from = mailimf_mailbox_list_new_empty(); |
137 | if ( from == NULL ) goto err_free_fromBox; | 147 | if ( from == NULL ) goto err_free_fromBox; |
138 | 148 | ||
139 | err = mailimf_mailbox_list_add( from, fromBox ); | 149 | err = mailimf_mailbox_list_add( from, fromBox ); |
140 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; | 150 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; |
141 | 151 | ||
142 | to = parseAddresses( mail->getTo() ); | 152 | to = parseAddresses( mail->getTo() ); |
143 | if ( to == NULL ) goto err_free_from; | 153 | if ( to == NULL ) goto err_free_from; |
144 | 154 | ||
145 | cc = parseAddresses( mail->getCC() ); | 155 | cc = parseAddresses( mail->getCC() ); |
146 | bcc = parseAddresses( mail->getBCC() ); | 156 | bcc = parseAddresses( mail->getBCC() ); |
147 | reply = parseAddresses( mail->getReply() ); | 157 | reply = parseAddresses( mail->getReply() ); |
148 | 158 | ||
149 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | 159 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, |
150 | NULL, NULL, subject ); | 160 | NULL, NULL, subject ); |
151 | if ( fields == NULL ) goto err_free_reply; | 161 | if ( fields == NULL ) goto err_free_reply; |
152 | 162 | ||
153 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 163 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), |
154 | strdup( USER_AGENT ) ); | 164 | strdup( USER_AGENT ) ); |
155 | if ( xmailer == NULL ) goto err_free_fields; | 165 | if ( xmailer == NULL ) goto err_free_fields; |
156 | 166 | ||
157 | err = mailimf_fields_add( fields, xmailer ); | 167 | err = mailimf_fields_add( fields, xmailer ); |
158 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; | 168 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; |
159 | 169 | ||
160 | return fields; // Success :) | 170 | return fields; // Success :) |
161 | 171 | ||
162 | err_free_xmailer: | 172 | err_free_xmailer: |
163 | mailimf_field_free( xmailer ); | 173 | mailimf_field_free( xmailer ); |
164 | err_free_fields: | 174 | err_free_fields: |
165 | mailimf_fields_free( fields ); | 175 | mailimf_fields_free( fields ); |
166 | err_free_reply: | 176 | err_free_reply: |
167 | mailimf_address_list_free( reply ); | 177 | mailimf_address_list_free( reply ); |
168 | mailimf_address_list_free( bcc ); | 178 | mailimf_address_list_free( bcc ); |
169 | mailimf_address_list_free( cc ); | 179 | mailimf_address_list_free( cc ); |
170 | mailimf_address_list_free( to ); | 180 | mailimf_address_list_free( to ); |
171 | err_free_from: | 181 | err_free_from: |
172 | mailimf_mailbox_list_free( from ); | 182 | mailimf_mailbox_list_free( from ); |
173 | err_free_fromBox: | 183 | err_free_fromBox: |
174 | mailimf_mailbox_free( fromBox ); | 184 | mailimf_mailbox_free( fromBox ); |
175 | err_free_sender: | 185 | err_free_sender: |
176 | mailimf_mailbox_free( sender ); | 186 | mailimf_mailbox_free( sender ); |
177 | err_free: | 187 | err_free: |
178 | free( subject ); | 188 | free( subject ); |
179 | qDebug( "createImfFields - error" ); | 189 | qDebug( "createImfFields - error" ); |
180 | 190 | ||
181 | return NULL; // Error :( | 191 | return NULL; // Error :( |
182 | } | 192 | } |
183 | 193 | ||
184 | mailmime *MailWrapper::buildTxtPart( QString str ) | 194 | mailmime *MailWrapper::buildTxtPart( QString str ) |
185 | { | 195 | { |
186 | mailmime *txtPart; | 196 | mailmime *txtPart; |
187 | mailmime_fields *fields; | 197 | mailmime_fields *fields; |
188 | mailmime_content *content; | 198 | mailmime_content *content; |
189 | mailmime_parameter *param; | 199 | mailmime_parameter *param; |
190 | char *txt = strdup( str.latin1() ); | 200 | char *txt = strdup( str.latin1() ); |
191 | int err; | 201 | int err; |
192 | 202 | ||
193 | param = mailmime_parameter_new( strdup( "charset" ), | 203 | param = mailmime_parameter_new( strdup( "charset" ), |
194 | strdup( "iso-8859-1" ) ); | 204 | strdup( "iso-8859-1" ) ); |
195 | if ( param == NULL ) goto err_free; | 205 | if ( param == NULL ) goto err_free; |
196 | 206 | ||
197 | content = mailmime_content_new_with_str( "text/plain" ); | 207 | content = mailmime_content_new_with_str( "text/plain" ); |
198 | if ( content == NULL ) goto err_free_param; | 208 | if ( content == NULL ) goto err_free_param; |
199 | 209 | ||
200 | err = clist_append( content->ct_parameters, param ); | 210 | err = clist_append( content->ct_parameters, param ); |
201 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | 211 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; |
202 | 212 | ||
203 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); | 213 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); |
204 | if ( fields == NULL ) goto err_free_content; | 214 | if ( fields == NULL ) goto err_free_content; |
205 | 215 | ||
206 | txtPart = mailmime_new_empty( content, fields ); | 216 | txtPart = mailmime_new_empty( content, fields ); |
207 | if ( txtPart == NULL ) goto err_free_fields; | 217 | if ( txtPart == NULL ) goto err_free_fields; |
208 | 218 | ||
209 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); | 219 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); |
210 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 220 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
211 | 221 | ||
212 | return txtPart; // Success :) | 222 | return txtPart; // Success :) |
213 | 223 | ||
214 | err_free_txtPart: | 224 | err_free_txtPart: |
215 | mailmime_free( txtPart ); | 225 | mailmime_free( txtPart ); |
216 | err_free_fields: | 226 | err_free_fields: |
217 | mailmime_fields_free( fields ); | 227 | mailmime_fields_free( fields ); |
218 | err_free_content: | 228 | err_free_content: |
219 | mailmime_content_free( content ); | 229 | mailmime_content_free( content ); |
220 | err_free_param: | 230 | err_free_param: |
221 | mailmime_parameter_free( param ); | 231 | mailmime_parameter_free( param ); |
222 | err_free: | 232 | err_free: |
223 | free( txt ); | 233 | free( txt ); |
224 | qDebug( "buildTxtPart - error" ); | 234 | qDebug( "buildTxtPart - error" ); |
225 | 235 | ||
226 | return NULL; // Error :( | 236 | return NULL; // Error :( |
227 | } | 237 | } |
228 | 238 | ||
229 | mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) | 239 | mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) |
230 | { | 240 | { |
231 | mailmime * filePart; | 241 | mailmime * filePart; |
232 | mailmime_fields * fields; | 242 | mailmime_fields * fields; |
233 | mailmime_content * content; | 243 | mailmime_content * content; |
234 | mailmime_parameter * param = NULL; | 244 | mailmime_parameter * param = NULL; |
235 | int err; | 245 | int err; |
236 | 246 | ||
237 | int pos = filename.findRev( '/' ); | 247 | int pos = filename.findRev( '/' ); |
238 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 248 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
239 | char *name = strdup( tmp.latin1() ); // just filename | 249 | char *name = strdup( tmp.latin1() ); // just filename |
240 | char *file = strdup( filename.latin1() ); // full name with path | 250 | char *file = strdup( filename.latin1() ); // full name with path |
241 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain | 251 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain |
242 | 252 | ||
243 | fields = mailmime_fields_new_filename( | 253 | fields = mailmime_fields_new_filename( |
244 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, | 254 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, |
245 | MAILMIME_MECHANISM_BASE64 ); | 255 | MAILMIME_MECHANISM_BASE64 ); |
246 | if ( fields == NULL ) goto err_free; | 256 | if ( fields == NULL ) goto err_free; |
247 | 257 | ||
248 | content = mailmime_content_new_with_str( mime ); | 258 | content = mailmime_content_new_with_str( mime ); |
249 | if ( content == NULL ) goto err_free_fields; | 259 | if ( content == NULL ) goto err_free_fields; |
250 | 260 | ||
251 | if ( mimetype.compare( "text/plain" ) == 0 ) { | 261 | if ( mimetype.compare( "text/plain" ) == 0 ) { |
252 | param = mailmime_parameter_new( strdup( "charset" ), | 262 | param = mailmime_parameter_new( strdup( "charset" ), |
253 | strdup( "iso-8859-1" ) ); | 263 | strdup( "iso-8859-1" ) ); |
254 | if ( param == NULL ) goto err_free_content; | 264 | if ( param == NULL ) goto err_free_content; |
255 | 265 | ||
256 | err = clist_append( content->ct_parameters, param ); | 266 | err = clist_append( content->ct_parameters, param ); |
257 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; | 267 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; |
258 | } | 268 | } |
259 | 269 | ||
260 | filePart = mailmime_new_empty( content, fields ); | 270 | filePart = mailmime_new_empty( content, fields ); |
261 | if ( filePart == NULL ) goto err_free_param; | 271 | if ( filePart == NULL ) goto err_free_param; |
262 | 272 | ||
263 | err = mailmime_set_body_file( filePart, file ); | 273 | err = mailmime_set_body_file( filePart, file ); |
264 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 274 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; |
265 | 275 | ||
266 | return filePart; // Success :) | 276 | return filePart; // Success :) |
267 | 277 | ||
268 | err_free_filePart: | 278 | err_free_filePart: |
269 | mailmime_free( filePart ); | 279 | mailmime_free( filePart ); |
270 | err_free_param: | 280 | err_free_param: |
271 | if ( param != NULL ) mailmime_parameter_free( param ); | 281 | if ( param != NULL ) mailmime_parameter_free( param ); |
272 | err_free_content: | 282 | err_free_content: |
273 | mailmime_content_free( content ); | 283 | mailmime_content_free( content ); |
274 | err_free_fields: | 284 | err_free_fields: |
275 | mailmime_fields_free( fields ); | 285 | mailmime_fields_free( fields ); |
276 | err_free: | 286 | err_free: |
277 | free( name ); | 287 | free( name ); |
278 | free( mime ); | 288 | free( mime ); |
279 | free( file ); | 289 | free( file ); |
280 | qDebug( "buildFilePart - error" ); | 290 | qDebug( "buildFilePart - error" ); |
281 | 291 | ||
282 | return NULL; // Error :( | 292 | return NULL; // Error :( |
283 | } | 293 | } |
284 | 294 | ||
285 | void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) | 295 | void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) |
286 | { | 296 | { |
287 | Attachment *it; | 297 | Attachment *it; |
288 | for ( it = files.first(); it; it = files.next() ) { | 298 | for ( it = files.first(); it; it = files.next() ) { |
289 | qDebug( "Adding file" ); | 299 | qDebug( "Adding file" ); |
290 | mailmime *filePart; | 300 | mailmime *filePart; |
291 | int err; | 301 | int err; |
292 | 302 | ||
293 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); | 303 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); |
294 | if ( filePart == NULL ) goto err_free; | 304 | if ( filePart == NULL ) goto err_free; |
295 | 305 | ||
296 | err = mailmime_smart_add_part( message, filePart ); | 306 | err = mailmime_smart_add_part( message, filePart ); |
297 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 307 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; |
298 | 308 | ||
299 | continue; // Success :) | 309 | continue; // Success :) |
300 | 310 | ||
301 | err_free_filePart: | 311 | err_free_filePart: |
302 | mailmime_free( filePart ); | 312 | mailmime_free( filePart ); |
303 | err_free: | 313 | err_free: |
304 | qDebug( "addFileParts: error adding file:" ); | 314 | qDebug( "addFileParts: error adding file:" ); |
305 | qDebug( it->getFileName() ); | 315 | qDebug( it->getFileName() ); |
306 | } | 316 | } |
307 | } | 317 | } |
308 | 318 | ||
309 | mailmime *MailWrapper::createMimeMail( Mail *mail ) | 319 | mailmime *MailWrapper::createMimeMail( Mail *mail ) |
310 | { | 320 | { |
311 | mailmime *message, *txtPart; | 321 | mailmime *message, *txtPart; |
312 | mailimf_fields *fields; | 322 | mailimf_fields *fields; |
313 | int err; | 323 | int err; |
314 | 324 | ||
315 | fields = createImfFields( mail ); | 325 | fields = createImfFields( mail ); |
316 | if ( fields == NULL ) goto err_free; | 326 | if ( fields == NULL ) goto err_free; |
317 | 327 | ||
318 | message = mailmime_new_message_data( NULL ); | 328 | message = mailmime_new_message_data( NULL ); |
319 | if ( message == NULL ) goto err_free_fields; | 329 | if ( message == NULL ) goto err_free_fields; |
320 | 330 | ||
321 | mailmime_set_imf_fields( message, fields ); | 331 | mailmime_set_imf_fields( message, fields ); |
322 | 332 | ||
323 | txtPart = buildTxtPart( mail->getMessage() ); | 333 | txtPart = buildTxtPart( mail->getMessage() ); |
324 | if ( txtPart == NULL ) goto err_free_message; | 334 | if ( txtPart == NULL ) goto err_free_message; |
325 | 335 | ||
326 | err = mailmime_smart_add_part( message, txtPart ); | 336 | err = mailmime_smart_add_part( message, txtPart ); |
327 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 337 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
328 | 338 | ||
329 | addFileParts( message, mail->getAttachments() ); | 339 | addFileParts( message, mail->getAttachments() ); |
330 | 340 | ||
331 | return message; // Success :) | 341 | return message; // Success :) |
332 | 342 | ||
333 | err_free_txtPart: | 343 | err_free_txtPart: |
334 | mailmime_free( txtPart ); | 344 | mailmime_free( txtPart ); |
335 | err_free_message: | 345 | err_free_message: |
336 | mailmime_free( message ); | 346 | mailmime_free( message ); |
337 | err_free_fields: | 347 | err_free_fields: |
338 | mailimf_fields_free( fields ); | 348 | mailimf_fields_free( fields ); |
339 | err_free: | 349 | err_free: |
340 | qDebug( "createMimeMail: error" ); | 350 | qDebug( "createMimeMail: error" ); |
341 | 351 | ||
342 | return NULL; // Error :( | 352 | return NULL; // Error :( |
343 | } | 353 | } |
344 | 354 | ||
345 | mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) | 355 | mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) |
346 | { | 356 | { |
347 | mailimf_field *field; | 357 | mailimf_field *field; |
348 | clistiter *it; | 358 | clistiter *it; |
349 | 359 | ||
350 | it = clist_begin( fields->fld_list ); | 360 | it = clist_begin( fields->fld_list ); |
351 | while ( it ) { | 361 | while ( it ) { |
352 | field = (mailimf_field *) it->data; | 362 | field = (mailimf_field *) it->data; |
353 | if ( field->fld_type == type ) { | 363 | if ( field->fld_type == type ) { |
354 | return field; | 364 | return field; |
355 | } | 365 | } |
356 | it = it->next; | 366 | it = it->next; |
357 | } | 367 | } |
358 | 368 | ||
359 | return NULL; | 369 | return NULL; |
360 | } | 370 | } |
361 | 371 | ||
362 | static void addRcpts( clist *list, mailimf_address_list *addr_list ) | 372 | static void addRcpts( clist *list, mailimf_address_list *addr_list ) |
363 | { | 373 | { |
364 | clistiter *it, *it2; | 374 | clistiter *it, *it2; |
365 | 375 | ||
366 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | 376 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { |
367 | mailimf_address *addr; | 377 | mailimf_address *addr; |
368 | addr = (mailimf_address *) it->data; | 378 | addr = (mailimf_address *) it->data; |
369 | 379 | ||
370 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | 380 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { |
371 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | 381 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); |
372 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { | 382 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { |
373 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | 383 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; |
374 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | 384 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { |
375 | mailimf_mailbox *mbox; | 385 | mailimf_mailbox *mbox; |
376 | mbox = (mailimf_mailbox *) it2->data; | 386 | mbox = (mailimf_mailbox *) it2->data; |
377 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | 387 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); |
378 | } | 388 | } |
379 | } | 389 | } |
380 | } | 390 | } |
381 | } | 391 | } |
382 | 392 | ||
383 | clist *MailWrapper::createRcptList( mailimf_fields *fields ) | 393 | clist *MailWrapper::createRcptList( mailimf_fields *fields ) |
384 | { | 394 | { |
385 | clist *rcptList; | 395 | clist *rcptList; |
386 | mailimf_field *field; | 396 | mailimf_field *field; |
387 | 397 | ||
388 | rcptList = esmtp_address_list_new(); | 398 | rcptList = esmtp_address_list_new(); |
389 | 399 | ||
390 | field = getField( fields, MAILIMF_FIELD_TO ); | 400 | field = getField( fields, MAILIMF_FIELD_TO ); |
391 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) | 401 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) |
392 | && field->fld_data.fld_to->to_addr_list ) { | 402 | && field->fld_data.fld_to->to_addr_list ) { |
393 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); | 403 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); |
394 | } | 404 | } |
395 | 405 | ||
396 | field = getField( fields, MAILIMF_FIELD_CC ); | 406 | field = getField( fields, MAILIMF_FIELD_CC ); |
397 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) | 407 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) |
398 | && field->fld_data.fld_cc->cc_addr_list ) { | 408 | && field->fld_data.fld_cc->cc_addr_list ) { |
399 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); | 409 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); |
400 | } | 410 | } |
401 | 411 | ||
402 | field = getField( fields, MAILIMF_FIELD_BCC ); | 412 | field = getField( fields, MAILIMF_FIELD_BCC ); |
403 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) | 413 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) |
404 | && field->fld_data.fld_bcc->bcc_addr_list ) { | 414 | && field->fld_data.fld_bcc->bcc_addr_list ) { |
405 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); | 415 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); |
406 | } | 416 | } |
407 | 417 | ||
408 | return rcptList; | 418 | return rcptList; |
409 | } | 419 | } |
410 | 420 | ||
411 | char *MailWrapper::getFrom( mailmime *mail ) | 421 | char *MailWrapper::getFrom( mailmime *mail ) |
412 | { | 422 | { |
413 | char *from = NULL; | 423 | char *from = NULL; |
414 | 424 | ||
415 | mailimf_field *ffrom; | 425 | mailimf_field *ffrom; |
416 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | 426 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); |
417 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 427 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) |
418 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | 428 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { |
419 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | 429 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; |
420 | clistiter *it; | 430 | clistiter *it; |
421 | for ( it = clist_begin( cl ); it; it = it->next ) { | 431 | for ( it = clist_begin( cl ); it; it = it->next ) { |
422 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 432 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
423 | from = strdup( mb->mb_addr_spec ); | 433 | from = strdup( mb->mb_addr_spec ); |
424 | } | 434 | } |
425 | } | 435 | } |
426 | 436 | ||
427 | return from; | 437 | return from; |
428 | } | 438 | } |
429 | 439 | ||
430 | SMTPaccount *MailWrapper::getAccount( QString from ) | 440 | SMTPaccount *MailWrapper::getAccount( QString from ) |
431 | { | 441 | { |
432 | SMTPaccount *smtp; | 442 | SMTPaccount *smtp; |
433 | 443 | ||
434 | QList<Account> list = settings->getAccounts(); | 444 | QList<Account> list = settings->getAccounts(); |
435 | Account *it; | 445 | Account *it; |
436 | for ( it = list.first(); it; it = list.next() ) { | 446 | for ( it = list.first(); it; it = list.next() ) { |
437 | if ( it->getType().compare( "SMTP" ) == 0 ) { | 447 | if ( it->getType().compare( "SMTP" ) == 0 ) { |
438 | smtp = static_cast<SMTPaccount *>(it); | 448 | smtp = static_cast<SMTPaccount *>(it); |
439 | if ( smtp->getMail().compare( from ) == 0 ) { | 449 | if ( smtp->getMail().compare( from ) == 0 ) { |
440 | qDebug( "SMTPaccount found for" ); | 450 | qDebug( "SMTPaccount found for" ); |
441 | qDebug( from ); | 451 | qDebug( from ); |
442 | return smtp; | 452 | return smtp; |
443 | } | 453 | } |
444 | } | 454 | } |
445 | } | 455 | } |
446 | 456 | ||
447 | return NULL; | 457 | return NULL; |
448 | } | 458 | } |
449 | 459 | ||
450 | QString MailWrapper::getTmpFile() { | 460 | QString MailWrapper::getTmpFile() { |
451 | int num = 0; | 461 | int num = 0; |
452 | QString unique; | 462 | QString unique; |
453 | 463 | ||
454 | QDir dir( "/tmp" ); | 464 | QDir dir( "/tmp" ); |
455 | QStringList::Iterator it; | 465 | QStringList::Iterator it; |
456 | 466 | ||
457 | QStringList list = dir.entryList( "opiemail-tmp-*" ); | 467 | QStringList list = dir.entryList( "opiemail-tmp-*" ); |
458 | do { | 468 | do { |
459 | unique.setNum( num++ ); | 469 | unique.setNum( num++ ); |
460 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); | 470 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); |
461 | 471 | ||
462 | return "/tmp/opiemail-tmp-" + unique; | 472 | return "/tmp/opiemail-tmp-" + unique; |
463 | } | 473 | } |
464 | 474 | ||
465 | void MailWrapper::writeToFile( QString file, mailmime *mail ) | 475 | void MailWrapper::writeToFile( QString file, mailmime *mail ) |
466 | { | 476 | { |
467 | FILE *f; | 477 | FILE *f; |
468 | int err, col = 0; | 478 | int err, col = 0; |
469 | 479 | ||
470 | f = fopen( file.latin1(), "w" ); | 480 | f = fopen( file.latin1(), "w" ); |
471 | if ( f == NULL ) { | 481 | if ( f == NULL ) { |
472 | qDebug( "writeToFile: error opening file" ); | 482 | qDebug( "writeToFile: error opening file" ); |
473 | return; | 483 | return; |
474 | } | 484 | } |
475 | 485 | ||
476 | err = mailmime_write( f, &col, mail ); | 486 | err = mailmime_write( f, &col, mail ); |
477 | if ( err != MAILIMF_NO_ERROR ) { | 487 | if ( err != MAILIMF_NO_ERROR ) { |
478 | fclose( f ); | 488 | fclose( f ); |
479 | qDebug( "writeToFile: error writing mailmime" ); | 489 | qDebug( "writeToFile: error writing mailmime" ); |
480 | return; | 490 | return; |
481 | } | 491 | } |
482 | 492 | ||
483 | fclose( f ); | 493 | fclose( f ); |
484 | } | 494 | } |
485 | 495 | ||
486 | void MailWrapper::readFromFile( QString file, char **data, size_t *size ) | 496 | void MailWrapper::readFromFile( QString file, char **data, size_t *size ) |
487 | { | 497 | { |
488 | char *buf; | 498 | char *buf; |
489 | struct stat st; | 499 | struct stat st; |
490 | int fd, count = 0, total = 0; | 500 | int fd, count = 0, total = 0; |
491 | 501 | ||
492 | fd = open( file.latin1(), O_RDONLY, 0 ); | 502 | fd = open( file.latin1(), O_RDONLY, 0 ); |
493 | if ( fd == -1 ) return; | 503 | if ( fd == -1 ) return; |
494 | 504 | ||
495 | if ( fstat( fd, &st ) != 0 ) goto err_close; | 505 | if ( fstat( fd, &st ) != 0 ) goto err_close; |
496 | if ( !st.st_size ) goto err_close; | 506 | if ( !st.st_size ) goto err_close; |
497 | 507 | ||
498 | buf = (char *) malloc( st.st_size ); | 508 | buf = (char *) malloc( st.st_size ); |
499 | if ( !buf ) goto err_close; | 509 | if ( !buf ) goto err_close; |
500 | 510 | ||
501 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { | 511 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { |
502 | count = read( fd, buf + total, st.st_size - total ); | 512 | count = read( fd, buf + total, st.st_size - total ); |
503 | total += count; | 513 | total += count; |
504 | } | 514 | } |
505 | if ( count < 0 ) goto err_free; | 515 | if ( count < 0 ) goto err_free; |
506 | 516 | ||
507 | *data = buf; | 517 | *data = buf; |
508 | *size = st.st_size; | 518 | *size = st.st_size; |
509 | 519 | ||
510 | close( fd ); | 520 | close( fd ); |
511 | 521 | ||
512 | return; // Success :) | 522 | return; // Success :) |
513 | 523 | ||
514 | err_free: | 524 | err_free: |
515 | free( buf ); | 525 | free( buf ); |
516 | err_close: | 526 | err_close: |
517 | close( fd ); | 527 | close( fd ); |
518 | } | 528 | } |
519 | 529 | ||
520 | void progress( size_t current, size_t maximum ) | 530 | void progress( size_t current, size_t maximum ) |
521 | { | 531 | { |
522 | qDebug( "Current: %i of %i", current, maximum ); | 532 | qDebug( "Current: %i of %i", current, maximum ); |
523 | } | 533 | } |
524 | 534 | ||
525 | void MailWrapper::smtpSend( mailmime *mail ) | 535 | void MailWrapper::smtpSend( mailmime *mail ) |
526 | { | 536 | { |
527 | mailsmtp *session; | 537 | mailsmtp *session; |
528 | clist *rcpts; | 538 | clist *rcpts; |
529 | char *from, *data, *server, *user = NULL, *pass = NULL; | 539 | char *from, *data, *server, *user = NULL, *pass = NULL; |
530 | size_t size; | 540 | size_t size; |
531 | int err; | 541 | int err; |
532 | bool ssl; | 542 | bool ssl; |
533 | uint16_t port; | 543 | uint16_t port; |
534 | 544 | ||
535 | 545 | ||
536 | from = getFrom( mail ); | 546 | from = getFrom( mail ); |
537 | SMTPaccount *smtp = getAccount( from ); | 547 | SMTPaccount *smtp = getAccount( from ); |
538 | if ( smtp == NULL ) { | 548 | if ( smtp == NULL ) { |
539 | free(from); | 549 | free(from); |
540 | return; | 550 | return; |
541 | } | 551 | } |
542 | server = strdup( smtp->getServer().latin1() ); | 552 | server = strdup( smtp->getServer().latin1() ); |
543 | ssl = smtp->getSSL(); | 553 | ssl = smtp->getSSL(); |
544 | port = smtp->getPort().toUInt(); | 554 | port = smtp->getPort().toUInt(); |
545 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 555 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
546 | 556 | ||
547 | QString file = getTmpFile(); | 557 | QString file = getTmpFile(); |
548 | writeToFile( file, mail ); | 558 | writeToFile( file, mail ); |
549 | readFromFile( file, &data, &size ); | 559 | readFromFile( file, &data, &size ); |
550 | QFile f( file ); | 560 | QFile f( file ); |
551 | f.remove(); | 561 | f.remove(); |
552 | 562 | ||
553 | session = mailsmtp_new( 20, &progress ); | 563 | session = mailsmtp_new( 20, &progress ); |
554 | if ( session == NULL ) goto free_mem; | 564 | if ( session == NULL ) goto free_mem; |
555 | 565 | ||
556 | qDebug( "Servername %s at port %i", server, port ); | 566 | qDebug( "Servername %s at port %i", server, port ); |
557 | if ( ssl ) { | 567 | if ( ssl ) { |
558 | qDebug( "SSL session" ); | 568 | qDebug( "SSL session" ); |
559 | err = mailsmtp_ssl_connect( session, server, port ); | 569 | err = mailsmtp_ssl_connect( session, server, port ); |
560 | } else { | 570 | } else { |
561 | qDebug( "No SSL session" ); | 571 | qDebug( "No SSL session" ); |
562 | err = mailsmtp_socket_connect( session, server, port ); | 572 | err = mailsmtp_socket_connect( session, server, port ); |
563 | } | 573 | } |
564 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; | 574 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; |
565 | 575 | ||
566 | err = mailsmtp_init( session ); | 576 | err = mailsmtp_init( session ); |
567 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 577 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; |
568 | 578 | ||
569 | qDebug( "INIT OK" ); | 579 | qDebug( "INIT OK" ); |
570 | 580 | ||
571 | if ( smtp->getLogin() ) { | 581 | if ( smtp->getLogin() ) { |
572 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | 582 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { |
573 | // get'em | 583 | // get'em |
574 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | 584 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); |
575 | login.show(); | 585 | login.show(); |
576 | if ( QDialog::Accepted == login.exec() ) { | 586 | if ( QDialog::Accepted == login.exec() ) { |
577 | // ok | 587 | // ok |
578 | user = strdup( login.getUser().latin1() ); | 588 | user = strdup( login.getUser().latin1() ); |
579 | pass = strdup( login.getPassword().latin1() ); | 589 | pass = strdup( login.getPassword().latin1() ); |
580 | } else { | 590 | } else { |
581 | goto free_con_session; | 591 | goto free_con_session; |
582 | } | 592 | } |
583 | } else { | 593 | } else { |
584 | user = strdup( smtp->getUser().latin1() ); | 594 | user = strdup( smtp->getUser().latin1() ); |
585 | pass = strdup( smtp->getPassword().latin1() ); | 595 | pass = strdup( smtp->getPassword().latin1() ); |
586 | } | 596 | } |
587 | qDebug( "session->auth: %i", session->auth); | 597 | qDebug( "session->auth: %i", session->auth); |
588 | err = mailsmtp_auth( session, user, pass ); | 598 | err = mailsmtp_auth( session, user, pass ); |
589 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); | 599 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); |
590 | qDebug( "Done auth!" ); | 600 | qDebug( "Done auth!" ); |
591 | } | 601 | } |
592 | 602 | ||
593 | err = mailsmtp_send( session, from, rcpts, data, size ); | 603 | err = mailsmtp_send( session, from, rcpts, data, size ); |
594 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 604 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; |
595 | 605 | ||
596 | qDebug( "Mail sent." ); | 606 | qDebug( "Mail sent." ); |
597 | 607 | ||
598 | free_con_session: | 608 | free_con_session: |
599 | mailsmtp_quit( session ); | 609 | mailsmtp_quit( session ); |
600 | free_mem_session: | 610 | free_mem_session: |
601 | mailsmtp_free( session ); | 611 | mailsmtp_free( session ); |
602 | free_mem: | 612 | free_mem: |
603 | smtp_address_list_free( rcpts ); | 613 | smtp_address_list_free( rcpts ); |
604 | free( data ); | 614 | free( data ); |
605 | free( server ); | 615 | free( server ); |
606 | if ( smtp->getLogin() ) { | 616 | if ( smtp->getLogin() ) { |
607 | free( user ); | 617 | free( user ); |
608 | free( pass ); | 618 | free( pass ); |
609 | } | 619 | } |
610 | free( from ); | 620 | free( from ); |
611 | } | 621 | } |
612 | 622 | ||
613 | void MailWrapper::sendMail( Mail mail ) | 623 | void MailWrapper::sendMail( Mail mail ) |
614 | { | 624 | { |
615 | mailmime *mimeMail; | 625 | mailmime *mimeMail; |
616 | 626 | ||
617 | mimeMail = createMimeMail( &mail ); | 627 | mimeMail = createMimeMail( &mail ); |
618 | if ( mimeMail == NULL ) { | 628 | if ( mimeMail == NULL ) { |
619 | qDebug( "sendMail: error creating mime mail" ); | 629 | qDebug( "sendMail: error creating mime mail" ); |
620 | } else { | 630 | } else { |
621 | smtpSend( mimeMail ); | 631 | smtpSend( mimeMail ); |
622 | mailmime_free( mimeMail ); | 632 | mailmime_free( mimeMail ); |
623 | } | 633 | } |
624 | } | 634 | } |
625 | 635 | ||
626 | Mail::Mail() | 636 | Mail::Mail() |
627 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") | 637 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") |
628 | { | 638 | { |
629 | } | 639 | } |
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h index 34fd5c5..6994dd8 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.h +++ b/noncore/net/mail/libmailwrapper/mailwrapper.h | |||
@@ -1,123 +1,123 @@ | |||
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 <libetpan/mailmime.h> | 6 | #include <libetpan/mailmime.h> |
7 | #include <libetpan/mailimf.h> | 7 | #include <libetpan/mailimf.h> |
8 | #include <libetpan/mailsmtp.h> | 8 | #include <libetpan/mailsmtp.h> |
9 | #include <libetpan/mailstorage.h> | 9 | #include <libetpan/mailstorage.h> |
10 | #include <libetpan/maildriver.h> | 10 | #include <libetpan/maildriver.h> |
11 | #include <qbitarray.h> | 11 | #include <qbitarray.h> |
12 | #include <qdatetime.h> | 12 | #include <qdatetime.h> |
13 | 13 | ||
14 | #include "settings.h" | 14 | #include "settings.h" |
15 | 15 | ||
16 | class Attachment | 16 | class Attachment |
17 | { | 17 | { |
18 | public: | 18 | public: |
19 | Attachment( DocLnk lnk ); | 19 | Attachment( DocLnk lnk ); |
20 | virtual ~Attachment(){} | 20 | virtual ~Attachment(){} |
21 | const QString getFileName()const{ return doc.file(); } | 21 | const QString getFileName()const{ return doc.file(); } |
22 | const QString getName()const{ return doc.name(); } | 22 | const QString getName()const{ return doc.name(); } |
23 | const QString getMimeType()const{ return doc.type(); } | 23 | const QString getMimeType()const{ return doc.type(); } |
24 | const QPixmap getPixmap()const{ return doc.pixmap(); } | 24 | const QPixmap getPixmap()const{ return doc.pixmap(); } |
25 | const int getSize()const { return size; } | 25 | const int getSize()const { return size; } |
26 | DocLnk getDocLnk() { return doc; } | 26 | DocLnk getDocLnk() { return doc; } |
27 | 27 | ||
28 | protected: | 28 | protected: |
29 | DocLnk doc; | 29 | DocLnk doc; |
30 | int size; | 30 | int size; |
31 | 31 | ||
32 | }; | 32 | }; |
33 | 33 | ||
34 | class Mail | 34 | class Mail |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | Mail(); | 37 | Mail(); |
38 | /* Possible that this destructor must not be declared virtual | 38 | /* Possible that this destructor must not be declared virtual |
39 | * 'cause it seems that it will never have some child classes. | 39 | * 'cause it seems that it will never have some child classes. |
40 | * in this case this object will not get a virtual table -> memory and | 40 | * in this case this object will not get a virtual table -> memory and |
41 | * speed will be a little bit better? | 41 | * speed will be a little bit better? |
42 | */ | 42 | */ |
43 | virtual ~Mail(){} | 43 | virtual ~Mail(){} |
44 | void addAttachment( Attachment *att ) { attList.append( att ); } | 44 | void addAttachment( Attachment *att ) { attList.append( att ); } |
45 | const QList<Attachment>& getAttachments()const { return attList; } | 45 | const QList<Attachment>& getAttachments()const { return attList; } |
46 | void removeAttachment( Attachment *att ) { attList.remove( att ); } | 46 | void removeAttachment( Attachment *att ) { attList.remove( att ); } |
47 | const QString&getName()const { return name; } | 47 | const QString&getName()const { return name; } |
48 | void setName( QString s ) { name = s; } | 48 | void setName( QString s ) { name = s; } |
49 | const QString&getMail()const{ return mail; } | 49 | const QString&getMail()const{ return mail; } |
50 | void setMail( const QString&s ) { mail = s; } | 50 | void setMail( const QString&s ) { mail = s; } |
51 | const QString&getTo()const{ return to; } | 51 | const QString&getTo()const{ return to; } |
52 | void setTo( const QString&s ) { to = s; } | 52 | void setTo( const QString&s ) { to = s; } |
53 | const QString&getCC()const{ return cc; } | 53 | const QString&getCC()const{ return cc; } |
54 | void setCC( const QString&s ) { cc = s; } | 54 | void setCC( const QString&s ) { cc = s; } |
55 | const QString&getBCC()const { return bcc; } | 55 | const QString&getBCC()const { return bcc; } |
56 | void setBCC( const QString&s ) { bcc = s; } | 56 | void setBCC( const QString&s ) { bcc = s; } |
57 | const QString&getMessage()const { return message; } | 57 | const QString&getMessage()const { return message; } |
58 | void setMessage( const QString&s ) { message = s; } | 58 | void setMessage( const QString&s ) { message = s; } |
59 | const QString&getSubject()const { return subject; } | 59 | const QString&getSubject()const { return subject; } |
60 | void setSubject( const QString&s ) { subject = s; } | 60 | void setSubject( const QString&s ) { subject = s; } |
61 | const QString&getReply()const{ return reply; } | 61 | const QString&getReply()const{ return reply; } |
62 | void setReply( const QString&a ) { reply = a; } | 62 | void setReply( const QString&a ) { reply = a; } |
63 | 63 | ||
64 | private: | 64 | private: |
65 | QList<Attachment> attList; | 65 | QList<Attachment> attList; |
66 | QString name, mail, to, cc, bcc, reply, subject, message; | 66 | QString name, mail, to, cc, bcc, reply, subject, message; |
67 | }; | 67 | }; |
68 | 68 | ||
69 | class Folder : public QObject | 69 | class Folder : public QObject |
70 | { | 70 | { |
71 | Q_OBJECT | 71 | Q_OBJECT |
72 | 72 | ||
73 | public: | 73 | public: |
74 | Folder( const QString&init_name ); | 74 | Folder( const QString&init_name ); |
75 | const QString&getDisplayName()const { return nameDisplay; } | 75 | const QString&getDisplayName()const { return nameDisplay; } |
76 | const QString&getName()const { return name; } | 76 | const QString&getName()const { return name; } |
77 | virtual bool may_select()const{return true;}; | 77 | virtual bool may_select()const{return true;}; |
78 | 78 | ||
79 | private: | 79 | protected: |
80 | QString nameDisplay, name; | 80 | QString nameDisplay, name; |
81 | 81 | ||
82 | }; | 82 | }; |
83 | 83 | ||
84 | class IMAPFolder : public Folder | 84 | class IMAPFolder : public Folder |
85 | { | 85 | { |
86 | public: | 86 | public: |
87 | IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} | 87 | IMAPFolder(const QString&name,bool select=true,const QString&prefix="" ); |
88 | virtual bool may_select()const{return m_MaySelect;} | 88 | virtual bool may_select()const{return m_MaySelect;} |
89 | private: | 89 | private: |
90 | bool m_MaySelect; | 90 | bool m_MaySelect; |
91 | }; | 91 | }; |
92 | 92 | ||
93 | class MailWrapper : public QObject | 93 | class MailWrapper : public QObject |
94 | { | 94 | { |
95 | Q_OBJECT | 95 | Q_OBJECT |
96 | 96 | ||
97 | public: | 97 | public: |
98 | MailWrapper( Settings *s ); | 98 | MailWrapper( Settings *s ); |
99 | void sendMail( Mail mail ); | 99 | void sendMail( Mail mail ); |
100 | 100 | ||
101 | private: | 101 | private: |
102 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | 102 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); |
103 | mailimf_address_list *parseAddresses(const QString&addr ); | 103 | mailimf_address_list *parseAddresses(const QString&addr ); |
104 | mailimf_fields *createImfFields( Mail *mail ); | 104 | mailimf_fields *createImfFields( Mail *mail ); |
105 | mailmime *buildTxtPart( QString str ); | 105 | mailmime *buildTxtPart( QString str ); |
106 | mailmime *buildFilePart( QString filename, QString mimetype ); | 106 | mailmime *buildFilePart( QString filename, QString mimetype ); |
107 | void addFileParts( mailmime *message, QList<Attachment> files ); | 107 | void addFileParts( mailmime *message, QList<Attachment> files ); |
108 | mailmime *createMimeMail( Mail *mail ); | 108 | mailmime *createMimeMail( Mail *mail ); |
109 | void smtpSend( mailmime *mail ); | 109 | void smtpSend( mailmime *mail ); |
110 | mailimf_field *getField( mailimf_fields *fields, int type ); | 110 | mailimf_field *getField( mailimf_fields *fields, int type ); |
111 | clist *createRcptList( mailimf_fields *fields ); | 111 | clist *createRcptList( mailimf_fields *fields ); |
112 | char *getFrom( mailmime *mail ); | 112 | char *getFrom( mailmime *mail ); |
113 | SMTPaccount *getAccount( QString from ); | 113 | SMTPaccount *getAccount( QString from ); |
114 | void writeToFile( QString file, mailmime *mail ); | 114 | void writeToFile( QString file, mailmime *mail ); |
115 | void readFromFile( QString file, char **data, size_t *size ); | 115 | void readFromFile( QString file, char **data, size_t *size ); |
116 | static QString mailsmtpError( int err ); | 116 | static QString mailsmtpError( int err ); |
117 | static QString getTmpFile(); | 117 | static QString getTmpFile(); |
118 | 118 | ||
119 | Settings *settings; | 119 | Settings *settings; |
120 | 120 | ||
121 | }; | 121 | }; |
122 | 122 | ||
123 | #endif | 123 | #endif |
diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp index 3ffc274..96602c2 100644 --- a/noncore/net/mail/mailwrapper.cpp +++ b/noncore/net/mail/mailwrapper.cpp | |||
@@ -1,629 +1,639 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
3 | #include <sys/types.h> | 3 | #include <sys/types.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <fcntl.h> | 5 | #include <fcntl.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | 8 | ||
9 | #include "mailwrapper.h" | 9 | #include "mailwrapper.h" |
10 | #include "logindialog.h" | 10 | #include "logindialog.h" |
11 | //#include "mail.h" | 11 | //#include "mail.h" |
12 | #include "defines.h" | 12 | #include "defines.h" |
13 | 13 | ||
14 | Attachment::Attachment( DocLnk lnk ) | 14 | Attachment::Attachment( DocLnk lnk ) |
15 | { | 15 | { |
16 | doc = lnk; | 16 | doc = lnk; |
17 | size = QFileInfo( doc.file() ).size(); | 17 | size = QFileInfo( doc.file() ).size(); |
18 | } | 18 | } |
19 | 19 | ||
20 | Folder::Folder(const QString&tmp_name ) | 20 | Folder::Folder(const QString&tmp_name ) |
21 | { | 21 | { |
22 | name = tmp_name; | 22 | name = tmp_name; |
23 | nameDisplay = name; | 23 | nameDisplay = name; |
24 | 24 | ||
25 | for ( int pos = nameDisplay.find( '&' ); pos != -1; | 25 | for ( int pos = nameDisplay.find( '&' ); pos != -1; |
26 | pos = nameDisplay.find( '&' ) ) { | 26 | pos = nameDisplay.find( '&' ) ) { |
27 | int end = nameDisplay.find( '-' ); | 27 | int end = nameDisplay.find( '-' ); |
28 | if ( end == -1 || end <= pos ) break; | 28 | if ( end == -1 || end <= pos ) break; |
29 | QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 ); | 29 | QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 ); |
30 | // TODO: do real base64 decoding here ! | 30 | // TODO: do real base64 decoding here ! |
31 | if ( str64.compare( "APw" ) == 0 ) { | 31 | if ( str64.compare( "APw" ) == 0 ) { |
32 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" ); | 32 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" ); |
33 | } else if ( str64.compare( "APY" ) == 0 ) { | 33 | } else if ( str64.compare( "APY" ) == 0 ) { |
34 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" ); | 34 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" ); |
35 | } | 35 | } |
36 | } | 36 | } |
37 | |||
38 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); | 37 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); |
39 | } | 38 | } |
40 | 39 | ||
40 | |||
41 | IMAPFolder::IMAPFolder(const QString&name,bool select,const QString&prefix ) | ||
42 | : Folder( name ),m_MaySelect(select) | ||
43 | { | ||
44 | if (prefix.length()>0) { | ||
45 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { | ||
46 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); | ||
47 | } | ||
48 | } | ||
49 | } | ||
50 | |||
41 | MailWrapper::MailWrapper( Settings *s ) | 51 | MailWrapper::MailWrapper( Settings *s ) |
42 | : QObject() | 52 | : QObject() |
43 | { | 53 | { |
44 | settings = s; | 54 | settings = s; |
45 | } | 55 | } |
46 | 56 | ||
47 | QString MailWrapper::mailsmtpError( int errnum ) | 57 | QString MailWrapper::mailsmtpError( int errnum ) |
48 | { | 58 | { |
49 | switch ( errnum ) { | 59 | switch ( errnum ) { |
50 | case MAILSMTP_NO_ERROR: | 60 | case MAILSMTP_NO_ERROR: |
51 | return tr( "No error" ); | 61 | return tr( "No error" ); |
52 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 62 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
53 | return tr( "Unexpected error code" ); | 63 | return tr( "Unexpected error code" ); |
54 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 64 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
55 | return tr( "Service not available" ); | 65 | return tr( "Service not available" ); |
56 | case MAILSMTP_ERROR_STREAM: | 66 | case MAILSMTP_ERROR_STREAM: |
57 | return tr( "Stream error" ); | 67 | return tr( "Stream error" ); |
58 | case MAILSMTP_ERROR_HOSTNAME: | 68 | case MAILSMTP_ERROR_HOSTNAME: |
59 | return tr( "gethostname() failed" ); | 69 | return tr( "gethostname() failed" ); |
60 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 70 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
61 | return tr( "Not implemented" ); | 71 | return tr( "Not implemented" ); |
62 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 72 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
63 | return tr( "Error, action not taken" ); | 73 | return tr( "Error, action not taken" ); |
64 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 74 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
65 | return tr( "Data exceeds storage allocation" ); | 75 | return tr( "Data exceeds storage allocation" ); |
66 | case MAILSMTP_ERROR_IN_PROCESSING: | 76 | case MAILSMTP_ERROR_IN_PROCESSING: |
67 | return tr( "Error in processing" ); | 77 | return tr( "Error in processing" ); |
68 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 78 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
69 | // return tr( "Insufficient system storage" ); | 79 | // return tr( "Insufficient system storage" ); |
70 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 80 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
71 | return tr( "Mailbox unavailable" ); | 81 | return tr( "Mailbox unavailable" ); |
72 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 82 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
73 | return tr( "Mailbox name not allowed" ); | 83 | return tr( "Mailbox name not allowed" ); |
74 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 84 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
75 | return tr( "Bad command sequence" ); | 85 | return tr( "Bad command sequence" ); |
76 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 86 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
77 | return tr( "User not local" ); | 87 | return tr( "User not local" ); |
78 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 88 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
79 | return tr( "Transaction failed" ); | 89 | return tr( "Transaction failed" ); |
80 | case MAILSMTP_ERROR_MEMORY: | 90 | case MAILSMTP_ERROR_MEMORY: |
81 | return tr( "Memory error" ); | 91 | return tr( "Memory error" ); |
82 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 92 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
83 | return tr( "Connection refused" ); | 93 | return tr( "Connection refused" ); |
84 | default: | 94 | default: |
85 | return tr( "Unknown error code" ); | 95 | return tr( "Unknown error code" ); |
86 | } | 96 | } |
87 | } | 97 | } |
88 | 98 | ||
89 | mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) | 99 | mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) |
90 | { | 100 | { |
91 | return mailimf_mailbox_new( strdup( name.latin1() ), | 101 | return mailimf_mailbox_new( strdup( name.latin1() ), |
92 | strdup( mail.latin1() ) ); | 102 | strdup( mail.latin1() ) ); |
93 | } | 103 | } |
94 | 104 | ||
95 | mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) | 105 | mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) |
96 | { | 106 | { |
97 | mailimf_address_list *addresses; | 107 | mailimf_address_list *addresses; |
98 | 108 | ||
99 | if ( addr.isEmpty() ) return NULL; | 109 | if ( addr.isEmpty() ) return NULL; |
100 | 110 | ||
101 | addresses = mailimf_address_list_new_empty(); | 111 | addresses = mailimf_address_list_new_empty(); |
102 | 112 | ||
103 | QStringList list = QStringList::split( ',', addr ); | 113 | QStringList list = QStringList::split( ',', addr ); |
104 | QStringList::Iterator it; | 114 | QStringList::Iterator it; |
105 | for ( it = list.begin(); it != list.end(); it++ ) { | 115 | for ( it = list.begin(); it != list.end(); it++ ) { |
106 | char *str = strdup( (*it).latin1() ); | 116 | char *str = strdup( (*it).latin1() ); |
107 | int err = mailimf_address_list_add_parse( addresses, str ); | 117 | int err = mailimf_address_list_add_parse( addresses, str ); |
108 | if ( err != MAILIMF_NO_ERROR ) { | 118 | if ( err != MAILIMF_NO_ERROR ) { |
109 | qDebug( "Error parsing" ); | 119 | qDebug( "Error parsing" ); |
110 | qDebug( *it ); | 120 | qDebug( *it ); |
111 | free( str ); | 121 | free( str ); |
112 | } else { | 122 | } else { |
113 | qDebug( "Parse success! :)" ); | 123 | qDebug( "Parse success! :)" ); |
114 | } | 124 | } |
115 | } | 125 | } |
116 | 126 | ||
117 | return addresses; | 127 | return addresses; |
118 | } | 128 | } |
119 | 129 | ||
120 | mailimf_fields *MailWrapper::createImfFields( Mail *mail ) | 130 | mailimf_fields *MailWrapper::createImfFields( Mail *mail ) |
121 | { | 131 | { |
122 | mailimf_fields *fields; | 132 | mailimf_fields *fields; |
123 | mailimf_field *xmailer; | 133 | mailimf_field *xmailer; |
124 | mailimf_mailbox *sender, *fromBox; | 134 | mailimf_mailbox *sender, *fromBox; |
125 | mailimf_mailbox_list *from; | 135 | mailimf_mailbox_list *from; |
126 | mailimf_address_list *to, *cc, *bcc, *reply; | 136 | mailimf_address_list *to, *cc, *bcc, *reply; |
127 | char *subject = strdup( mail->getSubject().latin1() ); | 137 | char *subject = strdup( mail->getSubject().latin1() ); |
128 | int err; | 138 | int err; |
129 | 139 | ||
130 | sender = newMailbox( mail->getName(), mail->getMail() ); | 140 | sender = newMailbox( mail->getName(), mail->getMail() ); |
131 | if ( sender == NULL ) goto err_free; | 141 | if ( sender == NULL ) goto err_free; |
132 | 142 | ||
133 | fromBox = newMailbox( mail->getName(), mail->getMail() ); | 143 | fromBox = newMailbox( mail->getName(), mail->getMail() ); |
134 | if ( fromBox == NULL ) goto err_free_sender; | 144 | if ( fromBox == NULL ) goto err_free_sender; |
135 | 145 | ||
136 | from = mailimf_mailbox_list_new_empty(); | 146 | from = mailimf_mailbox_list_new_empty(); |
137 | if ( from == NULL ) goto err_free_fromBox; | 147 | if ( from == NULL ) goto err_free_fromBox; |
138 | 148 | ||
139 | err = mailimf_mailbox_list_add( from, fromBox ); | 149 | err = mailimf_mailbox_list_add( from, fromBox ); |
140 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; | 150 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; |
141 | 151 | ||
142 | to = parseAddresses( mail->getTo() ); | 152 | to = parseAddresses( mail->getTo() ); |
143 | if ( to == NULL ) goto err_free_from; | 153 | if ( to == NULL ) goto err_free_from; |
144 | 154 | ||
145 | cc = parseAddresses( mail->getCC() ); | 155 | cc = parseAddresses( mail->getCC() ); |
146 | bcc = parseAddresses( mail->getBCC() ); | 156 | bcc = parseAddresses( mail->getBCC() ); |
147 | reply = parseAddresses( mail->getReply() ); | 157 | reply = parseAddresses( mail->getReply() ); |
148 | 158 | ||
149 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | 159 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, |
150 | NULL, NULL, subject ); | 160 | NULL, NULL, subject ); |
151 | if ( fields == NULL ) goto err_free_reply; | 161 | if ( fields == NULL ) goto err_free_reply; |
152 | 162 | ||
153 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 163 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), |
154 | strdup( USER_AGENT ) ); | 164 | strdup( USER_AGENT ) ); |
155 | if ( xmailer == NULL ) goto err_free_fields; | 165 | if ( xmailer == NULL ) goto err_free_fields; |
156 | 166 | ||
157 | err = mailimf_fields_add( fields, xmailer ); | 167 | err = mailimf_fields_add( fields, xmailer ); |
158 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; | 168 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; |
159 | 169 | ||
160 | return fields; // Success :) | 170 | return fields; // Success :) |
161 | 171 | ||
162 | err_free_xmailer: | 172 | err_free_xmailer: |
163 | mailimf_field_free( xmailer ); | 173 | mailimf_field_free( xmailer ); |
164 | err_free_fields: | 174 | err_free_fields: |
165 | mailimf_fields_free( fields ); | 175 | mailimf_fields_free( fields ); |
166 | err_free_reply: | 176 | err_free_reply: |
167 | mailimf_address_list_free( reply ); | 177 | mailimf_address_list_free( reply ); |
168 | mailimf_address_list_free( bcc ); | 178 | mailimf_address_list_free( bcc ); |
169 | mailimf_address_list_free( cc ); | 179 | mailimf_address_list_free( cc ); |
170 | mailimf_address_list_free( to ); | 180 | mailimf_address_list_free( to ); |
171 | err_free_from: | 181 | err_free_from: |
172 | mailimf_mailbox_list_free( from ); | 182 | mailimf_mailbox_list_free( from ); |
173 | err_free_fromBox: | 183 | err_free_fromBox: |
174 | mailimf_mailbox_free( fromBox ); | 184 | mailimf_mailbox_free( fromBox ); |
175 | err_free_sender: | 185 | err_free_sender: |
176 | mailimf_mailbox_free( sender ); | 186 | mailimf_mailbox_free( sender ); |
177 | err_free: | 187 | err_free: |
178 | free( subject ); | 188 | free( subject ); |
179 | qDebug( "createImfFields - error" ); | 189 | qDebug( "createImfFields - error" ); |
180 | 190 | ||
181 | return NULL; // Error :( | 191 | return NULL; // Error :( |
182 | } | 192 | } |
183 | 193 | ||
184 | mailmime *MailWrapper::buildTxtPart( QString str ) | 194 | mailmime *MailWrapper::buildTxtPart( QString str ) |
185 | { | 195 | { |
186 | mailmime *txtPart; | 196 | mailmime *txtPart; |
187 | mailmime_fields *fields; | 197 | mailmime_fields *fields; |
188 | mailmime_content *content; | 198 | mailmime_content *content; |
189 | mailmime_parameter *param; | 199 | mailmime_parameter *param; |
190 | char *txt = strdup( str.latin1() ); | 200 | char *txt = strdup( str.latin1() ); |
191 | int err; | 201 | int err; |
192 | 202 | ||
193 | param = mailmime_parameter_new( strdup( "charset" ), | 203 | param = mailmime_parameter_new( strdup( "charset" ), |
194 | strdup( "iso-8859-1" ) ); | 204 | strdup( "iso-8859-1" ) ); |
195 | if ( param == NULL ) goto err_free; | 205 | if ( param == NULL ) goto err_free; |
196 | 206 | ||
197 | content = mailmime_content_new_with_str( "text/plain" ); | 207 | content = mailmime_content_new_with_str( "text/plain" ); |
198 | if ( content == NULL ) goto err_free_param; | 208 | if ( content == NULL ) goto err_free_param; |
199 | 209 | ||
200 | err = clist_append( content->ct_parameters, param ); | 210 | err = clist_append( content->ct_parameters, param ); |
201 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | 211 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; |
202 | 212 | ||
203 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); | 213 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); |
204 | if ( fields == NULL ) goto err_free_content; | 214 | if ( fields == NULL ) goto err_free_content; |
205 | 215 | ||
206 | txtPart = mailmime_new_empty( content, fields ); | 216 | txtPart = mailmime_new_empty( content, fields ); |
207 | if ( txtPart == NULL ) goto err_free_fields; | 217 | if ( txtPart == NULL ) goto err_free_fields; |
208 | 218 | ||
209 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); | 219 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); |
210 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 220 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
211 | 221 | ||
212 | return txtPart; // Success :) | 222 | return txtPart; // Success :) |
213 | 223 | ||
214 | err_free_txtPart: | 224 | err_free_txtPart: |
215 | mailmime_free( txtPart ); | 225 | mailmime_free( txtPart ); |
216 | err_free_fields: | 226 | err_free_fields: |
217 | mailmime_fields_free( fields ); | 227 | mailmime_fields_free( fields ); |
218 | err_free_content: | 228 | err_free_content: |
219 | mailmime_content_free( content ); | 229 | mailmime_content_free( content ); |
220 | err_free_param: | 230 | err_free_param: |
221 | mailmime_parameter_free( param ); | 231 | mailmime_parameter_free( param ); |
222 | err_free: | 232 | err_free: |
223 | free( txt ); | 233 | free( txt ); |
224 | qDebug( "buildTxtPart - error" ); | 234 | qDebug( "buildTxtPart - error" ); |
225 | 235 | ||
226 | return NULL; // Error :( | 236 | return NULL; // Error :( |
227 | } | 237 | } |
228 | 238 | ||
229 | mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) | 239 | mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) |
230 | { | 240 | { |
231 | mailmime * filePart; | 241 | mailmime * filePart; |
232 | mailmime_fields * fields; | 242 | mailmime_fields * fields; |
233 | mailmime_content * content; | 243 | mailmime_content * content; |
234 | mailmime_parameter * param = NULL; | 244 | mailmime_parameter * param = NULL; |
235 | int err; | 245 | int err; |
236 | 246 | ||
237 | int pos = filename.findRev( '/' ); | 247 | int pos = filename.findRev( '/' ); |
238 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 248 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
239 | char *name = strdup( tmp.latin1() ); // just filename | 249 | char *name = strdup( tmp.latin1() ); // just filename |
240 | char *file = strdup( filename.latin1() ); // full name with path | 250 | char *file = strdup( filename.latin1() ); // full name with path |
241 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain | 251 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain |
242 | 252 | ||
243 | fields = mailmime_fields_new_filename( | 253 | fields = mailmime_fields_new_filename( |
244 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, | 254 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, |
245 | MAILMIME_MECHANISM_BASE64 ); | 255 | MAILMIME_MECHANISM_BASE64 ); |
246 | if ( fields == NULL ) goto err_free; | 256 | if ( fields == NULL ) goto err_free; |
247 | 257 | ||
248 | content = mailmime_content_new_with_str( mime ); | 258 | content = mailmime_content_new_with_str( mime ); |
249 | if ( content == NULL ) goto err_free_fields; | 259 | if ( content == NULL ) goto err_free_fields; |
250 | 260 | ||
251 | if ( mimetype.compare( "text/plain" ) == 0 ) { | 261 | if ( mimetype.compare( "text/plain" ) == 0 ) { |
252 | param = mailmime_parameter_new( strdup( "charset" ), | 262 | param = mailmime_parameter_new( strdup( "charset" ), |
253 | strdup( "iso-8859-1" ) ); | 263 | strdup( "iso-8859-1" ) ); |
254 | if ( param == NULL ) goto err_free_content; | 264 | if ( param == NULL ) goto err_free_content; |
255 | 265 | ||
256 | err = clist_append( content->ct_parameters, param ); | 266 | err = clist_append( content->ct_parameters, param ); |
257 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; | 267 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; |
258 | } | 268 | } |
259 | 269 | ||
260 | filePart = mailmime_new_empty( content, fields ); | 270 | filePart = mailmime_new_empty( content, fields ); |
261 | if ( filePart == NULL ) goto err_free_param; | 271 | if ( filePart == NULL ) goto err_free_param; |
262 | 272 | ||
263 | err = mailmime_set_body_file( filePart, file ); | 273 | err = mailmime_set_body_file( filePart, file ); |
264 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 274 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; |
265 | 275 | ||
266 | return filePart; // Success :) | 276 | return filePart; // Success :) |
267 | 277 | ||
268 | err_free_filePart: | 278 | err_free_filePart: |
269 | mailmime_free( filePart ); | 279 | mailmime_free( filePart ); |
270 | err_free_param: | 280 | err_free_param: |
271 | if ( param != NULL ) mailmime_parameter_free( param ); | 281 | if ( param != NULL ) mailmime_parameter_free( param ); |
272 | err_free_content: | 282 | err_free_content: |
273 | mailmime_content_free( content ); | 283 | mailmime_content_free( content ); |
274 | err_free_fields: | 284 | err_free_fields: |
275 | mailmime_fields_free( fields ); | 285 | mailmime_fields_free( fields ); |
276 | err_free: | 286 | err_free: |
277 | free( name ); | 287 | free( name ); |
278 | free( mime ); | 288 | free( mime ); |
279 | free( file ); | 289 | free( file ); |
280 | qDebug( "buildFilePart - error" ); | 290 | qDebug( "buildFilePart - error" ); |
281 | 291 | ||
282 | return NULL; // Error :( | 292 | return NULL; // Error :( |
283 | } | 293 | } |
284 | 294 | ||
285 | void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) | 295 | void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) |
286 | { | 296 | { |
287 | Attachment *it; | 297 | Attachment *it; |
288 | for ( it = files.first(); it; it = files.next() ) { | 298 | for ( it = files.first(); it; it = files.next() ) { |
289 | qDebug( "Adding file" ); | 299 | qDebug( "Adding file" ); |
290 | mailmime *filePart; | 300 | mailmime *filePart; |
291 | int err; | 301 | int err; |
292 | 302 | ||
293 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); | 303 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); |
294 | if ( filePart == NULL ) goto err_free; | 304 | if ( filePart == NULL ) goto err_free; |
295 | 305 | ||
296 | err = mailmime_smart_add_part( message, filePart ); | 306 | err = mailmime_smart_add_part( message, filePart ); |
297 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 307 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; |
298 | 308 | ||
299 | continue; // Success :) | 309 | continue; // Success :) |
300 | 310 | ||
301 | err_free_filePart: | 311 | err_free_filePart: |
302 | mailmime_free( filePart ); | 312 | mailmime_free( filePart ); |
303 | err_free: | 313 | err_free: |
304 | qDebug( "addFileParts: error adding file:" ); | 314 | qDebug( "addFileParts: error adding file:" ); |
305 | qDebug( it->getFileName() ); | 315 | qDebug( it->getFileName() ); |
306 | } | 316 | } |
307 | } | 317 | } |
308 | 318 | ||
309 | mailmime *MailWrapper::createMimeMail( Mail *mail ) | 319 | mailmime *MailWrapper::createMimeMail( Mail *mail ) |
310 | { | 320 | { |
311 | mailmime *message, *txtPart; | 321 | mailmime *message, *txtPart; |
312 | mailimf_fields *fields; | 322 | mailimf_fields *fields; |
313 | int err; | 323 | int err; |
314 | 324 | ||
315 | fields = createImfFields( mail ); | 325 | fields = createImfFields( mail ); |
316 | if ( fields == NULL ) goto err_free; | 326 | if ( fields == NULL ) goto err_free; |
317 | 327 | ||
318 | message = mailmime_new_message_data( NULL ); | 328 | message = mailmime_new_message_data( NULL ); |
319 | if ( message == NULL ) goto err_free_fields; | 329 | if ( message == NULL ) goto err_free_fields; |
320 | 330 | ||
321 | mailmime_set_imf_fields( message, fields ); | 331 | mailmime_set_imf_fields( message, fields ); |
322 | 332 | ||
323 | txtPart = buildTxtPart( mail->getMessage() ); | 333 | txtPart = buildTxtPart( mail->getMessage() ); |
324 | if ( txtPart == NULL ) goto err_free_message; | 334 | if ( txtPart == NULL ) goto err_free_message; |
325 | 335 | ||
326 | err = mailmime_smart_add_part( message, txtPart ); | 336 | err = mailmime_smart_add_part( message, txtPart ); |
327 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 337 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
328 | 338 | ||
329 | addFileParts( message, mail->getAttachments() ); | 339 | addFileParts( message, mail->getAttachments() ); |
330 | 340 | ||
331 | return message; // Success :) | 341 | return message; // Success :) |
332 | 342 | ||
333 | err_free_txtPart: | 343 | err_free_txtPart: |
334 | mailmime_free( txtPart ); | 344 | mailmime_free( txtPart ); |
335 | err_free_message: | 345 | err_free_message: |
336 | mailmime_free( message ); | 346 | mailmime_free( message ); |
337 | err_free_fields: | 347 | err_free_fields: |
338 | mailimf_fields_free( fields ); | 348 | mailimf_fields_free( fields ); |
339 | err_free: | 349 | err_free: |
340 | qDebug( "createMimeMail: error" ); | 350 | qDebug( "createMimeMail: error" ); |
341 | 351 | ||
342 | return NULL; // Error :( | 352 | return NULL; // Error :( |
343 | } | 353 | } |
344 | 354 | ||
345 | mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) | 355 | mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) |
346 | { | 356 | { |
347 | mailimf_field *field; | 357 | mailimf_field *field; |
348 | clistiter *it; | 358 | clistiter *it; |
349 | 359 | ||
350 | it = clist_begin( fields->fld_list ); | 360 | it = clist_begin( fields->fld_list ); |
351 | while ( it ) { | 361 | while ( it ) { |
352 | field = (mailimf_field *) it->data; | 362 | field = (mailimf_field *) it->data; |
353 | if ( field->fld_type == type ) { | 363 | if ( field->fld_type == type ) { |
354 | return field; | 364 | return field; |
355 | } | 365 | } |
356 | it = it->next; | 366 | it = it->next; |
357 | } | 367 | } |
358 | 368 | ||
359 | return NULL; | 369 | return NULL; |
360 | } | 370 | } |
361 | 371 | ||
362 | static void addRcpts( clist *list, mailimf_address_list *addr_list ) | 372 | static void addRcpts( clist *list, mailimf_address_list *addr_list ) |
363 | { | 373 | { |
364 | clistiter *it, *it2; | 374 | clistiter *it, *it2; |
365 | 375 | ||
366 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | 376 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { |
367 | mailimf_address *addr; | 377 | mailimf_address *addr; |
368 | addr = (mailimf_address *) it->data; | 378 | addr = (mailimf_address *) it->data; |
369 | 379 | ||
370 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | 380 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { |
371 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | 381 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); |
372 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { | 382 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { |
373 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | 383 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; |
374 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | 384 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { |
375 | mailimf_mailbox *mbox; | 385 | mailimf_mailbox *mbox; |
376 | mbox = (mailimf_mailbox *) it2->data; | 386 | mbox = (mailimf_mailbox *) it2->data; |
377 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | 387 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); |
378 | } | 388 | } |
379 | } | 389 | } |
380 | } | 390 | } |
381 | } | 391 | } |
382 | 392 | ||
383 | clist *MailWrapper::createRcptList( mailimf_fields *fields ) | 393 | clist *MailWrapper::createRcptList( mailimf_fields *fields ) |
384 | { | 394 | { |
385 | clist *rcptList; | 395 | clist *rcptList; |
386 | mailimf_field *field; | 396 | mailimf_field *field; |
387 | 397 | ||
388 | rcptList = esmtp_address_list_new(); | 398 | rcptList = esmtp_address_list_new(); |
389 | 399 | ||
390 | field = getField( fields, MAILIMF_FIELD_TO ); | 400 | field = getField( fields, MAILIMF_FIELD_TO ); |
391 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) | 401 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) |
392 | && field->fld_data.fld_to->to_addr_list ) { | 402 | && field->fld_data.fld_to->to_addr_list ) { |
393 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); | 403 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); |
394 | } | 404 | } |
395 | 405 | ||
396 | field = getField( fields, MAILIMF_FIELD_CC ); | 406 | field = getField( fields, MAILIMF_FIELD_CC ); |
397 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) | 407 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) |
398 | && field->fld_data.fld_cc->cc_addr_list ) { | 408 | && field->fld_data.fld_cc->cc_addr_list ) { |
399 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); | 409 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); |
400 | } | 410 | } |
401 | 411 | ||
402 | field = getField( fields, MAILIMF_FIELD_BCC ); | 412 | field = getField( fields, MAILIMF_FIELD_BCC ); |
403 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) | 413 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) |
404 | && field->fld_data.fld_bcc->bcc_addr_list ) { | 414 | && field->fld_data.fld_bcc->bcc_addr_list ) { |
405 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); | 415 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); |
406 | } | 416 | } |
407 | 417 | ||
408 | return rcptList; | 418 | return rcptList; |
409 | } | 419 | } |
410 | 420 | ||
411 | char *MailWrapper::getFrom( mailmime *mail ) | 421 | char *MailWrapper::getFrom( mailmime *mail ) |
412 | { | 422 | { |
413 | char *from = NULL; | 423 | char *from = NULL; |
414 | 424 | ||
415 | mailimf_field *ffrom; | 425 | mailimf_field *ffrom; |
416 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | 426 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); |
417 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 427 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) |
418 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | 428 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { |
419 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | 429 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; |
420 | clistiter *it; | 430 | clistiter *it; |
421 | for ( it = clist_begin( cl ); it; it = it->next ) { | 431 | for ( it = clist_begin( cl ); it; it = it->next ) { |
422 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 432 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
423 | from = strdup( mb->mb_addr_spec ); | 433 | from = strdup( mb->mb_addr_spec ); |
424 | } | 434 | } |
425 | } | 435 | } |
426 | 436 | ||
427 | return from; | 437 | return from; |
428 | } | 438 | } |
429 | 439 | ||
430 | SMTPaccount *MailWrapper::getAccount( QString from ) | 440 | SMTPaccount *MailWrapper::getAccount( QString from ) |
431 | { | 441 | { |
432 | SMTPaccount *smtp; | 442 | SMTPaccount *smtp; |
433 | 443 | ||
434 | QList<Account> list = settings->getAccounts(); | 444 | QList<Account> list = settings->getAccounts(); |
435 | Account *it; | 445 | Account *it; |
436 | for ( it = list.first(); it; it = list.next() ) { | 446 | for ( it = list.first(); it; it = list.next() ) { |
437 | if ( it->getType().compare( "SMTP" ) == 0 ) { | 447 | if ( it->getType().compare( "SMTP" ) == 0 ) { |
438 | smtp = static_cast<SMTPaccount *>(it); | 448 | smtp = static_cast<SMTPaccount *>(it); |
439 | if ( smtp->getMail().compare( from ) == 0 ) { | 449 | if ( smtp->getMail().compare( from ) == 0 ) { |
440 | qDebug( "SMTPaccount found for" ); | 450 | qDebug( "SMTPaccount found for" ); |
441 | qDebug( from ); | 451 | qDebug( from ); |
442 | return smtp; | 452 | return smtp; |
443 | } | 453 | } |
444 | } | 454 | } |
445 | } | 455 | } |
446 | 456 | ||
447 | return NULL; | 457 | return NULL; |
448 | } | 458 | } |
449 | 459 | ||
450 | QString MailWrapper::getTmpFile() { | 460 | QString MailWrapper::getTmpFile() { |
451 | int num = 0; | 461 | int num = 0; |
452 | QString unique; | 462 | QString unique; |
453 | 463 | ||
454 | QDir dir( "/tmp" ); | 464 | QDir dir( "/tmp" ); |
455 | QStringList::Iterator it; | 465 | QStringList::Iterator it; |
456 | 466 | ||
457 | QStringList list = dir.entryList( "opiemail-tmp-*" ); | 467 | QStringList list = dir.entryList( "opiemail-tmp-*" ); |
458 | do { | 468 | do { |
459 | unique.setNum( num++ ); | 469 | unique.setNum( num++ ); |
460 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); | 470 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); |
461 | 471 | ||
462 | return "/tmp/opiemail-tmp-" + unique; | 472 | return "/tmp/opiemail-tmp-" + unique; |
463 | } | 473 | } |
464 | 474 | ||
465 | void MailWrapper::writeToFile( QString file, mailmime *mail ) | 475 | void MailWrapper::writeToFile( QString file, mailmime *mail ) |
466 | { | 476 | { |
467 | FILE *f; | 477 | FILE *f; |
468 | int err, col = 0; | 478 | int err, col = 0; |
469 | 479 | ||
470 | f = fopen( file.latin1(), "w" ); | 480 | f = fopen( file.latin1(), "w" ); |
471 | if ( f == NULL ) { | 481 | if ( f == NULL ) { |
472 | qDebug( "writeToFile: error opening file" ); | 482 | qDebug( "writeToFile: error opening file" ); |
473 | return; | 483 | return; |
474 | } | 484 | } |
475 | 485 | ||
476 | err = mailmime_write( f, &col, mail ); | 486 | err = mailmime_write( f, &col, mail ); |
477 | if ( err != MAILIMF_NO_ERROR ) { | 487 | if ( err != MAILIMF_NO_ERROR ) { |
478 | fclose( f ); | 488 | fclose( f ); |
479 | qDebug( "writeToFile: error writing mailmime" ); | 489 | qDebug( "writeToFile: error writing mailmime" ); |
480 | return; | 490 | return; |
481 | } | 491 | } |
482 | 492 | ||
483 | fclose( f ); | 493 | fclose( f ); |
484 | } | 494 | } |
485 | 495 | ||
486 | void MailWrapper::readFromFile( QString file, char **data, size_t *size ) | 496 | void MailWrapper::readFromFile( QString file, char **data, size_t *size ) |
487 | { | 497 | { |
488 | char *buf; | 498 | char *buf; |
489 | struct stat st; | 499 | struct stat st; |
490 | int fd, count = 0, total = 0; | 500 | int fd, count = 0, total = 0; |
491 | 501 | ||
492 | fd = open( file.latin1(), O_RDONLY, 0 ); | 502 | fd = open( file.latin1(), O_RDONLY, 0 ); |
493 | if ( fd == -1 ) return; | 503 | if ( fd == -1 ) return; |
494 | 504 | ||
495 | if ( fstat( fd, &st ) != 0 ) goto err_close; | 505 | if ( fstat( fd, &st ) != 0 ) goto err_close; |
496 | if ( !st.st_size ) goto err_close; | 506 | if ( !st.st_size ) goto err_close; |
497 | 507 | ||
498 | buf = (char *) malloc( st.st_size ); | 508 | buf = (char *) malloc( st.st_size ); |
499 | if ( !buf ) goto err_close; | 509 | if ( !buf ) goto err_close; |
500 | 510 | ||
501 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { | 511 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { |
502 | count = read( fd, buf + total, st.st_size - total ); | 512 | count = read( fd, buf + total, st.st_size - total ); |
503 | total += count; | 513 | total += count; |
504 | } | 514 | } |
505 | if ( count < 0 ) goto err_free; | 515 | if ( count < 0 ) goto err_free; |
506 | 516 | ||
507 | *data = buf; | 517 | *data = buf; |
508 | *size = st.st_size; | 518 | *size = st.st_size; |
509 | 519 | ||
510 | close( fd ); | 520 | close( fd ); |
511 | 521 | ||
512 | return; // Success :) | 522 | return; // Success :) |
513 | 523 | ||
514 | err_free: | 524 | err_free: |
515 | free( buf ); | 525 | free( buf ); |
516 | err_close: | 526 | err_close: |
517 | close( fd ); | 527 | close( fd ); |
518 | } | 528 | } |
519 | 529 | ||
520 | void progress( size_t current, size_t maximum ) | 530 | void progress( size_t current, size_t maximum ) |
521 | { | 531 | { |
522 | qDebug( "Current: %i of %i", current, maximum ); | 532 | qDebug( "Current: %i of %i", current, maximum ); |
523 | } | 533 | } |
524 | 534 | ||
525 | void MailWrapper::smtpSend( mailmime *mail ) | 535 | void MailWrapper::smtpSend( mailmime *mail ) |
526 | { | 536 | { |
527 | mailsmtp *session; | 537 | mailsmtp *session; |
528 | clist *rcpts; | 538 | clist *rcpts; |
529 | char *from, *data, *server, *user = NULL, *pass = NULL; | 539 | char *from, *data, *server, *user = NULL, *pass = NULL; |
530 | size_t size; | 540 | size_t size; |
531 | int err; | 541 | int err; |
532 | bool ssl; | 542 | bool ssl; |
533 | uint16_t port; | 543 | uint16_t port; |
534 | 544 | ||
535 | 545 | ||
536 | from = getFrom( mail ); | 546 | from = getFrom( mail ); |
537 | SMTPaccount *smtp = getAccount( from ); | 547 | SMTPaccount *smtp = getAccount( from ); |
538 | if ( smtp == NULL ) { | 548 | if ( smtp == NULL ) { |
539 | free(from); | 549 | free(from); |
540 | return; | 550 | return; |
541 | } | 551 | } |
542 | server = strdup( smtp->getServer().latin1() ); | 552 | server = strdup( smtp->getServer().latin1() ); |
543 | ssl = smtp->getSSL(); | 553 | ssl = smtp->getSSL(); |
544 | port = smtp->getPort().toUInt(); | 554 | port = smtp->getPort().toUInt(); |
545 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 555 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
546 | 556 | ||
547 | QString file = getTmpFile(); | 557 | QString file = getTmpFile(); |
548 | writeToFile( file, mail ); | 558 | writeToFile( file, mail ); |
549 | readFromFile( file, &data, &size ); | 559 | readFromFile( file, &data, &size ); |
550 | QFile f( file ); | 560 | QFile f( file ); |
551 | f.remove(); | 561 | f.remove(); |
552 | 562 | ||
553 | session = mailsmtp_new( 20, &progress ); | 563 | session = mailsmtp_new( 20, &progress ); |
554 | if ( session == NULL ) goto free_mem; | 564 | if ( session == NULL ) goto free_mem; |
555 | 565 | ||
556 | qDebug( "Servername %s at port %i", server, port ); | 566 | qDebug( "Servername %s at port %i", server, port ); |
557 | if ( ssl ) { | 567 | if ( ssl ) { |
558 | qDebug( "SSL session" ); | 568 | qDebug( "SSL session" ); |
559 | err = mailsmtp_ssl_connect( session, server, port ); | 569 | err = mailsmtp_ssl_connect( session, server, port ); |
560 | } else { | 570 | } else { |
561 | qDebug( "No SSL session" ); | 571 | qDebug( "No SSL session" ); |
562 | err = mailsmtp_socket_connect( session, server, port ); | 572 | err = mailsmtp_socket_connect( session, server, port ); |
563 | } | 573 | } |
564 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; | 574 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; |
565 | 575 | ||
566 | err = mailsmtp_init( session ); | 576 | err = mailsmtp_init( session ); |
567 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 577 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; |
568 | 578 | ||
569 | qDebug( "INIT OK" ); | 579 | qDebug( "INIT OK" ); |
570 | 580 | ||
571 | if ( smtp->getLogin() ) { | 581 | if ( smtp->getLogin() ) { |
572 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | 582 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { |
573 | // get'em | 583 | // get'em |
574 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | 584 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); |
575 | login.show(); | 585 | login.show(); |
576 | if ( QDialog::Accepted == login.exec() ) { | 586 | if ( QDialog::Accepted == login.exec() ) { |
577 | // ok | 587 | // ok |
578 | user = strdup( login.getUser().latin1() ); | 588 | user = strdup( login.getUser().latin1() ); |
579 | pass = strdup( login.getPassword().latin1() ); | 589 | pass = strdup( login.getPassword().latin1() ); |
580 | } else { | 590 | } else { |
581 | goto free_con_session; | 591 | goto free_con_session; |
582 | } | 592 | } |
583 | } else { | 593 | } else { |
584 | user = strdup( smtp->getUser().latin1() ); | 594 | user = strdup( smtp->getUser().latin1() ); |
585 | pass = strdup( smtp->getPassword().latin1() ); | 595 | pass = strdup( smtp->getPassword().latin1() ); |
586 | } | 596 | } |
587 | qDebug( "session->auth: %i", session->auth); | 597 | qDebug( "session->auth: %i", session->auth); |
588 | err = mailsmtp_auth( session, user, pass ); | 598 | err = mailsmtp_auth( session, user, pass ); |
589 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); | 599 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); |
590 | qDebug( "Done auth!" ); | 600 | qDebug( "Done auth!" ); |
591 | } | 601 | } |
592 | 602 | ||
593 | err = mailsmtp_send( session, from, rcpts, data, size ); | 603 | err = mailsmtp_send( session, from, rcpts, data, size ); |
594 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 604 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; |
595 | 605 | ||
596 | qDebug( "Mail sent." ); | 606 | qDebug( "Mail sent." ); |
597 | 607 | ||
598 | free_con_session: | 608 | free_con_session: |
599 | mailsmtp_quit( session ); | 609 | mailsmtp_quit( session ); |
600 | free_mem_session: | 610 | free_mem_session: |
601 | mailsmtp_free( session ); | 611 | mailsmtp_free( session ); |
602 | free_mem: | 612 | free_mem: |
603 | smtp_address_list_free( rcpts ); | 613 | smtp_address_list_free( rcpts ); |
604 | free( data ); | 614 | free( data ); |
605 | free( server ); | 615 | free( server ); |
606 | if ( smtp->getLogin() ) { | 616 | if ( smtp->getLogin() ) { |
607 | free( user ); | 617 | free( user ); |
608 | free( pass ); | 618 | free( pass ); |
609 | } | 619 | } |
610 | free( from ); | 620 | free( from ); |
611 | } | 621 | } |
612 | 622 | ||
613 | void MailWrapper::sendMail( Mail mail ) | 623 | void MailWrapper::sendMail( Mail mail ) |
614 | { | 624 | { |
615 | mailmime *mimeMail; | 625 | mailmime *mimeMail; |
616 | 626 | ||
617 | mimeMail = createMimeMail( &mail ); | 627 | mimeMail = createMimeMail( &mail ); |
618 | if ( mimeMail == NULL ) { | 628 | if ( mimeMail == NULL ) { |
619 | qDebug( "sendMail: error creating mime mail" ); | 629 | qDebug( "sendMail: error creating mime mail" ); |
620 | } else { | 630 | } else { |
621 | smtpSend( mimeMail ); | 631 | smtpSend( mimeMail ); |
622 | mailmime_free( mimeMail ); | 632 | mailmime_free( mimeMail ); |
623 | } | 633 | } |
624 | } | 634 | } |
625 | 635 | ||
626 | Mail::Mail() | 636 | Mail::Mail() |
627 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") | 637 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") |
628 | { | 638 | { |
629 | } | 639 | } |
diff --git a/noncore/net/mail/mailwrapper.h b/noncore/net/mail/mailwrapper.h index 34fd5c5..6994dd8 100644 --- a/noncore/net/mail/mailwrapper.h +++ b/noncore/net/mail/mailwrapper.h | |||
@@ -1,123 +1,123 @@ | |||
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 <libetpan/mailmime.h> | 6 | #include <libetpan/mailmime.h> |
7 | #include <libetpan/mailimf.h> | 7 | #include <libetpan/mailimf.h> |
8 | #include <libetpan/mailsmtp.h> | 8 | #include <libetpan/mailsmtp.h> |
9 | #include <libetpan/mailstorage.h> | 9 | #include <libetpan/mailstorage.h> |
10 | #include <libetpan/maildriver.h> | 10 | #include <libetpan/maildriver.h> |
11 | #include <qbitarray.h> | 11 | #include <qbitarray.h> |
12 | #include <qdatetime.h> | 12 | #include <qdatetime.h> |
13 | 13 | ||
14 | #include "settings.h" | 14 | #include "settings.h" |
15 | 15 | ||
16 | class Attachment | 16 | class Attachment |
17 | { | 17 | { |
18 | public: | 18 | public: |
19 | Attachment( DocLnk lnk ); | 19 | Attachment( DocLnk lnk ); |
20 | virtual ~Attachment(){} | 20 | virtual ~Attachment(){} |
21 | const QString getFileName()const{ return doc.file(); } | 21 | const QString getFileName()const{ return doc.file(); } |
22 | const QString getName()const{ return doc.name(); } | 22 | const QString getName()const{ return doc.name(); } |
23 | const QString getMimeType()const{ return doc.type(); } | 23 | const QString getMimeType()const{ return doc.type(); } |
24 | const QPixmap getPixmap()const{ return doc.pixmap(); } | 24 | const QPixmap getPixmap()const{ return doc.pixmap(); } |
25 | const int getSize()const { return size; } | 25 | const int getSize()const { return size; } |
26 | DocLnk getDocLnk() { return doc; } | 26 | DocLnk getDocLnk() { return doc; } |
27 | 27 | ||
28 | protected: | 28 | protected: |
29 | DocLnk doc; | 29 | DocLnk doc; |
30 | int size; | 30 | int size; |
31 | 31 | ||
32 | }; | 32 | }; |
33 | 33 | ||
34 | class Mail | 34 | class Mail |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | Mail(); | 37 | Mail(); |
38 | /* Possible that this destructor must not be declared virtual | 38 | /* Possible that this destructor must not be declared virtual |
39 | * 'cause it seems that it will never have some child classes. | 39 | * 'cause it seems that it will never have some child classes. |
40 | * in this case this object will not get a virtual table -> memory and | 40 | * in this case this object will not get a virtual table -> memory and |
41 | * speed will be a little bit better? | 41 | * speed will be a little bit better? |
42 | */ | 42 | */ |
43 | virtual ~Mail(){} | 43 | virtual ~Mail(){} |
44 | void addAttachment( Attachment *att ) { attList.append( att ); } | 44 | void addAttachment( Attachment *att ) { attList.append( att ); } |
45 | const QList<Attachment>& getAttachments()const { return attList; } | 45 | const QList<Attachment>& getAttachments()const { return attList; } |
46 | void removeAttachment( Attachment *att ) { attList.remove( att ); } | 46 | void removeAttachment( Attachment *att ) { attList.remove( att ); } |
47 | const QString&getName()const { return name; } | 47 | const QString&getName()const { return name; } |
48 | void setName( QString s ) { name = s; } | 48 | void setName( QString s ) { name = s; } |
49 | const QString&getMail()const{ return mail; } | 49 | const QString&getMail()const{ return mail; } |
50 | void setMail( const QString&s ) { mail = s; } | 50 | void setMail( const QString&s ) { mail = s; } |
51 | const QString&getTo()const{ return to; } | 51 | const QString&getTo()const{ return to; } |
52 | void setTo( const QString&s ) { to = s; } | 52 | void setTo( const QString&s ) { to = s; } |
53 | const QString&getCC()const{ return cc; } | 53 | const QString&getCC()const{ return cc; } |
54 | void setCC( const QString&s ) { cc = s; } | 54 | void setCC( const QString&s ) { cc = s; } |
55 | const QString&getBCC()const { return bcc; } | 55 | const QString&getBCC()const { return bcc; } |
56 | void setBCC( const QString&s ) { bcc = s; } | 56 | void setBCC( const QString&s ) { bcc = s; } |
57 | const QString&getMessage()const { return message; } | 57 | const QString&getMessage()const { return message; } |
58 | void setMessage( const QString&s ) { message = s; } | 58 | void setMessage( const QString&s ) { message = s; } |
59 | const QString&getSubject()const { return subject; } | 59 | const QString&getSubject()const { return subject; } |
60 | void setSubject( const QString&s ) { subject = s; } | 60 | void setSubject( const QString&s ) { subject = s; } |
61 | const QString&getReply()const{ return reply; } | 61 | const QString&getReply()const{ return reply; } |
62 | void setReply( const QString&a ) { reply = a; } | 62 | void setReply( const QString&a ) { reply = a; } |
63 | 63 | ||
64 | private: | 64 | private: |
65 | QList<Attachment> attList; | 65 | QList<Attachment> attList; |
66 | QString name, mail, to, cc, bcc, reply, subject, message; | 66 | QString name, mail, to, cc, bcc, reply, subject, message; |
67 | }; | 67 | }; |
68 | 68 | ||
69 | class Folder : public QObject | 69 | class Folder : public QObject |
70 | { | 70 | { |
71 | Q_OBJECT | 71 | Q_OBJECT |
72 | 72 | ||
73 | public: | 73 | public: |
74 | Folder( const QString&init_name ); | 74 | Folder( const QString&init_name ); |
75 | const QString&getDisplayName()const { return nameDisplay; } | 75 | const QString&getDisplayName()const { return nameDisplay; } |
76 | const QString&getName()const { return name; } | 76 | const QString&getName()const { return name; } |
77 | virtual bool may_select()const{return true;}; | 77 | virtual bool may_select()const{return true;}; |
78 | 78 | ||
79 | private: | 79 | protected: |
80 | QString nameDisplay, name; | 80 | QString nameDisplay, name; |
81 | 81 | ||
82 | }; | 82 | }; |
83 | 83 | ||
84 | class IMAPFolder : public Folder | 84 | class IMAPFolder : public Folder |
85 | { | 85 | { |
86 | public: | 86 | public: |
87 | IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} | 87 | IMAPFolder(const QString&name,bool select=true,const QString&prefix="" ); |
88 | virtual bool may_select()const{return m_MaySelect;} | 88 | virtual bool may_select()const{return m_MaySelect;} |
89 | private: | 89 | private: |
90 | bool m_MaySelect; | 90 | bool m_MaySelect; |
91 | }; | 91 | }; |
92 | 92 | ||
93 | class MailWrapper : public QObject | 93 | class MailWrapper : public QObject |
94 | { | 94 | { |
95 | Q_OBJECT | 95 | Q_OBJECT |
96 | 96 | ||
97 | public: | 97 | public: |
98 | MailWrapper( Settings *s ); | 98 | MailWrapper( Settings *s ); |
99 | void sendMail( Mail mail ); | 99 | void sendMail( Mail mail ); |
100 | 100 | ||
101 | private: | 101 | private: |
102 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | 102 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); |
103 | mailimf_address_list *parseAddresses(const QString&addr ); | 103 | mailimf_address_list *parseAddresses(const QString&addr ); |
104 | mailimf_fields *createImfFields( Mail *mail ); | 104 | mailimf_fields *createImfFields( Mail *mail ); |
105 | mailmime *buildTxtPart( QString str ); | 105 | mailmime *buildTxtPart( QString str ); |
106 | mailmime *buildFilePart( QString filename, QString mimetype ); | 106 | mailmime *buildFilePart( QString filename, QString mimetype ); |
107 | void addFileParts( mailmime *message, QList<Attachment> files ); | 107 | void addFileParts( mailmime *message, QList<Attachment> files ); |
108 | mailmime *createMimeMail( Mail *mail ); | 108 | mailmime *createMimeMail( Mail *mail ); |
109 | void smtpSend( mailmime *mail ); | 109 | void smtpSend( mailmime *mail ); |
110 | mailimf_field *getField( mailimf_fields *fields, int type ); | 110 | mailimf_field *getField( mailimf_fields *fields, int type ); |
111 | clist *createRcptList( mailimf_fields *fields ); | 111 | clist *createRcptList( mailimf_fields *fields ); |
112 | char *getFrom( mailmime *mail ); | 112 | char *getFrom( mailmime *mail ); |
113 | SMTPaccount *getAccount( QString from ); | 113 | SMTPaccount *getAccount( QString from ); |
114 | void writeToFile( QString file, mailmime *mail ); | 114 | void writeToFile( QString file, mailmime *mail ); |
115 | void readFromFile( QString file, char **data, size_t *size ); | 115 | void readFromFile( QString file, char **data, size_t *size ); |
116 | static QString mailsmtpError( int err ); | 116 | static QString mailsmtpError( int err ); |
117 | static QString getTmpFile(); | 117 | static QString getTmpFile(); |
118 | 118 | ||
119 | Settings *settings; | 119 | Settings *settings; |
120 | 120 | ||
121 | }; | 121 | }; |
122 | 122 | ||
123 | #endif | 123 | #endif |