summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/accountview.cpp2
-rw-r--r--noncore/net/mail/imapwrapper.cpp302
-rw-r--r--noncore/net/mail/imapwrapper.h14
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp302
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h14
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.cpp2
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.h17
-rw-r--r--noncore/net/mail/mailwrapper.cpp2
-rw-r--r--noncore/net/mail/mailwrapper.h17
9 files changed, 427 insertions, 245 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index a531976..1bde886 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -1,111 +1,111 @@
1#include "accountview.h" 1#include "accountview.h"
2#include "imapwrapper.h" 2#include "imapwrapper.h"
3#include "defines.h" 3#include "defines.h"
4 4
5IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent ) 5IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent )
6 : AccountViewItem( parent ) 6 : AccountViewItem( parent )
7{ 7{
8 account = a; 8 account = a;
9 wrapper = new IMAPwrapper( account ); 9 wrapper = new IMAPwrapper( account );
10 setPixmap( 0, PIXMAP_IMAPFOLDER ); 10 setPixmap( 0, PIXMAP_IMAPFOLDER );
11 setText( 0, account->getAccountName() ); 11 setText( 0, account->getAccountName() );
12 setOpen( true ); 12 setOpen( true );
13} 13}
14 14
15IMAPviewItem::~IMAPviewItem() 15IMAPviewItem::~IMAPviewItem()
16{ 16{
17 delete wrapper; 17 delete wrapper;
18} 18}
19 19
20IMAPwrapper *IMAPviewItem::getWrapper() 20IMAPwrapper *IMAPviewItem::getWrapper()
21{ 21{
22 return wrapper; 22 return wrapper;
23} 23}
24 24
25void IMAPviewItem::refresh(Maillist&) 25void IMAPviewItem::refresh(Maillist&)
26{ 26{
27 QList<IMAPFolder> *folders = wrapper->listFolders(); 27 QList<IMAPFolder> *folders = wrapper->listFolders();
28 28
29 QListViewItem *child = firstChild(); 29 QListViewItem *child = firstChild();
30 while ( child ) { 30 while ( child ) {
31 QListViewItem *tmp = child; 31 QListViewItem *tmp = child;
32 child = child->nextSibling(); 32 child = child->nextSibling();
33 delete tmp; 33 delete tmp;
34 } 34 }
35 35
36 IMAPFolder *it; 36 IMAPFolder *it;
37 for ( it = folders->first(); it; it = folders->next() ) { 37 for ( it = folders->first(); it; it = folders->next() ) {
38 (void) new IMAPfolderItem( it, this ); 38 (void) new IMAPfolderItem( it, this );
39 } 39 }
40} 40}
41 41
42 42
43IMAPfolderItem::~IMAPfolderItem() 43IMAPfolderItem::~IMAPfolderItem()
44{ 44{
45 delete folder; 45 delete folder;
46} 46}
47 47
48IMAPfolderItem::IMAPfolderItem( IMAPFolder *folderInit, IMAPviewItem *parent ) 48IMAPfolderItem::IMAPfolderItem( IMAPFolder *folderInit, IMAPviewItem *parent )
49 : AccountViewItem( parent ) 49 : AccountViewItem( parent )
50{ 50{
51 folder = folderInit; 51 folder = folderInit;
52 imap = parent; 52 imap = parent;
53 setPixmap( 0, PIXMAP_IMAPFOLDER ); 53 setPixmap( 0, PIXMAP_IMAPFOLDER );
54 setText( 0, folder->getDisplayName() ); 54 setText( 0, folder->getDisplayName() );
55} 55}
56 56
57void IMAPfolderItem::refresh(Maillist&target) 57void IMAPfolderItem::refresh(Maillist&target)
58{ 58{
59 imap->getWrapper()->listMessages( folder->getName(),target ); 59 imap->getWrapper()->listMessages( folder->getName(),target );
60} 60}
61 61
62QString IMAPfolderItem::fetchBody(const RecMail&aMail) 62QString IMAPfolderItem::fetchBody(const RecMail&aMail)
63{ 63{
64 return imap->getWrapper()->fetchBody(folder->getName(),aMail); 64 return imap->getWrapper()->fetchBody(aMail);
65} 65}
66 66
67AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) 67AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
68 : QListView( parent, name, flags ) 68 : QListView( parent, name, flags )
69{ 69{
70 connect( this, SIGNAL( clicked( QListViewItem * ) ), 70 connect( this, SIGNAL( clicked( QListViewItem * ) ),
71 SLOT( refresh( QListViewItem * ) ) ); 71 SLOT( refresh( QListViewItem * ) ) );
72} 72}
73 73
74void AccountView::populate( QList<Account> list ) 74void AccountView::populate( QList<Account> list )
75{ 75{
76 clear(); 76 clear();
77 77
78 Account *it; 78 Account *it;
79 for ( it = list.first(); it; it = list.next() ) { 79 for ( it = list.first(); it; it = list.next() ) {
80 if ( it->getType().compare( "IMAP" ) == 0 ) { 80 if ( it->getType().compare( "IMAP" ) == 0 ) {
81 IMAPaccount *imap = static_cast<IMAPaccount *>(it); 81 IMAPaccount *imap = static_cast<IMAPaccount *>(it);
82 qDebug( "added IMAP " + imap->getAccountName() ); 82 qDebug( "added IMAP " + imap->getAccountName() );
83 (void) new IMAPviewItem( imap, this ); 83 (void) new IMAPviewItem( imap, this );
84 } 84 }
85 } 85 }
86} 86}
87 87
88void AccountView::refresh(QListViewItem *item) { 88void AccountView::refresh(QListViewItem *item) {
89 qDebug("AccountView refresh..."); 89 qDebug("AccountView refresh...");
90 if ( item ) { 90 if ( item ) {
91 Maillist headerlist; 91 Maillist headerlist;
92 headerlist.setAutoDelete(true); 92 headerlist.setAutoDelete(true);
93 AccountViewItem *view = static_cast<AccountViewItem *>(item); 93 AccountViewItem *view = static_cast<AccountViewItem *>(item);
94 view->refresh(headerlist); 94 view->refresh(headerlist);
95 emit refreshMailview(&headerlist); 95 emit refreshMailview(&headerlist);
96 } 96 }
97} 97}
98 98
99void AccountView::refreshAll() 99void AccountView::refreshAll()
100{ 100{
101 101
102} 102}
103 103
104QString AccountView::fetchBody(const RecMail&aMail) 104QString AccountView::fetchBody(const RecMail&aMail)
105{ 105{
106 QString Body; 106 QString Body;
107 QListViewItem*item = selectedItem (); 107 QListViewItem*item = selectedItem ();
108 if (!item) return Body; 108 if (!item) return Body;
109 AccountViewItem *view = static_cast<AccountViewItem *>(item); 109 AccountViewItem *view = static_cast<AccountViewItem *>(item);
110 return view->fetchBody(aMail); 110 return view->fetchBody(aMail);
111} 111}
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index 7b78499..1acc036 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,420 +1,490 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5 5#include <libetpan/mailimap.h>
6 6
7IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 7IMAPwrapper::IMAPwrapper( IMAPaccount *a )
8{ 8{
9 account = a; 9 account = a;
10 m_imap = 0;
10} 11}
11 12
12void imap_progress( size_t current, size_t maximum ) 13IMAPwrapper::~IMAPwrapper()
14{
15 logout();
16}
17
18void IMAPwrapper::imap_progress( size_t current, size_t maximum )
13{ 19{
14 qDebug( "IMAP: %i of %i", current, maximum ); 20 qDebug( "IMAP: %i of %i", current, maximum );
15} 21}
16 22
17void IMAPwrapper::listMessages(const QString&mailbox,Maillist&target ) 23void IMAPwrapper::login()
18{ 24{
19 const char *server, *user, *pass, *mb; 25 logout();
26 const char *server, *user, *pass;
20 uint16_t port; 27 uint16_t port;
21 int err = MAILIMAP_NO_ERROR; 28 int err = MAILIMAP_NO_ERROR;
22 clist *result;
23 clistcell *current;
24 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
25 mailimap_fetch_type *fetchType;
26 mailimap_set *set;
27 29
28 mb = mailbox.latin1();
29 server = account->getServer().latin1(); 30 server = account->getServer().latin1();
30 port = account->getPort().toUInt(); 31 port = account->getPort().toUInt();
31 user = account->getUser().latin1(); 32 user = account->getUser().latin1();
32 pass = account->getPassword().latin1(); 33 pass = account->getPassword().latin1();
33 34
34 mailimap *imap = mailimap_new( 20, &imap_progress ); 35 m_imap = mailimap_new( 20, &imap_progress );
35 if ( imap == NULL ) {
36 qDebug("IMAP Memory error");
37 return;
38 }
39
40 /* connect */ 36 /* connect */
41 err = mailimap_socket_connect( imap, (char*)server, port ); 37 err = mailimap_socket_connect( m_imap, (char*)server, port );
42 if ( err != MAILIMAP_NO_ERROR && 38 if ( err != MAILIMAP_NO_ERROR &&
43 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 39 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
44 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 40 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
45 qDebug("error connecting server: %s",imap->response); 41 qDebug("error connecting server: %s",m_imap->response);
46 mailimap_free( imap ); 42 mailimap_free( m_imap );
43 m_imap = 0;
47 return; 44 return;
48 } 45 }
49 46
50 /* login */ 47 /* login */
51 err = mailimap_login_simple( imap, (char*)user, (char*)pass ); 48 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
52 if ( err != MAILIMAP_NO_ERROR ) { 49 if ( err != MAILIMAP_NO_ERROR ) {
53 qDebug("error logging in imap: %s",imap->response); 50 qDebug("error logging in imap: %s",m_imap->response);
54 err = mailimap_close( imap ); 51 err = mailimap_close( m_imap );
55 mailimap_free( imap ); 52 mailimap_free( m_imap );
56 return; 53 m_imap = 0;
57 } 54 }
55}
56
57void IMAPwrapper::logout()
58{
59 int err = MAILIMAP_NO_ERROR;
60 if (!m_imap) return;
61 err = mailimap_logout( m_imap );
62 err = mailimap_close( m_imap );
63 mailimap_free( m_imap );
64 m_imap = 0;
65}
66
67void IMAPwrapper::listMessages(const QString&mailbox,Maillist&target )
68{
69 const char *mb;
70 int err = MAILIMAP_NO_ERROR;
71 clist *result;
72 clistcell *current;
73 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
74 mailimap_fetch_type *fetchType;
75 mailimap_set *set;
58 76
77 mb = mailbox.latin1();
78 login();
79 if (!m_imap) {
80 return;
81 }
59 /* select mailbox READONLY for operations */ 82 /* select mailbox READONLY for operations */
60 err = mailimap_examine( imap, (char*)mb); 83 err = mailimap_examine( m_imap, (char*)mb);
61 if ( err != MAILIMAP_NO_ERROR ) { 84 if ( err != MAILIMAP_NO_ERROR ) {
62 qDebug("error selecting mailbox: %s",imap->response); 85 qDebug("error selecting mailbox: %s",m_imap->response);
63 err = mailimap_logout( imap ); 86 logout();
64 err = mailimap_close( imap );
65 mailimap_free( imap );
66 return; 87 return;
67 } 88 }
68 89
69 int last = imap->selection_info->exists; 90 int last = m_imap->selection_info->exists;
91
70 if (last == 0) { 92 if (last == 0) {
71 qDebug("mailbox has no mails"); 93 qDebug("mailbox has no mails");
72 err = mailimap_logout( imap ); 94 logout();
73 err = mailimap_close( imap );
74 mailimap_free( imap );
75 return; 95 return;
76 } 96 }
77 97
78
79 result = clist_new(); 98 result = clist_new();
80 /* the range has to start at 1!!! not with 0!!!! */ 99 /* the range has to start at 1!!! not with 0!!!! */
81 set = mailimap_set_new_interval( 1, last ); 100 set = mailimap_set_new_interval( 1, last );
82 fetchAtt = mailimap_fetch_att_new_envelope(); 101 fetchAtt = mailimap_fetch_att_new_envelope();
83 fetchAttFlags = mailimap_fetch_att_new_flags(); 102 fetchAttFlags = mailimap_fetch_att_new_flags();
84 fetchAttDate = mailimap_fetch_att_new_internaldate(); 103 fetchAttDate = mailimap_fetch_att_new_internaldate();
85 104
86 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 105 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
87 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 106 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
88 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); 107 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt);
89 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); 108 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags);
90 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); 109 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate);
91 110
92 err = mailimap_fetch( imap, set, fetchType, &result ); 111 err = mailimap_fetch( m_imap, set, fetchType, &result );
93 mailimap_set_free( set ); 112 mailimap_set_free( set );
94 /* cleans up the fetch_att's too! */ 113 /* cleans up the fetch_att's too! */
95 mailimap_fetch_type_free( fetchType ); 114 mailimap_fetch_type_free( fetchType );
96 115
97 QString date,subject,from; 116 QString date,subject,from;
98 117
99 if ( err == MAILIMAP_NO_ERROR ) { 118 if ( err == MAILIMAP_NO_ERROR ) {
100 current = clist_begin(result); 119 current = clist_begin(result);
101 mailimap_msg_att * msg_att; 120 mailimap_msg_att * msg_att;
102 int i = 0; 121 int i = 0;
103 while ( current != 0 ) { 122 while ( current != 0 ) {
104 ++i; 123 ++i;
105 msg_att = (mailimap_msg_att*)current->data; 124 msg_att = (mailimap_msg_att*)current->data;
106 RecMail*m = parse_list_result(msg_att); 125 RecMail*m = parse_list_result(msg_att);
107 if (m) { 126 if (m) {
108 m->setNumber(i); 127 m->setNumber(i);
128 m->setMbox(mailbox);
109 target.append(m); 129 target.append(m);
110 } 130 }
111 current = current->next; 131 current = current->next;
112 } 132 }
113 } else { 133 } else {
114 qDebug("Error fetching headers: %s",imap->response); 134 qDebug("Error fetching headers: %s",m_imap->response);
115 } 135 }
116 136 logout();
117 err = mailimap_logout( imap );
118 err = mailimap_close( imap );
119 clist_free(result); 137 clist_free(result);
120 mailimap_free( imap );
121} 138}
122 139
123QList<IMAPFolder>* IMAPwrapper::listFolders() 140QList<IMAPFolder>* IMAPwrapper::listFolders()
124{ 141{
125 const char *server, *user, *pass, *path, *mask; 142 const char *path, *mask;
126 uint16_t port;
127 int err = MAILIMAP_NO_ERROR; 143 int err = MAILIMAP_NO_ERROR;
128 clist *result; 144 clist *result;
129 clistcell *current; 145 clistcell *current;
130 146
131 QList<IMAPFolder> * folders = new QList<IMAPFolder>(); 147 QList<IMAPFolder> * folders = new QList<IMAPFolder>();
132 folders->setAutoDelete( true ); 148 folders->setAutoDelete( true );
133 149 login();
134 server = account->getServer().latin1(); 150 if (!m_imap) {
135 port = account->getPort().toUInt();
136 user = account->getUser().latin1();
137 pass = account->getPassword().latin1();
138 path = account->getPrefix().latin1();
139
140 mailimap *imap = mailimap_new( 20, &imap_progress );
141 if ( imap == NULL ) {
142 qDebug("error mailimap_new");
143 return folders; 151 return folders;
144 } 152 }
145
146 err = mailimap_socket_connect( imap, (char*)server, port );
147 if ( err != MAILIMAP_NO_ERROR &&
148 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
149 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
150 mailimap_free(imap);
151 qDebug("error imap_socket_connect: %s",imap->response);
152 return folders;
153 }
154 153
155 err = mailimap_login_simple( imap, (char*)user, (char*)pass );
156 if ( err != MAILIMAP_NO_ERROR ) {
157 mailimap_free(imap);
158 qDebug("error logging in: %s",imap->response);
159 return folders;
160 }
161/* 154/*
162 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 155 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
163 * We must not forget to filter them out in next loop! 156 * We must not forget to filter them out in next loop!
164 * it seems like ugly code. and yes - it is ugly code. but the best way. 157 * it seems like ugly code. and yes - it is ugly code. but the best way.
165 */ 158 */
166 QString temp; 159 QString temp;
167 mask = "INBOX" ; 160 mask = "INBOX" ;
168 result = clist_new(); 161 result = clist_new();
169 mailimap_mailbox_list *list; 162 mailimap_mailbox_list *list;
170 err = mailimap_list( imap, (char*)"", (char*)mask, &result ); 163 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
171 if ( err == MAILIMAP_NO_ERROR ) { 164 if ( err == MAILIMAP_NO_ERROR ) {
172 current = result->first; 165 current = result->first;
173 for ( int i = result->count; i > 0; i-- ) { 166 for ( int i = result->count; i > 0; i-- ) {
174 list = (mailimap_mailbox_list *) current->data; 167 list = (mailimap_mailbox_list *) current->data;
175 // it is better use the deep copy mechanism of qt itself 168 // it is better use the deep copy mechanism of qt itself
176 // instead of using strdup! 169 // instead of using strdup!
177 temp = list->mb; 170 temp = list->mb;
178 folders->append( new IMAPFolder(temp)); 171 folders->append( new IMAPFolder(temp));
179 current = current->next; 172 current = current->next;
180 } 173 }
181 } else { 174 } else {
182 qDebug("error fetching folders: %s",imap->response); 175 qDebug("error fetching folders: %s",m_imap->response);
183 } 176 }
184 mailimap_list_result_free( result ); 177 mailimap_list_result_free( result );
185 178
186/* 179/*
187 * second stage - get the other then inbox folders 180 * second stage - get the other then inbox folders
188 */ 181 */
189 mask = "*" ; 182 mask = "*" ;
183 path = account->getPrefix().latin1();
190 result = clist_new(); 184 result = clist_new();
191 err = mailimap_list( imap, (char*)path, (char*)mask, &result ); 185 qDebug(path);
186 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
192 if ( err == MAILIMAP_NO_ERROR ) { 187 if ( err == MAILIMAP_NO_ERROR ) {
193 current = result->first; 188 current = result->first;
194 for ( int i = result->count; i > 0; i-- ) { 189 for ( int i = result->count; i > 0; i-- ) {
195 list = (mailimap_mailbox_list *) current->data; 190 list = (mailimap_mailbox_list *) current->data;
196 // it is better use the deep copy mechanism of qt itself 191 // it is better use the deep copy mechanism of qt itself
197 // instead of using strdup! 192 // instead of using strdup!
198 temp = list->mb; 193 temp = list->mb;
199 current = current->next; 194 current = current->next;
200 if (temp.lower()=="inbox") 195 if (temp.lower()=="inbox")
201 continue; 196 continue;
202 folders->append(new IMAPFolder(temp)); 197 folders->append(new IMAPFolder(temp));
203 198
204 } 199 }
205 } else { 200 } else {
206 qDebug("error fetching folders"); 201 qDebug("error fetching folders %s",m_imap->response);
207 } 202 }
208 mailimap_list_result_free( result ); 203 mailimap_list_result_free( result );
209 err = mailimap_logout( imap );
210 err = mailimap_close( imap );
211 mailimap_free( imap );
212 return folders; 204 return folders;
213} 205}
214 206
215RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 207RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
216{ 208{
217 RecMail * m = 0; 209 RecMail * m = 0;
218 mailimap_msg_att_item *item=0; 210 mailimap_msg_att_item *item=0;
219 bool named_from = false; 211 bool named_from = false;
220 QString from,date,subject; 212 QString from,date,subject;
221 date = from = subject = ""; 213 date = from = subject = "";
222 clistcell *current,*c,*cf, *current_from = NULL; 214 clistcell *current,*c,*cf, *current_from = NULL;
223 mailimap_address * current_address = NULL; 215 mailimap_address * current_address = NULL;
224 mailimap_msg_att_dynamic*flist; 216 mailimap_msg_att_dynamic*flist;
225 mailimap_flag_fetch*cflag; 217 mailimap_flag_fetch*cflag;
226 QBitArray mFlags(7); 218 QBitArray mFlags(7);
227 219
228 if (!m_att) { 220 if (!m_att) {
229 return m; 221 return m;
230 } 222 }
231 223
232#if 0 224#if 0
233 MAILIMAP_FLAG_KEYWORD, /* keyword flag */ 225 MAILIMAP_FLAG_KEYWORD, /* keyword flag */
234 MAILIMAP_FLAG_EXTENSION, /* \extension flag */ 226 MAILIMAP_FLAG_EXTENSION, /* \extension flag */
235#endif 227#endif
236 c = clist_begin(m_att->list); 228 c = clist_begin(m_att->list);
237 while ( c ) { 229 while ( c ) {
238 current = c; 230 current = c;
239 c = c->next; 231 c = c->next;
240 item = (mailimap_msg_att_item*)current->data; 232 item = (mailimap_msg_att_item*)current->data;
241 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 233 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
242 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; 234 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn;
243 if (!flist->list) { 235 if (!flist->list) {
244 continue; 236 continue;
245 } 237 }
246 cf = flist->list->first; 238 cf = flist->list->first;
247 while (cf) { 239 while (cf) {
248 cflag = (mailimap_flag_fetch*)cf->data; 240 cflag = (mailimap_flag_fetch*)cf->data;
249 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { 241 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) {
250 switch (cflag->flag->type) { 242 switch (cflag->flag->type) {
251 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 243 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
252 mFlags.setBit(FLAG_ANSWERED); 244 mFlags.setBit(FLAG_ANSWERED);
253 break; 245 break;
254 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 246 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
255 mFlags.setBit(FLAG_FLAGGED); 247 mFlags.setBit(FLAG_FLAGGED);
256 break; 248 break;
257 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 249 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
258 mFlags.setBit(FLAG_DELETED); 250 mFlags.setBit(FLAG_DELETED);
259 break; 251 break;
260 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 252 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
261 mFlags.setBit(FLAG_SEEN); 253 mFlags.setBit(FLAG_SEEN);
262 break; 254 break;
263 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 255 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
264 mFlags.setBit(FLAG_DRAFT); 256 mFlags.setBit(FLAG_DRAFT);
265 break; 257 break;
266 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 258 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
267 break; 259 break;
268 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 260 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
269 break; 261 break;
270 default: 262 default:
271 break; 263 break;
272 } 264 }
273 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { 265 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) {
274 mFlags.setBit(FLAG_RECENT); 266 mFlags.setBit(FLAG_RECENT);
275 } 267 }
276
277 cf = cf->next; 268 cf = cf->next;
278 } 269 }
279 continue; 270 continue;
280 } 271 }
281 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { 272 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) {
282 qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); 273 qDebug( "header: \n%s", item->msg_att_static->rfc822_header );
283 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { 274 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) {
284 mailimap_envelope * head = item->msg_att_static->env; 275 mailimap_envelope * head = item->msg_att_static->env;
285 date = head->date; 276 date = head->date;
286 subject = head->subject; 277 subject = head->subject;
287 if (head->from!=NULL) 278 if (head->from!=NULL)
288 current_from = head->from->list->first; 279 current_from = head->from->list->first;
289 while (current_from != NULL) { 280 while (current_from != NULL) {
290 from = ""; 281 from = "";
291 named_from = false; 282 named_from = false;
292 current_address=(mailimap_address*)current_from->data; 283 current_address=(mailimap_address*)current_from->data;
293 current_from = current_from->next; 284 current_from = current_from->next;
294 if (current_address->personal_name){ 285 if (current_address->personal_name){
295 from+=QString(current_address->personal_name); 286 from+=QString(current_address->personal_name);
296 from+=" "; 287 from+=" ";
297 named_from = true; 288 named_from = true;
298 } 289 }
299 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 290 if (named_from && (current_address->mailbox_name || current_address->host_name)) {
300 from+="<"; 291 from+="<";
301 } 292 }
302 if (current_address->mailbox_name) { 293 if (current_address->mailbox_name) {
303 from+=QString(current_address->mailbox_name); 294 from+=QString(current_address->mailbox_name);
304 from+="@"; 295 from+="@";
305 } 296 }
306 if (current_address->host_name) { 297 if (current_address->host_name) {
307 from+=QString(current_address->host_name); 298 from+=QString(current_address->host_name);
308 } 299 }
309 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 300 if (named_from && (current_address->mailbox_name || current_address->host_name)) {
310 from+=">"; 301 from+=">";
311 } 302 }
312 } 303 }
313 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s", 304 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s",
314 from.latin1(), 305 from.latin1(),
315 subject.latin1(),date.latin1()); 306 subject.latin1(),date.latin1());
316 m = new RecMail(); 307 m = new RecMail();
317 m->setSubject(subject); 308 m->setSubject(subject);
318 m->setFrom(from); 309 m->setFrom(from);
319 m->setDate(date); 310 m->setDate(date);
320 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { 311 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) {
321 mailimap_date_time*d = item->msg_att_static->internal_date; 312 mailimap_date_time*d = item->msg_att_static->internal_date;
322 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); 313 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec));
323 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec); 314 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec);
324 qDebug(da.toString()); 315 qDebug(da.toString());
325 } else { 316 } else {
326 qDebug("Another type"); 317 qDebug("Another type");
327 } 318 }
328 } 319 }
329 /* msg is already deleted */ 320 /* msg is already deleted */
330 if (mFlags.testBit(FLAG_DELETED) && m) { 321 if (mFlags.testBit(FLAG_DELETED) && m) {
331 delete m; 322 delete m;
332 m = 0; 323 m = 0;
333 } 324 }
334 if (m) { 325 if (m) {
335 m->setFlags(mFlags); 326 m->setFlags(mFlags);
336 } 327 }
337 return m; 328 return m;
338} 329}
339 330
340QString IMAPwrapper::fetchBody(const QString & mailbox,const RecMail&mail) 331#if 1
332QString IMAPwrapper::fetchBody(const RecMail&mail)
341{ 333{
342 QString body = ""; 334 QString body = "";
343 const char *server, *user, *pass, *mb; 335 const char *mb;
344 uint16_t port;
345 int err = MAILIMAP_NO_ERROR; 336 int err = MAILIMAP_NO_ERROR;
346 clist *result; 337 clist *result;
347 clistcell *current; 338 clistcell *current;
348 mailimap_fetch_att *fetchAtt; 339 mailimap_fetch_att *fetchAtt;
349 mailimap_fetch_type *fetchType; 340 mailimap_fetch_type *fetchType;
350 mailimap_set *set; 341 mailimap_set *set;
351 342
352 mb = mailbox.latin1(); 343 mb = mail.getMbox().latin1();
353 server = account->getServer().latin1();
354 port = account->getPort().toUInt();
355 user = account->getUser().latin1();
356 pass = account->getPassword().latin1();
357 344
358 mailimap *imap = mailimap_new( 20, &imap_progress ); 345 login();
359 if ( imap == NULL ) { 346 if (!m_imap) {
360 qDebug("IMAP Memory error"); 347 return body;
348 }
349 /* select mailbox READONLY for operations */
350 err = mailimap_examine( m_imap, (char*)mb);
351 if ( err != MAILIMAP_NO_ERROR ) {
352 qDebug("error selecting mailbox: %s",m_imap->response);
353 logout();
361 return body; 354 return body;
362 } 355 }
356 result = clist_new();
357 /* the range has to start at 1!!! not with 0!!!! */
358 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
359 fetchAtt = mailimap_fetch_att_new_rfc822_text();
360 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
361 err = mailimap_fetch( m_imap, set, fetchType, &result );
362 mailimap_set_free( set );
363 mailimap_fetch_type_free( fetchType );
364
365 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
366 mailimap_msg_att * msg_att;
367 msg_att = (mailimap_msg_att*)current->data;
368 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
363 369
364 /* connect */ 370 if (item->msg_att_static && item->msg_att_static->rfc822_text) {
365 err = mailimap_socket_connect( imap, (char*)server, port ); 371 body = item->msg_att_static->rfc822_text;
366 if ( err != MAILIMAP_NO_ERROR && 372 }
367 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 373 } else {
368 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 374 qDebug("error fetching text: %s",m_imap->response);
369 qDebug("error connecting server: %s",imap->response);
370 mailimap_free( imap );
371 return body;
372 } 375 }
373 376
374 /* login */ 377 clist_free(result);
375 err = mailimap_login_simple( imap, (char*)user, (char*)pass ); 378 logout();
376 if ( err != MAILIMAP_NO_ERROR ) { 379 return body;
377 qDebug("error logging in imap: %s",imap->response); 380}
378 err = mailimap_close( imap ); 381
379 mailimap_free( imap ); 382#else
383QString IMAPwrapper::fetchBody(const RecMail&mail)
384{
385 QString body = "";
386 const char *mb;
387 int err = MAILIMAP_NO_ERROR;
388 clist *result;
389 clistcell *current;
390 mailimap_fetch_att *fetchAtt;
391 mailimap_fetch_type *fetchType;
392 mailimap_set *set;
393 mailimap_body*body_desc;
394
395 mb = mail.getMbox().latin1();
396
397 login();
398 if (!m_imap) {
380 return body; 399 return body;
381 } 400 }
382
383 /* select mailbox READONLY for operations */ 401 /* select mailbox READONLY for operations */
384 err = mailimap_examine( imap, (char*)mb); 402 err = mailimap_examine( m_imap, (char*)mb);
385 if ( err != MAILIMAP_NO_ERROR ) { 403 if ( err != MAILIMAP_NO_ERROR ) {
386 qDebug("error selecting mailbox: %s",imap->response); 404 qDebug("error selecting mailbox: %s",m_imap->response);
387 err = mailimap_logout( imap ); 405 logout();
388 err = mailimap_close( imap ); 406 return body;
389 mailimap_free( imap ); 407 }
408 result = clist_new();
409 /* the range has to start at 1!!! not with 0!!!! */
410 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
411 fetchAtt = mailimap_fetch_att_new_body();
412 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
413 err = mailimap_fetch( m_imap, set, fetchType, &result );
414 mailimap_set_free( set );
415 mailimap_fetch_type_free( fetchType );
416
417 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
418 mailimap_msg_att * msg_att;
419 msg_att = (mailimap_msg_att*)current->data;
420 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
421 body_desc = item->msg_att_static->body;
422 if (body_desc->type==MAILIMAP_BODY_1PART) {
423 body = searchBodyText(mail,body_desc->body_1part);
424 } else {
425 }
426
427 } else {
428 qDebug("error fetching body: %s",m_imap->response);
429 }
430
431 clist_free(result);
432 logout();
433 return body;
434}
435#endif
436
437QString IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription)
438{
439 QString Body="";
440 if (!mailDescription) {
441 return Body;
442 }
443 switch (mailDescription->type) {
444 case MAILIMAP_BODY_TYPE_1PART_TEXT:
445 return getPlainBody(mail);
446 break;
447 default:
448 break;
449 }
450 return Body;
451}
452
453QString IMAPwrapper::getPlainBody(const RecMail&mail)
454{
455 QString body = "";
456 const char *mb;
457 int err = MAILIMAP_NO_ERROR;
458 clist *result;
459 clistcell *current;
460 mailimap_fetch_att *fetchAtt;
461 mailimap_fetch_type *fetchType;
462 mailimap_set *set;
463
464 mb = mail.getMbox().latin1();
465
466 if (!m_imap) {
390 return body; 467 return body;
391 } 468 }
392 result = clist_new(); 469 result = clist_new();
393 /* the range has to start at 1!!! not with 0!!!! */ 470 /* the range has to start at 1!!! not with 0!!!! */
394 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 471 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
395 fetchAtt = mailimap_fetch_att_new_rfc822_text(); 472 fetchAtt = mailimap_fetch_att_new_rfc822_text();
396 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 473 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
397 err = mailimap_fetch( imap, set, fetchType, &result ); 474 err = mailimap_fetch( m_imap, set, fetchType, &result );
398 mailimap_set_free( set ); 475 mailimap_set_free( set );
399 mailimap_fetch_type_free( fetchType ); 476 mailimap_fetch_type_free( fetchType );
400 477
401 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 478 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
402 mailimap_msg_att * msg_att; 479 mailimap_msg_att * msg_att;
403 msg_att = (mailimap_msg_att*)current->data; 480 msg_att = (mailimap_msg_att*)current->data;
404 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 481 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
405
406 if (item->msg_att_static && item->msg_att_static->rfc822_text) { 482 if (item->msg_att_static && item->msg_att_static->rfc822_text) {
407 body = item->msg_att_static->rfc822_text; 483 body = item->msg_att_static->rfc822_text;
408 } 484 }
409 } else { 485 } else {
410 qDebug("error fetching text: %s",imap->response); 486 qDebug("error fetching text: %s",m_imap->response);
411 } 487 }
412
413 err = mailimap_logout( imap );
414 err = mailimap_close( imap );
415 mailimap_free( imap );
416 clist_free(result); 488 clist_free(result);
417
418 return body; 489 return body;
419} 490}
420
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h
index 65c36e0..b02d26d 100644
--- a/noncore/net/mail/imapwrapper.h
+++ b/noncore/net/mail/imapwrapper.h
@@ -1,25 +1,33 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include <libetpan/mailimap.h> 5
6struct mailimap;
7struct mailimap_body_type_1part;
6 8
7class IMAPwrapper : public QObject 9class IMAPwrapper : public QObject
8{ 10{
9 Q_OBJECT 11 Q_OBJECT
10 12
11public: 13public:
12 IMAPwrapper( IMAPaccount *a ); 14 IMAPwrapper( IMAPaccount *a );
15 virtual ~IMAPwrapper();
13 QList<IMAPFolder>* listFolders(); 16 QList<IMAPFolder>* listFolders();
14 void listMessages(const QString & mailbox,Maillist&target ); 17 void listMessages(const QString & mailbox,Maillist&target );
15 QString fetchBody(const QString & mailbox,const RecMail&mail); 18 QString fetchBody(const RecMail&mail);
19 static void imap_progress( size_t current, size_t maximum );
16 20
17protected: 21protected:
18 RecMail*parse_list_result(mailimap_msg_att*); 22 RecMail*parse_list_result(mailimap_msg_att*);
23 void login();
24 void logout();
25 QString searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription);
26 QString getPlainBody(const RecMail&mail);
19 27
20private: 28private:
21 IMAPaccount *account; 29 IMAPaccount *account;
22 30 mailimap *m_imap;
23}; 31};
24 32
25#endif 33#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 7b78499..1acc036 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,420 +1,490 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5 5#include <libetpan/mailimap.h>
6 6
7IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 7IMAPwrapper::IMAPwrapper( IMAPaccount *a )
8{ 8{
9 account = a; 9 account = a;
10 m_imap = 0;
10} 11}
11 12
12void imap_progress( size_t current, size_t maximum ) 13IMAPwrapper::~IMAPwrapper()
14{
15 logout();
16}
17
18void IMAPwrapper::imap_progress( size_t current, size_t maximum )
13{ 19{
14 qDebug( "IMAP: %i of %i", current, maximum ); 20 qDebug( "IMAP: %i of %i", current, maximum );
15} 21}
16 22
17void IMAPwrapper::listMessages(const QString&mailbox,Maillist&target ) 23void IMAPwrapper::login()
18{ 24{
19 const char *server, *user, *pass, *mb; 25 logout();
26 const char *server, *user, *pass;
20 uint16_t port; 27 uint16_t port;
21 int err = MAILIMAP_NO_ERROR; 28 int err = MAILIMAP_NO_ERROR;
22 clist *result;
23 clistcell *current;
24 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
25 mailimap_fetch_type *fetchType;
26 mailimap_set *set;
27 29
28 mb = mailbox.latin1();
29 server = account->getServer().latin1(); 30 server = account->getServer().latin1();
30 port = account->getPort().toUInt(); 31 port = account->getPort().toUInt();
31 user = account->getUser().latin1(); 32 user = account->getUser().latin1();
32 pass = account->getPassword().latin1(); 33 pass = account->getPassword().latin1();
33 34
34 mailimap *imap = mailimap_new( 20, &imap_progress ); 35 m_imap = mailimap_new( 20, &imap_progress );
35 if ( imap == NULL ) {
36 qDebug("IMAP Memory error");
37 return;
38 }
39
40 /* connect */ 36 /* connect */
41 err = mailimap_socket_connect( imap, (char*)server, port ); 37 err = mailimap_socket_connect( m_imap, (char*)server, port );
42 if ( err != MAILIMAP_NO_ERROR && 38 if ( err != MAILIMAP_NO_ERROR &&
43 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 39 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
44 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 40 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
45 qDebug("error connecting server: %s",imap->response); 41 qDebug("error connecting server: %s",m_imap->response);
46 mailimap_free( imap ); 42 mailimap_free( m_imap );
43 m_imap = 0;
47 return; 44 return;
48 } 45 }
49 46
50 /* login */ 47 /* login */
51 err = mailimap_login_simple( imap, (char*)user, (char*)pass ); 48 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
52 if ( err != MAILIMAP_NO_ERROR ) { 49 if ( err != MAILIMAP_NO_ERROR ) {
53 qDebug("error logging in imap: %s",imap->response); 50 qDebug("error logging in imap: %s",m_imap->response);
54 err = mailimap_close( imap ); 51 err = mailimap_close( m_imap );
55 mailimap_free( imap ); 52 mailimap_free( m_imap );
56 return; 53 m_imap = 0;
57 } 54 }
55}
56
57void IMAPwrapper::logout()
58{
59 int err = MAILIMAP_NO_ERROR;
60 if (!m_imap) return;
61 err = mailimap_logout( m_imap );
62 err = mailimap_close( m_imap );
63 mailimap_free( m_imap );
64 m_imap = 0;
65}
66
67void IMAPwrapper::listMessages(const QString&mailbox,Maillist&target )
68{
69 const char *mb;
70 int err = MAILIMAP_NO_ERROR;
71 clist *result;
72 clistcell *current;
73 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
74 mailimap_fetch_type *fetchType;
75 mailimap_set *set;
58 76
77 mb = mailbox.latin1();
78 login();
79 if (!m_imap) {
80 return;
81 }
59 /* select mailbox READONLY for operations */ 82 /* select mailbox READONLY for operations */
60 err = mailimap_examine( imap, (char*)mb); 83 err = mailimap_examine( m_imap, (char*)mb);
61 if ( err != MAILIMAP_NO_ERROR ) { 84 if ( err != MAILIMAP_NO_ERROR ) {
62 qDebug("error selecting mailbox: %s",imap->response); 85 qDebug("error selecting mailbox: %s",m_imap->response);
63 err = mailimap_logout( imap ); 86 logout();
64 err = mailimap_close( imap );
65 mailimap_free( imap );
66 return; 87 return;
67 } 88 }
68 89
69 int last = imap->selection_info->exists; 90 int last = m_imap->selection_info->exists;
91
70 if (last == 0) { 92 if (last == 0) {
71 qDebug("mailbox has no mails"); 93 qDebug("mailbox has no mails");
72 err = mailimap_logout( imap ); 94 logout();
73 err = mailimap_close( imap );
74 mailimap_free( imap );
75 return; 95 return;
76 } 96 }
77 97
78
79 result = clist_new(); 98 result = clist_new();
80 /* the range has to start at 1!!! not with 0!!!! */ 99 /* the range has to start at 1!!! not with 0!!!! */
81 set = mailimap_set_new_interval( 1, last ); 100 set = mailimap_set_new_interval( 1, last );
82 fetchAtt = mailimap_fetch_att_new_envelope(); 101 fetchAtt = mailimap_fetch_att_new_envelope();
83 fetchAttFlags = mailimap_fetch_att_new_flags(); 102 fetchAttFlags = mailimap_fetch_att_new_flags();
84 fetchAttDate = mailimap_fetch_att_new_internaldate(); 103 fetchAttDate = mailimap_fetch_att_new_internaldate();
85 104
86 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 105 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
87 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 106 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
88 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); 107 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt);
89 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); 108 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags);
90 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); 109 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate);
91 110
92 err = mailimap_fetch( imap, set, fetchType, &result ); 111 err = mailimap_fetch( m_imap, set, fetchType, &result );
93 mailimap_set_free( set ); 112 mailimap_set_free( set );
94 /* cleans up the fetch_att's too! */ 113 /* cleans up the fetch_att's too! */
95 mailimap_fetch_type_free( fetchType ); 114 mailimap_fetch_type_free( fetchType );
96 115
97 QString date,subject,from; 116 QString date,subject,from;
98 117
99 if ( err == MAILIMAP_NO_ERROR ) { 118 if ( err == MAILIMAP_NO_ERROR ) {
100 current = clist_begin(result); 119 current = clist_begin(result);
101 mailimap_msg_att * msg_att; 120 mailimap_msg_att * msg_att;
102 int i = 0; 121 int i = 0;
103 while ( current != 0 ) { 122 while ( current != 0 ) {
104 ++i; 123 ++i;
105 msg_att = (mailimap_msg_att*)current->data; 124 msg_att = (mailimap_msg_att*)current->data;
106 RecMail*m = parse_list_result(msg_att); 125 RecMail*m = parse_list_result(msg_att);
107 if (m) { 126 if (m) {
108 m->setNumber(i); 127 m->setNumber(i);
128 m->setMbox(mailbox);
109 target.append(m); 129 target.append(m);
110 } 130 }
111 current = current->next; 131 current = current->next;
112 } 132 }
113 } else { 133 } else {
114 qDebug("Error fetching headers: %s",imap->response); 134 qDebug("Error fetching headers: %s",m_imap->response);
115 } 135 }
116 136 logout();
117 err = mailimap_logout( imap );
118 err = mailimap_close( imap );
119 clist_free(result); 137 clist_free(result);
120 mailimap_free( imap );
121} 138}
122 139
123QList<IMAPFolder>* IMAPwrapper::listFolders() 140QList<IMAPFolder>* IMAPwrapper::listFolders()
124{ 141{
125 const char *server, *user, *pass, *path, *mask; 142 const char *path, *mask;
126 uint16_t port;
127 int err = MAILIMAP_NO_ERROR; 143 int err = MAILIMAP_NO_ERROR;
128 clist *result; 144 clist *result;
129 clistcell *current; 145 clistcell *current;
130 146
131 QList<IMAPFolder> * folders = new QList<IMAPFolder>(); 147 QList<IMAPFolder> * folders = new QList<IMAPFolder>();
132 folders->setAutoDelete( true ); 148 folders->setAutoDelete( true );
133 149 login();
134 server = account->getServer().latin1(); 150 if (!m_imap) {
135 port = account->getPort().toUInt();
136 user = account->getUser().latin1();
137 pass = account->getPassword().latin1();
138 path = account->getPrefix().latin1();
139
140 mailimap *imap = mailimap_new( 20, &imap_progress );
141 if ( imap == NULL ) {
142 qDebug("error mailimap_new");
143 return folders; 151 return folders;
144 } 152 }
145
146 err = mailimap_socket_connect( imap, (char*)server, port );
147 if ( err != MAILIMAP_NO_ERROR &&
148 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
149 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
150 mailimap_free(imap);
151 qDebug("error imap_socket_connect: %s",imap->response);
152 return folders;
153 }
154 153
155 err = mailimap_login_simple( imap, (char*)user, (char*)pass );
156 if ( err != MAILIMAP_NO_ERROR ) {
157 mailimap_free(imap);
158 qDebug("error logging in: %s",imap->response);
159 return folders;
160 }
161/* 154/*
162 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 155 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
163 * We must not forget to filter them out in next loop! 156 * We must not forget to filter them out in next loop!
164 * it seems like ugly code. and yes - it is ugly code. but the best way. 157 * it seems like ugly code. and yes - it is ugly code. but the best way.
165 */ 158 */
166 QString temp; 159 QString temp;
167 mask = "INBOX" ; 160 mask = "INBOX" ;
168 result = clist_new(); 161 result = clist_new();
169 mailimap_mailbox_list *list; 162 mailimap_mailbox_list *list;
170 err = mailimap_list( imap, (char*)"", (char*)mask, &result ); 163 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
171 if ( err == MAILIMAP_NO_ERROR ) { 164 if ( err == MAILIMAP_NO_ERROR ) {
172 current = result->first; 165 current = result->first;
173 for ( int i = result->count; i > 0; i-- ) { 166 for ( int i = result->count; i > 0; i-- ) {
174 list = (mailimap_mailbox_list *) current->data; 167 list = (mailimap_mailbox_list *) current->data;
175 // it is better use the deep copy mechanism of qt itself 168 // it is better use the deep copy mechanism of qt itself
176 // instead of using strdup! 169 // instead of using strdup!
177 temp = list->mb; 170 temp = list->mb;
178 folders->append( new IMAPFolder(temp)); 171 folders->append( new IMAPFolder(temp));
179 current = current->next; 172 current = current->next;
180 } 173 }
181 } else { 174 } else {
182 qDebug("error fetching folders: %s",imap->response); 175 qDebug("error fetching folders: %s",m_imap->response);
183 } 176 }
184 mailimap_list_result_free( result ); 177 mailimap_list_result_free( result );
185 178
186/* 179/*
187 * second stage - get the other then inbox folders 180 * second stage - get the other then inbox folders
188 */ 181 */
189 mask = "*" ; 182 mask = "*" ;
183 path = account->getPrefix().latin1();
190 result = clist_new(); 184 result = clist_new();
191 err = mailimap_list( imap, (char*)path, (char*)mask, &result ); 185 qDebug(path);
186 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
192 if ( err == MAILIMAP_NO_ERROR ) { 187 if ( err == MAILIMAP_NO_ERROR ) {
193 current = result->first; 188 current = result->first;
194 for ( int i = result->count; i > 0; i-- ) { 189 for ( int i = result->count; i > 0; i-- ) {
195 list = (mailimap_mailbox_list *) current->data; 190 list = (mailimap_mailbox_list *) current->data;
196 // it is better use the deep copy mechanism of qt itself 191 // it is better use the deep copy mechanism of qt itself
197 // instead of using strdup! 192 // instead of using strdup!
198 temp = list->mb; 193 temp = list->mb;
199 current = current->next; 194 current = current->next;
200 if (temp.lower()=="inbox") 195 if (temp.lower()=="inbox")
201 continue; 196 continue;
202 folders->append(new IMAPFolder(temp)); 197 folders->append(new IMAPFolder(temp));
203 198
204 } 199 }
205 } else { 200 } else {
206 qDebug("error fetching folders"); 201 qDebug("error fetching folders %s",m_imap->response);
207 } 202 }
208 mailimap_list_result_free( result ); 203 mailimap_list_result_free( result );
209 err = mailimap_logout( imap );
210 err = mailimap_close( imap );
211 mailimap_free( imap );
212 return folders; 204 return folders;
213} 205}
214 206
215RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 207RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
216{ 208{
217 RecMail * m = 0; 209 RecMail * m = 0;
218 mailimap_msg_att_item *item=0; 210 mailimap_msg_att_item *item=0;
219 bool named_from = false; 211 bool named_from = false;
220 QString from,date,subject; 212 QString from,date,subject;
221 date = from = subject = ""; 213 date = from = subject = "";
222 clistcell *current,*c,*cf, *current_from = NULL; 214 clistcell *current,*c,*cf, *current_from = NULL;
223 mailimap_address * current_address = NULL; 215 mailimap_address * current_address = NULL;
224 mailimap_msg_att_dynamic*flist; 216 mailimap_msg_att_dynamic*flist;
225 mailimap_flag_fetch*cflag; 217 mailimap_flag_fetch*cflag;
226 QBitArray mFlags(7); 218 QBitArray mFlags(7);
227 219
228 if (!m_att) { 220 if (!m_att) {
229 return m; 221 return m;
230 } 222 }
231 223
232#if 0 224#if 0
233 MAILIMAP_FLAG_KEYWORD, /* keyword flag */ 225 MAILIMAP_FLAG_KEYWORD, /* keyword flag */
234 MAILIMAP_FLAG_EXTENSION, /* \extension flag */ 226 MAILIMAP_FLAG_EXTENSION, /* \extension flag */
235#endif 227#endif
236 c = clist_begin(m_att->list); 228 c = clist_begin(m_att->list);
237 while ( c ) { 229 while ( c ) {
238 current = c; 230 current = c;
239 c = c->next; 231 c = c->next;
240 item = (mailimap_msg_att_item*)current->data; 232 item = (mailimap_msg_att_item*)current->data;
241 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 233 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
242 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; 234 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn;
243 if (!flist->list) { 235 if (!flist->list) {
244 continue; 236 continue;
245 } 237 }
246 cf = flist->list->first; 238 cf = flist->list->first;
247 while (cf) { 239 while (cf) {
248 cflag = (mailimap_flag_fetch*)cf->data; 240 cflag = (mailimap_flag_fetch*)cf->data;
249 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { 241 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) {
250 switch (cflag->flag->type) { 242 switch (cflag->flag->type) {
251 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 243 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
252 mFlags.setBit(FLAG_ANSWERED); 244 mFlags.setBit(FLAG_ANSWERED);
253 break; 245 break;
254 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 246 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
255 mFlags.setBit(FLAG_FLAGGED); 247 mFlags.setBit(FLAG_FLAGGED);
256 break; 248 break;
257 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 249 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
258 mFlags.setBit(FLAG_DELETED); 250 mFlags.setBit(FLAG_DELETED);
259 break; 251 break;
260 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 252 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
261 mFlags.setBit(FLAG_SEEN); 253 mFlags.setBit(FLAG_SEEN);
262 break; 254 break;
263 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 255 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
264 mFlags.setBit(FLAG_DRAFT); 256 mFlags.setBit(FLAG_DRAFT);
265 break; 257 break;
266 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 258 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
267 break; 259 break;
268 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 260 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
269 break; 261 break;
270 default: 262 default:
271 break; 263 break;
272 } 264 }
273 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { 265 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) {
274 mFlags.setBit(FLAG_RECENT); 266 mFlags.setBit(FLAG_RECENT);
275 } 267 }
276
277 cf = cf->next; 268 cf = cf->next;
278 } 269 }
279 continue; 270 continue;
280 } 271 }
281 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { 272 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) {
282 qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); 273 qDebug( "header: \n%s", item->msg_att_static->rfc822_header );
283 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { 274 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) {
284 mailimap_envelope * head = item->msg_att_static->env; 275 mailimap_envelope * head = item->msg_att_static->env;
285 date = head->date; 276 date = head->date;
286 subject = head->subject; 277 subject = head->subject;
287 if (head->from!=NULL) 278 if (head->from!=NULL)
288 current_from = head->from->list->first; 279 current_from = head->from->list->first;
289 while (current_from != NULL) { 280 while (current_from != NULL) {
290 from = ""; 281 from = "";
291 named_from = false; 282 named_from = false;
292 current_address=(mailimap_address*)current_from->data; 283 current_address=(mailimap_address*)current_from->data;
293 current_from = current_from->next; 284 current_from = current_from->next;
294 if (current_address->personal_name){ 285 if (current_address->personal_name){
295 from+=QString(current_address->personal_name); 286 from+=QString(current_address->personal_name);
296 from+=" "; 287 from+=" ";
297 named_from = true; 288 named_from = true;
298 } 289 }
299 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 290 if (named_from && (current_address->mailbox_name || current_address->host_name)) {
300 from+="<"; 291 from+="<";
301 } 292 }
302 if (current_address->mailbox_name) { 293 if (current_address->mailbox_name) {
303 from+=QString(current_address->mailbox_name); 294 from+=QString(current_address->mailbox_name);
304 from+="@"; 295 from+="@";
305 } 296 }
306 if (current_address->host_name) { 297 if (current_address->host_name) {
307 from+=QString(current_address->host_name); 298 from+=QString(current_address->host_name);
308 } 299 }
309 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 300 if (named_from && (current_address->mailbox_name || current_address->host_name)) {
310 from+=">"; 301 from+=">";
311 } 302 }
312 } 303 }
313 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s", 304 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s",
314 from.latin1(), 305 from.latin1(),
315 subject.latin1(),date.latin1()); 306 subject.latin1(),date.latin1());
316 m = new RecMail(); 307 m = new RecMail();
317 m->setSubject(subject); 308 m->setSubject(subject);
318 m->setFrom(from); 309 m->setFrom(from);
319 m->setDate(date); 310 m->setDate(date);
320 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { 311 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) {
321 mailimap_date_time*d = item->msg_att_static->internal_date; 312 mailimap_date_time*d = item->msg_att_static->internal_date;
322 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); 313 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec));
323 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec); 314 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec);
324 qDebug(da.toString()); 315 qDebug(da.toString());
325 } else { 316 } else {
326 qDebug("Another type"); 317 qDebug("Another type");
327 } 318 }
328 } 319 }
329 /* msg is already deleted */ 320 /* msg is already deleted */
330 if (mFlags.testBit(FLAG_DELETED) && m) { 321 if (mFlags.testBit(FLAG_DELETED) && m) {
331 delete m; 322 delete m;
332 m = 0; 323 m = 0;
333 } 324 }
334 if (m) { 325 if (m) {
335 m->setFlags(mFlags); 326 m->setFlags(mFlags);
336 } 327 }
337 return m; 328 return m;
338} 329}
339 330
340QString IMAPwrapper::fetchBody(const QString & mailbox,const RecMail&mail) 331#if 1
332QString IMAPwrapper::fetchBody(const RecMail&mail)
341{ 333{
342 QString body = ""; 334 QString body = "";
343 const char *server, *user, *pass, *mb; 335 const char *mb;
344 uint16_t port;
345 int err = MAILIMAP_NO_ERROR; 336 int err = MAILIMAP_NO_ERROR;
346 clist *result; 337 clist *result;
347 clistcell *current; 338 clistcell *current;
348 mailimap_fetch_att *fetchAtt; 339 mailimap_fetch_att *fetchAtt;
349 mailimap_fetch_type *fetchType; 340 mailimap_fetch_type *fetchType;
350 mailimap_set *set; 341 mailimap_set *set;
351 342
352 mb = mailbox.latin1(); 343 mb = mail.getMbox().latin1();
353 server = account->getServer().latin1();
354 port = account->getPort().toUInt();
355 user = account->getUser().latin1();
356 pass = account->getPassword().latin1();
357 344
358 mailimap *imap = mailimap_new( 20, &imap_progress ); 345 login();
359 if ( imap == NULL ) { 346 if (!m_imap) {
360 qDebug("IMAP Memory error"); 347 return body;
348 }
349 /* select mailbox READONLY for operations */
350 err = mailimap_examine( m_imap, (char*)mb);
351 if ( err != MAILIMAP_NO_ERROR ) {
352 qDebug("error selecting mailbox: %s",m_imap->response);
353 logout();
361 return body; 354 return body;
362 } 355 }
356 result = clist_new();
357 /* the range has to start at 1!!! not with 0!!!! */
358 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
359 fetchAtt = mailimap_fetch_att_new_rfc822_text();
360 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
361 err = mailimap_fetch( m_imap, set, fetchType, &result );
362 mailimap_set_free( set );
363 mailimap_fetch_type_free( fetchType );
364
365 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
366 mailimap_msg_att * msg_att;
367 msg_att = (mailimap_msg_att*)current->data;
368 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
363 369
364 /* connect */ 370 if (item->msg_att_static && item->msg_att_static->rfc822_text) {
365 err = mailimap_socket_connect( imap, (char*)server, port ); 371 body = item->msg_att_static->rfc822_text;
366 if ( err != MAILIMAP_NO_ERROR && 372 }
367 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 373 } else {
368 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 374 qDebug("error fetching text: %s",m_imap->response);
369 qDebug("error connecting server: %s",imap->response);
370 mailimap_free( imap );
371 return body;
372 } 375 }
373 376
374 /* login */ 377 clist_free(result);
375 err = mailimap_login_simple( imap, (char*)user, (char*)pass ); 378 logout();
376 if ( err != MAILIMAP_NO_ERROR ) { 379 return body;
377 qDebug("error logging in imap: %s",imap->response); 380}
378 err = mailimap_close( imap ); 381
379 mailimap_free( imap ); 382#else
383QString IMAPwrapper::fetchBody(const RecMail&mail)
384{
385 QString body = "";
386 const char *mb;
387 int err = MAILIMAP_NO_ERROR;
388 clist *result;
389 clistcell *current;
390 mailimap_fetch_att *fetchAtt;
391 mailimap_fetch_type *fetchType;
392 mailimap_set *set;
393 mailimap_body*body_desc;
394
395 mb = mail.getMbox().latin1();
396
397 login();
398 if (!m_imap) {
380 return body; 399 return body;
381 } 400 }
382
383 /* select mailbox READONLY for operations */ 401 /* select mailbox READONLY for operations */
384 err = mailimap_examine( imap, (char*)mb); 402 err = mailimap_examine( m_imap, (char*)mb);
385 if ( err != MAILIMAP_NO_ERROR ) { 403 if ( err != MAILIMAP_NO_ERROR ) {
386 qDebug("error selecting mailbox: %s",imap->response); 404 qDebug("error selecting mailbox: %s",m_imap->response);
387 err = mailimap_logout( imap ); 405 logout();
388 err = mailimap_close( imap ); 406 return body;
389 mailimap_free( imap ); 407 }
408 result = clist_new();
409 /* the range has to start at 1!!! not with 0!!!! */
410 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
411 fetchAtt = mailimap_fetch_att_new_body();
412 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
413 err = mailimap_fetch( m_imap, set, fetchType, &result );
414 mailimap_set_free( set );
415 mailimap_fetch_type_free( fetchType );
416
417 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
418 mailimap_msg_att * msg_att;
419 msg_att = (mailimap_msg_att*)current->data;
420 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
421 body_desc = item->msg_att_static->body;
422 if (body_desc->type==MAILIMAP_BODY_1PART) {
423 body = searchBodyText(mail,body_desc->body_1part);
424 } else {
425 }
426
427 } else {
428 qDebug("error fetching body: %s",m_imap->response);
429 }
430
431 clist_free(result);
432 logout();
433 return body;
434}
435#endif
436
437QString IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription)
438{
439 QString Body="";
440 if (!mailDescription) {
441 return Body;
442 }
443 switch (mailDescription->type) {
444 case MAILIMAP_BODY_TYPE_1PART_TEXT:
445 return getPlainBody(mail);
446 break;
447 default:
448 break;
449 }
450 return Body;
451}
452
453QString IMAPwrapper::getPlainBody(const RecMail&mail)
454{
455 QString body = "";
456 const char *mb;
457 int err = MAILIMAP_NO_ERROR;
458 clist *result;
459 clistcell *current;
460 mailimap_fetch_att *fetchAtt;
461 mailimap_fetch_type *fetchType;
462 mailimap_set *set;
463
464 mb = mail.getMbox().latin1();
465
466 if (!m_imap) {
390 return body; 467 return body;
391 } 468 }
392 result = clist_new(); 469 result = clist_new();
393 /* the range has to start at 1!!! not with 0!!!! */ 470 /* the range has to start at 1!!! not with 0!!!! */
394 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 471 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
395 fetchAtt = mailimap_fetch_att_new_rfc822_text(); 472 fetchAtt = mailimap_fetch_att_new_rfc822_text();
396 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 473 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
397 err = mailimap_fetch( imap, set, fetchType, &result ); 474 err = mailimap_fetch( m_imap, set, fetchType, &result );
398 mailimap_set_free( set ); 475 mailimap_set_free( set );
399 mailimap_fetch_type_free( fetchType ); 476 mailimap_fetch_type_free( fetchType );
400 477
401 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 478 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
402 mailimap_msg_att * msg_att; 479 mailimap_msg_att * msg_att;
403 msg_att = (mailimap_msg_att*)current->data; 480 msg_att = (mailimap_msg_att*)current->data;
404 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 481 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
405
406 if (item->msg_att_static && item->msg_att_static->rfc822_text) { 482 if (item->msg_att_static && item->msg_att_static->rfc822_text) {
407 body = item->msg_att_static->rfc822_text; 483 body = item->msg_att_static->rfc822_text;
408 } 484 }
409 } else { 485 } else {
410 qDebug("error fetching text: %s",imap->response); 486 qDebug("error fetching text: %s",m_imap->response);
411 } 487 }
412
413 err = mailimap_logout( imap );
414 err = mailimap_close( imap );
415 mailimap_free( imap );
416 clist_free(result); 488 clist_free(result);
417
418 return body; 489 return body;
419} 490}
420
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index 65c36e0..b02d26d 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,25 +1,33 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include <libetpan/mailimap.h> 5
6struct mailimap;
7struct mailimap_body_type_1part;
6 8
7class IMAPwrapper : public QObject 9class IMAPwrapper : public QObject
8{ 10{
9 Q_OBJECT 11 Q_OBJECT
10 12
11public: 13public:
12 IMAPwrapper( IMAPaccount *a ); 14 IMAPwrapper( IMAPaccount *a );
15 virtual ~IMAPwrapper();
13 QList<IMAPFolder>* listFolders(); 16 QList<IMAPFolder>* listFolders();
14 void listMessages(const QString & mailbox,Maillist&target ); 17 void listMessages(const QString & mailbox,Maillist&target );
15 QString fetchBody(const QString & mailbox,const RecMail&mail); 18 QString fetchBody(const RecMail&mail);
19 static void imap_progress( size_t current, size_t maximum );
16 20
17protected: 21protected:
18 RecMail*parse_list_result(mailimap_msg_att*); 22 RecMail*parse_list_result(mailimap_msg_att*);
23 void login();
24 void logout();
25 QString searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription);
26 QString getPlainBody(const RecMail&mail);
19 27
20private: 28private:
21 IMAPaccount *account; 29 IMAPaccount *account;
22 30 mailimap *m_imap;
23}; 31};
24 32
25#endif 33#endif
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
index ea9e7b2..7f67cd8 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
@@ -248,394 +248,394 @@ mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype )
248 content = mailmime_content_new_with_str( mime ); 248 content = mailmime_content_new_with_str( mime );
249 if ( content == NULL ) goto err_free_fields; 249 if ( content == NULL ) goto err_free_fields;
250 250
251 if ( mimetype.compare( "text/plain" ) == 0 ) { 251 if ( mimetype.compare( "text/plain" ) == 0 ) {
252 param = mailmime_parameter_new( strdup( "charset" ), 252 param = mailmime_parameter_new( strdup( "charset" ),
253 strdup( "iso-8859-1" ) ); 253 strdup( "iso-8859-1" ) );
254 if ( param == NULL ) goto err_free_content; 254 if ( param == NULL ) goto err_free_content;
255 255
256 err = clist_append( content->parameters, param ); 256 err = clist_append( content->parameters, param );
257 if ( err != MAILIMF_NO_ERROR ) goto err_free_param; 257 if ( err != MAILIMF_NO_ERROR ) goto err_free_param;
258 } 258 }
259 259
260 filePart = mailmime_new_empty( content, fields ); 260 filePart = mailmime_new_empty( content, fields );
261 if ( filePart == NULL ) goto err_free_param; 261 if ( filePart == NULL ) goto err_free_param;
262 262
263 err = mailmime_set_body_file( filePart, file ); 263 err = mailmime_set_body_file( filePart, file );
264 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; 264 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
265 265
266 return filePart; // Success :) 266 return filePart; // Success :)
267 267
268err_free_filePart: 268err_free_filePart:
269 mailmime_free( filePart ); 269 mailmime_free( filePart );
270err_free_param: 270err_free_param:
271 if ( param != NULL ) mailmime_parameter_free( param ); 271 if ( param != NULL ) mailmime_parameter_free( param );
272err_free_content: 272err_free_content:
273 mailmime_content_free( content ); 273 mailmime_content_free( content );
274err_free_fields: 274err_free_fields:
275 mailmime_fields_free( fields ); 275 mailmime_fields_free( fields );
276err_free: 276err_free:
277 free( name ); 277 free( name );
278 free( mime ); 278 free( mime );
279 free( file ); 279 free( file );
280 qDebug( "buildFilePart - error" ); 280 qDebug( "buildFilePart - error" );
281 281
282 return NULL; // Error :( 282 return NULL; // Error :(
283} 283}
284 284
285void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) 285void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files )
286{ 286{
287 Attachment *it; 287 Attachment *it;
288 for ( it = files.first(); it; it = files.next() ) { 288 for ( it = files.first(); it; it = files.next() ) {
289 qDebug( "Adding file" ); 289 qDebug( "Adding file" );
290 mailmime *filePart; 290 mailmime *filePart;
291 int err; 291 int err;
292 292
293 filePart = buildFilePart( it->getFileName(), it->getMimeType() ); 293 filePart = buildFilePart( it->getFileName(), it->getMimeType() );
294 if ( filePart == NULL ) goto err_free; 294 if ( filePart == NULL ) goto err_free;
295 295
296 err = mailmime_smart_add_part( message, filePart ); 296 err = mailmime_smart_add_part( message, filePart );
297 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; 297 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
298 298
299 continue; // Success :) 299 continue; // Success :)
300 300
301 err_free_filePart: 301 err_free_filePart:
302 mailmime_free( filePart ); 302 mailmime_free( filePart );
303 err_free: 303 err_free:
304 qDebug( "addFileParts: error adding file:" ); 304 qDebug( "addFileParts: error adding file:" );
305 qDebug( it->getFileName() ); 305 qDebug( it->getFileName() );
306 } 306 }
307} 307}
308 308
309mailmime *MailWrapper::createMimeMail( Mail *mail ) 309mailmime *MailWrapper::createMimeMail( Mail *mail )
310{ 310{
311 mailmime *message, *txtPart; 311 mailmime *message, *txtPart;
312 mailimf_fields *fields; 312 mailimf_fields *fields;
313 int err; 313 int err;
314 314
315 fields = createImfFields( mail ); 315 fields = createImfFields( mail );
316 if ( fields == NULL ) goto err_free; 316 if ( fields == NULL ) goto err_free;
317 317
318 message = mailmime_new_message_data( NULL ); 318 message = mailmime_new_message_data( NULL );
319 if ( message == NULL ) goto err_free_fields; 319 if ( message == NULL ) goto err_free_fields;
320 320
321 mailmime_set_imf_fields( message, fields ); 321 mailmime_set_imf_fields( message, fields );
322 322
323 txtPart = buildTxtPart( mail->getMessage() ); 323 txtPart = buildTxtPart( mail->getMessage() );
324 if ( txtPart == NULL ) goto err_free_message; 324 if ( txtPart == NULL ) goto err_free_message;
325 325
326 err = mailmime_smart_add_part( message, txtPart ); 326 err = mailmime_smart_add_part( message, txtPart );
327 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 327 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
328 328
329 addFileParts( message, mail->getAttachments() ); 329 addFileParts( message, mail->getAttachments() );
330 330
331 return message; // Success :) 331 return message; // Success :)
332 332
333err_free_txtPart: 333err_free_txtPart:
334 mailmime_free( txtPart ); 334 mailmime_free( txtPart );
335err_free_message: 335err_free_message:
336 mailmime_free( message ); 336 mailmime_free( message );
337err_free_fields: 337err_free_fields:
338 mailimf_fields_free( fields ); 338 mailimf_fields_free( fields );
339err_free: 339err_free:
340 qDebug( "createMimeMail: error" ); 340 qDebug( "createMimeMail: error" );
341 341
342 return NULL; // Error :( 342 return NULL; // Error :(
343} 343}
344 344
345mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) 345mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type )
346{ 346{
347 mailimf_field *field; 347 mailimf_field *field;
348 clistiter *it; 348 clistiter *it;
349 349
350 it = clist_begin( fields->list ); 350 it = clist_begin( fields->list );
351 while ( it ) { 351 while ( it ) {
352 field = (mailimf_field *) it->data; 352 field = (mailimf_field *) it->data;
353 if ( field->type == type ) { 353 if ( field->type == type ) {
354 return field; 354 return field;
355 } 355 }
356 it = it->next; 356 it = it->next;
357 } 357 }
358 358
359 return NULL; 359 return NULL;
360} 360}
361 361
362static void addRcpts( clist *list, mailimf_address_list *addr_list ) 362static void addRcpts( clist *list, mailimf_address_list *addr_list )
363{ 363{
364 clistiter *it, *it2; 364 clistiter *it, *it2;
365 365
366 for ( it = clist_begin( addr_list->list ); it; it = it->next ) { 366 for ( it = clist_begin( addr_list->list ); it; it = it->next ) {
367 mailimf_address *addr; 367 mailimf_address *addr;
368 addr = (mailimf_address *) it->data; 368 addr = (mailimf_address *) it->data;
369 369
370 if ( addr->type == MAILIMF_ADDRESS_MAILBOX ) { 370 if ( addr->type == MAILIMF_ADDRESS_MAILBOX ) {
371 esmtp_address_list_add( list, addr->mailbox->addr_spec, 0, NULL ); 371 esmtp_address_list_add( list, addr->mailbox->addr_spec, 0, NULL );
372 } else if ( addr->type == MAILIMF_ADDRESS_GROUP ) { 372 } else if ( addr->type == MAILIMF_ADDRESS_GROUP ) {
373 clist *l = addr->group->mb_list->list; 373 clist *l = addr->group->mb_list->list;
374 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { 374 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
375 mailimf_mailbox *mbox; 375 mailimf_mailbox *mbox;
376 mbox = (mailimf_mailbox *) it2->data; 376 mbox = (mailimf_mailbox *) it2->data;
377 esmtp_address_list_add( list, mbox->addr_spec, 0, NULL ); 377 esmtp_address_list_add( list, mbox->addr_spec, 0, NULL );
378 } 378 }
379 } 379 }
380 } 380 }
381} 381}
382 382
383clist *MailWrapper::createRcptList( mailimf_fields *fields ) 383clist *MailWrapper::createRcptList( mailimf_fields *fields )
384{ 384{
385 clist *rcptList; 385 clist *rcptList;
386 mailimf_field *field; 386 mailimf_field *field;
387 387
388 rcptList = esmtp_address_list_new(); 388 rcptList = esmtp_address_list_new();
389 389
390 field = getField( fields, MAILIMF_FIELD_TO ); 390 field = getField( fields, MAILIMF_FIELD_TO );
391 if ( field && (field->type == MAILIMF_FIELD_TO) 391 if ( field && (field->type == MAILIMF_FIELD_TO)
392 && field->field.to->addr_list ) { 392 && field->field.to->addr_list ) {
393 addRcpts( rcptList, field->field.to->addr_list ); 393 addRcpts( rcptList, field->field.to->addr_list );
394 } 394 }
395 395
396 field = getField( fields, MAILIMF_FIELD_CC ); 396 field = getField( fields, MAILIMF_FIELD_CC );
397 if ( field && (field->type == MAILIMF_FIELD_CC) 397 if ( field && (field->type == MAILIMF_FIELD_CC)
398 && field->field.cc->addr_list ) { 398 && field->field.cc->addr_list ) {
399 addRcpts( rcptList, field->field.cc->addr_list ); 399 addRcpts( rcptList, field->field.cc->addr_list );
400 } 400 }
401 401
402 field = getField( fields, MAILIMF_FIELD_BCC ); 402 field = getField( fields, MAILIMF_FIELD_BCC );
403 if ( field && (field->type == MAILIMF_FIELD_BCC) 403 if ( field && (field->type == MAILIMF_FIELD_BCC)
404 && field->field.bcc->addr_list ) { 404 && field->field.bcc->addr_list ) {
405 addRcpts( rcptList, field->field.bcc->addr_list ); 405 addRcpts( rcptList, field->field.bcc->addr_list );
406 } 406 }
407 407
408 return rcptList; 408 return rcptList;
409} 409}
410 410
411char *MailWrapper::getFrom( mailmime *mail ) 411char *MailWrapper::getFrom( mailmime *mail )
412{ 412{
413 char *from = NULL; 413 char *from = NULL;
414 414
415 mailimf_field *ffrom; 415 mailimf_field *ffrom;
416 ffrom = getField( mail->fields, MAILIMF_FIELD_FROM ); 416 ffrom = getField( mail->fields, MAILIMF_FIELD_FROM );
417 if ( ffrom && (ffrom->type == MAILIMF_FIELD_FROM) 417 if ( ffrom && (ffrom->type == MAILIMF_FIELD_FROM)
418 && ffrom->field.from->mb_list && ffrom->field.from->mb_list->list ) { 418 && ffrom->field.from->mb_list && ffrom->field.from->mb_list->list ) {
419 clist *cl = ffrom->field.from->mb_list->list; 419 clist *cl = ffrom->field.from->mb_list->list;
420 clistiter *it; 420 clistiter *it;
421 for ( it = clist_begin( cl ); it; it = it->next ) { 421 for ( it = clist_begin( cl ); it; it = it->next ) {
422 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 422 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
423 from = strdup( mb->addr_spec ); 423 from = strdup( mb->addr_spec );
424 } 424 }
425 } 425 }
426 426
427 return from; 427 return from;
428} 428}
429 429
430SMTPaccount *MailWrapper::getAccount( QString from ) 430SMTPaccount *MailWrapper::getAccount( QString from )
431{ 431{
432 SMTPaccount *smtp; 432 SMTPaccount *smtp;
433 433
434 QList<Account> list = settings->getAccounts(); 434 QList<Account> list = settings->getAccounts();
435 Account *it; 435 Account *it;
436 for ( it = list.first(); it; it = list.next() ) { 436 for ( it = list.first(); it; it = list.next() ) {
437 if ( it->getType().compare( "SMTP" ) == 0 ) { 437 if ( it->getType().compare( "SMTP" ) == 0 ) {
438 smtp = static_cast<SMTPaccount *>(it); 438 smtp = static_cast<SMTPaccount *>(it);
439 if ( smtp->getMail().compare( from ) == 0 ) { 439 if ( smtp->getMail().compare( from ) == 0 ) {
440 qDebug( "SMTPaccount found for" ); 440 qDebug( "SMTPaccount found for" );
441 qDebug( from ); 441 qDebug( from );
442 return smtp; 442 return smtp;
443 } 443 }
444 } 444 }
445 } 445 }
446 446
447 return NULL; 447 return NULL;
448} 448}
449 449
450QString MailWrapper::getTmpFile() { 450QString MailWrapper::getTmpFile() {
451 int num = 0; 451 int num = 0;
452 QString unique; 452 QString unique;
453 453
454 QDir dir( "/tmp" ); 454 QDir dir( "/tmp" );
455 QStringList::Iterator it; 455 QStringList::Iterator it;
456 456
457 QStringList list = dir.entryList( "opiemail-tmp-*" ); 457 QStringList list = dir.entryList( "opiemail-tmp-*" );
458 do { 458 do {
459 unique.setNum( num++ ); 459 unique.setNum( num++ );
460 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); 460 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 );
461 461
462 return "/tmp/opiemail-tmp-" + unique; 462 return "/tmp/opiemail-tmp-" + unique;
463} 463}
464 464
465void MailWrapper::writeToFile( QString file, mailmime *mail ) 465void MailWrapper::writeToFile( QString file, mailmime *mail )
466{ 466{
467 FILE *f; 467 FILE *f;
468 int err, col = 0; 468 int err, col = 0;
469 469
470 f = fopen( file.latin1(), "w" ); 470 f = fopen( file.latin1(), "w" );
471 if ( f == NULL ) { 471 if ( f == NULL ) {
472 qDebug( "writeToFile: error opening file" ); 472 qDebug( "writeToFile: error opening file" );
473 return; 473 return;
474 } 474 }
475 475
476 err = mailmime_write( f, &col, mail ); 476 err = mailmime_write( f, &col, mail );
477 if ( err != MAILIMF_NO_ERROR ) { 477 if ( err != MAILIMF_NO_ERROR ) {
478 fclose( f ); 478 fclose( f );
479 qDebug( "writeToFile: error writing mailmime" ); 479 qDebug( "writeToFile: error writing mailmime" );
480 return; 480 return;
481 } 481 }
482 482
483 fclose( f ); 483 fclose( f );
484} 484}
485 485
486void MailWrapper::readFromFile( QString file, char **data, size_t *size ) 486void MailWrapper::readFromFile( QString file, char **data, size_t *size )
487{ 487{
488 char *buf; 488 char *buf;
489 struct stat st; 489 struct stat st;
490 int fd, count = 0, total = 0; 490 int fd, count = 0, total = 0;
491 491
492 fd = open( file.latin1(), O_RDONLY, 0 ); 492 fd = open( file.latin1(), O_RDONLY, 0 );
493 if ( fd == -1 ) return; 493 if ( fd == -1 ) return;
494 494
495 if ( fstat( fd, &st ) != 0 ) goto err_close; 495 if ( fstat( fd, &st ) != 0 ) goto err_close;
496 if ( !st.st_size ) goto err_close; 496 if ( !st.st_size ) goto err_close;
497 497
498 buf = (char *) malloc( st.st_size ); 498 buf = (char *) malloc( st.st_size );
499 if ( !buf ) goto err_close; 499 if ( !buf ) goto err_close;
500 500
501 while ( ( total < st.st_size ) && ( count >= 0 ) ) { 501 while ( ( total < st.st_size ) && ( count >= 0 ) ) {
502 count = read( fd, buf + total, st.st_size - total ); 502 count = read( fd, buf + total, st.st_size - total );
503 total += count; 503 total += count;
504 } 504 }
505 if ( count < 0 ) goto err_free; 505 if ( count < 0 ) goto err_free;
506 506
507 *data = buf; 507 *data = buf;
508 *size = st.st_size; 508 *size = st.st_size;
509 509
510 close( fd ); 510 close( fd );
511 511
512 return; // Success :) 512 return; // Success :)
513 513
514err_free: 514err_free:
515 free( buf ); 515 free( buf );
516err_close: 516err_close:
517 close( fd ); 517 close( fd );
518} 518}
519 519
520void progress( size_t current, size_t maximum ) 520void progress( size_t current, size_t maximum )
521{ 521{
522 qDebug( "Current: %i of %i", current, maximum ); 522 qDebug( "Current: %i of %i", current, maximum );
523} 523}
524 524
525void MailWrapper::smtpSend( mailmime *mail ) 525void MailWrapper::smtpSend( mailmime *mail )
526{ 526{
527 mailsmtp *session; 527 mailsmtp *session;
528 clist *rcpts; 528 clist *rcpts;
529 char *from, *data, *server, *user = NULL, *pass = NULL; 529 char *from, *data, *server, *user = NULL, *pass = NULL;
530 size_t size; 530 size_t size;
531 int err; 531 int err;
532 bool ssl; 532 bool ssl;
533 uint16_t port; 533 uint16_t port;
534 534
535 535
536 from = getFrom( mail ); 536 from = getFrom( mail );
537 SMTPaccount *smtp = getAccount( from ); 537 SMTPaccount *smtp = getAccount( from );
538 if ( smtp == NULL ) { 538 if ( smtp == NULL ) {
539 free(from); 539 free(from);
540 return; 540 return;
541 } 541 }
542 server = strdup( smtp->getServer().latin1() ); 542 server = strdup( smtp->getServer().latin1() );
543 ssl = smtp->getSSL(); 543 ssl = smtp->getSSL();
544 port = smtp->getPort().toUInt(); 544 port = smtp->getPort().toUInt();
545 rcpts = createRcptList( mail->fields ); 545 rcpts = createRcptList( mail->fields );
546 546
547 QString file = getTmpFile(); 547 QString file = getTmpFile();
548 writeToFile( file, mail ); 548 writeToFile( file, mail );
549 readFromFile( file, &data, &size ); 549 readFromFile( file, &data, &size );
550 QFile f( file ); 550 QFile f( file );
551 f.remove(); 551 f.remove();
552 552
553 session = mailsmtp_new( 20, &progress ); 553 session = mailsmtp_new( 20, &progress );
554 if ( session == NULL ) goto free_mem; 554 if ( session == NULL ) goto free_mem;
555 555
556 qDebug( "Servername %s at port %i", server, port ); 556 qDebug( "Servername %s at port %i", server, port );
557 if ( ssl ) { 557 if ( ssl ) {
558 qDebug( "SSL session" ); 558 qDebug( "SSL session" );
559 err = mailsmtp_ssl_connect( session, server, port ); 559 err = mailsmtp_ssl_connect( session, server, port );
560 } else { 560 } else {
561 qDebug( "No SSL session" ); 561 qDebug( "No SSL session" );
562 err = mailsmtp_socket_connect( session, server, port ); 562 err = mailsmtp_socket_connect( session, server, port );
563 } 563 }
564 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; 564 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session;
565 565
566 err = mailsmtp_init( session ); 566 err = mailsmtp_init( session );
567 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; 567 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session;
568 568
569 qDebug( "INIT OK" ); 569 qDebug( "INIT OK" );
570 570
571 if ( smtp->getLogin() ) { 571 if ( smtp->getLogin() ) {
572 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 572 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
573 // get'em 573 // get'em
574 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 574 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
575 login.show(); 575 login.show();
576 if ( QDialog::Accepted == login.exec() ) { 576 if ( QDialog::Accepted == login.exec() ) {
577 // ok 577 // ok
578 user = strdup( login.getUser().latin1() ); 578 user = strdup( login.getUser().latin1() );
579 pass = strdup( login.getPassword().latin1() ); 579 pass = strdup( login.getPassword().latin1() );
580 } else { 580 } else {
581 goto free_con_session; 581 goto free_con_session;
582 } 582 }
583 } else { 583 } else {
584 user = strdup( smtp->getUser().latin1() ); 584 user = strdup( smtp->getUser().latin1() );
585 pass = strdup( smtp->getPassword().latin1() ); 585 pass = strdup( smtp->getPassword().latin1() );
586 } 586 }
587 qDebug( "session->auth: %i", session->auth); 587 qDebug( "session->auth: %i", session->auth);
588 err = mailsmtp_auth( session, user, pass ); 588 err = mailsmtp_auth( session, user, pass );
589 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); 589 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
590 qDebug( "Done auth!" ); 590 qDebug( "Done auth!" );
591 } 591 }
592 592
593 err = mailsmtp_send( session, from, rcpts, data, size ); 593 err = mailsmtp_send( session, from, rcpts, data, size );
594 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; 594 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session;
595 595
596 qDebug( "Mail sent." ); 596 qDebug( "Mail sent." );
597 597
598free_con_session: 598free_con_session:
599 mailsmtp_quit( session ); 599 mailsmtp_quit( session );
600free_mem_session: 600free_mem_session:
601 mailsmtp_free( session ); 601 mailsmtp_free( session );
602free_mem: 602free_mem:
603 smtp_address_list_free( rcpts ); 603 smtp_address_list_free( rcpts );
604 free( data ); 604 free( data );
605 free( server ); 605 free( server );
606 if ( smtp->getLogin() ) { 606 if ( smtp->getLogin() ) {
607 free( user ); 607 free( user );
608 free( pass ); 608 free( pass );
609 } 609 }
610 free( from ); 610 free( from );
611} 611}
612 612
613void MailWrapper::sendMail( Mail mail ) 613void MailWrapper::sendMail( Mail mail )
614{ 614{
615 mailmime *mimeMail; 615 mailmime *mimeMail;
616 616
617 mimeMail = createMimeMail( &mail ); 617 mimeMail = createMimeMail( &mail );
618 if ( mimeMail == NULL ) { 618 if ( mimeMail == NULL ) {
619 qDebug( "sendMail: error creating mime mail" ); 619 qDebug( "sendMail: error creating mime mail" );
620 } else { 620 } else {
621 smtpSend( mimeMail ); 621 smtpSend( mimeMail );
622 mailmime_free( mimeMail ); 622 mailmime_free( mimeMail );
623 } 623 }
624} 624}
625 625
626Mail::Mail() 626Mail::Mail()
627 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") 627 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
628{ 628{
629} 629}
630 630
631RecMail::RecMail() 631RecMail::RecMail()
632 :subject(""),date(""),msg_number(0),msg_flags(7) 632 :subject(""),date(""),mbox(""),msg_number(0),msg_flags(7)
633{ 633{
634} 634}
635 635
636#if 0 636#if 0
637void RecMail::setDate(const QString&aDate) 637void RecMail::setDate(const QString&aDate)
638{ 638{
639 mDate = QDateTime::fromString(aDate); 639 mDate = QDateTime::fromString(aDate);
640} 640}
641#endif 641#endif
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h
index 955a8e2..332034f 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.h
@@ -1,164 +1,177 @@
1#ifndef MAILWRAPPER_H 1#ifndef MAILWRAPPER_H
2#define MAILWRAPPER_H 2#define MAILWRAPPER_H
3 3
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5 5
6#include <libetpan/mailmime.h> 6#include <libetpan/mailmime.h>
7#include <libetpan/mailimf.h> 7#include <libetpan/mailimf.h>
8#include <libetpan/mailsmtp.h> 8#include <libetpan/mailsmtp.h>
9#include <libetpan/mailstorage.h> 9#include <libetpan/mailstorage.h>
10#include <libetpan/maildriver.h> 10#include <libetpan/maildriver.h>
11#include <qbitarray.h> 11#include <qbitarray.h>
12#include <qdatetime.h> 12#include <qdatetime.h>
13 13
14#include "settings.h" 14#include "settings.h"
15 15
16class Attachment 16class Attachment
17{ 17{
18public: 18public:
19 Attachment( DocLnk lnk ); 19 Attachment( DocLnk lnk );
20 virtual ~Attachment(){} 20 virtual ~Attachment(){}
21 const QString getFileName()const{ return doc.file(); } 21 const QString getFileName()const{ return doc.file(); }
22 const QString getName()const{ return doc.name(); } 22 const QString getName()const{ return doc.name(); }
23 const QString getMimeType()const{ return doc.type(); } 23 const QString getMimeType()const{ return doc.type(); }
24 const QPixmap getPixmap()const{ return doc.pixmap(); } 24 const QPixmap getPixmap()const{ return doc.pixmap(); }
25 const int getSize()const { return size; } 25 const int getSize()const { return size; }
26 DocLnk getDocLnk() { return doc; } 26 DocLnk getDocLnk() { return doc; }
27 27
28protected: 28protected:
29 DocLnk doc; 29 DocLnk doc;
30 int size; 30 int size;
31 31
32}; 32};
33 33
34#define FLAG_ANSWERED 0 34#define FLAG_ANSWERED 0
35#define FLAG_FLAGGED 1 35#define FLAG_FLAGGED 1
36#define FLAG_DELETED 2 36#define FLAG_DELETED 2
37#define FLAG_SEEN 3 37#define FLAG_SEEN 3
38#define FLAG_DRAFT 4 38#define FLAG_DRAFT 4
39#define FLAG_RECENT 5 39#define FLAG_RECENT 5
40 40
41/* a class to describe mails in a mailbox */ 41/* a class to describe mails in a mailbox */
42/* Attention!
43 From programmers point of view it would make sense to
44 store the mail body into this class, too.
45 But: not from the point of view of the device.
46 Mailbodies can be real large. So we request them when
47 needed from the mail-wrapper class direct from the server itself
48 (imap) or from a file-based cache (pop3?)
49 So there is no interface "const QString&body()" but you should
50 make a request to the mailwrapper with this class as parameter to
51 get the body. Same words for the attachments.
52*/
42class RecMail 53class RecMail
43{ 54{
44public: 55public:
45 RecMail(); 56 RecMail();
46 virtual ~RecMail(){} 57 virtual ~RecMail(){}
47 58
48 const int getNumber()const{return msg_number;} 59 const int getNumber()const{return msg_number;}
49 void setNumber(int number){msg_number=number;} 60 void setNumber(int number){msg_number=number;}
50 const QString&getDate()const{ return date; } 61 const QString&getDate()const{ return date; }
51 void setDate( const QString&a ) { date = a; } 62 void setDate( const QString&a ) { date = a; }
52 const QString&getFrom()const{ return from; } 63 const QString&getFrom()const{ return from; }
53 void setFrom( const QString&a ) { from = a; } 64 void setFrom( const QString&a ) { from = a; }
54 const QString&getSubject()const { return subject; } 65 const QString&getSubject()const { return subject; }
55 void setSubject( const QString&s ) { subject = s; } 66 void setSubject( const QString&s ) { subject = s; }
56 void setFlags(const QBitArray&flags){msg_flags = flags;} 67 const QString&getMbox()const{return mbox;}
68 void setMbox(const QString&box){mbox = box;}
57 const QBitArray&getFlags()const{return msg_flags;} 69 const QBitArray&getFlags()const{return msg_flags;}
70 void setFlags(const QBitArray&flags){msg_flags = flags;}
58 71
59#if 0 72#if 0
60 void setDate(const QString&dstring); 73 void setDate(const QString&dstring);
61 void setDate(const QDateTime&date){mDate = date;} 74 void setDate(const QDateTime&date){mDate = date;}
62 QString getDate()const{return mDate.toString();} 75 QString getDate()const{return mDate.toString();}
63#endif 76#endif
64protected: 77protected:
65 QString subject,date,from; 78 QString subject,date,from,mbox;
66 int msg_number; 79 int msg_number;
67 QBitArray msg_flags; 80 QBitArray msg_flags;
68#if 0 81#if 0
69 QDateTime mDate; 82 QDateTime mDate;
70#endif 83#endif
71}; 84};
72 85
73typedef QList<RecMail> Maillist; 86typedef QList<RecMail> Maillist;
74 87
75class Mail 88class Mail
76{ 89{
77public: 90public:
78 Mail(); 91 Mail();
79 /* Possible that this destructor must not be declared virtual 92 /* Possible that this destructor must not be declared virtual
80 * 'cause it seems that it will never have some child classes. 93 * 'cause it seems that it will never have some child classes.
81 * in this case this object will not get a virtual table -> memory and 94 * in this case this object will not get a virtual table -> memory and
82 * speed will be a little bit better? 95 * speed will be a little bit better?
83 */ 96 */
84 virtual ~Mail(){} 97 virtual ~Mail(){}
85 void addAttachment( Attachment *att ) { attList.append( att ); } 98 void addAttachment( Attachment *att ) { attList.append( att ); }
86 const QList<Attachment>& getAttachments()const { return attList; } 99 const QList<Attachment>& getAttachments()const { return attList; }
87 void removeAttachment( Attachment *att ) { attList.remove( att ); } 100 void removeAttachment( Attachment *att ) { attList.remove( att ); }
88 const QString&getName()const { return name; } 101 const QString&getName()const { return name; }
89 void setName( QString s ) { name = s; } 102 void setName( QString s ) { name = s; }
90 const QString&getMail()const{ return mail; } 103 const QString&getMail()const{ return mail; }
91 void setMail( const QString&s ) { mail = s; } 104 void setMail( const QString&s ) { mail = s; }
92 const QString&getTo()const{ return to; } 105 const QString&getTo()const{ return to; }
93 void setTo( const QString&s ) { to = s; } 106 void setTo( const QString&s ) { to = s; }
94 const QString&getCC()const{ return cc; } 107 const QString&getCC()const{ return cc; }
95 void setCC( const QString&s ) { cc = s; } 108 void setCC( const QString&s ) { cc = s; }
96 const QString&getBCC()const { return bcc; } 109 const QString&getBCC()const { return bcc; }
97 void setBCC( const QString&s ) { bcc = s; } 110 void setBCC( const QString&s ) { bcc = s; }
98 const QString&getMessage()const { return message; } 111 const QString&getMessage()const { return message; }
99 void setMessage( const QString&s ) { message = s; } 112 void setMessage( const QString&s ) { message = s; }
100 const QString&getSubject()const { return subject; } 113 const QString&getSubject()const { return subject; }
101 void setSubject( const QString&s ) { subject = s; } 114 void setSubject( const QString&s ) { subject = s; }
102 const QString&getReply()const{ return reply; } 115 const QString&getReply()const{ return reply; }
103 void setReply( const QString&a ) { reply = a; } 116 void setReply( const QString&a ) { reply = a; }
104 117
105private: 118private:
106 QList<Attachment> attList; 119 QList<Attachment> attList;
107 QString name, mail, to, cc, bcc, reply, subject, message; 120 QString name, mail, to, cc, bcc, reply, subject, message;
108}; 121};
109 122
110class Folder : public QObject 123class Folder : public QObject
111{ 124{
112 Q_OBJECT 125 Q_OBJECT
113 126
114public: 127public:
115 Folder( const QString&init_name ); 128 Folder( const QString&init_name );
116 const QString&getDisplayName()const { return nameDisplay; } 129 const QString&getDisplayName()const { return nameDisplay; }
117 const QString&getName()const { return name; } 130 const QString&getName()const { return name; }
118 virtual bool may_select()const{return true;}; 131 virtual bool may_select()const{return true;};
119 132
120private: 133private:
121 QString nameDisplay, name; 134 QString nameDisplay, name;
122 135
123}; 136};
124 137
125class IMAPFolder : public Folder 138class IMAPFolder : public Folder
126{ 139{
127 public: 140 public:
128 IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} 141 IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {}
129 virtual bool may_select()const{return m_MaySelect;} 142 virtual bool may_select()const{return m_MaySelect;}
130 private: 143 private:
131 bool m_MaySelect; 144 bool m_MaySelect;
132}; 145};
133 146
134class MailWrapper : public QObject 147class MailWrapper : public QObject
135{ 148{
136 Q_OBJECT 149 Q_OBJECT
137 150
138public: 151public:
139 MailWrapper( Settings *s ); 152 MailWrapper( Settings *s );
140 void sendMail( Mail mail ); 153 void sendMail( Mail mail );
141 154
142private: 155private:
143 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 156 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
144 mailimf_address_list *parseAddresses(const QString&addr ); 157 mailimf_address_list *parseAddresses(const QString&addr );
145 mailimf_fields *createImfFields( Mail *mail ); 158 mailimf_fields *createImfFields( Mail *mail );
146 mailmime *buildTxtPart( QString str ); 159 mailmime *buildTxtPart( QString str );
147 mailmime *buildFilePart( QString filename, QString mimetype ); 160 mailmime *buildFilePart( QString filename, QString mimetype );
148 void addFileParts( mailmime *message, QList<Attachment> files ); 161 void addFileParts( mailmime *message, QList<Attachment> files );
149 mailmime *createMimeMail( Mail *mail ); 162 mailmime *createMimeMail( Mail *mail );
150 void smtpSend( mailmime *mail ); 163 void smtpSend( mailmime *mail );
151 mailimf_field *getField( mailimf_fields *fields, int type ); 164 mailimf_field *getField( mailimf_fields *fields, int type );
152 clist *createRcptList( mailimf_fields *fields ); 165 clist *createRcptList( mailimf_fields *fields );
153 char *getFrom( mailmime *mail ); 166 char *getFrom( mailmime *mail );
154 SMTPaccount *getAccount( QString from ); 167 SMTPaccount *getAccount( QString from );
155 void writeToFile( QString file, mailmime *mail ); 168 void writeToFile( QString file, mailmime *mail );
156 void readFromFile( QString file, char **data, size_t *size ); 169 void readFromFile( QString file, char **data, size_t *size );
157 static QString mailsmtpError( int err ); 170 static QString mailsmtpError( int err );
158 static QString getTmpFile(); 171 static QString getTmpFile();
159 172
160 Settings *settings; 173 Settings *settings;
161 174
162}; 175};
163 176
164#endif 177#endif
diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp
index ea9e7b2..7f67cd8 100644
--- a/noncore/net/mail/mailwrapper.cpp
+++ b/noncore/net/mail/mailwrapper.cpp
@@ -248,394 +248,394 @@ mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype )
248 content = mailmime_content_new_with_str( mime ); 248 content = mailmime_content_new_with_str( mime );
249 if ( content == NULL ) goto err_free_fields; 249 if ( content == NULL ) goto err_free_fields;
250 250
251 if ( mimetype.compare( "text/plain" ) == 0 ) { 251 if ( mimetype.compare( "text/plain" ) == 0 ) {
252 param = mailmime_parameter_new( strdup( "charset" ), 252 param = mailmime_parameter_new( strdup( "charset" ),
253 strdup( "iso-8859-1" ) ); 253 strdup( "iso-8859-1" ) );
254 if ( param == NULL ) goto err_free_content; 254 if ( param == NULL ) goto err_free_content;
255 255
256 err = clist_append( content->parameters, param ); 256 err = clist_append( content->parameters, param );
257 if ( err != MAILIMF_NO_ERROR ) goto err_free_param; 257 if ( err != MAILIMF_NO_ERROR ) goto err_free_param;
258 } 258 }
259 259
260 filePart = mailmime_new_empty( content, fields ); 260 filePart = mailmime_new_empty( content, fields );
261 if ( filePart == NULL ) goto err_free_param; 261 if ( filePart == NULL ) goto err_free_param;
262 262
263 err = mailmime_set_body_file( filePart, file ); 263 err = mailmime_set_body_file( filePart, file );
264 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; 264 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
265 265
266 return filePart; // Success :) 266 return filePart; // Success :)
267 267
268err_free_filePart: 268err_free_filePart:
269 mailmime_free( filePart ); 269 mailmime_free( filePart );
270err_free_param: 270err_free_param:
271 if ( param != NULL ) mailmime_parameter_free( param ); 271 if ( param != NULL ) mailmime_parameter_free( param );
272err_free_content: 272err_free_content:
273 mailmime_content_free( content ); 273 mailmime_content_free( content );
274err_free_fields: 274err_free_fields:
275 mailmime_fields_free( fields ); 275 mailmime_fields_free( fields );
276err_free: 276err_free:
277 free( name ); 277 free( name );
278 free( mime ); 278 free( mime );
279 free( file ); 279 free( file );
280 qDebug( "buildFilePart - error" ); 280 qDebug( "buildFilePart - error" );
281 281
282 return NULL; // Error :( 282 return NULL; // Error :(
283} 283}
284 284
285void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) 285void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files )
286{ 286{
287 Attachment *it; 287 Attachment *it;
288 for ( it = files.first(); it; it = files.next() ) { 288 for ( it = files.first(); it; it = files.next() ) {
289 qDebug( "Adding file" ); 289 qDebug( "Adding file" );
290 mailmime *filePart; 290 mailmime *filePart;
291 int err; 291 int err;
292 292
293 filePart = buildFilePart( it->getFileName(), it->getMimeType() ); 293 filePart = buildFilePart( it->getFileName(), it->getMimeType() );
294 if ( filePart == NULL ) goto err_free; 294 if ( filePart == NULL ) goto err_free;
295 295
296 err = mailmime_smart_add_part( message, filePart ); 296 err = mailmime_smart_add_part( message, filePart );
297 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; 297 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
298 298
299 continue; // Success :) 299 continue; // Success :)
300 300
301 err_free_filePart: 301 err_free_filePart:
302 mailmime_free( filePart ); 302 mailmime_free( filePart );
303 err_free: 303 err_free:
304 qDebug( "addFileParts: error adding file:" ); 304 qDebug( "addFileParts: error adding file:" );
305 qDebug( it->getFileName() ); 305 qDebug( it->getFileName() );
306 } 306 }
307} 307}
308 308
309mailmime *MailWrapper::createMimeMail( Mail *mail ) 309mailmime *MailWrapper::createMimeMail( Mail *mail )
310{ 310{
311 mailmime *message, *txtPart; 311 mailmime *message, *txtPart;
312 mailimf_fields *fields; 312 mailimf_fields *fields;
313 int err; 313 int err;
314 314
315 fields = createImfFields( mail ); 315 fields = createImfFields( mail );
316 if ( fields == NULL ) goto err_free; 316 if ( fields == NULL ) goto err_free;
317 317
318 message = mailmime_new_message_data( NULL ); 318 message = mailmime_new_message_data( NULL );
319 if ( message == NULL ) goto err_free_fields; 319 if ( message == NULL ) goto err_free_fields;
320 320
321 mailmime_set_imf_fields( message, fields ); 321 mailmime_set_imf_fields( message, fields );
322 322
323 txtPart = buildTxtPart( mail->getMessage() ); 323 txtPart = buildTxtPart( mail->getMessage() );
324 if ( txtPart == NULL ) goto err_free_message; 324 if ( txtPart == NULL ) goto err_free_message;
325 325
326 err = mailmime_smart_add_part( message, txtPart ); 326 err = mailmime_smart_add_part( message, txtPart );
327 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 327 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
328 328
329 addFileParts( message, mail->getAttachments() ); 329 addFileParts( message, mail->getAttachments() );
330 330
331 return message; // Success :) 331 return message; // Success :)
332 332
333err_free_txtPart: 333err_free_txtPart:
334 mailmime_free( txtPart ); 334 mailmime_free( txtPart );
335err_free_message: 335err_free_message:
336 mailmime_free( message ); 336 mailmime_free( message );
337err_free_fields: 337err_free_fields:
338 mailimf_fields_free( fields ); 338 mailimf_fields_free( fields );
339err_free: 339err_free:
340 qDebug( "createMimeMail: error" ); 340 qDebug( "createMimeMail: error" );
341 341
342 return NULL; // Error :( 342 return NULL; // Error :(
343} 343}
344 344
345mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) 345mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type )
346{ 346{
347 mailimf_field *field; 347 mailimf_field *field;
348 clistiter *it; 348 clistiter *it;
349 349
350 it = clist_begin( fields->list ); 350 it = clist_begin( fields->list );
351 while ( it ) { 351 while ( it ) {
352 field = (mailimf_field *) it->data; 352 field = (mailimf_field *) it->data;
353 if ( field->type == type ) { 353 if ( field->type == type ) {
354 return field; 354 return field;
355 } 355 }
356 it = it->next; 356 it = it->next;
357 } 357 }
358 358
359 return NULL; 359 return NULL;
360} 360}
361 361
362static void addRcpts( clist *list, mailimf_address_list *addr_list ) 362static void addRcpts( clist *list, mailimf_address_list *addr_list )
363{ 363{
364 clistiter *it, *it2; 364 clistiter *it, *it2;
365 365
366 for ( it = clist_begin( addr_list->list ); it; it = it->next ) { 366 for ( it = clist_begin( addr_list->list ); it; it = it->next ) {
367 mailimf_address *addr; 367 mailimf_address *addr;
368 addr = (mailimf_address *) it->data; 368 addr = (mailimf_address *) it->data;
369 369
370 if ( addr->type == MAILIMF_ADDRESS_MAILBOX ) { 370 if ( addr->type == MAILIMF_ADDRESS_MAILBOX ) {
371 esmtp_address_list_add( list, addr->mailbox->addr_spec, 0, NULL ); 371 esmtp_address_list_add( list, addr->mailbox->addr_spec, 0, NULL );
372 } else if ( addr->type == MAILIMF_ADDRESS_GROUP ) { 372 } else if ( addr->type == MAILIMF_ADDRESS_GROUP ) {
373 clist *l = addr->group->mb_list->list; 373 clist *l = addr->group->mb_list->list;
374 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { 374 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
375 mailimf_mailbox *mbox; 375 mailimf_mailbox *mbox;
376 mbox = (mailimf_mailbox *) it2->data; 376 mbox = (mailimf_mailbox *) it2->data;
377 esmtp_address_list_add( list, mbox->addr_spec, 0, NULL ); 377 esmtp_address_list_add( list, mbox->addr_spec, 0, NULL );
378 } 378 }
379 } 379 }
380 } 380 }
381} 381}
382 382
383clist *MailWrapper::createRcptList( mailimf_fields *fields ) 383clist *MailWrapper::createRcptList( mailimf_fields *fields )
384{ 384{
385 clist *rcptList; 385 clist *rcptList;
386 mailimf_field *field; 386 mailimf_field *field;
387 387
388 rcptList = esmtp_address_list_new(); 388 rcptList = esmtp_address_list_new();
389 389
390 field = getField( fields, MAILIMF_FIELD_TO ); 390 field = getField( fields, MAILIMF_FIELD_TO );
391 if ( field && (field->type == MAILIMF_FIELD_TO) 391 if ( field && (field->type == MAILIMF_FIELD_TO)
392 && field->field.to->addr_list ) { 392 && field->field.to->addr_list ) {
393 addRcpts( rcptList, field->field.to->addr_list ); 393 addRcpts( rcptList, field->field.to->addr_list );
394 } 394 }
395 395
396 field = getField( fields, MAILIMF_FIELD_CC ); 396 field = getField( fields, MAILIMF_FIELD_CC );
397 if ( field && (field->type == MAILIMF_FIELD_CC) 397 if ( field && (field->type == MAILIMF_FIELD_CC)
398 && field->field.cc->addr_list ) { 398 && field->field.cc->addr_list ) {
399 addRcpts( rcptList, field->field.cc->addr_list ); 399 addRcpts( rcptList, field->field.cc->addr_list );
400 } 400 }
401 401
402 field = getField( fields, MAILIMF_FIELD_BCC ); 402 field = getField( fields, MAILIMF_FIELD_BCC );
403 if ( field && (field->type == MAILIMF_FIELD_BCC) 403 if ( field && (field->type == MAILIMF_FIELD_BCC)
404 && field->field.bcc->addr_list ) { 404 && field->field.bcc->addr_list ) {
405 addRcpts( rcptList, field->field.bcc->addr_list ); 405 addRcpts( rcptList, field->field.bcc->addr_list );
406 } 406 }
407 407
408 return rcptList; 408 return rcptList;
409} 409}
410 410
411char *MailWrapper::getFrom( mailmime *mail ) 411char *MailWrapper::getFrom( mailmime *mail )
412{ 412{
413 char *from = NULL; 413 char *from = NULL;
414 414
415 mailimf_field *ffrom; 415 mailimf_field *ffrom;
416 ffrom = getField( mail->fields, MAILIMF_FIELD_FROM ); 416 ffrom = getField( mail->fields, MAILIMF_FIELD_FROM );
417 if ( ffrom && (ffrom->type == MAILIMF_FIELD_FROM) 417 if ( ffrom && (ffrom->type == MAILIMF_FIELD_FROM)
418 && ffrom->field.from->mb_list && ffrom->field.from->mb_list->list ) { 418 && ffrom->field.from->mb_list && ffrom->field.from->mb_list->list ) {
419 clist *cl = ffrom->field.from->mb_list->list; 419 clist *cl = ffrom->field.from->mb_list->list;
420 clistiter *it; 420 clistiter *it;
421 for ( it = clist_begin( cl ); it; it = it->next ) { 421 for ( it = clist_begin( cl ); it; it = it->next ) {
422 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 422 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
423 from = strdup( mb->addr_spec ); 423 from = strdup( mb->addr_spec );
424 } 424 }
425 } 425 }
426 426
427 return from; 427 return from;
428} 428}
429 429
430SMTPaccount *MailWrapper::getAccount( QString from ) 430SMTPaccount *MailWrapper::getAccount( QString from )
431{ 431{
432 SMTPaccount *smtp; 432 SMTPaccount *smtp;
433 433
434 QList<Account> list = settings->getAccounts(); 434 QList<Account> list = settings->getAccounts();
435 Account *it; 435 Account *it;
436 for ( it = list.first(); it; it = list.next() ) { 436 for ( it = list.first(); it; it = list.next() ) {
437 if ( it->getType().compare( "SMTP" ) == 0 ) { 437 if ( it->getType().compare( "SMTP" ) == 0 ) {
438 smtp = static_cast<SMTPaccount *>(it); 438 smtp = static_cast<SMTPaccount *>(it);
439 if ( smtp->getMail().compare( from ) == 0 ) { 439 if ( smtp->getMail().compare( from ) == 0 ) {
440 qDebug( "SMTPaccount found for" ); 440 qDebug( "SMTPaccount found for" );
441 qDebug( from ); 441 qDebug( from );
442 return smtp; 442 return smtp;
443 } 443 }
444 } 444 }
445 } 445 }
446 446
447 return NULL; 447 return NULL;
448} 448}
449 449
450QString MailWrapper::getTmpFile() { 450QString MailWrapper::getTmpFile() {
451 int num = 0; 451 int num = 0;
452 QString unique; 452 QString unique;
453 453
454 QDir dir( "/tmp" ); 454 QDir dir( "/tmp" );
455 QStringList::Iterator it; 455 QStringList::Iterator it;
456 456
457 QStringList list = dir.entryList( "opiemail-tmp-*" ); 457 QStringList list = dir.entryList( "opiemail-tmp-*" );
458 do { 458 do {
459 unique.setNum( num++ ); 459 unique.setNum( num++ );
460 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); 460 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 );
461 461
462 return "/tmp/opiemail-tmp-" + unique; 462 return "/tmp/opiemail-tmp-" + unique;
463} 463}
464 464
465void MailWrapper::writeToFile( QString file, mailmime *mail ) 465void MailWrapper::writeToFile( QString file, mailmime *mail )
466{ 466{
467 FILE *f; 467 FILE *f;
468 int err, col = 0; 468 int err, col = 0;
469 469
470 f = fopen( file.latin1(), "w" ); 470 f = fopen( file.latin1(), "w" );
471 if ( f == NULL ) { 471 if ( f == NULL ) {
472 qDebug( "writeToFile: error opening file" ); 472 qDebug( "writeToFile: error opening file" );
473 return; 473 return;
474 } 474 }
475 475
476 err = mailmime_write( f, &col, mail ); 476 err = mailmime_write( f, &col, mail );
477 if ( err != MAILIMF_NO_ERROR ) { 477 if ( err != MAILIMF_NO_ERROR ) {
478 fclose( f ); 478 fclose( f );
479 qDebug( "writeToFile: error writing mailmime" ); 479 qDebug( "writeToFile: error writing mailmime" );
480 return; 480 return;
481 } 481 }
482 482
483 fclose( f ); 483 fclose( f );
484} 484}
485 485
486void MailWrapper::readFromFile( QString file, char **data, size_t *size ) 486void MailWrapper::readFromFile( QString file, char **data, size_t *size )
487{ 487{
488 char *buf; 488 char *buf;
489 struct stat st; 489 struct stat st;
490 int fd, count = 0, total = 0; 490 int fd, count = 0, total = 0;
491 491
492 fd = open( file.latin1(), O_RDONLY, 0 ); 492 fd = open( file.latin1(), O_RDONLY, 0 );
493 if ( fd == -1 ) return; 493 if ( fd == -1 ) return;
494 494
495 if ( fstat( fd, &st ) != 0 ) goto err_close; 495 if ( fstat( fd, &st ) != 0 ) goto err_close;
496 if ( !st.st_size ) goto err_close; 496 if ( !st.st_size ) goto err_close;
497 497
498 buf = (char *) malloc( st.st_size ); 498 buf = (char *) malloc( st.st_size );
499 if ( !buf ) goto err_close; 499 if ( !buf ) goto err_close;
500 500
501 while ( ( total < st.st_size ) && ( count >= 0 ) ) { 501 while ( ( total < st.st_size ) && ( count >= 0 ) ) {
502 count = read( fd, buf + total, st.st_size - total ); 502 count = read( fd, buf + total, st.st_size - total );
503 total += count; 503 total += count;
504 } 504 }
505 if ( count < 0 ) goto err_free; 505 if ( count < 0 ) goto err_free;
506 506
507 *data = buf; 507 *data = buf;
508 *size = st.st_size; 508 *size = st.st_size;
509 509
510 close( fd ); 510 close( fd );
511 511
512 return; // Success :) 512 return; // Success :)
513 513
514err_free: 514err_free:
515 free( buf ); 515 free( buf );
516err_close: 516err_close:
517 close( fd ); 517 close( fd );
518} 518}
519 519
520void progress( size_t current, size_t maximum ) 520void progress( size_t current, size_t maximum )
521{ 521{
522 qDebug( "Current: %i of %i", current, maximum ); 522 qDebug( "Current: %i of %i", current, maximum );
523} 523}
524 524
525void MailWrapper::smtpSend( mailmime *mail ) 525void MailWrapper::smtpSend( mailmime *mail )
526{ 526{
527 mailsmtp *session; 527 mailsmtp *session;
528 clist *rcpts; 528 clist *rcpts;
529 char *from, *data, *server, *user = NULL, *pass = NULL; 529 char *from, *data, *server, *user = NULL, *pass = NULL;
530 size_t size; 530 size_t size;
531 int err; 531 int err;
532 bool ssl; 532 bool ssl;
533 uint16_t port; 533 uint16_t port;
534 534
535 535
536 from = getFrom( mail ); 536 from = getFrom( mail );
537 SMTPaccount *smtp = getAccount( from ); 537 SMTPaccount *smtp = getAccount( from );
538 if ( smtp == NULL ) { 538 if ( smtp == NULL ) {
539 free(from); 539 free(from);
540 return; 540 return;
541 } 541 }
542 server = strdup( smtp->getServer().latin1() ); 542 server = strdup( smtp->getServer().latin1() );
543 ssl = smtp->getSSL(); 543 ssl = smtp->getSSL();
544 port = smtp->getPort().toUInt(); 544 port = smtp->getPort().toUInt();
545 rcpts = createRcptList( mail->fields ); 545 rcpts = createRcptList( mail->fields );
546 546
547 QString file = getTmpFile(); 547 QString file = getTmpFile();
548 writeToFile( file, mail ); 548 writeToFile( file, mail );
549 readFromFile( file, &data, &size ); 549 readFromFile( file, &data, &size );
550 QFile f( file ); 550 QFile f( file );
551 f.remove(); 551 f.remove();
552 552
553 session = mailsmtp_new( 20, &progress ); 553 session = mailsmtp_new( 20, &progress );
554 if ( session == NULL ) goto free_mem; 554 if ( session == NULL ) goto free_mem;
555 555
556 qDebug( "Servername %s at port %i", server, port ); 556 qDebug( "Servername %s at port %i", server, port );
557 if ( ssl ) { 557 if ( ssl ) {
558 qDebug( "SSL session" ); 558 qDebug( "SSL session" );
559 err = mailsmtp_ssl_connect( session, server, port ); 559 err = mailsmtp_ssl_connect( session, server, port );
560 } else { 560 } else {
561 qDebug( "No SSL session" ); 561 qDebug( "No SSL session" );
562 err = mailsmtp_socket_connect( session, server, port ); 562 err = mailsmtp_socket_connect( session, server, port );
563 } 563 }
564 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; 564 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session;
565 565
566 err = mailsmtp_init( session ); 566 err = mailsmtp_init( session );
567 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; 567 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session;
568 568
569 qDebug( "INIT OK" ); 569 qDebug( "INIT OK" );
570 570
571 if ( smtp->getLogin() ) { 571 if ( smtp->getLogin() ) {
572 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 572 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
573 // get'em 573 // get'em
574 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 574 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
575 login.show(); 575 login.show();
576 if ( QDialog::Accepted == login.exec() ) { 576 if ( QDialog::Accepted == login.exec() ) {
577 // ok 577 // ok
578 user = strdup( login.getUser().latin1() ); 578 user = strdup( login.getUser().latin1() );
579 pass = strdup( login.getPassword().latin1() ); 579 pass = strdup( login.getPassword().latin1() );
580 } else { 580 } else {
581 goto free_con_session; 581 goto free_con_session;
582 } 582 }
583 } else { 583 } else {
584 user = strdup( smtp->getUser().latin1() ); 584 user = strdup( smtp->getUser().latin1() );
585 pass = strdup( smtp->getPassword().latin1() ); 585 pass = strdup( smtp->getPassword().latin1() );
586 } 586 }
587 qDebug( "session->auth: %i", session->auth); 587 qDebug( "session->auth: %i", session->auth);
588 err = mailsmtp_auth( session, user, pass ); 588 err = mailsmtp_auth( session, user, pass );
589 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); 589 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
590 qDebug( "Done auth!" ); 590 qDebug( "Done auth!" );
591 } 591 }
592 592
593 err = mailsmtp_send( session, from, rcpts, data, size ); 593 err = mailsmtp_send( session, from, rcpts, data, size );
594 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; 594 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session;
595 595
596 qDebug( "Mail sent." ); 596 qDebug( "Mail sent." );
597 597
598free_con_session: 598free_con_session:
599 mailsmtp_quit( session ); 599 mailsmtp_quit( session );
600free_mem_session: 600free_mem_session:
601 mailsmtp_free( session ); 601 mailsmtp_free( session );
602free_mem: 602free_mem:
603 smtp_address_list_free( rcpts ); 603 smtp_address_list_free( rcpts );
604 free( data ); 604 free( data );
605 free( server ); 605 free( server );
606 if ( smtp->getLogin() ) { 606 if ( smtp->getLogin() ) {
607 free( user ); 607 free( user );
608 free( pass ); 608 free( pass );
609 } 609 }
610 free( from ); 610 free( from );
611} 611}
612 612
613void MailWrapper::sendMail( Mail mail ) 613void MailWrapper::sendMail( Mail mail )
614{ 614{
615 mailmime *mimeMail; 615 mailmime *mimeMail;
616 616
617 mimeMail = createMimeMail( &mail ); 617 mimeMail = createMimeMail( &mail );
618 if ( mimeMail == NULL ) { 618 if ( mimeMail == NULL ) {
619 qDebug( "sendMail: error creating mime mail" ); 619 qDebug( "sendMail: error creating mime mail" );
620 } else { 620 } else {
621 smtpSend( mimeMail ); 621 smtpSend( mimeMail );
622 mailmime_free( mimeMail ); 622 mailmime_free( mimeMail );
623 } 623 }
624} 624}
625 625
626Mail::Mail() 626Mail::Mail()
627 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") 627 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
628{ 628{
629} 629}
630 630
631RecMail::RecMail() 631RecMail::RecMail()
632 :subject(""),date(""),msg_number(0),msg_flags(7) 632 :subject(""),date(""),mbox(""),msg_number(0),msg_flags(7)
633{ 633{
634} 634}
635 635
636#if 0 636#if 0
637void RecMail::setDate(const QString&aDate) 637void RecMail::setDate(const QString&aDate)
638{ 638{
639 mDate = QDateTime::fromString(aDate); 639 mDate = QDateTime::fromString(aDate);
640} 640}
641#endif 641#endif
diff --git a/noncore/net/mail/mailwrapper.h b/noncore/net/mail/mailwrapper.h
index 955a8e2..332034f 100644
--- a/noncore/net/mail/mailwrapper.h
+++ b/noncore/net/mail/mailwrapper.h
@@ -1,164 +1,177 @@
1#ifndef MAILWRAPPER_H 1#ifndef MAILWRAPPER_H
2#define MAILWRAPPER_H 2#define MAILWRAPPER_H
3 3
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5 5
6#include <libetpan/mailmime.h> 6#include <libetpan/mailmime.h>
7#include <libetpan/mailimf.h> 7#include <libetpan/mailimf.h>
8#include <libetpan/mailsmtp.h> 8#include <libetpan/mailsmtp.h>
9#include <libetpan/mailstorage.h> 9#include <libetpan/mailstorage.h>
10#include <libetpan/maildriver.h> 10#include <libetpan/maildriver.h>
11#include <qbitarray.h> 11#include <qbitarray.h>
12#include <qdatetime.h> 12#include <qdatetime.h>
13 13
14#include "settings.h" 14#include "settings.h"
15 15
16class Attachment 16class Attachment
17{ 17{
18public: 18public:
19 Attachment( DocLnk lnk ); 19 Attachment( DocLnk lnk );
20 virtual ~Attachment(){} 20 virtual ~Attachment(){}
21 const QString getFileName()const{ return doc.file(); } 21 const QString getFileName()const{ return doc.file(); }
22 const QString getName()const{ return doc.name(); } 22 const QString getName()const{ return doc.name(); }
23 const QString getMimeType()const{ return doc.type(); } 23 const QString getMimeType()const{ return doc.type(); }
24 const QPixmap getPixmap()const{ return doc.pixmap(); } 24 const QPixmap getPixmap()const{ return doc.pixmap(); }
25 const int getSize()const { return size; } 25 const int getSize()const { return size; }
26 DocLnk getDocLnk() { return doc; } 26 DocLnk getDocLnk() { return doc; }
27 27
28protected: 28protected:
29 DocLnk doc; 29 DocLnk doc;
30 int size; 30 int size;
31 31
32}; 32};
33 33
34#define FLAG_ANSWERED 0 34#define FLAG_ANSWERED 0
35#define FLAG_FLAGGED 1 35#define FLAG_FLAGGED 1
36#define FLAG_DELETED 2 36#define FLAG_DELETED 2
37#define FLAG_SEEN 3 37#define FLAG_SEEN 3
38#define FLAG_DRAFT 4 38#define FLAG_DRAFT 4
39#define FLAG_RECENT 5 39#define FLAG_RECENT 5
40 40
41/* a class to describe mails in a mailbox */ 41/* a class to describe mails in a mailbox */
42/* Attention!
43 From programmers point of view it would make sense to
44 store the mail body into this class, too.
45 But: not from the point of view of the device.
46 Mailbodies can be real large. So we request them when
47 needed from the mail-wrapper class direct from the server itself
48 (imap) or from a file-based cache (pop3?)
49 So there is no interface "const QString&body()" but you should
50 make a request to the mailwrapper with this class as parameter to
51 get the body. Same words for the attachments.
52*/
42class RecMail 53class RecMail
43{ 54{
44public: 55public:
45 RecMail(); 56 RecMail();
46 virtual ~RecMail(){} 57 virtual ~RecMail(){}
47 58
48 const int getNumber()const{return msg_number;} 59 const int getNumber()const{return msg_number;}
49 void setNumber(int number){msg_number=number;} 60 void setNumber(int number){msg_number=number;}
50 const QString&getDate()const{ return date; } 61 const QString&getDate()const{ return date; }
51 void setDate( const QString&a ) { date = a; } 62 void setDate( const QString&a ) { date = a; }
52 const QString&getFrom()const{ return from; } 63 const QString&getFrom()const{ return from; }
53 void setFrom( const QString&a ) { from = a; } 64 void setFrom( const QString&a ) { from = a; }
54 const QString&getSubject()const { return subject; } 65 const QString&getSubject()const { return subject; }
55 void setSubject( const QString&s ) { subject = s; } 66 void setSubject( const QString&s ) { subject = s; }
56 void setFlags(const QBitArray&flags){msg_flags = flags;} 67 const QString&getMbox()const{return mbox;}
68 void setMbox(const QString&box){mbox = box;}
57 const QBitArray&getFlags()const{return msg_flags;} 69 const QBitArray&getFlags()const{return msg_flags;}
70 void setFlags(const QBitArray&flags){msg_flags = flags;}
58 71
59#if 0 72#if 0
60 void setDate(const QString&dstring); 73 void setDate(const QString&dstring);
61 void setDate(const QDateTime&date){mDate = date;} 74 void setDate(const QDateTime&date){mDate = date;}
62 QString getDate()const{return mDate.toString();} 75 QString getDate()const{return mDate.toString();}
63#endif 76#endif
64protected: 77protected:
65 QString subject,date,from; 78 QString subject,date,from,mbox;
66 int msg_number; 79 int msg_number;
67 QBitArray msg_flags; 80 QBitArray msg_flags;
68#if 0 81#if 0
69 QDateTime mDate; 82 QDateTime mDate;
70#endif 83#endif
71}; 84};
72 85
73typedef QList<RecMail> Maillist; 86typedef QList<RecMail> Maillist;
74 87
75class Mail 88class Mail
76{ 89{
77public: 90public:
78 Mail(); 91 Mail();
79 /* Possible that this destructor must not be declared virtual 92 /* Possible that this destructor must not be declared virtual
80 * 'cause it seems that it will never have some child classes. 93 * 'cause it seems that it will never have some child classes.
81 * in this case this object will not get a virtual table -> memory and 94 * in this case this object will not get a virtual table -> memory and
82 * speed will be a little bit better? 95 * speed will be a little bit better?
83 */ 96 */
84 virtual ~Mail(){} 97 virtual ~Mail(){}
85 void addAttachment( Attachment *att ) { attList.append( att ); } 98 void addAttachment( Attachment *att ) { attList.append( att ); }
86 const QList<Attachment>& getAttachments()const { return attList; } 99 const QList<Attachment>& getAttachments()const { return attList; }
87 void removeAttachment( Attachment *att ) { attList.remove( att ); } 100 void removeAttachment( Attachment *att ) { attList.remove( att ); }
88 const QString&getName()const { return name; } 101 const QString&getName()const { return name; }
89 void setName( QString s ) { name = s; } 102 void setName( QString s ) { name = s; }
90 const QString&getMail()const{ return mail; } 103 const QString&getMail()const{ return mail; }
91 void setMail( const QString&s ) { mail = s; } 104 void setMail( const QString&s ) { mail = s; }
92 const QString&getTo()const{ return to; } 105 const QString&getTo()const{ return to; }
93 void setTo( const QString&s ) { to = s; } 106 void setTo( const QString&s ) { to = s; }
94 const QString&getCC()const{ return cc; } 107 const QString&getCC()const{ return cc; }
95 void setCC( const QString&s ) { cc = s; } 108 void setCC( const QString&s ) { cc = s; }
96 const QString&getBCC()const { return bcc; } 109 const QString&getBCC()const { return bcc; }
97 void setBCC( const QString&s ) { bcc = s; } 110 void setBCC( const QString&s ) { bcc = s; }
98 const QString&getMessage()const { return message; } 111 const QString&getMessage()const { return message; }
99 void setMessage( const QString&s ) { message = s; } 112 void setMessage( const QString&s ) { message = s; }
100 const QString&getSubject()const { return subject; } 113 const QString&getSubject()const { return subject; }
101 void setSubject( const QString&s ) { subject = s; } 114 void setSubject( const QString&s ) { subject = s; }
102 const QString&getReply()const{ return reply; } 115 const QString&getReply()const{ return reply; }
103 void setReply( const QString&a ) { reply = a; } 116 void setReply( const QString&a ) { reply = a; }
104 117
105private: 118private:
106 QList<Attachment> attList; 119 QList<Attachment> attList;
107 QString name, mail, to, cc, bcc, reply, subject, message; 120 QString name, mail, to, cc, bcc, reply, subject, message;
108}; 121};
109 122
110class Folder : public QObject 123class Folder : public QObject
111{ 124{
112 Q_OBJECT 125 Q_OBJECT
113 126
114public: 127public:
115 Folder( const QString&init_name ); 128 Folder( const QString&init_name );
116 const QString&getDisplayName()const { return nameDisplay; } 129 const QString&getDisplayName()const { return nameDisplay; }
117 const QString&getName()const { return name; } 130 const QString&getName()const { return name; }
118 virtual bool may_select()const{return true;}; 131 virtual bool may_select()const{return true;};
119 132
120private: 133private:
121 QString nameDisplay, name; 134 QString nameDisplay, name;
122 135
123}; 136};
124 137
125class IMAPFolder : public Folder 138class IMAPFolder : public Folder
126{ 139{
127 public: 140 public:
128 IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} 141 IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {}
129 virtual bool may_select()const{return m_MaySelect;} 142 virtual bool may_select()const{return m_MaySelect;}
130 private: 143 private:
131 bool m_MaySelect; 144 bool m_MaySelect;
132}; 145};
133 146
134class MailWrapper : public QObject 147class MailWrapper : public QObject
135{ 148{
136 Q_OBJECT 149 Q_OBJECT
137 150
138public: 151public:
139 MailWrapper( Settings *s ); 152 MailWrapper( Settings *s );
140 void sendMail( Mail mail ); 153 void sendMail( Mail mail );
141 154
142private: 155private:
143 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 156 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
144 mailimf_address_list *parseAddresses(const QString&addr ); 157 mailimf_address_list *parseAddresses(const QString&addr );
145 mailimf_fields *createImfFields( Mail *mail ); 158 mailimf_fields *createImfFields( Mail *mail );
146 mailmime *buildTxtPart( QString str ); 159 mailmime *buildTxtPart( QString str );
147 mailmime *buildFilePart( QString filename, QString mimetype ); 160 mailmime *buildFilePart( QString filename, QString mimetype );
148 void addFileParts( mailmime *message, QList<Attachment> files ); 161 void addFileParts( mailmime *message, QList<Attachment> files );
149 mailmime *createMimeMail( Mail *mail ); 162 mailmime *createMimeMail( Mail *mail );
150 void smtpSend( mailmime *mail ); 163 void smtpSend( mailmime *mail );
151 mailimf_field *getField( mailimf_fields *fields, int type ); 164 mailimf_field *getField( mailimf_fields *fields, int type );
152 clist *createRcptList( mailimf_fields *fields ); 165 clist *createRcptList( mailimf_fields *fields );
153 char *getFrom( mailmime *mail ); 166 char *getFrom( mailmime *mail );
154 SMTPaccount *getAccount( QString from ); 167 SMTPaccount *getAccount( QString from );
155 void writeToFile( QString file, mailmime *mail ); 168 void writeToFile( QString file, mailmime *mail );
156 void readFromFile( QString file, char **data, size_t *size ); 169 void readFromFile( QString file, char **data, size_t *size );
157 static QString mailsmtpError( int err ); 170 static QString mailsmtpError( int err );
158 static QString getTmpFile(); 171 static QString getTmpFile();
159 172
160 Settings *settings; 173 Settings *settings;
161 174
162}; 175};
163 176
164#endif 177#endif