-rw-r--r-- | noncore/net/mail/ProgrammersDoc/ReceivingMails.dia | bin | 3031 -> 3086 bytes | |||
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 170 | ||||
-rw-r--r-- | noncore/net/mail/imapwrapper.h | 6 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 170 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.h | 6 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailtypes.cpp | 33 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailtypes.h | 10 | ||||
-rw-r--r-- | noncore/net/mail/mailtypes.cpp | 33 | ||||
-rw-r--r-- | noncore/net/mail/mailtypes.h | 10 |
9 files changed, 228 insertions, 210 deletions
diff --git a/noncore/net/mail/ProgrammersDoc/ReceivingMails.dia b/noncore/net/mail/ProgrammersDoc/ReceivingMails.dia index dcef8c8..08c6434 100644 --- a/noncore/net/mail/ProgrammersDoc/ReceivingMails.dia +++ b/noncore/net/mail/ProgrammersDoc/ReceivingMails.dia | |||
Binary files differ | |||
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index 725dcc9..5ce140e 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -28,467 +28,441 @@ void IMAPwrapper::login() | |||
28 | uint16_t port; | 28 | uint16_t port; |
29 | int err = MAILIMAP_NO_ERROR; | 29 | int err = MAILIMAP_NO_ERROR; |
30 | 30 | ||
31 | server = account->getServer().latin1(); | 31 | server = account->getServer().latin1(); |
32 | port = account->getPort().toUInt(); | 32 | port = account->getPort().toUInt(); |
33 | user = account->getUser().latin1(); | 33 | user = account->getUser().latin1(); |
34 | pass = account->getPassword().latin1(); | 34 | pass = account->getPassword().latin1(); |
35 | 35 | ||
36 | m_imap = mailimap_new( 20, &imap_progress ); | 36 | m_imap = mailimap_new( 20, &imap_progress ); |
37 | /* connect */ | 37 | /* connect */ |
38 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 38 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
39 | if ( err != MAILIMAP_NO_ERROR && | 39 | if ( err != MAILIMAP_NO_ERROR && |
40 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 40 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
41 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 41 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
42 | qDebug("error connecting server: %s",m_imap->response); | 42 | qDebug("error connecting server: %s",m_imap->response); |
43 | mailimap_free( m_imap ); | 43 | mailimap_free( m_imap ); |
44 | m_imap = 0; | 44 | m_imap = 0; |
45 | return; | 45 | return; |
46 | } | 46 | } |
47 | 47 | ||
48 | /* login */ | 48 | /* login */ |
49 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 49 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
50 | if ( err != MAILIMAP_NO_ERROR ) { | 50 | if ( err != MAILIMAP_NO_ERROR ) { |
51 | qDebug("error logging in imap: %s",m_imap->response); | 51 | qDebug("error logging in imap: %s",m_imap->response); |
52 | err = mailimap_close( m_imap ); | 52 | err = mailimap_close( m_imap ); |
53 | mailimap_free( m_imap ); | 53 | mailimap_free( m_imap ); |
54 | m_imap = 0; | 54 | m_imap = 0; |
55 | } | 55 | } |
56 | } | 56 | } |
57 | 57 | ||
58 | void IMAPwrapper::logout() | 58 | void IMAPwrapper::logout() |
59 | { | 59 | { |
60 | int err = MAILIMAP_NO_ERROR; | 60 | int err = MAILIMAP_NO_ERROR; |
61 | if (!m_imap) return; | 61 | if (!m_imap) return; |
62 | err = mailimap_logout( m_imap ); | 62 | err = mailimap_logout( m_imap ); |
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 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 68 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
69 | { | 69 | { |
70 | const char *mb; | 70 | const char *mb; |
71 | int err = MAILIMAP_NO_ERROR; | 71 | int err = MAILIMAP_NO_ERROR; |
72 | clist *result; | 72 | clist *result; |
73 | clistcell *current; | 73 | clistcell *current; |
74 | mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; | 74 | mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; |
75 | mailimap_fetch_type *fetchType; | 75 | mailimap_fetch_type *fetchType; |
76 | mailimap_set *set; | 76 | mailimap_set *set; |
77 | 77 | ||
78 | mb = mailbox.latin1(); | 78 | mb = mailbox.latin1(); |
79 | login(); | 79 | login(); |
80 | if (!m_imap) { | 80 | if (!m_imap) { |
81 | return; | 81 | return; |
82 | } | 82 | } |
83 | /* select mailbox READONLY for operations */ | 83 | /* select mailbox READONLY for operations */ |
84 | err = mailimap_examine( m_imap, (char*)mb); | 84 | err = mailimap_examine( m_imap, (char*)mb); |
85 | if ( err != MAILIMAP_NO_ERROR ) { | 85 | if ( err != MAILIMAP_NO_ERROR ) { |
86 | qDebug("error selecting mailbox: %s",m_imap->response); | 86 | qDebug("error selecting mailbox: %s",m_imap->response); |
87 | logout(); | 87 | logout(); |
88 | return; | 88 | return; |
89 | } | 89 | } |
90 | 90 | ||
91 | int last = m_imap->selection_info->exists; | 91 | int last = m_imap->selection_info->exists; |
92 | 92 | ||
93 | if (last == 0) { | 93 | if (last == 0) { |
94 | qDebug("mailbox has no mails"); | 94 | qDebug("mailbox has no mails"); |
95 | logout(); | 95 | logout(); |
96 | return; | 96 | return; |
97 | } | 97 | } |
98 | 98 | ||
99 | result = clist_new(); | 99 | result = clist_new(); |
100 | /* the range has to start at 1!!! not with 0!!!! */ | 100 | /* the range has to start at 1!!! not with 0!!!! */ |
101 | set = mailimap_set_new_interval( 1, last ); | 101 | set = mailimap_set_new_interval( 1, last ); |
102 | fetchAtt = mailimap_fetch_att_new_envelope(); | 102 | fetchAtt = mailimap_fetch_att_new_envelope(); |
103 | fetchAttFlags = mailimap_fetch_att_new_flags(); | 103 | fetchAttFlags = mailimap_fetch_att_new_flags(); |
104 | fetchAttDate = mailimap_fetch_att_new_internaldate(); | 104 | fetchAttDate = mailimap_fetch_att_new_internaldate(); |
105 | 105 | ||
106 | //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 106 | //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
107 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 107 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
108 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); | 108 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); |
109 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); | 109 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); |
110 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); | 110 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); |
111 | 111 | ||
112 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 112 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
113 | mailimap_set_free( set ); | 113 | mailimap_set_free( set ); |
114 | /* cleans up the fetch_att's too! */ | 114 | /* cleans up the fetch_att's too! */ |
115 | mailimap_fetch_type_free( fetchType ); | 115 | mailimap_fetch_type_free( fetchType ); |
116 | 116 | ||
117 | QString date,subject,from; | 117 | QString date,subject,from; |
118 | 118 | ||
119 | if ( err == MAILIMAP_NO_ERROR ) { | 119 | if ( err == MAILIMAP_NO_ERROR ) { |
120 | current = clist_begin(result); | 120 | current = clist_begin(result); |
121 | mailimap_msg_att * msg_att; | 121 | mailimap_msg_att * msg_att; |
122 | int i = 0; | 122 | int i = 0; |
123 | while ( current != 0 ) { | 123 | while ( current != 0 ) { |
124 | ++i; | 124 | ++i; |
125 | msg_att = (mailimap_msg_att*)current->data; | 125 | msg_att = (mailimap_msg_att*)current->data; |
126 | RecMail*m = parse_list_result(msg_att); | 126 | RecMail*m = parse_list_result(msg_att); |
127 | if (m) { | 127 | if (m) { |
128 | m->setNumber(i); | 128 | m->setNumber(i); |
129 | m->setMbox(mailbox); | 129 | m->setMbox(mailbox); |
130 | target.append(m); | 130 | target.append(m); |
131 | } | 131 | } |
132 | current = current->next; | 132 | current = current->next; |
133 | } | 133 | } |
134 | } else { | 134 | } else { |
135 | qDebug("Error fetching headers: %s",m_imap->response); | 135 | qDebug("Error fetching headers: %s",m_imap->response); |
136 | } | 136 | } |
137 | logout(); | 137 | logout(); |
138 | clist_free(result); | 138 | clist_free(result); |
139 | } | 139 | } |
140 | 140 | ||
141 | QList<IMAPFolder>* IMAPwrapper::listFolders() | 141 | QList<IMAPFolder>* IMAPwrapper::listFolders() |
142 | { | 142 | { |
143 | const char *path, *mask; | 143 | const char *path, *mask; |
144 | int err = MAILIMAP_NO_ERROR; | 144 | int err = MAILIMAP_NO_ERROR; |
145 | clist *result; | 145 | clist *result; |
146 | clistcell *current; | 146 | clistcell *current; |
147 | 147 | ||
148 | QList<IMAPFolder> * folders = new QList<IMAPFolder>(); | 148 | QList<IMAPFolder> * folders = new QList<IMAPFolder>(); |
149 | folders->setAutoDelete( true ); | 149 | folders->setAutoDelete( true ); |
150 | login(); | 150 | login(); |
151 | if (!m_imap) { | 151 | if (!m_imap) { |
152 | return folders; | 152 | return folders; |
153 | } | 153 | } |
154 | 154 | ||
155 | /* | 155 | /* |
156 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 156 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
157 | * We must not forget to filter them out in next loop! | 157 | * We must not forget to filter them out in next loop! |
158 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 158 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
159 | */ | 159 | */ |
160 | QString temp; | 160 | QString temp; |
161 | mask = "INBOX" ; | 161 | mask = "INBOX" ; |
162 | result = clist_new(); | 162 | result = clist_new(); |
163 | mailimap_mailbox_list *list; | 163 | mailimap_mailbox_list *list; |
164 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 164 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
165 | if ( err == MAILIMAP_NO_ERROR ) { | 165 | if ( err == MAILIMAP_NO_ERROR ) { |
166 | current = result->first; | 166 | current = result->first; |
167 | for ( int i = result->count; i > 0; i-- ) { | 167 | for ( int i = result->count; i > 0; i-- ) { |
168 | list = (mailimap_mailbox_list *) current->data; | 168 | list = (mailimap_mailbox_list *) current->data; |
169 | // it is better use the deep copy mechanism of qt itself | 169 | // it is better use the deep copy mechanism of qt itself |
170 | // instead of using strdup! | 170 | // instead of using strdup! |
171 | temp = list->mb; | 171 | temp = list->mb; |
172 | folders->append( new IMAPFolder(temp)); | 172 | folders->append( new IMAPFolder(temp)); |
173 | current = current->next; | 173 | current = current->next; |
174 | } | 174 | } |
175 | } else { | 175 | } else { |
176 | qDebug("error fetching folders: %s",m_imap->response); | 176 | qDebug("error fetching folders: %s",m_imap->response); |
177 | } | 177 | } |
178 | mailimap_list_result_free( result ); | 178 | mailimap_list_result_free( result ); |
179 | 179 | ||
180 | /* | 180 | /* |
181 | * second stage - get the other then inbox folders | 181 | * second stage - get the other then inbox folders |
182 | */ | 182 | */ |
183 | mask = "*" ; | 183 | mask = "*" ; |
184 | path = account->getPrefix().latin1(); | 184 | path = account->getPrefix().latin1(); |
185 | result = clist_new(); | 185 | result = clist_new(); |
186 | qDebug(path); | 186 | qDebug(path); |
187 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 187 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
188 | if ( err == MAILIMAP_NO_ERROR ) { | 188 | if ( err == MAILIMAP_NO_ERROR ) { |
189 | current = result->first; | 189 | current = result->first; |
190 | for ( int i = result->count; i > 0; i-- ) { | 190 | for ( int i = result->count; i > 0; i-- ) { |
191 | list = (mailimap_mailbox_list *) current->data; | 191 | list = (mailimap_mailbox_list *) current->data; |
192 | // it is better use the deep copy mechanism of qt itself | 192 | // it is better use the deep copy mechanism of qt itself |
193 | // instead of using strdup! | 193 | // instead of using strdup! |
194 | temp = list->mb; | 194 | temp = list->mb; |
195 | current = current->next; | 195 | current = current->next; |
196 | if (temp.lower()=="inbox") | 196 | if (temp.lower()=="inbox") |
197 | continue; | 197 | continue; |
198 | folders->append(new IMAPFolder(temp)); | 198 | folders->append(new IMAPFolder(temp)); |
199 | 199 | ||
200 | } | 200 | } |
201 | } else { | 201 | } else { |
202 | qDebug("error fetching folders %s",m_imap->response); | 202 | qDebug("error fetching folders %s",m_imap->response); |
203 | } | 203 | } |
204 | mailimap_list_result_free( result ); | 204 | mailimap_list_result_free( result ); |
205 | return folders; | 205 | return folders; |
206 | } | 206 | } |
207 | 207 | ||
208 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 208 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
209 | { | 209 | { |
210 | RecMail * m = 0; | 210 | RecMail * m = 0; |
211 | mailimap_msg_att_item *item=0; | 211 | mailimap_msg_att_item *item=0; |
212 | bool named_from = false; | 212 | bool named_from = false; |
213 | QString from,date,subject; | 213 | QString from,date,subject; |
214 | date = from = subject = ""; | 214 | date = from = subject = ""; |
215 | clistcell *current,*c,*cf, *current_from = NULL; | 215 | clistcell *current,*c,*cf, *current_from = NULL; |
216 | mailimap_address * current_address = NULL; | 216 | mailimap_address * current_address = NULL; |
217 | mailimap_msg_att_dynamic*flist; | 217 | mailimap_msg_att_dynamic*flist; |
218 | mailimap_flag_fetch*cflag; | 218 | mailimap_flag_fetch*cflag; |
219 | QBitArray mFlags(7); | 219 | QBitArray mFlags(7); |
220 | QStringList addresslist; | ||
220 | 221 | ||
221 | if (!m_att) { | 222 | if (!m_att) { |
222 | return m; | 223 | return m; |
223 | } | 224 | } |
224 | 225 | ||
225 | #if 0 | ||
226 | MAILIMAP_FLAG_KEYWORD, /* keyword flag */ | ||
227 | MAILIMAP_FLAG_EXTENSION, /* \extension flag */ | ||
228 | #endif | ||
229 | c = clist_begin(m_att->list); | 226 | c = clist_begin(m_att->list); |
230 | while ( c ) { | 227 | while ( c ) { |
231 | current = c; | 228 | current = c; |
232 | c = c->next; | 229 | c = c->next; |
233 | item = (mailimap_msg_att_item*)current->data; | 230 | item = (mailimap_msg_att_item*)current->data; |
234 | if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 231 | if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
235 | flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; | 232 | flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; |
236 | if (!flist->list) { | 233 | if (!flist->list) { |
237 | continue; | 234 | continue; |
238 | } | 235 | } |
239 | cf = flist->list->first; | 236 | cf = flist->list->first; |
240 | while (cf) { | 237 | while (cf) { |
241 | cflag = (mailimap_flag_fetch*)cf->data; | 238 | cflag = (mailimap_flag_fetch*)cf->data; |
242 | if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { | 239 | if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { |
243 | switch (cflag->flag->type) { | 240 | switch (cflag->flag->type) { |
244 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 241 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
245 | mFlags.setBit(FLAG_ANSWERED); | 242 | mFlags.setBit(FLAG_ANSWERED); |
246 | break; | 243 | break; |
247 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 244 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
248 | mFlags.setBit(FLAG_FLAGGED); | 245 | mFlags.setBit(FLAG_FLAGGED); |
249 | break; | 246 | break; |
250 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 247 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
251 | mFlags.setBit(FLAG_DELETED); | 248 | mFlags.setBit(FLAG_DELETED); |
252 | break; | 249 | break; |
253 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 250 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
254 | mFlags.setBit(FLAG_SEEN); | 251 | mFlags.setBit(FLAG_SEEN); |
255 | break; | 252 | break; |
256 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 253 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
257 | mFlags.setBit(FLAG_DRAFT); | 254 | mFlags.setBit(FLAG_DRAFT); |
258 | break; | 255 | break; |
259 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 256 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
260 | break; | 257 | break; |
261 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 258 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
262 | break; | 259 | break; |
263 | default: | 260 | default: |
264 | break; | 261 | break; |
265 | } | 262 | } |
266 | } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { | 263 | } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { |
267 | mFlags.setBit(FLAG_RECENT); | 264 | mFlags.setBit(FLAG_RECENT); |
268 | } | 265 | } |
269 | cf = cf->next; | 266 | cf = cf->next; |
270 | } | 267 | } |
271 | continue; | 268 | continue; |
272 | } | 269 | } |
273 | if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { | 270 | if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { |
274 | qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); | 271 | qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); |
275 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { | 272 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { |
276 | mailimap_envelope * head = item->msg_att_static->env; | 273 | mailimap_envelope * head = item->msg_att_static->env; |
277 | date = head->date; | 274 | date = head->date; |
278 | subject = head->subject; | 275 | subject = head->subject; |
279 | if (head->from!=NULL) | 276 | m = new RecMail(); |
280 | current_from = head->from->list->first; | 277 | if (head->from!=NULL) { |
281 | while (current_from != NULL) { | 278 | addresslist = address_list_to_stringlist(head->from->list); |
282 | from = ""; | 279 | if (addresslist.count()) { |
283 | named_from = false; | 280 | from = addresslist.first(); |
284 | current_address=(mailimap_address*)current_from->data; | ||
285 | current_from = current_from->next; | ||
286 | if (current_address->personal_name){ | ||
287 | from+=QString(current_address->personal_name); | ||
288 | from+=" "; | ||
289 | named_from = true; | ||
290 | } | ||
291 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | ||
292 | from+="<"; | ||
293 | } | ||
294 | if (current_address->mailbox_name) { | ||
295 | from+=QString(current_address->mailbox_name); | ||
296 | from+="@"; | ||
297 | } | ||
298 | if (current_address->host_name) { | ||
299 | from+=QString(current_address->host_name); | ||
300 | } | ||
301 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | ||
302 | from+=">"; | ||
303 | } | 281 | } |
304 | } | 282 | } |
305 | qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s", | 283 | if (head->to!=NULL) { |
306 | from.latin1(), | 284 | addresslist = address_list_to_stringlist(head->to->list); |
307 | subject.latin1(),date.latin1()); | 285 | m->setTo(addresslist); |
308 | m = new RecMail(); | 286 | } |
287 | if (head->cc!=NULL) { | ||
288 | addresslist = address_list_to_stringlist(head->cc->list); | ||
289 | m->setCC(addresslist); | ||
290 | } | ||
291 | if (head->bcc!=NULL) { | ||
292 | addresslist = address_list_to_stringlist(head->bcc->list); | ||
293 | m->setBcc(addresslist); | ||
294 | } | ||
309 | m->setSubject(subject); | 295 | m->setSubject(subject); |
310 | m->setFrom(from); | 296 | m->setFrom(from); |
311 | m->setDate(date); | 297 | m->setDate(date); |
298 | m->setMsgid(QString(head->message_id)); | ||
299 | qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s\nMsgid: %s", | ||
300 | from.latin1(), | ||
301 | subject.latin1(),date.latin1(),m->Msgid().latin1()); | ||
312 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 302 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
313 | mailimap_date_time*d = item->msg_att_static->internal_date; | 303 | mailimap_date_time*d = item->msg_att_static->internal_date; |
314 | QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); | 304 | QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); |
315 | qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec); | 305 | qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec); |
316 | qDebug(da.toString()); | 306 | qDebug(da.toString()); |
317 | } else { | 307 | } else { |
318 | qDebug("Another type"); | 308 | qDebug("Another type"); |
319 | } | 309 | } |
320 | } | 310 | } |
321 | /* msg is already deleted */ | 311 | /* msg is already deleted */ |
322 | if (mFlags.testBit(FLAG_DELETED) && m) { | 312 | if (mFlags.testBit(FLAG_DELETED) && m) { |
323 | delete m; | 313 | delete m; |
324 | m = 0; | 314 | m = 0; |
325 | } | 315 | } |
326 | if (m) { | 316 | if (m) { |
327 | m->setFlags(mFlags); | 317 | m->setFlags(mFlags); |
328 | } | 318 | } |
329 | return m; | 319 | return m; |
330 | } | 320 | } |
331 | 321 | ||
332 | #if 1 | ||
333 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 322 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
334 | { | 323 | { |
335 | RecBody body; | 324 | RecBody body; |
336 | QString body_text; | ||
337 | |||
338 | const char *mb; | ||
339 | int err = MAILIMAP_NO_ERROR; | ||
340 | clist *result; | ||
341 | clistcell *current; | ||
342 | mailimap_fetch_att *fetchAtt; | ||
343 | mailimap_fetch_type *fetchType; | ||
344 | mailimap_set *set; | ||
345 | |||
346 | mb = mail.getMbox().latin1(); | ||
347 | |||
348 | login(); | ||
349 | if (!m_imap) { | ||
350 | return body; | ||
351 | } | ||
352 | /* select mailbox READONLY for operations */ | ||
353 | err = mailimap_examine( m_imap, (char*)mb); | ||
354 | if ( err != MAILIMAP_NO_ERROR ) { | ||
355 | qDebug("error selecting mailbox: %s",m_imap->response); | ||
356 | logout(); | ||
357 | return body; | ||
358 | } | ||
359 | result = clist_new(); | ||
360 | /* the range has to start at 1!!! not with 0!!!! */ | ||
361 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | ||
362 | fetchAtt = mailimap_fetch_att_new_rfc822_text(); | ||
363 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | ||
364 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | ||
365 | mailimap_set_free( set ); | ||
366 | mailimap_fetch_type_free( fetchType ); | ||
367 | |||
368 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | ||
369 | mailimap_msg_att * msg_att; | ||
370 | msg_att = (mailimap_msg_att*)current->data; | ||
371 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; | ||
372 | |||
373 | if (item->msg_att_static && item->msg_att_static->rfc822_text) { | ||
374 | body_text = item->msg_att_static->rfc822_text; | ||
375 | body.setBodytext(body_text); | ||
376 | } | ||
377 | } else { | ||
378 | qDebug("error fetching text: %s",m_imap->response); | ||
379 | } | ||
380 | |||
381 | clist_free(result); | ||
382 | logout(); | ||
383 | return body; | ||
384 | } | ||
385 | |||
386 | #else | ||
387 | QString IMAPwrapper::fetchBody(const RecMail&mail) | ||
388 | { | ||
389 | QString body = ""; | ||
390 | const char *mb; | 325 | const char *mb; |
391 | int err = MAILIMAP_NO_ERROR; | 326 | int err = MAILIMAP_NO_ERROR; |
392 | clist *result; | 327 | clist *result; |
393 | clistcell *current; | 328 | clistcell *current; |
394 | mailimap_fetch_att *fetchAtt; | 329 | mailimap_fetch_att *fetchAtt; |
395 | mailimap_fetch_type *fetchType; | 330 | mailimap_fetch_type *fetchType; |
396 | mailimap_set *set; | 331 | mailimap_set *set; |
397 | mailimap_body*body_desc; | 332 | mailimap_body*body_desc; |
398 | 333 | ||
399 | mb = mail.getMbox().latin1(); | 334 | mb = mail.getMbox().latin1(); |
400 | 335 | ||
401 | login(); | 336 | login(); |
402 | if (!m_imap) { | 337 | if (!m_imap) { |
403 | return body; | 338 | return body; |
404 | } | 339 | } |
405 | /* select mailbox READONLY for operations */ | 340 | /* select mailbox READONLY for operations */ |
406 | err = mailimap_examine( m_imap, (char*)mb); | 341 | err = mailimap_examine( m_imap, (char*)mb); |
407 | if ( err != MAILIMAP_NO_ERROR ) { | 342 | if ( err != MAILIMAP_NO_ERROR ) { |
408 | qDebug("error selecting mailbox: %s",m_imap->response); | 343 | qDebug("error selecting mailbox: %s",m_imap->response); |
409 | logout(); | 344 | logout(); |
410 | return body; | 345 | return body; |
411 | } | 346 | } |
412 | result = clist_new(); | 347 | result = clist_new(); |
413 | /* the range has to start at 1!!! not with 0!!!! */ | 348 | /* the range has to start at 1!!! not with 0!!!! */ |
414 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 349 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
415 | fetchAtt = mailimap_fetch_att_new_body(); | 350 | fetchAtt = mailimap_fetch_att_new_body(); |
416 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 351 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
417 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 352 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
418 | mailimap_set_free( set ); | 353 | mailimap_set_free( set ); |
419 | mailimap_fetch_type_free( fetchType ); | 354 | mailimap_fetch_type_free( fetchType ); |
420 | 355 | ||
421 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 356 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
422 | mailimap_msg_att * msg_att; | 357 | mailimap_msg_att * msg_att; |
423 | msg_att = (mailimap_msg_att*)current->data; | 358 | msg_att = (mailimap_msg_att*)current->data; |
424 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; | 359 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; |
425 | body_desc = item->msg_att_static->body; | 360 | body_desc = item->msg_att_static->body; |
426 | if (body_desc->type==MAILIMAP_BODY_1PART) { | 361 | if (body_desc->type==MAILIMAP_BODY_1PART) { |
427 | body = searchBodyText(mail,body_desc->body_1part); | 362 | searchBodyText(mail,body_desc->body_1part,body); |
428 | } else { | 363 | } else { |
429 | } | 364 | } |
430 | 365 | ||
431 | } else { | 366 | } else { |
432 | qDebug("error fetching body: %s",m_imap->response); | 367 | qDebug("error fetching body: %s",m_imap->response); |
433 | } | 368 | } |
434 | 369 | ||
435 | clist_free(result); | 370 | clist_free(result); |
436 | logout(); | 371 | logout(); |
437 | return body; | 372 | return body; |
438 | } | 373 | } |
439 | #endif | ||
440 | 374 | ||
441 | QString IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription) | 375 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
442 | { | 376 | { |
443 | QString Body=""; | ||
444 | if (!mailDescription) { | 377 | if (!mailDescription) { |
445 | return Body; | 378 | return; |
446 | } | 379 | } |
447 | switch (mailDescription->type) { | 380 | switch (mailDescription->type) { |
448 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 381 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
449 | return getPlainBody(mail); | 382 | fillPlainBody(mail,target_body,mailDescription->body_type_text); |
450 | break; | 383 | break; |
451 | default: | 384 | default: |
452 | break; | 385 | break; |
453 | } | 386 | } |
454 | return Body; | 387 | return; |
455 | } | 388 | } |
456 | 389 | ||
457 | QString IMAPwrapper::getPlainBody(const RecMail&mail) | 390 | void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body) |
458 | { | 391 | { |
459 | QString body = ""; | ||
460 | const char *mb; | 392 | const char *mb; |
393 | QString body=""; | ||
461 | int err = MAILIMAP_NO_ERROR; | 394 | int err = MAILIMAP_NO_ERROR; |
462 | clist *result; | 395 | clist *result; |
463 | clistcell *current; | 396 | clistcell *current; |
464 | mailimap_fetch_att *fetchAtt; | 397 | mailimap_fetch_att *fetchAtt; |
465 | mailimap_fetch_type *fetchType; | 398 | mailimap_fetch_type *fetchType; |
466 | mailimap_set *set; | 399 | mailimap_set *set; |
467 | 400 | ||
468 | mb = mail.getMbox().latin1(); | 401 | mb = mail.getMbox().latin1(); |
469 | 402 | ||
470 | if (!m_imap) { | 403 | if (!m_imap) { |
471 | return body; | 404 | return; |
472 | } | 405 | } |
406 | |||
473 | result = clist_new(); | 407 | result = clist_new(); |
474 | /* the range has to start at 1!!! not with 0!!!! */ | 408 | /* the range has to start at 1!!! not with 0!!!! */ |
475 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 409 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
476 | fetchAtt = mailimap_fetch_att_new_rfc822_text(); | 410 | fetchAtt = mailimap_fetch_att_new_rfc822_text(); |
477 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 411 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
478 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 412 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
479 | mailimap_set_free( set ); | 413 | mailimap_set_free( set ); |
480 | mailimap_fetch_type_free( fetchType ); | 414 | mailimap_fetch_type_free( fetchType ); |
481 | 415 | ||
482 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 416 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
483 | mailimap_msg_att * msg_att; | 417 | mailimap_msg_att * msg_att; |
484 | msg_att = (mailimap_msg_att*)current->data; | 418 | msg_att = (mailimap_msg_att*)current->data; |
485 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; | 419 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; |
486 | if (item->msg_att_static && item->msg_att_static->rfc822_text) { | 420 | if (item->msg_att_static && item->msg_att_static->rfc822_text) { |
487 | body = item->msg_att_static->rfc822_text; | 421 | body = item->msg_att_static->rfc822_text; |
488 | } | 422 | } |
489 | } else { | 423 | } else { |
490 | qDebug("error fetching text: %s",m_imap->response); | 424 | qDebug("error fetching text: %s",m_imap->response); |
491 | } | 425 | } |
492 | clist_free(result); | 426 | clist_free(result); |
493 | return body; | 427 | target_body.setBodytext(body); |
428 | return; | ||
429 | } | ||
430 | |||
431 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | ||
432 | { | ||
433 | QStringList l; | ||
434 | QString from; | ||
435 | bool named_from; | ||
436 | clistcell *current = NULL; | ||
437 | mailimap_address * current_address=NULL; | ||
438 | if (!list) { | ||
439 | return l; | ||
440 | } | ||
441 | current = clist_begin(list); | ||
442 | while (current!= NULL) { | ||
443 | from = ""; | ||
444 | named_from = false; | ||
445 | current_address=(mailimap_address*)current->data; | ||
446 | current = current->next; | ||
447 | if (current_address->personal_name){ | ||
448 | from+=QString(current_address->personal_name); | ||
449 | from+=" "; | ||
450 | named_from = true; | ||
451 | } | ||
452 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | ||
453 | from+="<"; | ||
454 | } | ||
455 | if (current_address->mailbox_name) { | ||
456 | from+=QString(current_address->mailbox_name); | ||
457 | from+="@"; | ||
458 | } | ||
459 | if (current_address->host_name) { | ||
460 | from+=QString(current_address->host_name); | ||
461 | } | ||
462 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | ||
463 | from+=">"; | ||
464 | } | ||
465 | l.append(QString(from)); | ||
466 | } | ||
467 | return l; | ||
494 | } | 468 | } |
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h index 1423faf..6565896 100644 --- a/noncore/net/mail/imapwrapper.h +++ b/noncore/net/mail/imapwrapper.h | |||
@@ -1,36 +1,38 @@ | |||
1 | #ifndef __IMAPWRAPPER | 1 | #ifndef __IMAPWRAPPER |
2 | #define __IMAPWRAPPER | 2 | #define __IMAPWRAPPER |
3 | 3 | ||
4 | #include <qlist.h> | 4 | #include <qlist.h> |
5 | #include "mailwrapper.h" | 5 | #include "mailwrapper.h" |
6 | 6 | ||
7 | struct mailimap; | 7 | struct mailimap; |
8 | struct mailimap_body_type_1part; | 8 | struct mailimap_body_type_1part; |
9 | struct mailimap_body_type_text; | ||
9 | class RecMail; | 10 | class RecMail; |
10 | class RecBody; | 11 | class RecBody; |
11 | 12 | ||
12 | class IMAPwrapper : public QObject | 13 | class IMAPwrapper : public QObject |
13 | { | 14 | { |
14 | Q_OBJECT | 15 | Q_OBJECT |
15 | 16 | ||
16 | public: | 17 | public: |
17 | IMAPwrapper( IMAPaccount *a ); | 18 | IMAPwrapper( IMAPaccount *a ); |
18 | virtual ~IMAPwrapper(); | 19 | virtual ~IMAPwrapper(); |
19 | QList<IMAPFolder>* listFolders(); | 20 | QList<IMAPFolder>* listFolders(); |
20 | void listMessages(const QString & mailbox,QList<RecMail>&target ); | 21 | void listMessages(const QString & mailbox,QList<RecMail>&target ); |
21 | RecBody fetchBody(const RecMail&mail); | 22 | RecBody fetchBody(const RecMail&mail); |
22 | static void imap_progress( size_t current, size_t maximum ); | 23 | static void imap_progress( size_t current, size_t maximum ); |
23 | 24 | ||
24 | protected: | 25 | protected: |
25 | RecMail*parse_list_result(mailimap_msg_att*); | 26 | RecMail*parse_list_result(mailimap_msg_att*); |
26 | void login(); | 27 | void login(); |
27 | void logout(); | 28 | void logout(); |
28 | QString searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription); | 29 | void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); |
29 | QString getPlainBody(const RecMail&mail); | 30 | void fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body); |
31 | QStringList address_list_to_stringlist(clist*list); | ||
30 | 32 | ||
31 | private: | 33 | private: |
32 | IMAPaccount *account; | 34 | IMAPaccount *account; |
33 | mailimap *m_imap; | 35 | mailimap *m_imap; |
34 | }; | 36 | }; |
35 | 37 | ||
36 | #endif | 38 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 725dcc9..5ce140e 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -28,467 +28,441 @@ void IMAPwrapper::login() | |||
28 | uint16_t port; | 28 | uint16_t port; |
29 | int err = MAILIMAP_NO_ERROR; | 29 | int err = MAILIMAP_NO_ERROR; |
30 | 30 | ||
31 | server = account->getServer().latin1(); | 31 | server = account->getServer().latin1(); |
32 | port = account->getPort().toUInt(); | 32 | port = account->getPort().toUInt(); |
33 | user = account->getUser().latin1(); | 33 | user = account->getUser().latin1(); |
34 | pass = account->getPassword().latin1(); | 34 | pass = account->getPassword().latin1(); |
35 | 35 | ||
36 | m_imap = mailimap_new( 20, &imap_progress ); | 36 | m_imap = mailimap_new( 20, &imap_progress ); |
37 | /* connect */ | 37 | /* connect */ |
38 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 38 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
39 | if ( err != MAILIMAP_NO_ERROR && | 39 | if ( err != MAILIMAP_NO_ERROR && |
40 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 40 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
41 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 41 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
42 | qDebug("error connecting server: %s",m_imap->response); | 42 | qDebug("error connecting server: %s",m_imap->response); |
43 | mailimap_free( m_imap ); | 43 | mailimap_free( m_imap ); |
44 | m_imap = 0; | 44 | m_imap = 0; |
45 | return; | 45 | return; |
46 | } | 46 | } |
47 | 47 | ||
48 | /* login */ | 48 | /* login */ |
49 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 49 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
50 | if ( err != MAILIMAP_NO_ERROR ) { | 50 | if ( err != MAILIMAP_NO_ERROR ) { |
51 | qDebug("error logging in imap: %s",m_imap->response); | 51 | qDebug("error logging in imap: %s",m_imap->response); |
52 | err = mailimap_close( m_imap ); | 52 | err = mailimap_close( m_imap ); |
53 | mailimap_free( m_imap ); | 53 | mailimap_free( m_imap ); |
54 | m_imap = 0; | 54 | m_imap = 0; |
55 | } | 55 | } |
56 | } | 56 | } |
57 | 57 | ||
58 | void IMAPwrapper::logout() | 58 | void IMAPwrapper::logout() |
59 | { | 59 | { |
60 | int err = MAILIMAP_NO_ERROR; | 60 | int err = MAILIMAP_NO_ERROR; |
61 | if (!m_imap) return; | 61 | if (!m_imap) return; |
62 | err = mailimap_logout( m_imap ); | 62 | err = mailimap_logout( m_imap ); |
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 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 68 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
69 | { | 69 | { |
70 | const char *mb; | 70 | const char *mb; |
71 | int err = MAILIMAP_NO_ERROR; | 71 | int err = MAILIMAP_NO_ERROR; |
72 | clist *result; | 72 | clist *result; |
73 | clistcell *current; | 73 | clistcell *current; |
74 | mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; | 74 | mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; |
75 | mailimap_fetch_type *fetchType; | 75 | mailimap_fetch_type *fetchType; |
76 | mailimap_set *set; | 76 | mailimap_set *set; |
77 | 77 | ||
78 | mb = mailbox.latin1(); | 78 | mb = mailbox.latin1(); |
79 | login(); | 79 | login(); |
80 | if (!m_imap) { | 80 | if (!m_imap) { |
81 | return; | 81 | return; |
82 | } | 82 | } |
83 | /* select mailbox READONLY for operations */ | 83 | /* select mailbox READONLY for operations */ |
84 | err = mailimap_examine( m_imap, (char*)mb); | 84 | err = mailimap_examine( m_imap, (char*)mb); |
85 | if ( err != MAILIMAP_NO_ERROR ) { | 85 | if ( err != MAILIMAP_NO_ERROR ) { |
86 | qDebug("error selecting mailbox: %s",m_imap->response); | 86 | qDebug("error selecting mailbox: %s",m_imap->response); |
87 | logout(); | 87 | logout(); |
88 | return; | 88 | return; |
89 | } | 89 | } |
90 | 90 | ||
91 | int last = m_imap->selection_info->exists; | 91 | int last = m_imap->selection_info->exists; |
92 | 92 | ||
93 | if (last == 0) { | 93 | if (last == 0) { |
94 | qDebug("mailbox has no mails"); | 94 | qDebug("mailbox has no mails"); |
95 | logout(); | 95 | logout(); |
96 | return; | 96 | return; |
97 | } | 97 | } |
98 | 98 | ||
99 | result = clist_new(); | 99 | result = clist_new(); |
100 | /* the range has to start at 1!!! not with 0!!!! */ | 100 | /* the range has to start at 1!!! not with 0!!!! */ |
101 | set = mailimap_set_new_interval( 1, last ); | 101 | set = mailimap_set_new_interval( 1, last ); |
102 | fetchAtt = mailimap_fetch_att_new_envelope(); | 102 | fetchAtt = mailimap_fetch_att_new_envelope(); |
103 | fetchAttFlags = mailimap_fetch_att_new_flags(); | 103 | fetchAttFlags = mailimap_fetch_att_new_flags(); |
104 | fetchAttDate = mailimap_fetch_att_new_internaldate(); | 104 | fetchAttDate = mailimap_fetch_att_new_internaldate(); |
105 | 105 | ||
106 | //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 106 | //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
107 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 107 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
108 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); | 108 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); |
109 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); | 109 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); |
110 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); | 110 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); |
111 | 111 | ||
112 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 112 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
113 | mailimap_set_free( set ); | 113 | mailimap_set_free( set ); |
114 | /* cleans up the fetch_att's too! */ | 114 | /* cleans up the fetch_att's too! */ |
115 | mailimap_fetch_type_free( fetchType ); | 115 | mailimap_fetch_type_free( fetchType ); |
116 | 116 | ||
117 | QString date,subject,from; | 117 | QString date,subject,from; |
118 | 118 | ||
119 | if ( err == MAILIMAP_NO_ERROR ) { | 119 | if ( err == MAILIMAP_NO_ERROR ) { |
120 | current = clist_begin(result); | 120 | current = clist_begin(result); |
121 | mailimap_msg_att * msg_att; | 121 | mailimap_msg_att * msg_att; |
122 | int i = 0; | 122 | int i = 0; |
123 | while ( current != 0 ) { | 123 | while ( current != 0 ) { |
124 | ++i; | 124 | ++i; |
125 | msg_att = (mailimap_msg_att*)current->data; | 125 | msg_att = (mailimap_msg_att*)current->data; |
126 | RecMail*m = parse_list_result(msg_att); | 126 | RecMail*m = parse_list_result(msg_att); |
127 | if (m) { | 127 | if (m) { |
128 | m->setNumber(i); | 128 | m->setNumber(i); |
129 | m->setMbox(mailbox); | 129 | m->setMbox(mailbox); |
130 | target.append(m); | 130 | target.append(m); |
131 | } | 131 | } |
132 | current = current->next; | 132 | current = current->next; |
133 | } | 133 | } |
134 | } else { | 134 | } else { |
135 | qDebug("Error fetching headers: %s",m_imap->response); | 135 | qDebug("Error fetching headers: %s",m_imap->response); |
136 | } | 136 | } |
137 | logout(); | 137 | logout(); |
138 | clist_free(result); | 138 | clist_free(result); |
139 | } | 139 | } |
140 | 140 | ||
141 | QList<IMAPFolder>* IMAPwrapper::listFolders() | 141 | QList<IMAPFolder>* IMAPwrapper::listFolders() |
142 | { | 142 | { |
143 | const char *path, *mask; | 143 | const char *path, *mask; |
144 | int err = MAILIMAP_NO_ERROR; | 144 | int err = MAILIMAP_NO_ERROR; |
145 | clist *result; | 145 | clist *result; |
146 | clistcell *current; | 146 | clistcell *current; |
147 | 147 | ||
148 | QList<IMAPFolder> * folders = new QList<IMAPFolder>(); | 148 | QList<IMAPFolder> * folders = new QList<IMAPFolder>(); |
149 | folders->setAutoDelete( true ); | 149 | folders->setAutoDelete( true ); |
150 | login(); | 150 | login(); |
151 | if (!m_imap) { | 151 | if (!m_imap) { |
152 | return folders; | 152 | return folders; |
153 | } | 153 | } |
154 | 154 | ||
155 | /* | 155 | /* |
156 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 156 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
157 | * We must not forget to filter them out in next loop! | 157 | * We must not forget to filter them out in next loop! |
158 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 158 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
159 | */ | 159 | */ |
160 | QString temp; | 160 | QString temp; |
161 | mask = "INBOX" ; | 161 | mask = "INBOX" ; |
162 | result = clist_new(); | 162 | result = clist_new(); |
163 | mailimap_mailbox_list *list; | 163 | mailimap_mailbox_list *list; |
164 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 164 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
165 | if ( err == MAILIMAP_NO_ERROR ) { | 165 | if ( err == MAILIMAP_NO_ERROR ) { |
166 | current = result->first; | 166 | current = result->first; |
167 | for ( int i = result->count; i > 0; i-- ) { | 167 | for ( int i = result->count; i > 0; i-- ) { |
168 | list = (mailimap_mailbox_list *) current->data; | 168 | list = (mailimap_mailbox_list *) current->data; |
169 | // it is better use the deep copy mechanism of qt itself | 169 | // it is better use the deep copy mechanism of qt itself |
170 | // instead of using strdup! | 170 | // instead of using strdup! |
171 | temp = list->mb; | 171 | temp = list->mb; |
172 | folders->append( new IMAPFolder(temp)); | 172 | folders->append( new IMAPFolder(temp)); |
173 | current = current->next; | 173 | current = current->next; |
174 | } | 174 | } |
175 | } else { | 175 | } else { |
176 | qDebug("error fetching folders: %s",m_imap->response); | 176 | qDebug("error fetching folders: %s",m_imap->response); |
177 | } | 177 | } |
178 | mailimap_list_result_free( result ); | 178 | mailimap_list_result_free( result ); |
179 | 179 | ||
180 | /* | 180 | /* |
181 | * second stage - get the other then inbox folders | 181 | * second stage - get the other then inbox folders |
182 | */ | 182 | */ |
183 | mask = "*" ; | 183 | mask = "*" ; |
184 | path = account->getPrefix().latin1(); | 184 | path = account->getPrefix().latin1(); |
185 | result = clist_new(); | 185 | result = clist_new(); |
186 | qDebug(path); | 186 | qDebug(path); |
187 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 187 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
188 | if ( err == MAILIMAP_NO_ERROR ) { | 188 | if ( err == MAILIMAP_NO_ERROR ) { |
189 | current = result->first; | 189 | current = result->first; |
190 | for ( int i = result->count; i > 0; i-- ) { | 190 | for ( int i = result->count; i > 0; i-- ) { |
191 | list = (mailimap_mailbox_list *) current->data; | 191 | list = (mailimap_mailbox_list *) current->data; |
192 | // it is better use the deep copy mechanism of qt itself | 192 | // it is better use the deep copy mechanism of qt itself |
193 | // instead of using strdup! | 193 | // instead of using strdup! |
194 | temp = list->mb; | 194 | temp = list->mb; |
195 | current = current->next; | 195 | current = current->next; |
196 | if (temp.lower()=="inbox") | 196 | if (temp.lower()=="inbox") |
197 | continue; | 197 | continue; |
198 | folders->append(new IMAPFolder(temp)); | 198 | folders->append(new IMAPFolder(temp)); |
199 | 199 | ||
200 | } | 200 | } |
201 | } else { | 201 | } else { |
202 | qDebug("error fetching folders %s",m_imap->response); | 202 | qDebug("error fetching folders %s",m_imap->response); |
203 | } | 203 | } |
204 | mailimap_list_result_free( result ); | 204 | mailimap_list_result_free( result ); |
205 | return folders; | 205 | return folders; |
206 | } | 206 | } |
207 | 207 | ||
208 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 208 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
209 | { | 209 | { |
210 | RecMail * m = 0; | 210 | RecMail * m = 0; |
211 | mailimap_msg_att_item *item=0; | 211 | mailimap_msg_att_item *item=0; |
212 | bool named_from = false; | 212 | bool named_from = false; |
213 | QString from,date,subject; | 213 | QString from,date,subject; |
214 | date = from = subject = ""; | 214 | date = from = subject = ""; |
215 | clistcell *current,*c,*cf, *current_from = NULL; | 215 | clistcell *current,*c,*cf, *current_from = NULL; |
216 | mailimap_address * current_address = NULL; | 216 | mailimap_address * current_address = NULL; |
217 | mailimap_msg_att_dynamic*flist; | 217 | mailimap_msg_att_dynamic*flist; |
218 | mailimap_flag_fetch*cflag; | 218 | mailimap_flag_fetch*cflag; |
219 | QBitArray mFlags(7); | 219 | QBitArray mFlags(7); |
220 | QStringList addresslist; | ||
220 | 221 | ||
221 | if (!m_att) { | 222 | if (!m_att) { |
222 | return m; | 223 | return m; |
223 | } | 224 | } |
224 | 225 | ||
225 | #if 0 | ||
226 | MAILIMAP_FLAG_KEYWORD, /* keyword flag */ | ||
227 | MAILIMAP_FLAG_EXTENSION, /* \extension flag */ | ||
228 | #endif | ||
229 | c = clist_begin(m_att->list); | 226 | c = clist_begin(m_att->list); |
230 | while ( c ) { | 227 | while ( c ) { |
231 | current = c; | 228 | current = c; |
232 | c = c->next; | 229 | c = c->next; |
233 | item = (mailimap_msg_att_item*)current->data; | 230 | item = (mailimap_msg_att_item*)current->data; |
234 | if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 231 | if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
235 | flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; | 232 | flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; |
236 | if (!flist->list) { | 233 | if (!flist->list) { |
237 | continue; | 234 | continue; |
238 | } | 235 | } |
239 | cf = flist->list->first; | 236 | cf = flist->list->first; |
240 | while (cf) { | 237 | while (cf) { |
241 | cflag = (mailimap_flag_fetch*)cf->data; | 238 | cflag = (mailimap_flag_fetch*)cf->data; |
242 | if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { | 239 | if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { |
243 | switch (cflag->flag->type) { | 240 | switch (cflag->flag->type) { |
244 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 241 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
245 | mFlags.setBit(FLAG_ANSWERED); | 242 | mFlags.setBit(FLAG_ANSWERED); |
246 | break; | 243 | break; |
247 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 244 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
248 | mFlags.setBit(FLAG_FLAGGED); | 245 | mFlags.setBit(FLAG_FLAGGED); |
249 | break; | 246 | break; |
250 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 247 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
251 | mFlags.setBit(FLAG_DELETED); | 248 | mFlags.setBit(FLAG_DELETED); |
252 | break; | 249 | break; |
253 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 250 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
254 | mFlags.setBit(FLAG_SEEN); | 251 | mFlags.setBit(FLAG_SEEN); |
255 | break; | 252 | break; |
256 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 253 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
257 | mFlags.setBit(FLAG_DRAFT); | 254 | mFlags.setBit(FLAG_DRAFT); |
258 | break; | 255 | break; |
259 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 256 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
260 | break; | 257 | break; |
261 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 258 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
262 | break; | 259 | break; |
263 | default: | 260 | default: |
264 | break; | 261 | break; |
265 | } | 262 | } |
266 | } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { | 263 | } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { |
267 | mFlags.setBit(FLAG_RECENT); | 264 | mFlags.setBit(FLAG_RECENT); |
268 | } | 265 | } |
269 | cf = cf->next; | 266 | cf = cf->next; |
270 | } | 267 | } |
271 | continue; | 268 | continue; |
272 | } | 269 | } |
273 | if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { | 270 | if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { |
274 | qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); | 271 | qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); |
275 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { | 272 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { |
276 | mailimap_envelope * head = item->msg_att_static->env; | 273 | mailimap_envelope * head = item->msg_att_static->env; |
277 | date = head->date; | 274 | date = head->date; |
278 | subject = head->subject; | 275 | subject = head->subject; |
279 | if (head->from!=NULL) | 276 | m = new RecMail(); |
280 | current_from = head->from->list->first; | 277 | if (head->from!=NULL) { |
281 | while (current_from != NULL) { | 278 | addresslist = address_list_to_stringlist(head->from->list); |
282 | from = ""; | 279 | if (addresslist.count()) { |
283 | named_from = false; | 280 | from = addresslist.first(); |
284 | current_address=(mailimap_address*)current_from->data; | ||
285 | current_from = current_from->next; | ||
286 | if (current_address->personal_name){ | ||
287 | from+=QString(current_address->personal_name); | ||
288 | from+=" "; | ||
289 | named_from = true; | ||
290 | } | ||
291 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | ||
292 | from+="<"; | ||
293 | } | ||
294 | if (current_address->mailbox_name) { | ||
295 | from+=QString(current_address->mailbox_name); | ||
296 | from+="@"; | ||
297 | } | ||
298 | if (current_address->host_name) { | ||
299 | from+=QString(current_address->host_name); | ||
300 | } | ||
301 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | ||
302 | from+=">"; | ||
303 | } | 281 | } |
304 | } | 282 | } |
305 | qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s", | 283 | if (head->to!=NULL) { |
306 | from.latin1(), | 284 | addresslist = address_list_to_stringlist(head->to->list); |
307 | subject.latin1(),date.latin1()); | 285 | m->setTo(addresslist); |
308 | m = new RecMail(); | 286 | } |
287 | if (head->cc!=NULL) { | ||
288 | addresslist = address_list_to_stringlist(head->cc->list); | ||
289 | m->setCC(addresslist); | ||
290 | } | ||
291 | if (head->bcc!=NULL) { | ||
292 | addresslist = address_list_to_stringlist(head->bcc->list); | ||
293 | m->setBcc(addresslist); | ||
294 | } | ||
309 | m->setSubject(subject); | 295 | m->setSubject(subject); |
310 | m->setFrom(from); | 296 | m->setFrom(from); |
311 | m->setDate(date); | 297 | m->setDate(date); |
298 | m->setMsgid(QString(head->message_id)); | ||
299 | qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s\nMsgid: %s", | ||
300 | from.latin1(), | ||
301 | subject.latin1(),date.latin1(),m->Msgid().latin1()); | ||
312 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 302 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
313 | mailimap_date_time*d = item->msg_att_static->internal_date; | 303 | mailimap_date_time*d = item->msg_att_static->internal_date; |
314 | QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); | 304 | QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); |
315 | qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec); | 305 | qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec); |
316 | qDebug(da.toString()); | 306 | qDebug(da.toString()); |
317 | } else { | 307 | } else { |
318 | qDebug("Another type"); | 308 | qDebug("Another type"); |
319 | } | 309 | } |
320 | } | 310 | } |
321 | /* msg is already deleted */ | 311 | /* msg is already deleted */ |
322 | if (mFlags.testBit(FLAG_DELETED) && m) { | 312 | if (mFlags.testBit(FLAG_DELETED) && m) { |
323 | delete m; | 313 | delete m; |
324 | m = 0; | 314 | m = 0; |
325 | } | 315 | } |
326 | if (m) { | 316 | if (m) { |
327 | m->setFlags(mFlags); | 317 | m->setFlags(mFlags); |
328 | } | 318 | } |
329 | return m; | 319 | return m; |
330 | } | 320 | } |
331 | 321 | ||
332 | #if 1 | ||
333 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 322 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
334 | { | 323 | { |
335 | RecBody body; | 324 | RecBody body; |
336 | QString body_text; | ||
337 | |||
338 | const char *mb; | ||
339 | int err = MAILIMAP_NO_ERROR; | ||
340 | clist *result; | ||
341 | clistcell *current; | ||
342 | mailimap_fetch_att *fetchAtt; | ||
343 | mailimap_fetch_type *fetchType; | ||
344 | mailimap_set *set; | ||
345 | |||
346 | mb = mail.getMbox().latin1(); | ||
347 | |||
348 | login(); | ||
349 | if (!m_imap) { | ||
350 | return body; | ||
351 | } | ||
352 | /* select mailbox READONLY for operations */ | ||
353 | err = mailimap_examine( m_imap, (char*)mb); | ||
354 | if ( err != MAILIMAP_NO_ERROR ) { | ||
355 | qDebug("error selecting mailbox: %s",m_imap->response); | ||
356 | logout(); | ||
357 | return body; | ||
358 | } | ||
359 | result = clist_new(); | ||
360 | /* the range has to start at 1!!! not with 0!!!! */ | ||
361 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | ||
362 | fetchAtt = mailimap_fetch_att_new_rfc822_text(); | ||
363 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | ||
364 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | ||
365 | mailimap_set_free( set ); | ||
366 | mailimap_fetch_type_free( fetchType ); | ||
367 | |||
368 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | ||
369 | mailimap_msg_att * msg_att; | ||
370 | msg_att = (mailimap_msg_att*)current->data; | ||
371 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; | ||
372 | |||
373 | if (item->msg_att_static && item->msg_att_static->rfc822_text) { | ||
374 | body_text = item->msg_att_static->rfc822_text; | ||
375 | body.setBodytext(body_text); | ||
376 | } | ||
377 | } else { | ||
378 | qDebug("error fetching text: %s",m_imap->response); | ||
379 | } | ||
380 | |||
381 | clist_free(result); | ||
382 | logout(); | ||
383 | return body; | ||
384 | } | ||
385 | |||
386 | #else | ||
387 | QString IMAPwrapper::fetchBody(const RecMail&mail) | ||
388 | { | ||
389 | QString body = ""; | ||
390 | const char *mb; | 325 | const char *mb; |
391 | int err = MAILIMAP_NO_ERROR; | 326 | int err = MAILIMAP_NO_ERROR; |
392 | clist *result; | 327 | clist *result; |
393 | clistcell *current; | 328 | clistcell *current; |
394 | mailimap_fetch_att *fetchAtt; | 329 | mailimap_fetch_att *fetchAtt; |
395 | mailimap_fetch_type *fetchType; | 330 | mailimap_fetch_type *fetchType; |
396 | mailimap_set *set; | 331 | mailimap_set *set; |
397 | mailimap_body*body_desc; | 332 | mailimap_body*body_desc; |
398 | 333 | ||
399 | mb = mail.getMbox().latin1(); | 334 | mb = mail.getMbox().latin1(); |
400 | 335 | ||
401 | login(); | 336 | login(); |
402 | if (!m_imap) { | 337 | if (!m_imap) { |
403 | return body; | 338 | return body; |
404 | } | 339 | } |
405 | /* select mailbox READONLY for operations */ | 340 | /* select mailbox READONLY for operations */ |
406 | err = mailimap_examine( m_imap, (char*)mb); | 341 | err = mailimap_examine( m_imap, (char*)mb); |
407 | if ( err != MAILIMAP_NO_ERROR ) { | 342 | if ( err != MAILIMAP_NO_ERROR ) { |
408 | qDebug("error selecting mailbox: %s",m_imap->response); | 343 | qDebug("error selecting mailbox: %s",m_imap->response); |
409 | logout(); | 344 | logout(); |
410 | return body; | 345 | return body; |
411 | } | 346 | } |
412 | result = clist_new(); | 347 | result = clist_new(); |
413 | /* the range has to start at 1!!! not with 0!!!! */ | 348 | /* the range has to start at 1!!! not with 0!!!! */ |
414 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 349 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
415 | fetchAtt = mailimap_fetch_att_new_body(); | 350 | fetchAtt = mailimap_fetch_att_new_body(); |
416 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 351 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
417 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 352 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
418 | mailimap_set_free( set ); | 353 | mailimap_set_free( set ); |
419 | mailimap_fetch_type_free( fetchType ); | 354 | mailimap_fetch_type_free( fetchType ); |
420 | 355 | ||
421 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 356 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
422 | mailimap_msg_att * msg_att; | 357 | mailimap_msg_att * msg_att; |
423 | msg_att = (mailimap_msg_att*)current->data; | 358 | msg_att = (mailimap_msg_att*)current->data; |
424 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; | 359 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; |
425 | body_desc = item->msg_att_static->body; | 360 | body_desc = item->msg_att_static->body; |
426 | if (body_desc->type==MAILIMAP_BODY_1PART) { | 361 | if (body_desc->type==MAILIMAP_BODY_1PART) { |
427 | body = searchBodyText(mail,body_desc->body_1part); | 362 | searchBodyText(mail,body_desc->body_1part,body); |
428 | } else { | 363 | } else { |
429 | } | 364 | } |
430 | 365 | ||
431 | } else { | 366 | } else { |
432 | qDebug("error fetching body: %s",m_imap->response); | 367 | qDebug("error fetching body: %s",m_imap->response); |
433 | } | 368 | } |
434 | 369 | ||
435 | clist_free(result); | 370 | clist_free(result); |
436 | logout(); | 371 | logout(); |
437 | return body; | 372 | return body; |
438 | } | 373 | } |
439 | #endif | ||
440 | 374 | ||
441 | QString IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription) | 375 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
442 | { | 376 | { |
443 | QString Body=""; | ||
444 | if (!mailDescription) { | 377 | if (!mailDescription) { |
445 | return Body; | 378 | return; |
446 | } | 379 | } |
447 | switch (mailDescription->type) { | 380 | switch (mailDescription->type) { |
448 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 381 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
449 | return getPlainBody(mail); | 382 | fillPlainBody(mail,target_body,mailDescription->body_type_text); |
450 | break; | 383 | break; |
451 | default: | 384 | default: |
452 | break; | 385 | break; |
453 | } | 386 | } |
454 | return Body; | 387 | return; |
455 | } | 388 | } |
456 | 389 | ||
457 | QString IMAPwrapper::getPlainBody(const RecMail&mail) | 390 | void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body) |
458 | { | 391 | { |
459 | QString body = ""; | ||
460 | const char *mb; | 392 | const char *mb; |
393 | QString body=""; | ||
461 | int err = MAILIMAP_NO_ERROR; | 394 | int err = MAILIMAP_NO_ERROR; |
462 | clist *result; | 395 | clist *result; |
463 | clistcell *current; | 396 | clistcell *current; |
464 | mailimap_fetch_att *fetchAtt; | 397 | mailimap_fetch_att *fetchAtt; |
465 | mailimap_fetch_type *fetchType; | 398 | mailimap_fetch_type *fetchType; |
466 | mailimap_set *set; | 399 | mailimap_set *set; |
467 | 400 | ||
468 | mb = mail.getMbox().latin1(); | 401 | mb = mail.getMbox().latin1(); |
469 | 402 | ||
470 | if (!m_imap) { | 403 | if (!m_imap) { |
471 | return body; | 404 | return; |
472 | } | 405 | } |
406 | |||
473 | result = clist_new(); | 407 | result = clist_new(); |
474 | /* the range has to start at 1!!! not with 0!!!! */ | 408 | /* the range has to start at 1!!! not with 0!!!! */ |
475 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 409 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
476 | fetchAtt = mailimap_fetch_att_new_rfc822_text(); | 410 | fetchAtt = mailimap_fetch_att_new_rfc822_text(); |
477 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 411 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
478 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 412 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
479 | mailimap_set_free( set ); | 413 | mailimap_set_free( set ); |
480 | mailimap_fetch_type_free( fetchType ); | 414 | mailimap_fetch_type_free( fetchType ); |
481 | 415 | ||
482 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 416 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
483 | mailimap_msg_att * msg_att; | 417 | mailimap_msg_att * msg_att; |
484 | msg_att = (mailimap_msg_att*)current->data; | 418 | msg_att = (mailimap_msg_att*)current->data; |
485 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; | 419 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; |
486 | if (item->msg_att_static && item->msg_att_static->rfc822_text) { | 420 | if (item->msg_att_static && item->msg_att_static->rfc822_text) { |
487 | body = item->msg_att_static->rfc822_text; | 421 | body = item->msg_att_static->rfc822_text; |
488 | } | 422 | } |
489 | } else { | 423 | } else { |
490 | qDebug("error fetching text: %s",m_imap->response); | 424 | qDebug("error fetching text: %s",m_imap->response); |
491 | } | 425 | } |
492 | clist_free(result); | 426 | clist_free(result); |
493 | return body; | 427 | target_body.setBodytext(body); |
428 | return; | ||
429 | } | ||
430 | |||
431 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | ||
432 | { | ||
433 | QStringList l; | ||
434 | QString from; | ||
435 | bool named_from; | ||
436 | clistcell *current = NULL; | ||
437 | mailimap_address * current_address=NULL; | ||
438 | if (!list) { | ||
439 | return l; | ||
440 | } | ||
441 | current = clist_begin(list); | ||
442 | while (current!= NULL) { | ||
443 | from = ""; | ||
444 | named_from = false; | ||
445 | current_address=(mailimap_address*)current->data; | ||
446 | current = current->next; | ||
447 | if (current_address->personal_name){ | ||
448 | from+=QString(current_address->personal_name); | ||
449 | from+=" "; | ||
450 | named_from = true; | ||
451 | } | ||
452 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | ||
453 | from+="<"; | ||
454 | } | ||
455 | if (current_address->mailbox_name) { | ||
456 | from+=QString(current_address->mailbox_name); | ||
457 | from+="@"; | ||
458 | } | ||
459 | if (current_address->host_name) { | ||
460 | from+=QString(current_address->host_name); | ||
461 | } | ||
462 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | ||
463 | from+=">"; | ||
464 | } | ||
465 | l.append(QString(from)); | ||
466 | } | ||
467 | return l; | ||
494 | } | 468 | } |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h index 1423faf..6565896 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.h +++ b/noncore/net/mail/libmailwrapper/imapwrapper.h | |||
@@ -1,36 +1,38 @@ | |||
1 | #ifndef __IMAPWRAPPER | 1 | #ifndef __IMAPWRAPPER |
2 | #define __IMAPWRAPPER | 2 | #define __IMAPWRAPPER |
3 | 3 | ||
4 | #include <qlist.h> | 4 | #include <qlist.h> |
5 | #include "mailwrapper.h" | 5 | #include "mailwrapper.h" |
6 | 6 | ||
7 | struct mailimap; | 7 | struct mailimap; |
8 | struct mailimap_body_type_1part; | 8 | struct mailimap_body_type_1part; |
9 | struct mailimap_body_type_text; | ||
9 | class RecMail; | 10 | class RecMail; |
10 | class RecBody; | 11 | class RecBody; |
11 | 12 | ||
12 | class IMAPwrapper : public QObject | 13 | class IMAPwrapper : public QObject |
13 | { | 14 | { |
14 | Q_OBJECT | 15 | Q_OBJECT |
15 | 16 | ||
16 | public: | 17 | public: |
17 | IMAPwrapper( IMAPaccount *a ); | 18 | IMAPwrapper( IMAPaccount *a ); |
18 | virtual ~IMAPwrapper(); | 19 | virtual ~IMAPwrapper(); |
19 | QList<IMAPFolder>* listFolders(); | 20 | QList<IMAPFolder>* listFolders(); |
20 | void listMessages(const QString & mailbox,QList<RecMail>&target ); | 21 | void listMessages(const QString & mailbox,QList<RecMail>&target ); |
21 | RecBody fetchBody(const RecMail&mail); | 22 | RecBody fetchBody(const RecMail&mail); |
22 | static void imap_progress( size_t current, size_t maximum ); | 23 | static void imap_progress( size_t current, size_t maximum ); |
23 | 24 | ||
24 | protected: | 25 | protected: |
25 | RecMail*parse_list_result(mailimap_msg_att*); | 26 | RecMail*parse_list_result(mailimap_msg_att*); |
26 | void login(); | 27 | void login(); |
27 | void logout(); | 28 | void logout(); |
28 | QString searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription); | 29 | void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); |
29 | QString getPlainBody(const RecMail&mail); | 30 | void fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body); |
31 | QStringList address_list_to_stringlist(clist*list); | ||
30 | 32 | ||
31 | private: | 33 | private: |
32 | IMAPaccount *account; | 34 | IMAPaccount *account; |
33 | mailimap *m_imap; | 35 | mailimap *m_imap; |
34 | }; | 36 | }; |
35 | 37 | ||
36 | #endif | 38 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.cpp b/noncore/net/mail/libmailwrapper/mailtypes.cpp index 9f2c9e3..f9e5794 100644 --- a/noncore/net/mail/libmailwrapper/mailtypes.cpp +++ b/noncore/net/mail/libmailwrapper/mailtypes.cpp | |||
@@ -1,129 +1,158 @@ | |||
1 | #include "mailtypes.h" | 1 | #include "mailtypes.h" |
2 | 2 | ||
3 | 3 | ||
4 | RecMail::RecMail() | 4 | RecMail::RecMail() |
5 | :subject(""),date(""),mbox(""),msg_number(0),msg_flags(7) | 5 | :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) |
6 | { | 6 | { |
7 | init(); | ||
8 | } | ||
9 | |||
10 | RecMail::RecMail(const RecMail&old) | ||
11 | :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) | ||
12 | { | ||
13 | init(); | ||
14 | copy_old(old); | ||
15 | qDebug("Copy constructor RecMail"); | ||
16 | } | ||
17 | |||
18 | void RecMail::copy_old(const RecMail&old) | ||
19 | { | ||
20 | subject = old.subject; | ||
21 | date = old.date; | ||
22 | mbox = old.mbox; | ||
23 | msg_id = old.msg_id; | ||
24 | msg_number = old.msg_number; | ||
25 | from = old.from; | ||
26 | msg_flags = old.msg_flags; | ||
27 | to = old.to; | ||
28 | cc = old.cc; | ||
29 | bcc = old.bcc; | ||
30 | } | ||
31 | |||
32 | void RecMail::init() | ||
33 | { | ||
34 | to.clear(); | ||
35 | cc.clear(); | ||
36 | bcc.clear(); | ||
7 | } | 37 | } |
8 | 38 | ||
9 | void RecMail::setTo(const QStringList&list) | 39 | void RecMail::setTo(const QStringList&list) |
10 | { | 40 | { |
11 | to = list; | 41 | to = list; |
12 | } | 42 | } |
13 | 43 | ||
14 | const QStringList&RecMail::To()const | 44 | const QStringList&RecMail::To()const |
15 | { | 45 | { |
16 | return to; | 46 | return to; |
17 | } | 47 | } |
18 | 48 | ||
19 | void RecMail::setCC(const QStringList&list) | 49 | void RecMail::setCC(const QStringList&list) |
20 | { | 50 | { |
21 | cc = list; | 51 | cc = list; |
22 | } | 52 | } |
23 | 53 | ||
24 | const QStringList&RecMail::CC()const | 54 | const QStringList&RecMail::CC()const |
25 | { | 55 | { |
26 | return cc; | 56 | return cc; |
27 | } | 57 | } |
28 | 58 | ||
29 | void RecMail::setBcc(const QStringList&list) | 59 | void RecMail::setBcc(const QStringList&list) |
30 | { | 60 | { |
31 | bcc = list; | 61 | bcc = list; |
32 | } | 62 | } |
33 | 63 | ||
34 | const QStringList& RecMail::Bcc()const | 64 | const QStringList& RecMail::Bcc()const |
35 | { | 65 | { |
36 | return bcc; | 66 | return bcc; |
37 | } | 67 | } |
38 | 68 | ||
39 | |||
40 | RecPart::RecPart() | 69 | RecPart::RecPart() |
41 | : m_type(""),m_subtype(""),m_identifier(""),m_encoding("") | 70 | : m_type(""),m_subtype(""),m_identifier(""),m_encoding("") |
42 | { | 71 | { |
43 | } | 72 | } |
44 | 73 | ||
45 | RecPart::RecPart(const QString&identifier,const QString&type,const QString&subtype,const QString&encoding) | 74 | RecPart::RecPart(const QString&identifier,const QString&type,const QString&subtype,const QString&encoding) |
46 | : m_type(type),m_subtype(subtype),m_identifier(identifier),m_encoding(encoding) | 75 | : m_type(type),m_subtype(subtype),m_identifier(identifier),m_encoding(encoding) |
47 | { | 76 | { |
48 | } | 77 | } |
49 | 78 | ||
50 | RecPart::~RecPart() | 79 | RecPart::~RecPart() |
51 | { | 80 | { |
52 | } | 81 | } |
53 | 82 | ||
54 | const QString& RecPart::Type()const | 83 | const QString& RecPart::Type()const |
55 | { | 84 | { |
56 | return m_type; | 85 | return m_type; |
57 | } | 86 | } |
58 | 87 | ||
59 | void RecPart::setType(const QString&type) | 88 | void RecPart::setType(const QString&type) |
60 | { | 89 | { |
61 | m_type = type; | 90 | m_type = type; |
62 | } | 91 | } |
63 | 92 | ||
64 | const QString& RecPart::Subtype()const | 93 | const QString& RecPart::Subtype()const |
65 | { | 94 | { |
66 | return m_subtype; | 95 | return m_subtype; |
67 | } | 96 | } |
68 | 97 | ||
69 | void RecPart::setSubtype(const QString&subtype) | 98 | void RecPart::setSubtype(const QString&subtype) |
70 | { | 99 | { |
71 | m_subtype = subtype; | 100 | m_subtype = subtype; |
72 | } | 101 | } |
73 | 102 | ||
74 | const QString& RecPart::Identifier()const | 103 | const QString& RecPart::Identifier()const |
75 | { | 104 | { |
76 | return m_identifier; | 105 | return m_identifier; |
77 | } | 106 | } |
78 | 107 | ||
79 | void RecPart::setIdentifier(const QString&identifier) | 108 | void RecPart::setIdentifier(const QString&identifier) |
80 | { | 109 | { |
81 | m_identifier = identifier; | 110 | m_identifier = identifier; |
82 | } | 111 | } |
83 | 112 | ||
84 | const QString& RecPart::Encoding()const | 113 | const QString& RecPart::Encoding()const |
85 | { | 114 | { |
86 | return m_encoding; | 115 | return m_encoding; |
87 | } | 116 | } |
88 | 117 | ||
89 | void RecPart::setEncoding(const QString&encoding) | 118 | void RecPart::setEncoding(const QString&encoding) |
90 | { | 119 | { |
91 | m_encoding = encoding; | 120 | m_encoding = encoding; |
92 | } | 121 | } |
93 | 122 | ||
94 | RecBody::RecBody() | 123 | RecBody::RecBody() |
95 | : m_BodyText(""),m_PartsList() | 124 | : m_BodyText(""),m_PartsList() |
96 | { | 125 | { |
97 | m_PartsList.setAutoDelete(true); | 126 | m_PartsList.setAutoDelete(true); |
98 | } | 127 | } |
99 | 128 | ||
100 | RecBody::~RecBody() | 129 | RecBody::~RecBody() |
101 | { | 130 | { |
102 | } | 131 | } |
103 | 132 | ||
104 | void RecBody::setBodytext(const QString&bodyText) | 133 | void RecBody::setBodytext(const QString&bodyText) |
105 | { | 134 | { |
106 | m_BodyText = bodyText; | 135 | m_BodyText = bodyText; |
107 | } | 136 | } |
108 | 137 | ||
109 | const QString& RecBody::Bodytext()const | 138 | const QString& RecBody::Bodytext()const |
110 | { | 139 | { |
111 | return m_BodyText; | 140 | return m_BodyText; |
112 | } | 141 | } |
113 | 142 | ||
114 | void RecBody::setParts(const QList<RecPart>&parts) | 143 | void RecBody::setParts(const QList<RecPart>&parts) |
115 | { | 144 | { |
116 | m_PartsList = parts; | 145 | m_PartsList = parts; |
117 | m_PartsList.setAutoDelete(true); | 146 | m_PartsList.setAutoDelete(true); |
118 | } | 147 | } |
119 | 148 | ||
120 | const QList<RecPart>& RecBody::Parts()const | 149 | const QList<RecPart>& RecBody::Parts()const |
121 | { | 150 | { |
122 | return m_PartsList; | 151 | return m_PartsList; |
123 | } | 152 | } |
124 | 153 | ||
125 | void RecBody::addPart(const RecPart& part) | 154 | void RecBody::addPart(const RecPart& part) |
126 | { | 155 | { |
127 | RecPart*p = new RecPart(part); | 156 | RecPart*p = new RecPart(part); |
128 | m_PartsList.append(p); | 157 | m_PartsList.append(p); |
129 | } | 158 | } |
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h index bb6a483..c8d533a 100644 --- a/noncore/net/mail/libmailwrapper/mailtypes.h +++ b/noncore/net/mail/libmailwrapper/mailtypes.h | |||
@@ -1,98 +1,102 @@ | |||
1 | #ifndef __MAIL_TYPES_H | 1 | #ifndef __MAIL_TYPES_H |
2 | #define __MAIL_TYPES_H | 2 | #define __MAIL_TYPES_H |
3 | 3 | ||
4 | #define FLAG_ANSWERED 0 | 4 | #define FLAG_ANSWERED 0 |
5 | #define FLAG_FLAGGED 1 | 5 | #define FLAG_FLAGGED 1 |
6 | #define FLAG_DELETED 2 | 6 | #define FLAG_DELETED 2 |
7 | #define FLAG_SEEN 3 | 7 | #define FLAG_SEEN 3 |
8 | #define FLAG_DRAFT 4 | 8 | #define FLAG_DRAFT 4 |
9 | #define FLAG_RECENT 5 | 9 | #define FLAG_RECENT 5 |
10 | 10 | ||
11 | #include <qlist.h> | 11 | #include <qlist.h> |
12 | #include <qbitarray.h> | 12 | #include <qbitarray.h> |
13 | #include <qstring.h> | 13 | #include <qstring.h> |
14 | #include <qstringlist.h> | 14 | #include <qstringlist.h> |
15 | 15 | ||
16 | /* a class to describe mails in a mailbox */ | 16 | /* a class to describe mails in a mailbox */ |
17 | /* Attention! | 17 | /* Attention! |
18 | From programmers point of view it would make sense to | 18 | From programmers point of view it would make sense to |
19 | store the mail body into this class, too. | 19 | store the mail body into this class, too. |
20 | But: not from the point of view of the device. | 20 | But: not from the point of view of the device. |
21 | Mailbodies can be real large. So we request them when | 21 | Mailbodies can be real large. So we request them when |
22 | needed from the mail-wrapper class direct from the server itself | 22 | needed from the mail-wrapper class direct from the server itself |
23 | (imap) or from a file-based cache (pop3?) | 23 | (imap) or from a file-based cache (pop3?) |
24 | So there is no interface "const QString&body()" but you should | 24 | So there is no interface "const QString&body()" but you should |
25 | make a request to the mailwrapper with this class as parameter to | 25 | make a request to the mailwrapper with this class as parameter to |
26 | get the body. Same words for the attachments. | 26 | get the body. Same words for the attachments. |
27 | */ | 27 | */ |
28 | class RecMail | 28 | class RecMail |
29 | { | 29 | { |
30 | public: | 30 | public: |
31 | RecMail(); | 31 | RecMail(); |
32 | RecMail(const RecMail&old); | ||
32 | virtual ~RecMail(){} | 33 | virtual ~RecMail(){} |
33 | 34 | ||
34 | const int getNumber()const{return msg_number;} | 35 | const int getNumber()const{return msg_number;} |
35 | void setNumber(int number){msg_number=number;} | 36 | void setNumber(int number){msg_number=number;} |
36 | const QString&getDate()const{ return date; } | 37 | const QString&getDate()const{ return date; } |
37 | void setDate( const QString&a ) { date = a; } | 38 | void setDate( const QString&a ) { date = a; } |
38 | const QString&getFrom()const{ return from; } | 39 | const QString&getFrom()const{ return from; } |
39 | void setFrom( const QString&a ) { from = a; } | 40 | void setFrom( const QString&a ) { from = a; } |
40 | const QString&getSubject()const { return subject; } | 41 | const QString&getSubject()const { return subject; } |
41 | void setSubject( const QString&s ) { subject = s; } | 42 | void setSubject( const QString&s ) { subject = s; } |
42 | const QString&getMbox()const{return mbox;} | 43 | const QString&getMbox()const{return mbox;} |
43 | void setMbox(const QString&box){mbox = box;} | 44 | void setMbox(const QString&box){mbox = box;} |
44 | 45 | void setMsgid(const QString&id){msg_id=id;} | |
46 | const QString&Msgid()const{return msg_id;} | ||
47 | |||
45 | void setTo(const QStringList&list); | 48 | void setTo(const QStringList&list); |
46 | const QStringList&To()const; | 49 | const QStringList&To()const; |
47 | void setCC(const QStringList&list); | 50 | void setCC(const QStringList&list); |
48 | const QStringList&CC()const; | 51 | const QStringList&CC()const; |
49 | void setBcc(const QStringList&list); | 52 | void setBcc(const QStringList&list); |
50 | const QStringList&Bcc()const; | 53 | const QStringList&Bcc()const; |
51 | |||
52 | const QBitArray&getFlags()const{return msg_flags;} | 54 | const QBitArray&getFlags()const{return msg_flags;} |
53 | void setFlags(const QBitArray&flags){msg_flags = flags;} | 55 | void setFlags(const QBitArray&flags){msg_flags = flags;} |
54 | 56 | ||
55 | protected: | 57 | protected: |
56 | QString subject,date,from,mbox; | 58 | QString subject,date,from,mbox,msg_id; |
57 | int msg_number; | 59 | int msg_number; |
58 | QBitArray msg_flags; | 60 | QBitArray msg_flags; |
59 | QStringList to,cc,bcc; | 61 | QStringList to,cc,bcc; |
62 | void init(); | ||
63 | void copy_old(const RecMail&old); | ||
60 | }; | 64 | }; |
61 | 65 | ||
62 | class RecPart | 66 | class RecPart |
63 | { | 67 | { |
64 | protected: | 68 | protected: |
65 | QString m_type,m_subtype,m_identifier,m_encoding; | 69 | QString m_type,m_subtype,m_identifier,m_encoding; |
66 | public: | 70 | public: |
67 | RecPart(); | 71 | RecPart(); |
68 | RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64"); | 72 | RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64"); |
69 | virtual ~RecPart(); | 73 | virtual ~RecPart(); |
70 | 74 | ||
71 | const QString&Type()const; | 75 | const QString&Type()const; |
72 | void setType(const QString&type); | 76 | void setType(const QString&type); |
73 | const QString&Subtype()const; | 77 | const QString&Subtype()const; |
74 | void setSubtype(const QString&subtype); | 78 | void setSubtype(const QString&subtype); |
75 | const QString&Identifier()const; | 79 | const QString&Identifier()const; |
76 | void setIdentifier(const QString&identifier); | 80 | void setIdentifier(const QString&identifier); |
77 | const QString&Encoding()const; | 81 | const QString&Encoding()const; |
78 | void setEncoding(const QString&encoding); | 82 | void setEncoding(const QString&encoding); |
79 | }; | 83 | }; |
80 | 84 | ||
81 | class RecBody | 85 | class RecBody |
82 | { | 86 | { |
83 | protected: | 87 | protected: |
84 | QString m_BodyText; | 88 | QString m_BodyText; |
85 | QList<RecPart> m_PartsList; | 89 | QList<RecPart> m_PartsList; |
86 | 90 | ||
87 | public: | 91 | public: |
88 | RecBody(); | 92 | RecBody(); |
89 | virtual ~RecBody(); | 93 | virtual ~RecBody(); |
90 | void setBodytext(const QString&); | 94 | void setBodytext(const QString&); |
91 | const QString& Bodytext()const; | 95 | const QString& Bodytext()const; |
92 | 96 | ||
93 | void setParts(const QList<RecPart>&parts); | 97 | void setParts(const QList<RecPart>&parts); |
94 | const QList<RecPart>& Parts()const; | 98 | const QList<RecPart>& Parts()const; |
95 | void addPart(const RecPart&part); | 99 | void addPart(const RecPart&part); |
96 | }; | 100 | }; |
97 | 101 | ||
98 | #endif | 102 | #endif |
diff --git a/noncore/net/mail/mailtypes.cpp b/noncore/net/mail/mailtypes.cpp index 9f2c9e3..f9e5794 100644 --- a/noncore/net/mail/mailtypes.cpp +++ b/noncore/net/mail/mailtypes.cpp | |||
@@ -1,129 +1,158 @@ | |||
1 | #include "mailtypes.h" | 1 | #include "mailtypes.h" |
2 | 2 | ||
3 | 3 | ||
4 | RecMail::RecMail() | 4 | RecMail::RecMail() |
5 | :subject(""),date(""),mbox(""),msg_number(0),msg_flags(7) | 5 | :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) |
6 | { | 6 | { |
7 | init(); | ||
8 | } | ||
9 | |||
10 | RecMail::RecMail(const RecMail&old) | ||
11 | :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) | ||
12 | { | ||
13 | init(); | ||
14 | copy_old(old); | ||
15 | qDebug("Copy constructor RecMail"); | ||
16 | } | ||
17 | |||
18 | void RecMail::copy_old(const RecMail&old) | ||
19 | { | ||
20 | subject = old.subject; | ||
21 | date = old.date; | ||
22 | mbox = old.mbox; | ||
23 | msg_id = old.msg_id; | ||
24 | msg_number = old.msg_number; | ||
25 | from = old.from; | ||
26 | msg_flags = old.msg_flags; | ||
27 | to = old.to; | ||
28 | cc = old.cc; | ||
29 | bcc = old.bcc; | ||
30 | } | ||
31 | |||
32 | void RecMail::init() | ||
33 | { | ||
34 | to.clear(); | ||
35 | cc.clear(); | ||
36 | bcc.clear(); | ||
7 | } | 37 | } |
8 | 38 | ||
9 | void RecMail::setTo(const QStringList&list) | 39 | void RecMail::setTo(const QStringList&list) |
10 | { | 40 | { |
11 | to = list; | 41 | to = list; |
12 | } | 42 | } |
13 | 43 | ||
14 | const QStringList&RecMail::To()const | 44 | const QStringList&RecMail::To()const |
15 | { | 45 | { |
16 | return to; | 46 | return to; |
17 | } | 47 | } |
18 | 48 | ||
19 | void RecMail::setCC(const QStringList&list) | 49 | void RecMail::setCC(const QStringList&list) |
20 | { | 50 | { |
21 | cc = list; | 51 | cc = list; |
22 | } | 52 | } |
23 | 53 | ||
24 | const QStringList&RecMail::CC()const | 54 | const QStringList&RecMail::CC()const |
25 | { | 55 | { |
26 | return cc; | 56 | return cc; |
27 | } | 57 | } |
28 | 58 | ||
29 | void RecMail::setBcc(const QStringList&list) | 59 | void RecMail::setBcc(const QStringList&list) |
30 | { | 60 | { |
31 | bcc = list; | 61 | bcc = list; |
32 | } | 62 | } |
33 | 63 | ||
34 | const QStringList& RecMail::Bcc()const | 64 | const QStringList& RecMail::Bcc()const |
35 | { | 65 | { |
36 | return bcc; | 66 | return bcc; |
37 | } | 67 | } |
38 | 68 | ||
39 | |||
40 | RecPart::RecPart() | 69 | RecPart::RecPart() |
41 | : m_type(""),m_subtype(""),m_identifier(""),m_encoding("") | 70 | : m_type(""),m_subtype(""),m_identifier(""),m_encoding("") |
42 | { | 71 | { |
43 | } | 72 | } |
44 | 73 | ||
45 | RecPart::RecPart(const QString&identifier,const QString&type,const QString&subtype,const QString&encoding) | 74 | RecPart::RecPart(const QString&identifier,const QString&type,const QString&subtype,const QString&encoding) |
46 | : m_type(type),m_subtype(subtype),m_identifier(identifier),m_encoding(encoding) | 75 | : m_type(type),m_subtype(subtype),m_identifier(identifier),m_encoding(encoding) |
47 | { | 76 | { |
48 | } | 77 | } |
49 | 78 | ||
50 | RecPart::~RecPart() | 79 | RecPart::~RecPart() |
51 | { | 80 | { |
52 | } | 81 | } |
53 | 82 | ||
54 | const QString& RecPart::Type()const | 83 | const QString& RecPart::Type()const |
55 | { | 84 | { |
56 | return m_type; | 85 | return m_type; |
57 | } | 86 | } |
58 | 87 | ||
59 | void RecPart::setType(const QString&type) | 88 | void RecPart::setType(const QString&type) |
60 | { | 89 | { |
61 | m_type = type; | 90 | m_type = type; |
62 | } | 91 | } |
63 | 92 | ||
64 | const QString& RecPart::Subtype()const | 93 | const QString& RecPart::Subtype()const |
65 | { | 94 | { |
66 | return m_subtype; | 95 | return m_subtype; |
67 | } | 96 | } |
68 | 97 | ||
69 | void RecPart::setSubtype(const QString&subtype) | 98 | void RecPart::setSubtype(const QString&subtype) |
70 | { | 99 | { |
71 | m_subtype = subtype; | 100 | m_subtype = subtype; |
72 | } | 101 | } |
73 | 102 | ||
74 | const QString& RecPart::Identifier()const | 103 | const QString& RecPart::Identifier()const |
75 | { | 104 | { |
76 | return m_identifier; | 105 | return m_identifier; |
77 | } | 106 | } |
78 | 107 | ||
79 | void RecPart::setIdentifier(const QString&identifier) | 108 | void RecPart::setIdentifier(const QString&identifier) |
80 | { | 109 | { |
81 | m_identifier = identifier; | 110 | m_identifier = identifier; |
82 | } | 111 | } |
83 | 112 | ||
84 | const QString& RecPart::Encoding()const | 113 | const QString& RecPart::Encoding()const |
85 | { | 114 | { |
86 | return m_encoding; | 115 | return m_encoding; |
87 | } | 116 | } |
88 | 117 | ||
89 | void RecPart::setEncoding(const QString&encoding) | 118 | void RecPart::setEncoding(const QString&encoding) |
90 | { | 119 | { |
91 | m_encoding = encoding; | 120 | m_encoding = encoding; |
92 | } | 121 | } |
93 | 122 | ||
94 | RecBody::RecBody() | 123 | RecBody::RecBody() |
95 | : m_BodyText(""),m_PartsList() | 124 | : m_BodyText(""),m_PartsList() |
96 | { | 125 | { |
97 | m_PartsList.setAutoDelete(true); | 126 | m_PartsList.setAutoDelete(true); |
98 | } | 127 | } |
99 | 128 | ||
100 | RecBody::~RecBody() | 129 | RecBody::~RecBody() |
101 | { | 130 | { |
102 | } | 131 | } |
103 | 132 | ||
104 | void RecBody::setBodytext(const QString&bodyText) | 133 | void RecBody::setBodytext(const QString&bodyText) |
105 | { | 134 | { |
106 | m_BodyText = bodyText; | 135 | m_BodyText = bodyText; |
107 | } | 136 | } |
108 | 137 | ||
109 | const QString& RecBody::Bodytext()const | 138 | const QString& RecBody::Bodytext()const |
110 | { | 139 | { |
111 | return m_BodyText; | 140 | return m_BodyText; |
112 | } | 141 | } |
113 | 142 | ||
114 | void RecBody::setParts(const QList<RecPart>&parts) | 143 | void RecBody::setParts(const QList<RecPart>&parts) |
115 | { | 144 | { |
116 | m_PartsList = parts; | 145 | m_PartsList = parts; |
117 | m_PartsList.setAutoDelete(true); | 146 | m_PartsList.setAutoDelete(true); |
118 | } | 147 | } |
119 | 148 | ||
120 | const QList<RecPart>& RecBody::Parts()const | 149 | const QList<RecPart>& RecBody::Parts()const |
121 | { | 150 | { |
122 | return m_PartsList; | 151 | return m_PartsList; |
123 | } | 152 | } |
124 | 153 | ||
125 | void RecBody::addPart(const RecPart& part) | 154 | void RecBody::addPart(const RecPart& part) |
126 | { | 155 | { |
127 | RecPart*p = new RecPart(part); | 156 | RecPart*p = new RecPart(part); |
128 | m_PartsList.append(p); | 157 | m_PartsList.append(p); |
129 | } | 158 | } |
diff --git a/noncore/net/mail/mailtypes.h b/noncore/net/mail/mailtypes.h index bb6a483..c8d533a 100644 --- a/noncore/net/mail/mailtypes.h +++ b/noncore/net/mail/mailtypes.h | |||
@@ -1,98 +1,102 @@ | |||
1 | #ifndef __MAIL_TYPES_H | 1 | #ifndef __MAIL_TYPES_H |
2 | #define __MAIL_TYPES_H | 2 | #define __MAIL_TYPES_H |
3 | 3 | ||
4 | #define FLAG_ANSWERED 0 | 4 | #define FLAG_ANSWERED 0 |
5 | #define FLAG_FLAGGED 1 | 5 | #define FLAG_FLAGGED 1 |
6 | #define FLAG_DELETED 2 | 6 | #define FLAG_DELETED 2 |
7 | #define FLAG_SEEN 3 | 7 | #define FLAG_SEEN 3 |
8 | #define FLAG_DRAFT 4 | 8 | #define FLAG_DRAFT 4 |
9 | #define FLAG_RECENT 5 | 9 | #define FLAG_RECENT 5 |
10 | 10 | ||
11 | #include <qlist.h> | 11 | #include <qlist.h> |
12 | #include <qbitarray.h> | 12 | #include <qbitarray.h> |
13 | #include <qstring.h> | 13 | #include <qstring.h> |
14 | #include <qstringlist.h> | 14 | #include <qstringlist.h> |
15 | 15 | ||
16 | /* a class to describe mails in a mailbox */ | 16 | /* a class to describe mails in a mailbox */ |
17 | /* Attention! | 17 | /* Attention! |
18 | From programmers point of view it would make sense to | 18 | From programmers point of view it would make sense to |
19 | store the mail body into this class, too. | 19 | store the mail body into this class, too. |
20 | But: not from the point of view of the device. | 20 | But: not from the point of view of the device. |
21 | Mailbodies can be real large. So we request them when | 21 | Mailbodies can be real large. So we request them when |
22 | needed from the mail-wrapper class direct from the server itself | 22 | needed from the mail-wrapper class direct from the server itself |
23 | (imap) or from a file-based cache (pop3?) | 23 | (imap) or from a file-based cache (pop3?) |
24 | So there is no interface "const QString&body()" but you should | 24 | So there is no interface "const QString&body()" but you should |
25 | make a request to the mailwrapper with this class as parameter to | 25 | make a request to the mailwrapper with this class as parameter to |
26 | get the body. Same words for the attachments. | 26 | get the body. Same words for the attachments. |
27 | */ | 27 | */ |
28 | class RecMail | 28 | class RecMail |
29 | { | 29 | { |
30 | public: | 30 | public: |
31 | RecMail(); | 31 | RecMail(); |
32 | RecMail(const RecMail&old); | ||
32 | virtual ~RecMail(){} | 33 | virtual ~RecMail(){} |
33 | 34 | ||
34 | const int getNumber()const{return msg_number;} | 35 | const int getNumber()const{return msg_number;} |
35 | void setNumber(int number){msg_number=number;} | 36 | void setNumber(int number){msg_number=number;} |
36 | const QString&getDate()const{ return date; } | 37 | const QString&getDate()const{ return date; } |
37 | void setDate( const QString&a ) { date = a; } | 38 | void setDate( const QString&a ) { date = a; } |
38 | const QString&getFrom()const{ return from; } | 39 | const QString&getFrom()const{ return from; } |
39 | void setFrom( const QString&a ) { from = a; } | 40 | void setFrom( const QString&a ) { from = a; } |
40 | const QString&getSubject()const { return subject; } | 41 | const QString&getSubject()const { return subject; } |
41 | void setSubject( const QString&s ) { subject = s; } | 42 | void setSubject( const QString&s ) { subject = s; } |
42 | const QString&getMbox()const{return mbox;} | 43 | const QString&getMbox()const{return mbox;} |
43 | void setMbox(const QString&box){mbox = box;} | 44 | void setMbox(const QString&box){mbox = box;} |
44 | 45 | void setMsgid(const QString&id){msg_id=id;} | |
46 | const QString&Msgid()const{return msg_id;} | ||
47 | |||
45 | void setTo(const QStringList&list); | 48 | void setTo(const QStringList&list); |
46 | const QStringList&To()const; | 49 | const QStringList&To()const; |
47 | void setCC(const QStringList&list); | 50 | void setCC(const QStringList&list); |
48 | const QStringList&CC()const; | 51 | const QStringList&CC()const; |
49 | void setBcc(const QStringList&list); | 52 | void setBcc(const QStringList&list); |
50 | const QStringList&Bcc()const; | 53 | const QStringList&Bcc()const; |
51 | |||
52 | const QBitArray&getFlags()const{return msg_flags;} | 54 | const QBitArray&getFlags()const{return msg_flags;} |
53 | void setFlags(const QBitArray&flags){msg_flags = flags;} | 55 | void setFlags(const QBitArray&flags){msg_flags = flags;} |
54 | 56 | ||
55 | protected: | 57 | protected: |
56 | QString subject,date,from,mbox; | 58 | QString subject,date,from,mbox,msg_id; |
57 | int msg_number; | 59 | int msg_number; |
58 | QBitArray msg_flags; | 60 | QBitArray msg_flags; |
59 | QStringList to,cc,bcc; | 61 | QStringList to,cc,bcc; |
62 | void init(); | ||
63 | void copy_old(const RecMail&old); | ||
60 | }; | 64 | }; |
61 | 65 | ||
62 | class RecPart | 66 | class RecPart |
63 | { | 67 | { |
64 | protected: | 68 | protected: |
65 | QString m_type,m_subtype,m_identifier,m_encoding; | 69 | QString m_type,m_subtype,m_identifier,m_encoding; |
66 | public: | 70 | public: |
67 | RecPart(); | 71 | RecPart(); |
68 | RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64"); | 72 | RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64"); |
69 | virtual ~RecPart(); | 73 | virtual ~RecPart(); |
70 | 74 | ||
71 | const QString&Type()const; | 75 | const QString&Type()const; |
72 | void setType(const QString&type); | 76 | void setType(const QString&type); |
73 | const QString&Subtype()const; | 77 | const QString&Subtype()const; |
74 | void setSubtype(const QString&subtype); | 78 | void setSubtype(const QString&subtype); |
75 | const QString&Identifier()const; | 79 | const QString&Identifier()const; |
76 | void setIdentifier(const QString&identifier); | 80 | void setIdentifier(const QString&identifier); |
77 | const QString&Encoding()const; | 81 | const QString&Encoding()const; |
78 | void setEncoding(const QString&encoding); | 82 | void setEncoding(const QString&encoding); |
79 | }; | 83 | }; |
80 | 84 | ||
81 | class RecBody | 85 | class RecBody |
82 | { | 86 | { |
83 | protected: | 87 | protected: |
84 | QString m_BodyText; | 88 | QString m_BodyText; |
85 | QList<RecPart> m_PartsList; | 89 | QList<RecPart> m_PartsList; |
86 | 90 | ||
87 | public: | 91 | public: |
88 | RecBody(); | 92 | RecBody(); |
89 | virtual ~RecBody(); | 93 | virtual ~RecBody(); |
90 | void setBodytext(const QString&); | 94 | void setBodytext(const QString&); |
91 | const QString& Bodytext()const; | 95 | const QString& Bodytext()const; |
92 | 96 | ||
93 | void setParts(const QList<RecPart>&parts); | 97 | void setParts(const QList<RecPart>&parts); |
94 | const QList<RecPart>& Parts()const; | 98 | const QList<RecPart>& Parts()const; |
95 | void addPart(const RecPart&part); | 99 | void addPart(const RecPart&part); |
96 | }; | 100 | }; |
97 | 101 | ||
98 | #endif | 102 | #endif |