Diffstat (limited to 'noncore/net/mail/libmailwrapper') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.cpp | 199 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.h | 30 |
2 files changed, 229 insertions, 0 deletions
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp new file mode 100644 index 0000000..7581715 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp | |||
@@ -0,0 +1,199 @@ | |||
1 | #include "mboxwrapper.h" | ||
2 | #include "mailtypes.h" | ||
3 | #include "mailwrapper.h" | ||
4 | #include "libetpan/libetpan.h" | ||
5 | #include "libetpan/mailstorage.h" | ||
6 | #include <qdir.h> | ||
7 | |||
8 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir) | ||
9 | : Genericwrapper(),MBOXPath(mbox_dir) | ||
10 | { | ||
11 | QDir dir(MBOXPath); | ||
12 | if (!dir.exists()) { | ||
13 | dir.mkdir(MBOXPath); | ||
14 | } | ||
15 | } | ||
16 | |||
17 | MBOXwrapper::~MBOXwrapper() | ||
18 | { | ||
19 | } | ||
20 | |||
21 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | ||
22 | { | ||
23 | mailstorage*storage = mailstorage_new(NULL); | ||
24 | QString p = MBOXPath+"/"; | ||
25 | p+=mailbox; | ||
26 | |||
27 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | ||
28 | mailfolder*folder; | ||
29 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | ||
30 | r = mailfolder_connect(folder); | ||
31 | if (r != MAIL_NO_ERROR) { | ||
32 | qDebug("Error initializing mbox"); | ||
33 | mailfolder_free(folder); | ||
34 | mailstorage_free(storage); | ||
35 | return; | ||
36 | } | ||
37 | mailmessage_list * env_list = 0; | ||
38 | r = mailsession_get_messages_list(folder->fld_session,&env_list); | ||
39 | if (r != MAIL_NO_ERROR) { | ||
40 | qDebug("Error message list"); | ||
41 | mailfolder_free(folder); | ||
42 | mailstorage_free(storage); | ||
43 | return; | ||
44 | } | ||
45 | r = mailsession_get_envelopes_list(folder->fld_session, env_list); | ||
46 | if (r != MAIL_NO_ERROR) { | ||
47 | qDebug("Error filling message list"); | ||
48 | if (env_list) { | ||
49 | mailmessage_list_free(env_list); | ||
50 | } | ||
51 | mailfolder_free(folder); | ||
52 | mailstorage_free(storage); | ||
53 | return; | ||
54 | } | ||
55 | mailimf_references * refs; | ||
56 | |||
57 | for(int i = 0 ; i < carray_count(env_list->msg_tab) ; ++i) { | ||
58 | mailmessage * msg; | ||
59 | QBitArray mFlags(7); | ||
60 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | ||
61 | if (msg->msg_fields == NULL) { | ||
62 | qDebug("could not fetch envelope of message %i", i); | ||
63 | continue; | ||
64 | } | ||
65 | RecMail * mail = new RecMail(); | ||
66 | mail->setWrapper(this); | ||
67 | mail_flags * flag_result = 0; | ||
68 | r = mailmessage_get_flags(msg,&flag_result); | ||
69 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | ||
70 | qDebug("flag fetching not implemented"); | ||
71 | mFlags.setBit(FLAG_SEEN); | ||
72 | } | ||
73 | mailimf_single_fields single_fields; | ||
74 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | ||
75 | mail->setMsgsize(msg->msg_size); | ||
76 | mail->setFlags(mFlags); | ||
77 | mail->setMbox(mailbox); | ||
78 | mail->setNumber(i+1); | ||
79 | if (single_fields.fld_subject) | ||
80 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | ||
81 | if (single_fields.fld_from) | ||
82 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); | ||
83 | if (single_fields.fld_to) | ||
84 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); | ||
85 | if (single_fields.fld_cc) | ||
86 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); | ||
87 | if (single_fields.fld_bcc) | ||
88 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); | ||
89 | if (single_fields.fld_orig_date) | ||
90 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); | ||
91 | if (single_fields.fld_message_id->mid_value) | ||
92 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | ||
93 | refs = single_fields.fld_references; | ||
94 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | ||
95 | char * text = (char*)refs->mid_list->first->data; | ||
96 | mail->setReplyto(QString(text)); | ||
97 | } | ||
98 | |||
99 | target.append(mail); | ||
100 | } | ||
101 | if (env_list) { | ||
102 | mailmessage_list_free(env_list); | ||
103 | } | ||
104 | mailfolder_disconnect(folder); | ||
105 | mailfolder_free(folder); | ||
106 | mailstorage_free(storage); | ||
107 | } | ||
108 | |||
109 | QList<Folder>* MBOXwrapper::listFolders() | ||
110 | { | ||
111 | QList<Folder> * folders = new QList<Folder>(); | ||
112 | folders->setAutoDelete( false ); | ||
113 | QDir dir(MBOXPath); | ||
114 | if (!dir.exists()) return folders; | ||
115 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); | ||
116 | QStringList entries = dir.entryList(); | ||
117 | QStringList::ConstIterator it = entries.begin(); | ||
118 | for (;it!=entries.end();++it) { | ||
119 | Folder*inb=new Folder(*it,"/"); | ||
120 | folders->append(inb); | ||
121 | } | ||
122 | return folders; | ||
123 | } | ||
124 | |||
125 | void MBOXwrapper::deleteMail(const RecMail&mail) | ||
126 | { | ||
127 | mailstorage*storage = mailstorage_new(NULL); | ||
128 | QString p = MBOXPath+"/"; | ||
129 | p+=mail.getMbox(); | ||
130 | mailmessage * msg; | ||
131 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | ||
132 | mailfolder*folder; | ||
133 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | ||
134 | r = mailfolder_connect(folder); | ||
135 | if (r != MAIL_NO_ERROR) { | ||
136 | qDebug("Error initializing mbox"); | ||
137 | mailfolder_free(folder); | ||
138 | mailstorage_free(storage); | ||
139 | return; | ||
140 | } | ||
141 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); | ||
142 | if (r != MAIL_NO_ERROR) { | ||
143 | qDebug("error deleting mail"); | ||
144 | } | ||
145 | mailfolder_free(folder); | ||
146 | mailstorage_free(storage); | ||
147 | } | ||
148 | |||
149 | void MBOXwrapper::answeredMail(const RecMail&) | ||
150 | { | ||
151 | } | ||
152 | |||
153 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) | ||
154 | { | ||
155 | RecBody body; | ||
156 | mailstorage*storage = mailstorage_new(NULL); | ||
157 | QString p = MBOXPath+"/"; | ||
158 | p+=mail.getMbox(); | ||
159 | mailmessage * msg; | ||
160 | char*data=0; | ||
161 | size_t size; | ||
162 | |||
163 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | ||
164 | mailfolder*folder; | ||
165 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | ||
166 | r = mailfolder_connect(folder); | ||
167 | if (r != MAIL_NO_ERROR) { | ||
168 | qDebug("Error initializing mbox"); | ||
169 | mailfolder_free(folder); | ||
170 | mailstorage_free(storage); | ||
171 | return body; | ||
172 | } | ||
173 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | ||
174 | if (r != MAIL_NO_ERROR) { | ||
175 | qDebug("Error fetching mail %i",mail.getNumber()); | ||
176 | mailfolder_free(folder); | ||
177 | mailstorage_free(storage); | ||
178 | return body; | ||
179 | } | ||
180 | r = mailmessage_fetch(msg,&data,&size); | ||
181 | if (r != MAIL_NO_ERROR) { | ||
182 | qDebug("Error fetching mail %i",mail.getNumber()); | ||
183 | mailfolder_free(folder); | ||
184 | mailstorage_free(storage); | ||
185 | mailmessage_free(msg); | ||
186 | return body; | ||
187 | } | ||
188 | body = parseMail(msg); | ||
189 | mailmessage_fetch_result_free(msg,data); | ||
190 | mailfolder_free(folder); | ||
191 | mailstorage_free(storage); | ||
192 | |||
193 | return body; | ||
194 | } | ||
195 | |||
196 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) | ||
197 | { | ||
198 | qDebug("MBOX %i von %i",current,maximum); | ||
199 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.h b/noncore/net/mail/libmailwrapper/mboxwrapper.h new file mode 100644 index 0000000..779dbc8 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.h | |||
@@ -0,0 +1,30 @@ | |||
1 | #ifndef __MBOX_WRAPPER_H | ||
2 | #define __MBOX_WRAPPER_H | ||
3 | |||
4 | #include "genericwrapper.h" | ||
5 | #include <qstring.h> | ||
6 | |||
7 | class RecMail; | ||
8 | class RecBody; | ||
9 | |||
10 | class MBOXwrapper : public Genericwrapper | ||
11 | { | ||
12 | Q_OBJECT | ||
13 | public: | ||
14 | MBOXwrapper(const QString & dir); | ||
15 | virtual ~MBOXwrapper(); | ||
16 | |||
17 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | ||
18 | virtual QList<Folder>* listFolders(); | ||
19 | |||
20 | virtual void deleteMail(const RecMail&mail); | ||
21 | virtual void answeredMail(const RecMail&mail); | ||
22 | |||
23 | virtual RecBody fetchBody( const RecMail &mail ); | ||
24 | static void mbox_progress( size_t current, size_t maximum ); | ||
25 | |||
26 | protected: | ||
27 | QString MBOXPath; | ||
28 | }; | ||
29 | |||
30 | #endif | ||