Diffstat (limited to 'kmicromail/libmailwrapper/mhwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/mhwrapper.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/kmicromail/libmailwrapper/mhwrapper.cpp b/kmicromail/libmailwrapper/mhwrapper.cpp index 787e85d..4cd7a94 100644 --- a/kmicromail/libmailwrapper/mhwrapper.cpp +++ b/kmicromail/libmailwrapper/mhwrapper.cpp | |||
@@ -1,458 +1,460 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include "mhwrapper.h" | 2 | #include "mhwrapper.h" |
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | #include <libetpan/libetpan.h> | 5 | #include <libetpan/libetpan.h> |
6 | #include <qdir.h> | 6 | #include <qdir.h> |
7 | #include <qmessagebox.h> | 7 | #include <qmessagebox.h> |
8 | //Added by qt3to4: | ||
9 | #include <Q3ValueList> | ||
8 | #include <stdlib.h> | 10 | #include <stdlib.h> |
9 | #include <qpe/global.h> | 11 | #include <qpe/global.h> |
10 | #include <klocale.h> | 12 | #include <klocale.h> |
11 | #include <kglobal.h> | 13 | #include <kglobal.h> |
12 | //#include <opie2/odebug.h> | 14 | //#include <opie2/odebug.h> |
13 | 15 | ||
14 | using namespace Opie::Core; | 16 | using namespace Opie::Core; |
15 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) | 17 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) |
16 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) | 18 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) |
17 | { | 19 | { |
18 | if (MHPath.length()>0) { | 20 | if (MHPath.length()>0) { |
19 | if (MHPath[MHPath.length()-1]=='/') { | 21 | if (MHPath[MHPath.length()-1]=='/') { |
20 | MHPath=MHPath.left(MHPath.length()-1); | 22 | MHPath=MHPath.left(MHPath.length()-1); |
21 | } | 23 | } |
22 | //odebug << MHPath << oendl; | 24 | //odebug << MHPath << oendl; |
23 | QDir dir(MHPath); | 25 | QDir dir(MHPath); |
24 | if (!dir.exists()) { | 26 | if (!dir.exists()) { |
25 | dir.mkdir(MHPath); | 27 | dir.mkdir(MHPath); |
26 | } | 28 | } |
27 | init_storage(); | 29 | init_storage(); |
28 | } | 30 | } |
29 | } | 31 | } |
30 | 32 | ||
31 | void MHwrapper::init_storage() | 33 | void MHwrapper::init_storage() |
32 | { | 34 | { |
33 | int r; | 35 | int r; |
34 | QString pre = MHPath; | 36 | QString pre = MHPath; |
35 | if (!m_storage) { | 37 | if (!m_storage) { |
36 | m_storage = mailstorage_new(NULL); | 38 | m_storage = mailstorage_new(NULL); |
37 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); | 39 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); |
38 | if (r != MAIL_NO_ERROR) { | 40 | if (r != MAIL_NO_ERROR) { |
39 | qDebug(" error init storage "); | 41 | qDebug(" error init storage "); |
40 | mailstorage_free(m_storage); | 42 | mailstorage_free(m_storage); |
41 | m_storage = 0; | 43 | m_storage = 0; |
42 | return; | 44 | return; |
43 | } | 45 | } |
44 | } | 46 | } |
45 | r = mailstorage_connect(m_storage); | 47 | r = mailstorage_connect(m_storage); |
46 | if (r!=MAIL_NO_ERROR) { | 48 | if (r!=MAIL_NO_ERROR) { |
47 | qDebug("error connecting storage "); | 49 | qDebug("error connecting storage "); |
48 | mailstorage_free(m_storage); | 50 | mailstorage_free(m_storage); |
49 | m_storage = 0; | 51 | m_storage = 0; |
50 | } | 52 | } |
51 | } | 53 | } |
52 | 54 | ||
53 | void MHwrapper::clean_storage() | 55 | void MHwrapper::clean_storage() |
54 | { | 56 | { |
55 | if (m_storage) { | 57 | if (m_storage) { |
56 | mailstorage_disconnect(m_storage); | 58 | mailstorage_disconnect(m_storage); |
57 | mailstorage_free(m_storage); | 59 | mailstorage_free(m_storage); |
58 | m_storage = 0; | 60 | m_storage = 0; |
59 | } | 61 | } |
60 | } | 62 | } |
61 | 63 | ||
62 | MHwrapper::~MHwrapper() | 64 | MHwrapper::~MHwrapper() |
63 | { | 65 | { |
64 | clean_storage(); | 66 | clean_storage(); |
65 | } | 67 | } |
66 | 68 | ||
67 | void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) | 69 | void MHwrapper::listMessages(const QString & mailbox, Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) |
68 | { | 70 | { |
69 | init_storage(); | 71 | init_storage(); |
70 | if (!m_storage) { | 72 | if (!m_storage) { |
71 | return; | 73 | return; |
72 | } | 74 | } |
73 | QString f = buildPath(mailbox); | 75 | QString f = buildPath(mailbox); |
74 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 76 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
75 | if (r!=MAIL_NO_ERROR) { | 77 | if (r!=MAIL_NO_ERROR) { |
76 | qDebug("listMessages: error selecting folder! "); | 78 | qDebug("listMessages: error selecting folder! "); |
77 | return; | 79 | return; |
78 | } | 80 | } |
79 | parseList(target,m_storage->sto_session,f, false, maxSizeInKb ); | 81 | parseList(target,m_storage->sto_session,f, false, maxSizeInKb ); |
80 | Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count())); | 82 | Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count())); |
81 | } | 83 | } |
82 | 84 | ||
83 | QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() | 85 | Q3ValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() |
84 | { | 86 | { |
85 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); | 87 | Q3ValueList<Opie::Core::OSmartPointer<Folder> >* folders = new Q3ValueList<Opie::Core::OSmartPointer<Folder> >(); |
86 | /* this is needed! */ | 88 | /* this is needed! */ |
87 | if (m_storage) mailstorage_disconnect(m_storage); | 89 | if (m_storage) mailstorage_disconnect(m_storage); |
88 | init_storage(); | 90 | init_storage(); |
89 | if (!m_storage) { | 91 | if (!m_storage) { |
90 | return folders; | 92 | return folders; |
91 | } | 93 | } |
92 | mail_list*flist = 0; | 94 | mail_list*flist = 0; |
93 | clistcell*current=0; | 95 | clistcell*current=0; |
94 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); | 96 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); |
95 | if (r != MAIL_NO_ERROR || !flist) { | 97 | if (r != MAIL_NO_ERROR || !flist) { |
96 | qDebug("error getting folder list "); | 98 | qDebug("error getting folder list "); |
97 | return folders; | 99 | return folders; |
98 | } | 100 | } |
99 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { | 101 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { |
100 | QString t = (char*)current->data; | 102 | QString t = (char*)current->data; |
101 | t.replace(0,MHPath.length(),""); | 103 | t.replace(0,MHPath.length(),""); |
102 | folders->append(new MHFolder(t,MHPath)); | 104 | folders->append(new MHFolder(t,MHPath)); |
103 | } | 105 | } |
104 | mail_list_free(flist); | 106 | mail_list_free(flist); |
105 | return folders; | 107 | return folders; |
106 | } | 108 | } |
107 | 109 | ||
108 | void MHwrapper::deleteMail(const RecMailP&mail) | 110 | void MHwrapper::deleteMail(const RecMailP&mail) |
109 | { | 111 | { |
110 | init_storage(); | 112 | init_storage(); |
111 | if (!m_storage) { | 113 | if (!m_storage) { |
112 | return; | 114 | return; |
113 | } | 115 | } |
114 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 116 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
115 | if (r!=MAIL_NO_ERROR) { | 117 | if (r!=MAIL_NO_ERROR) { |
116 | qDebug("error selecting folder! "); | 118 | qDebug("error selecting folder! "); |
117 | return; | 119 | return; |
118 | } | 120 | } |
119 | r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); | 121 | r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); |
120 | if (r != MAIL_NO_ERROR) { | 122 | if (r != MAIL_NO_ERROR) { |
121 | qDebug("error deleting mail "); | 123 | qDebug("error deleting mail "); |
122 | } | 124 | } |
123 | } | 125 | } |
124 | 126 | ||
125 | void MHwrapper::answeredMail(const RecMailP&) | 127 | void MHwrapper::answeredMail(const RecMailP&) |
126 | { | 128 | { |
127 | } | 129 | } |
128 | 130 | ||
129 | RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) | 131 | RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) |
130 | { | 132 | { |
131 | qDebug("MHwrapper::fetchBody "); | 133 | qDebug("MHwrapper::fetchBody "); |
132 | RecBodyP body = new RecBody(); | 134 | RecBodyP body = new RecBody(); |
133 | init_storage(); | 135 | init_storage(); |
134 | if (!m_storage) { | 136 | if (!m_storage) { |
135 | return body; | 137 | return body; |
136 | } | 138 | } |
137 | mailmessage * msg; | 139 | mailmessage * msg; |
138 | char*data=0; | 140 | char*data=0; |
139 | 141 | ||
140 | /* mail should hold the complete path! */ | 142 | /* mail should hold the complete path! */ |
141 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 143 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
142 | if (r != MAIL_NO_ERROR) { | 144 | if (r != MAIL_NO_ERROR) { |
143 | return body; | 145 | return body; |
144 | } | 146 | } |
145 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); | 147 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); |
146 | if (r != MAIL_NO_ERROR) { | 148 | if (r != MAIL_NO_ERROR) { |
147 | qDebug("Error fetching mail "); | 149 | qDebug("Error fetching mail "); |
148 | 150 | ||
149 | return body; | 151 | return body; |
150 | } | 152 | } |
151 | body = parseMail(msg); | 153 | body = parseMail(msg); |
152 | mailmessage_fetch_result_free(msg,data); | 154 | mailmessage_fetch_result_free(msg,data); |
153 | return body; | 155 | return body; |
154 | } | 156 | } |
155 | 157 | ||
156 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) | 158 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) |
157 | { | 159 | { |
158 | qDebug("MBox Progress %d of %d",current,maximum ); | 160 | qDebug("MBox Progress %d of %d",current,maximum ); |
159 | //odebug << "MH " << current << " von " << maximum << "" << oendl; | 161 | //odebug << "MH " << current << " von " << maximum << "" << oendl; |
160 | } | 162 | } |
161 | 163 | ||
162 | QString MHwrapper::buildPath(const QString&p) | 164 | QString MHwrapper::buildPath(const QString&p) |
163 | { | 165 | { |
164 | QString f=""; | 166 | QString f=""; |
165 | if (p.length()==0||p=="/") | 167 | if (p.length()==0||p=="/") |
166 | return MHPath; | 168 | return MHPath; |
167 | if (!p.startsWith(MHPath)) { | 169 | if (!p.startsWith(MHPath)) { |
168 | f+=MHPath; | 170 | f+=MHPath; |
169 | } | 171 | } |
170 | if (!p.startsWith("/")) { | 172 | if (!p.startsWith("/")) { |
171 | f+="/"; | 173 | f+="/"; |
172 | } | 174 | } |
173 | f+=p; | 175 | f+=p; |
174 | return f; | 176 | return f; |
175 | } | 177 | } |
176 | 178 | ||
177 | int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) | 179 | int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) |
178 | { | 180 | { |
179 | 181 | ||
180 | QString f; | 182 | QString f; |
181 | if (!pfolder) { | 183 | if (!pfolder) { |
182 | // toplevel folder | 184 | // toplevel folder |
183 | f = buildPath(folder); | 185 | f = buildPath(folder); |
184 | } else { | 186 | } else { |
185 | f = pfolder->getName(); | 187 | f = pfolder->getName(); |
186 | f+="/"; | 188 | f+="/"; |
187 | f+=folder; | 189 | f+=folder; |
188 | } | 190 | } |
189 | QFileInfo fi ( f ); | 191 | QFileInfo fi ( f ); |
190 | if ( fi. exists () ) { | 192 | if ( fi. exists () ) { |
191 | qDebug("folder exists "); | 193 | qDebug("folder exists "); |
192 | return 1; | 194 | return 1; |
193 | } | 195 | } |
194 | qDebug("creating folder ---%s--- ",f.latin1() ); | 196 | qDebug("creating folder ---%s--- ",f.latin1() ); |
195 | init_storage(); | 197 | init_storage(); |
196 | if (!m_storage) { | 198 | if (!m_storage) { |
197 | return 0; | 199 | return 0; |
198 | } | 200 | } |
199 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); | 201 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); |
200 | if (r != MAIL_NO_ERROR) { | 202 | if (r != MAIL_NO_ERROR) { |
201 | qDebug("error %d creating folder %s", r, f.latin1()); | 203 | qDebug("error %d creating folder %s", r, f.latin1()); |
202 | return 0; | 204 | return 0; |
203 | } | 205 | } |
204 | return 1; | 206 | return 1; |
205 | } | 207 | } |
206 | 208 | ||
207 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) | 209 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) |
208 | { | 210 | { |
209 | init_storage(); | 211 | init_storage(); |
210 | if (!m_storage) { | 212 | if (!m_storage) { |
211 | return; | 213 | return; |
212 | } | 214 | } |
213 | QString f = buildPath(Folder); | 215 | QString f = buildPath(Folder); |
214 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 216 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
215 | if (r!=MAIL_NO_ERROR) { | 217 | if (r!=MAIL_NO_ERROR) { |
216 | qDebug("error selecting folder %d", r); | 218 | qDebug("error selecting folder %d", r); |
217 | return; | 219 | return; |
218 | } | 220 | } |
219 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); | 221 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); |
220 | if (r!=MAIL_NO_ERROR) { | 222 | if (r!=MAIL_NO_ERROR) { |
221 | if ( r != MAIL_ERROR_APPEND ) | 223 | if ( r != MAIL_ERROR_APPEND ) |
222 | qDebug("error storing mail %d", r); | 224 | qDebug("error storing mail %d", r); |
223 | } | 225 | } |
224 | return; | 226 | return; |
225 | } | 227 | } |
226 | 228 | ||
227 | encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) | 229 | encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) |
228 | { | 230 | { |
229 | encodedString*result = 0; | 231 | encodedString*result = 0; |
230 | init_storage(); | 232 | init_storage(); |
231 | if (!m_storage) { | 233 | if (!m_storage) { |
232 | return result; | 234 | return result; |
233 | } | 235 | } |
234 | mailmessage * msg = 0; | 236 | mailmessage * msg = 0; |
235 | char*data=0; | 237 | char*data=0; |
236 | size_t size; | 238 | size_t size; |
237 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 239 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
238 | if (r!=MAIL_NO_ERROR) { | 240 | if (r!=MAIL_NO_ERROR) { |
239 | qDebug("error selecting folder! "); | 241 | qDebug("error selecting folder! "); |
240 | return result; | 242 | return result; |
241 | } | 243 | } |
242 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); | 244 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); |
243 | if (r != MAIL_NO_ERROR) { | 245 | if (r != MAIL_NO_ERROR) { |
244 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); | 246 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); |
245 | return 0; | 247 | return 0; |
246 | } | 248 | } |
247 | r = mailmessage_fetch(msg,&data,&size); | 249 | r = mailmessage_fetch(msg,&data,&size); |
248 | if (r != MAIL_NO_ERROR) { | 250 | if (r != MAIL_NO_ERROR) { |
249 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); | 251 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); |
250 | if (msg) mailmessage_free(msg); | 252 | if (msg) mailmessage_free(msg); |
251 | return 0; | 253 | return 0; |
252 | } | 254 | } |
253 | result = new encodedString(data,size); | 255 | result = new encodedString(data,size); |
254 | if (msg) mailmessage_free(msg); | 256 | if (msg) mailmessage_free(msg); |
255 | return result; | 257 | return result; |
256 | } | 258 | } |
257 | 259 | ||
258 | void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) | 260 | void MHwrapper::deleteMails(const QString & mailbox,const Q3ValueList<RecMailP> &target) |
259 | { | 261 | { |
260 | QString f = buildPath(mailbox); | 262 | QString f = buildPath(mailbox); |
261 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 263 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
262 | if (r!=MAIL_NO_ERROR) { | 264 | if (r!=MAIL_NO_ERROR) { |
263 | qDebug("deleteMails: error selecting folder! "); | 265 | qDebug("deleteMails: error selecting folder! "); |
264 | return; | 266 | return; |
265 | } | 267 | } |
266 | QValueList<RecMailP>::ConstIterator it; | 268 | Q3ValueList<RecMailP>::ConstIterator it; |
267 | for (it=target.begin(); it!=target.end();++it) { | 269 | for (it=target.begin(); it!=target.end();++it) { |
268 | r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); | 270 | r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); |
269 | if (r != MAIL_NO_ERROR) { | 271 | if (r != MAIL_NO_ERROR) { |
270 | qDebug("error deleting mail "); | 272 | qDebug("error deleting mail "); |
271 | break; | 273 | break; |
272 | } | 274 | } |
273 | } | 275 | } |
274 | } | 276 | } |
275 | 277 | ||
276 | int MHwrapper::deleteAllMail(const FolderP&tfolder) | 278 | int MHwrapper::deleteAllMail(const FolderP&tfolder) |
277 | { | 279 | { |
278 | init_storage(); | 280 | init_storage(); |
279 | if (!m_storage) { | 281 | if (!m_storage) { |
280 | return 0; | 282 | return 0; |
281 | } | 283 | } |
282 | int res = 1; | 284 | int res = 1; |
283 | if (!tfolder) return 0; | 285 | if (!tfolder) return 0; |
284 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 286 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
285 | if (r!=MAIL_NO_ERROR) { | 287 | if (r!=MAIL_NO_ERROR) { |
286 | qDebug("error selecting folder! "); | 288 | qDebug("error selecting folder! "); |
287 | return 0; | 289 | return 0; |
288 | } | 290 | } |
289 | mailmessage_list*l=0; | 291 | mailmessage_list*l=0; |
290 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | 292 | r = mailsession_get_messages_list(m_storage->sto_session,&l); |
291 | if (r != MAIL_NO_ERROR) { | 293 | if (r != MAIL_NO_ERROR) { |
292 | qDebug("Error message list "); | 294 | qDebug("Error message list "); |
293 | res = 0; | 295 | res = 0; |
294 | } | 296 | } |
295 | unsigned j = 0; | 297 | unsigned j = 0; |
296 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | 298 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { |
297 | mailmessage * msg; | 299 | mailmessage * msg; |
298 | msg = (mailmessage*)carray_get(l->msg_tab, i); | 300 | msg = (mailmessage*)carray_get(l->msg_tab, i); |
299 | j = msg->msg_index; | 301 | j = msg->msg_index; |
300 | r = mailsession_remove_message(m_storage->sto_session,j); | 302 | r = mailsession_remove_message(m_storage->sto_session,j); |
301 | if (r != MAIL_NO_ERROR) { | 303 | if (r != MAIL_NO_ERROR) { |
302 | Global::statusMessage(i18n("Error deleting mail %1").arg(i+1)); | 304 | Global::statusMessage(i18n("Error deleting mail %1").arg(i+1)); |
303 | res = 0; | 305 | res = 0; |
304 | break; | 306 | break; |
305 | } | 307 | } |
306 | } | 308 | } |
307 | if (l) mailmessage_list_free(l); | 309 | if (l) mailmessage_list_free(l); |
308 | return res; | 310 | return res; |
309 | } | 311 | } |
310 | bool MHwrapper::rmDir(QString folder) // absolute path! | 312 | bool MHwrapper::rmDir(QString folder) // absolute path! |
311 | { | 313 | { |
312 | QDir dir ( folder ); | 314 | QDir dir ( folder ); |
313 | if ( !dir.exists() ) | 315 | if ( !dir.exists() ) |
314 | return false; | 316 | return false; |
315 | int i; | 317 | int i; |
316 | // qDebug("rmdir %s ",folder.latin1()); | 318 | // qDebug("rmdir %s ",folder.latin1()); |
317 | QStringList list = dir.entryList(QDir::Dirs|QDir::Files|QDir::NoSymLinks|QDir::Hidden ); | 319 | QStringList list = dir.entryList(QDir::Dirs|QDir::Files|QDir::NoSymLinks|QDir::Hidden ); |
318 | for (i=0; i<list.count(); i++ ) { | 320 | for (i=0; i<list.count(); i++ ) { |
319 | bool result = true; | 321 | bool result = true; |
320 | QString entry = folder+"/"+ list[i] ; | 322 | QString entry = folder+"/"+ list[i] ; |
321 | //qDebug("entry %s ",entry.latin1() ); | 323 | //qDebug("entry %s ",entry.latin1() ); |
322 | 324 | ||
323 | QFileInfo fi ( entry ); | 325 | QFileInfo fi ( entry ); |
324 | if ( fi.isFile() ) { | 326 | if ( fi.isFile() ) { |
325 | //qDebug("file %s ",entry.latin1() ); | 327 | //qDebug("file %s ",entry.latin1() ); |
326 | result = QFile::remove ( entry ) ; | 328 | result = QFile::remove ( entry ) ; |
327 | } else { | 329 | } else { |
328 | //qDebug("dir %s ",entry.latin1()); | 330 | //qDebug("dir %s ",entry.latin1()); |
329 | if ( list[i] != "." && list[i] != ".." ) | 331 | if ( list[i] != "." && list[i] != ".." ) |
330 | result = rmDir( entry ); | 332 | result = rmDir( entry ); |
331 | } | 333 | } |
332 | if ( ! result ) | 334 | if ( ! result ) |
333 | return false; | 335 | return false; |
334 | } | 336 | } |
335 | //qDebug("removing... "); | 337 | //qDebug("removing... "); |
336 | return QDir::root().rmdir ( folder, true ); | 338 | return QDir::root().rmdir ( folder, true ); |
337 | } | 339 | } |
338 | int MHwrapper::deleteMbox(const FolderP&tfolder) | 340 | int MHwrapper::deleteMbox(const FolderP&tfolder) |
339 | { | 341 | { |
340 | init_storage(); | 342 | init_storage(); |
341 | if (!m_storage) { | 343 | if (!m_storage) { |
342 | return 0; | 344 | return 0; |
343 | } | 345 | } |
344 | if (!tfolder) return 0; | 346 | if (!tfolder) return 0; |
345 | if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; | 347 | if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; |
346 | 348 | ||
347 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 349 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
348 | 350 | ||
349 | if (r != MAIL_NO_ERROR) { | 351 | if (r != MAIL_NO_ERROR) { |
350 | qDebug("error deleting mail box "); | 352 | qDebug("error deleting mail box "); |
351 | return 0; | 353 | return 0; |
352 | } | 354 | } |
353 | //qDebug("*****************\ndel %s %s ", delDir.latin1(),tfolder->getName().latin1() ); | 355 | //qDebug("*****************\ndel %s %s ", delDir.latin1(),tfolder->getName().latin1() ); |
354 | if ( !rmDir( tfolder->getName() )) { | 356 | if ( !rmDir( tfolder->getName() )) { |
355 | qDebug("error deleteing folder %s ",tfolder->getName().latin1()); | 357 | qDebug("error deleteing folder %s ",tfolder->getName().latin1()); |
356 | } | 358 | } |
357 | else | 359 | else |
358 | qDebug("mail box deleted %s ", tfolder->getName().latin1()); | 360 | qDebug("mail box deleted %s ", tfolder->getName().latin1()); |
359 | return 1; | 361 | return 1; |
360 | } | 362 | } |
361 | 363 | ||
362 | 364 | ||
363 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 365 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
364 | { | 366 | { |
365 | init_storage(); | 367 | init_storage(); |
366 | if (!m_storage) { | 368 | if (!m_storage) { |
367 | return; | 369 | return; |
368 | } | 370 | } |
369 | target_stat.message_count = 0; | 371 | target_stat.message_count = 0; |
370 | target_stat.message_unseen = 0; | 372 | target_stat.message_unseen = 0; |
371 | target_stat.message_recent = 0; | 373 | target_stat.message_recent = 0; |
372 | QString f = buildPath(mailbox); | 374 | QString f = buildPath(mailbox); |
373 | int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, | 375 | int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, |
374 | &target_stat.message_recent,&target_stat.message_unseen); | 376 | &target_stat.message_recent,&target_stat.message_unseen); |
375 | if (r != MAIL_NO_ERROR) { | 377 | if (r != MAIL_NO_ERROR) { |
376 | Global::statusMessage(i18n("Error retrieving status")); | 378 | Global::statusMessage(i18n("Error retrieving status")); |
377 | } | 379 | } |
378 | } | 380 | } |
379 | 381 | ||
380 | MAILLIB::ATYPE MHwrapper::getType()const | 382 | MAILLIB::ATYPE MHwrapper::getType()const |
381 | { | 383 | { |
382 | return MAILLIB::A_MH; | 384 | return MAILLIB::A_MH; |
383 | } | 385 | } |
384 | 386 | ||
385 | const QString&MHwrapper::getName()const | 387 | const QString&MHwrapper::getName()const |
386 | { | 388 | { |
387 | return MHName; | 389 | return MHName; |
388 | } | 390 | } |
389 | void MHwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 391 | void MHwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
390 | { | 392 | { |
391 | init_storage(); | 393 | init_storage(); |
392 | if (!m_storage) { | 394 | if (!m_storage) { |
393 | return; | 395 | return; |
394 | } | 396 | } |
395 | if (targetWrapper != this) { | 397 | if (targetWrapper != this) { |
396 | qDebug("Using generic "); | 398 | qDebug("Using generic "); |
397 | Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); | 399 | Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); |
398 | return; | 400 | return; |
399 | } | 401 | } |
400 | qDebug("Using internal routines for move/copy "); | 402 | qDebug("Using internal routines for move/copy "); |
401 | QString tf = buildPath(targetFolder); | 403 | QString tf = buildPath(targetFolder); |
402 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 404 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
403 | if (r != MAIL_NO_ERROR) { | 405 | if (r != MAIL_NO_ERROR) { |
404 | qDebug("Error selecting source mailbox "); | 406 | qDebug("Error selecting source mailbox "); |
405 | return; | 407 | return; |
406 | } | 408 | } |
407 | if (moveit) { | 409 | if (moveit) { |
408 | r = mailsession_move_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); | 410 | r = mailsession_move_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); |
409 | } else { | 411 | } else { |
410 | r = mailsession_copy_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); | 412 | r = mailsession_copy_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); |
411 | } | 413 | } |
412 | if (r != MAIL_NO_ERROR) { | 414 | if (r != MAIL_NO_ERROR) { |
413 | qDebug("Error copy/moving mail internal "); | 415 | qDebug("Error copy/moving mail internal "); |
414 | } | 416 | } |
415 | } | 417 | } |
416 | 418 | ||
417 | void MHwrapper::mvcpAllMails(const FolderP&fromFolder, | 419 | void MHwrapper::mvcpAllMails(const FolderP&fromFolder, |
418 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 420 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
419 | { | 421 | { |
420 | init_storage(); | 422 | init_storage(); |
421 | if (!m_storage) { | 423 | if (!m_storage) { |
422 | return; | 424 | return; |
423 | } | 425 | } |
424 | if (targetWrapper != this) { | 426 | if (targetWrapper != this) { |
425 | qDebug("Using generic "); | 427 | qDebug("Using generic "); |
426 | Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); | 428 | Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); |
427 | return; | 429 | return; |
428 | } | 430 | } |
429 | if (!fromFolder) return; | 431 | if (!fromFolder) return; |
430 | int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1()); | 432 | int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1()); |
431 | if (r!=MAIL_NO_ERROR) { | 433 | if (r!=MAIL_NO_ERROR) { |
432 | qDebug("error selecting source folder! "); | 434 | qDebug("error selecting source folder! "); |
433 | return; | 435 | return; |
434 | } | 436 | } |
435 | QString tf = buildPath(targetFolder); | 437 | QString tf = buildPath(targetFolder); |
436 | mailmessage_list*l=0; | 438 | mailmessage_list*l=0; |
437 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | 439 | r = mailsession_get_messages_list(m_storage->sto_session,&l); |
438 | if (r != MAIL_NO_ERROR) { | 440 | if (r != MAIL_NO_ERROR) { |
439 | qDebug("Error message list "); | 441 | qDebug("Error message list "); |
440 | } | 442 | } |
441 | unsigned j = 0; | 443 | unsigned j = 0; |
442 | for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) { | 444 | for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) { |
443 | mailmessage * msg; | 445 | mailmessage * msg; |
444 | msg = (mailmessage*)carray_get(l->msg_tab, i); | 446 | msg = (mailmessage*)carray_get(l->msg_tab, i); |
445 | j = msg->msg_index; | 447 | j = msg->msg_index; |
446 | if (moveit) { | 448 | if (moveit) { |
447 | r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1()); | 449 | r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1()); |
448 | } else { | 450 | } else { |
449 | r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1()); | 451 | r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1()); |
450 | } | 452 | } |
451 | if (r != MAIL_NO_ERROR) { | 453 | if (r != MAIL_NO_ERROR) { |
452 | qDebug("Error copy/moving mail interna "); | 454 | qDebug("Error copy/moving mail interna "); |
453 | 455 | ||
454 | break; | 456 | break; |
455 | } | 457 | } |
456 | } | 458 | } |
457 | if (l) mailmessage_list_free(l); | 459 | if (l) mailmessage_list_free(l); |
458 | } | 460 | } |