summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-11 16:02:52 (UTC)
committer zautrix <zautrix>2004-09-11 16:02:52 (UTC)
commit53e10fa5e66620ff1eba1c9d17738103ad511c91 (patch) (unidiff)
treec9ed39ce780dc3e8b9b7138781d77db793defdc9
parent32f9963a39236d08718a36d5adad2a0c5c4e2602 (diff)
downloadkdepimpi-53e10fa5e66620ff1eba1c9d17738103ad511c91.zip
kdepimpi-53e10fa5e66620ff1eba1c9d17738103ad511c91.tar.gz
kdepimpi-53e10fa5e66620ff1eba1c9d17738103ad511c91.tar.bz2
More mail enh.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/abstractmail.cpp11
-rw-r--r--kmicromail/libmailwrapper/genericwrapper.cpp16
2 files changed, 16 insertions, 11 deletions
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp
index 374d606..44878e0 100644
--- a/kmicromail/libmailwrapper/abstractmail.cpp
+++ b/kmicromail/libmailwrapper/abstractmail.cpp
@@ -1,277 +1,272 @@
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#include <qmessagebox.h>
14 14
15#include <kdecore/kstandarddirs.h> 15#include <kdecore/kstandarddirs.h>
16#include <qfile.h> 16#include <qfile.h>
17#include <qtextstream.h> 17#include <qtextstream.h>
18#include <stdlib.h> 18#include <stdlib.h>
19#include <libetpan/mailmime_content.h> 19#include <libetpan/mailmime_content.h>
20#include <libetpan/mailmime.h> 20#include <libetpan/mailmime.h>
21 21
22using namespace Opie::Core; 22using namespace Opie::Core;
23AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 23AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
24{ 24{
25 return new IMAPwrapper(a); 25 return new IMAPwrapper(a);
26} 26}
27 27
28AbstractMail* AbstractMail::getWrapper(POP3account *a) 28AbstractMail* AbstractMail::getWrapper(POP3account *a)
29{ 29{
30 return new POP3wrapper(a); 30 return new POP3wrapper(a);
31} 31}
32 32
33AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) 33AbstractMail* AbstractMail::getWrapper(NNTPaccount *a)
34{ 34{
35 return new NNTPwrapper(a); 35 return new NNTPwrapper(a);
36} 36}
37 37
38AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) 38AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
39{ 39{
40 return new MHwrapper(a,name); 40 return new MHwrapper(a,name);
41} 41}
42 42
43AbstractMail* AbstractMail::getWrapper(Account*a) 43AbstractMail* AbstractMail::getWrapper(Account*a)
44{ 44{
45 if (!a) return 0; 45 if (!a) return 0;
46 switch (a->getType()) { 46 switch (a->getType()) {
47 case MAILLIB::A_IMAP: 47 case MAILLIB::A_IMAP:
48 return new IMAPwrapper((IMAPaccount*)a); 48 return new IMAPwrapper((IMAPaccount*)a);
49 break; 49 break;
50 case MAILLIB::A_POP3: 50 case MAILLIB::A_POP3:
51 return new POP3wrapper((POP3account*)a); 51 return new POP3wrapper((POP3account*)a);
52 break; 52 break;
53 case MAILLIB::A_NNTP: 53 case MAILLIB::A_NNTP:
54 return new NNTPwrapper((NNTPaccount*)a); 54 return new NNTPwrapper((NNTPaccount*)a);
55 break; 55 break;
56 default: 56 default:
57 return 0; 57 return 0;
58 } 58 }
59} 59}
60 60
61encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 61encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
62{ 62{
63 // odebug << "Decode string start" << oendl; 63 // odebug << "Decode string start" << oendl;
64 char*result_text; 64 char*result_text;
65 size_t index = 0; 65 size_t index = 0;
66 /* reset for recursive use! */ 66 /* reset for recursive use! */
67 size_t target_length = 0; 67 size_t target_length = 0;
68 result_text = 0; 68 result_text = 0;
69 int mimetype = MAILMIME_MECHANISM_7BIT; 69 int mimetype = MAILMIME_MECHANISM_7BIT;
70 if (enc.lower()=="quoted-printable") { 70 if (enc.lower()=="quoted-printable") {
71 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 71 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
72 } else if (enc.lower()=="base64") { 72 } else if (enc.lower()=="base64") {
73 mimetype = MAILMIME_MECHANISM_BASE64; 73 mimetype = MAILMIME_MECHANISM_BASE64;
74 } else if (enc.lower()=="8bit") { 74 } else if (enc.lower()=="8bit") {
75 mimetype = MAILMIME_MECHANISM_8BIT; 75 mimetype = MAILMIME_MECHANISM_8BIT;
76 } else if (enc.lower()=="binary") { 76 } else if (enc.lower()=="binary") {
77 mimetype = MAILMIME_MECHANISM_BINARY; 77 mimetype = MAILMIME_MECHANISM_BINARY;
78 } 78 }
79 79
80 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 80 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
81 &result_text,&target_length); 81 &result_text,&target_length);
82 82
83 encodedString* result = new encodedString(); 83 encodedString* result = new encodedString();
84 if (err == MAILIMF_NO_ERROR) { 84 if (err == MAILIMF_NO_ERROR) {
85 result->setContent(result_text,target_length); 85 result->setContent(result_text,target_length);
86 } 86 }
87 //odebug << "Decode string finished" << oendl; 87 //odebug << "Decode string finished" << oendl;
88 return result; 88 return result;
89} 89}
90 90
91QString AbstractMail::convert_String(const char*text) 91QString AbstractMail::convert_String(const char*text)
92{ 92{
93 //size_t index = 0; 93 //size_t index = 0;
94 char*res = 0; 94 char*res = 0;
95 int err = MAILIMF_NO_ERROR; 95 int err = MAILIMF_NO_ERROR;
96 96
97 QString result(text); 97 QString result(text);
98 98
99 /* due a bug in libetpan it isn't usable this moment */ 99 /* due a bug in libetpan it isn't usable this moment */
100/* int err = mailmime_encoded_phrase_parse("iso-8859-1", 100/* int err = mailmime_encoded_phrase_parse("iso-8859-1",
101 text, strlen(text),&index, "iso-8859-1",&res);*/ 101 text, strlen(text),&index, "iso-8859-1",&res);*/
102 //odebug << "Input: " << text << "" << oendl; 102 //odebug << "Input: " << text << "" << oendl;
103 if (err == MAILIMF_NO_ERROR && res && strlen(res)) { 103 if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
104// result = QString(res); 104// result = QString(res);
105// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl; 105// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl;
106 } 106 }
107 if (res) free(res); 107 if (res) free(res);
108 return result; 108 return result;
109} 109}
110 110
111/* cp & paste from launcher */ 111/* cp & paste from launcher */
112QString AbstractMail::gen_attachment_id() 112QString AbstractMail::gen_attachment_id()
113{ 113{
114 QFile file( "/proc/sys/kernel/random/uuid" ); 114 QFile file( "/proc/sys/kernel/random/uuid" );
115 if (!file.open(IO_ReadOnly ) ) 115 if (!file.open(IO_ReadOnly ) )
116 return QString::null; 116 return QString::null;
117 117
118 QTextStream stream(&file); 118 QTextStream stream(&file);
119 119
120 return "{" + stream.read().stripWhiteSpace() + "}"; 120 return "{" + stream.read().stripWhiteSpace() + "}";
121} 121}
122 122
123int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) 123int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool)
124{ 124{
125 return 0; 125 return 0;
126} 126}
127 127
128QString AbstractMail::defaultLocalfolder() 128QString AbstractMail::defaultLocalfolder()
129{ 129{
130 // QString f = getenv( "HOME" ); 130 // QString f = getenv( "HOME" );
131 QString f = locateLocal( "data", "kopiemail/localmail"); 131 QString f = locateLocal( "data", "kopiemail/localmail");
132 // f += "/Applications/opiemail/localmail"; 132 // f += "/Applications/opiemail/localmail";
133 return f; 133 return f;
134} 134}
135 135
136QString AbstractMail::draftFolder() 136QString AbstractMail::draftFolder()
137{ 137{
138 return QString("Drafts"); 138 return QString("Drafts");
139} 139}
140 140
141/* temporary - will be removed when implemented in all classes */ 141/* temporary - will be removed when implemented in all classes */
142void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) 142void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &)
143{ 143{
144} 144}
145void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) 145void AbstractMail::deleteMailList(const QValueList<RecMailP>&target)
146{ 146{
147 //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); 147 //qDebug("AbstractMail::deleteMailList:: Please reimplement! ");
148 // this is currently re-implemented in pop3wrapper and imapwrapper 148 // this is currently re-implemented in pop3wrapper and imapwrapper
149 int iii = 0; 149 int iii = 0;
150 int count = target.count(); 150 int count = target.count();
151 QWidget wid; 151 QWidget wid;
152 wid.show(); 152 wid.show();
153 while (iii < count ) { 153 while (iii < count ) {
154 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));
155 wid.raise(); 155 wid.raise();
156 qApp->processEvents(); 156 qApp->processEvents();
157 RecMailP mail = (*target.at( iii )); 157 RecMailP mail = (*target.at( iii ));
158 deleteMail(mail); 158 deleteMail(mail);
159 ++iii; 159 ++iii;
160 } 160 }
161} 161}
162 162
163void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail ) 163void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail )
164{ 164{
165 qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1()); 165 //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1());
166 // get local folder 166 // get local folder
167 Account * acc = getAccount(); 167 Account * acc = getAccount();
168 if ( !acc ) return; 168 if ( !acc ) return;
169 QString lfName = acc->getLocalFolder(); 169 QString lfName = acc->getLocalFolder();
170 if ( lfName.isEmpty() ) 170 if ( lfName.isEmpty() )
171 lfName = acc->getAccountName(); 171 lfName = acc->getAccountName();
172 // create local folder 172 // create local folder
173 if ( !targetMail->createMbox(lfName)) 173 if ( !targetMail->createMbox(lfName))
174 { 174 {
175 QMessageBox::critical(0,tr("Error creating new Folder"), 175 QMessageBox::critical(0,tr("Error creating new Folder"),
176 tr("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName)); 176 tr("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName));
177 return; 177 return;
178 } 178 }
179 QValueList<RecMailP> t; 179 QValueList<RecMailP> t;
180 listMessages(fromFolder->getName(),t,acc->getMaxMailSize() ); 180 listMessages(fromFolder->getName(),t,acc->getMaxMailSize() );
181 if ( t.count() == 0 ) { 181 if ( t.count() == 0 ) {
182 Global::statusMessage(tr("There are no new messages")); 182 Global::statusMessage(tr("There are no new messages"));
183 return; 183 return;
184 } 184 }
185 QValueList<RecMailP> e; 185 QValueList<RecMailP> e;
186 targetMail->listMessages(lfName,e,acc->getMaxMailSize() ); 186 targetMail->listMessages(lfName,e,acc->getMaxMailSize() );
187 qDebug("target has mails %d ", e.count()); 187 //qDebug("target has mails %d ", e.count());
188 QValueList<RecMailP> n; 188 QValueList<RecMailP> n;
189 int iii = 0; 189 int iii = 0;
190 int count = t.count(); 190 int count = t.count();
191 while (iii < count ) { 191 while (iii < count ) {
192 RecMailP r = (*t.at( iii )); 192 RecMailP r = (*t.at( iii ));
193 bool found = false; 193 bool found = false;
194 int jjj = 0; 194 int jjj = 0;
195 int countE = e.count(); 195 int countE = e.count();
196 while (jjj < countE ) { 196 while (jjj < countE ) {
197 RecMailP re = (*e.at( jjj )); 197 RecMailP re = (*e.at( jjj ));
198 if ( re->isEqual(r) ) { 198 if ( re->isEqual(r) ) {
199 found = true; 199 found = true;
200 break; 200 break;
201 } 201 }
202 ++jjj; 202 ++jjj;
203 } 203 }
204 if ( found )
205 qDebug("found ");
206 else
207 qDebug("NOT found ");
208
209 if ( !found ) { 204 if ( !found ) {
210 n.append( r ); 205 n.append( r );
211 } 206 }
212 ++iii; 207 ++iii;
213 } 208 }
214 if ( n.count() == 0 ) { 209 if ( n.count() == 0 ) {
215 Global::statusMessage(tr("There are no new messages")); 210 Global::statusMessage(tr("There are no new messages"));
216 return; 211 return;
217 } 212 }
218 mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer()); 213 mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer());
219 214 Global::statusMessage(tr("Downloaded %1 messages").arg(n.count()));
220 215
221#if 0 216#if 0
222 QValueList<RecMailP> t; 217 QValueList<RecMailP> t;
223 listMessages(fromFolder->getName(),t, maxSizeInKb); 218 listMessages(fromFolder->getName(),t, maxSizeInKb);
224 mvcpMailList( t,targetFolder,targetWrapper,moveit); 219 mvcpMailList( t,targetFolder,targetWrapper,moveit);
225#endif 220#endif
226 221
227} 222}
228void AbstractMail::mvcpAllMails(const FolderP&fromFolder, 223void AbstractMail::mvcpAllMails(const FolderP&fromFolder,
229 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 224 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
230{ 225{
231 QValueList<RecMailP> t; 226 QValueList<RecMailP> t;
232 listMessages(fromFolder->getName(),t, maxSizeInKb); 227 listMessages(fromFolder->getName(),t, maxSizeInKb);
233 mvcpMailList( t,targetFolder,targetWrapper,moveit); 228 mvcpMailList( t,targetFolder,targetWrapper,moveit);
234 229
235} 230}
236void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, 231void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t,
237 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 232 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
238{ 233{
239 encodedString*st = 0; 234 encodedString*st = 0;
240 int iii = 0; 235 int iii = 0;
241 int count = t.count(); 236 int count = t.count();
242 if ( count == 0 ) 237 if ( count == 0 )
243 return; 238 return;
244 // wel, processevents is qite strange, we need a widget for getting 239 // wel, processevents is qite strange, we need a widget for getting
245 // Global::statusMessage(tr("Copy2 message %1").arg(iii)); displayed 240 // Global::statusMessage(tr("Copy2 message %1").arg(iii)); displayed
246 QWidget wid; 241 QWidget wid;
247 wid.show(); 242 wid.show();
248 while (iii < count ) { 243 while (iii < count ) {
249 Global::statusMessage(tr("Copy message %1 of %2").arg(iii).arg(count)); 244 Global::statusMessage(tr("Copy message %1 of %2").arg(iii).arg(count));
250 wid.raise(); 245 wid.raise();
251 qApp->processEvents(); 246 qApp->processEvents();
252 RecMailP r = (*t.at( iii )); 247 RecMailP r = (*t.at( iii ));
253 st = fetchRawBody(r); 248 st = fetchRawBody(r);
254 if (st) { 249 if (st) {
255 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 250 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
256 delete st; 251 delete st;
257 } 252 }
258 ++iii; 253 ++iii;
259 } 254 }
260 if (moveit) { 255 if (moveit) {
261 deleteMailList( t ); 256 deleteMailList( t );
262 //deleteAllMail(fromFolder); 257 //deleteAllMail(fromFolder);
263 } 258 }
264} 259}
265 260
266void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 261void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
267{ 262{
268 encodedString*st = 0; 263 encodedString*st = 0;
269 st = fetchRawBody(mail); 264 st = fetchRawBody(mail);
270 if (st) { 265 if (st) {
271 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 266 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
272 delete st; 267 delete st;
273 } 268 }
274 if (moveit) { 269 if (moveit) {
275 deleteMail(mail); 270 deleteMail(mail);
276 } 271 }
277} 272}
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp
index 2b04847..ed591fc 100644
--- a/kmicromail/libmailwrapper/genericwrapper.cpp
+++ b/kmicromail/libmailwrapper/genericwrapper.cpp
@@ -1,521 +1,531 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include "genericwrapper.h" 2#include "genericwrapper.h"
3#include <libetpan/libetpan.h> 3#include <libetpan/libetpan.h>
4#include "mailtypes.h" 4#include "mailtypes.h"
5 5
6#include <kconfig.h> 6#include <kconfig.h>
7#include <kglobal.h> 7#include <kglobal.h>
8#include <kstandarddirs.h> 8#include <kstandarddirs.h>
9 9
10 10
11using namespace Opie::Core; 11using namespace Opie::Core;
12Genericwrapper::Genericwrapper() 12Genericwrapper::Genericwrapper()
13 : AbstractMail() 13 : AbstractMail()
14{ 14{
15 bodyCache.clear(); 15 bodyCache.clear();
16 m_storage = 0; 16 m_storage = 0;
17 m_folder = 0; 17 m_folder = 0;
18} 18}
19 19
20Genericwrapper::~Genericwrapper() 20Genericwrapper::~Genericwrapper()
21{ 21{
22 if (m_folder) { 22 if (m_folder) {
23 mailfolder_free(m_folder); 23 mailfolder_free(m_folder);
24 } 24 }
25 if (m_storage) { 25 if (m_storage) {
26 mailstorage_free(m_storage); 26 mailstorage_free(m_storage);
27 } 27 }
28 cleanMimeCache(); 28 cleanMimeCache();
29} 29}
30QString Genericwrapper::parseDateTime( mailimf_date_time *date ) 30QString Genericwrapper::parseDateTime( mailimf_date_time *date )
31{ 31{
32 static bool init = false ; 32 static bool init = false ;
33 if ( ! init ) { 33 if ( ! init ) {
34 KConfig kon ( locateLocal( "config", "korganizerrc" ) ); 34 KConfig kon ( locateLocal( "config", "korganizerrc" ) );
35 kon.setGroup("Locale"); 35 kon.setGroup("Locale");
36 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)kon.readNumEntry( "PreferredDate",0) ); 36 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)kon.readNumEntry( "PreferredDate",0) );
37 QString dummy = kon.readEntry( "UserDateFormatShort","%aK %d.%m.%y" );// kon.readEntry( ""); 37 QString dummy = kon.readEntry( "UserDateFormatShort","%aK %d.%m.%y" );// kon.readEntry( "");
38 KGlobal::locale()->setHore24Format( !kon.readBoolEntry( "PreferredTime",0 ) ); 38 KGlobal::locale()->setHore24Format( !kon.readBoolEntry( "PreferredTime",0 ) );
39 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 39 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
40 kon.setGroup("Time & Date"); 40 kon.setGroup("Time & Date");
41 KGlobal::locale()->setDaylightSaving( kon.readBoolEntry( "UseDaylightsaving", true ), 41 KGlobal::locale()->setDaylightSaving( kon.readBoolEntry( "UseDaylightsaving", true ),
42 kon.readNumEntry( "DaylightsavingStart", 90), 42 kon.readNumEntry( "DaylightsavingStart", 90),
43 kon.readNumEntry( "DaylightsavingEnd",304) ); 43 kon.readNumEntry( "DaylightsavingEnd",304) );
44 KGlobal::locale()->setTimezone( kon.readEntry( "TimeZoneName" ," 00:00 Europe/London(UTC)") ); 44 KGlobal::locale()->setTimezone( kon.readEntry( "TimeZoneName" ," 00:00 Europe/London(UTC)") );
45 45
46 init = true; 46 init = true;
47 47
48 } 48 }
49 QDateTime dt (QDate(date->dt_year,date->dt_month, date->dt_day ),QTime(date->dt_hour, date->dt_min, date->dt_sec ) ); 49 QDate da (date->dt_year,date->dt_month, date->dt_day );
50 QTime ti ( date->dt_hour, date->dt_min, date->dt_sec );
51 QDateTime dt ( da ,ti );
50 int off = KGlobal::locale()->localTimeOffset( dt ); 52 int off = KGlobal::locale()->localTimeOffset( dt );
51 dt = dt.addSecs( off*60 ); 53 //dt = dt.addSecs( off*60 );
52 QString ret = KGlobal::locale()->formatDateTime( dt,true,true); 54 QString ret;
55 if ( da == QDate::currentDate () )
56 ret = KGlobal::locale()->formatTime( ti,true);
57
58 else {
59 ret = KGlobal::locale()->formatDateTime( dt,true,true);
60 }
61#if 0
53 if ( off < 0 ) 62 if ( off < 0 )
54 ret += " -"; 63 ret += " -";
55 else 64 else
56 ret += " +"; 65 ret += " +";
57 ret += QString::number( off / 60 ); 66 ret += QString::number( off / 60 );
58 ret += "h"; 67 ret += "h";
68#endif
59#if 0 69#if 0
60 char tmp[23]; 70 char tmp[23];
61 71
62 // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 72 // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
63 // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 73 // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
64 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i", 74 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i",
65 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 75 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
66 76
67 77
68 return QString( tmp ); 78 return QString( tmp );
69#endif 79#endif
70 return ret; 80 return ret;
71} 81}
72 82
73void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) 83void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime)
74{ 84{
75 if (!mime) { 85 if (!mime) {
76 return; 86 return;
77 } 87 }
78 mailmime_field*field = 0; 88 mailmime_field*field = 0;
79 mailmime_single_fields fields; 89 mailmime_single_fields fields;
80 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 90 memset(&fields, 0, sizeof(struct mailmime_single_fields));
81 if (mime->mm_mime_fields != NULL) { 91 if (mime->mm_mime_fields != NULL) {
82 mailmime_single_fields_init(&fields, mime->mm_mime_fields, 92 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
83 mime->mm_content_type); 93 mime->mm_content_type);
84 } 94 }
85 95
86 mailmime_content*type = fields.fld_content; 96 mailmime_content*type = fields.fld_content;
87 clistcell*current; 97 clistcell*current;
88 if (!type) { 98 if (!type) {
89 target->setType("text"); 99 target->setType("text");
90 target->setSubtype("plain"); 100 target->setSubtype("plain");
91 } else { 101 } else {
92 target->setSubtype(type->ct_subtype); 102 target->setSubtype(type->ct_subtype);
93 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { 103 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
94 case MAILMIME_DISCRETE_TYPE_TEXT: 104 case MAILMIME_DISCRETE_TYPE_TEXT:
95 target->setType("text"); 105 target->setType("text");
96 break; 106 break;
97 case MAILMIME_DISCRETE_TYPE_IMAGE: 107 case MAILMIME_DISCRETE_TYPE_IMAGE:
98 target->setType("image"); 108 target->setType("image");
99 break; 109 break;
100 case MAILMIME_DISCRETE_TYPE_AUDIO: 110 case MAILMIME_DISCRETE_TYPE_AUDIO:
101 target->setType("audio"); 111 target->setType("audio");
102 break; 112 break;
103 case MAILMIME_DISCRETE_TYPE_VIDEO: 113 case MAILMIME_DISCRETE_TYPE_VIDEO:
104 target->setType("video"); 114 target->setType("video");
105 break; 115 break;
106 case MAILMIME_DISCRETE_TYPE_APPLICATION: 116 case MAILMIME_DISCRETE_TYPE_APPLICATION:
107 target->setType("application"); 117 target->setType("application");
108 break; 118 break;
109 case MAILMIME_DISCRETE_TYPE_EXTENSION: 119 case MAILMIME_DISCRETE_TYPE_EXTENSION:
110 default: 120 default:
111 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { 121 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
112 target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); 122 target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension);
113 } 123 }
114 break; 124 break;
115 } 125 }
116 if (type->ct_parameters) { 126 if (type->ct_parameters) {
117 fillParameters(target,type->ct_parameters); 127 fillParameters(target,type->ct_parameters);
118 } 128 }
119 } 129 }
120 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { 130 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
121 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { 131 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) {
122 field = (mailmime_field*)current->data; 132 field = (mailmime_field*)current->data;
123 switch(field->fld_type) { 133 switch(field->fld_type) {
124 case MAILMIME_FIELD_TRANSFER_ENCODING: 134 case MAILMIME_FIELD_TRANSFER_ENCODING:
125 target->setEncoding(getencoding(field->fld_data.fld_encoding)); 135 target->setEncoding(getencoding(field->fld_data.fld_encoding));
126 break; 136 break;
127 case MAILMIME_FIELD_ID: 137 case MAILMIME_FIELD_ID:
128 target->setIdentifier(field->fld_data.fld_id); 138 target->setIdentifier(field->fld_data.fld_id);
129 break; 139 break;
130 case MAILMIME_FIELD_DESCRIPTION: 140 case MAILMIME_FIELD_DESCRIPTION:
131 target->setDescription(field->fld_data.fld_description); 141 target->setDescription(field->fld_data.fld_description);
132 break; 142 break;
133 default: 143 default:
134 break; 144 break;
135 } 145 }
136 } 146 }
137 } 147 }
138} 148}
139 149
140void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) 150void Genericwrapper::fillParameters(RecPartP&target,clist*parameters)
141{ 151{
142 if (!parameters) {return;} 152 if (!parameters) {return;}
143 clistcell*current=0; 153 clistcell*current=0;
144 mailmime_parameter*param; 154 mailmime_parameter*param;
145 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { 155 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
146 param = (mailmime_parameter*)current->data; 156 param = (mailmime_parameter*)current->data;
147 if (param) { 157 if (param) {
148 target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 158 target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
149 } 159 }
150 } 160 }
151} 161}
152 162
153QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) 163QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
154{ 164{
155 QString enc="7bit"; 165 QString enc="7bit";
156 if (!aEnc) return enc; 166 if (!aEnc) return enc;
157 switch(aEnc->enc_type) { 167 switch(aEnc->enc_type) {
158 case MAILMIME_MECHANISM_7BIT: 168 case MAILMIME_MECHANISM_7BIT:
159 enc = "7bit"; 169 enc = "7bit";
160 break; 170 break;
161 case MAILMIME_MECHANISM_8BIT: 171 case MAILMIME_MECHANISM_8BIT:
162 enc = "8bit"; 172 enc = "8bit";
163 break; 173 break;
164 case MAILMIME_MECHANISM_BINARY: 174 case MAILMIME_MECHANISM_BINARY:
165 enc = "binary"; 175 enc = "binary";
166 break; 176 break;
167 case MAILMIME_MECHANISM_QUOTED_PRINTABLE: 177 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
168 enc = "quoted-printable"; 178 enc = "quoted-printable";
169 break; 179 break;
170 case MAILMIME_MECHANISM_BASE64: 180 case MAILMIME_MECHANISM_BASE64:
171 enc = "base64"; 181 enc = "base64";
172 break; 182 break;
173 case MAILMIME_MECHANISM_TOKEN: 183 case MAILMIME_MECHANISM_TOKEN:
174 default: 184 default:
175 if (aEnc->enc_token) { 185 if (aEnc->enc_token) {
176 enc = QString(aEnc->enc_token); 186 enc = QString(aEnc->enc_token);
177 } 187 }
178 break; 188 break;
179 } 189 }
180 return enc; 190 return enc;
181} 191}
182 192
183void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) 193void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count)
184{ 194{
185 if (current_rec >= 10) { 195 if (current_rec >= 10) {
186 ; // odebug << "too deep recursion!" << oendl; 196 ; // odebug << "too deep recursion!" << oendl;
187 } 197 }
188 if (!message || !mime) { 198 if (!message || !mime) {
189 return; 199 return;
190 } 200 }
191 int r; 201 int r;
192 char*data = 0; 202 char*data = 0;
193 size_t len; 203 size_t len;
194 clistiter * cur = 0; 204 clistiter * cur = 0;
195 QString b; 205 QString b;
196 RecPartP part = new RecPart(); 206 RecPartP part = new RecPart();
197 207
198 switch (mime->mm_type) { 208 switch (mime->mm_type) {
199 case MAILMIME_SINGLE: 209 case MAILMIME_SINGLE:
200 { 210 {
201 QValueList<int>countlist = recList; 211 QValueList<int>countlist = recList;
202 countlist.append(current_count); 212 countlist.append(current_count);
203 r = mailmessage_fetch_section(message,mime,&data,&len); 213 r = mailmessage_fetch_section(message,mime,&data,&len);
204 part->setSize(len); 214 part->setSize(len);
205 part->setPositionlist(countlist); 215 part->setPositionlist(countlist);
206 b = gen_attachment_id(); 216 b = gen_attachment_id();
207 part->setIdentifier(b); 217 part->setIdentifier(b);
208 fillSingleBody(part,message,mime); 218 fillSingleBody(part,message,mime);
209 if (part->Type()=="text" && target->Bodytext().isNull()) { 219 if (part->Type()=="text" && target->Bodytext().isNull()) {
210 encodedString*rs = new encodedString(); 220 encodedString*rs = new encodedString();
211 rs->setContent(data,len); 221 rs->setContent(data,len);
212 encodedString*res = decode_String(rs,part->Encoding()); 222 encodedString*res = decode_String(rs,part->Encoding());
213 if (countlist.count()>2) { 223 if (countlist.count()>2) {
214 bodyCache[b]=rs; 224 bodyCache[b]=rs;
215 target->addPart(part); 225 target->addPart(part);
216 } else { 226 } else {
217 delete rs; 227 delete rs;
218 } 228 }
219 b = QString(res->Content()); 229 b = QString(res->Content());
220 delete res; 230 delete res;
221 target->setBodytext(b); 231 target->setBodytext(b);
222 target->setDescription(part); 232 target->setDescription(part);
223 } else { 233 } else {
224 bodyCache[b]=new encodedString(data,len); 234 bodyCache[b]=new encodedString(data,len);
225 target->addPart(part); 235 target->addPart(part);
226 } 236 }
227 } 237 }
228 break; 238 break;
229 case MAILMIME_MULTIPLE: 239 case MAILMIME_MULTIPLE:
230 { 240 {
231 unsigned int ccount = 1; 241 unsigned int ccount = 1;
232 mailmime*cbody=0; 242 mailmime*cbody=0;
233 QValueList<int>countlist = recList; 243 QValueList<int>countlist = recList;
234 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { 244 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
235 cbody = (mailmime*)clist_content(cur); 245 cbody = (mailmime*)clist_content(cur);
236 if (cbody->mm_type==MAILMIME_MULTIPLE) { 246 if (cbody->mm_type==MAILMIME_MULTIPLE) {
237 RecPartP targetPart = new RecPart(); 247 RecPartP targetPart = new RecPart();
238 targetPart->setType("multipart"); 248 targetPart->setType("multipart");
239 countlist.append(current_count); 249 countlist.append(current_count);
240 targetPart->setPositionlist(countlist); 250 targetPart->setPositionlist(countlist);
241 target->addPart(targetPart); 251 target->addPart(targetPart);
242 } 252 }
243 traverseBody(target,message, cbody,countlist,current_rec+1,ccount); 253 traverseBody(target,message, cbody,countlist,current_rec+1,ccount);
244 if (cbody->mm_type==MAILMIME_MULTIPLE) { 254 if (cbody->mm_type==MAILMIME_MULTIPLE) {
245 countlist = recList; 255 countlist = recList;
246 } 256 }
247 ++ccount; 257 ++ccount;
248 } 258 }
249 } 259 }
250 break; 260 break;
251 case MAILMIME_MESSAGE: 261 case MAILMIME_MESSAGE:
252 { 262 {
253 QValueList<int>countlist = recList; 263 QValueList<int>countlist = recList;
254 countlist.append(current_count); 264 countlist.append(current_count);
255 /* the own header is always at recursion 0 - we don't need that */ 265 /* the own header is always at recursion 0 - we don't need that */
256 if (current_rec > 0) { 266 if (current_rec > 0) {
257 part->setPositionlist(countlist); 267 part->setPositionlist(countlist);
258 r = mailmessage_fetch_section(message,mime,&data,&len); 268 r = mailmessage_fetch_section(message,mime,&data,&len);
259 part->setSize(len); 269 part->setSize(len);
260 part->setPositionlist(countlist); 270 part->setPositionlist(countlist);
261 b = gen_attachment_id(); 271 b = gen_attachment_id();
262 part->setIdentifier(b); 272 part->setIdentifier(b);
263 part->setType("message"); 273 part->setType("message");
264 part->setSubtype("rfc822"); 274 part->setSubtype("rfc822");
265 bodyCache[b]=new encodedString(data,len); 275 bodyCache[b]=new encodedString(data,len);
266 target->addPart(part); 276 target->addPart(part);
267 } 277 }
268 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 278 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
269 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); 279 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1);
270 } 280 }
271 } 281 }
272 break; 282 break;
273 } 283 }
274} 284}
275 285
276RecBodyP Genericwrapper::parseMail( mailmessage * msg ) 286RecBodyP Genericwrapper::parseMail( mailmessage * msg )
277{ 287{
278 int err = MAILIMF_NO_ERROR; 288 int err = MAILIMF_NO_ERROR;
279 mailmime_single_fields fields; 289 mailmime_single_fields fields;
280 /* is bound to msg and will be freed there */ 290 /* is bound to msg and will be freed there */
281 mailmime * mime=0; 291 mailmime * mime=0;
282 RecBodyP body = new RecBody(); 292 RecBodyP body = new RecBody();
283 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 293 memset(&fields, 0, sizeof(struct mailmime_single_fields));
284 err = mailmessage_get_bodystructure(msg,&mime); 294 err = mailmessage_get_bodystructure(msg,&mime);
285 QValueList<int>recList; 295 QValueList<int>recList;
286 traverseBody(body,msg,mime,recList); 296 traverseBody(body,msg,mime,recList);
287 return body; 297 return body;
288} 298}
289 299
290 300
291QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 301QString Genericwrapper::parseAddressList( mailimf_address_list *list )
292{ 302{
293 QString result( "" ); 303 QString result( "" );
294 304
295 bool first = true; 305 bool first = true;
296 if (list == 0) return result; 306 if (list == 0) return result;
297 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 307 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
298 mailimf_address *addr = (mailimf_address *) current->data; 308 mailimf_address *addr = (mailimf_address *) current->data;
299 309
300 if ( !first ) { 310 if ( !first ) {
301 result.append( "," ); 311 result.append( "," );
302 } else { 312 } else {
303 first = false; 313 first = false;
304 } 314 }
305 315
306 switch ( addr->ad_type ) { 316 switch ( addr->ad_type ) {
307 case MAILIMF_ADDRESS_MAILBOX: 317 case MAILIMF_ADDRESS_MAILBOX:
308 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 318 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
309 break; 319 break;
310 case MAILIMF_ADDRESS_GROUP: 320 case MAILIMF_ADDRESS_GROUP:
311 result.append( parseGroup( addr->ad_data.ad_group ) ); 321 result.append( parseGroup( addr->ad_data.ad_group ) );
312 break; 322 break;
313 default: 323 default:
314 ; // odebug << "Generic: unkown mailimf address type" << oendl; 324 ; // odebug << "Generic: unkown mailimf address type" << oendl;
315 break; 325 break;
316 } 326 }
317 } 327 }
318 328
319 return result; 329 return result;
320} 330}
321 331
322QString Genericwrapper::parseGroup( mailimf_group *group ) 332QString Genericwrapper::parseGroup( mailimf_group *group )
323{ 333{
324 QString result( "" ); 334 QString result( "" );
325 335
326 result.append( group->grp_display_name ); 336 result.append( group->grp_display_name );
327 result.append( ": " ); 337 result.append( ": " );
328 338
329 if ( group->grp_mb_list != NULL ) { 339 if ( group->grp_mb_list != NULL ) {
330 result.append( parseMailboxList( group->grp_mb_list ) ); 340 result.append( parseMailboxList( group->grp_mb_list ) );
331 } 341 }
332 342
333 result.append( ";" ); 343 result.append( ";" );
334 344
335 return result; 345 return result;
336} 346}
337 347
338QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) 348QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
339{ 349{
340 QString result( "" ); 350 QString result( "" );
341 351
342 if ( box->mb_display_name == NULL ) { 352 if ( box->mb_display_name == NULL ) {
343 result.append( box->mb_addr_spec ); 353 result.append( box->mb_addr_spec );
344 } else { 354 } else {
345 result.append( convert_String(box->mb_display_name).latin1() ); 355 result.append( convert_String(box->mb_display_name).latin1() );
346 result.append( " <" ); 356 result.append( " <" );
347 result.append( box->mb_addr_spec ); 357 result.append( box->mb_addr_spec );
348 result.append( ">" ); 358 result.append( ">" );
349 } 359 }
350 360
351 return result; 361 return result;
352} 362}
353 363
354QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) 364QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
355{ 365{
356 QString result( "" ); 366 QString result( "" );
357 367
358 bool first = true; 368 bool first = true;
359 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 369 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
360 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 370 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
361 371
362 if ( !first ) { 372 if ( !first ) {
363 result.append( "," ); 373 result.append( "," );
364 } else { 374 } else {
365 first = false; 375 first = false;
366 } 376 }
367 377
368 result.append( parseMailbox( box ) ); 378 result.append( parseMailbox( box ) );
369 } 379 }
370 380
371 return result; 381 return result;
372} 382}
373 383
374encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) 384encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part)
375{ 385{
376 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); 386 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier());
377 if (it==bodyCache.end()) return new encodedString(); 387 if (it==bodyCache.end()) return new encodedString();
378 encodedString*t = decode_String(it.data(),part->Encoding()); 388 encodedString*t = decode_String(it.data(),part->Encoding());
379 return t; 389 return t;
380} 390}
381 391
382encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) 392encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part)
383{ 393{
384 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); 394 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier());
385 if (it==bodyCache.end()) return new encodedString(); 395 if (it==bodyCache.end()) return new encodedString();
386 encodedString*t = it.data(); 396 encodedString*t = it.data();
387 return t; 397 return t;
388} 398}
389 399
390QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 400QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
391{ 401{
392 encodedString*t = fetchDecodedPart(mail,part); 402 encodedString*t = fetchDecodedPart(mail,part);
393 QString text=t->Content(); 403 QString text=t->Content();
394 delete t; 404 delete t;
395 return text; 405 return text;
396} 406}
397 407
398void Genericwrapper::cleanMimeCache() 408void Genericwrapper::cleanMimeCache()
399{ 409{
400 QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); 410 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
401 for (;it!=bodyCache.end();++it) { 411 for (;it!=bodyCache.end();++it) {
402 encodedString*t = it.data(); 412 encodedString*t = it.data();
403 //it.setValue(0); 413 //it.setValue(0);
404 if (t) delete t; 414 if (t) delete t;
405 } 415 }
406 bodyCache.clear(); 416 bodyCache.clear();
407 ; // odebug << "Genericwrapper: cache cleaned" << oendl; 417 ; // odebug << "Genericwrapper: cache cleaned" << oendl;
408} 418}
409 419
410QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) 420QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies)
411{ 421{
412 QStringList res; 422 QStringList res;
413 if (!in_replies || !in_replies->mid_list) return res; 423 if (!in_replies || !in_replies->mid_list) return res;
414 clistiter * current = 0; 424 clistiter * current = 0;
415 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { 425 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) {
416 QString h((char*)current->data); 426 QString h((char*)current->data);
417 while (h.length()>0 && h[0]=='<') { 427 while (h.length()>0 && h[0]=='<') {
418 h.remove(0,1); 428 h.remove(0,1);
419 } 429 }
420 while (h.length()>0 && h[h.length()-1]=='>') { 430 while (h.length()>0 && h[h.length()-1]=='>') {
421 h.remove(h.length()-1,1); 431 h.remove(h.length()-1,1);
422 } 432 }
423 if (h.length()>0) { 433 if (h.length()>0) {
424 res.append(h); 434 res.append(h);
425 } 435 }
426 } 436 }
427 return res; 437 return res;
428} 438}
429 439
430void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) 440void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb)
431{ 441{
432 int r; 442 int r;
433 mailmessage_list * env_list = 0; 443 mailmessage_list * env_list = 0;
434 r = mailsession_get_messages_list(session,&env_list); 444 r = mailsession_get_messages_list(session,&env_list);
435 if (r != MAIL_NO_ERROR) { 445 if (r != MAIL_NO_ERROR) {
436 ; // odebug << "Error message list" << oendl; 446 ; // odebug << "Error message list" << oendl;
437 return; 447 return;
438 } 448 }
439 r = mailsession_get_envelopes_list(session, env_list); 449 r = mailsession_get_envelopes_list(session, env_list);
440 if (r != MAIL_NO_ERROR) { 450 if (r != MAIL_NO_ERROR) {
441 ; // odebug << "Error filling message list" << oendl; 451 ; // odebug << "Error filling message list" << oendl;
442 if (env_list) { 452 if (env_list) {
443 mailmessage_list_free(env_list); 453 mailmessage_list_free(env_list);
444 } 454 }
445 return; 455 return;
446 } 456 }
447 mailimf_references * refs = 0; 457 mailimf_references * refs = 0;
448 mailimf_in_reply_to * in_replies = 0; 458 mailimf_in_reply_to * in_replies = 0;
449 uint32_t i = 0; 459 uint32_t i = 0;
450 for(; i < carray_count(env_list->msg_tab) ; ++i) { 460 for(; i < carray_count(env_list->msg_tab) ; ++i) {
451 mailmessage * msg; 461 mailmessage * msg;
452 QBitArray mFlags(7); 462 QBitArray mFlags(7);
453 msg = (mailmessage*)carray_get(env_list->msg_tab, i); 463 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
454 if (msg->msg_fields == NULL) { 464 if (msg->msg_fields == NULL) {
455 //; // odebug << "could not fetch envelope of message " << i << "" << oendl; 465 //; // odebug << "could not fetch envelope of message " << i << "" << oendl;
456 continue; 466 continue;
457 } 467 }
458 RecMailP mail = new RecMail(); 468 RecMailP mail = new RecMail();
459 mail->setWrapper(this); 469 mail->setWrapper(this);
460 mail_flags * flag_result = 0; 470 mail_flags * flag_result = 0;
461 r = mailmessage_get_flags(msg,&flag_result); 471 r = mailmessage_get_flags(msg,&flag_result);
462 if (r == MAIL_ERROR_NOT_IMPLEMENTED) { 472 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
463 mFlags.setBit(FLAG_SEEN); 473 mFlags.setBit(FLAG_SEEN);
464 } 474 }
465 mailimf_single_fields single_fields; 475 mailimf_single_fields single_fields;
466 mailimf_single_fields_init(&single_fields, msg->msg_fields); 476 mailimf_single_fields_init(&single_fields, msg->msg_fields);
467 mail->setMsgsize(msg->msg_size); 477 mail->setMsgsize(msg->msg_size);
468 mail->setFlags(mFlags); 478 mail->setFlags(mFlags);
469 mail->setMbox(mailbox); 479 mail->setMbox(mailbox);
470 mail->setNumber(msg->msg_index); 480 mail->setNumber(msg->msg_index);
471 if (single_fields.fld_subject) 481 if (single_fields.fld_subject)
472 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); 482 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
473 if (single_fields.fld_from) 483 if (single_fields.fld_from)
474 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); 484 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
475 if (!mbox_as_to) { 485 if (!mbox_as_to) {
476 if (single_fields.fld_to) 486 if (single_fields.fld_to)
477 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); 487 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
478 } else { 488 } else {
479 mail->setTo(mailbox); 489 mail->setTo(mailbox);
480 } 490 }
481 if (single_fields.fld_cc) 491 if (single_fields.fld_cc)
482 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); 492 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
483 if (single_fields.fld_bcc) 493 if (single_fields.fld_bcc)
484 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); 494 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
485 if (single_fields.fld_orig_date) { 495 if (single_fields.fld_orig_date) {
486 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); 496 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) );
487 char tmp[23]; 497 char tmp[23];
488 struct mailimf_date_time* date = single_fields.fld_orig_date->dt_date_time; 498 struct mailimf_date_time* date = single_fields.fld_orig_date->dt_date_time;
489 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %05i", 499 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %05i",
490 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 500 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
491 mail->setIsoDate( QString( tmp ) ); 501 mail->setIsoDate( QString( tmp ) );
492 } 502 }
493 // crashes when accessing pop3 account? 503 // crashes when accessing pop3 account?
494 if (single_fields.fld_message_id) { 504 if (single_fields.fld_message_id) {
495 mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); 505 mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
496 ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; 506 ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl;
497 } 507 }
498 if (single_fields.fld_reply_to) { 508 if (single_fields.fld_reply_to) {
499 QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); 509 QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list);
500 if (t.count()>0) { 510 if (t.count()>0) {
501 mail->setReplyto(t[0]); 511 mail->setReplyto(t[0]);
502 } 512 }
503 } 513 }
504#if 0 514#if 0
505 refs = single_fields.fld_references; 515 refs = single_fields.fld_references;
506 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 516 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
507 char * text = (char*)refs->mid_list->first->data; 517 char * text = (char*)refs->mid_list->first->data;
508 mail->setReplyto(QString(text)); 518 mail->setReplyto(QString(text));
509 } 519 }
510#endif 520#endif
511 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && 521 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list &&
512 clist_count(single_fields.fld_in_reply_to->mid_list)) { 522 clist_count(single_fields.fld_in_reply_to->mid_list)) {
513 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); 523 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to));
514 } 524 }
515 if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 ) 525 if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 )
516 target.append(mail); 526 target.append(mail);
517 } 527 }
518 if (env_list) { 528 if (env_list) {
519 mailmessage_list_free(env_list); 529 mailmessage_list_free(env_list);
520 } 530 }
521} 531}