summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper
Unidiff
Diffstat (limited to 'kmicromail/libmailwrapper') (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
@@ -101,177 +101,172 @@ QString AbstractMail::convert_String(const char*text)
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,122 +1,132 @@
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;