author | alwin <alwin> | 2003-12-16 13:14:05 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-16 13:14:05 (UTC) |
commit | 49c02bbbb7a0aeee933d58ba1d3d3e86e6bc7838 (patch) (unidiff) | |
tree | 710393582789ed1db97592fed5bb88ad4d56550d | |
parent | f42c15f884d4377bc99d73e16fa1722b0fb2a4d3 (diff) | |
download | opie-49c02bbbb7a0aeee933d58ba1d3d3e86e6bc7838.zip opie-49c02bbbb7a0aeee933d58ba1d3d3e86e6bc7838.tar.gz opie-49c02bbbb7a0aeee933d58ba1d3d3e86e6bc7838.tar.bz2 |
saving of attachments implemented.
-rw-r--r-- | noncore/net/mail/abstractmail.cpp | 28 | ||||
-rw-r--r-- | noncore/net/mail/abstractmail.h | 8 | ||||
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 78 | ||||
-rw-r--r-- | noncore/net/mail/imapwrapper.h | 12 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.cpp | 28 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.h | 8 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 78 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.h | 12 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailtypes.cpp | 90 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailtypes.h | 47 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 11 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 6 | ||||
-rw-r--r-- | noncore/net/mail/mailtypes.cpp | 90 | ||||
-rw-r--r-- | noncore/net/mail/mailtypes.h | 47 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 11 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.h | 6 | ||||
-rw-r--r-- | noncore/net/mail/viewmail.cpp | 13 |
17 files changed, 477 insertions, 96 deletions
diff --git a/noncore/net/mail/abstractmail.cpp b/noncore/net/mail/abstractmail.cpp index 0bb2525..92a46f1 100644 --- a/noncore/net/mail/abstractmail.cpp +++ b/noncore/net/mail/abstractmail.cpp | |||
@@ -1,34 +1,48 @@ | |||
1 | #include "abstractmail.h" | 1 | #include "abstractmail.h" |
2 | #include "imapwrapper.h" | 2 | #include "imapwrapper.h" |
3 | #include "pop3wrapper.h" | 3 | #include "pop3wrapper.h" |
4 | #include "mailtypes.h" | ||
4 | 5 | ||
5 | #include <qstring.h> | 6 | #include <qstring.h> |
6 | #include <stdlib.h> | 7 | #include <stdlib.h> |
7 | #include <libetpan/mailmime_content.h> | 8 | #include <libetpan/mailmime_content.h> |
8 | 9 | ||
9 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) | 10 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) |
10 | { | 11 | { |
11 | return new IMAPwrapper(a); | 12 | return new IMAPwrapper(a); |
12 | } | 13 | } |
13 | 14 | ||
14 | AbstractMail* AbstractMail::getWrapper(POP3account *a) | 15 | AbstractMail* AbstractMail::getWrapper(POP3account *a) |
15 | { | 16 | { |
16 | return new POP3wrapper(a); | 17 | return new POP3wrapper(a); |
17 | } | 18 | } |
18 | 19 | ||
19 | QString AbstractMail::decode_quoted_printable(const char*text) | 20 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) |
20 | { | 21 | { |
22 | qDebug("Decode string start"); | ||
21 | char*result_text; | 23 | char*result_text; |
22 | size_t index = 0; | 24 | size_t index = 0; |
23 | QString result = ""; | ||
24 | /* reset for recursive use! */ | 25 | /* reset for recursive use! */ |
25 | size_t target_length = 0; | 26 | size_t target_length = 0; |
26 | result_text = 0; | 27 | result_text = 0; |
27 | int err = mailmime_quoted_printable_body_parse(text,strlen(text), | 28 | int mimetype = MAILMIME_MECHANISM_7BIT; |
28 | &index,&result_text,&target_length,0); | 29 | if (enc.lower()=="quoted-printable") { |
29 | if (result_text) { | 30 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
30 | result = result_text; | 31 | } else if (enc.lower()=="base64") { |
31 | free(result_text); | 32 | mimetype = MAILMIME_MECHANISM_BASE64; |
33 | } else if (enc.lower()=="8bit") { | ||
34 | mimetype = MAILMIME_MECHANISM_8BIT; | ||
35 | } else if (enc.lower()=="binary") { | ||
36 | mimetype = MAILMIME_MECHANISM_BINARY; | ||
32 | } | 37 | } |
38 | |||
39 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, | ||
40 | &result_text,&target_length); | ||
41 | |||
42 | encodedString* result = new encodedString(); | ||
43 | if (err == MAILIMF_NO_ERROR) { | ||
44 | result->setContent(result_text,target_length); | ||
45 | } | ||
46 | qDebug("Decode string finished"); | ||
33 | return result; | 47 | return result; |
34 | } | 48 | } |
diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h index 4473ad2..f1a8468 100644 --- a/noncore/net/mail/abstractmail.h +++ b/noncore/net/mail/abstractmail.h | |||
@@ -1,31 +1,35 @@ | |||
1 | #ifndef __abstract_mail_ | 1 | #ifndef __abstract_mail_ |
2 | #define __abstract_mail_ | 2 | #define __abstract_mail_ |
3 | 3 | ||
4 | #include <qobject.h> | 4 | #include <qobject.h> |
5 | #include "settings.h" | 5 | #include "settings.h" |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | class RecPart; | 9 | class RecPart; |
10 | class IMAPwrapper; | 10 | class IMAPwrapper; |
11 | class POP3wrapper; | 11 | class POP3wrapper; |
12 | class Folder; | 12 | class Folder; |
13 | class encodedString; | ||
13 | 14 | ||
14 | class AbstractMail:public QObject | 15 | class AbstractMail:public QObject |
15 | { | 16 | { |
16 | Q_OBJECT | 17 | Q_OBJECT |
17 | public: | 18 | public: |
18 | AbstractMail(){}; | 19 | AbstractMail(){}; |
19 | virtual ~AbstractMail(){} | 20 | virtual ~AbstractMail(){} |
20 | virtual QList<Folder>* listFolders()=0; | 21 | virtual QList<Folder>* listFolders()=0; |
21 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; | 22 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; |
22 | virtual RecBody fetchBody(const RecMail&mail)=0; | 23 | virtual RecBody fetchBody(const RecMail&mail)=0; |
23 | virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0; | 24 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; |
25 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; | ||
26 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; | ||
27 | |||
24 | virtual void deleteMail(const RecMail&mail)=0; | 28 | virtual void deleteMail(const RecMail&mail)=0; |
25 | virtual void answeredMail(const RecMail&mail)=0; | 29 | virtual void answeredMail(const RecMail&mail)=0; |
26 | 30 | ||
27 | static AbstractMail* getWrapper(IMAPaccount *a); | 31 | static AbstractMail* getWrapper(IMAPaccount *a); |
28 | static AbstractMail* getWrapper(POP3account *a); | 32 | static AbstractMail* getWrapper(POP3account *a); |
29 | static QString decode_quoted_printable(const char*text); | 33 | static encodedString*decode_String(const encodedString*text,const QString&enc); |
30 | }; | 34 | }; |
31 | #endif | 35 | #endif |
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index a4e6228..d56d7f9 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -1,786 +1,800 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include "imapwrapper.h" | 4 | #include "imapwrapper.h" |
5 | #include "mailtypes.h" | 5 | #include "mailtypes.h" |
6 | #include <libetpan/mailimap.h> | 6 | #include <libetpan/mailimap.h> |
7 | 7 | ||
8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
9 | : AbstractMail() | 9 | : AbstractMail() |
10 | { | 10 | { |
11 | account = a; | 11 | account = a; |
12 | m_imap = 0; | 12 | m_imap = 0; |
13 | } | 13 | } |
14 | 14 | ||
15 | IMAPwrapper::~IMAPwrapper() | 15 | IMAPwrapper::~IMAPwrapper() |
16 | { | 16 | { |
17 | logout(); | 17 | logout(); |
18 | } | 18 | } |
19 | 19 | ||
20 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 20 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
21 | { | 21 | { |
22 | qDebug( "IMAP: %i of %i", current, maximum ); | 22 | qDebug( "IMAP: %i of %i", current, maximum ); |
23 | } | 23 | } |
24 | 24 | ||
25 | void IMAPwrapper::login() | 25 | void IMAPwrapper::login() |
26 | { | 26 | { |
27 | const char *server, *user, *pass; | 27 | const char *server, *user, *pass; |
28 | uint16_t port; | 28 | uint16_t port; |
29 | int err = MAILIMAP_NO_ERROR; | 29 | int err = MAILIMAP_NO_ERROR; |
30 | 30 | ||
31 | /* we are connected this moment */ | 31 | /* we are connected this moment */ |
32 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 32 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
33 | if (m_imap) { | 33 | if (m_imap) { |
34 | mailstream_flush(m_imap->imap_stream); | 34 | mailstream_flush(m_imap->imap_stream); |
35 | return; | 35 | return; |
36 | } | 36 | } |
37 | server = account->getServer().latin1(); | 37 | server = account->getServer().latin1(); |
38 | port = account->getPort().toUInt(); | 38 | port = account->getPort().toUInt(); |
39 | user = account->getUser().latin1(); | 39 | user = account->getUser().latin1(); |
40 | pass = account->getPassword().latin1(); | 40 | pass = account->getPassword().latin1(); |
41 | 41 | ||
42 | m_imap = mailimap_new( 20, &imap_progress ); | 42 | m_imap = mailimap_new( 20, &imap_progress ); |
43 | /* connect */ | 43 | /* connect */ |
44 | if (account->getSSL()) { | 44 | if (account->getSSL()) { |
45 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 45 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
46 | } else { | 46 | } else { |
47 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 47 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
48 | } | 48 | } |
49 | 49 | ||
50 | if ( err != MAILIMAP_NO_ERROR && | 50 | if ( err != MAILIMAP_NO_ERROR && |
51 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 51 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
52 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 52 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
53 | qDebug("error connecting server: %s",m_imap->imap_response); | 53 | qDebug("error connecting server: %s",m_imap->imap_response); |
54 | mailimap_free( m_imap ); | 54 | mailimap_free( m_imap ); |
55 | m_imap = 0; | 55 | m_imap = 0; |
56 | return; | 56 | return; |
57 | } | 57 | } |
58 | 58 | ||
59 | /* login */ | 59 | /* login */ |
60 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 60 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
61 | if ( err != MAILIMAP_NO_ERROR ) { | 61 | if ( err != MAILIMAP_NO_ERROR ) { |
62 | qDebug("error logging in imap: %s",m_imap->imap_response); | 62 | qDebug("error logging in imap: %s",m_imap->imap_response); |
63 | err = mailimap_close( m_imap ); | 63 | err = mailimap_close( m_imap ); |
64 | mailimap_free( m_imap ); | 64 | mailimap_free( m_imap ); |
65 | m_imap = 0; | 65 | m_imap = 0; |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | void IMAPwrapper::logout() | 69 | void IMAPwrapper::logout() |
70 | { | 70 | { |
71 | int err = MAILIMAP_NO_ERROR; | 71 | int err = MAILIMAP_NO_ERROR; |
72 | if (!m_imap) return; | 72 | if (!m_imap) return; |
73 | err = mailimap_logout( m_imap ); | 73 | err = mailimap_logout( m_imap ); |
74 | err = mailimap_close( m_imap ); | 74 | err = mailimap_close( m_imap ); |
75 | mailimap_free( m_imap ); | 75 | mailimap_free( m_imap ); |
76 | m_imap = 0; | 76 | m_imap = 0; |
77 | } | 77 | } |
78 | 78 | ||
79 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 79 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
80 | { | 80 | { |
81 | const char *mb; | 81 | const char *mb; |
82 | int err = MAILIMAP_NO_ERROR; | 82 | int err = MAILIMAP_NO_ERROR; |
83 | clist *result; | 83 | clist *result; |
84 | clistcell *current; | 84 | clistcell *current; |
85 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; | 85 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; |
86 | mailimap_fetch_type *fetchType; | 86 | mailimap_fetch_type *fetchType; |
87 | mailimap_set *set; | 87 | mailimap_set *set; |
88 | 88 | ||
89 | mb = mailbox.latin1(); | 89 | mb = mailbox.latin1(); |
90 | login(); | 90 | login(); |
91 | if (!m_imap) { | 91 | if (!m_imap) { |
92 | return; | 92 | return; |
93 | } | 93 | } |
94 | /* select mailbox READONLY for operations */ | 94 | /* select mailbox READONLY for operations */ |
95 | err = mailimap_examine( m_imap, (char*)mb); | 95 | err = mailimap_examine( m_imap, (char*)mb); |
96 | if ( err != MAILIMAP_NO_ERROR ) { | 96 | if ( err != MAILIMAP_NO_ERROR ) { |
97 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 97 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
98 | return; | 98 | return; |
99 | } | 99 | } |
100 | 100 | ||
101 | int last = m_imap->imap_selection_info->sel_exists; | 101 | int last = m_imap->imap_selection_info->sel_exists; |
102 | 102 | ||
103 | if (last == 0) { | 103 | if (last == 0) { |
104 | qDebug("mailbox has no mails"); | 104 | qDebug("mailbox has no mails"); |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | 107 | ||
108 | result = clist_new(); | 108 | result = clist_new(); |
109 | /* the range has to start at 1!!! not with 0!!!! */ | 109 | /* the range has to start at 1!!! not with 0!!!! */ |
110 | set = mailimap_set_new_interval( 1, last ); | 110 | set = mailimap_set_new_interval( 1, last ); |
111 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 111 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
114 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 114 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
115 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 115 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
116 | 116 | ||
117 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 117 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
118 | mailimap_set_free( set ); | 118 | mailimap_set_free( set ); |
119 | mailimap_fetch_type_free( fetchType ); | 119 | mailimap_fetch_type_free( fetchType ); |
120 | 120 | ||
121 | QString date,subject,from; | 121 | QString date,subject,from; |
122 | 122 | ||
123 | if ( err == MAILIMAP_NO_ERROR ) { | 123 | if ( err == MAILIMAP_NO_ERROR ) { |
124 | 124 | ||
125 | mailimap_msg_att * msg_att; | 125 | mailimap_msg_att * msg_att; |
126 | int i = 0; | 126 | int i = 0; |
127 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 127 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
128 | ++i; | 128 | ++i; |
129 | msg_att = (mailimap_msg_att*)current->data; | 129 | msg_att = (mailimap_msg_att*)current->data; |
130 | RecMail*m = parse_list_result(msg_att); | 130 | RecMail*m = parse_list_result(msg_att); |
131 | if (m) { | 131 | if (m) { |
132 | m->setNumber(i); | 132 | m->setNumber(i); |
133 | m->setMbox(mailbox); | 133 | m->setMbox(mailbox); |
134 | m->setWrapper(this); | 134 | m->setWrapper(this); |
135 | target.append(m); | 135 | target.append(m); |
136 | } | 136 | } |
137 | } | 137 | } |
138 | } else { | 138 | } else { |
139 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 139 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
140 | } | 140 | } |
141 | mailimap_fetch_list_free(result); | 141 | mailimap_fetch_list_free(result); |
142 | } | 142 | } |
143 | 143 | ||
144 | QList<Folder>* IMAPwrapper::listFolders() | 144 | QList<Folder>* IMAPwrapper::listFolders() |
145 | { | 145 | { |
146 | const char *path, *mask; | 146 | const char *path, *mask; |
147 | int err = MAILIMAP_NO_ERROR; | 147 | int err = MAILIMAP_NO_ERROR; |
148 | clist *result; | 148 | clist *result; |
149 | clistcell *current; | 149 | clistcell *current; |
150 | 150 | ||
151 | QList<Folder> * folders = new QList<Folder>(); | 151 | QList<Folder> * folders = new QList<Folder>(); |
152 | folders->setAutoDelete( false ); | 152 | folders->setAutoDelete( false ); |
153 | login(); | 153 | login(); |
154 | if (!m_imap) { | 154 | if (!m_imap) { |
155 | return folders; | 155 | return folders; |
156 | } | 156 | } |
157 | 157 | ||
158 | /* | 158 | /* |
159 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 159 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
160 | * We must not forget to filter them out in next loop! | 160 | * We must not forget to filter them out in next loop! |
161 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 161 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
162 | */ | 162 | */ |
163 | QString temp; | 163 | QString temp; |
164 | mask = "INBOX" ; | 164 | mask = "INBOX" ; |
165 | result = clist_new(); | 165 | result = clist_new(); |
166 | mailimap_mailbox_list *list; | 166 | mailimap_mailbox_list *list; |
167 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 167 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
168 | if ( err == MAILIMAP_NO_ERROR ) { | 168 | if ( err == MAILIMAP_NO_ERROR ) { |
169 | current = result->first; | 169 | current = result->first; |
170 | for ( int i = result->count; i > 0; i-- ) { | 170 | for ( int i = result->count; i > 0; i-- ) { |
171 | list = (mailimap_mailbox_list *) current->data; | 171 | list = (mailimap_mailbox_list *) current->data; |
172 | // it is better use the deep copy mechanism of qt itself | 172 | // it is better use the deep copy mechanism of qt itself |
173 | // instead of using strdup! | 173 | // instead of using strdup! |
174 | temp = list->mb_name; | 174 | temp = list->mb_name; |
175 | folders->append( new IMAPFolder(temp)); | 175 | folders->append( new IMAPFolder(temp)); |
176 | current = current->next; | 176 | current = current->next; |
177 | } | 177 | } |
178 | } else { | 178 | } else { |
179 | qDebug("error fetching folders: %s",m_imap->imap_response); | 179 | qDebug("error fetching folders: %s",m_imap->imap_response); |
180 | } | 180 | } |
181 | mailimap_list_result_free( result ); | 181 | mailimap_list_result_free( result ); |
182 | 182 | ||
183 | /* | 183 | /* |
184 | * second stage - get the other then inbox folders | 184 | * second stage - get the other then inbox folders |
185 | */ | 185 | */ |
186 | mask = "*" ; | 186 | mask = "*" ; |
187 | path = account->getPrefix().latin1(); | 187 | path = account->getPrefix().latin1(); |
188 | if (!path) path = ""; | 188 | if (!path) path = ""; |
189 | result = clist_new(); | 189 | result = clist_new(); |
190 | qDebug(path); | 190 | qDebug(path); |
191 | bool selectable = true; | 191 | bool selectable = true; |
192 | mailimap_mbx_list_flags*bflags; | 192 | mailimap_mbx_list_flags*bflags; |
193 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 193 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
194 | if ( err == MAILIMAP_NO_ERROR ) { | 194 | if ( err == MAILIMAP_NO_ERROR ) { |
195 | current = result->first; | 195 | current = result->first; |
196 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 196 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
197 | list = (mailimap_mailbox_list *) current->data; | 197 | list = (mailimap_mailbox_list *) current->data; |
198 | // it is better use the deep copy mechanism of qt itself | 198 | // it is better use the deep copy mechanism of qt itself |
199 | // instead of using strdup! | 199 | // instead of using strdup! |
200 | temp = list->mb_name; | 200 | temp = list->mb_name; |
201 | if (temp.lower()=="inbox") | 201 | if (temp.lower()=="inbox") |
202 | continue; | 202 | continue; |
203 | if (temp.lower()==account->getPrefix().lower()) | 203 | if (temp.lower()==account->getPrefix().lower()) |
204 | continue; | 204 | continue; |
205 | if ( (bflags = list->mb_flag) ) { | 205 | if ( (bflags = list->mb_flag) ) { |
206 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 206 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
207 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 207 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
208 | } | 208 | } |
209 | folders->append(new IMAPFolder(temp,selectable,account->getPrefix())); | 209 | folders->append(new IMAPFolder(temp,selectable,account->getPrefix())); |
210 | } | 210 | } |
211 | } else { | 211 | } else { |
212 | qDebug("error fetching folders %s",m_imap->imap_response); | 212 | qDebug("error fetching folders %s",m_imap->imap_response); |
213 | } | 213 | } |
214 | mailimap_list_result_free( result ); | 214 | mailimap_list_result_free( result ); |
215 | return folders; | 215 | return folders; |
216 | } | 216 | } |
217 | 217 | ||
218 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 218 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
219 | { | 219 | { |
220 | RecMail * m = 0; | 220 | RecMail * m = 0; |
221 | mailimap_msg_att_item *item=0; | 221 | mailimap_msg_att_item *item=0; |
222 | clistcell *current,*c,*cf; | 222 | clistcell *current,*c,*cf; |
223 | mailimap_msg_att_dynamic*flist; | 223 | mailimap_msg_att_dynamic*flist; |
224 | mailimap_flag_fetch*cflag; | 224 | mailimap_flag_fetch*cflag; |
225 | int size; | 225 | int size; |
226 | QBitArray mFlags(7); | 226 | QBitArray mFlags(7); |
227 | QStringList addresslist; | 227 | QStringList addresslist; |
228 | 228 | ||
229 | if (!m_att) { | 229 | if (!m_att) { |
230 | return m; | 230 | return m; |
231 | } | 231 | } |
232 | m = new RecMail(); | 232 | m = new RecMail(); |
233 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 233 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
234 | current = c; | 234 | current = c; |
235 | size = 0; | 235 | size = 0; |
236 | item = (mailimap_msg_att_item*)current->data; | 236 | item = (mailimap_msg_att_item*)current->data; |
237 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 237 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
238 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 238 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
239 | if (!flist->att_list) { | 239 | if (!flist->att_list) { |
240 | continue; | 240 | continue; |
241 | } | 241 | } |
242 | cf = flist->att_list->first; | 242 | cf = flist->att_list->first; |
243 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 243 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
244 | cflag = (mailimap_flag_fetch*)cf->data; | 244 | cflag = (mailimap_flag_fetch*)cf->data; |
245 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 245 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
246 | switch (cflag->fl_flag->fl_type) { | 246 | switch (cflag->fl_flag->fl_type) { |
247 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 247 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
248 | mFlags.setBit(FLAG_ANSWERED); | 248 | mFlags.setBit(FLAG_ANSWERED); |
249 | break; | 249 | break; |
250 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 250 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
251 | mFlags.setBit(FLAG_FLAGGED); | 251 | mFlags.setBit(FLAG_FLAGGED); |
252 | break; | 252 | break; |
253 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 253 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
254 | mFlags.setBit(FLAG_DELETED); | 254 | mFlags.setBit(FLAG_DELETED); |
255 | break; | 255 | break; |
256 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 256 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
257 | mFlags.setBit(FLAG_SEEN); | 257 | mFlags.setBit(FLAG_SEEN); |
258 | break; | 258 | break; |
259 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 259 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
260 | mFlags.setBit(FLAG_DRAFT); | 260 | mFlags.setBit(FLAG_DRAFT); |
261 | break; | 261 | break; |
262 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 262 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
263 | break; | 263 | break; |
264 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 264 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
265 | break; | 265 | break; |
266 | default: | 266 | default: |
267 | break; | 267 | break; |
268 | } | 268 | } |
269 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 269 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
270 | mFlags.setBit(FLAG_RECENT); | 270 | mFlags.setBit(FLAG_RECENT); |
271 | } | 271 | } |
272 | } | 272 | } |
273 | continue; | 273 | continue; |
274 | } | 274 | } |
275 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 275 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
276 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 276 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
277 | m->setDate(head->env_date); | 277 | m->setDate(head->env_date); |
278 | m->setSubject(head->env_subject); | 278 | m->setSubject(head->env_subject); |
279 | if (head->env_from!=NULL) { | 279 | if (head->env_from!=NULL) { |
280 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 280 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
281 | if (addresslist.count()) { | 281 | if (addresslist.count()) { |
282 | m->setFrom(addresslist.first()); | 282 | m->setFrom(addresslist.first()); |
283 | } | 283 | } |
284 | } | 284 | } |
285 | if (head->env_to!=NULL) { | 285 | if (head->env_to!=NULL) { |
286 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 286 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
287 | m->setTo(addresslist); | 287 | m->setTo(addresslist); |
288 | } | 288 | } |
289 | if (head->env_cc!=NULL) { | 289 | if (head->env_cc!=NULL) { |
290 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 290 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
291 | m->setCC(addresslist); | 291 | m->setCC(addresslist); |
292 | } | 292 | } |
293 | if (head->env_bcc!=NULL) { | 293 | if (head->env_bcc!=NULL) { |
294 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 294 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
295 | m->setBcc(addresslist); | 295 | m->setBcc(addresslist); |
296 | } | 296 | } |
297 | if (head->env_reply_to!=NULL) { | 297 | if (head->env_reply_to!=NULL) { |
298 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 298 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
299 | if (addresslist.count()) { | 299 | if (addresslist.count()) { |
300 | m->setReplyto(addresslist.first()); | 300 | m->setReplyto(addresslist.first()); |
301 | } | 301 | } |
302 | } | 302 | } |
303 | m->setMsgid(QString(head->env_message_id)); | 303 | m->setMsgid(QString(head->env_message_id)); |
304 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 304 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
305 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | ||
306 | #if 0 | 305 | #if 0 |
306 | |||
307 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | ||
307 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 308 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
308 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); | 309 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); |
309 | qDebug(da.toString()); | 310 | qDebug(da.toString()); |
310 | #endif | 311 | #endif |
311 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 312 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
312 | size = item->att_data.att_static->att_data.att_rfc822_size; | 313 | size = item->att_data.att_static->att_data.att_rfc822_size; |
313 | } | 314 | } |
314 | } | 315 | } |
315 | /* msg is already deleted */ | 316 | /* msg is already deleted */ |
316 | if (mFlags.testBit(FLAG_DELETED) && m) { | 317 | if (mFlags.testBit(FLAG_DELETED) && m) { |
317 | delete m; | 318 | delete m; |
318 | m = 0; | 319 | m = 0; |
319 | } | 320 | } |
320 | if (m) { | 321 | if (m) { |
321 | m->setFlags(mFlags); | 322 | m->setFlags(mFlags); |
322 | m->setMsgsize(size); | 323 | m->setMsgsize(size); |
323 | } | 324 | } |
324 | return m; | 325 | return m; |
325 | } | 326 | } |
326 | 327 | ||
327 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 328 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
328 | { | 329 | { |
329 | RecBody body; | 330 | RecBody body; |
330 | const char *mb; | 331 | const char *mb; |
331 | int err = MAILIMAP_NO_ERROR; | 332 | int err = MAILIMAP_NO_ERROR; |
332 | clist *result; | 333 | clist *result; |
333 | clistcell *current; | 334 | clistcell *current; |
334 | mailimap_fetch_att *fetchAtt; | 335 | mailimap_fetch_att *fetchAtt; |
335 | mailimap_fetch_type *fetchType; | 336 | mailimap_fetch_type *fetchType; |
336 | mailimap_set *set; | 337 | mailimap_set *set; |
337 | mailimap_body*body_desc; | 338 | mailimap_body*body_desc; |
338 | 339 | ||
339 | mb = mail.getMbox().latin1(); | 340 | mb = mail.getMbox().latin1(); |
340 | 341 | ||
341 | login(); | 342 | login(); |
342 | if (!m_imap) { | 343 | if (!m_imap) { |
343 | return body; | 344 | return body; |
344 | } | 345 | } |
345 | 346 | ||
346 | err = mailimap_select( m_imap, (char*)mb); | 347 | err = mailimap_select( m_imap, (char*)mb); |
347 | if ( err != MAILIMAP_NO_ERROR ) { | 348 | if ( err != MAILIMAP_NO_ERROR ) { |
348 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 349 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
349 | return body; | 350 | return body; |
350 | } | 351 | } |
351 | 352 | ||
352 | result = clist_new(); | 353 | result = clist_new(); |
353 | /* the range has to start at 1!!! not with 0!!!! */ | 354 | /* the range has to start at 1!!! not with 0!!!! */ |
354 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 355 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
355 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 356 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
356 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 357 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
357 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 358 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
358 | mailimap_set_free( set ); | 359 | mailimap_set_free( set ); |
359 | mailimap_fetch_type_free( fetchType ); | 360 | mailimap_fetch_type_free( fetchType ); |
360 | 361 | ||
361 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 362 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
362 | mailimap_msg_att * msg_att; | 363 | mailimap_msg_att * msg_att; |
363 | msg_att = (mailimap_msg_att*)current->data; | 364 | msg_att = (mailimap_msg_att*)current->data; |
364 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 365 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
365 | body_desc = item->att_data.att_static->att_data.att_body; | 366 | body_desc = item->att_data.att_static->att_data.att_body; |
366 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 367 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
367 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 368 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
368 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | 369 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
369 | qDebug("Mulitpart mail"); | 370 | qDebug("Mulitpart mail"); |
370 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | 371 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); |
371 | } | 372 | } |
372 | } else { | 373 | } else { |
373 | qDebug("error fetching body: %s",m_imap->imap_response); | 374 | qDebug("error fetching body: %s",m_imap->imap_response); |
374 | } | 375 | } |
375 | mailimap_fetch_list_free(result); | 376 | mailimap_fetch_list_free(result); |
376 | return body; | 377 | return body; |
377 | } | 378 | } |
378 | 379 | ||
379 | /* this routine is just called when the mail has only ONE part. | 380 | /* this routine is just called when the mail has only ONE part. |
380 | for filling the parts of a multi-part-message there are other | 381 | for filling the parts of a multi-part-message there are other |
381 | routines 'cause we can not simply fetch the whole body. */ | 382 | routines 'cause we can not simply fetch the whole body. */ |
382 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 383 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
383 | { | 384 | { |
384 | if (!mailDescription) { | 385 | if (!mailDescription) { |
385 | return; | 386 | return; |
386 | } | 387 | } |
387 | QString sub,body_text; | 388 | QString sub,body_text; |
388 | RecPart singlePart; | 389 | RecPart singlePart; |
389 | QValueList<int> path; | 390 | QValueList<int> path; |
390 | fillSinglePart(singlePart,mailDescription); | 391 | fillSinglePart(singlePart,mailDescription); |
391 | switch (mailDescription->bd_type) { | 392 | switch (mailDescription->bd_type) { |
392 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 393 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
393 | path.append(1); | 394 | path.append(1); |
394 | body_text = fetchPart(mail,path,true); | 395 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); |
395 | if (singlePart.Encoding()=="quoted-printable") { | ||
396 | body_text = decode_quoted_printable(body_text.latin1()); | ||
397 | } | ||
398 | target_body.setBodytext(body_text); | 396 | target_body.setBodytext(body_text); |
399 | target_body.setDescription(singlePart); | 397 | target_body.setDescription(singlePart); |
400 | break; | 398 | break; |
401 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 399 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
402 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | 400 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); |
403 | path.append(1); | 401 | path.append(1); |
404 | body_text = fetchPart(mail,path,true); | 402 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); |
405 | if (singlePart.Encoding()=="quoted-printable") { | ||
406 | body_text = decode_quoted_printable(body_text.latin1()); | ||
407 | } | ||
408 | target_body.setBodytext(body_text); | 403 | target_body.setBodytext(body_text); |
409 | target_body.setDescription(singlePart); | 404 | target_body.setDescription(singlePart); |
410 | break; | 405 | break; |
411 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 406 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
412 | qDebug("Single attachment"); | 407 | qDebug("Single attachment"); |
413 | target_body.setBodytext(""); | 408 | target_body.setBodytext(""); |
414 | target_body.addPart(singlePart); | 409 | target_body.addPart(singlePart); |
415 | break; | 410 | break; |
416 | default: | 411 | default: |
417 | break; | 412 | break; |
418 | } | 413 | } |
419 | 414 | ||
420 | return; | 415 | return; |
421 | } | 416 | } |
422 | 417 | ||
423 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 418 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
424 | { | 419 | { |
425 | QStringList l; | 420 | QStringList l; |
426 | QString from; | 421 | QString from; |
427 | bool named_from; | 422 | bool named_from; |
428 | clistcell *current = NULL; | 423 | clistcell *current = NULL; |
429 | mailimap_address * current_address=NULL; | 424 | mailimap_address * current_address=NULL; |
430 | if (!list) { | 425 | if (!list) { |
431 | return l; | 426 | return l; |
432 | } | 427 | } |
433 | unsigned int count = 0; | 428 | unsigned int count = 0; |
434 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 429 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
435 | from = ""; | 430 | from = ""; |
436 | named_from = false; | 431 | named_from = false; |
437 | current_address=(mailimap_address*)current->data; | 432 | current_address=(mailimap_address*)current->data; |
438 | if (current_address->ad_personal_name){ | 433 | if (current_address->ad_personal_name){ |
439 | from+=QString(current_address->ad_personal_name); | 434 | from+=QString(current_address->ad_personal_name); |
440 | from+=" "; | 435 | from+=" "; |
441 | named_from = true; | 436 | named_from = true; |
442 | } | 437 | } |
443 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 438 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
444 | from+="<"; | 439 | from+="<"; |
445 | } | 440 | } |
446 | if (current_address->ad_mailbox_name) { | 441 | if (current_address->ad_mailbox_name) { |
447 | from+=QString(current_address->ad_mailbox_name); | 442 | from+=QString(current_address->ad_mailbox_name); |
448 | from+="@"; | 443 | from+="@"; |
449 | } | 444 | } |
450 | if (current_address->ad_host_name) { | 445 | if (current_address->ad_host_name) { |
451 | from+=QString(current_address->ad_host_name); | 446 | from+=QString(current_address->ad_host_name); |
452 | } | 447 | } |
453 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 448 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
454 | from+=">"; | 449 | from+=">"; |
455 | } | 450 | } |
456 | l.append(QString(from)); | 451 | l.append(QString(from)); |
457 | if (++count > 99) { | 452 | if (++count > 99) { |
458 | break; | 453 | break; |
459 | } | 454 | } |
460 | } | 455 | } |
461 | return l; | 456 | return l; |
462 | } | 457 | } |
463 | 458 | ||
464 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 459 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
465 | { | 460 | { |
466 | QString body(""); | 461 | encodedString*res=new encodedString; |
467 | const char*mb; | 462 | const char*mb; |
468 | int err; | 463 | int err; |
469 | mailimap_fetch_type *fetchType; | 464 | mailimap_fetch_type *fetchType; |
470 | mailimap_set *set; | 465 | mailimap_set *set; |
471 | clistcell*current,*cur; | 466 | clistcell*current,*cur; |
472 | 467 | ||
473 | login(); | 468 | login(); |
474 | if (!m_imap) { | 469 | if (!m_imap) { |
475 | return body; | 470 | return res; |
476 | } | 471 | } |
477 | if (!internal_call) { | 472 | if (!internal_call) { |
478 | mb = mail.getMbox().latin1(); | 473 | mb = mail.getMbox().latin1(); |
479 | err = mailimap_select( m_imap, (char*)mb); | 474 | err = mailimap_select( m_imap, (char*)mb); |
480 | if ( err != MAILIMAP_NO_ERROR ) { | 475 | if ( err != MAILIMAP_NO_ERROR ) { |
481 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 476 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
482 | return body; | 477 | return res; |
483 | } | 478 | } |
484 | } | 479 | } |
485 | set = mailimap_set_new_single(mail.getNumber()); | 480 | set = mailimap_set_new_single(mail.getNumber()); |
486 | clist*id_list=clist_new(); | 481 | clist*id_list=clist_new(); |
487 | for (unsigned j=0; j < path.count();++j) { | 482 | for (unsigned j=0; j < path.count();++j) { |
488 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 483 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
489 | *p_id = path[j]; | 484 | *p_id = path[j]; |
490 | clist_append(id_list,p_id); | 485 | clist_append(id_list,p_id); |
491 | } | 486 | } |
492 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 487 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
493 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 488 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
494 | mailimap_section * section = mailimap_section_new(section_spec); | 489 | mailimap_section * section = mailimap_section_new(section_spec); |
495 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 490 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
496 | 491 | ||
497 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 492 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
498 | 493 | ||
499 | clist*result = clist_new(); | 494 | clist*result = clist_new(); |
500 | 495 | ||
501 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 496 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
502 | mailimap_set_free( set ); | 497 | mailimap_set_free( set ); |
503 | mailimap_fetch_type_free( fetchType ); | 498 | mailimap_fetch_type_free( fetchType ); |
504 | 499 | ||
505 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 500 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
506 | mailimap_msg_att * msg_att; | 501 | mailimap_msg_att * msg_att; |
507 | msg_att = (mailimap_msg_att*)current->data; | 502 | msg_att = (mailimap_msg_att*)current->data; |
508 | mailimap_msg_att_item*msg_att_item; | 503 | mailimap_msg_att_item*msg_att_item; |
509 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 504 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
510 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 505 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
511 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 506 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
512 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 507 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
513 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 508 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
509 | /* detach - we take over the content */ | ||
514 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 510 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
515 | if (text) { | 511 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
516 | if (enc=="quoted-printable") { | ||
517 | body = decode_quoted_printable(text); | ||
518 | } else { | ||
519 | body = QString(text); | ||
520 | } | ||
521 | free(text); | ||
522 | } else { | ||
523 | body = ""; | ||
524 | } | ||
525 | } | 512 | } |
526 | } | 513 | } |
527 | } | 514 | } |
528 | |||
529 | } else { | 515 | } else { |
530 | qDebug("error fetching text: %s",m_imap->imap_response); | 516 | qDebug("error fetching text: %s",m_imap->imap_response); |
531 | } | 517 | } |
532 | mailimap_fetch_list_free(result); | 518 | mailimap_fetch_list_free(result); |
533 | return body; | 519 | return res; |
534 | } | 520 | } |
535 | 521 | ||
536 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 522 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
537 | { | 523 | { |
538 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 524 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
539 | if (!mailDescription||current_recursion==10) { | 525 | if (!mailDescription||current_recursion==10) { |
540 | return; | 526 | return; |
541 | } | 527 | } |
542 | clistcell*current; | 528 | clistcell*current; |
543 | mailimap_body*current_body; | 529 | mailimap_body*current_body; |
544 | unsigned int count = 0; | 530 | unsigned int count = 0; |
545 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 531 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
546 | /* the point in the message */ | 532 | /* the point in the message */ |
547 | ++count; | 533 | ++count; |
548 | current_body = (mailimap_body*)current->data; | 534 | current_body = (mailimap_body*)current->data; |
549 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 535 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
550 | QValueList<int>clist = recList; | 536 | QValueList<int>clist = recList; |
551 | clist.append(count); | 537 | clist.append(count); |
552 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); | 538 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); |
553 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 539 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ |
554 | RecPart currentPart; | 540 | RecPart currentPart; |
555 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 541 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
556 | QValueList<int>clist = recList; | 542 | QValueList<int>clist = recList; |
557 | clist.append(count); | 543 | clist.append(count); |
558 | /* important: Check for is NULL 'cause a body can be empty! */ | 544 | /* important: Check for is NULL 'cause a body can be empty! */ |
559 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 545 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
560 | QString body_text = fetchPart(mail,clist,true,currentPart.Encoding()); | 546 | QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding()); |
561 | target_body.setDescription(currentPart); | 547 | target_body.setDescription(currentPart); |
562 | target_body.setBodytext(body_text); | 548 | target_body.setBodytext(body_text); |
563 | } else { | 549 | } else { |
564 | QString id(""); | 550 | QString id(""); |
565 | for (unsigned int j = 0; j < clist.count();++j) { | 551 | for (unsigned int j = 0; j < clist.count();++j) { |
566 | id+=(j>0?" ":""); | 552 | id+=(j>0?" ":""); |
567 | id+=QString("%1").arg(clist[j]); | 553 | id+=QString("%1").arg(clist[j]); |
568 | } | 554 | } |
569 | qDebug("ID= %s",id.latin1()); | 555 | qDebug("ID= %s",id.latin1()); |
570 | currentPart.setIdentifier(id); | 556 | currentPart.setIdentifier(id); |
571 | currentPart.setPositionlist(clist); | 557 | currentPart.setPositionlist(clist); |
572 | target_body.addPart(currentPart); | 558 | target_body.addPart(currentPart); |
573 | } | 559 | } |
574 | } | 560 | } |
575 | } | 561 | } |
576 | } | 562 | } |
577 | 563 | ||
578 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 564 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
579 | { | 565 | { |
580 | if (!Description) { | 566 | if (!Description) { |
581 | return; | 567 | return; |
582 | } | 568 | } |
583 | switch (Description->bd_type) { | 569 | switch (Description->bd_type) { |
584 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 570 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
585 | target_part.setType("text"); | 571 | target_part.setType("text"); |
586 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 572 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
587 | break; | 573 | break; |
588 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 574 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
589 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 575 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
590 | break; | 576 | break; |
591 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 577 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
592 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 578 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
593 | break; | 579 | break; |
594 | default: | 580 | default: |
595 | break; | 581 | break; |
596 | } | 582 | } |
597 | } | 583 | } |
598 | 584 | ||
599 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 585 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
600 | { | 586 | { |
601 | if (!which) { | 587 | if (!which) { |
602 | return; | 588 | return; |
603 | } | 589 | } |
604 | QString sub; | 590 | QString sub; |
605 | sub = which->bd_media_text; | 591 | sub = which->bd_media_text; |
606 | target_part.setSubtype(sub.lower()); | 592 | target_part.setSubtype(sub.lower()); |
607 | target_part.setLines(which->bd_lines); | 593 | target_part.setLines(which->bd_lines); |
608 | fillBodyFields(target_part,which->bd_fields); | 594 | fillBodyFields(target_part,which->bd_fields); |
609 | } | 595 | } |
610 | 596 | ||
611 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 597 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
612 | { | 598 | { |
613 | if (!which) { | 599 | if (!which) { |
614 | return; | 600 | return; |
615 | } | 601 | } |
616 | // QString sub; | 602 | // QString sub; |
617 | // sub = which->bd_media_text; | 603 | // sub = which->bd_media_text; |
618 | // target_part.setSubtype(sub.lower()); | 604 | // target_part.setSubtype(sub.lower()); |
619 | qDebug("Message part"); | 605 | qDebug("Message part"); |
620 | /* we set this type to text/plain */ | 606 | /* we set this type to text/plain */ |
621 | target_part.setType("text"); | 607 | target_part.setType("text"); |
622 | target_part.setSubtype("plain"); | 608 | target_part.setSubtype("plain"); |
623 | target_part.setLines(which->bd_lines); | 609 | target_part.setLines(which->bd_lines); |
624 | fillBodyFields(target_part,which->bd_fields); | 610 | fillBodyFields(target_part,which->bd_fields); |
625 | } | 611 | } |
626 | 612 | ||
627 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 613 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
628 | { | 614 | { |
629 | if (!which) { | 615 | if (!which) { |
630 | return; | 616 | return; |
631 | } | 617 | } |
632 | QString type,sub; | 618 | QString type,sub; |
633 | switch (which->bd_media_basic->med_type) { | 619 | switch (which->bd_media_basic->med_type) { |
634 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 620 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
635 | type = "application"; | 621 | type = "application"; |
636 | break; | 622 | break; |
637 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 623 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
638 | type = "audio"; | 624 | type = "audio"; |
639 | break; | 625 | break; |
640 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 626 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
641 | type = "image"; | 627 | type = "image"; |
642 | break; | 628 | break; |
643 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 629 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
644 | type = "message"; | 630 | type = "message"; |
645 | break; | 631 | break; |
646 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 632 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
647 | type = "video"; | 633 | type = "video"; |
648 | break; | 634 | break; |
649 | case MAILIMAP_MEDIA_BASIC_OTHER: | 635 | case MAILIMAP_MEDIA_BASIC_OTHER: |
650 | default: | 636 | default: |
651 | if (which->bd_media_basic->med_basic_type) { | 637 | if (which->bd_media_basic->med_basic_type) { |
652 | type = which->bd_media_basic->med_basic_type; | 638 | type = which->bd_media_basic->med_basic_type; |
653 | } else { | 639 | } else { |
654 | type = ""; | 640 | type = ""; |
655 | } | 641 | } |
656 | break; | 642 | break; |
657 | } | 643 | } |
658 | if (which->bd_media_basic->med_subtype) { | 644 | if (which->bd_media_basic->med_subtype) { |
659 | sub = which->bd_media_basic->med_subtype; | 645 | sub = which->bd_media_basic->med_subtype; |
660 | } else { | 646 | } else { |
661 | sub = ""; | 647 | sub = ""; |
662 | } | 648 | } |
663 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | 649 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); |
664 | target_part.setType(type.lower()); | 650 | target_part.setType(type.lower()); |
665 | target_part.setSubtype(sub.lower()); | 651 | target_part.setSubtype(sub.lower()); |
666 | fillBodyFields(target_part,which->bd_fields); | 652 | fillBodyFields(target_part,which->bd_fields); |
667 | } | 653 | } |
668 | 654 | ||
669 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 655 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) |
670 | { | 656 | { |
671 | if (!which) return; | 657 | if (!which) return; |
672 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 658 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
673 | clistcell*cur; | 659 | clistcell*cur; |
674 | mailimap_single_body_fld_param*param=0; | 660 | mailimap_single_body_fld_param*param=0; |
675 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 661 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
676 | param = (mailimap_single_body_fld_param*)cur->data; | 662 | param = (mailimap_single_body_fld_param*)cur->data; |
677 | if (param) { | 663 | if (param) { |
678 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 664 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
679 | } | 665 | } |
680 | } | 666 | } |
681 | } | 667 | } |
682 | mailimap_body_fld_enc*enc = which->bd_encoding; | 668 | mailimap_body_fld_enc*enc = which->bd_encoding; |
683 | QString encoding(""); | 669 | QString encoding(""); |
684 | switch (enc->enc_type) { | 670 | switch (enc->enc_type) { |
685 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 671 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
686 | encoding = "7bit"; | 672 | encoding = "7bit"; |
687 | break; | 673 | break; |
688 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 674 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
689 | encoding = "8bit"; | 675 | encoding = "8bit"; |
690 | break; | 676 | break; |
691 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 677 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
692 | encoding="binary"; | 678 | encoding="binary"; |
693 | break; | 679 | break; |
694 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 680 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
695 | encoding="base64"; | 681 | encoding="base64"; |
696 | break; | 682 | break; |
697 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 683 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
698 | encoding="quoted-printable"; | 684 | encoding="quoted-printable"; |
699 | break; | 685 | break; |
700 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 686 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
701 | default: | 687 | default: |
702 | if (enc->enc_value) { | 688 | if (enc->enc_value) { |
703 | char*t=enc->enc_value; | 689 | char*t=enc->enc_value; |
704 | encoding=QString(enc->enc_value); | 690 | encoding=QString(enc->enc_value); |
705 | enc->enc_value=0L; | 691 | enc->enc_value=0L; |
706 | free(t); | 692 | free(t); |
707 | } | 693 | } |
708 | } | 694 | } |
709 | if (which->bd_description) { | 695 | if (which->bd_description) { |
710 | target_part.setDescription(QString(which->bd_description)); | 696 | target_part.setDescription(QString(which->bd_description)); |
711 | } | 697 | } |
712 | target_part.setEncoding(encoding); | 698 | target_part.setEncoding(encoding); |
713 | target_part.setSize(which->bd_size); | 699 | target_part.setSize(which->bd_size); |
714 | } | 700 | } |
715 | 701 | ||
716 | QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) | ||
717 | { | ||
718 | return fetchPart(mail,part.Positionlist(),false,part.Encoding()); | ||
719 | } | ||
720 | |||
721 | void IMAPwrapper::deleteMail(const RecMail&mail) | 702 | void IMAPwrapper::deleteMail(const RecMail&mail) |
722 | { | 703 | { |
723 | mailimap_flag_list*flist; | 704 | mailimap_flag_list*flist; |
724 | mailimap_set *set; | 705 | mailimap_set *set; |
725 | mailimap_store_att_flags * store_flags; | 706 | mailimap_store_att_flags * store_flags; |
726 | int err; | 707 | int err; |
727 | login(); | 708 | login(); |
728 | if (!m_imap) { | 709 | if (!m_imap) { |
729 | return; | 710 | return; |
730 | } | 711 | } |
731 | const char *mb = mail.getMbox().latin1(); | 712 | const char *mb = mail.getMbox().latin1(); |
732 | err = mailimap_select( m_imap, (char*)mb); | 713 | err = mailimap_select( m_imap, (char*)mb); |
733 | if ( err != MAILIMAP_NO_ERROR ) { | 714 | if ( err != MAILIMAP_NO_ERROR ) { |
734 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); | 715 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); |
735 | return; | 716 | return; |
736 | } | 717 | } |
737 | flist = mailimap_flag_list_new_empty(); | 718 | flist = mailimap_flag_list_new_empty(); |
738 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 719 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
739 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 720 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
740 | set = mailimap_set_new_single(mail.getNumber()); | 721 | set = mailimap_set_new_single(mail.getNumber()); |
741 | err = mailimap_store(m_imap,set,store_flags); | 722 | err = mailimap_store(m_imap,set,store_flags); |
742 | mailimap_set_free( set ); | 723 | mailimap_set_free( set ); |
743 | mailimap_store_att_flags_free(store_flags); | 724 | mailimap_store_att_flags_free(store_flags); |
744 | 725 | ||
745 | if (err != MAILIMAP_NO_ERROR) { | 726 | if (err != MAILIMAP_NO_ERROR) { |
746 | qDebug("error deleting mail: %s",m_imap->imap_response); | 727 | qDebug("error deleting mail: %s",m_imap->imap_response); |
747 | return; | 728 | return; |
748 | } | 729 | } |
749 | qDebug("deleting mail: %s",m_imap->imap_response); | 730 | qDebug("deleting mail: %s",m_imap->imap_response); |
750 | /* should we realy do that at this moment? */ | 731 | /* should we realy do that at this moment? */ |
751 | err = mailimap_expunge(m_imap); | 732 | err = mailimap_expunge(m_imap); |
752 | if (err != MAILIMAP_NO_ERROR) { | 733 | if (err != MAILIMAP_NO_ERROR) { |
753 | qDebug("error deleting mail: %s",m_imap->imap_response); | 734 | qDebug("error deleting mail: %s",m_imap->imap_response); |
754 | } | 735 | } |
755 | qDebug("Delete successfull %s",m_imap->imap_response); | 736 | qDebug("Delete successfull %s",m_imap->imap_response); |
756 | } | 737 | } |
757 | 738 | ||
758 | void IMAPwrapper::answeredMail(const RecMail&mail) | 739 | void IMAPwrapper::answeredMail(const RecMail&mail) |
759 | { | 740 | { |
760 | mailimap_flag_list*flist; | 741 | mailimap_flag_list*flist; |
761 | mailimap_set *set; | 742 | mailimap_set *set; |
762 | mailimap_store_att_flags * store_flags; | 743 | mailimap_store_att_flags * store_flags; |
763 | int err; | 744 | int err; |
764 | login(); | 745 | login(); |
765 | if (!m_imap) { | 746 | if (!m_imap) { |
766 | return; | 747 | return; |
767 | } | 748 | } |
768 | const char *mb = mail.getMbox().latin1(); | 749 | const char *mb = mail.getMbox().latin1(); |
769 | err = mailimap_select( m_imap, (char*)mb); | 750 | err = mailimap_select( m_imap, (char*)mb); |
770 | if ( err != MAILIMAP_NO_ERROR ) { | 751 | if ( err != MAILIMAP_NO_ERROR ) { |
771 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); | 752 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); |
772 | return; | 753 | return; |
773 | } | 754 | } |
774 | flist = mailimap_flag_list_new_empty(); | 755 | flist = mailimap_flag_list_new_empty(); |
775 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 756 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
776 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 757 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
777 | set = mailimap_set_new_single(mail.getNumber()); | 758 | set = mailimap_set_new_single(mail.getNumber()); |
778 | err = mailimap_store(m_imap,set,store_flags); | 759 | err = mailimap_store(m_imap,set,store_flags); |
779 | mailimap_set_free( set ); | 760 | mailimap_set_free( set ); |
780 | mailimap_store_att_flags_free(store_flags); | 761 | mailimap_store_att_flags_free(store_flags); |
781 | 762 | ||
782 | if (err != MAILIMAP_NO_ERROR) { | 763 | if (err != MAILIMAP_NO_ERROR) { |
783 | qDebug("error marking mail: %s",m_imap->imap_response); | 764 | qDebug("error marking mail: %s",m_imap->imap_response); |
784 | return; | 765 | return; |
785 | } | 766 | } |
786 | } | 767 | } |
768 | |||
769 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | ||
770 | { | ||
771 | QString body(""); | ||
772 | encodedString*res = fetchRawPart(mail,path,internal_call); | ||
773 | encodedString*r = decode_String(res,enc); | ||
774 | delete res; | ||
775 | if (r) { | ||
776 | if (r->Length()>0) { | ||
777 | body = r->Content(); | ||
778 | } | ||
779 | delete r; | ||
780 | } | ||
781 | return body; | ||
782 | } | ||
783 | |||
784 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | ||
785 | { | ||
786 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); | ||
787 | } | ||
788 | |||
789 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) | ||
790 | { | ||
791 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); | ||
792 | encodedString*r = decode_String(res,part.Encoding()); | ||
793 | delete res; | ||
794 | return r; | ||
795 | } | ||
796 | |||
797 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) | ||
798 | { | ||
799 | return fetchRawPart(mail,part.Positionlist(),false); | ||
800 | } | ||
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h index 768a517..aeebda8 100644 --- a/noncore/net/mail/imapwrapper.h +++ b/noncore/net/mail/imapwrapper.h | |||
@@ -1,56 +1,62 @@ | |||
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 | #include "abstractmail.h" | 6 | #include "abstractmail.h" |
7 | 7 | ||
8 | struct mailimap; | 8 | struct mailimap; |
9 | struct mailimap_body_type_1part; | 9 | struct mailimap_body_type_1part; |
10 | struct mailimap_body_type_text; | 10 | struct mailimap_body_type_text; |
11 | struct mailimap_body_type_basic; | 11 | struct mailimap_body_type_basic; |
12 | struct mailimap_body_type_msg; | 12 | struct mailimap_body_type_msg; |
13 | struct mailimap_body_type_mpart; | 13 | struct mailimap_body_type_mpart; |
14 | struct mailimap_body_fields; | 14 | struct mailimap_body_fields; |
15 | struct mailimap_msg_att; | 15 | struct mailimap_msg_att; |
16 | class encodedString; | ||
16 | 17 | ||
17 | class IMAPwrapper : public AbstractMail | 18 | class IMAPwrapper : public AbstractMail |
18 | { | 19 | { |
19 | Q_OBJECT | 20 | Q_OBJECT |
20 | public: | 21 | public: |
21 | IMAPwrapper( IMAPaccount *a ); | 22 | IMAPwrapper( IMAPaccount *a ); |
22 | virtual ~IMAPwrapper(); | 23 | virtual ~IMAPwrapper(); |
23 | virtual QList<Folder>* listFolders(); | 24 | virtual QList<Folder>* listFolders(); |
24 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); | 25 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); |
25 | virtual RecBody fetchBody(const RecMail&mail); | 26 | |
26 | virtual QString fetchPart(const RecMail&mail,const RecPart&part); | ||
27 | virtual void deleteMail(const RecMail&mail); | 27 | virtual void deleteMail(const RecMail&mail); |
28 | virtual void answeredMail(const RecMail&mail); | 28 | virtual void answeredMail(const RecMail&mail); |
29 | 29 | ||
30 | virtual RecBody fetchBody(const RecMail&mail); | ||
31 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); | ||
32 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); | ||
33 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); | ||
34 | |||
30 | static void imap_progress( size_t current, size_t maximum ); | 35 | static void imap_progress( size_t current, size_t maximum ); |
31 | 36 | ||
32 | protected: | 37 | protected: |
33 | RecMail*parse_list_result(mailimap_msg_att*); | 38 | RecMail*parse_list_result(mailimap_msg_att*); |
34 | void login(); | 39 | void login(); |
35 | void logout(); | 40 | void logout(); |
36 | 41 | ||
37 | virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); | 42 | virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); |
43 | virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); | ||
38 | 44 | ||
39 | void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); | 45 | void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); |
40 | void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); | 46 | void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); |
41 | 47 | ||
42 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); | 48 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); |
43 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); | 49 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); |
44 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); | 50 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); |
45 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); | 51 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); |
46 | 52 | ||
47 | /* just helpers */ | 53 | /* just helpers */ |
48 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); | 54 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); |
49 | static QStringList address_list_to_stringlist(clist*list); | 55 | static QStringList address_list_to_stringlist(clist*list); |
50 | 56 | ||
51 | 57 | ||
52 | IMAPaccount *account; | 58 | IMAPaccount *account; |
53 | mailimap *m_imap; | 59 | mailimap *m_imap; |
54 | }; | 60 | }; |
55 | 61 | ||
56 | #endif | 62 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp index 0bb2525..92a46f1 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.cpp +++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp | |||
@@ -1,34 +1,48 @@ | |||
1 | #include "abstractmail.h" | 1 | #include "abstractmail.h" |
2 | #include "imapwrapper.h" | 2 | #include "imapwrapper.h" |
3 | #include "pop3wrapper.h" | 3 | #include "pop3wrapper.h" |
4 | #include "mailtypes.h" | ||
4 | 5 | ||
5 | #include <qstring.h> | 6 | #include <qstring.h> |
6 | #include <stdlib.h> | 7 | #include <stdlib.h> |
7 | #include <libetpan/mailmime_content.h> | 8 | #include <libetpan/mailmime_content.h> |
8 | 9 | ||
9 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) | 10 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) |
10 | { | 11 | { |
11 | return new IMAPwrapper(a); | 12 | return new IMAPwrapper(a); |
12 | } | 13 | } |
13 | 14 | ||
14 | AbstractMail* AbstractMail::getWrapper(POP3account *a) | 15 | AbstractMail* AbstractMail::getWrapper(POP3account *a) |
15 | { | 16 | { |
16 | return new POP3wrapper(a); | 17 | return new POP3wrapper(a); |
17 | } | 18 | } |
18 | 19 | ||
19 | QString AbstractMail::decode_quoted_printable(const char*text) | 20 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) |
20 | { | 21 | { |
22 | qDebug("Decode string start"); | ||
21 | char*result_text; | 23 | char*result_text; |
22 | size_t index = 0; | 24 | size_t index = 0; |
23 | QString result = ""; | ||
24 | /* reset for recursive use! */ | 25 | /* reset for recursive use! */ |
25 | size_t target_length = 0; | 26 | size_t target_length = 0; |
26 | result_text = 0; | 27 | result_text = 0; |
27 | int err = mailmime_quoted_printable_body_parse(text,strlen(text), | 28 | int mimetype = MAILMIME_MECHANISM_7BIT; |
28 | &index,&result_text,&target_length,0); | 29 | if (enc.lower()=="quoted-printable") { |
29 | if (result_text) { | 30 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
30 | result = result_text; | 31 | } else if (enc.lower()=="base64") { |
31 | free(result_text); | 32 | mimetype = MAILMIME_MECHANISM_BASE64; |
33 | } else if (enc.lower()=="8bit") { | ||
34 | mimetype = MAILMIME_MECHANISM_8BIT; | ||
35 | } else if (enc.lower()=="binary") { | ||
36 | mimetype = MAILMIME_MECHANISM_BINARY; | ||
32 | } | 37 | } |
38 | |||
39 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, | ||
40 | &result_text,&target_length); | ||
41 | |||
42 | encodedString* result = new encodedString(); | ||
43 | if (err == MAILIMF_NO_ERROR) { | ||
44 | result->setContent(result_text,target_length); | ||
45 | } | ||
46 | qDebug("Decode string finished"); | ||
33 | return result; | 47 | return result; |
34 | } | 48 | } |
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h index 4473ad2..f1a8468 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.h +++ b/noncore/net/mail/libmailwrapper/abstractmail.h | |||
@@ -1,31 +1,35 @@ | |||
1 | #ifndef __abstract_mail_ | 1 | #ifndef __abstract_mail_ |
2 | #define __abstract_mail_ | 2 | #define __abstract_mail_ |
3 | 3 | ||
4 | #include <qobject.h> | 4 | #include <qobject.h> |
5 | #include "settings.h" | 5 | #include "settings.h" |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | class RecPart; | 9 | class RecPart; |
10 | class IMAPwrapper; | 10 | class IMAPwrapper; |
11 | class POP3wrapper; | 11 | class POP3wrapper; |
12 | class Folder; | 12 | class Folder; |
13 | class encodedString; | ||
13 | 14 | ||
14 | class AbstractMail:public QObject | 15 | class AbstractMail:public QObject |
15 | { | 16 | { |
16 | Q_OBJECT | 17 | Q_OBJECT |
17 | public: | 18 | public: |
18 | AbstractMail(){}; | 19 | AbstractMail(){}; |
19 | virtual ~AbstractMail(){} | 20 | virtual ~AbstractMail(){} |
20 | virtual QList<Folder>* listFolders()=0; | 21 | virtual QList<Folder>* listFolders()=0; |
21 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; | 22 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; |
22 | virtual RecBody fetchBody(const RecMail&mail)=0; | 23 | virtual RecBody fetchBody(const RecMail&mail)=0; |
23 | virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0; | 24 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; |
25 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; | ||
26 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; | ||
27 | |||
24 | virtual void deleteMail(const RecMail&mail)=0; | 28 | virtual void deleteMail(const RecMail&mail)=0; |
25 | virtual void answeredMail(const RecMail&mail)=0; | 29 | virtual void answeredMail(const RecMail&mail)=0; |
26 | 30 | ||
27 | static AbstractMail* getWrapper(IMAPaccount *a); | 31 | static AbstractMail* getWrapper(IMAPaccount *a); |
28 | static AbstractMail* getWrapper(POP3account *a); | 32 | static AbstractMail* getWrapper(POP3account *a); |
29 | static QString decode_quoted_printable(const char*text); | 33 | static encodedString*decode_String(const encodedString*text,const QString&enc); |
30 | }; | 34 | }; |
31 | #endif | 35 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index a4e6228..d56d7f9 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,786 +1,800 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include "imapwrapper.h" | 4 | #include "imapwrapper.h" |
5 | #include "mailtypes.h" | 5 | #include "mailtypes.h" |
6 | #include <libetpan/mailimap.h> | 6 | #include <libetpan/mailimap.h> |
7 | 7 | ||
8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
9 | : AbstractMail() | 9 | : AbstractMail() |
10 | { | 10 | { |
11 | account = a; | 11 | account = a; |
12 | m_imap = 0; | 12 | m_imap = 0; |
13 | } | 13 | } |
14 | 14 | ||
15 | IMAPwrapper::~IMAPwrapper() | 15 | IMAPwrapper::~IMAPwrapper() |
16 | { | 16 | { |
17 | logout(); | 17 | logout(); |
18 | } | 18 | } |
19 | 19 | ||
20 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 20 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
21 | { | 21 | { |
22 | qDebug( "IMAP: %i of %i", current, maximum ); | 22 | qDebug( "IMAP: %i of %i", current, maximum ); |
23 | } | 23 | } |
24 | 24 | ||
25 | void IMAPwrapper::login() | 25 | void IMAPwrapper::login() |
26 | { | 26 | { |
27 | const char *server, *user, *pass; | 27 | const char *server, *user, *pass; |
28 | uint16_t port; | 28 | uint16_t port; |
29 | int err = MAILIMAP_NO_ERROR; | 29 | int err = MAILIMAP_NO_ERROR; |
30 | 30 | ||
31 | /* we are connected this moment */ | 31 | /* we are connected this moment */ |
32 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 32 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
33 | if (m_imap) { | 33 | if (m_imap) { |
34 | mailstream_flush(m_imap->imap_stream); | 34 | mailstream_flush(m_imap->imap_stream); |
35 | return; | 35 | return; |
36 | } | 36 | } |
37 | server = account->getServer().latin1(); | 37 | server = account->getServer().latin1(); |
38 | port = account->getPort().toUInt(); | 38 | port = account->getPort().toUInt(); |
39 | user = account->getUser().latin1(); | 39 | user = account->getUser().latin1(); |
40 | pass = account->getPassword().latin1(); | 40 | pass = account->getPassword().latin1(); |
41 | 41 | ||
42 | m_imap = mailimap_new( 20, &imap_progress ); | 42 | m_imap = mailimap_new( 20, &imap_progress ); |
43 | /* connect */ | 43 | /* connect */ |
44 | if (account->getSSL()) { | 44 | if (account->getSSL()) { |
45 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 45 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
46 | } else { | 46 | } else { |
47 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 47 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
48 | } | 48 | } |
49 | 49 | ||
50 | if ( err != MAILIMAP_NO_ERROR && | 50 | if ( err != MAILIMAP_NO_ERROR && |
51 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 51 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
52 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 52 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
53 | qDebug("error connecting server: %s",m_imap->imap_response); | 53 | qDebug("error connecting server: %s",m_imap->imap_response); |
54 | mailimap_free( m_imap ); | 54 | mailimap_free( m_imap ); |
55 | m_imap = 0; | 55 | m_imap = 0; |
56 | return; | 56 | return; |
57 | } | 57 | } |
58 | 58 | ||
59 | /* login */ | 59 | /* login */ |
60 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 60 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
61 | if ( err != MAILIMAP_NO_ERROR ) { | 61 | if ( err != MAILIMAP_NO_ERROR ) { |
62 | qDebug("error logging in imap: %s",m_imap->imap_response); | 62 | qDebug("error logging in imap: %s",m_imap->imap_response); |
63 | err = mailimap_close( m_imap ); | 63 | err = mailimap_close( m_imap ); |
64 | mailimap_free( m_imap ); | 64 | mailimap_free( m_imap ); |
65 | m_imap = 0; | 65 | m_imap = 0; |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | void IMAPwrapper::logout() | 69 | void IMAPwrapper::logout() |
70 | { | 70 | { |
71 | int err = MAILIMAP_NO_ERROR; | 71 | int err = MAILIMAP_NO_ERROR; |
72 | if (!m_imap) return; | 72 | if (!m_imap) return; |
73 | err = mailimap_logout( m_imap ); | 73 | err = mailimap_logout( m_imap ); |
74 | err = mailimap_close( m_imap ); | 74 | err = mailimap_close( m_imap ); |
75 | mailimap_free( m_imap ); | 75 | mailimap_free( m_imap ); |
76 | m_imap = 0; | 76 | m_imap = 0; |
77 | } | 77 | } |
78 | 78 | ||
79 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 79 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
80 | { | 80 | { |
81 | const char *mb; | 81 | const char *mb; |
82 | int err = MAILIMAP_NO_ERROR; | 82 | int err = MAILIMAP_NO_ERROR; |
83 | clist *result; | 83 | clist *result; |
84 | clistcell *current; | 84 | clistcell *current; |
85 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; | 85 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; |
86 | mailimap_fetch_type *fetchType; | 86 | mailimap_fetch_type *fetchType; |
87 | mailimap_set *set; | 87 | mailimap_set *set; |
88 | 88 | ||
89 | mb = mailbox.latin1(); | 89 | mb = mailbox.latin1(); |
90 | login(); | 90 | login(); |
91 | if (!m_imap) { | 91 | if (!m_imap) { |
92 | return; | 92 | return; |
93 | } | 93 | } |
94 | /* select mailbox READONLY for operations */ | 94 | /* select mailbox READONLY for operations */ |
95 | err = mailimap_examine( m_imap, (char*)mb); | 95 | err = mailimap_examine( m_imap, (char*)mb); |
96 | if ( err != MAILIMAP_NO_ERROR ) { | 96 | if ( err != MAILIMAP_NO_ERROR ) { |
97 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 97 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
98 | return; | 98 | return; |
99 | } | 99 | } |
100 | 100 | ||
101 | int last = m_imap->imap_selection_info->sel_exists; | 101 | int last = m_imap->imap_selection_info->sel_exists; |
102 | 102 | ||
103 | if (last == 0) { | 103 | if (last == 0) { |
104 | qDebug("mailbox has no mails"); | 104 | qDebug("mailbox has no mails"); |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | 107 | ||
108 | result = clist_new(); | 108 | result = clist_new(); |
109 | /* the range has to start at 1!!! not with 0!!!! */ | 109 | /* the range has to start at 1!!! not with 0!!!! */ |
110 | set = mailimap_set_new_interval( 1, last ); | 110 | set = mailimap_set_new_interval( 1, last ); |
111 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 111 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
114 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 114 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
115 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 115 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
116 | 116 | ||
117 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 117 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
118 | mailimap_set_free( set ); | 118 | mailimap_set_free( set ); |
119 | mailimap_fetch_type_free( fetchType ); | 119 | mailimap_fetch_type_free( fetchType ); |
120 | 120 | ||
121 | QString date,subject,from; | 121 | QString date,subject,from; |
122 | 122 | ||
123 | if ( err == MAILIMAP_NO_ERROR ) { | 123 | if ( err == MAILIMAP_NO_ERROR ) { |
124 | 124 | ||
125 | mailimap_msg_att * msg_att; | 125 | mailimap_msg_att * msg_att; |
126 | int i = 0; | 126 | int i = 0; |
127 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 127 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
128 | ++i; | 128 | ++i; |
129 | msg_att = (mailimap_msg_att*)current->data; | 129 | msg_att = (mailimap_msg_att*)current->data; |
130 | RecMail*m = parse_list_result(msg_att); | 130 | RecMail*m = parse_list_result(msg_att); |
131 | if (m) { | 131 | if (m) { |
132 | m->setNumber(i); | 132 | m->setNumber(i); |
133 | m->setMbox(mailbox); | 133 | m->setMbox(mailbox); |
134 | m->setWrapper(this); | 134 | m->setWrapper(this); |
135 | target.append(m); | 135 | target.append(m); |
136 | } | 136 | } |
137 | } | 137 | } |
138 | } else { | 138 | } else { |
139 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 139 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
140 | } | 140 | } |
141 | mailimap_fetch_list_free(result); | 141 | mailimap_fetch_list_free(result); |
142 | } | 142 | } |
143 | 143 | ||
144 | QList<Folder>* IMAPwrapper::listFolders() | 144 | QList<Folder>* IMAPwrapper::listFolders() |
145 | { | 145 | { |
146 | const char *path, *mask; | 146 | const char *path, *mask; |
147 | int err = MAILIMAP_NO_ERROR; | 147 | int err = MAILIMAP_NO_ERROR; |
148 | clist *result; | 148 | clist *result; |
149 | clistcell *current; | 149 | clistcell *current; |
150 | 150 | ||
151 | QList<Folder> * folders = new QList<Folder>(); | 151 | QList<Folder> * folders = new QList<Folder>(); |
152 | folders->setAutoDelete( false ); | 152 | folders->setAutoDelete( false ); |
153 | login(); | 153 | login(); |
154 | if (!m_imap) { | 154 | if (!m_imap) { |
155 | return folders; | 155 | return folders; |
156 | } | 156 | } |
157 | 157 | ||
158 | /* | 158 | /* |
159 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 159 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
160 | * We must not forget to filter them out in next loop! | 160 | * We must not forget to filter them out in next loop! |
161 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 161 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
162 | */ | 162 | */ |
163 | QString temp; | 163 | QString temp; |
164 | mask = "INBOX" ; | 164 | mask = "INBOX" ; |
165 | result = clist_new(); | 165 | result = clist_new(); |
166 | mailimap_mailbox_list *list; | 166 | mailimap_mailbox_list *list; |
167 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 167 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
168 | if ( err == MAILIMAP_NO_ERROR ) { | 168 | if ( err == MAILIMAP_NO_ERROR ) { |
169 | current = result->first; | 169 | current = result->first; |
170 | for ( int i = result->count; i > 0; i-- ) { | 170 | for ( int i = result->count; i > 0; i-- ) { |
171 | list = (mailimap_mailbox_list *) current->data; | 171 | list = (mailimap_mailbox_list *) current->data; |
172 | // it is better use the deep copy mechanism of qt itself | 172 | // it is better use the deep copy mechanism of qt itself |
173 | // instead of using strdup! | 173 | // instead of using strdup! |
174 | temp = list->mb_name; | 174 | temp = list->mb_name; |
175 | folders->append( new IMAPFolder(temp)); | 175 | folders->append( new IMAPFolder(temp)); |
176 | current = current->next; | 176 | current = current->next; |
177 | } | 177 | } |
178 | } else { | 178 | } else { |
179 | qDebug("error fetching folders: %s",m_imap->imap_response); | 179 | qDebug("error fetching folders: %s",m_imap->imap_response); |
180 | } | 180 | } |
181 | mailimap_list_result_free( result ); | 181 | mailimap_list_result_free( result ); |
182 | 182 | ||
183 | /* | 183 | /* |
184 | * second stage - get the other then inbox folders | 184 | * second stage - get the other then inbox folders |
185 | */ | 185 | */ |
186 | mask = "*" ; | 186 | mask = "*" ; |
187 | path = account->getPrefix().latin1(); | 187 | path = account->getPrefix().latin1(); |
188 | if (!path) path = ""; | 188 | if (!path) path = ""; |
189 | result = clist_new(); | 189 | result = clist_new(); |
190 | qDebug(path); | 190 | qDebug(path); |
191 | bool selectable = true; | 191 | bool selectable = true; |
192 | mailimap_mbx_list_flags*bflags; | 192 | mailimap_mbx_list_flags*bflags; |
193 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 193 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
194 | if ( err == MAILIMAP_NO_ERROR ) { | 194 | if ( err == MAILIMAP_NO_ERROR ) { |
195 | current = result->first; | 195 | current = result->first; |
196 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 196 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
197 | list = (mailimap_mailbox_list *) current->data; | 197 | list = (mailimap_mailbox_list *) current->data; |
198 | // it is better use the deep copy mechanism of qt itself | 198 | // it is better use the deep copy mechanism of qt itself |
199 | // instead of using strdup! | 199 | // instead of using strdup! |
200 | temp = list->mb_name; | 200 | temp = list->mb_name; |
201 | if (temp.lower()=="inbox") | 201 | if (temp.lower()=="inbox") |
202 | continue; | 202 | continue; |
203 | if (temp.lower()==account->getPrefix().lower()) | 203 | if (temp.lower()==account->getPrefix().lower()) |
204 | continue; | 204 | continue; |
205 | if ( (bflags = list->mb_flag) ) { | 205 | if ( (bflags = list->mb_flag) ) { |
206 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 206 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
207 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 207 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
208 | } | 208 | } |
209 | folders->append(new IMAPFolder(temp,selectable,account->getPrefix())); | 209 | folders->append(new IMAPFolder(temp,selectable,account->getPrefix())); |
210 | } | 210 | } |
211 | } else { | 211 | } else { |
212 | qDebug("error fetching folders %s",m_imap->imap_response); | 212 | qDebug("error fetching folders %s",m_imap->imap_response); |
213 | } | 213 | } |
214 | mailimap_list_result_free( result ); | 214 | mailimap_list_result_free( result ); |
215 | return folders; | 215 | return folders; |
216 | } | 216 | } |
217 | 217 | ||
218 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 218 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
219 | { | 219 | { |
220 | RecMail * m = 0; | 220 | RecMail * m = 0; |
221 | mailimap_msg_att_item *item=0; | 221 | mailimap_msg_att_item *item=0; |
222 | clistcell *current,*c,*cf; | 222 | clistcell *current,*c,*cf; |
223 | mailimap_msg_att_dynamic*flist; | 223 | mailimap_msg_att_dynamic*flist; |
224 | mailimap_flag_fetch*cflag; | 224 | mailimap_flag_fetch*cflag; |
225 | int size; | 225 | int size; |
226 | QBitArray mFlags(7); | 226 | QBitArray mFlags(7); |
227 | QStringList addresslist; | 227 | QStringList addresslist; |
228 | 228 | ||
229 | if (!m_att) { | 229 | if (!m_att) { |
230 | return m; | 230 | return m; |
231 | } | 231 | } |
232 | m = new RecMail(); | 232 | m = new RecMail(); |
233 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 233 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
234 | current = c; | 234 | current = c; |
235 | size = 0; | 235 | size = 0; |
236 | item = (mailimap_msg_att_item*)current->data; | 236 | item = (mailimap_msg_att_item*)current->data; |
237 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 237 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
238 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 238 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
239 | if (!flist->att_list) { | 239 | if (!flist->att_list) { |
240 | continue; | 240 | continue; |
241 | } | 241 | } |
242 | cf = flist->att_list->first; | 242 | cf = flist->att_list->first; |
243 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 243 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
244 | cflag = (mailimap_flag_fetch*)cf->data; | 244 | cflag = (mailimap_flag_fetch*)cf->data; |
245 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 245 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
246 | switch (cflag->fl_flag->fl_type) { | 246 | switch (cflag->fl_flag->fl_type) { |
247 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 247 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
248 | mFlags.setBit(FLAG_ANSWERED); | 248 | mFlags.setBit(FLAG_ANSWERED); |
249 | break; | 249 | break; |
250 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 250 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
251 | mFlags.setBit(FLAG_FLAGGED); | 251 | mFlags.setBit(FLAG_FLAGGED); |
252 | break; | 252 | break; |
253 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 253 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
254 | mFlags.setBit(FLAG_DELETED); | 254 | mFlags.setBit(FLAG_DELETED); |
255 | break; | 255 | break; |
256 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 256 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
257 | mFlags.setBit(FLAG_SEEN); | 257 | mFlags.setBit(FLAG_SEEN); |
258 | break; | 258 | break; |
259 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 259 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
260 | mFlags.setBit(FLAG_DRAFT); | 260 | mFlags.setBit(FLAG_DRAFT); |
261 | break; | 261 | break; |
262 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 262 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
263 | break; | 263 | break; |
264 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 264 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
265 | break; | 265 | break; |
266 | default: | 266 | default: |
267 | break; | 267 | break; |
268 | } | 268 | } |
269 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 269 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
270 | mFlags.setBit(FLAG_RECENT); | 270 | mFlags.setBit(FLAG_RECENT); |
271 | } | 271 | } |
272 | } | 272 | } |
273 | continue; | 273 | continue; |
274 | } | 274 | } |
275 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 275 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
276 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 276 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
277 | m->setDate(head->env_date); | 277 | m->setDate(head->env_date); |
278 | m->setSubject(head->env_subject); | 278 | m->setSubject(head->env_subject); |
279 | if (head->env_from!=NULL) { | 279 | if (head->env_from!=NULL) { |
280 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 280 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
281 | if (addresslist.count()) { | 281 | if (addresslist.count()) { |
282 | m->setFrom(addresslist.first()); | 282 | m->setFrom(addresslist.first()); |
283 | } | 283 | } |
284 | } | 284 | } |
285 | if (head->env_to!=NULL) { | 285 | if (head->env_to!=NULL) { |
286 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 286 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
287 | m->setTo(addresslist); | 287 | m->setTo(addresslist); |
288 | } | 288 | } |
289 | if (head->env_cc!=NULL) { | 289 | if (head->env_cc!=NULL) { |
290 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 290 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
291 | m->setCC(addresslist); | 291 | m->setCC(addresslist); |
292 | } | 292 | } |
293 | if (head->env_bcc!=NULL) { | 293 | if (head->env_bcc!=NULL) { |
294 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 294 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
295 | m->setBcc(addresslist); | 295 | m->setBcc(addresslist); |
296 | } | 296 | } |
297 | if (head->env_reply_to!=NULL) { | 297 | if (head->env_reply_to!=NULL) { |
298 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 298 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
299 | if (addresslist.count()) { | 299 | if (addresslist.count()) { |
300 | m->setReplyto(addresslist.first()); | 300 | m->setReplyto(addresslist.first()); |
301 | } | 301 | } |
302 | } | 302 | } |
303 | m->setMsgid(QString(head->env_message_id)); | 303 | m->setMsgid(QString(head->env_message_id)); |
304 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 304 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
305 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | ||
306 | #if 0 | 305 | #if 0 |
306 | |||
307 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | ||
307 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 308 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
308 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); | 309 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); |
309 | qDebug(da.toString()); | 310 | qDebug(da.toString()); |
310 | #endif | 311 | #endif |
311 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 312 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
312 | size = item->att_data.att_static->att_data.att_rfc822_size; | 313 | size = item->att_data.att_static->att_data.att_rfc822_size; |
313 | } | 314 | } |
314 | } | 315 | } |
315 | /* msg is already deleted */ | 316 | /* msg is already deleted */ |
316 | if (mFlags.testBit(FLAG_DELETED) && m) { | 317 | if (mFlags.testBit(FLAG_DELETED) && m) { |
317 | delete m; | 318 | delete m; |
318 | m = 0; | 319 | m = 0; |
319 | } | 320 | } |
320 | if (m) { | 321 | if (m) { |
321 | m->setFlags(mFlags); | 322 | m->setFlags(mFlags); |
322 | m->setMsgsize(size); | 323 | m->setMsgsize(size); |
323 | } | 324 | } |
324 | return m; | 325 | return m; |
325 | } | 326 | } |
326 | 327 | ||
327 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 328 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
328 | { | 329 | { |
329 | RecBody body; | 330 | RecBody body; |
330 | const char *mb; | 331 | const char *mb; |
331 | int err = MAILIMAP_NO_ERROR; | 332 | int err = MAILIMAP_NO_ERROR; |
332 | clist *result; | 333 | clist *result; |
333 | clistcell *current; | 334 | clistcell *current; |
334 | mailimap_fetch_att *fetchAtt; | 335 | mailimap_fetch_att *fetchAtt; |
335 | mailimap_fetch_type *fetchType; | 336 | mailimap_fetch_type *fetchType; |
336 | mailimap_set *set; | 337 | mailimap_set *set; |
337 | mailimap_body*body_desc; | 338 | mailimap_body*body_desc; |
338 | 339 | ||
339 | mb = mail.getMbox().latin1(); | 340 | mb = mail.getMbox().latin1(); |
340 | 341 | ||
341 | login(); | 342 | login(); |
342 | if (!m_imap) { | 343 | if (!m_imap) { |
343 | return body; | 344 | return body; |
344 | } | 345 | } |
345 | 346 | ||
346 | err = mailimap_select( m_imap, (char*)mb); | 347 | err = mailimap_select( m_imap, (char*)mb); |
347 | if ( err != MAILIMAP_NO_ERROR ) { | 348 | if ( err != MAILIMAP_NO_ERROR ) { |
348 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 349 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
349 | return body; | 350 | return body; |
350 | } | 351 | } |
351 | 352 | ||
352 | result = clist_new(); | 353 | result = clist_new(); |
353 | /* the range has to start at 1!!! not with 0!!!! */ | 354 | /* the range has to start at 1!!! not with 0!!!! */ |
354 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 355 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
355 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 356 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
356 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 357 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
357 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 358 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
358 | mailimap_set_free( set ); | 359 | mailimap_set_free( set ); |
359 | mailimap_fetch_type_free( fetchType ); | 360 | mailimap_fetch_type_free( fetchType ); |
360 | 361 | ||
361 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 362 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
362 | mailimap_msg_att * msg_att; | 363 | mailimap_msg_att * msg_att; |
363 | msg_att = (mailimap_msg_att*)current->data; | 364 | msg_att = (mailimap_msg_att*)current->data; |
364 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 365 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
365 | body_desc = item->att_data.att_static->att_data.att_body; | 366 | body_desc = item->att_data.att_static->att_data.att_body; |
366 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 367 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
367 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 368 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
368 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | 369 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
369 | qDebug("Mulitpart mail"); | 370 | qDebug("Mulitpart mail"); |
370 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | 371 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); |
371 | } | 372 | } |
372 | } else { | 373 | } else { |
373 | qDebug("error fetching body: %s",m_imap->imap_response); | 374 | qDebug("error fetching body: %s",m_imap->imap_response); |
374 | } | 375 | } |
375 | mailimap_fetch_list_free(result); | 376 | mailimap_fetch_list_free(result); |
376 | return body; | 377 | return body; |
377 | } | 378 | } |
378 | 379 | ||
379 | /* this routine is just called when the mail has only ONE part. | 380 | /* this routine is just called when the mail has only ONE part. |
380 | for filling the parts of a multi-part-message there are other | 381 | for filling the parts of a multi-part-message there are other |
381 | routines 'cause we can not simply fetch the whole body. */ | 382 | routines 'cause we can not simply fetch the whole body. */ |
382 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 383 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
383 | { | 384 | { |
384 | if (!mailDescription) { | 385 | if (!mailDescription) { |
385 | return; | 386 | return; |
386 | } | 387 | } |
387 | QString sub,body_text; | 388 | QString sub,body_text; |
388 | RecPart singlePart; | 389 | RecPart singlePart; |
389 | QValueList<int> path; | 390 | QValueList<int> path; |
390 | fillSinglePart(singlePart,mailDescription); | 391 | fillSinglePart(singlePart,mailDescription); |
391 | switch (mailDescription->bd_type) { | 392 | switch (mailDescription->bd_type) { |
392 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 393 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
393 | path.append(1); | 394 | path.append(1); |
394 | body_text = fetchPart(mail,path,true); | 395 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); |
395 | if (singlePart.Encoding()=="quoted-printable") { | ||
396 | body_text = decode_quoted_printable(body_text.latin1()); | ||
397 | } | ||
398 | target_body.setBodytext(body_text); | 396 | target_body.setBodytext(body_text); |
399 | target_body.setDescription(singlePart); | 397 | target_body.setDescription(singlePart); |
400 | break; | 398 | break; |
401 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 399 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
402 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | 400 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); |
403 | path.append(1); | 401 | path.append(1); |
404 | body_text = fetchPart(mail,path,true); | 402 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); |
405 | if (singlePart.Encoding()=="quoted-printable") { | ||
406 | body_text = decode_quoted_printable(body_text.latin1()); | ||
407 | } | ||
408 | target_body.setBodytext(body_text); | 403 | target_body.setBodytext(body_text); |
409 | target_body.setDescription(singlePart); | 404 | target_body.setDescription(singlePart); |
410 | break; | 405 | break; |
411 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 406 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
412 | qDebug("Single attachment"); | 407 | qDebug("Single attachment"); |
413 | target_body.setBodytext(""); | 408 | target_body.setBodytext(""); |
414 | target_body.addPart(singlePart); | 409 | target_body.addPart(singlePart); |
415 | break; | 410 | break; |
416 | default: | 411 | default: |
417 | break; | 412 | break; |
418 | } | 413 | } |
419 | 414 | ||
420 | return; | 415 | return; |
421 | } | 416 | } |
422 | 417 | ||
423 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 418 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
424 | { | 419 | { |
425 | QStringList l; | 420 | QStringList l; |
426 | QString from; | 421 | QString from; |
427 | bool named_from; | 422 | bool named_from; |
428 | clistcell *current = NULL; | 423 | clistcell *current = NULL; |
429 | mailimap_address * current_address=NULL; | 424 | mailimap_address * current_address=NULL; |
430 | if (!list) { | 425 | if (!list) { |
431 | return l; | 426 | return l; |
432 | } | 427 | } |
433 | unsigned int count = 0; | 428 | unsigned int count = 0; |
434 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 429 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
435 | from = ""; | 430 | from = ""; |
436 | named_from = false; | 431 | named_from = false; |
437 | current_address=(mailimap_address*)current->data; | 432 | current_address=(mailimap_address*)current->data; |
438 | if (current_address->ad_personal_name){ | 433 | if (current_address->ad_personal_name){ |
439 | from+=QString(current_address->ad_personal_name); | 434 | from+=QString(current_address->ad_personal_name); |
440 | from+=" "; | 435 | from+=" "; |
441 | named_from = true; | 436 | named_from = true; |
442 | } | 437 | } |
443 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 438 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
444 | from+="<"; | 439 | from+="<"; |
445 | } | 440 | } |
446 | if (current_address->ad_mailbox_name) { | 441 | if (current_address->ad_mailbox_name) { |
447 | from+=QString(current_address->ad_mailbox_name); | 442 | from+=QString(current_address->ad_mailbox_name); |
448 | from+="@"; | 443 | from+="@"; |
449 | } | 444 | } |
450 | if (current_address->ad_host_name) { | 445 | if (current_address->ad_host_name) { |
451 | from+=QString(current_address->ad_host_name); | 446 | from+=QString(current_address->ad_host_name); |
452 | } | 447 | } |
453 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 448 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
454 | from+=">"; | 449 | from+=">"; |
455 | } | 450 | } |
456 | l.append(QString(from)); | 451 | l.append(QString(from)); |
457 | if (++count > 99) { | 452 | if (++count > 99) { |
458 | break; | 453 | break; |
459 | } | 454 | } |
460 | } | 455 | } |
461 | return l; | 456 | return l; |
462 | } | 457 | } |
463 | 458 | ||
464 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 459 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
465 | { | 460 | { |
466 | QString body(""); | 461 | encodedString*res=new encodedString; |
467 | const char*mb; | 462 | const char*mb; |
468 | int err; | 463 | int err; |
469 | mailimap_fetch_type *fetchType; | 464 | mailimap_fetch_type *fetchType; |
470 | mailimap_set *set; | 465 | mailimap_set *set; |
471 | clistcell*current,*cur; | 466 | clistcell*current,*cur; |
472 | 467 | ||
473 | login(); | 468 | login(); |
474 | if (!m_imap) { | 469 | if (!m_imap) { |
475 | return body; | 470 | return res; |
476 | } | 471 | } |
477 | if (!internal_call) { | 472 | if (!internal_call) { |
478 | mb = mail.getMbox().latin1(); | 473 | mb = mail.getMbox().latin1(); |
479 | err = mailimap_select( m_imap, (char*)mb); | 474 | err = mailimap_select( m_imap, (char*)mb); |
480 | if ( err != MAILIMAP_NO_ERROR ) { | 475 | if ( err != MAILIMAP_NO_ERROR ) { |
481 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 476 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
482 | return body; | 477 | return res; |
483 | } | 478 | } |
484 | } | 479 | } |
485 | set = mailimap_set_new_single(mail.getNumber()); | 480 | set = mailimap_set_new_single(mail.getNumber()); |
486 | clist*id_list=clist_new(); | 481 | clist*id_list=clist_new(); |
487 | for (unsigned j=0; j < path.count();++j) { | 482 | for (unsigned j=0; j < path.count();++j) { |
488 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 483 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
489 | *p_id = path[j]; | 484 | *p_id = path[j]; |
490 | clist_append(id_list,p_id); | 485 | clist_append(id_list,p_id); |
491 | } | 486 | } |
492 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 487 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
493 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 488 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
494 | mailimap_section * section = mailimap_section_new(section_spec); | 489 | mailimap_section * section = mailimap_section_new(section_spec); |
495 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 490 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
496 | 491 | ||
497 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 492 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
498 | 493 | ||
499 | clist*result = clist_new(); | 494 | clist*result = clist_new(); |
500 | 495 | ||
501 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 496 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
502 | mailimap_set_free( set ); | 497 | mailimap_set_free( set ); |
503 | mailimap_fetch_type_free( fetchType ); | 498 | mailimap_fetch_type_free( fetchType ); |
504 | 499 | ||
505 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 500 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
506 | mailimap_msg_att * msg_att; | 501 | mailimap_msg_att * msg_att; |
507 | msg_att = (mailimap_msg_att*)current->data; | 502 | msg_att = (mailimap_msg_att*)current->data; |
508 | mailimap_msg_att_item*msg_att_item; | 503 | mailimap_msg_att_item*msg_att_item; |
509 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 504 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
510 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 505 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
511 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 506 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
512 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 507 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
513 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 508 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
509 | /* detach - we take over the content */ | ||
514 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 510 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
515 | if (text) { | 511 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
516 | if (enc=="quoted-printable") { | ||
517 | body = decode_quoted_printable(text); | ||
518 | } else { | ||
519 | body = QString(text); | ||
520 | } | ||
521 | free(text); | ||
522 | } else { | ||
523 | body = ""; | ||
524 | } | ||
525 | } | 512 | } |
526 | } | 513 | } |
527 | } | 514 | } |
528 | |||
529 | } else { | 515 | } else { |
530 | qDebug("error fetching text: %s",m_imap->imap_response); | 516 | qDebug("error fetching text: %s",m_imap->imap_response); |
531 | } | 517 | } |
532 | mailimap_fetch_list_free(result); | 518 | mailimap_fetch_list_free(result); |
533 | return body; | 519 | return res; |
534 | } | 520 | } |
535 | 521 | ||
536 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 522 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
537 | { | 523 | { |
538 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 524 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
539 | if (!mailDescription||current_recursion==10) { | 525 | if (!mailDescription||current_recursion==10) { |
540 | return; | 526 | return; |
541 | } | 527 | } |
542 | clistcell*current; | 528 | clistcell*current; |
543 | mailimap_body*current_body; | 529 | mailimap_body*current_body; |
544 | unsigned int count = 0; | 530 | unsigned int count = 0; |
545 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 531 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
546 | /* the point in the message */ | 532 | /* the point in the message */ |
547 | ++count; | 533 | ++count; |
548 | current_body = (mailimap_body*)current->data; | 534 | current_body = (mailimap_body*)current->data; |
549 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 535 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
550 | QValueList<int>clist = recList; | 536 | QValueList<int>clist = recList; |
551 | clist.append(count); | 537 | clist.append(count); |
552 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); | 538 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); |
553 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 539 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ |
554 | RecPart currentPart; | 540 | RecPart currentPart; |
555 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 541 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
556 | QValueList<int>clist = recList; | 542 | QValueList<int>clist = recList; |
557 | clist.append(count); | 543 | clist.append(count); |
558 | /* important: Check for is NULL 'cause a body can be empty! */ | 544 | /* important: Check for is NULL 'cause a body can be empty! */ |
559 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 545 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
560 | QString body_text = fetchPart(mail,clist,true,currentPart.Encoding()); | 546 | QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding()); |
561 | target_body.setDescription(currentPart); | 547 | target_body.setDescription(currentPart); |
562 | target_body.setBodytext(body_text); | 548 | target_body.setBodytext(body_text); |
563 | } else { | 549 | } else { |
564 | QString id(""); | 550 | QString id(""); |
565 | for (unsigned int j = 0; j < clist.count();++j) { | 551 | for (unsigned int j = 0; j < clist.count();++j) { |
566 | id+=(j>0?" ":""); | 552 | id+=(j>0?" ":""); |
567 | id+=QString("%1").arg(clist[j]); | 553 | id+=QString("%1").arg(clist[j]); |
568 | } | 554 | } |
569 | qDebug("ID= %s",id.latin1()); | 555 | qDebug("ID= %s",id.latin1()); |
570 | currentPart.setIdentifier(id); | 556 | currentPart.setIdentifier(id); |
571 | currentPart.setPositionlist(clist); | 557 | currentPart.setPositionlist(clist); |
572 | target_body.addPart(currentPart); | 558 | target_body.addPart(currentPart); |
573 | } | 559 | } |
574 | } | 560 | } |
575 | } | 561 | } |
576 | } | 562 | } |
577 | 563 | ||
578 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 564 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
579 | { | 565 | { |
580 | if (!Description) { | 566 | if (!Description) { |
581 | return; | 567 | return; |
582 | } | 568 | } |
583 | switch (Description->bd_type) { | 569 | switch (Description->bd_type) { |
584 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 570 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
585 | target_part.setType("text"); | 571 | target_part.setType("text"); |
586 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 572 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
587 | break; | 573 | break; |
588 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 574 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
589 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 575 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
590 | break; | 576 | break; |
591 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 577 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
592 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 578 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
593 | break; | 579 | break; |
594 | default: | 580 | default: |
595 | break; | 581 | break; |
596 | } | 582 | } |
597 | } | 583 | } |
598 | 584 | ||
599 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 585 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
600 | { | 586 | { |
601 | if (!which) { | 587 | if (!which) { |
602 | return; | 588 | return; |
603 | } | 589 | } |
604 | QString sub; | 590 | QString sub; |
605 | sub = which->bd_media_text; | 591 | sub = which->bd_media_text; |
606 | target_part.setSubtype(sub.lower()); | 592 | target_part.setSubtype(sub.lower()); |
607 | target_part.setLines(which->bd_lines); | 593 | target_part.setLines(which->bd_lines); |
608 | fillBodyFields(target_part,which->bd_fields); | 594 | fillBodyFields(target_part,which->bd_fields); |
609 | } | 595 | } |
610 | 596 | ||
611 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 597 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
612 | { | 598 | { |
613 | if (!which) { | 599 | if (!which) { |
614 | return; | 600 | return; |
615 | } | 601 | } |
616 | // QString sub; | 602 | // QString sub; |
617 | // sub = which->bd_media_text; | 603 | // sub = which->bd_media_text; |
618 | // target_part.setSubtype(sub.lower()); | 604 | // target_part.setSubtype(sub.lower()); |
619 | qDebug("Message part"); | 605 | qDebug("Message part"); |
620 | /* we set this type to text/plain */ | 606 | /* we set this type to text/plain */ |
621 | target_part.setType("text"); | 607 | target_part.setType("text"); |
622 | target_part.setSubtype("plain"); | 608 | target_part.setSubtype("plain"); |
623 | target_part.setLines(which->bd_lines); | 609 | target_part.setLines(which->bd_lines); |
624 | fillBodyFields(target_part,which->bd_fields); | 610 | fillBodyFields(target_part,which->bd_fields); |
625 | } | 611 | } |
626 | 612 | ||
627 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 613 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
628 | { | 614 | { |
629 | if (!which) { | 615 | if (!which) { |
630 | return; | 616 | return; |
631 | } | 617 | } |
632 | QString type,sub; | 618 | QString type,sub; |
633 | switch (which->bd_media_basic->med_type) { | 619 | switch (which->bd_media_basic->med_type) { |
634 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 620 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
635 | type = "application"; | 621 | type = "application"; |
636 | break; | 622 | break; |
637 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 623 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
638 | type = "audio"; | 624 | type = "audio"; |
639 | break; | 625 | break; |
640 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 626 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
641 | type = "image"; | 627 | type = "image"; |
642 | break; | 628 | break; |
643 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 629 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
644 | type = "message"; | 630 | type = "message"; |
645 | break; | 631 | break; |
646 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 632 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
647 | type = "video"; | 633 | type = "video"; |
648 | break; | 634 | break; |
649 | case MAILIMAP_MEDIA_BASIC_OTHER: | 635 | case MAILIMAP_MEDIA_BASIC_OTHER: |
650 | default: | 636 | default: |
651 | if (which->bd_media_basic->med_basic_type) { | 637 | if (which->bd_media_basic->med_basic_type) { |
652 | type = which->bd_media_basic->med_basic_type; | 638 | type = which->bd_media_basic->med_basic_type; |
653 | } else { | 639 | } else { |
654 | type = ""; | 640 | type = ""; |
655 | } | 641 | } |
656 | break; | 642 | break; |
657 | } | 643 | } |
658 | if (which->bd_media_basic->med_subtype) { | 644 | if (which->bd_media_basic->med_subtype) { |
659 | sub = which->bd_media_basic->med_subtype; | 645 | sub = which->bd_media_basic->med_subtype; |
660 | } else { | 646 | } else { |
661 | sub = ""; | 647 | sub = ""; |
662 | } | 648 | } |
663 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | 649 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); |
664 | target_part.setType(type.lower()); | 650 | target_part.setType(type.lower()); |
665 | target_part.setSubtype(sub.lower()); | 651 | target_part.setSubtype(sub.lower()); |
666 | fillBodyFields(target_part,which->bd_fields); | 652 | fillBodyFields(target_part,which->bd_fields); |
667 | } | 653 | } |
668 | 654 | ||
669 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 655 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) |
670 | { | 656 | { |
671 | if (!which) return; | 657 | if (!which) return; |
672 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 658 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
673 | clistcell*cur; | 659 | clistcell*cur; |
674 | mailimap_single_body_fld_param*param=0; | 660 | mailimap_single_body_fld_param*param=0; |
675 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 661 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
676 | param = (mailimap_single_body_fld_param*)cur->data; | 662 | param = (mailimap_single_body_fld_param*)cur->data; |
677 | if (param) { | 663 | if (param) { |
678 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 664 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
679 | } | 665 | } |
680 | } | 666 | } |
681 | } | 667 | } |
682 | mailimap_body_fld_enc*enc = which->bd_encoding; | 668 | mailimap_body_fld_enc*enc = which->bd_encoding; |
683 | QString encoding(""); | 669 | QString encoding(""); |
684 | switch (enc->enc_type) { | 670 | switch (enc->enc_type) { |
685 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 671 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
686 | encoding = "7bit"; | 672 | encoding = "7bit"; |
687 | break; | 673 | break; |
688 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 674 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
689 | encoding = "8bit"; | 675 | encoding = "8bit"; |
690 | break; | 676 | break; |
691 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 677 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
692 | encoding="binary"; | 678 | encoding="binary"; |
693 | break; | 679 | break; |
694 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 680 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
695 | encoding="base64"; | 681 | encoding="base64"; |
696 | break; | 682 | break; |
697 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 683 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
698 | encoding="quoted-printable"; | 684 | encoding="quoted-printable"; |
699 | break; | 685 | break; |
700 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 686 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
701 | default: | 687 | default: |
702 | if (enc->enc_value) { | 688 | if (enc->enc_value) { |
703 | char*t=enc->enc_value; | 689 | char*t=enc->enc_value; |
704 | encoding=QString(enc->enc_value); | 690 | encoding=QString(enc->enc_value); |
705 | enc->enc_value=0L; | 691 | enc->enc_value=0L; |
706 | free(t); | 692 | free(t); |
707 | } | 693 | } |
708 | } | 694 | } |
709 | if (which->bd_description) { | 695 | if (which->bd_description) { |
710 | target_part.setDescription(QString(which->bd_description)); | 696 | target_part.setDescription(QString(which->bd_description)); |
711 | } | 697 | } |
712 | target_part.setEncoding(encoding); | 698 | target_part.setEncoding(encoding); |
713 | target_part.setSize(which->bd_size); | 699 | target_part.setSize(which->bd_size); |
714 | } | 700 | } |
715 | 701 | ||
716 | QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) | ||
717 | { | ||
718 | return fetchPart(mail,part.Positionlist(),false,part.Encoding()); | ||
719 | } | ||
720 | |||
721 | void IMAPwrapper::deleteMail(const RecMail&mail) | 702 | void IMAPwrapper::deleteMail(const RecMail&mail) |
722 | { | 703 | { |
723 | mailimap_flag_list*flist; | 704 | mailimap_flag_list*flist; |
724 | mailimap_set *set; | 705 | mailimap_set *set; |
725 | mailimap_store_att_flags * store_flags; | 706 | mailimap_store_att_flags * store_flags; |
726 | int err; | 707 | int err; |
727 | login(); | 708 | login(); |
728 | if (!m_imap) { | 709 | if (!m_imap) { |
729 | return; | 710 | return; |
730 | } | 711 | } |
731 | const char *mb = mail.getMbox().latin1(); | 712 | const char *mb = mail.getMbox().latin1(); |
732 | err = mailimap_select( m_imap, (char*)mb); | 713 | err = mailimap_select( m_imap, (char*)mb); |
733 | if ( err != MAILIMAP_NO_ERROR ) { | 714 | if ( err != MAILIMAP_NO_ERROR ) { |
734 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); | 715 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); |
735 | return; | 716 | return; |
736 | } | 717 | } |
737 | flist = mailimap_flag_list_new_empty(); | 718 | flist = mailimap_flag_list_new_empty(); |
738 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 719 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
739 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 720 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
740 | set = mailimap_set_new_single(mail.getNumber()); | 721 | set = mailimap_set_new_single(mail.getNumber()); |
741 | err = mailimap_store(m_imap,set,store_flags); | 722 | err = mailimap_store(m_imap,set,store_flags); |
742 | mailimap_set_free( set ); | 723 | mailimap_set_free( set ); |
743 | mailimap_store_att_flags_free(store_flags); | 724 | mailimap_store_att_flags_free(store_flags); |
744 | 725 | ||
745 | if (err != MAILIMAP_NO_ERROR) { | 726 | if (err != MAILIMAP_NO_ERROR) { |
746 | qDebug("error deleting mail: %s",m_imap->imap_response); | 727 | qDebug("error deleting mail: %s",m_imap->imap_response); |
747 | return; | 728 | return; |
748 | } | 729 | } |
749 | qDebug("deleting mail: %s",m_imap->imap_response); | 730 | qDebug("deleting mail: %s",m_imap->imap_response); |
750 | /* should we realy do that at this moment? */ | 731 | /* should we realy do that at this moment? */ |
751 | err = mailimap_expunge(m_imap); | 732 | err = mailimap_expunge(m_imap); |
752 | if (err != MAILIMAP_NO_ERROR) { | 733 | if (err != MAILIMAP_NO_ERROR) { |
753 | qDebug("error deleting mail: %s",m_imap->imap_response); | 734 | qDebug("error deleting mail: %s",m_imap->imap_response); |
754 | } | 735 | } |
755 | qDebug("Delete successfull %s",m_imap->imap_response); | 736 | qDebug("Delete successfull %s",m_imap->imap_response); |
756 | } | 737 | } |
757 | 738 | ||
758 | void IMAPwrapper::answeredMail(const RecMail&mail) | 739 | void IMAPwrapper::answeredMail(const RecMail&mail) |
759 | { | 740 | { |
760 | mailimap_flag_list*flist; | 741 | mailimap_flag_list*flist; |
761 | mailimap_set *set; | 742 | mailimap_set *set; |
762 | mailimap_store_att_flags * store_flags; | 743 | mailimap_store_att_flags * store_flags; |
763 | int err; | 744 | int err; |
764 | login(); | 745 | login(); |
765 | if (!m_imap) { | 746 | if (!m_imap) { |
766 | return; | 747 | return; |
767 | } | 748 | } |
768 | const char *mb = mail.getMbox().latin1(); | 749 | const char *mb = mail.getMbox().latin1(); |
769 | err = mailimap_select( m_imap, (char*)mb); | 750 | err = mailimap_select( m_imap, (char*)mb); |
770 | if ( err != MAILIMAP_NO_ERROR ) { | 751 | if ( err != MAILIMAP_NO_ERROR ) { |
771 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); | 752 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); |
772 | return; | 753 | return; |
773 | } | 754 | } |
774 | flist = mailimap_flag_list_new_empty(); | 755 | flist = mailimap_flag_list_new_empty(); |
775 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 756 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
776 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 757 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
777 | set = mailimap_set_new_single(mail.getNumber()); | 758 | set = mailimap_set_new_single(mail.getNumber()); |
778 | err = mailimap_store(m_imap,set,store_flags); | 759 | err = mailimap_store(m_imap,set,store_flags); |
779 | mailimap_set_free( set ); | 760 | mailimap_set_free( set ); |
780 | mailimap_store_att_flags_free(store_flags); | 761 | mailimap_store_att_flags_free(store_flags); |
781 | 762 | ||
782 | if (err != MAILIMAP_NO_ERROR) { | 763 | if (err != MAILIMAP_NO_ERROR) { |
783 | qDebug("error marking mail: %s",m_imap->imap_response); | 764 | qDebug("error marking mail: %s",m_imap->imap_response); |
784 | return; | 765 | return; |
785 | } | 766 | } |
786 | } | 767 | } |
768 | |||
769 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | ||
770 | { | ||
771 | QString body(""); | ||
772 | encodedString*res = fetchRawPart(mail,path,internal_call); | ||
773 | encodedString*r = decode_String(res,enc); | ||
774 | delete res; | ||
775 | if (r) { | ||
776 | if (r->Length()>0) { | ||
777 | body = r->Content(); | ||
778 | } | ||
779 | delete r; | ||
780 | } | ||
781 | return body; | ||
782 | } | ||
783 | |||
784 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | ||
785 | { | ||
786 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); | ||
787 | } | ||
788 | |||
789 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) | ||
790 | { | ||
791 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); | ||
792 | encodedString*r = decode_String(res,part.Encoding()); | ||
793 | delete res; | ||
794 | return r; | ||
795 | } | ||
796 | |||
797 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) | ||
798 | { | ||
799 | return fetchRawPart(mail,part.Positionlist(),false); | ||
800 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h index 768a517..aeebda8 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.h +++ b/noncore/net/mail/libmailwrapper/imapwrapper.h | |||
@@ -1,56 +1,62 @@ | |||
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 | #include "abstractmail.h" | 6 | #include "abstractmail.h" |
7 | 7 | ||
8 | struct mailimap; | 8 | struct mailimap; |
9 | struct mailimap_body_type_1part; | 9 | struct mailimap_body_type_1part; |
10 | struct mailimap_body_type_text; | 10 | struct mailimap_body_type_text; |
11 | struct mailimap_body_type_basic; | 11 | struct mailimap_body_type_basic; |
12 | struct mailimap_body_type_msg; | 12 | struct mailimap_body_type_msg; |
13 | struct mailimap_body_type_mpart; | 13 | struct mailimap_body_type_mpart; |
14 | struct mailimap_body_fields; | 14 | struct mailimap_body_fields; |
15 | struct mailimap_msg_att; | 15 | struct mailimap_msg_att; |
16 | class encodedString; | ||
16 | 17 | ||
17 | class IMAPwrapper : public AbstractMail | 18 | class IMAPwrapper : public AbstractMail |
18 | { | 19 | { |
19 | Q_OBJECT | 20 | Q_OBJECT |
20 | public: | 21 | public: |
21 | IMAPwrapper( IMAPaccount *a ); | 22 | IMAPwrapper( IMAPaccount *a ); |
22 | virtual ~IMAPwrapper(); | 23 | virtual ~IMAPwrapper(); |
23 | virtual QList<Folder>* listFolders(); | 24 | virtual QList<Folder>* listFolders(); |
24 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); | 25 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); |
25 | virtual RecBody fetchBody(const RecMail&mail); | 26 | |
26 | virtual QString fetchPart(const RecMail&mail,const RecPart&part); | ||
27 | virtual void deleteMail(const RecMail&mail); | 27 | virtual void deleteMail(const RecMail&mail); |
28 | virtual void answeredMail(const RecMail&mail); | 28 | virtual void answeredMail(const RecMail&mail); |
29 | 29 | ||
30 | virtual RecBody fetchBody(const RecMail&mail); | ||
31 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); | ||
32 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); | ||
33 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); | ||
34 | |||
30 | static void imap_progress( size_t current, size_t maximum ); | 35 | static void imap_progress( size_t current, size_t maximum ); |
31 | 36 | ||
32 | protected: | 37 | protected: |
33 | RecMail*parse_list_result(mailimap_msg_att*); | 38 | RecMail*parse_list_result(mailimap_msg_att*); |
34 | void login(); | 39 | void login(); |
35 | void logout(); | 40 | void logout(); |
36 | 41 | ||
37 | virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); | 42 | virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); |
43 | virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); | ||
38 | 44 | ||
39 | void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); | 45 | void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); |
40 | void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); | 46 | void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); |
41 | 47 | ||
42 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); | 48 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); |
43 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); | 49 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); |
44 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); | 50 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); |
45 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); | 51 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); |
46 | 52 | ||
47 | /* just helpers */ | 53 | /* just helpers */ |
48 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); | 54 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); |
49 | static QStringList address_list_to_stringlist(clist*list); | 55 | static QStringList address_list_to_stringlist(clist*list); |
50 | 56 | ||
51 | 57 | ||
52 | IMAPaccount *account; | 58 | IMAPaccount *account; |
53 | mailimap *m_imap; | 59 | mailimap *m_imap; |
54 | }; | 60 | }; |
55 | 61 | ||
56 | #endif | 62 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.cpp b/noncore/net/mail/libmailwrapper/mailtypes.cpp index 8d9b247..d8a36e7 100644 --- a/noncore/net/mail/libmailwrapper/mailtypes.cpp +++ b/noncore/net/mail/libmailwrapper/mailtypes.cpp | |||
@@ -1,247 +1,335 @@ | |||
1 | #include "mailtypes.h" | 1 | #include "mailtypes.h" |
2 | 2 | #include <stdlib.h> | |
3 | 3 | ||
4 | RecMail::RecMail() | 4 | RecMail::RecMail() |
5 | :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) | 5 | :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) |
6 | { | 6 | { |
7 | init(); | 7 | init(); |
8 | } | 8 | } |
9 | 9 | ||
10 | RecMail::RecMail(const RecMail&old) | 10 | RecMail::RecMail(const RecMail&old) |
11 | :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) | 11 | :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) |
12 | { | 12 | { |
13 | init(); | 13 | init(); |
14 | copy_old(old); | 14 | copy_old(old); |
15 | qDebug("Copy constructor RecMail"); | 15 | qDebug("Copy constructor RecMail"); |
16 | } | 16 | } |
17 | 17 | ||
18 | RecMail::~RecMail() | 18 | RecMail::~RecMail() |
19 | { | 19 | { |
20 | wrapper = 0; | 20 | wrapper = 0; |
21 | } | 21 | } |
22 | 22 | ||
23 | void RecMail::copy_old(const RecMail&old) | 23 | void RecMail::copy_old(const RecMail&old) |
24 | { | 24 | { |
25 | subject = old.subject; | 25 | subject = old.subject; |
26 | date = old.date; | 26 | date = old.date; |
27 | mbox = old.mbox; | 27 | mbox = old.mbox; |
28 | msg_id = old.msg_id; | 28 | msg_id = old.msg_id; |
29 | msg_size = old.msg_size; | 29 | msg_size = old.msg_size; |
30 | msg_number = old.msg_number; | 30 | msg_number = old.msg_number; |
31 | from = old.from; | 31 | from = old.from; |
32 | msg_flags = old.msg_flags; | 32 | msg_flags = old.msg_flags; |
33 | to = old.to; | 33 | to = old.to; |
34 | cc = old.cc; | 34 | cc = old.cc; |
35 | bcc = old.bcc; | 35 | bcc = old.bcc; |
36 | wrapper = old.wrapper; | 36 | wrapper = old.wrapper; |
37 | } | 37 | } |
38 | 38 | ||
39 | void RecMail::init() | 39 | void RecMail::init() |
40 | { | 40 | { |
41 | to.clear(); | 41 | to.clear(); |
42 | cc.clear(); | 42 | cc.clear(); |
43 | bcc.clear(); | 43 | bcc.clear(); |
44 | wrapper = 0; | 44 | wrapper = 0; |
45 | } | 45 | } |
46 | 46 | ||
47 | void RecMail::setWrapper(AbstractMail*awrapper) | 47 | void RecMail::setWrapper(AbstractMail*awrapper) |
48 | { | 48 | { |
49 | wrapper = awrapper; | 49 | wrapper = awrapper; |
50 | } | 50 | } |
51 | 51 | ||
52 | AbstractMail* RecMail::Wrapper() | 52 | AbstractMail* RecMail::Wrapper() |
53 | { | 53 | { |
54 | return wrapper; | 54 | return wrapper; |
55 | } | 55 | } |
56 | 56 | ||
57 | void RecMail::setTo(const QStringList&list) | 57 | void RecMail::setTo(const QStringList&list) |
58 | { | 58 | { |
59 | to = list; | 59 | to = list; |
60 | } | 60 | } |
61 | 61 | ||
62 | const QStringList&RecMail::To()const | 62 | const QStringList&RecMail::To()const |
63 | { | 63 | { |
64 | return to; | 64 | return to; |
65 | } | 65 | } |
66 | 66 | ||
67 | void RecMail::setCC(const QStringList&list) | 67 | void RecMail::setCC(const QStringList&list) |
68 | { | 68 | { |
69 | cc = list; | 69 | cc = list; |
70 | } | 70 | } |
71 | 71 | ||
72 | const QStringList&RecMail::CC()const | 72 | const QStringList&RecMail::CC()const |
73 | { | 73 | { |
74 | return cc; | 74 | return cc; |
75 | } | 75 | } |
76 | 76 | ||
77 | void RecMail::setBcc(const QStringList&list) | 77 | void RecMail::setBcc(const QStringList&list) |
78 | { | 78 | { |
79 | bcc = list; | 79 | bcc = list; |
80 | } | 80 | } |
81 | 81 | ||
82 | const QStringList& RecMail::Bcc()const | 82 | const QStringList& RecMail::Bcc()const |
83 | { | 83 | { |
84 | return bcc; | 84 | return bcc; |
85 | } | 85 | } |
86 | 86 | ||
87 | RecPart::RecPart() | 87 | RecPart::RecPart() |
88 | : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) | 88 | : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) |
89 | { | 89 | { |
90 | m_Parameters.clear(); | 90 | m_Parameters.clear(); |
91 | m_poslist.clear(); | 91 | m_poslist.clear(); |
92 | } | 92 | } |
93 | 93 | ||
94 | RecPart::~RecPart() | 94 | RecPart::~RecPart() |
95 | { | 95 | { |
96 | } | 96 | } |
97 | 97 | ||
98 | void RecPart::setSize(unsigned int size) | 98 | void RecPart::setSize(unsigned int size) |
99 | { | 99 | { |
100 | m_size = size; | 100 | m_size = size; |
101 | } | 101 | } |
102 | 102 | ||
103 | const unsigned int RecPart::Size()const | 103 | const unsigned int RecPart::Size()const |
104 | { | 104 | { |
105 | return m_size; | 105 | return m_size; |
106 | } | 106 | } |
107 | 107 | ||
108 | void RecPart::setLines(unsigned int lines) | 108 | void RecPart::setLines(unsigned int lines) |
109 | { | 109 | { |
110 | m_lines = lines; | 110 | m_lines = lines; |
111 | } | 111 | } |
112 | 112 | ||
113 | const unsigned int RecPart::Lines()const | 113 | const unsigned int RecPart::Lines()const |
114 | { | 114 | { |
115 | return m_lines; | 115 | return m_lines; |
116 | } | 116 | } |
117 | 117 | ||
118 | const QString& RecPart::Type()const | 118 | const QString& RecPart::Type()const |
119 | { | 119 | { |
120 | return m_type; | 120 | return m_type; |
121 | } | 121 | } |
122 | 122 | ||
123 | void RecPart::setType(const QString&type) | 123 | void RecPart::setType(const QString&type) |
124 | { | 124 | { |
125 | m_type = type; | 125 | m_type = type; |
126 | } | 126 | } |
127 | 127 | ||
128 | const QString& RecPart::Subtype()const | 128 | const QString& RecPart::Subtype()const |
129 | { | 129 | { |
130 | return m_subtype; | 130 | return m_subtype; |
131 | } | 131 | } |
132 | 132 | ||
133 | void RecPart::setSubtype(const QString&subtype) | 133 | void RecPart::setSubtype(const QString&subtype) |
134 | { | 134 | { |
135 | m_subtype = subtype; | 135 | m_subtype = subtype; |
136 | } | 136 | } |
137 | 137 | ||
138 | const QString& RecPart::Identifier()const | 138 | const QString& RecPart::Identifier()const |
139 | { | 139 | { |
140 | return m_identifier; | 140 | return m_identifier; |
141 | } | 141 | } |
142 | 142 | ||
143 | void RecPart::setIdentifier(const QString&identifier) | 143 | void RecPart::setIdentifier(const QString&identifier) |
144 | { | 144 | { |
145 | m_identifier = identifier; | 145 | m_identifier = identifier; |
146 | } | 146 | } |
147 | 147 | ||
148 | const QString& RecPart::Encoding()const | 148 | const QString& RecPart::Encoding()const |
149 | { | 149 | { |
150 | return m_encoding; | 150 | return m_encoding; |
151 | } | 151 | } |
152 | 152 | ||
153 | void RecPart::setEncoding(const QString&encoding) | 153 | void RecPart::setEncoding(const QString&encoding) |
154 | { | 154 | { |
155 | m_encoding = encoding; | 155 | m_encoding = encoding; |
156 | } | 156 | } |
157 | 157 | ||
158 | const QString& RecPart::Description()const | 158 | const QString& RecPart::Description()const |
159 | { | 159 | { |
160 | return m_description; | 160 | return m_description; |
161 | } | 161 | } |
162 | 162 | ||
163 | void RecPart::setDescription(const QString&desc) | 163 | void RecPart::setDescription(const QString&desc) |
164 | { | 164 | { |
165 | m_description = desc; | 165 | m_description = desc; |
166 | } | 166 | } |
167 | 167 | ||
168 | void RecPart::setParameters(const part_plist_t&list) | 168 | void RecPart::setParameters(const part_plist_t&list) |
169 | { | 169 | { |
170 | m_Parameters = list; | 170 | m_Parameters = list; |
171 | } | 171 | } |
172 | 172 | ||
173 | const part_plist_t& RecPart::Parameters()const | 173 | const part_plist_t& RecPart::Parameters()const |
174 | { | 174 | { |
175 | return m_Parameters; | 175 | return m_Parameters; |
176 | } | 176 | } |
177 | 177 | ||
178 | void RecPart::addParameter(const QString&key,const QString&value) | 178 | void RecPart::addParameter(const QString&key,const QString&value) |
179 | { | 179 | { |
180 | m_Parameters[key]=value; | 180 | m_Parameters[key]=value; |
181 | } | 181 | } |
182 | 182 | ||
183 | const QString RecPart::searchParamter(const QString&key)const | 183 | const QString RecPart::searchParamter(const QString&key)const |
184 | { | 184 | { |
185 | QString value(""); | 185 | QString value(""); |
186 | part_plist_t::ConstIterator it = m_Parameters.find(key); | 186 | part_plist_t::ConstIterator it = m_Parameters.find(key); |
187 | if (it != m_Parameters.end()) { | 187 | if (it != m_Parameters.end()) { |
188 | value = it.data(); | 188 | value = it.data(); |
189 | } | 189 | } |
190 | return value; | 190 | return value; |
191 | } | 191 | } |
192 | 192 | ||
193 | void RecPart::setPositionlist(const QValueList<int>&poslist) | 193 | void RecPart::setPositionlist(const QValueList<int>&poslist) |
194 | { | 194 | { |
195 | m_poslist = poslist; | 195 | m_poslist = poslist; |
196 | } | 196 | } |
197 | 197 | ||
198 | const QValueList<int>& RecPart::Positionlist()const | 198 | const QValueList<int>& RecPart::Positionlist()const |
199 | { | 199 | { |
200 | return m_poslist; | 200 | return m_poslist; |
201 | } | 201 | } |
202 | 202 | ||
203 | RecBody::RecBody() | 203 | RecBody::RecBody() |
204 | : m_BodyText(),m_PartsList(),m_description() | 204 | : m_BodyText(),m_PartsList(),m_description() |
205 | { | 205 | { |
206 | m_PartsList.clear(); | 206 | m_PartsList.clear(); |
207 | } | 207 | } |
208 | 208 | ||
209 | RecBody::~RecBody() | 209 | RecBody::~RecBody() |
210 | { | 210 | { |
211 | } | 211 | } |
212 | 212 | ||
213 | void RecBody::setBodytext(const QString&bodyText) | 213 | void RecBody::setBodytext(const QString&bodyText) |
214 | { | 214 | { |
215 | m_BodyText = bodyText; | 215 | m_BodyText = bodyText; |
216 | } | 216 | } |
217 | 217 | ||
218 | const QString& RecBody::Bodytext()const | 218 | const QString& RecBody::Bodytext()const |
219 | { | 219 | { |
220 | return m_BodyText; | 220 | return m_BodyText; |
221 | } | 221 | } |
222 | 222 | ||
223 | void RecBody::setParts(const QValueList<RecPart>&parts) | 223 | void RecBody::setParts(const QValueList<RecPart>&parts) |
224 | { | 224 | { |
225 | m_PartsList.clear(); | 225 | m_PartsList.clear(); |
226 | m_PartsList = parts; | 226 | m_PartsList = parts; |
227 | } | 227 | } |
228 | 228 | ||
229 | const QValueList<RecPart>& RecBody::Parts()const | 229 | const QValueList<RecPart>& RecBody::Parts()const |
230 | { | 230 | { |
231 | return m_PartsList; | 231 | return m_PartsList; |
232 | } | 232 | } |
233 | 233 | ||
234 | void RecBody::addPart(const RecPart& part) | 234 | void RecBody::addPart(const RecPart& part) |
235 | { | 235 | { |
236 | m_PartsList.append(part); | 236 | m_PartsList.append(part); |
237 | } | 237 | } |
238 | 238 | ||
239 | void RecBody::setDescription(const RecPart&des) | 239 | void RecBody::setDescription(const RecPart&des) |
240 | { | 240 | { |
241 | m_description = des; | 241 | m_description = des; |
242 | } | 242 | } |
243 | 243 | ||
244 | const RecPart& RecBody::Description()const | 244 | const RecPart& RecBody::Description()const |
245 | { | 245 | { |
246 | return m_description; | 246 | return m_description; |
247 | } | 247 | } |
248 | |||
249 | /* handling encoded content */ | ||
250 | encodedString::encodedString() | ||
251 | { | ||
252 | init(); | ||
253 | } | ||
254 | |||
255 | encodedString::encodedString(const char*nContent,unsigned int nSize) | ||
256 | { | ||
257 | init(); | ||
258 | setContent(nContent,nSize); | ||
259 | } | ||
260 | |||
261 | encodedString::encodedString(char*nContent,unsigned int nSize) | ||
262 | { | ||
263 | init(); | ||
264 | setContent(nContent,nSize); | ||
265 | } | ||
266 | |||
267 | encodedString::encodedString(const encodedString&old) | ||
268 | { | ||
269 | init(); | ||
270 | copy_old(old); | ||
271 | qDebug("encodedeString: copy constructor!"); | ||
272 | } | ||
273 | |||
274 | encodedString& encodedString::operator=(const encodedString&old) | ||
275 | { | ||
276 | init(); | ||
277 | copy_old(old); | ||
278 | qDebug("encodedString: assign operator!"); | ||
279 | return *this; | ||
280 | } | ||
281 | |||
282 | encodedString::~encodedString() | ||
283 | { | ||
284 | clean(); | ||
285 | } | ||
286 | |||
287 | void encodedString::init() | ||
288 | { | ||
289 | content = 0; | ||
290 | size = 0; | ||
291 | } | ||
292 | |||
293 | void encodedString::clean() | ||
294 | { | ||
295 | if (content) { | ||
296 | free(content); | ||
297 | } | ||
298 | content = 0; | ||
299 | size = 0; | ||
300 | } | ||
301 | |||
302 | void encodedString::copy_old(const encodedString&old) | ||
303 | { | ||
304 | clean(); | ||
305 | if (old.size>0 && old.content) { | ||
306 | content = (char*)malloc(old.size*sizeof(char)); | ||
307 | memcpy(content,old.content,size); | ||
308 | size = old.size; | ||
309 | } | ||
310 | } | ||
311 | |||
312 | const char*encodedString::Content()const | ||
313 | { | ||
314 | return content; | ||
315 | } | ||
316 | |||
317 | const int encodedString::Length()const | ||
318 | { | ||
319 | return size; | ||
320 | } | ||
321 | |||
322 | void encodedString::setContent(const char*nContent,int nSize) | ||
323 | { | ||
324 | if (nSize>0 && nContent) { | ||
325 | content = (char*)malloc(nSize*sizeof(char)); | ||
326 | memcpy(content,nContent,nSize); | ||
327 | size = nSize; | ||
328 | } | ||
329 | } | ||
330 | |||
331 | void encodedString::setContent(char*nContent,int nSize) | ||
332 | { | ||
333 | content = nContent; | ||
334 | size = nSize; | ||
335 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h index 7d7bebc..abfbe65 100644 --- a/noncore/net/mail/libmailwrapper/mailtypes.h +++ b/noncore/net/mail/libmailwrapper/mailtypes.h | |||
@@ -1,138 +1,185 @@ | |||
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 | #include <qmap.h> | 15 | #include <qmap.h> |
16 | #include <qvaluelist.h> | 16 | #include <qvaluelist.h> |
17 | 17 | ||
18 | class AbstractMail; | 18 | class AbstractMail; |
19 | /* a class to describe mails in a mailbox */ | 19 | /* a class to describe mails in a mailbox */ |
20 | /* Attention! | 20 | /* Attention! |
21 | From programmers point of view it would make sense to | 21 | From programmers point of view it would make sense to |
22 | store the mail body into this class, too. | 22 | store the mail body into this class, too. |
23 | But: not from the point of view of the device. | 23 | But: not from the point of view of the device. |
24 | Mailbodies can be real large. So we request them when | 24 | Mailbodies can be real large. So we request them when |
25 | needed from the mail-wrapper class direct from the server itself | 25 | needed from the mail-wrapper class direct from the server itself |
26 | (imap) or from a file-based cache (pop3?) | 26 | (imap) or from a file-based cache (pop3?) |
27 | So there is no interface "const QString&body()" but you should | 27 | So there is no interface "const QString&body()" but you should |
28 | make a request to the mailwrapper with this class as parameter to | 28 | make a request to the mailwrapper with this class as parameter to |
29 | get the body. Same words for the attachments. | 29 | get the body. Same words for the attachments. |
30 | */ | 30 | */ |
31 | class RecMail | 31 | class RecMail |
32 | { | 32 | { |
33 | public: | 33 | public: |
34 | RecMail(); | 34 | RecMail(); |
35 | RecMail(const RecMail&old); | 35 | RecMail(const RecMail&old); |
36 | virtual ~RecMail(); | 36 | virtual ~RecMail(); |
37 | 37 | ||
38 | const int getNumber()const{return msg_number;} | 38 | const int getNumber()const{return msg_number;} |
39 | void setNumber(int number){msg_number=number;} | 39 | void setNumber(int number){msg_number=number;} |
40 | const QString&getDate()const{ return date; } | 40 | const QString&getDate()const{ return date; } |
41 | void setDate( const QString&a ) { date = a; } | 41 | void setDate( const QString&a ) { date = a; } |
42 | const QString&getFrom()const{ return from; } | 42 | const QString&getFrom()const{ return from; } |
43 | void setFrom( const QString&a ) { from = a; } | 43 | void setFrom( const QString&a ) { from = a; } |
44 | const QString&getSubject()const { return subject; } | 44 | const QString&getSubject()const { return subject; } |
45 | void setSubject( const QString&s ) { subject = s; } | 45 | void setSubject( const QString&s ) { subject = s; } |
46 | const QString&getMbox()const{return mbox;} | 46 | const QString&getMbox()const{return mbox;} |
47 | void setMbox(const QString&box){mbox = box;} | 47 | void setMbox(const QString&box){mbox = box;} |
48 | void setMsgid(const QString&id){msg_id=id;} | 48 | void setMsgid(const QString&id){msg_id=id;} |
49 | const QString&Msgid()const{return msg_id;} | 49 | const QString&Msgid()const{return msg_id;} |
50 | void setReplyto(const QString&reply){replyto=reply;} | 50 | void setReplyto(const QString&reply){replyto=reply;} |
51 | const QString&Replyto()const{return replyto;} | 51 | const QString&Replyto()const{return replyto;} |
52 | void setMsgsize(int size){msg_size = size;} | 52 | void setMsgsize(int size){msg_size = size;} |
53 | const int Msgsize()const{return msg_size;} | 53 | const int Msgsize()const{return msg_size;} |
54 | 54 | ||
55 | 55 | ||
56 | void setTo(const QStringList&list); | 56 | void setTo(const QStringList&list); |
57 | const QStringList&To()const; | 57 | const QStringList&To()const; |
58 | void setCC(const QStringList&list); | 58 | void setCC(const QStringList&list); |
59 | const QStringList&CC()const; | 59 | const QStringList&CC()const; |
60 | void setBcc(const QStringList&list); | 60 | void setBcc(const QStringList&list); |
61 | const QStringList&Bcc()const; | 61 | const QStringList&Bcc()const; |
62 | const QBitArray&getFlags()const{return msg_flags;} | 62 | const QBitArray&getFlags()const{return msg_flags;} |
63 | void setFlags(const QBitArray&flags){msg_flags = flags;} | 63 | void setFlags(const QBitArray&flags){msg_flags = flags;} |
64 | 64 | ||
65 | void setWrapper(AbstractMail*wrapper); | 65 | void setWrapper(AbstractMail*wrapper); |
66 | AbstractMail* Wrapper(); | 66 | AbstractMail* Wrapper(); |
67 | 67 | ||
68 | protected: | 68 | protected: |
69 | QString subject,date,from,mbox,msg_id,replyto; | 69 | QString subject,date,from,mbox,msg_id,replyto; |
70 | int msg_number,msg_size; | 70 | int msg_number,msg_size; |
71 | QBitArray msg_flags; | 71 | QBitArray msg_flags; |
72 | QStringList to,cc,bcc; | 72 | QStringList to,cc,bcc; |
73 | AbstractMail*wrapper; | 73 | AbstractMail*wrapper; |
74 | void init(); | 74 | void init(); |
75 | void copy_old(const RecMail&old); | 75 | void copy_old(const RecMail&old); |
76 | }; | 76 | }; |
77 | 77 | ||
78 | typedef QMap<QString,QString> part_plist_t; | 78 | typedef QMap<QString,QString> part_plist_t; |
79 | 79 | ||
80 | class RecPart | 80 | class RecPart |
81 | { | 81 | { |
82 | protected: | 82 | protected: |
83 | QString m_type,m_subtype,m_identifier,m_encoding,m_description; | 83 | QString m_type,m_subtype,m_identifier,m_encoding,m_description; |
84 | unsigned int m_lines,m_size; | 84 | unsigned int m_lines,m_size; |
85 | part_plist_t m_Parameters; | 85 | part_plist_t m_Parameters; |
86 | /* describes the position in the mail */ | 86 | /* describes the position in the mail */ |
87 | QValueList<int> m_poslist; | 87 | QValueList<int> m_poslist; |
88 | 88 | ||
89 | public: | 89 | public: |
90 | RecPart(); | 90 | RecPart(); |
91 | virtual ~RecPart(); | 91 | virtual ~RecPart(); |
92 | 92 | ||
93 | const QString&Type()const; | 93 | const QString&Type()const; |
94 | void setType(const QString&type); | 94 | void setType(const QString&type); |
95 | const QString&Subtype()const; | 95 | const QString&Subtype()const; |
96 | void setSubtype(const QString&subtype); | 96 | void setSubtype(const QString&subtype); |
97 | const QString&Identifier()const; | 97 | const QString&Identifier()const; |
98 | void setIdentifier(const QString&identifier); | 98 | void setIdentifier(const QString&identifier); |
99 | const QString&Encoding()const; | 99 | const QString&Encoding()const; |
100 | void setEncoding(const QString&encoding); | 100 | void setEncoding(const QString&encoding); |
101 | const QString&Description()const; | 101 | const QString&Description()const; |
102 | void setDescription(const QString&desc); | 102 | void setDescription(const QString&desc); |
103 | void setLines(unsigned int lines); | 103 | void setLines(unsigned int lines); |
104 | const unsigned int Lines()const; | 104 | const unsigned int Lines()const; |
105 | void setSize(unsigned int size); | 105 | void setSize(unsigned int size); |
106 | const unsigned int Size()const; | 106 | const unsigned int Size()const; |
107 | 107 | ||
108 | 108 | ||
109 | void setParameters(const part_plist_t&list); | 109 | void setParameters(const part_plist_t&list); |
110 | const part_plist_t&Parameters()const; | 110 | const part_plist_t&Parameters()const; |
111 | void addParameter(const QString&key,const QString&value); | 111 | void addParameter(const QString&key,const QString&value); |
112 | const QString searchParamter(const QString&key)const; | 112 | const QString searchParamter(const QString&key)const; |
113 | void setPositionlist(const QValueList<int>&poslist); | 113 | void setPositionlist(const QValueList<int>&poslist); |
114 | const QValueList<int>& Positionlist()const; | 114 | const QValueList<int>& Positionlist()const; |
115 | }; | 115 | }; |
116 | 116 | ||
117 | class RecBody | 117 | class RecBody |
118 | { | 118 | { |
119 | protected: | 119 | protected: |
120 | QString m_BodyText; | 120 | QString m_BodyText; |
121 | QValueList<RecPart> m_PartsList; | 121 | QValueList<RecPart> m_PartsList; |
122 | RecPart m_description; | 122 | RecPart m_description; |
123 | 123 | ||
124 | public: | 124 | public: |
125 | RecBody(); | 125 | RecBody(); |
126 | virtual ~RecBody(); | 126 | virtual ~RecBody(); |
127 | void setBodytext(const QString&); | 127 | void setBodytext(const QString&); |
128 | const QString& Bodytext()const; | 128 | const QString& Bodytext()const; |
129 | 129 | ||
130 | void setDescription(const RecPart&des); | 130 | void setDescription(const RecPart&des); |
131 | const RecPart& Description()const; | 131 | const RecPart& Description()const; |
132 | 132 | ||
133 | void setParts(const QValueList<RecPart>&parts); | 133 | void setParts(const QValueList<RecPart>&parts); |
134 | const QValueList<RecPart>& Parts()const; | 134 | const QValueList<RecPart>& Parts()const; |
135 | void addPart(const RecPart&part); | 135 | void addPart(const RecPart&part); |
136 | }; | 136 | }; |
137 | 137 | ||
138 | class encodedString | ||
139 | { | ||
140 | public: | ||
141 | encodedString(); | ||
142 | /* | ||
143 | creates an new content string. | ||
144 | it makes a deep copy of it! | ||
145 | */ | ||
146 | encodedString(const char*nContent,unsigned int length); | ||
147 | /* | ||
148 | Take over the nContent. Means: it will just copy the pointer, not the content. | ||
149 | so make sure: No one else frees the string, the string has allocated with | ||
150 | malloc for compatibility with c-based libs | ||
151 | */ | ||
152 | encodedString(char*nContent,unsigned int nSize); | ||
153 | /* copy construkor - makes ALWAYS a deep copy!!!! */ | ||
154 | encodedString(const encodedString&old); | ||
155 | /* assign operator - makes ALWAYS a deep copy!!!! */ | ||
156 | encodedString& operator=(const encodedString&old); | ||
157 | /* destructor - cleans the content */ | ||
158 | virtual ~encodedString(); | ||
159 | |||
160 | /* returns a pointer to the content - do not delete yoursel! */ | ||
161 | const char*Content()const; | ||
162 | /* returns the lengths of the content 'cause it must not be a null-terminated string! */ | ||
163 | const int Length()const; | ||
164 | |||
165 | /* | ||
166 | makes a deep copy of nContent! | ||
167 | */ | ||
168 | void setContent(const char*nContent,int nSize); | ||
169 | /* | ||
170 | Take over the nContent. Means: it will just copy the pointer, not the content. | ||
171 | so make sure: No one else frees the string, the string has allocated with | ||
172 | malloc for compatibility with c-based libs | ||
173 | */ | ||
174 | void setContent(char*nContent,int nSize); | ||
175 | |||
176 | protected: | ||
177 | char * content; | ||
178 | unsigned int size; | ||
179 | |||
180 | void init(); | ||
181 | void copy_old(const encodedString&old); | ||
182 | void clean(); | ||
183 | }; | ||
184 | |||
138 | #endif | 185 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index a33a16b..075d8c7 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |||
@@ -1,349 +1,358 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include "pop3wrapper.h" | 2 | #include "pop3wrapper.h" |
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | #include <libetpan/mailpop3.h> | 4 | #include <libetpan/mailpop3.h> |
5 | 5 | ||
6 | POP3wrapper::POP3wrapper( POP3account *a ) | 6 | POP3wrapper::POP3wrapper( POP3account *a ) |
7 | { | 7 | { |
8 | account = a; | 8 | account = a; |
9 | m_pop3 = NULL; | 9 | m_pop3 = NULL; |
10 | } | 10 | } |
11 | 11 | ||
12 | POP3wrapper::~POP3wrapper() | 12 | POP3wrapper::~POP3wrapper() |
13 | { | 13 | { |
14 | logout(); | 14 | logout(); |
15 | } | 15 | } |
16 | 16 | ||
17 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) | 17 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) |
18 | { | 18 | { |
19 | //qDebug( "POP3: %i of %i", current, maximum ); | 19 | //qDebug( "POP3: %i of %i", current, maximum ); |
20 | } | 20 | } |
21 | 21 | ||
22 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) | 22 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) |
23 | { | 23 | { |
24 | int err = MAILPOP3_NO_ERROR; | 24 | int err = MAILPOP3_NO_ERROR; |
25 | char *message; | 25 | char *message; |
26 | size_t length = 0; | 26 | size_t length = 0; |
27 | 27 | ||
28 | login(); | 28 | login(); |
29 | if ( !m_pop3 ) return RecBody(); | 29 | if ( !m_pop3 ) return RecBody(); |
30 | 30 | ||
31 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); | 31 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); |
32 | if ( err != MAILPOP3_NO_ERROR ) { | 32 | if ( err != MAILPOP3_NO_ERROR ) { |
33 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); | 33 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); |
34 | return RecBody(); | 34 | return RecBody(); |
35 | } | 35 | } |
36 | 36 | ||
37 | return parseBody( message ); | 37 | return parseBody( message ); |
38 | } | 38 | } |
39 | 39 | ||
40 | RecBody POP3wrapper::parseBody( const char *message ) | 40 | RecBody POP3wrapper::parseBody( const char *message ) |
41 | { | 41 | { |
42 | int err = MAILIMF_NO_ERROR; | 42 | int err = MAILIMF_NO_ERROR; |
43 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ | 43 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ |
44 | size_t curTok = 0; | 44 | size_t curTok = 0; |
45 | mailimf_message *result = 0; | 45 | mailimf_message *result = 0; |
46 | RecBody body; | 46 | RecBody body; |
47 | 47 | ||
48 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); | 48 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); |
49 | if ( err != MAILIMF_NO_ERROR ) { | 49 | if ( err != MAILIMF_NO_ERROR ) { |
50 | if (result) mailimf_message_free(result); | 50 | if (result) mailimf_message_free(result); |
51 | return body; | 51 | return body; |
52 | } | 52 | } |
53 | 53 | ||
54 | if ( result && result->msg_body && result->msg_body->bd_text ) { | 54 | if ( result && result->msg_body && result->msg_body->bd_text ) { |
55 | qDebug( "POP3: bodytext found" ); | 55 | qDebug( "POP3: bodytext found" ); |
56 | // when curTok isn't set to 0 this line will fault! 'cause upper line faults! | 56 | // when curTok isn't set to 0 this line will fault! 'cause upper line faults! |
57 | body.setBodytext( QString( result->msg_body->bd_text ) ); | 57 | body.setBodytext( QString( result->msg_body->bd_text ) ); |
58 | } | 58 | } |
59 | if (result) mailimf_message_free(result); | 59 | if (result) mailimf_message_free(result); |
60 | return body; | 60 | return body; |
61 | } | 61 | } |
62 | 62 | ||
63 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) | 63 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) |
64 | { | 64 | { |
65 | int err = MAILPOP3_NO_ERROR; | 65 | int err = MAILPOP3_NO_ERROR; |
66 | char * header = 0; | 66 | char * header = 0; |
67 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ | 67 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ |
68 | size_t length = 0; | 68 | size_t length = 0; |
69 | carray * messages = 0; | 69 | carray * messages = 0; |
70 | 70 | ||
71 | login(); | 71 | login(); |
72 | if (!m_pop3) return; | 72 | if (!m_pop3) return; |
73 | mailpop3_list( m_pop3, &messages ); | 73 | mailpop3_list( m_pop3, &messages ); |
74 | 74 | ||
75 | for (unsigned int i = 0; i < carray_count(messages);++i) { | 75 | for (unsigned int i = 0; i < carray_count(messages);++i) { |
76 | mailpop3_msg_info *info; | 76 | mailpop3_msg_info *info; |
77 | err = mailpop3_get_msg_info(m_pop3,i+1,&info); | 77 | err = mailpop3_get_msg_info(m_pop3,i+1,&info); |
78 | if (info->msg_deleted) | 78 | if (info->msg_deleted) |
79 | continue; | 79 | continue; |
80 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); | 80 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); |
81 | if ( err != MAILPOP3_NO_ERROR ) { | 81 | if ( err != MAILPOP3_NO_ERROR ) { |
82 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); | 82 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); |
83 | free(header); | 83 | free(header); |
84 | return; | 84 | return; |
85 | } | 85 | } |
86 | RecMail *mail = parseHeader( header ); | 86 | RecMail *mail = parseHeader( header ); |
87 | mail->setNumber( info->msg_index ); | 87 | mail->setNumber( info->msg_index ); |
88 | mail->setWrapper(this); | 88 | mail->setWrapper(this); |
89 | mail->setMsgsize(info->msg_size); | 89 | mail->setMsgsize(info->msg_size); |
90 | target.append( mail ); | 90 | target.append( mail ); |
91 | free(header); | 91 | free(header); |
92 | } | 92 | } |
93 | } | 93 | } |
94 | 94 | ||
95 | RecMail *POP3wrapper::parseHeader( const char *header ) | 95 | RecMail *POP3wrapper::parseHeader( const char *header ) |
96 | { | 96 | { |
97 | int err = MAILIMF_NO_ERROR; | 97 | int err = MAILIMF_NO_ERROR; |
98 | size_t curTok = 0; | 98 | size_t curTok = 0; |
99 | RecMail *mail = new RecMail(); | 99 | RecMail *mail = new RecMail(); |
100 | mailimf_fields *fields; | 100 | mailimf_fields *fields; |
101 | mailimf_references * refs; | 101 | mailimf_references * refs; |
102 | mailimf_keywords*keys; | 102 | mailimf_keywords*keys; |
103 | QString status; | 103 | QString status; |
104 | QString value; | 104 | QString value; |
105 | QBitArray mFlags(7); | 105 | QBitArray mFlags(7); |
106 | 106 | ||
107 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); | 107 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); |
108 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { | 108 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { |
109 | mailimf_field *field = (mailimf_field *) current->data; | 109 | mailimf_field *field = (mailimf_field *) current->data; |
110 | switch ( field->fld_type ) { | 110 | switch ( field->fld_type ) { |
111 | case MAILIMF_FIELD_FROM: | 111 | case MAILIMF_FIELD_FROM: |
112 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); | 112 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); |
113 | break; | 113 | break; |
114 | case MAILIMF_FIELD_TO: | 114 | case MAILIMF_FIELD_TO: |
115 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); | 115 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); |
116 | break; | 116 | break; |
117 | case MAILIMF_FIELD_CC: | 117 | case MAILIMF_FIELD_CC: |
118 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); | 118 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); |
119 | break; | 119 | break; |
120 | case MAILIMF_FIELD_BCC: | 120 | case MAILIMF_FIELD_BCC: |
121 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); | 121 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); |
122 | break; | 122 | break; |
123 | case MAILIMF_FIELD_SUBJECT: | 123 | case MAILIMF_FIELD_SUBJECT: |
124 | mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); | 124 | mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); |
125 | break; | 125 | break; |
126 | case MAILIMF_FIELD_ORIG_DATE: | 126 | case MAILIMF_FIELD_ORIG_DATE: |
127 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); | 127 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); |
128 | break; | 128 | break; |
129 | case MAILIMF_FIELD_MESSAGE_ID: | 129 | case MAILIMF_FIELD_MESSAGE_ID: |
130 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); | 130 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); |
131 | break; | 131 | break; |
132 | case MAILIMF_FIELD_REFERENCES: | 132 | case MAILIMF_FIELD_REFERENCES: |
133 | refs = field->fld_data.fld_references; | 133 | refs = field->fld_data.fld_references; |
134 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 134 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
135 | char * text = (char*)refs->mid_list->first->data; | 135 | char * text = (char*)refs->mid_list->first->data; |
136 | mail->setReplyto(QString(text)); | 136 | mail->setReplyto(QString(text)); |
137 | } | 137 | } |
138 | break; | 138 | break; |
139 | case MAILIMF_FIELD_KEYWORDS: | 139 | case MAILIMF_FIELD_KEYWORDS: |
140 | keys = field->fld_data.fld_keywords; | 140 | keys = field->fld_data.fld_keywords; |
141 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { | 141 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { |
142 | qDebug("Keyword: %s",(char*)cur->data); | 142 | qDebug("Keyword: %s",(char*)cur->data); |
143 | } | 143 | } |
144 | break; | 144 | break; |
145 | case MAILIMF_FIELD_OPTIONAL_FIELD: | 145 | case MAILIMF_FIELD_OPTIONAL_FIELD: |
146 | status = field->fld_data.fld_optional_field->fld_name; | 146 | status = field->fld_data.fld_optional_field->fld_name; |
147 | value = field->fld_data.fld_optional_field->fld_value; | 147 | value = field->fld_data.fld_optional_field->fld_value; |
148 | if (status.lower()=="status") { | 148 | if (status.lower()=="status") { |
149 | if (value.lower()=="ro") { | 149 | if (value.lower()=="ro") { |
150 | mFlags.setBit(FLAG_SEEN); | 150 | mFlags.setBit(FLAG_SEEN); |
151 | } | 151 | } |
152 | } else if (status.lower()=="x-status") { | 152 | } else if (status.lower()=="x-status") { |
153 | qDebug("X-Status: %s",value.latin1()); | 153 | qDebug("X-Status: %s",value.latin1()); |
154 | if (value.lower()=="a") { | 154 | if (value.lower()=="a") { |
155 | 155 | ||
156 | mFlags.setBit(FLAG_ANSWERED); | 156 | mFlags.setBit(FLAG_ANSWERED); |
157 | } | 157 | } |
158 | } else { | 158 | } else { |
159 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, | 159 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, |
160 | // field->fld_data.fld_optional_field->fld_value); | 160 | // field->fld_data.fld_optional_field->fld_value); |
161 | } | 161 | } |
162 | break; | 162 | break; |
163 | default: | 163 | default: |
164 | qDebug("Non parsed field"); | 164 | qDebug("Non parsed field"); |
165 | break; | 165 | break; |
166 | } | 166 | } |
167 | } | 167 | } |
168 | if (fields) mailimf_fields_free(fields); | 168 | if (fields) mailimf_fields_free(fields); |
169 | mail->setFlags(mFlags); | 169 | mail->setFlags(mFlags); |
170 | return mail; | 170 | return mail; |
171 | } | 171 | } |
172 | 172 | ||
173 | QString POP3wrapper::parseDateTime( mailimf_date_time *date ) | 173 | QString POP3wrapper::parseDateTime( mailimf_date_time *date ) |
174 | { | 174 | { |
175 | char tmp[23]; | 175 | char tmp[23]; |
176 | 176 | ||
177 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | 177 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", |
178 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | 178 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); |
179 | 179 | ||
180 | return QString( tmp ); | 180 | return QString( tmp ); |
181 | } | 181 | } |
182 | 182 | ||
183 | QString POP3wrapper::parseAddressList( mailimf_address_list *list ) | 183 | QString POP3wrapper::parseAddressList( mailimf_address_list *list ) |
184 | { | 184 | { |
185 | QString result( "" ); | 185 | QString result( "" ); |
186 | 186 | ||
187 | bool first = true; | 187 | bool first = true; |
188 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | 188 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { |
189 | mailimf_address *addr = (mailimf_address *) current->data; | 189 | mailimf_address *addr = (mailimf_address *) current->data; |
190 | 190 | ||
191 | if ( !first ) { | 191 | if ( !first ) { |
192 | result.append( "," ); | 192 | result.append( "," ); |
193 | } else { | 193 | } else { |
194 | first = false; | 194 | first = false; |
195 | } | 195 | } |
196 | 196 | ||
197 | switch ( addr->ad_type ) { | 197 | switch ( addr->ad_type ) { |
198 | case MAILIMF_ADDRESS_MAILBOX: | 198 | case MAILIMF_ADDRESS_MAILBOX: |
199 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | 199 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); |
200 | break; | 200 | break; |
201 | case MAILIMF_ADDRESS_GROUP: | 201 | case MAILIMF_ADDRESS_GROUP: |
202 | result.append( parseGroup( addr->ad_data.ad_group ) ); | 202 | result.append( parseGroup( addr->ad_data.ad_group ) ); |
203 | break; | 203 | break; |
204 | default: | 204 | default: |
205 | qDebug( "POP3: unkown mailimf address type" ); | 205 | qDebug( "POP3: unkown mailimf address type" ); |
206 | break; | 206 | break; |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
210 | return result; | 210 | return result; |
211 | } | 211 | } |
212 | 212 | ||
213 | QString POP3wrapper::parseGroup( mailimf_group *group ) | 213 | QString POP3wrapper::parseGroup( mailimf_group *group ) |
214 | { | 214 | { |
215 | QString result( "" ); | 215 | QString result( "" ); |
216 | 216 | ||
217 | result.append( group->grp_display_name ); | 217 | result.append( group->grp_display_name ); |
218 | result.append( ": " ); | 218 | result.append( ": " ); |
219 | 219 | ||
220 | if ( group->grp_mb_list != NULL ) { | 220 | if ( group->grp_mb_list != NULL ) { |
221 | result.append( parseMailboxList( group->grp_mb_list ) ); | 221 | result.append( parseMailboxList( group->grp_mb_list ) ); |
222 | } | 222 | } |
223 | 223 | ||
224 | result.append( ";" ); | 224 | result.append( ";" ); |
225 | 225 | ||
226 | return result; | 226 | return result; |
227 | } | 227 | } |
228 | 228 | ||
229 | QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) | 229 | QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) |
230 | { | 230 | { |
231 | QString result( "" ); | 231 | QString result( "" ); |
232 | 232 | ||
233 | if ( box->mb_display_name == NULL ) { | 233 | if ( box->mb_display_name == NULL ) { |
234 | result.append( box->mb_addr_spec ); | 234 | result.append( box->mb_addr_spec ); |
235 | } else { | 235 | } else { |
236 | result.append( box->mb_display_name ); | 236 | result.append( box->mb_display_name ); |
237 | result.append( " <" ); | 237 | result.append( " <" ); |
238 | result.append( box->mb_addr_spec ); | 238 | result.append( box->mb_addr_spec ); |
239 | result.append( ">" ); | 239 | result.append( ">" ); |
240 | } | 240 | } |
241 | 241 | ||
242 | return result; | 242 | return result; |
243 | } | 243 | } |
244 | 244 | ||
245 | QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) | 245 | QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) |
246 | { | 246 | { |
247 | QString result( "" ); | 247 | QString result( "" ); |
248 | 248 | ||
249 | bool first = true; | 249 | bool first = true; |
250 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { | 250 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { |
251 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | 251 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; |
252 | 252 | ||
253 | if ( !first ) { | 253 | if ( !first ) { |
254 | result.append( "," ); | 254 | result.append( "," ); |
255 | } else { | 255 | } else { |
256 | first = false; | 256 | first = false; |
257 | } | 257 | } |
258 | 258 | ||
259 | result.append( parseMailbox( box ) ); | 259 | result.append( parseMailbox( box ) ); |
260 | } | 260 | } |
261 | 261 | ||
262 | return result; | 262 | return result; |
263 | } | 263 | } |
264 | 264 | ||
265 | void POP3wrapper::login() | 265 | void POP3wrapper::login() |
266 | { | 266 | { |
267 | /* we'll hold the line */ | 267 | /* we'll hold the line */ |
268 | if ( m_pop3 != NULL ) return; | 268 | if ( m_pop3 != NULL ) return; |
269 | 269 | ||
270 | const char *server, *user, *pass; | 270 | const char *server, *user, *pass; |
271 | uint16_t port; | 271 | uint16_t port; |
272 | int err = MAILPOP3_NO_ERROR; | 272 | int err = MAILPOP3_NO_ERROR; |
273 | 273 | ||
274 | server = account->getServer().latin1(); | 274 | server = account->getServer().latin1(); |
275 | port = account->getPort().toUInt(); | 275 | port = account->getPort().toUInt(); |
276 | user = account->getUser().latin1(); | 276 | user = account->getUser().latin1(); |
277 | pass = account->getPassword().latin1(); | 277 | pass = account->getPassword().latin1(); |
278 | 278 | ||
279 | m_pop3 = mailpop3_new( 200, &pop3_progress ); | 279 | m_pop3 = mailpop3_new( 200, &pop3_progress ); |
280 | 280 | ||
281 | // connect | 281 | // connect |
282 | if (account->getSSL()) { | 282 | if (account->getSSL()) { |
283 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); | 283 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); |
284 | } else { | 284 | } else { |
285 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); | 285 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); |
286 | } | 286 | } |
287 | 287 | ||
288 | if ( err != MAILPOP3_NO_ERROR ) { | 288 | if ( err != MAILPOP3_NO_ERROR ) { |
289 | qDebug( "pop3: error connecting to %s\n reason: %s", server, | 289 | qDebug( "pop3: error connecting to %s\n reason: %s", server, |
290 | m_pop3->pop3_response ); | 290 | m_pop3->pop3_response ); |
291 | mailpop3_free( m_pop3 ); | 291 | mailpop3_free( m_pop3 ); |
292 | m_pop3 = NULL; | 292 | m_pop3 = NULL; |
293 | return; | 293 | return; |
294 | } | 294 | } |
295 | qDebug( "POP3: connected!" ); | 295 | qDebug( "POP3: connected!" ); |
296 | 296 | ||
297 | // login | 297 | // login |
298 | // TODO: decide if apop or plain login should be used | 298 | // TODO: decide if apop or plain login should be used |
299 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); | 299 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); |
300 | if ( err != MAILPOP3_NO_ERROR ) { | 300 | if ( err != MAILPOP3_NO_ERROR ) { |
301 | qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); | 301 | qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); |
302 | logout(); | 302 | logout(); |
303 | return; | 303 | return; |
304 | } | 304 | } |
305 | 305 | ||
306 | qDebug( "POP3: logged in!" ); | 306 | qDebug( "POP3: logged in!" ); |
307 | } | 307 | } |
308 | 308 | ||
309 | void POP3wrapper::logout() | 309 | void POP3wrapper::logout() |
310 | { | 310 | { |
311 | int err = MAILPOP3_NO_ERROR; | 311 | int err = MAILPOP3_NO_ERROR; |
312 | if ( m_pop3 == NULL ) return; | 312 | if ( m_pop3 == NULL ) return; |
313 | err = mailpop3_quit( m_pop3 ); | 313 | err = mailpop3_quit( m_pop3 ); |
314 | mailpop3_free( m_pop3 ); | 314 | mailpop3_free( m_pop3 ); |
315 | m_pop3 = NULL; | 315 | m_pop3 = NULL; |
316 | } | 316 | } |
317 | 317 | ||
318 | 318 | ||
319 | QList<Folder>* POP3wrapper::listFolders() | 319 | QList<Folder>* POP3wrapper::listFolders() |
320 | { | 320 | { |
321 | /* TODO: integrate MH directories | 321 | /* TODO: integrate MH directories |
322 | but not before version 0.1 ;) | 322 | but not before version 0.1 ;) |
323 | */ | 323 | */ |
324 | QList<Folder> * folders = new QList<Folder>(); | 324 | QList<Folder> * folders = new QList<Folder>(); |
325 | folders->setAutoDelete( false ); | 325 | folders->setAutoDelete( false ); |
326 | Folder*inb=new Folder("INBOX"); | 326 | Folder*inb=new Folder("INBOX"); |
327 | folders->append(inb); | 327 | folders->append(inb); |
328 | return folders; | 328 | return folders; |
329 | } | 329 | } |
330 | 330 | ||
331 | QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) | 331 | QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&) |
332 | { | 332 | { |
333 | return ""; | 333 | return ""; |
334 | } | 334 | } |
335 | 335 | ||
336 | void POP3wrapper::deleteMail(const RecMail&mail) | 336 | void POP3wrapper::deleteMail(const RecMail&mail) |
337 | { | 337 | { |
338 | login(); | 338 | login(); |
339 | if (!m_pop3) return; | 339 | if (!m_pop3) return; |
340 | int err = mailpop3_dele(m_pop3,mail.getNumber()); | 340 | int err = mailpop3_dele(m_pop3,mail.getNumber()); |
341 | if (err != MAILPOP3_NO_ERROR) { | 341 | if (err != MAILPOP3_NO_ERROR) { |
342 | qDebug("error deleting mail"); | 342 | qDebug("error deleting mail"); |
343 | } | 343 | } |
344 | } | 344 | } |
345 | 345 | ||
346 | void POP3wrapper::answeredMail(const RecMail&) | 346 | void POP3wrapper::answeredMail(const RecMail&) |
347 | { | 347 | { |
348 | } | 348 | } |
349 | 349 | ||
350 | encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&) | ||
351 | { | ||
352 | return new encodedString(); | ||
353 | } | ||
354 | |||
355 | encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&) | ||
356 | { | ||
357 | return new encodedString(); | ||
358 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index 6ff8d62..8d3adda 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h | |||
@@ -1,44 +1,48 @@ | |||
1 | #ifndef __POP3WRAPPER | 1 | #ifndef __POP3WRAPPER |
2 | #define __POP3WRAPPER | 2 | #define __POP3WRAPPER |
3 | 3 | ||
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | #include "abstractmail.h" | 5 | #include "abstractmail.h" |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | class encodedString; | ||
9 | struct mailpop3; | 10 | struct mailpop3; |
10 | 11 | ||
11 | class POP3wrapper : public AbstractMail | 12 | class POP3wrapper : public AbstractMail |
12 | { | 13 | { |
13 | Q_OBJECT | 14 | Q_OBJECT |
14 | 15 | ||
15 | public: | 16 | public: |
16 | POP3wrapper( POP3account *a ); | 17 | POP3wrapper( POP3account *a ); |
17 | virtual ~POP3wrapper(); | 18 | virtual ~POP3wrapper(); |
18 | /* mailbox will be ignored */ | 19 | /* mailbox will be ignored */ |
19 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 20 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
20 | virtual QList<Folder>* listFolders(); | 21 | virtual QList<Folder>* listFolders(); |
21 | virtual QString fetchPart(const RecMail&mail,const RecPart&part); | 22 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); |
23 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); | ||
24 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); | ||
25 | |||
22 | virtual void deleteMail(const RecMail&mail); | 26 | virtual void deleteMail(const RecMail&mail); |
23 | virtual void answeredMail(const RecMail&mail); | 27 | virtual void answeredMail(const RecMail&mail); |
24 | 28 | ||
25 | RecBody fetchBody( const RecMail &mail ); | 29 | RecBody fetchBody( const RecMail &mail ); |
26 | static void pop3_progress( size_t current, size_t maximum ); | 30 | static void pop3_progress( size_t current, size_t maximum ); |
27 | 31 | ||
28 | protected: | 32 | protected: |
29 | void login(); | 33 | void login(); |
30 | void logout(); | 34 | void logout(); |
31 | 35 | ||
32 | private: | 36 | private: |
33 | RecMail *parseHeader( const char *header ); | 37 | RecMail *parseHeader( const char *header ); |
34 | RecBody parseBody( const char *message ); | 38 | RecBody parseBody( const char *message ); |
35 | QString parseMailboxList( mailimf_mailbox_list *list ); | 39 | QString parseMailboxList( mailimf_mailbox_list *list ); |
36 | QString parseMailbox( mailimf_mailbox *box ); | 40 | QString parseMailbox( mailimf_mailbox *box ); |
37 | QString parseGroup( mailimf_group *group ); | 41 | QString parseGroup( mailimf_group *group ); |
38 | QString parseAddressList( mailimf_address_list *list ); | 42 | QString parseAddressList( mailimf_address_list *list ); |
39 | QString parseDateTime( mailimf_date_time *date ); | 43 | QString parseDateTime( mailimf_date_time *date ); |
40 | POP3account *account; | 44 | POP3account *account; |
41 | mailpop3 *m_pop3; | 45 | mailpop3 *m_pop3; |
42 | }; | 46 | }; |
43 | 47 | ||
44 | #endif | 48 | #endif |
diff --git a/noncore/net/mail/mailtypes.cpp b/noncore/net/mail/mailtypes.cpp index 8d9b247..d8a36e7 100644 --- a/noncore/net/mail/mailtypes.cpp +++ b/noncore/net/mail/mailtypes.cpp | |||
@@ -1,247 +1,335 @@ | |||
1 | #include "mailtypes.h" | 1 | #include "mailtypes.h" |
2 | 2 | #include <stdlib.h> | |
3 | 3 | ||
4 | RecMail::RecMail() | 4 | RecMail::RecMail() |
5 | :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) | 5 | :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) |
6 | { | 6 | { |
7 | init(); | 7 | init(); |
8 | } | 8 | } |
9 | 9 | ||
10 | RecMail::RecMail(const RecMail&old) | 10 | RecMail::RecMail(const RecMail&old) |
11 | :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) | 11 | :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) |
12 | { | 12 | { |
13 | init(); | 13 | init(); |
14 | copy_old(old); | 14 | copy_old(old); |
15 | qDebug("Copy constructor RecMail"); | 15 | qDebug("Copy constructor RecMail"); |
16 | } | 16 | } |
17 | 17 | ||
18 | RecMail::~RecMail() | 18 | RecMail::~RecMail() |
19 | { | 19 | { |
20 | wrapper = 0; | 20 | wrapper = 0; |
21 | } | 21 | } |
22 | 22 | ||
23 | void RecMail::copy_old(const RecMail&old) | 23 | void RecMail::copy_old(const RecMail&old) |
24 | { | 24 | { |
25 | subject = old.subject; | 25 | subject = old.subject; |
26 | date = old.date; | 26 | date = old.date; |
27 | mbox = old.mbox; | 27 | mbox = old.mbox; |
28 | msg_id = old.msg_id; | 28 | msg_id = old.msg_id; |
29 | msg_size = old.msg_size; | 29 | msg_size = old.msg_size; |
30 | msg_number = old.msg_number; | 30 | msg_number = old.msg_number; |
31 | from = old.from; | 31 | from = old.from; |
32 | msg_flags = old.msg_flags; | 32 | msg_flags = old.msg_flags; |
33 | to = old.to; | 33 | to = old.to; |
34 | cc = old.cc; | 34 | cc = old.cc; |
35 | bcc = old.bcc; | 35 | bcc = old.bcc; |
36 | wrapper = old.wrapper; | 36 | wrapper = old.wrapper; |
37 | } | 37 | } |
38 | 38 | ||
39 | void RecMail::init() | 39 | void RecMail::init() |
40 | { | 40 | { |
41 | to.clear(); | 41 | to.clear(); |
42 | cc.clear(); | 42 | cc.clear(); |
43 | bcc.clear(); | 43 | bcc.clear(); |
44 | wrapper = 0; | 44 | wrapper = 0; |
45 | } | 45 | } |
46 | 46 | ||
47 | void RecMail::setWrapper(AbstractMail*awrapper) | 47 | void RecMail::setWrapper(AbstractMail*awrapper) |
48 | { | 48 | { |
49 | wrapper = awrapper; | 49 | wrapper = awrapper; |
50 | } | 50 | } |
51 | 51 | ||
52 | AbstractMail* RecMail::Wrapper() | 52 | AbstractMail* RecMail::Wrapper() |
53 | { | 53 | { |
54 | return wrapper; | 54 | return wrapper; |
55 | } | 55 | } |
56 | 56 | ||
57 | void RecMail::setTo(const QStringList&list) | 57 | void RecMail::setTo(const QStringList&list) |
58 | { | 58 | { |
59 | to = list; | 59 | to = list; |
60 | } | 60 | } |
61 | 61 | ||
62 | const QStringList&RecMail::To()const | 62 | const QStringList&RecMail::To()const |
63 | { | 63 | { |
64 | return to; | 64 | return to; |
65 | } | 65 | } |
66 | 66 | ||
67 | void RecMail::setCC(const QStringList&list) | 67 | void RecMail::setCC(const QStringList&list) |
68 | { | 68 | { |
69 | cc = list; | 69 | cc = list; |
70 | } | 70 | } |
71 | 71 | ||
72 | const QStringList&RecMail::CC()const | 72 | const QStringList&RecMail::CC()const |
73 | { | 73 | { |
74 | return cc; | 74 | return cc; |
75 | } | 75 | } |
76 | 76 | ||
77 | void RecMail::setBcc(const QStringList&list) | 77 | void RecMail::setBcc(const QStringList&list) |
78 | { | 78 | { |
79 | bcc = list; | 79 | bcc = list; |
80 | } | 80 | } |
81 | 81 | ||
82 | const QStringList& RecMail::Bcc()const | 82 | const QStringList& RecMail::Bcc()const |
83 | { | 83 | { |
84 | return bcc; | 84 | return bcc; |
85 | } | 85 | } |
86 | 86 | ||
87 | RecPart::RecPart() | 87 | RecPart::RecPart() |
88 | : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) | 88 | : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) |
89 | { | 89 | { |
90 | m_Parameters.clear(); | 90 | m_Parameters.clear(); |
91 | m_poslist.clear(); | 91 | m_poslist.clear(); |
92 | } | 92 | } |
93 | 93 | ||
94 | RecPart::~RecPart() | 94 | RecPart::~RecPart() |
95 | { | 95 | { |
96 | } | 96 | } |
97 | 97 | ||
98 | void RecPart::setSize(unsigned int size) | 98 | void RecPart::setSize(unsigned int size) |
99 | { | 99 | { |
100 | m_size = size; | 100 | m_size = size; |
101 | } | 101 | } |
102 | 102 | ||
103 | const unsigned int RecPart::Size()const | 103 | const unsigned int RecPart::Size()const |
104 | { | 104 | { |
105 | return m_size; | 105 | return m_size; |
106 | } | 106 | } |
107 | 107 | ||
108 | void RecPart::setLines(unsigned int lines) | 108 | void RecPart::setLines(unsigned int lines) |
109 | { | 109 | { |
110 | m_lines = lines; | 110 | m_lines = lines; |
111 | } | 111 | } |
112 | 112 | ||
113 | const unsigned int RecPart::Lines()const | 113 | const unsigned int RecPart::Lines()const |
114 | { | 114 | { |
115 | return m_lines; | 115 | return m_lines; |
116 | } | 116 | } |
117 | 117 | ||
118 | const QString& RecPart::Type()const | 118 | const QString& RecPart::Type()const |
119 | { | 119 | { |
120 | return m_type; | 120 | return m_type; |
121 | } | 121 | } |
122 | 122 | ||
123 | void RecPart::setType(const QString&type) | 123 | void RecPart::setType(const QString&type) |
124 | { | 124 | { |
125 | m_type = type; | 125 | m_type = type; |
126 | } | 126 | } |
127 | 127 | ||
128 | const QString& RecPart::Subtype()const | 128 | const QString& RecPart::Subtype()const |
129 | { | 129 | { |
130 | return m_subtype; | 130 | return m_subtype; |
131 | } | 131 | } |
132 | 132 | ||
133 | void RecPart::setSubtype(const QString&subtype) | 133 | void RecPart::setSubtype(const QString&subtype) |
134 | { | 134 | { |
135 | m_subtype = subtype; | 135 | m_subtype = subtype; |
136 | } | 136 | } |
137 | 137 | ||
138 | const QString& RecPart::Identifier()const | 138 | const QString& RecPart::Identifier()const |
139 | { | 139 | { |
140 | return m_identifier; | 140 | return m_identifier; |
141 | } | 141 | } |
142 | 142 | ||
143 | void RecPart::setIdentifier(const QString&identifier) | 143 | void RecPart::setIdentifier(const QString&identifier) |
144 | { | 144 | { |
145 | m_identifier = identifier; | 145 | m_identifier = identifier; |
146 | } | 146 | } |
147 | 147 | ||
148 | const QString& RecPart::Encoding()const | 148 | const QString& RecPart::Encoding()const |
149 | { | 149 | { |
150 | return m_encoding; | 150 | return m_encoding; |
151 | } | 151 | } |
152 | 152 | ||
153 | void RecPart::setEncoding(const QString&encoding) | 153 | void RecPart::setEncoding(const QString&encoding) |
154 | { | 154 | { |
155 | m_encoding = encoding; | 155 | m_encoding = encoding; |
156 | } | 156 | } |
157 | 157 | ||
158 | const QString& RecPart::Description()const | 158 | const QString& RecPart::Description()const |
159 | { | 159 | { |
160 | return m_description; | 160 | return m_description; |
161 | } | 161 | } |
162 | 162 | ||
163 | void RecPart::setDescription(const QString&desc) | 163 | void RecPart::setDescription(const QString&desc) |
164 | { | 164 | { |
165 | m_description = desc; | 165 | m_description = desc; |
166 | } | 166 | } |
167 | 167 | ||
168 | void RecPart::setParameters(const part_plist_t&list) | 168 | void RecPart::setParameters(const part_plist_t&list) |
169 | { | 169 | { |
170 | m_Parameters = list; | 170 | m_Parameters = list; |
171 | } | 171 | } |
172 | 172 | ||
173 | const part_plist_t& RecPart::Parameters()const | 173 | const part_plist_t& RecPart::Parameters()const |
174 | { | 174 | { |
175 | return m_Parameters; | 175 | return m_Parameters; |
176 | } | 176 | } |
177 | 177 | ||
178 | void RecPart::addParameter(const QString&key,const QString&value) | 178 | void RecPart::addParameter(const QString&key,const QString&value) |
179 | { | 179 | { |
180 | m_Parameters[key]=value; | 180 | m_Parameters[key]=value; |
181 | } | 181 | } |
182 | 182 | ||
183 | const QString RecPart::searchParamter(const QString&key)const | 183 | const QString RecPart::searchParamter(const QString&key)const |
184 | { | 184 | { |
185 | QString value(""); | 185 | QString value(""); |
186 | part_plist_t::ConstIterator it = m_Parameters.find(key); | 186 | part_plist_t::ConstIterator it = m_Parameters.find(key); |
187 | if (it != m_Parameters.end()) { | 187 | if (it != m_Parameters.end()) { |
188 | value = it.data(); | 188 | value = it.data(); |
189 | } | 189 | } |
190 | return value; | 190 | return value; |
191 | } | 191 | } |
192 | 192 | ||
193 | void RecPart::setPositionlist(const QValueList<int>&poslist) | 193 | void RecPart::setPositionlist(const QValueList<int>&poslist) |
194 | { | 194 | { |
195 | m_poslist = poslist; | 195 | m_poslist = poslist; |
196 | } | 196 | } |
197 | 197 | ||
198 | const QValueList<int>& RecPart::Positionlist()const | 198 | const QValueList<int>& RecPart::Positionlist()const |
199 | { | 199 | { |
200 | return m_poslist; | 200 | return m_poslist; |
201 | } | 201 | } |
202 | 202 | ||
203 | RecBody::RecBody() | 203 | RecBody::RecBody() |
204 | : m_BodyText(),m_PartsList(),m_description() | 204 | : m_BodyText(),m_PartsList(),m_description() |
205 | { | 205 | { |
206 | m_PartsList.clear(); | 206 | m_PartsList.clear(); |
207 | } | 207 | } |
208 | 208 | ||
209 | RecBody::~RecBody() | 209 | RecBody::~RecBody() |
210 | { | 210 | { |
211 | } | 211 | } |
212 | 212 | ||
213 | void RecBody::setBodytext(const QString&bodyText) | 213 | void RecBody::setBodytext(const QString&bodyText) |
214 | { | 214 | { |
215 | m_BodyText = bodyText; | 215 | m_BodyText = bodyText; |
216 | } | 216 | } |
217 | 217 | ||
218 | const QString& RecBody::Bodytext()const | 218 | const QString& RecBody::Bodytext()const |
219 | { | 219 | { |
220 | return m_BodyText; | 220 | return m_BodyText; |
221 | } | 221 | } |
222 | 222 | ||
223 | void RecBody::setParts(const QValueList<RecPart>&parts) | 223 | void RecBody::setParts(const QValueList<RecPart>&parts) |
224 | { | 224 | { |
225 | m_PartsList.clear(); | 225 | m_PartsList.clear(); |
226 | m_PartsList = parts; | 226 | m_PartsList = parts; |
227 | } | 227 | } |
228 | 228 | ||
229 | const QValueList<RecPart>& RecBody::Parts()const | 229 | const QValueList<RecPart>& RecBody::Parts()const |
230 | { | 230 | { |
231 | return m_PartsList; | 231 | return m_PartsList; |
232 | } | 232 | } |
233 | 233 | ||
234 | void RecBody::addPart(const RecPart& part) | 234 | void RecBody::addPart(const RecPart& part) |
235 | { | 235 | { |
236 | m_PartsList.append(part); | 236 | m_PartsList.append(part); |
237 | } | 237 | } |
238 | 238 | ||
239 | void RecBody::setDescription(const RecPart&des) | 239 | void RecBody::setDescription(const RecPart&des) |
240 | { | 240 | { |
241 | m_description = des; | 241 | m_description = des; |
242 | } | 242 | } |
243 | 243 | ||
244 | const RecPart& RecBody::Description()const | 244 | const RecPart& RecBody::Description()const |
245 | { | 245 | { |
246 | return m_description; | 246 | return m_description; |
247 | } | 247 | } |
248 | |||
249 | /* handling encoded content */ | ||
250 | encodedString::encodedString() | ||
251 | { | ||
252 | init(); | ||
253 | } | ||
254 | |||
255 | encodedString::encodedString(const char*nContent,unsigned int nSize) | ||
256 | { | ||
257 | init(); | ||
258 | setContent(nContent,nSize); | ||
259 | } | ||
260 | |||
261 | encodedString::encodedString(char*nContent,unsigned int nSize) | ||
262 | { | ||
263 | init(); | ||
264 | setContent(nContent,nSize); | ||
265 | } | ||
266 | |||
267 | encodedString::encodedString(const encodedString&old) | ||
268 | { | ||
269 | init(); | ||
270 | copy_old(old); | ||
271 | qDebug("encodedeString: copy constructor!"); | ||
272 | } | ||
273 | |||
274 | encodedString& encodedString::operator=(const encodedString&old) | ||
275 | { | ||
276 | init(); | ||
277 | copy_old(old); | ||
278 | qDebug("encodedString: assign operator!"); | ||
279 | return *this; | ||
280 | } | ||
281 | |||
282 | encodedString::~encodedString() | ||
283 | { | ||
284 | clean(); | ||
285 | } | ||
286 | |||
287 | void encodedString::init() | ||
288 | { | ||
289 | content = 0; | ||
290 | size = 0; | ||
291 | } | ||
292 | |||
293 | void encodedString::clean() | ||
294 | { | ||
295 | if (content) { | ||
296 | free(content); | ||
297 | } | ||
298 | content = 0; | ||
299 | size = 0; | ||
300 | } | ||
301 | |||
302 | void encodedString::copy_old(const encodedString&old) | ||
303 | { | ||
304 | clean(); | ||
305 | if (old.size>0 && old.content) { | ||
306 | content = (char*)malloc(old.size*sizeof(char)); | ||
307 | memcpy(content,old.content,size); | ||
308 | size = old.size; | ||
309 | } | ||
310 | } | ||
311 | |||
312 | const char*encodedString::Content()const | ||
313 | { | ||
314 | return content; | ||
315 | } | ||
316 | |||
317 | const int encodedString::Length()const | ||
318 | { | ||
319 | return size; | ||
320 | } | ||
321 | |||
322 | void encodedString::setContent(const char*nContent,int nSize) | ||
323 | { | ||
324 | if (nSize>0 && nContent) { | ||
325 | content = (char*)malloc(nSize*sizeof(char)); | ||
326 | memcpy(content,nContent,nSize); | ||
327 | size = nSize; | ||
328 | } | ||
329 | } | ||
330 | |||
331 | void encodedString::setContent(char*nContent,int nSize) | ||
332 | { | ||
333 | content = nContent; | ||
334 | size = nSize; | ||
335 | } | ||
diff --git a/noncore/net/mail/mailtypes.h b/noncore/net/mail/mailtypes.h index 7d7bebc..abfbe65 100644 --- a/noncore/net/mail/mailtypes.h +++ b/noncore/net/mail/mailtypes.h | |||
@@ -1,138 +1,185 @@ | |||
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 | #include <qmap.h> | 15 | #include <qmap.h> |
16 | #include <qvaluelist.h> | 16 | #include <qvaluelist.h> |
17 | 17 | ||
18 | class AbstractMail; | 18 | class AbstractMail; |
19 | /* a class to describe mails in a mailbox */ | 19 | /* a class to describe mails in a mailbox */ |
20 | /* Attention! | 20 | /* Attention! |
21 | From programmers point of view it would make sense to | 21 | From programmers point of view it would make sense to |
22 | store the mail body into this class, too. | 22 | store the mail body into this class, too. |
23 | But: not from the point of view of the device. | 23 | But: not from the point of view of the device. |
24 | Mailbodies can be real large. So we request them when | 24 | Mailbodies can be real large. So we request them when |
25 | needed from the mail-wrapper class direct from the server itself | 25 | needed from the mail-wrapper class direct from the server itself |
26 | (imap) or from a file-based cache (pop3?) | 26 | (imap) or from a file-based cache (pop3?) |
27 | So there is no interface "const QString&body()" but you should | 27 | So there is no interface "const QString&body()" but you should |
28 | make a request to the mailwrapper with this class as parameter to | 28 | make a request to the mailwrapper with this class as parameter to |
29 | get the body. Same words for the attachments. | 29 | get the body. Same words for the attachments. |
30 | */ | 30 | */ |
31 | class RecMail | 31 | class RecMail |
32 | { | 32 | { |
33 | public: | 33 | public: |
34 | RecMail(); | 34 | RecMail(); |
35 | RecMail(const RecMail&old); | 35 | RecMail(const RecMail&old); |
36 | virtual ~RecMail(); | 36 | virtual ~RecMail(); |
37 | 37 | ||
38 | const int getNumber()const{return msg_number;} | 38 | const int getNumber()const{return msg_number;} |
39 | void setNumber(int number){msg_number=number;} | 39 | void setNumber(int number){msg_number=number;} |
40 | const QString&getDate()const{ return date; } | 40 | const QString&getDate()const{ return date; } |
41 | void setDate( const QString&a ) { date = a; } | 41 | void setDate( const QString&a ) { date = a; } |
42 | const QString&getFrom()const{ return from; } | 42 | const QString&getFrom()const{ return from; } |
43 | void setFrom( const QString&a ) { from = a; } | 43 | void setFrom( const QString&a ) { from = a; } |
44 | const QString&getSubject()const { return subject; } | 44 | const QString&getSubject()const { return subject; } |
45 | void setSubject( const QString&s ) { subject = s; } | 45 | void setSubject( const QString&s ) { subject = s; } |
46 | const QString&getMbox()const{return mbox;} | 46 | const QString&getMbox()const{return mbox;} |
47 | void setMbox(const QString&box){mbox = box;} | 47 | void setMbox(const QString&box){mbox = box;} |
48 | void setMsgid(const QString&id){msg_id=id;} | 48 | void setMsgid(const QString&id){msg_id=id;} |
49 | const QString&Msgid()const{return msg_id;} | 49 | const QString&Msgid()const{return msg_id;} |
50 | void setReplyto(const QString&reply){replyto=reply;} | 50 | void setReplyto(const QString&reply){replyto=reply;} |
51 | const QString&Replyto()const{return replyto;} | 51 | const QString&Replyto()const{return replyto;} |
52 | void setMsgsize(int size){msg_size = size;} | 52 | void setMsgsize(int size){msg_size = size;} |
53 | const int Msgsize()const{return msg_size;} | 53 | const int Msgsize()const{return msg_size;} |
54 | 54 | ||
55 | 55 | ||
56 | void setTo(const QStringList&list); | 56 | void setTo(const QStringList&list); |
57 | const QStringList&To()const; | 57 | const QStringList&To()const; |
58 | void setCC(const QStringList&list); | 58 | void setCC(const QStringList&list); |
59 | const QStringList&CC()const; | 59 | const QStringList&CC()const; |
60 | void setBcc(const QStringList&list); | 60 | void setBcc(const QStringList&list); |
61 | const QStringList&Bcc()const; | 61 | const QStringList&Bcc()const; |
62 | const QBitArray&getFlags()const{return msg_flags;} | 62 | const QBitArray&getFlags()const{return msg_flags;} |
63 | void setFlags(const QBitArray&flags){msg_flags = flags;} | 63 | void setFlags(const QBitArray&flags){msg_flags = flags;} |
64 | 64 | ||
65 | void setWrapper(AbstractMail*wrapper); | 65 | void setWrapper(AbstractMail*wrapper); |
66 | AbstractMail* Wrapper(); | 66 | AbstractMail* Wrapper(); |
67 | 67 | ||
68 | protected: | 68 | protected: |
69 | QString subject,date,from,mbox,msg_id,replyto; | 69 | QString subject,date,from,mbox,msg_id,replyto; |
70 | int msg_number,msg_size; | 70 | int msg_number,msg_size; |
71 | QBitArray msg_flags; | 71 | QBitArray msg_flags; |
72 | QStringList to,cc,bcc; | 72 | QStringList to,cc,bcc; |
73 | AbstractMail*wrapper; | 73 | AbstractMail*wrapper; |
74 | void init(); | 74 | void init(); |
75 | void copy_old(const RecMail&old); | 75 | void copy_old(const RecMail&old); |
76 | }; | 76 | }; |
77 | 77 | ||
78 | typedef QMap<QString,QString> part_plist_t; | 78 | typedef QMap<QString,QString> part_plist_t; |
79 | 79 | ||
80 | class RecPart | 80 | class RecPart |
81 | { | 81 | { |
82 | protected: | 82 | protected: |
83 | QString m_type,m_subtype,m_identifier,m_encoding,m_description; | 83 | QString m_type,m_subtype,m_identifier,m_encoding,m_description; |
84 | unsigned int m_lines,m_size; | 84 | unsigned int m_lines,m_size; |
85 | part_plist_t m_Parameters; | 85 | part_plist_t m_Parameters; |
86 | /* describes the position in the mail */ | 86 | /* describes the position in the mail */ |
87 | QValueList<int> m_poslist; | 87 | QValueList<int> m_poslist; |
88 | 88 | ||
89 | public: | 89 | public: |
90 | RecPart(); | 90 | RecPart(); |
91 | virtual ~RecPart(); | 91 | virtual ~RecPart(); |
92 | 92 | ||
93 | const QString&Type()const; | 93 | const QString&Type()const; |
94 | void setType(const QString&type); | 94 | void setType(const QString&type); |
95 | const QString&Subtype()const; | 95 | const QString&Subtype()const; |
96 | void setSubtype(const QString&subtype); | 96 | void setSubtype(const QString&subtype); |
97 | const QString&Identifier()const; | 97 | const QString&Identifier()const; |
98 | void setIdentifier(const QString&identifier); | 98 | void setIdentifier(const QString&identifier); |
99 | const QString&Encoding()const; | 99 | const QString&Encoding()const; |
100 | void setEncoding(const QString&encoding); | 100 | void setEncoding(const QString&encoding); |
101 | const QString&Description()const; | 101 | const QString&Description()const; |
102 | void setDescription(const QString&desc); | 102 | void setDescription(const QString&desc); |
103 | void setLines(unsigned int lines); | 103 | void setLines(unsigned int lines); |
104 | const unsigned int Lines()const; | 104 | const unsigned int Lines()const; |
105 | void setSize(unsigned int size); | 105 | void setSize(unsigned int size); |
106 | const unsigned int Size()const; | 106 | const unsigned int Size()const; |
107 | 107 | ||
108 | 108 | ||
109 | void setParameters(const part_plist_t&list); | 109 | void setParameters(const part_plist_t&list); |
110 | const part_plist_t&Parameters()const; | 110 | const part_plist_t&Parameters()const; |
111 | void addParameter(const QString&key,const QString&value); | 111 | void addParameter(const QString&key,const QString&value); |
112 | const QString searchParamter(const QString&key)const; | 112 | const QString searchParamter(const QString&key)const; |
113 | void setPositionlist(const QValueList<int>&poslist); | 113 | void setPositionlist(const QValueList<int>&poslist); |
114 | const QValueList<int>& Positionlist()const; | 114 | const QValueList<int>& Positionlist()const; |
115 | }; | 115 | }; |
116 | 116 | ||
117 | class RecBody | 117 | class RecBody |
118 | { | 118 | { |
119 | protected: | 119 | protected: |
120 | QString m_BodyText; | 120 | QString m_BodyText; |
121 | QValueList<RecPart> m_PartsList; | 121 | QValueList<RecPart> m_PartsList; |
122 | RecPart m_description; | 122 | RecPart m_description; |
123 | 123 | ||
124 | public: | 124 | public: |
125 | RecBody(); | 125 | RecBody(); |
126 | virtual ~RecBody(); | 126 | virtual ~RecBody(); |
127 | void setBodytext(const QString&); | 127 | void setBodytext(const QString&); |
128 | const QString& Bodytext()const; | 128 | const QString& Bodytext()const; |
129 | 129 | ||
130 | void setDescription(const RecPart&des); | 130 | void setDescription(const RecPart&des); |
131 | const RecPart& Description()const; | 131 | const RecPart& Description()const; |
132 | 132 | ||
133 | void setParts(const QValueList<RecPart>&parts); | 133 | void setParts(const QValueList<RecPart>&parts); |
134 | const QValueList<RecPart>& Parts()const; | 134 | const QValueList<RecPart>& Parts()const; |
135 | void addPart(const RecPart&part); | 135 | void addPart(const RecPart&part); |
136 | }; | 136 | }; |
137 | 137 | ||
138 | class encodedString | ||
139 | { | ||
140 | public: | ||
141 | encodedString(); | ||
142 | /* | ||
143 | creates an new content string. | ||
144 | it makes a deep copy of it! | ||
145 | */ | ||
146 | encodedString(const char*nContent,unsigned int length); | ||
147 | /* | ||
148 | Take over the nContent. Means: it will just copy the pointer, not the content. | ||
149 | so make sure: No one else frees the string, the string has allocated with | ||
150 | malloc for compatibility with c-based libs | ||
151 | */ | ||
152 | encodedString(char*nContent,unsigned int nSize); | ||
153 | /* copy construkor - makes ALWAYS a deep copy!!!! */ | ||
154 | encodedString(const encodedString&old); | ||
155 | /* assign operator - makes ALWAYS a deep copy!!!! */ | ||
156 | encodedString& operator=(const encodedString&old); | ||
157 | /* destructor - cleans the content */ | ||
158 | virtual ~encodedString(); | ||
159 | |||
160 | /* returns a pointer to the content - do not delete yoursel! */ | ||
161 | const char*Content()const; | ||
162 | /* returns the lengths of the content 'cause it must not be a null-terminated string! */ | ||
163 | const int Length()const; | ||
164 | |||
165 | /* | ||
166 | makes a deep copy of nContent! | ||
167 | */ | ||
168 | void setContent(const char*nContent,int nSize); | ||
169 | /* | ||
170 | Take over the nContent. Means: it will just copy the pointer, not the content. | ||
171 | so make sure: No one else frees the string, the string has allocated with | ||
172 | malloc for compatibility with c-based libs | ||
173 | */ | ||
174 | void setContent(char*nContent,int nSize); | ||
175 | |||
176 | protected: | ||
177 | char * content; | ||
178 | unsigned int size; | ||
179 | |||
180 | void init(); | ||
181 | void copy_old(const encodedString&old); | ||
182 | void clean(); | ||
183 | }; | ||
184 | |||
138 | #endif | 185 | #endif |
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp index a33a16b..075d8c7 100644 --- a/noncore/net/mail/pop3wrapper.cpp +++ b/noncore/net/mail/pop3wrapper.cpp | |||
@@ -1,349 +1,358 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include "pop3wrapper.h" | 2 | #include "pop3wrapper.h" |
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | #include <libetpan/mailpop3.h> | 4 | #include <libetpan/mailpop3.h> |
5 | 5 | ||
6 | POP3wrapper::POP3wrapper( POP3account *a ) | 6 | POP3wrapper::POP3wrapper( POP3account *a ) |
7 | { | 7 | { |
8 | account = a; | 8 | account = a; |
9 | m_pop3 = NULL; | 9 | m_pop3 = NULL; |
10 | } | 10 | } |
11 | 11 | ||
12 | POP3wrapper::~POP3wrapper() | 12 | POP3wrapper::~POP3wrapper() |
13 | { | 13 | { |
14 | logout(); | 14 | logout(); |
15 | } | 15 | } |
16 | 16 | ||
17 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) | 17 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) |
18 | { | 18 | { |
19 | //qDebug( "POP3: %i of %i", current, maximum ); | 19 | //qDebug( "POP3: %i of %i", current, maximum ); |
20 | } | 20 | } |
21 | 21 | ||
22 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) | 22 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) |
23 | { | 23 | { |
24 | int err = MAILPOP3_NO_ERROR; | 24 | int err = MAILPOP3_NO_ERROR; |
25 | char *message; | 25 | char *message; |
26 | size_t length = 0; | 26 | size_t length = 0; |
27 | 27 | ||
28 | login(); | 28 | login(); |
29 | if ( !m_pop3 ) return RecBody(); | 29 | if ( !m_pop3 ) return RecBody(); |
30 | 30 | ||
31 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); | 31 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); |
32 | if ( err != MAILPOP3_NO_ERROR ) { | 32 | if ( err != MAILPOP3_NO_ERROR ) { |
33 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); | 33 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); |
34 | return RecBody(); | 34 | return RecBody(); |
35 | } | 35 | } |
36 | 36 | ||
37 | return parseBody( message ); | 37 | return parseBody( message ); |
38 | } | 38 | } |
39 | 39 | ||
40 | RecBody POP3wrapper::parseBody( const char *message ) | 40 | RecBody POP3wrapper::parseBody( const char *message ) |
41 | { | 41 | { |
42 | int err = MAILIMF_NO_ERROR; | 42 | int err = MAILIMF_NO_ERROR; |
43 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ | 43 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ |
44 | size_t curTok = 0; | 44 | size_t curTok = 0; |
45 | mailimf_message *result = 0; | 45 | mailimf_message *result = 0; |
46 | RecBody body; | 46 | RecBody body; |
47 | 47 | ||
48 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); | 48 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); |
49 | if ( err != MAILIMF_NO_ERROR ) { | 49 | if ( err != MAILIMF_NO_ERROR ) { |
50 | if (result) mailimf_message_free(result); | 50 | if (result) mailimf_message_free(result); |
51 | return body; | 51 | return body; |
52 | } | 52 | } |
53 | 53 | ||
54 | if ( result && result->msg_body && result->msg_body->bd_text ) { | 54 | if ( result && result->msg_body && result->msg_body->bd_text ) { |
55 | qDebug( "POP3: bodytext found" ); | 55 | qDebug( "POP3: bodytext found" ); |
56 | // when curTok isn't set to 0 this line will fault! 'cause upper line faults! | 56 | // when curTok isn't set to 0 this line will fault! 'cause upper line faults! |
57 | body.setBodytext( QString( result->msg_body->bd_text ) ); | 57 | body.setBodytext( QString( result->msg_body->bd_text ) ); |
58 | } | 58 | } |
59 | if (result) mailimf_message_free(result); | 59 | if (result) mailimf_message_free(result); |
60 | return body; | 60 | return body; |
61 | } | 61 | } |
62 | 62 | ||
63 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) | 63 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) |
64 | { | 64 | { |
65 | int err = MAILPOP3_NO_ERROR; | 65 | int err = MAILPOP3_NO_ERROR; |
66 | char * header = 0; | 66 | char * header = 0; |
67 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ | 67 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ |
68 | size_t length = 0; | 68 | size_t length = 0; |
69 | carray * messages = 0; | 69 | carray * messages = 0; |
70 | 70 | ||
71 | login(); | 71 | login(); |
72 | if (!m_pop3) return; | 72 | if (!m_pop3) return; |
73 | mailpop3_list( m_pop3, &messages ); | 73 | mailpop3_list( m_pop3, &messages ); |
74 | 74 | ||
75 | for (unsigned int i = 0; i < carray_count(messages);++i) { | 75 | for (unsigned int i = 0; i < carray_count(messages);++i) { |
76 | mailpop3_msg_info *info; | 76 | mailpop3_msg_info *info; |
77 | err = mailpop3_get_msg_info(m_pop3,i+1,&info); | 77 | err = mailpop3_get_msg_info(m_pop3,i+1,&info); |
78 | if (info->msg_deleted) | 78 | if (info->msg_deleted) |
79 | continue; | 79 | continue; |
80 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); | 80 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); |
81 | if ( err != MAILPOP3_NO_ERROR ) { | 81 | if ( err != MAILPOP3_NO_ERROR ) { |
82 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); | 82 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); |
83 | free(header); | 83 | free(header); |
84 | return; | 84 | return; |
85 | } | 85 | } |
86 | RecMail *mail = parseHeader( header ); | 86 | RecMail *mail = parseHeader( header ); |
87 | mail->setNumber( info->msg_index ); | 87 | mail->setNumber( info->msg_index ); |
88 | mail->setWrapper(this); | 88 | mail->setWrapper(this); |
89 | mail->setMsgsize(info->msg_size); | 89 | mail->setMsgsize(info->msg_size); |
90 | target.append( mail ); | 90 | target.append( mail ); |
91 | free(header); | 91 | free(header); |
92 | } | 92 | } |
93 | } | 93 | } |
94 | 94 | ||
95 | RecMail *POP3wrapper::parseHeader( const char *header ) | 95 | RecMail *POP3wrapper::parseHeader( const char *header ) |
96 | { | 96 | { |
97 | int err = MAILIMF_NO_ERROR; | 97 | int err = MAILIMF_NO_ERROR; |
98 | size_t curTok = 0; | 98 | size_t curTok = 0; |
99 | RecMail *mail = new RecMail(); | 99 | RecMail *mail = new RecMail(); |
100 | mailimf_fields *fields; | 100 | mailimf_fields *fields; |
101 | mailimf_references * refs; | 101 | mailimf_references * refs; |
102 | mailimf_keywords*keys; | 102 | mailimf_keywords*keys; |
103 | QString status; | 103 | QString status; |
104 | QString value; | 104 | QString value; |
105 | QBitArray mFlags(7); | 105 | QBitArray mFlags(7); |
106 | 106 | ||
107 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); | 107 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); |
108 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { | 108 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { |
109 | mailimf_field *field = (mailimf_field *) current->data; | 109 | mailimf_field *field = (mailimf_field *) current->data; |
110 | switch ( field->fld_type ) { | 110 | switch ( field->fld_type ) { |
111 | case MAILIMF_FIELD_FROM: | 111 | case MAILIMF_FIELD_FROM: |
112 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); | 112 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); |
113 | break; | 113 | break; |
114 | case MAILIMF_FIELD_TO: | 114 | case MAILIMF_FIELD_TO: |
115 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); | 115 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); |
116 | break; | 116 | break; |
117 | case MAILIMF_FIELD_CC: | 117 | case MAILIMF_FIELD_CC: |
118 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); | 118 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); |
119 | break; | 119 | break; |
120 | case MAILIMF_FIELD_BCC: | 120 | case MAILIMF_FIELD_BCC: |
121 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); | 121 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); |
122 | break; | 122 | break; |
123 | case MAILIMF_FIELD_SUBJECT: | 123 | case MAILIMF_FIELD_SUBJECT: |
124 | mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); | 124 | mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); |
125 | break; | 125 | break; |
126 | case MAILIMF_FIELD_ORIG_DATE: | 126 | case MAILIMF_FIELD_ORIG_DATE: |
127 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); | 127 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); |
128 | break; | 128 | break; |
129 | case MAILIMF_FIELD_MESSAGE_ID: | 129 | case MAILIMF_FIELD_MESSAGE_ID: |
130 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); | 130 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); |
131 | break; | 131 | break; |
132 | case MAILIMF_FIELD_REFERENCES: | 132 | case MAILIMF_FIELD_REFERENCES: |
133 | refs = field->fld_data.fld_references; | 133 | refs = field->fld_data.fld_references; |
134 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 134 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
135 | char * text = (char*)refs->mid_list->first->data; | 135 | char * text = (char*)refs->mid_list->first->data; |
136 | mail->setReplyto(QString(text)); | 136 | mail->setReplyto(QString(text)); |
137 | } | 137 | } |
138 | break; | 138 | break; |
139 | case MAILIMF_FIELD_KEYWORDS: | 139 | case MAILIMF_FIELD_KEYWORDS: |
140 | keys = field->fld_data.fld_keywords; | 140 | keys = field->fld_data.fld_keywords; |
141 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { | 141 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { |
142 | qDebug("Keyword: %s",(char*)cur->data); | 142 | qDebug("Keyword: %s",(char*)cur->data); |
143 | } | 143 | } |
144 | break; | 144 | break; |
145 | case MAILIMF_FIELD_OPTIONAL_FIELD: | 145 | case MAILIMF_FIELD_OPTIONAL_FIELD: |
146 | status = field->fld_data.fld_optional_field->fld_name; | 146 | status = field->fld_data.fld_optional_field->fld_name; |
147 | value = field->fld_data.fld_optional_field->fld_value; | 147 | value = field->fld_data.fld_optional_field->fld_value; |
148 | if (status.lower()=="status") { | 148 | if (status.lower()=="status") { |
149 | if (value.lower()=="ro") { | 149 | if (value.lower()=="ro") { |
150 | mFlags.setBit(FLAG_SEEN); | 150 | mFlags.setBit(FLAG_SEEN); |
151 | } | 151 | } |
152 | } else if (status.lower()=="x-status") { | 152 | } else if (status.lower()=="x-status") { |
153 | qDebug("X-Status: %s",value.latin1()); | 153 | qDebug("X-Status: %s",value.latin1()); |
154 | if (value.lower()=="a") { | 154 | if (value.lower()=="a") { |
155 | 155 | ||
156 | mFlags.setBit(FLAG_ANSWERED); | 156 | mFlags.setBit(FLAG_ANSWERED); |
157 | } | 157 | } |
158 | } else { | 158 | } else { |
159 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, | 159 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, |
160 | // field->fld_data.fld_optional_field->fld_value); | 160 | // field->fld_data.fld_optional_field->fld_value); |
161 | } | 161 | } |
162 | break; | 162 | break; |
163 | default: | 163 | default: |
164 | qDebug("Non parsed field"); | 164 | qDebug("Non parsed field"); |
165 | break; | 165 | break; |
166 | } | 166 | } |
167 | } | 167 | } |
168 | if (fields) mailimf_fields_free(fields); | 168 | if (fields) mailimf_fields_free(fields); |
169 | mail->setFlags(mFlags); | 169 | mail->setFlags(mFlags); |
170 | return mail; | 170 | return mail; |
171 | } | 171 | } |
172 | 172 | ||
173 | QString POP3wrapper::parseDateTime( mailimf_date_time *date ) | 173 | QString POP3wrapper::parseDateTime( mailimf_date_time *date ) |
174 | { | 174 | { |
175 | char tmp[23]; | 175 | char tmp[23]; |
176 | 176 | ||
177 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | 177 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", |
178 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | 178 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); |
179 | 179 | ||
180 | return QString( tmp ); | 180 | return QString( tmp ); |
181 | } | 181 | } |
182 | 182 | ||
183 | QString POP3wrapper::parseAddressList( mailimf_address_list *list ) | 183 | QString POP3wrapper::parseAddressList( mailimf_address_list *list ) |
184 | { | 184 | { |
185 | QString result( "" ); | 185 | QString result( "" ); |
186 | 186 | ||
187 | bool first = true; | 187 | bool first = true; |
188 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | 188 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { |
189 | mailimf_address *addr = (mailimf_address *) current->data; | 189 | mailimf_address *addr = (mailimf_address *) current->data; |
190 | 190 | ||
191 | if ( !first ) { | 191 | if ( !first ) { |
192 | result.append( "," ); | 192 | result.append( "," ); |
193 | } else { | 193 | } else { |
194 | first = false; | 194 | first = false; |
195 | } | 195 | } |
196 | 196 | ||
197 | switch ( addr->ad_type ) { | 197 | switch ( addr->ad_type ) { |
198 | case MAILIMF_ADDRESS_MAILBOX: | 198 | case MAILIMF_ADDRESS_MAILBOX: |
199 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | 199 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); |
200 | break; | 200 | break; |
201 | case MAILIMF_ADDRESS_GROUP: | 201 | case MAILIMF_ADDRESS_GROUP: |
202 | result.append( parseGroup( addr->ad_data.ad_group ) ); | 202 | result.append( parseGroup( addr->ad_data.ad_group ) ); |
203 | break; | 203 | break; |
204 | default: | 204 | default: |
205 | qDebug( "POP3: unkown mailimf address type" ); | 205 | qDebug( "POP3: unkown mailimf address type" ); |
206 | break; | 206 | break; |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
210 | return result; | 210 | return result; |
211 | } | 211 | } |
212 | 212 | ||
213 | QString POP3wrapper::parseGroup( mailimf_group *group ) | 213 | QString POP3wrapper::parseGroup( mailimf_group *group ) |
214 | { | 214 | { |
215 | QString result( "" ); | 215 | QString result( "" ); |
216 | 216 | ||
217 | result.append( group->grp_display_name ); | 217 | result.append( group->grp_display_name ); |
218 | result.append( ": " ); | 218 | result.append( ": " ); |
219 | 219 | ||
220 | if ( group->grp_mb_list != NULL ) { | 220 | if ( group->grp_mb_list != NULL ) { |
221 | result.append( parseMailboxList( group->grp_mb_list ) ); | 221 | result.append( parseMailboxList( group->grp_mb_list ) ); |
222 | } | 222 | } |
223 | 223 | ||
224 | result.append( ";" ); | 224 | result.append( ";" ); |
225 | 225 | ||
226 | return result; | 226 | return result; |
227 | } | 227 | } |
228 | 228 | ||
229 | QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) | 229 | QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) |
230 | { | 230 | { |
231 | QString result( "" ); | 231 | QString result( "" ); |
232 | 232 | ||
233 | if ( box->mb_display_name == NULL ) { | 233 | if ( box->mb_display_name == NULL ) { |
234 | result.append( box->mb_addr_spec ); | 234 | result.append( box->mb_addr_spec ); |
235 | } else { | 235 | } else { |
236 | result.append( box->mb_display_name ); | 236 | result.append( box->mb_display_name ); |
237 | result.append( " <" ); | 237 | result.append( " <" ); |
238 | result.append( box->mb_addr_spec ); | 238 | result.append( box->mb_addr_spec ); |
239 | result.append( ">" ); | 239 | result.append( ">" ); |
240 | } | 240 | } |
241 | 241 | ||
242 | return result; | 242 | return result; |
243 | } | 243 | } |
244 | 244 | ||
245 | QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) | 245 | QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) |
246 | { | 246 | { |
247 | QString result( "" ); | 247 | QString result( "" ); |
248 | 248 | ||
249 | bool first = true; | 249 | bool first = true; |
250 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { | 250 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { |
251 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | 251 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; |
252 | 252 | ||
253 | if ( !first ) { | 253 | if ( !first ) { |
254 | result.append( "," ); | 254 | result.append( "," ); |
255 | } else { | 255 | } else { |
256 | first = false; | 256 | first = false; |
257 | } | 257 | } |
258 | 258 | ||
259 | result.append( parseMailbox( box ) ); | 259 | result.append( parseMailbox( box ) ); |
260 | } | 260 | } |
261 | 261 | ||
262 | return result; | 262 | return result; |
263 | } | 263 | } |
264 | 264 | ||
265 | void POP3wrapper::login() | 265 | void POP3wrapper::login() |
266 | { | 266 | { |
267 | /* we'll hold the line */ | 267 | /* we'll hold the line */ |
268 | if ( m_pop3 != NULL ) return; | 268 | if ( m_pop3 != NULL ) return; |
269 | 269 | ||
270 | const char *server, *user, *pass; | 270 | const char *server, *user, *pass; |
271 | uint16_t port; | 271 | uint16_t port; |
272 | int err = MAILPOP3_NO_ERROR; | 272 | int err = MAILPOP3_NO_ERROR; |
273 | 273 | ||
274 | server = account->getServer().latin1(); | 274 | server = account->getServer().latin1(); |
275 | port = account->getPort().toUInt(); | 275 | port = account->getPort().toUInt(); |
276 | user = account->getUser().latin1(); | 276 | user = account->getUser().latin1(); |
277 | pass = account->getPassword().latin1(); | 277 | pass = account->getPassword().latin1(); |
278 | 278 | ||
279 | m_pop3 = mailpop3_new( 200, &pop3_progress ); | 279 | m_pop3 = mailpop3_new( 200, &pop3_progress ); |
280 | 280 | ||
281 | // connect | 281 | // connect |
282 | if (account->getSSL()) { | 282 | if (account->getSSL()) { |
283 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); | 283 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); |
284 | } else { | 284 | } else { |
285 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); | 285 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); |
286 | } | 286 | } |
287 | 287 | ||
288 | if ( err != MAILPOP3_NO_ERROR ) { | 288 | if ( err != MAILPOP3_NO_ERROR ) { |
289 | qDebug( "pop3: error connecting to %s\n reason: %s", server, | 289 | qDebug( "pop3: error connecting to %s\n reason: %s", server, |
290 | m_pop3->pop3_response ); | 290 | m_pop3->pop3_response ); |
291 | mailpop3_free( m_pop3 ); | 291 | mailpop3_free( m_pop3 ); |
292 | m_pop3 = NULL; | 292 | m_pop3 = NULL; |
293 | return; | 293 | return; |
294 | } | 294 | } |
295 | qDebug( "POP3: connected!" ); | 295 | qDebug( "POP3: connected!" ); |
296 | 296 | ||
297 | // login | 297 | // login |
298 | // TODO: decide if apop or plain login should be used | 298 | // TODO: decide if apop or plain login should be used |
299 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); | 299 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); |
300 | if ( err != MAILPOP3_NO_ERROR ) { | 300 | if ( err != MAILPOP3_NO_ERROR ) { |
301 | qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); | 301 | qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); |
302 | logout(); | 302 | logout(); |
303 | return; | 303 | return; |
304 | } | 304 | } |
305 | 305 | ||
306 | qDebug( "POP3: logged in!" ); | 306 | qDebug( "POP3: logged in!" ); |
307 | } | 307 | } |
308 | 308 | ||
309 | void POP3wrapper::logout() | 309 | void POP3wrapper::logout() |
310 | { | 310 | { |
311 | int err = MAILPOP3_NO_ERROR; | 311 | int err = MAILPOP3_NO_ERROR; |
312 | if ( m_pop3 == NULL ) return; | 312 | if ( m_pop3 == NULL ) return; |
313 | err = mailpop3_quit( m_pop3 ); | 313 | err = mailpop3_quit( m_pop3 ); |
314 | mailpop3_free( m_pop3 ); | 314 | mailpop3_free( m_pop3 ); |
315 | m_pop3 = NULL; | 315 | m_pop3 = NULL; |
316 | } | 316 | } |
317 | 317 | ||
318 | 318 | ||
319 | QList<Folder>* POP3wrapper::listFolders() | 319 | QList<Folder>* POP3wrapper::listFolders() |
320 | { | 320 | { |
321 | /* TODO: integrate MH directories | 321 | /* TODO: integrate MH directories |
322 | but not before version 0.1 ;) | 322 | but not before version 0.1 ;) |
323 | */ | 323 | */ |
324 | QList<Folder> * folders = new QList<Folder>(); | 324 | QList<Folder> * folders = new QList<Folder>(); |
325 | folders->setAutoDelete( false ); | 325 | folders->setAutoDelete( false ); |
326 | Folder*inb=new Folder("INBOX"); | 326 | Folder*inb=new Folder("INBOX"); |
327 | folders->append(inb); | 327 | folders->append(inb); |
328 | return folders; | 328 | return folders; |
329 | } | 329 | } |
330 | 330 | ||
331 | QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) | 331 | QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&) |
332 | { | 332 | { |
333 | return ""; | 333 | return ""; |
334 | } | 334 | } |
335 | 335 | ||
336 | void POP3wrapper::deleteMail(const RecMail&mail) | 336 | void POP3wrapper::deleteMail(const RecMail&mail) |
337 | { | 337 | { |
338 | login(); | 338 | login(); |
339 | if (!m_pop3) return; | 339 | if (!m_pop3) return; |
340 | int err = mailpop3_dele(m_pop3,mail.getNumber()); | 340 | int err = mailpop3_dele(m_pop3,mail.getNumber()); |
341 | if (err != MAILPOP3_NO_ERROR) { | 341 | if (err != MAILPOP3_NO_ERROR) { |
342 | qDebug("error deleting mail"); | 342 | qDebug("error deleting mail"); |
343 | } | 343 | } |
344 | } | 344 | } |
345 | 345 | ||
346 | void POP3wrapper::answeredMail(const RecMail&) | 346 | void POP3wrapper::answeredMail(const RecMail&) |
347 | { | 347 | { |
348 | } | 348 | } |
349 | 349 | ||
350 | encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&) | ||
351 | { | ||
352 | return new encodedString(); | ||
353 | } | ||
354 | |||
355 | encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&) | ||
356 | { | ||
357 | return new encodedString(); | ||
358 | } | ||
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h index 6ff8d62..8d3adda 100644 --- a/noncore/net/mail/pop3wrapper.h +++ b/noncore/net/mail/pop3wrapper.h | |||
@@ -1,44 +1,48 @@ | |||
1 | #ifndef __POP3WRAPPER | 1 | #ifndef __POP3WRAPPER |
2 | #define __POP3WRAPPER | 2 | #define __POP3WRAPPER |
3 | 3 | ||
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | #include "abstractmail.h" | 5 | #include "abstractmail.h" |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | class encodedString; | ||
9 | struct mailpop3; | 10 | struct mailpop3; |
10 | 11 | ||
11 | class POP3wrapper : public AbstractMail | 12 | class POP3wrapper : public AbstractMail |
12 | { | 13 | { |
13 | Q_OBJECT | 14 | Q_OBJECT |
14 | 15 | ||
15 | public: | 16 | public: |
16 | POP3wrapper( POP3account *a ); | 17 | POP3wrapper( POP3account *a ); |
17 | virtual ~POP3wrapper(); | 18 | virtual ~POP3wrapper(); |
18 | /* mailbox will be ignored */ | 19 | /* mailbox will be ignored */ |
19 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 20 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
20 | virtual QList<Folder>* listFolders(); | 21 | virtual QList<Folder>* listFolders(); |
21 | virtual QString fetchPart(const RecMail&mail,const RecPart&part); | 22 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); |
23 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); | ||
24 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); | ||
25 | |||
22 | virtual void deleteMail(const RecMail&mail); | 26 | virtual void deleteMail(const RecMail&mail); |
23 | virtual void answeredMail(const RecMail&mail); | 27 | virtual void answeredMail(const RecMail&mail); |
24 | 28 | ||
25 | RecBody fetchBody( const RecMail &mail ); | 29 | RecBody fetchBody( const RecMail &mail ); |
26 | static void pop3_progress( size_t current, size_t maximum ); | 30 | static void pop3_progress( size_t current, size_t maximum ); |
27 | 31 | ||
28 | protected: | 32 | protected: |
29 | void login(); | 33 | void login(); |
30 | void logout(); | 34 | void logout(); |
31 | 35 | ||
32 | private: | 36 | private: |
33 | RecMail *parseHeader( const char *header ); | 37 | RecMail *parseHeader( const char *header ); |
34 | RecBody parseBody( const char *message ); | 38 | RecBody parseBody( const char *message ); |
35 | QString parseMailboxList( mailimf_mailbox_list *list ); | 39 | QString parseMailboxList( mailimf_mailbox_list *list ); |
36 | QString parseMailbox( mailimf_mailbox *box ); | 40 | QString parseMailbox( mailimf_mailbox *box ); |
37 | QString parseGroup( mailimf_group *group ); | 41 | QString parseGroup( mailimf_group *group ); |
38 | QString parseAddressList( mailimf_address_list *list ); | 42 | QString parseAddressList( mailimf_address_list *list ); |
39 | QString parseDateTime( mailimf_date_time *date ); | 43 | QString parseDateTime( mailimf_date_time *date ); |
40 | POP3account *account; | 44 | POP3account *account; |
41 | mailpop3 *m_pop3; | 45 | mailpop3 *m_pop3; |
42 | }; | 46 | }; |
43 | 47 | ||
44 | #endif | 48 | #endif |
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp index 48b71eb..0947879 100644 --- a/noncore/net/mail/viewmail.cpp +++ b/noncore/net/mail/viewmail.cpp | |||
@@ -1,338 +1,347 @@ | |||
1 | #include <qtextbrowser.h> | 1 | #include <qtextbrowser.h> |
2 | #include <qmessagebox.h> | 2 | #include <qmessagebox.h> |
3 | #include <qtextstream.h> | 3 | #include <qtextstream.h> |
4 | #include <qaction.h> | 4 | #include <qaction.h> |
5 | #include <qpopupmenu.h> | 5 | #include <qpopupmenu.h> |
6 | #include <qfile.h> | ||
6 | #include <qapplication.h> | 7 | #include <qapplication.h> |
7 | 8 | ||
8 | #include <opie/ofiledialog.h> | 9 | #include <opie/ofiledialog.h> |
9 | 10 | ||
10 | #include "settings.h" | 11 | #include "settings.h" |
11 | #include "composemail.h" | 12 | #include "composemail.h" |
12 | #include "viewmail.h" | 13 | #include "viewmail.h" |
13 | #include "abstractmail.h" | 14 | #include "abstractmail.h" |
14 | #include "accountview.h" | 15 | #include "accountview.h" |
16 | #include "mailtypes.h" | ||
15 | 17 | ||
16 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, | 18 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, |
17 | const QString&fsize,int num) | 19 | const QString&fsize,int num) |
18 | : QListViewItem(parent,after),_partNum(num) | 20 | : QListViewItem(parent,after),_partNum(num) |
19 | { | 21 | { |
20 | setText(0, mime); | 22 | setText(0, mime); |
21 | setText(1, desc); | 23 | setText(1, desc); |
22 | setText(2, file); | 24 | setText(2, file); |
23 | setText(3, fsize); | 25 | setText(3, fsize); |
24 | } | 26 | } |
25 | 27 | ||
26 | void ViewMail::setBody( RecBody body ) { | 28 | void ViewMail::setBody( RecBody body ) { |
27 | 29 | ||
28 | m_body = body; | 30 | m_body = body; |
29 | m_mail[2] = body.Bodytext(); | 31 | m_mail[2] = body.Bodytext(); |
30 | attachbutton->setEnabled(body.Parts().count()>0); | 32 | attachbutton->setEnabled(body.Parts().count()>0); |
31 | attachments->setEnabled(body.Parts().count()>0); | 33 | attachments->setEnabled(body.Parts().count()>0); |
32 | if (body.Parts().count()==0) { | 34 | if (body.Parts().count()==0) { |
33 | return; | 35 | return; |
34 | } | 36 | } |
35 | AttachItem * curItem=0; | 37 | AttachItem * curItem=0; |
36 | QString type=body.Description().Type()+"/"+body.Description().Subtype(); | 38 | QString type=body.Description().Type()+"/"+body.Description().Subtype(); |
37 | QString desc,fsize; | 39 | QString desc,fsize; |
38 | double s = body.Description().Size(); | 40 | double s = body.Description().Size(); |
39 | int w; | 41 | int w; |
40 | w=0; | 42 | w=0; |
41 | 43 | ||
42 | while (s>1024) { | 44 | while (s>1024) { |
43 | s/=1024; | 45 | s/=1024; |
44 | ++w; | 46 | ++w; |
45 | if (w>=2) break; | 47 | if (w>=2) break; |
46 | } | 48 | } |
47 | 49 | ||
48 | QString q=""; | 50 | QString q=""; |
49 | switch(w) { | 51 | switch(w) { |
50 | case 1: | 52 | case 1: |
51 | q="k"; | 53 | q="k"; |
52 | break; | 54 | break; |
53 | case 2: | 55 | case 2: |
54 | q="M"; | 56 | q="M"; |
55 | break; | 57 | break; |
56 | default: | 58 | default: |
57 | break; | 59 | break; |
58 | } | 60 | } |
59 | 61 | ||
60 | { | 62 | { |
61 | /* I did not found a method to make a CONTENT reset on a QTextStream | 63 | /* I did not found a method to make a CONTENT reset on a QTextStream |
62 | so I use this construct that the stream will re-constructed in each | 64 | so I use this construct that the stream will re-constructed in each |
63 | loop. To let it work, the textstream is packed into a own area of | 65 | loop. To let it work, the textstream is packed into a own area of |
64 | code is it will be destructed after finishing its small job. | 66 | code is it will be destructed after finishing its small job. |
65 | */ | 67 | */ |
66 | QTextOStream o(&fsize); | 68 | QTextOStream o(&fsize); |
67 | if (w>0) o.precision(2); else o.precision(0); | 69 | if (w>0) o.precision(2); else o.precision(0); |
68 | o.setf(QTextStream::fixed); | 70 | o.setf(QTextStream::fixed); |
69 | o << s << " " << q << "Byte"; | 71 | o << s << " " << q << "Byte"; |
70 | } | 72 | } |
71 | 73 | ||
72 | curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1); | 74 | curItem=new AttachItem(attachments,curItem,type,"Mailbody","",fsize,-1); |
73 | QString filename = ""; | 75 | QString filename = ""; |
74 | for (unsigned int i = 0; i < body.Parts().count();++i) { | 76 | for (unsigned int i = 0; i < body.Parts().count();++i) { |
75 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); | 77 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); |
76 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); | 78 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); |
77 | for (;it!=body.Parts()[i].Parameters().end();++it) { | 79 | for (;it!=body.Parts()[i].Parameters().end();++it) { |
78 | qDebug(it.key()); | 80 | qDebug(it.key()); |
79 | if (it.key().lower()=="name") { | 81 | if (it.key().lower()=="name") { |
80 | filename=it.data(); | 82 | filename=it.data(); |
81 | } | 83 | } |
82 | } | 84 | } |
83 | s = body.Parts()[i].Size(); | 85 | s = body.Parts()[i].Size(); |
84 | w = 0; | 86 | w = 0; |
85 | while (s>1024) { | 87 | while (s>1024) { |
86 | s/=1024; | 88 | s/=1024; |
87 | ++w; | 89 | ++w; |
88 | if (w>=2) break; | 90 | if (w>=2) break; |
89 | } | 91 | } |
90 | switch(w) { | 92 | switch(w) { |
91 | case 1: | 93 | case 1: |
92 | q="k"; | 94 | q="k"; |
93 | break; | 95 | break; |
94 | case 2: | 96 | case 2: |
95 | q="M"; | 97 | q="M"; |
96 | break; | 98 | break; |
97 | default: | 99 | default: |
98 | q=""; | 100 | q=""; |
99 | break; | 101 | break; |
100 | } | 102 | } |
101 | QTextOStream o(&fsize); | 103 | QTextOStream o(&fsize); |
102 | if (w>0) o.precision(2); else o.precision(0); | 104 | if (w>0) o.precision(2); else o.precision(0); |
103 | o.setf(QTextStream::fixed); | 105 | o.setf(QTextStream::fixed); |
104 | o << s << " " << q << "Byte"; | 106 | o << s << " " << q << "Byte"; |
105 | desc = body.Parts()[i].Description(); | 107 | desc = body.Parts()[i].Description(); |
106 | curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i); | 108 | curItem=new AttachItem(attachments,curItem,type,desc,filename,fsize,i); |
107 | } | 109 | } |
108 | } | 110 | } |
109 | 111 | ||
110 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) { | 112 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int ) { |
111 | if (!item ) | 113 | if (!item ) |
112 | return; | 114 | return; |
113 | 115 | ||
114 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { | 116 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { |
115 | setText(); | 117 | setText(); |
116 | return; | 118 | return; |
117 | } | 119 | } |
118 | QPopupMenu *menu = new QPopupMenu(); | 120 | QPopupMenu *menu = new QPopupMenu(); |
119 | int ret=0; | 121 | int ret=0; |
120 | 122 | ||
121 | if ( item->text( 0 ).left( 5 ) == "text/" ) { | 123 | if ( item->text( 0 ).left( 5 ) == "text/" ) { |
122 | menu->insertItem( tr( "Show Text" ), 1 ); | 124 | menu->insertItem( tr( "Show Text" ), 1 ); |
123 | } | 125 | } |
124 | menu->insertItem( tr( "Save Attachment" ), 0 ); | 126 | menu->insertItem( tr( "Save Attachment" ), 0 ); |
125 | menu->insertSeparator(1); | 127 | menu->insertSeparator(1); |
126 | 128 | ||
127 | ret = menu->exec( point, 0 ); | 129 | ret = menu->exec( point, 0 ); |
128 | 130 | ||
129 | switch(ret) { | 131 | switch(ret) { |
130 | case 0: | 132 | case 0: |
131 | { MimeTypes types; | 133 | { MimeTypes types; |
132 | types.insert( "all", "*" ); | 134 | types.insert( "all", "*" ); |
133 | QString str = OFileDialog::getSaveFileName( 1, | 135 | QString str = OFileDialog::getSaveFileName( 1, |
134 | "/", item->text( 2 ) , types, 0 ); | 136 | "/", item->text( 2 ) , types, 0 ); |
135 | 137 | ||
136 | if( !str.isEmpty() ) { | 138 | if( !str.isEmpty() ) { |
137 | qDebug( "first we will need a MIME wrapper" ); | 139 | encodedString*content = m_recMail.Wrapper()->fetchDecodedPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ); |
140 | if (content) { | ||
141 | QFile output(str); | ||
142 | output.open(IO_WriteOnly); | ||
143 | output.writeBlock(content->Content(),content->Length()); | ||
144 | output.close(); | ||
145 | delete content; | ||
146 | } | ||
138 | } | 147 | } |
139 | } | 148 | } |
140 | break ; | 149 | break ; |
141 | 150 | ||
142 | case 1: | 151 | case 1: |
143 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { | 152 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { |
144 | setText(); | 153 | setText(); |
145 | } else { | 154 | } else { |
146 | if ( m_recMail.Wrapper() != 0l ) { // make sure that there is a wrapper , even after delete or simular actions | 155 | if ( m_recMail.Wrapper() != 0l ) { // make sure that there is a wrapper , even after delete or simular actions |
147 | browser->setText( m_recMail.Wrapper()->fetchPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); | 156 | browser->setText( m_recMail.Wrapper()->fetchTextPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); |
148 | } | 157 | } |
149 | } | 158 | } |
150 | break; | 159 | break; |
151 | } | 160 | } |
152 | delete menu; | 161 | delete menu; |
153 | } | 162 | } |
154 | 163 | ||
155 | 164 | ||
156 | void ViewMail::setMail( RecMail mail ) { | 165 | void ViewMail::setMail( RecMail mail ) { |
157 | 166 | ||
158 | m_recMail = mail; | 167 | m_recMail = mail; |
159 | 168 | ||
160 | m_mail[0] = mail.getFrom(); | 169 | m_mail[0] = mail.getFrom(); |
161 | m_mail[1] = mail.getSubject(); | 170 | m_mail[1] = mail.getSubject(); |
162 | m_mail[3] = mail.getDate(); | 171 | m_mail[3] = mail.getDate(); |
163 | m_mail[4] = mail.Msgid(); | 172 | m_mail[4] = mail.Msgid(); |
164 | 173 | ||
165 | m_mail2[0] = mail.To(); | 174 | m_mail2[0] = mail.To(); |
166 | m_mail2[1] = mail.CC(); | 175 | m_mail2[1] = mail.CC(); |
167 | m_mail2[2] = mail.Bcc(); | 176 | m_mail2[2] = mail.Bcc(); |
168 | 177 | ||
169 | setText(); | 178 | setText(); |
170 | } | 179 | } |
171 | 180 | ||
172 | 181 | ||
173 | 182 | ||
174 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) | 183 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) |
175 | : ViewMailBase(parent, name, fl), _inLoop(false) | 184 | : ViewMailBase(parent, name, fl), _inLoop(false) |
176 | { | 185 | { |
177 | m_gotBody = false; | 186 | m_gotBody = false; |
178 | 187 | ||
179 | connect(reply, SIGNAL(activated()), SLOT(slotReply())); | 188 | connect(reply, SIGNAL(activated()), SLOT(slotReply())); |
180 | connect(forward, SIGNAL(activated()), SLOT(slotForward())); | 189 | connect(forward, SIGNAL(activated()), SLOT(slotForward())); |
181 | connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail( ) ) ); | 190 | connect( deleteMail, SIGNAL( activated() ), SLOT( slotDeleteMail( ) ) ); |
182 | 191 | ||
183 | attachments->setEnabled(m_gotBody); | 192 | attachments->setEnabled(m_gotBody); |
184 | connect( attachments, SIGNAL( clicked ( QListViewItem *, const QPoint & , int ) ), SLOT( slotItemClicked( QListViewItem *, const QPoint & , int ) ) ); | 193 | connect( attachments, SIGNAL( clicked ( QListViewItem *, const QPoint & , int ) ), SLOT( slotItemClicked( QListViewItem *, const QPoint & , int ) ) ); |
185 | 194 | ||
186 | } | 195 | } |
187 | 196 | ||
188 | void ViewMail::setText() | 197 | void ViewMail::setText() |
189 | { | 198 | { |
190 | 199 | ||
191 | QString toString; | 200 | QString toString; |
192 | QString ccString; | 201 | QString ccString; |
193 | QString bccString; | 202 | QString bccString; |
194 | 203 | ||
195 | for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) { | 204 | for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) { |
196 | toString += (*it); | 205 | toString += (*it); |
197 | } | 206 | } |
198 | for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) { | 207 | for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) { |
199 | ccString += (*it); | 208 | ccString += (*it); |
200 | } | 209 | } |
201 | for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) { | 210 | for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) { |
202 | bccString += (*it); | 211 | bccString += (*it); |
203 | } | 212 | } |
204 | 213 | ||
205 | setCaption( caption().arg( m_mail[0] ) ); | 214 | setCaption( caption().arg( m_mail[0] ) ); |
206 | 215 | ||
207 | m_mailHtml = "<html><body>" | 216 | m_mailHtml = "<html><body>" |
208 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" | 217 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" |
209 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" | 218 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" |
210 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" | 219 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" |
211 | "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" | 220 | "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" |
212 | "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + | 221 | "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + |
213 | tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" | 222 | tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" |
214 | "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + | 223 | "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + |
215 | "</td></tr></table><font face=fixed>"; | 224 | "</td></tr></table><font face=fixed>"; |
216 | 225 | ||
217 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); | 226 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); |
218 | // remove later in favor of a real handling | 227 | // remove later in favor of a real handling |
219 | m_gotBody = true; | 228 | m_gotBody = true; |
220 | } | 229 | } |
221 | 230 | ||
222 | 231 | ||
223 | ViewMail::~ViewMail() | 232 | ViewMail::~ViewMail() |
224 | { | 233 | { |
225 | hide(); | 234 | hide(); |
226 | } | 235 | } |
227 | 236 | ||
228 | void ViewMail::hide() | 237 | void ViewMail::hide() |
229 | { | 238 | { |
230 | QWidget::hide(); | 239 | QWidget::hide(); |
231 | 240 | ||
232 | if (_inLoop) { | 241 | if (_inLoop) { |
233 | _inLoop = false; | 242 | _inLoop = false; |
234 | qApp->exit_loop(); | 243 | qApp->exit_loop(); |
235 | 244 | ||
236 | } | 245 | } |
237 | 246 | ||
238 | } | 247 | } |
239 | 248 | ||
240 | void ViewMail::exec() | 249 | void ViewMail::exec() |
241 | { | 250 | { |
242 | show(); | 251 | show(); |
243 | 252 | ||
244 | if (!_inLoop) { | 253 | if (!_inLoop) { |
245 | _inLoop = true; | 254 | _inLoop = true; |
246 | qApp->enter_loop(); | 255 | qApp->enter_loop(); |
247 | } | 256 | } |
248 | 257 | ||
249 | } | 258 | } |
250 | 259 | ||
251 | QString ViewMail::deHtml(const QString &string) | 260 | QString ViewMail::deHtml(const QString &string) |
252 | { | 261 | { |
253 | QString string_ = string; | 262 | QString string_ = string; |
254 | string_.replace(QRegExp("&"), "&"); | 263 | string_.replace(QRegExp("&"), "&"); |
255 | string_.replace(QRegExp("<"), "<"); | 264 | string_.replace(QRegExp("<"), "<"); |
256 | string_.replace(QRegExp(">"), ">"); | 265 | string_.replace(QRegExp(">"), ">"); |
257 | string_.replace(QRegExp("\\n"), "<br>"); | 266 | string_.replace(QRegExp("\\n"), "<br>"); |
258 | return string_; | 267 | return string_; |
259 | } | 268 | } |
260 | 269 | ||
261 | void ViewMail::slotReply() | 270 | void ViewMail::slotReply() |
262 | { | 271 | { |
263 | if (!m_gotBody) { | 272 | if (!m_gotBody) { |
264 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); | 273 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); |
265 | return; | 274 | return; |
266 | } | 275 | } |
267 | 276 | ||
268 | QString rtext; | 277 | QString rtext; |
269 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose | 278 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose |
270 | .arg( m_mail[0] ) | 279 | .arg( m_mail[0] ) |
271 | .arg( m_mail[3] ); | 280 | .arg( m_mail[3] ); |
272 | 281 | ||
273 | QString text = m_mail[2]; | 282 | QString text = m_mail[2]; |
274 | QStringList lines = QStringList::split(QRegExp("\\n"), text); | 283 | QStringList lines = QStringList::split(QRegExp("\\n"), text); |
275 | QStringList::Iterator it; | 284 | QStringList::Iterator it; |
276 | for (it = lines.begin(); it != lines.end(); it++) { | 285 | for (it = lines.begin(); it != lines.end(); it++) { |
277 | rtext += "> " + *it + "\n"; | 286 | rtext += "> " + *it + "\n"; |
278 | } | 287 | } |
279 | rtext += "\n"; | 288 | rtext += "\n"; |
280 | 289 | ||
281 | QString prefix; | 290 | QString prefix; |
282 | if ( m_mail[1].find(QRegExp("^Re: *$")) != -1) prefix = ""; | 291 | if ( m_mail[1].find(QRegExp("^Re: *$")) != -1) prefix = ""; |
283 | else prefix = "Re: "; // no i18n on purpose | 292 | else prefix = "Re: "; // no i18n on purpose |
284 | 293 | ||
285 | Settings *settings = new Settings(); | 294 | Settings *settings = new Settings(); |
286 | ComposeMail composer( settings ,this, 0, true); | 295 | ComposeMail composer( settings ,this, 0, true); |
287 | composer.setTo( m_mail[0] ); | 296 | composer.setTo( m_mail[0] ); |
288 | composer.setSubject( "Re: " + m_mail[1] ); | 297 | composer.setSubject( "Re: " + m_mail[1] ); |
289 | composer.setMessage( rtext ); | 298 | composer.setMessage( rtext ); |
290 | composer.showMaximized(); | 299 | composer.showMaximized(); |
291 | if ( QDialog::Accepted==composer.exec()) { | 300 | if ( QDialog::Accepted==composer.exec()) { |
292 | m_recMail.Wrapper()->answeredMail(m_recMail); | 301 | m_recMail.Wrapper()->answeredMail(m_recMail); |
293 | } | 302 | } |
294 | } | 303 | } |
295 | 304 | ||
296 | void ViewMail::slotForward() | 305 | void ViewMail::slotForward() |
297 | { | 306 | { |
298 | if (!m_gotBody) { | 307 | if (!m_gotBody) { |
299 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); | 308 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); |
300 | return; | 309 | return; |
301 | } | 310 | } |
302 | 311 | ||
303 | QString ftext; | 312 | QString ftext; |
304 | ftext += QString("\n----- Forwarded message from %1 -----\n\n") | 313 | ftext += QString("\n----- Forwarded message from %1 -----\n\n") |
305 | .arg( m_mail[0] ); | 314 | .arg( m_mail[0] ); |
306 | if (!m_mail[3].isNull()) | 315 | if (!m_mail[3].isNull()) |
307 | ftext += QString("Date: %1\n") | 316 | ftext += QString("Date: %1\n") |
308 | .arg( m_mail[3] ); | 317 | .arg( m_mail[3] ); |
309 | if (!m_mail[0].isNull()) | 318 | if (!m_mail[0].isNull()) |
310 | ftext += QString("From: %1\n") | 319 | ftext += QString("From: %1\n") |
311 | .arg( m_mail[0] ); | 320 | .arg( m_mail[0] ); |
312 | if (!m_mail[1].isNull()) | 321 | if (!m_mail[1].isNull()) |
313 | ftext += QString("Subject: %1\n") | 322 | ftext += QString("Subject: %1\n") |
314 | .arg( m_mail[1] ); | 323 | .arg( m_mail[1] ); |
315 | 324 | ||
316 | ftext += QString("\n%1\n") | 325 | ftext += QString("\n%1\n") |
317 | .arg( m_mail[2]); | 326 | .arg( m_mail[2]); |
318 | 327 | ||
319 | ftext += QString("----- End forwarded message -----\n"); | 328 | ftext += QString("----- End forwarded message -----\n"); |
320 | 329 | ||
321 | Settings *settings = new Settings(); | 330 | Settings *settings = new Settings(); |
322 | ComposeMail composer( settings ,this, 0, true); | 331 | ComposeMail composer( settings ,this, 0, true); |
323 | composer.setSubject( "Fwd: " + m_mail[1] ); | 332 | composer.setSubject( "Fwd: " + m_mail[1] ); |
324 | composer.setMessage( ftext ); | 333 | composer.setMessage( ftext ); |
325 | composer.showMaximized(); | 334 | composer.showMaximized(); |
326 | if ( QDialog::Accepted==composer.exec()) { | 335 | if ( QDialog::Accepted==composer.exec()) { |
327 | 336 | ||
328 | } | 337 | } |
329 | } | 338 | } |
330 | 339 | ||
331 | void ViewMail::slotDeleteMail( ) | 340 | void ViewMail::slotDeleteMail( ) |
332 | { | 341 | { |
333 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { | 342 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + m_mail[0] + " - " + m_mail[1] ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { |
334 | m_recMail.Wrapper()->deleteMail( m_recMail ); | 343 | m_recMail.Wrapper()->deleteMail( m_recMail ); |
335 | hide(); | 344 | hide(); |
336 | deleted = true; | 345 | deleted = true; |
337 | } | 346 | } |
338 | } | 347 | } |