Diffstat (limited to 'kmicromail/libmailwrapper/abstractmail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/abstractmail.cpp | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp index 870985e..746d2ae 100644 --- a/kmicromail/libmailwrapper/abstractmail.cpp +++ b/kmicromail/libmailwrapper/abstractmail.cpp | |||
@@ -1,49 +1,51 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include "abstractmail.h" | 2 | #include "abstractmail.h" |
3 | #include "imapwrapper.h" | 3 | #include "imapwrapper.h" |
4 | #include "pop3wrapper.h" | 4 | #include "pop3wrapper.h" |
5 | #include "nntpwrapper.h" | 5 | #include "nntpwrapper.h" |
6 | #include "mhwrapper.h" | 6 | #include "mhwrapper.h" |
7 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
8 | #include <qpe/global.h> | 8 | #include <qpe/global.h> |
9 | 9 | ||
10 | 10 | ||
11 | #include <qprogressbar.h> | 11 | #include <q3progressbar.h> |
12 | #include <qapplication.h> | 12 | #include <qapplication.h> |
13 | #include <qmessagebox.h> | 13 | #include <qmessagebox.h> |
14 | //Added by qt3to4: | ||
15 | #include <Q3ValueList> | ||
14 | #include <klocale.h> | 16 | #include <klocale.h> |
15 | #include <kdecore/kstandarddirs.h> | 17 | #include <kdecore/kstandarddirs.h> |
16 | #include <qfile.h> | 18 | #include <qfile.h> |
17 | #include <qtextstream.h> | 19 | #include <q3textstream.h> |
18 | #include <stdlib.h> | 20 | #include <stdlib.h> |
19 | #include <libetpan/mailmime_content.h> | 21 | #include <libetpan/mailmime_content.h> |
20 | #include <libetpan/mailmime.h> | 22 | #include <libetpan/mailmime.h> |
21 | 23 | ||
22 | using namespace Opie::Core; | 24 | using namespace Opie::Core; |
23 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) | 25 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) |
24 | { | 26 | { |
25 | return new IMAPwrapper(a); | 27 | return new IMAPwrapper(a); |
26 | } | 28 | } |
27 | 29 | ||
28 | AbstractMail* AbstractMail::getWrapper(POP3account *a) | 30 | AbstractMail* AbstractMail::getWrapper(POP3account *a) |
29 | { | 31 | { |
30 | return new POP3wrapper(a); | 32 | return new POP3wrapper(a); |
31 | } | 33 | } |
32 | 34 | ||
33 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) | 35 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) |
34 | { | 36 | { |
35 | return new NNTPwrapper(a); | 37 | return new NNTPwrapper(a); |
36 | } | 38 | } |
37 | 39 | ||
38 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) | 40 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) |
39 | { | 41 | { |
40 | return new MHwrapper(a,name); | 42 | return new MHwrapper(a,name); |
41 | } | 43 | } |
42 | 44 | ||
43 | AbstractMail* AbstractMail::getWrapper(Account*a) | 45 | AbstractMail* AbstractMail::getWrapper(Account*a) |
44 | { | 46 | { |
45 | if (!a) return 0; | 47 | if (!a) return 0; |
46 | switch (a->getType()) { | 48 | switch (a->getType()) { |
47 | case MAILLIB::A_IMAP: | 49 | case MAILLIB::A_IMAP: |
48 | return new IMAPwrapper((IMAPaccount*)a); | 50 | return new IMAPwrapper((IMAPaccount*)a); |
49 | break; | 51 | break; |
@@ -82,200 +84,200 @@ encodedString* AbstractMail::decode_String(const encodedString*text,const QStrin | |||
82 | encodedString* result = new encodedString(); | 84 | encodedString* result = new encodedString(); |
83 | if (err == MAILIMF_NO_ERROR) { | 85 | if (err == MAILIMF_NO_ERROR) { |
84 | result->setContent(result_text,target_length); | 86 | result->setContent(result_text,target_length); |
85 | } | 87 | } |
86 | //odebug << "Decode string finished" << oendl; | 88 | //odebug << "Decode string finished" << oendl; |
87 | return result; | 89 | return result; |
88 | } | 90 | } |
89 | 91 | ||
90 | QString AbstractMail::convert_String(const char*text) | 92 | QString AbstractMail::convert_String(const char*text) |
91 | { | 93 | { |
92 | size_t index = 0; | 94 | size_t index = 0; |
93 | char*res = 0; | 95 | char*res = 0; |
94 | int err = MAILIMF_NO_ERROR; | 96 | int err = MAILIMF_NO_ERROR; |
95 | 97 | ||
96 | QString result(text); | 98 | QString result(text); |
97 | //qDebug("convert_String %s ", text); | 99 | //qDebug("convert_String %s ", text); |
98 | //err = mailmime_encoded_phrase_parse("iso-8859-1", | 100 | //err = mailmime_encoded_phrase_parse("iso-8859-1", |
99 | // text, strlen(text),&index, "iso-8859-1",&res); | 101 | // text, strlen(text),&index, "iso-8859-1",&res); |
100 | err = mailmime_encoded_phrase_parse("iso-8859-1", | 102 | err = mailmime_encoded_phrase_parse("iso-8859-1", |
101 | text, strlen(text),&index, "utf-8",&res); | 103 | text, strlen(text),&index, "utf-8",&res); |
102 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { | 104 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { |
103 | result = QString::fromUtf8(res); | 105 | result = QString::fromUtf8(res); |
104 | } | 106 | } |
105 | //qDebug("convert_String:%s ",result.latin1() ); | 107 | //qDebug("convert_String:%s ",result.latin1() ); |
106 | if (res) free(res); | 108 | if (res) free(res); |
107 | return result; | 109 | return result; |
108 | } | 110 | } |
109 | 111 | ||
110 | /* cp & paste from launcher */ | 112 | /* cp & paste from launcher */ |
111 | QString AbstractMail::gen_attachment_id() | 113 | QString AbstractMail::gen_attachment_id() |
112 | { | 114 | { |
113 | QFile file( "/proc/sys/kernel/random/uuid" ); | 115 | QFile file( "/proc/sys/kernel/random/uuid" ); |
114 | if (!file.open(IO_ReadOnly ) ) | 116 | if (!file.open(QIODevice::ReadOnly ) ) |
115 | return QString::null; | 117 | return QString::null; |
116 | 118 | ||
117 | QTextStream stream(&file); | 119 | Q3TextStream stream(&file); |
118 | 120 | ||
119 | return "{" + stream.read().stripWhiteSpace() + "}"; | 121 | return "{" + stream.read().stripWhiteSpace() + "}"; |
120 | } | 122 | } |
121 | 123 | ||
122 | int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) | 124 | int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) |
123 | { | 125 | { |
124 | return 0; | 126 | return 0; |
125 | } | 127 | } |
126 | 128 | ||
127 | QString AbstractMail::defaultLocalfolder() | 129 | QString AbstractMail::defaultLocalfolder() |
128 | { | 130 | { |
129 | // QString f = getenv( "HOME" ); | 131 | // QString f = getenv( "HOME" ); |
130 | QString f = locateLocal( "data", "kopiemail/localmail"); | 132 | QString f = locateLocal( "data", "kopiemail/localmail"); |
131 | // f += "/Applications/opiemail/localmail"; | 133 | // f += "/Applications/opiemail/localmail"; |
132 | return f; | 134 | return f; |
133 | } | 135 | } |
134 | 136 | ||
135 | QString AbstractMail::draftFolder() | 137 | QString AbstractMail::draftFolder() |
136 | { | 138 | { |
137 | return QString("Drafts"); | 139 | return QString("Drafts"); |
138 | } | 140 | } |
139 | 141 | ||
140 | /* temporary - will be removed when implemented in all classes */ | 142 | /* temporary - will be removed when implemented in all classes */ |
141 | void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) | 143 | void AbstractMail::deleteMails(const QString &,const Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &) |
142 | { | 144 | { |
143 | } | 145 | } |
144 | void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) | 146 | void AbstractMail::deleteMailList(const Q3ValueList<RecMailP>&target) |
145 | { | 147 | { |
146 | //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); | 148 | //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); |
147 | // this is currently re-implemented in pop3wrapper and imapwrapper | 149 | // this is currently re-implemented in pop3wrapper and imapwrapper |
148 | int iii = 0; | 150 | int iii = 0; |
149 | int count = target.count(); | 151 | int count = target.count(); |
150 | QProgressBar wid ( count ); | 152 | Q3ProgressBar wid ( count ); |
151 | wid.setCaption( i18n("Deleting ...")); | 153 | wid.setCaption( i18n("Deleting ...")); |
152 | wid.show(); | 154 | wid.show(); |
153 | while (iii < count ) { | 155 | while (iii < count ) { |
154 | Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); | 156 | Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); |
155 | wid.setProgress( iii ); | 157 | wid.setProgress( iii ); |
156 | wid.raise(); | 158 | wid.raise(); |
157 | qApp->processEvents(); | 159 | qApp->processEvents(); |
158 | RecMailP mail = (*target.at( iii )); | 160 | RecMailP mail = (*target.at( iii )); |
159 | deleteMail(mail); | 161 | deleteMail(mail); |
160 | ++iii; | 162 | ++iii; |
161 | } | 163 | } |
162 | } | 164 | } |
163 | 165 | ||
164 | void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail ) | 166 | void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail ) |
165 | { | 167 | { |
166 | //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1()); | 168 | //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1()); |
167 | // get local folder | 169 | // get local folder |
168 | Account * acc = getAccount(); | 170 | Account * acc = getAccount(); |
169 | if ( !acc ) return; | 171 | if ( !acc ) return; |
170 | QString lfName = acc->getLocalFolder(); | 172 | QString lfName = acc->getLocalFolder(); |
171 | if ( lfName.isEmpty() ) | 173 | if ( lfName.isEmpty() ) |
172 | lfName = acc->getAccountName(); | 174 | lfName = acc->getAccountName(); |
173 | // create local folder | 175 | // create local folder |
174 | if ( !targetMail->createMbox(lfName)) | 176 | if ( !targetMail->createMbox(lfName)) |
175 | { | 177 | { |
176 | QMessageBox::critical(0,i18n("Error creating new Folder"), | 178 | QMessageBox::critical(0,i18n("Error creating new Folder"), |
177 | i18n("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName)); | 179 | i18n("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName)); |
178 | return; | 180 | return; |
179 | } | 181 | } |
180 | QValueList<RecMailP> t; | 182 | Q3ValueList<RecMailP> t; |
181 | listMessages(fromFolder->getName(),t,acc->getMaxMailSize() ); | 183 | listMessages(fromFolder->getName(),t,acc->getMaxMailSize() ); |
182 | if ( t.count() == 0 ) { | 184 | if ( t.count() == 0 ) { |
183 | qDebug("There are no new messages %s", fromFolder->getName().latin1()); | 185 | qDebug("There are no new messages %s", fromFolder->getName().latin1()); |
184 | Global::statusMessage(i18n("There are no new messages")); | 186 | Global::statusMessage(i18n("There are no new messages")); |
185 | return; | 187 | return; |
186 | } | 188 | } |
187 | Global::statusMessage(i18n("%1 :Downloading mails..."). arg(acc->getAccountName())); | 189 | Global::statusMessage(i18n("%1 :Downloading mails..."). arg(acc->getAccountName())); |
188 | qDebug(i18n("%1 :Downloading mails..."). arg(acc->getAccountName())); | 190 | qDebug(i18n("%1 :Downloading mails..."). arg(acc->getAccountName())); |
189 | qApp->processEvents(); | 191 | qApp->processEvents(); |
190 | QValueList<RecMailP> e; | 192 | Q3ValueList<RecMailP> e; |
191 | targetMail->listMessages(lfName,e,acc->getMaxMailSize() ); | 193 | targetMail->listMessages(lfName,e,acc->getMaxMailSize() ); |
192 | //qDebug("target has mails %d ", e.count()); | 194 | //qDebug("target has mails %d ", e.count()); |
193 | QValueList<RecMailP> n; | 195 | Q3ValueList<RecMailP> n; |
194 | int iii = 0; | 196 | int iii = 0; |
195 | int count = t.count(); | 197 | int count = t.count(); |
196 | while (iii < count ) { | 198 | while (iii < count ) { |
197 | RecMailP r = (*t.at( iii )); | 199 | RecMailP r = (*t.at( iii )); |
198 | bool found = false; | 200 | bool found = false; |
199 | int jjj = 0; | 201 | int jjj = 0; |
200 | int countE = e.count(); | 202 | int countE = e.count(); |
201 | while (jjj < countE ) { | 203 | while (jjj < countE ) { |
202 | RecMailP re = (*e.at( jjj )); | 204 | RecMailP re = (*e.at( jjj )); |
203 | if ( re->isEqual(r) ) { | 205 | if ( re->isEqual(r) ) { |
204 | found = true; | 206 | found = true; |
205 | break; | 207 | break; |
206 | } | 208 | } |
207 | ++jjj; | 209 | ++jjj; |
208 | } | 210 | } |
209 | if ( !found ) { | 211 | if ( !found ) { |
210 | //qDebug("AAAdate *%s* ", r->isodate.latin1() ); | 212 | //qDebug("AAAdate *%s* ", r->isodate.latin1() ); |
211 | n.append( r ); | 213 | n.append( r ); |
212 | } | 214 | } |
213 | ++iii; | 215 | ++iii; |
214 | } | 216 | } |
215 | qDebug("Downloaded %d messages ",n.count() ); | 217 | qDebug("Downloaded %d messages ",n.count() ); |
216 | if ( n.count() == 0 ) { | 218 | if ( n.count() == 0 ) { |
217 | Global::statusMessage(i18n("There are no new messages")); | 219 | Global::statusMessage(i18n("There are no new messages")); |
218 | return; | 220 | return; |
219 | } | 221 | } |
220 | mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer()); | 222 | mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer()); |
221 | Global::statusMessage(i18n("Downloaded %1 messages").arg(n.count())); | 223 | Global::statusMessage(i18n("Downloaded %1 messages").arg(n.count())); |
222 | 224 | ||
223 | #if 0 | 225 | #if 0 |
224 | QValueList<RecMailP> t; | 226 | Q3ValueList<RecMailP> t; |
225 | listMessages(fromFolder->getName(),t, maxSizeInKb); | 227 | listMessages(fromFolder->getName(),t, maxSizeInKb); |
226 | mvcpMailList( t,targetFolder,targetWrapper,moveit); | 228 | mvcpMailList( t,targetFolder,targetWrapper,moveit); |
227 | #endif | 229 | #endif |
228 | 230 | ||
229 | } | 231 | } |
230 | void AbstractMail::mvcpAllMails(const FolderP&fromFolder, | 232 | void AbstractMail::mvcpAllMails(const FolderP&fromFolder, |
231 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) | 233 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) |
232 | { | 234 | { |
233 | QValueList<RecMailP> t; | 235 | Q3ValueList<RecMailP> t; |
234 | listMessages(fromFolder->getName(),t, maxSizeInKb); | 236 | listMessages(fromFolder->getName(),t, maxSizeInKb); |
235 | mvcpMailList( t,targetFolder,targetWrapper,moveit); | 237 | mvcpMailList( t,targetFolder,targetWrapper,moveit); |
236 | 238 | ||
237 | } | 239 | } |
238 | void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, | 240 | void AbstractMail::mvcpMailList(const Q3ValueList<RecMailP>& t, |
239 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 241 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
240 | { | 242 | { |
241 | encodedString*st = 0; | 243 | encodedString*st = 0; |
242 | int iii = 0; | 244 | int iii = 0; |
243 | int count = t.count(); | 245 | int count = t.count(); |
244 | if ( count == 0 ) | 246 | if ( count == 0 ) |
245 | return; | 247 | return; |
246 | // wel, processevents is qite strange, we need a widget for getting | 248 | // wel, processevents is qite strange, we need a widget for getting |
247 | // Global::statusMessage(i18n("Copy2 message %1").arg(iii)); displaye | 249 | // Global::statusMessage(i18n("Copy2 message %1").arg(iii)); displaye |
248 | 250 | ||
249 | QProgressBar wid ( count ); | 251 | Q3ProgressBar wid ( count ); |
250 | wid.setCaption( i18n("Copying...")); | 252 | wid.setCaption( i18n("Copying...")); |
251 | wid.show(); | 253 | wid.show(); |
252 | while (iii < count ) { | 254 | while (iii < count ) { |
253 | Global::statusMessage(i18n("Copy message %1 of %2").arg(iii).arg(count)); | 255 | Global::statusMessage(i18n("Copy message %1 of %2").arg(iii).arg(count)); |
254 | wid.setProgress( iii ); | 256 | wid.setProgress( iii ); |
255 | wid.raise(); | 257 | wid.raise(); |
256 | qApp->processEvents(); | 258 | qApp->processEvents(); |
257 | RecMailP r = (*t.at( iii )); | 259 | RecMailP r = (*t.at( iii )); |
258 | st = fetchRawBody(r); | 260 | st = fetchRawBody(r); |
259 | if (st) { | 261 | if (st) { |
260 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); | 262 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); |
261 | delete st; | 263 | delete st; |
262 | } | 264 | } |
263 | ++iii; | 265 | ++iii; |
264 | } | 266 | } |
265 | if (moveit) { | 267 | if (moveit) { |
266 | deleteMailList( t ); | 268 | deleteMailList( t ); |
267 | //deleteAllMail(fromFolder); | 269 | //deleteAllMail(fromFolder); |
268 | } | 270 | } |
269 | } | 271 | } |
270 | 272 | ||
271 | void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 273 | void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
272 | { | 274 | { |
273 | encodedString*st = 0; | 275 | encodedString*st = 0; |
274 | st = fetchRawBody(mail); | 276 | st = fetchRawBody(mail); |
275 | if (st) { | 277 | if (st) { |
276 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); | 278 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); |
277 | delete st; | 279 | delete st; |
278 | } | 280 | } |
279 | if (moveit) { | 281 | if (moveit) { |
280 | deleteMail(mail); | 282 | deleteMail(mail); |
281 | } | 283 | } |