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