author | zautrix <zautrix> | 2004-09-11 15:41:30 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-11 15:41:30 (UTC) |
commit | 32f9963a39236d08718a36d5adad2a0c5c4e2602 (patch) (unidiff) | |
tree | 8856a90d505df8dc3afa0d72541f27cb68913a0d /kmicromail/libmailwrapper/abstractmail.cpp | |
parent | d7a273f40838f56205c1377ed0bcc5457bd46ea3 (diff) | |
download | kdepimpi-32f9963a39236d08718a36d5adad2a0c5c4e2602.zip kdepimpi-32f9963a39236d08718a36d5adad2a0c5c4e2602.tar.gz kdepimpi-32f9963a39236d08718a36d5adad2a0c5c4e2602.tar.bz2 |
Mail enhancements
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,60 +1,61 @@ | |||
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) |
@@ -113,96 +114,162 @@ QString AbstractMail::gen_attachment_id() | |||
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); |