summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-13 21:03:45 (UTC)
committer alwin <alwin>2003-12-13 21:03:45 (UTC)
commitc0e86973b0cd2d01163ccf60340c8d295aa645f4 (patch) (unidiff)
tree4ccb0f7b8071711bf7ebc5320ea5c2f6974d6fb4
parent85444223acfafd9d7955032b2cbdad3279ba27ad (diff)
downloadopie-c0e86973b0cd2d01163ccf60340c8d295aa645f4.zip
opie-c0e86973b0cd2d01163ccf60340c8d295aa645f4.tar.gz
opie-c0e86973b0cd2d01163ccf60340c8d295aa645f4.tar.bz2
the RecMail class get on creation a mailwrapper assigened
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp1
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp1
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.cpp17
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.h7
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp1
-rw-r--r--noncore/net/mail/mailtypes.cpp17
-rw-r--r--noncore/net/mail/mailtypes.h7
-rw-r--r--noncore/net/mail/pop3wrapper.cpp1
8 files changed, 50 insertions, 2 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index e5eb335..3222c7e 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -70,128 +70,129 @@ 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
79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 79void 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 target.append(m); 135 target.append(m);
135 } 136 }
136 } 137 }
137 } else { 138 } else {
138 qDebug("Error fetching headers: %s",m_imap->imap_response); 139 qDebug("Error fetching headers: %s",m_imap->imap_response);
139 } 140 }
140 mailimap_fetch_list_free(result); 141 mailimap_fetch_list_free(result);
141} 142}
142 143
143QList<Folder>* IMAPwrapper::listFolders() 144QList<Folder>* IMAPwrapper::listFolders()
144{ 145{
145 const char *path, *mask; 146 const char *path, *mask;
146 int err = MAILIMAP_NO_ERROR; 147 int err = MAILIMAP_NO_ERROR;
147 clist *result; 148 clist *result;
148 clistcell *current; 149 clistcell *current;
149 150
150 QList<Folder> * folders = new QList<Folder>(); 151 QList<Folder> * folders = new QList<Folder>();
151 folders->setAutoDelete( true ); 152 folders->setAutoDelete( true );
152 login(); 153 login();
153 if (!m_imap) { 154 if (!m_imap) {
154 return folders; 155 return folders;
155 } 156 }
156 157
157/* 158/*
158 * 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.
159 * We must not forget to filter them out in next loop! 160 * We must not forget to filter them out in next loop!
160 * 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.
161 */ 162 */
162 QString temp; 163 QString temp;
163 mask = "INBOX" ; 164 mask = "INBOX" ;
164 result = clist_new(); 165 result = clist_new();
165 mailimap_mailbox_list *list; 166 mailimap_mailbox_list *list;
166 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
167 if ( err == MAILIMAP_NO_ERROR ) { 168 if ( err == MAILIMAP_NO_ERROR ) {
168 current = result->first; 169 current = result->first;
169 for ( int i = result->count; i > 0; i-- ) { 170 for ( int i = result->count; i > 0; i-- ) {
170 list = (mailimap_mailbox_list *) current->data; 171 list = (mailimap_mailbox_list *) current->data;
171 // it is better use the deep copy mechanism of qt itself 172 // it is better use the deep copy mechanism of qt itself
172 // instead of using strdup! 173 // instead of using strdup!
173 temp = list->mb_name; 174 temp = list->mb_name;
174 folders->append( new IMAPFolder(temp)); 175 folders->append( new IMAPFolder(temp));
175 current = current->next; 176 current = current->next;
176 } 177 }
177 } else { 178 } else {
178 qDebug("error fetching folders: %s",m_imap->imap_response); 179 qDebug("error fetching folders: %s",m_imap->imap_response);
179 } 180 }
180 mailimap_list_result_free( result ); 181 mailimap_list_result_free( result );
181 182
182/* 183/*
183 * second stage - get the other then inbox folders 184 * second stage - get the other then inbox folders
184 */ 185 */
185 mask = "*" ; 186 mask = "*" ;
186 path = account->getPrefix().latin1(); 187 path = account->getPrefix().latin1();
187 if (!path) path = ""; 188 if (!path) path = "";
188 result = clist_new(); 189 result = clist_new();
189 qDebug(path); 190 qDebug(path);
190 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 191 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
191 if ( err == MAILIMAP_NO_ERROR ) { 192 if ( err == MAILIMAP_NO_ERROR ) {
192 current = result->first; 193 current = result->first;
193 for ( int i = result->count; i > 0; i-- ) { 194 for ( int i = result->count; i > 0; i-- ) {
194 list = (mailimap_mailbox_list *) current->data; 195 list = (mailimap_mailbox_list *) current->data;
195 // it is better use the deep copy mechanism of qt itself 196 // it is better use the deep copy mechanism of qt itself
196 // instead of using strdup! 197 // instead of using strdup!
197 temp = list->mb_name; 198 temp = list->mb_name;
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index e5eb335..3222c7e 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -70,128 +70,129 @@ 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
79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 79void 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 target.append(m); 135 target.append(m);
135 } 136 }
136 } 137 }
137 } else { 138 } else {
138 qDebug("Error fetching headers: %s",m_imap->imap_response); 139 qDebug("Error fetching headers: %s",m_imap->imap_response);
139 } 140 }
140 mailimap_fetch_list_free(result); 141 mailimap_fetch_list_free(result);
141} 142}
142 143
143QList<Folder>* IMAPwrapper::listFolders() 144QList<Folder>* IMAPwrapper::listFolders()
144{ 145{
145 const char *path, *mask; 146 const char *path, *mask;
146 int err = MAILIMAP_NO_ERROR; 147 int err = MAILIMAP_NO_ERROR;
147 clist *result; 148 clist *result;
148 clistcell *current; 149 clistcell *current;
149 150
150 QList<Folder> * folders = new QList<Folder>(); 151 QList<Folder> * folders = new QList<Folder>();
151 folders->setAutoDelete( true ); 152 folders->setAutoDelete( true );
152 login(); 153 login();
153 if (!m_imap) { 154 if (!m_imap) {
154 return folders; 155 return folders;
155 } 156 }
156 157
157/* 158/*
158 * 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.
159 * We must not forget to filter them out in next loop! 160 * We must not forget to filter them out in next loop!
160 * 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.
161 */ 162 */
162 QString temp; 163 QString temp;
163 mask = "INBOX" ; 164 mask = "INBOX" ;
164 result = clist_new(); 165 result = clist_new();
165 mailimap_mailbox_list *list; 166 mailimap_mailbox_list *list;
166 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
167 if ( err == MAILIMAP_NO_ERROR ) { 168 if ( err == MAILIMAP_NO_ERROR ) {
168 current = result->first; 169 current = result->first;
169 for ( int i = result->count; i > 0; i-- ) { 170 for ( int i = result->count; i > 0; i-- ) {
170 list = (mailimap_mailbox_list *) current->data; 171 list = (mailimap_mailbox_list *) current->data;
171 // it is better use the deep copy mechanism of qt itself 172 // it is better use the deep copy mechanism of qt itself
172 // instead of using strdup! 173 // instead of using strdup!
173 temp = list->mb_name; 174 temp = list->mb_name;
174 folders->append( new IMAPFolder(temp)); 175 folders->append( new IMAPFolder(temp));
175 current = current->next; 176 current = current->next;
176 } 177 }
177 } else { 178 } else {
178 qDebug("error fetching folders: %s",m_imap->imap_response); 179 qDebug("error fetching folders: %s",m_imap->imap_response);
179 } 180 }
180 mailimap_list_result_free( result ); 181 mailimap_list_result_free( result );
181 182
182/* 183/*
183 * second stage - get the other then inbox folders 184 * second stage - get the other then inbox folders
184 */ 185 */
185 mask = "*" ; 186 mask = "*" ;
186 path = account->getPrefix().latin1(); 187 path = account->getPrefix().latin1();
187 if (!path) path = ""; 188 if (!path) path = "";
188 result = clist_new(); 189 result = clist_new();
189 qDebug(path); 190 qDebug(path);
190 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 191 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
191 if ( err == MAILIMAP_NO_ERROR ) { 192 if ( err == MAILIMAP_NO_ERROR ) {
192 current = result->first; 193 current = result->first;
193 for ( int i = result->count; i > 0; i-- ) { 194 for ( int i = result->count; i > 0; i-- ) {
194 list = (mailimap_mailbox_list *) current->data; 195 list = (mailimap_mailbox_list *) current->data;
195 // it is better use the deep copy mechanism of qt itself 196 // it is better use the deep copy mechanism of qt itself
196 // instead of using strdup! 197 // instead of using strdup!
197 temp = list->mb_name; 198 temp = list->mb_name;
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.cpp b/noncore/net/mail/libmailwrapper/mailtypes.cpp
index 5cd45ed..94f5d6f 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.cpp
+++ b/noncore/net/mail/libmailwrapper/mailtypes.cpp
@@ -1,101 +1,118 @@
1#include "mailtypes.h" 1#include "mailtypes.h"
2 2
3 3
4RecMail::RecMail() 4RecMail::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
10RecMail::RecMail(const RecMail&old) 10RecMail::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
18RecMail::~RecMail()
19{
20 wrapper = 0;
21}
22
18void RecMail::copy_old(const RecMail&old) 23void RecMail::copy_old(const RecMail&old)
19{ 24{
20 subject = old.subject; 25 subject = old.subject;
21 date = old.date; 26 date = old.date;
22 mbox = old.mbox; 27 mbox = old.mbox;
23 msg_id = old.msg_id; 28 msg_id = old.msg_id;
24 msg_size = old.msg_size; 29 msg_size = old.msg_size;
25 msg_number = old.msg_number; 30 msg_number = old.msg_number;
26 from = old.from; 31 from = old.from;
27 msg_flags = old.msg_flags; 32 msg_flags = old.msg_flags;
28 to = old.to; 33 to = old.to;
29 cc = old.cc; 34 cc = old.cc;
30 bcc = old.bcc; 35 bcc = old.bcc;
36 wrapper = old.wrapper;
31} 37}
32 38
33void RecMail::init() 39void RecMail::init()
34{ 40{
35 to.clear(); 41 to.clear();
36 cc.clear(); 42 cc.clear();
37 bcc.clear(); 43 bcc.clear();
44 wrapper = 0;
45}
46
47void RecMail::setWrapper(AbstractMail*awrapper)
48{
49 wrapper = awrapper;
50}
51
52AbstractMail* RecMail::Wrapper()
53{
54 return wrapper;
38} 55}
39 56
40void RecMail::setTo(const QStringList&list) 57void RecMail::setTo(const QStringList&list)
41{ 58{
42 to = list; 59 to = list;
43} 60}
44 61
45const QStringList&RecMail::To()const 62const QStringList&RecMail::To()const
46{ 63{
47 return to; 64 return to;
48} 65}
49 66
50void RecMail::setCC(const QStringList&list) 67void RecMail::setCC(const QStringList&list)
51{ 68{
52 cc = list; 69 cc = list;
53} 70}
54 71
55const QStringList&RecMail::CC()const 72const QStringList&RecMail::CC()const
56{ 73{
57 return cc; 74 return cc;
58} 75}
59 76
60void RecMail::setBcc(const QStringList&list) 77void RecMail::setBcc(const QStringList&list)
61{ 78{
62 bcc = list; 79 bcc = list;
63} 80}
64 81
65const QStringList& RecMail::Bcc()const 82const QStringList& RecMail::Bcc()const
66{ 83{
67 return bcc; 84 return bcc;
68} 85}
69 86
70RecPart::RecPart() 87RecPart::RecPart()
71 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0),m_size(0) 88 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0),m_size(0)
72{ 89{
73 m_Parameters.clear(); 90 m_Parameters.clear();
74 m_poslist.clear(); 91 m_poslist.clear();
75} 92}
76 93
77RecPart::~RecPart() 94RecPart::~RecPart()
78{ 95{
79} 96}
80 97
81void RecPart::setSize(unsigned int size) 98void RecPart::setSize(unsigned int size)
82{ 99{
83 m_size = size; 100 m_size = size;
84} 101}
85 102
86const unsigned int RecPart::Size()const 103const unsigned int RecPart::Size()const
87{ 104{
88 return m_size; 105 return m_size;
89} 106}
90 107
91void RecPart::setLines(unsigned int lines) 108void RecPart::setLines(unsigned int lines)
92{ 109{
93 m_lines = lines; 110 m_lines = lines;
94} 111}
95 112
96const unsigned int RecPart::Lines()const 113const unsigned int RecPart::Lines()const
97{ 114{
98 return m_lines; 115 return m_lines;
99} 116}
100 117
101const QString& RecPart::Type()const 118const QString& RecPart::Type()const
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h
index 24518cf..9ef762d 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.h
+++ b/noncore/net/mail/libmailwrapper/mailtypes.h
@@ -1,131 +1,136 @@
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
18class AbstractMail;
18/* a class to describe mails in a mailbox */ 19/* a class to describe mails in a mailbox */
19/* Attention! 20/* Attention!
20 From programmers point of view it would make sense to 21 From programmers point of view it would make sense to
21 store the mail body into this class, too. 22 store the mail body into this class, too.
22 But: not from the point of view of the device. 23 But: not from the point of view of the device.
23 Mailbodies can be real large. So we request them when 24 Mailbodies can be real large. So we request them when
24 needed from the mail-wrapper class direct from the server itself 25 needed from the mail-wrapper class direct from the server itself
25 (imap) or from a file-based cache (pop3?) 26 (imap) or from a file-based cache (pop3?)
26 So there is no interface "const QString&body()" but you should 27 So there is no interface "const QString&body()" but you should
27 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
28 get the body. Same words for the attachments. 29 get the body. Same words for the attachments.
29*/ 30*/
30class RecMail 31class RecMail
31{ 32{
32public: 33public:
33 RecMail(); 34 RecMail();
34 RecMail(const RecMail&old); 35 RecMail(const RecMail&old);
35 virtual ~RecMail(){} 36 virtual ~RecMail();
36 37
37 const int getNumber()const{return msg_number;} 38 const int getNumber()const{return msg_number;}
38 void setNumber(int number){msg_number=number;} 39 void setNumber(int number){msg_number=number;}
39 const QString&getDate()const{ return date; } 40 const QString&getDate()const{ return date; }
40 void setDate( const QString&a ) { date = a; } 41 void setDate( const QString&a ) { date = a; }
41 const QString&getFrom()const{ return from; } 42 const QString&getFrom()const{ return from; }
42 void setFrom( const QString&a ) { from = a; } 43 void setFrom( const QString&a ) { from = a; }
43 const QString&getSubject()const { return subject; } 44 const QString&getSubject()const { return subject; }
44 void setSubject( const QString&s ) { subject = s; } 45 void setSubject( const QString&s ) { subject = s; }
45 const QString&getMbox()const{return mbox;} 46 const QString&getMbox()const{return mbox;}
46 void setMbox(const QString&box){mbox = box;} 47 void setMbox(const QString&box){mbox = box;}
47 void setMsgid(const QString&id){msg_id=id;} 48 void setMsgid(const QString&id){msg_id=id;}
48 const QString&Msgid()const{return msg_id;} 49 const QString&Msgid()const{return msg_id;}
49 void setReplyto(const QString&reply){replyto=reply;} 50 void setReplyto(const QString&reply){replyto=reply;}
50 const QString&Replyto()const{return replyto;} 51 const QString&Replyto()const{return replyto;}
51 void setMsgsize(int size){msg_size = size;} 52 void setMsgsize(int size){msg_size = size;}
52 const int Msgsize()const{return msg_size;} 53 const int Msgsize()const{return msg_size;}
53 54
54 55
55 void setTo(const QStringList&list); 56 void setTo(const QStringList&list);
56 const QStringList&To()const; 57 const QStringList&To()const;
57 void setCC(const QStringList&list); 58 void setCC(const QStringList&list);
58 const QStringList&CC()const; 59 const QStringList&CC()const;
59 void setBcc(const QStringList&list); 60 void setBcc(const QStringList&list);
60 const QStringList&Bcc()const; 61 const QStringList&Bcc()const;
61 const QBitArray&getFlags()const{return msg_flags;} 62 const QBitArray&getFlags()const{return msg_flags;}
62 void setFlags(const QBitArray&flags){msg_flags = flags;} 63 void setFlags(const QBitArray&flags){msg_flags = flags;}
64
65 void setWrapper(AbstractMail*wrapper);
66 AbstractMail* Wrapper();
63 67
64protected: 68protected:
65 QString subject,date,from,mbox,msg_id,replyto; 69 QString subject,date,from,mbox,msg_id,replyto;
66 int msg_number,msg_size; 70 int msg_number,msg_size;
67 QBitArray msg_flags; 71 QBitArray msg_flags;
68 QStringList to,cc,bcc; 72 QStringList to,cc,bcc;
73 AbstractMail*wrapper;
69 void init(); 74 void init();
70 void copy_old(const RecMail&old); 75 void copy_old(const RecMail&old);
71}; 76};
72 77
73typedef QMap<QString,QString> part_plist_t; 78typedef QMap<QString,QString> part_plist_t;
74 79
75class RecPart 80class RecPart
76{ 81{
77protected: 82protected:
78 QString m_type,m_subtype,m_identifier,m_encoding; 83 QString m_type,m_subtype,m_identifier,m_encoding;
79 unsigned int m_lines,m_size; 84 unsigned int m_lines,m_size;
80 part_plist_t m_Parameters; 85 part_plist_t m_Parameters;
81 /* describes the position in the mail */ 86 /* describes the position in the mail */
82 QValueList<int> m_poslist; 87 QValueList<int> m_poslist;
83 88
84public: 89public:
85 RecPart(); 90 RecPart();
86 virtual ~RecPart(); 91 virtual ~RecPart();
87 92
88 const QString&Type()const; 93 const QString&Type()const;
89 void setType(const QString&type); 94 void setType(const QString&type);
90 const QString&Subtype()const; 95 const QString&Subtype()const;
91 void setSubtype(const QString&subtype); 96 void setSubtype(const QString&subtype);
92 const QString&Identifier()const; 97 const QString&Identifier()const;
93 void setIdentifier(const QString&identifier); 98 void setIdentifier(const QString&identifier);
94 const QString&Encoding()const; 99 const QString&Encoding()const;
95 void setEncoding(const QString&encoding); 100 void setEncoding(const QString&encoding);
96 void setLines(unsigned int lines); 101 void setLines(unsigned int lines);
97 const unsigned int Lines()const; 102 const unsigned int Lines()const;
98 void setSize(unsigned int size); 103 void setSize(unsigned int size);
99 const unsigned int Size()const; 104 const unsigned int Size()const;
100 105
101 106
102 void setParameters(const part_plist_t&list); 107 void setParameters(const part_plist_t&list);
103 const part_plist_t&Parameters()const; 108 const part_plist_t&Parameters()const;
104 void addParameter(const QString&key,const QString&value); 109 void addParameter(const QString&key,const QString&value);
105 const QString searchParamter(const QString&key)const; 110 const QString searchParamter(const QString&key)const;
106 void setPositionlist(const QValueList<int>&poslist); 111 void setPositionlist(const QValueList<int>&poslist);
107 const QValueList<int>& Positionlist()const; 112 const QValueList<int>& Positionlist()const;
108}; 113};
109 114
110class RecBody 115class RecBody
111{ 116{
112protected: 117protected:
113 QString m_BodyText; 118 QString m_BodyText;
114 QValueList<RecPart> m_PartsList; 119 QValueList<RecPart> m_PartsList;
115 RecPart m_description; 120 RecPart m_description;
116 121
117public: 122public:
118 RecBody(); 123 RecBody();
119 virtual ~RecBody(); 124 virtual ~RecBody();
120 void setBodytext(const QString&); 125 void setBodytext(const QString&);
121 const QString& Bodytext()const; 126 const QString& Bodytext()const;
122 127
123 void setDescription(const RecPart&des); 128 void setDescription(const RecPart&des);
124 const RecPart& Description()const; 129 const RecPart& Description()const;
125 130
126 void setParts(const QValueList<RecPart>&parts); 131 void setParts(const QValueList<RecPart>&parts);
127 const QValueList<RecPart>& Parts()const; 132 const QValueList<RecPart>& Parts()const;
128 void addPart(const RecPart&part); 133 void addPart(const RecPart&part);
129}; 134};
130 135
131#endif 136#endif
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 49c3b7a..903ef4d 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -20,128 +20,129 @@ void POP3wrapper::pop3_progress( size_t current, size_t maximum )
20} 20}
21 21
22RecBody POP3wrapper::fetchBody( const RecMail &mail ) 22RecBody 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; 26 size_t length;
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 logout(); 34 logout();
35 return RecBody(); 35 return RecBody();
36 } 36 }
37 37
38 logout(); 38 logout();
39 39
40 return parseBody( message ); 40 return parseBody( message );
41} 41}
42 42
43RecBody POP3wrapper::parseBody( const char *message ) 43RecBody POP3wrapper::parseBody( const char *message )
44{ 44{
45 int err = MAILIMF_NO_ERROR; 45 int err = MAILIMF_NO_ERROR;
46 size_t curTok; 46 size_t curTok;
47 mailimf_message *result; 47 mailimf_message *result;
48 RecBody body; 48 RecBody body;
49 49
50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
51 if ( err != MAILIMF_NO_ERROR ) return body; 51 if ( err != MAILIMF_NO_ERROR ) return body;
52 52
53 if ( result && result->msg_body && result->msg_body->bd_text ) { 53 if ( result && result->msg_body && result->msg_body->bd_text ) {
54 qDebug( "POP3: bodytext found" ); 54 qDebug( "POP3: bodytext found" );
55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. 55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan.
56 body.setBodytext( QString( result->msg_body->bd_text ) ); 56 body.setBodytext( QString( result->msg_body->bd_text ) );
57 } 57 }
58 58
59 return body; 59 return body;
60} 60}
61 61
62void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 62void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
63{ 63{
64 int err = MAILPOP3_NO_ERROR; 64 int err = MAILPOP3_NO_ERROR;
65 char *header; 65 char *header;
66 size_t length; 66 size_t length;
67 carray *messages; 67 carray *messages;
68 68
69 login(); 69 login();
70 if (!m_pop3) return; 70 if (!m_pop3) return;
71 mailpop3_list( m_pop3, &messages ); 71 mailpop3_list( m_pop3, &messages );
72 72
73 for ( int i = carray_count( messages ); i > 0; i-- ) { 73 for ( int i = carray_count( messages ); i > 0; i-- ) {
74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); 74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 );
75 75
76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
77 if ( err != MAILPOP3_NO_ERROR ) { 77 if ( err != MAILPOP3_NO_ERROR ) {
78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
79 logout(); 79 logout();
80 return; 80 return;
81 } 81 }
82 RecMail *mail = parseHeader( header ); 82 RecMail *mail = parseHeader( header );
83 mail->setNumber( info->msg_index ); 83 mail->setNumber( info->msg_index );
84 mail->setWrapper(this);
84 target.append( mail ); 85 target.append( mail );
85 } 86 }
86 87
87 logout(); 88 logout();
88} 89}
89 90
90RecMail *POP3wrapper::parseHeader( const char *header ) 91RecMail *POP3wrapper::parseHeader( const char *header )
91{ 92{
92 int err = MAILIMF_NO_ERROR; 93 int err = MAILIMF_NO_ERROR;
93 size_t curTok; 94 size_t curTok;
94 RecMail *mail = new RecMail(); 95 RecMail *mail = new RecMail();
95 mailimf_fields *fields; 96 mailimf_fields *fields;
96 97
97 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 98 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
98 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 99 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
99 mailimf_field *field = (mailimf_field *) current->data; 100 mailimf_field *field = (mailimf_field *) current->data;
100 switch ( field->fld_type ) { 101 switch ( field->fld_type ) {
101 case MAILIMF_FIELD_FROM: 102 case MAILIMF_FIELD_FROM:
102 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 103 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
103 break; 104 break;
104 case MAILIMF_FIELD_TO: 105 case MAILIMF_FIELD_TO:
105 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 106 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
106 break; 107 break;
107 case MAILIMF_FIELD_CC: 108 case MAILIMF_FIELD_CC:
108 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 109 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
109 break; 110 break;
110 case MAILIMF_FIELD_BCC: 111 case MAILIMF_FIELD_BCC:
111 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 112 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
112 break; 113 break;
113 case MAILIMF_FIELD_SUBJECT: 114 case MAILIMF_FIELD_SUBJECT:
114 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); 115 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) );
115 break; 116 break;
116 case MAILIMF_FIELD_ORIG_DATE: 117 case MAILIMF_FIELD_ORIG_DATE:
117 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 118 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
118 break; 119 break;
119 default: 120 default:
120 break; 121 break;
121 } 122 }
122 } 123 }
123 124
124 return mail; 125 return mail;
125} 126}
126 127
127QString POP3wrapper::parseDateTime( mailimf_date_time *date ) 128QString POP3wrapper::parseDateTime( mailimf_date_time *date )
128{ 129{
129 char tmp[23]; 130 char tmp[23];
130 131
131 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 132 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
132 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 133 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
133 134
134 return QString( tmp ); 135 return QString( tmp );
135} 136}
136 137
137QString POP3wrapper::parseAddressList( mailimf_address_list *list ) 138QString POP3wrapper::parseAddressList( mailimf_address_list *list )
138{ 139{
139 QString result( "" ); 140 QString result( "" );
140 141
141 bool first = true; 142 bool first = true;
142 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 143 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
143 mailimf_address *addr = (mailimf_address *) current->data; 144 mailimf_address *addr = (mailimf_address *) current->data;
144 145
145 if ( !first ) { 146 if ( !first ) {
146 result.append( "," ); 147 result.append( "," );
147 } else { 148 } else {
diff --git a/noncore/net/mail/mailtypes.cpp b/noncore/net/mail/mailtypes.cpp
index 5cd45ed..94f5d6f 100644
--- a/noncore/net/mail/mailtypes.cpp
+++ b/noncore/net/mail/mailtypes.cpp
@@ -1,101 +1,118 @@
1#include "mailtypes.h" 1#include "mailtypes.h"
2 2
3 3
4RecMail::RecMail() 4RecMail::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
10RecMail::RecMail(const RecMail&old) 10RecMail::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
18RecMail::~RecMail()
19{
20 wrapper = 0;
21}
22
18void RecMail::copy_old(const RecMail&old) 23void RecMail::copy_old(const RecMail&old)
19{ 24{
20 subject = old.subject; 25 subject = old.subject;
21 date = old.date; 26 date = old.date;
22 mbox = old.mbox; 27 mbox = old.mbox;
23 msg_id = old.msg_id; 28 msg_id = old.msg_id;
24 msg_size = old.msg_size; 29 msg_size = old.msg_size;
25 msg_number = old.msg_number; 30 msg_number = old.msg_number;
26 from = old.from; 31 from = old.from;
27 msg_flags = old.msg_flags; 32 msg_flags = old.msg_flags;
28 to = old.to; 33 to = old.to;
29 cc = old.cc; 34 cc = old.cc;
30 bcc = old.bcc; 35 bcc = old.bcc;
36 wrapper = old.wrapper;
31} 37}
32 38
33void RecMail::init() 39void RecMail::init()
34{ 40{
35 to.clear(); 41 to.clear();
36 cc.clear(); 42 cc.clear();
37 bcc.clear(); 43 bcc.clear();
44 wrapper = 0;
45}
46
47void RecMail::setWrapper(AbstractMail*awrapper)
48{
49 wrapper = awrapper;
50}
51
52AbstractMail* RecMail::Wrapper()
53{
54 return wrapper;
38} 55}
39 56
40void RecMail::setTo(const QStringList&list) 57void RecMail::setTo(const QStringList&list)
41{ 58{
42 to = list; 59 to = list;
43} 60}
44 61
45const QStringList&RecMail::To()const 62const QStringList&RecMail::To()const
46{ 63{
47 return to; 64 return to;
48} 65}
49 66
50void RecMail::setCC(const QStringList&list) 67void RecMail::setCC(const QStringList&list)
51{ 68{
52 cc = list; 69 cc = list;
53} 70}
54 71
55const QStringList&RecMail::CC()const 72const QStringList&RecMail::CC()const
56{ 73{
57 return cc; 74 return cc;
58} 75}
59 76
60void RecMail::setBcc(const QStringList&list) 77void RecMail::setBcc(const QStringList&list)
61{ 78{
62 bcc = list; 79 bcc = list;
63} 80}
64 81
65const QStringList& RecMail::Bcc()const 82const QStringList& RecMail::Bcc()const
66{ 83{
67 return bcc; 84 return bcc;
68} 85}
69 86
70RecPart::RecPart() 87RecPart::RecPart()
71 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0),m_size(0) 88 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0),m_size(0)
72{ 89{
73 m_Parameters.clear(); 90 m_Parameters.clear();
74 m_poslist.clear(); 91 m_poslist.clear();
75} 92}
76 93
77RecPart::~RecPart() 94RecPart::~RecPart()
78{ 95{
79} 96}
80 97
81void RecPart::setSize(unsigned int size) 98void RecPart::setSize(unsigned int size)
82{ 99{
83 m_size = size; 100 m_size = size;
84} 101}
85 102
86const unsigned int RecPart::Size()const 103const unsigned int RecPart::Size()const
87{ 104{
88 return m_size; 105 return m_size;
89} 106}
90 107
91void RecPart::setLines(unsigned int lines) 108void RecPart::setLines(unsigned int lines)
92{ 109{
93 m_lines = lines; 110 m_lines = lines;
94} 111}
95 112
96const unsigned int RecPart::Lines()const 113const unsigned int RecPart::Lines()const
97{ 114{
98 return m_lines; 115 return m_lines;
99} 116}
100 117
101const QString& RecPart::Type()const 118const QString& RecPart::Type()const
diff --git a/noncore/net/mail/mailtypes.h b/noncore/net/mail/mailtypes.h
index 24518cf..9ef762d 100644
--- a/noncore/net/mail/mailtypes.h
+++ b/noncore/net/mail/mailtypes.h
@@ -1,131 +1,136 @@
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
18class AbstractMail;
18/* a class to describe mails in a mailbox */ 19/* a class to describe mails in a mailbox */
19/* Attention! 20/* Attention!
20 From programmers point of view it would make sense to 21 From programmers point of view it would make sense to
21 store the mail body into this class, too. 22 store the mail body into this class, too.
22 But: not from the point of view of the device. 23 But: not from the point of view of the device.
23 Mailbodies can be real large. So we request them when 24 Mailbodies can be real large. So we request them when
24 needed from the mail-wrapper class direct from the server itself 25 needed from the mail-wrapper class direct from the server itself
25 (imap) or from a file-based cache (pop3?) 26 (imap) or from a file-based cache (pop3?)
26 So there is no interface "const QString&body()" but you should 27 So there is no interface "const QString&body()" but you should
27 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
28 get the body. Same words for the attachments. 29 get the body. Same words for the attachments.
29*/ 30*/
30class RecMail 31class RecMail
31{ 32{
32public: 33public:
33 RecMail(); 34 RecMail();
34 RecMail(const RecMail&old); 35 RecMail(const RecMail&old);
35 virtual ~RecMail(){} 36 virtual ~RecMail();
36 37
37 const int getNumber()const{return msg_number;} 38 const int getNumber()const{return msg_number;}
38 void setNumber(int number){msg_number=number;} 39 void setNumber(int number){msg_number=number;}
39 const QString&getDate()const{ return date; } 40 const QString&getDate()const{ return date; }
40 void setDate( const QString&a ) { date = a; } 41 void setDate( const QString&a ) { date = a; }
41 const QString&getFrom()const{ return from; } 42 const QString&getFrom()const{ return from; }
42 void setFrom( const QString&a ) { from = a; } 43 void setFrom( const QString&a ) { from = a; }
43 const QString&getSubject()const { return subject; } 44 const QString&getSubject()const { return subject; }
44 void setSubject( const QString&s ) { subject = s; } 45 void setSubject( const QString&s ) { subject = s; }
45 const QString&getMbox()const{return mbox;} 46 const QString&getMbox()const{return mbox;}
46 void setMbox(const QString&box){mbox = box;} 47 void setMbox(const QString&box){mbox = box;}
47 void setMsgid(const QString&id){msg_id=id;} 48 void setMsgid(const QString&id){msg_id=id;}
48 const QString&Msgid()const{return msg_id;} 49 const QString&Msgid()const{return msg_id;}
49 void setReplyto(const QString&reply){replyto=reply;} 50 void setReplyto(const QString&reply){replyto=reply;}
50 const QString&Replyto()const{return replyto;} 51 const QString&Replyto()const{return replyto;}
51 void setMsgsize(int size){msg_size = size;} 52 void setMsgsize(int size){msg_size = size;}
52 const int Msgsize()const{return msg_size;} 53 const int Msgsize()const{return msg_size;}
53 54
54 55
55 void setTo(const QStringList&list); 56 void setTo(const QStringList&list);
56 const QStringList&To()const; 57 const QStringList&To()const;
57 void setCC(const QStringList&list); 58 void setCC(const QStringList&list);
58 const QStringList&CC()const; 59 const QStringList&CC()const;
59 void setBcc(const QStringList&list); 60 void setBcc(const QStringList&list);
60 const QStringList&Bcc()const; 61 const QStringList&Bcc()const;
61 const QBitArray&getFlags()const{return msg_flags;} 62 const QBitArray&getFlags()const{return msg_flags;}
62 void setFlags(const QBitArray&flags){msg_flags = flags;} 63 void setFlags(const QBitArray&flags){msg_flags = flags;}
64
65 void setWrapper(AbstractMail*wrapper);
66 AbstractMail* Wrapper();
63 67
64protected: 68protected:
65 QString subject,date,from,mbox,msg_id,replyto; 69 QString subject,date,from,mbox,msg_id,replyto;
66 int msg_number,msg_size; 70 int msg_number,msg_size;
67 QBitArray msg_flags; 71 QBitArray msg_flags;
68 QStringList to,cc,bcc; 72 QStringList to,cc,bcc;
73 AbstractMail*wrapper;
69 void init(); 74 void init();
70 void copy_old(const RecMail&old); 75 void copy_old(const RecMail&old);
71}; 76};
72 77
73typedef QMap<QString,QString> part_plist_t; 78typedef QMap<QString,QString> part_plist_t;
74 79
75class RecPart 80class RecPart
76{ 81{
77protected: 82protected:
78 QString m_type,m_subtype,m_identifier,m_encoding; 83 QString m_type,m_subtype,m_identifier,m_encoding;
79 unsigned int m_lines,m_size; 84 unsigned int m_lines,m_size;
80 part_plist_t m_Parameters; 85 part_plist_t m_Parameters;
81 /* describes the position in the mail */ 86 /* describes the position in the mail */
82 QValueList<int> m_poslist; 87 QValueList<int> m_poslist;
83 88
84public: 89public:
85 RecPart(); 90 RecPart();
86 virtual ~RecPart(); 91 virtual ~RecPart();
87 92
88 const QString&Type()const; 93 const QString&Type()const;
89 void setType(const QString&type); 94 void setType(const QString&type);
90 const QString&Subtype()const; 95 const QString&Subtype()const;
91 void setSubtype(const QString&subtype); 96 void setSubtype(const QString&subtype);
92 const QString&Identifier()const; 97 const QString&Identifier()const;
93 void setIdentifier(const QString&identifier); 98 void setIdentifier(const QString&identifier);
94 const QString&Encoding()const; 99 const QString&Encoding()const;
95 void setEncoding(const QString&encoding); 100 void setEncoding(const QString&encoding);
96 void setLines(unsigned int lines); 101 void setLines(unsigned int lines);
97 const unsigned int Lines()const; 102 const unsigned int Lines()const;
98 void setSize(unsigned int size); 103 void setSize(unsigned int size);
99 const unsigned int Size()const; 104 const unsigned int Size()const;
100 105
101 106
102 void setParameters(const part_plist_t&list); 107 void setParameters(const part_plist_t&list);
103 const part_plist_t&Parameters()const; 108 const part_plist_t&Parameters()const;
104 void addParameter(const QString&key,const QString&value); 109 void addParameter(const QString&key,const QString&value);
105 const QString searchParamter(const QString&key)const; 110 const QString searchParamter(const QString&key)const;
106 void setPositionlist(const QValueList<int>&poslist); 111 void setPositionlist(const QValueList<int>&poslist);
107 const QValueList<int>& Positionlist()const; 112 const QValueList<int>& Positionlist()const;
108}; 113};
109 114
110class RecBody 115class RecBody
111{ 116{
112protected: 117protected:
113 QString m_BodyText; 118 QString m_BodyText;
114 QValueList<RecPart> m_PartsList; 119 QValueList<RecPart> m_PartsList;
115 RecPart m_description; 120 RecPart m_description;
116 121
117public: 122public:
118 RecBody(); 123 RecBody();
119 virtual ~RecBody(); 124 virtual ~RecBody();
120 void setBodytext(const QString&); 125 void setBodytext(const QString&);
121 const QString& Bodytext()const; 126 const QString& Bodytext()const;
122 127
123 void setDescription(const RecPart&des); 128 void setDescription(const RecPart&des);
124 const RecPart& Description()const; 129 const RecPart& Description()const;
125 130
126 void setParts(const QValueList<RecPart>&parts); 131 void setParts(const QValueList<RecPart>&parts);
127 const QValueList<RecPart>& Parts()const; 132 const QValueList<RecPart>& Parts()const;
128 void addPart(const RecPart&part); 133 void addPart(const RecPart&part);
129}; 134};
130 135
131#endif 136#endif
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index 49c3b7a..903ef4d 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -20,128 +20,129 @@ void POP3wrapper::pop3_progress( size_t current, size_t maximum )
20} 20}
21 21
22RecBody POP3wrapper::fetchBody( const RecMail &mail ) 22RecBody 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; 26 size_t length;
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 logout(); 34 logout();
35 return RecBody(); 35 return RecBody();
36 } 36 }
37 37
38 logout(); 38 logout();
39 39
40 return parseBody( message ); 40 return parseBody( message );
41} 41}
42 42
43RecBody POP3wrapper::parseBody( const char *message ) 43RecBody POP3wrapper::parseBody( const char *message )
44{ 44{
45 int err = MAILIMF_NO_ERROR; 45 int err = MAILIMF_NO_ERROR;
46 size_t curTok; 46 size_t curTok;
47 mailimf_message *result; 47 mailimf_message *result;
48 RecBody body; 48 RecBody body;
49 49
50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
51 if ( err != MAILIMF_NO_ERROR ) return body; 51 if ( err != MAILIMF_NO_ERROR ) return body;
52 52
53 if ( result && result->msg_body && result->msg_body->bd_text ) { 53 if ( result && result->msg_body && result->msg_body->bd_text ) {
54 qDebug( "POP3: bodytext found" ); 54 qDebug( "POP3: bodytext found" );
55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. 55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan.
56 body.setBodytext( QString( result->msg_body->bd_text ) ); 56 body.setBodytext( QString( result->msg_body->bd_text ) );
57 } 57 }
58 58
59 return body; 59 return body;
60} 60}
61 61
62void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 62void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
63{ 63{
64 int err = MAILPOP3_NO_ERROR; 64 int err = MAILPOP3_NO_ERROR;
65 char *header; 65 char *header;
66 size_t length; 66 size_t length;
67 carray *messages; 67 carray *messages;
68 68
69 login(); 69 login();
70 if (!m_pop3) return; 70 if (!m_pop3) return;
71 mailpop3_list( m_pop3, &messages ); 71 mailpop3_list( m_pop3, &messages );
72 72
73 for ( int i = carray_count( messages ); i > 0; i-- ) { 73 for ( int i = carray_count( messages ); i > 0; i-- ) {
74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); 74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 );
75 75
76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
77 if ( err != MAILPOP3_NO_ERROR ) { 77 if ( err != MAILPOP3_NO_ERROR ) {
78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
79 logout(); 79 logout();
80 return; 80 return;
81 } 81 }
82 RecMail *mail = parseHeader( header ); 82 RecMail *mail = parseHeader( header );
83 mail->setNumber( info->msg_index ); 83 mail->setNumber( info->msg_index );
84 mail->setWrapper(this);
84 target.append( mail ); 85 target.append( mail );
85 } 86 }
86 87
87 logout(); 88 logout();
88} 89}
89 90
90RecMail *POP3wrapper::parseHeader( const char *header ) 91RecMail *POP3wrapper::parseHeader( const char *header )
91{ 92{
92 int err = MAILIMF_NO_ERROR; 93 int err = MAILIMF_NO_ERROR;
93 size_t curTok; 94 size_t curTok;
94 RecMail *mail = new RecMail(); 95 RecMail *mail = new RecMail();
95 mailimf_fields *fields; 96 mailimf_fields *fields;
96 97
97 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 98 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
98 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 99 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
99 mailimf_field *field = (mailimf_field *) current->data; 100 mailimf_field *field = (mailimf_field *) current->data;
100 switch ( field->fld_type ) { 101 switch ( field->fld_type ) {
101 case MAILIMF_FIELD_FROM: 102 case MAILIMF_FIELD_FROM:
102 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 103 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
103 break; 104 break;
104 case MAILIMF_FIELD_TO: 105 case MAILIMF_FIELD_TO:
105 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 106 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
106 break; 107 break;
107 case MAILIMF_FIELD_CC: 108 case MAILIMF_FIELD_CC:
108 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 109 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
109 break; 110 break;
110 case MAILIMF_FIELD_BCC: 111 case MAILIMF_FIELD_BCC:
111 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 112 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
112 break; 113 break;
113 case MAILIMF_FIELD_SUBJECT: 114 case MAILIMF_FIELD_SUBJECT:
114 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); 115 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) );
115 break; 116 break;
116 case MAILIMF_FIELD_ORIG_DATE: 117 case MAILIMF_FIELD_ORIG_DATE:
117 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 118 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
118 break; 119 break;
119 default: 120 default:
120 break; 121 break;
121 } 122 }
122 } 123 }
123 124
124 return mail; 125 return mail;
125} 126}
126 127
127QString POP3wrapper::parseDateTime( mailimf_date_time *date ) 128QString POP3wrapper::parseDateTime( mailimf_date_time *date )
128{ 129{
129 char tmp[23]; 130 char tmp[23];
130 131
131 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 132 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
132 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 133 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
133 134
134 return QString( tmp ); 135 return QString( tmp );
135} 136}
136 137
137QString POP3wrapper::parseAddressList( mailimf_address_list *list ) 138QString POP3wrapper::parseAddressList( mailimf_address_list *list )
138{ 139{
139 QString result( "" ); 140 QString result( "" );
140 141
141 bool first = true; 142 bool first = true;
142 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 143 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
143 mailimf_address *addr = (mailimf_address *) current->data; 144 mailimf_address *addr = (mailimf_address *) current->data;
144 145
145 if ( !first ) { 146 if ( !first ) {
146 result.append( "," ); 147 result.append( "," );
147 } else { 148 } else {