summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/opiemail.cpp87
1 files changed, 86 insertions, 1 deletions
diff --git a/noncore/net/mail/opiemail.cpp b/noncore/net/mail/opiemail.cpp
index b153292..5654476 100644
--- a/noncore/net/mail/opiemail.cpp
+++ b/noncore/net/mail/opiemail.cpp
@@ -1,309 +1,394 @@
1 1
2#include "settingsdialog.h" 2#include "settingsdialog.h"
3#include "opiemail.h" 3#include "opiemail.h"
4#include "editaccounts.h" 4#include "editaccounts.h"
5#include "composemail.h" 5#include "composemail.h"
6#include "mailistviewitem.h" 6#include "mailistviewitem.h"
7#include "viewmail.h" 7#include "viewmail.h"
8#include "selectstore.h" 8#include "selectstore.h"
9#include "selectsmtp.h" 9#include "selectsmtp.h"
10 10
11#include <libmailwrapper/smtpwrapper.h> 11#include <libmailwrapper/smtpwrapper.h>
12#include <libmailwrapper/mailtypes.h> 12#include <libmailwrapper/mailtypes.h>
13#include <libmailwrapper/abstractmail.h> 13#include <libmailwrapper/abstractmail.h>
14/* OPIE */ 14/* OPIE */
15#include <opie2/odebug.h> 15#include <opie2/odebug.h>
16#include <qpe/resource.h> 16#include <qpe/resource.h>
17#include <qpe/qpeapplication.h> 17#include <qpe/qpeapplication.h>
18 18
19/* QT */ 19/* QT */
20#include <qmap.h>
21#include <qvaluelist.h>
20 22
21/* UNIX */ 23/* UNIX */
22#include <signal.h> 24#include <signal.h>
23 25
24using namespace Opie::Core; 26using namespace Opie::Core;
25 27
28typedef QMapNode<QString,QString> tkeyvalues;
29typedef QValueList<tkeyvalues> tvaluelist;
30
31class ValueExplode
32{
33protected:
34 //! what was parsed last
35 tvaluelist m_LastParsed;
36 //! the delemiter to use
37 QString mDelemiter;
38 //! the inner delemiter
39 QString m2Delemiter;
40 //! the real split routine
41 void splitit();
42 //! the content
43 QString m_Command;
44 //! constructor
45 ValueExplode(){}
46public:
47 //! constructor
48 /*!
49 * \param aCommand the string to be splitted
50 * \param aDelemiter which sign will be the delemiter character
51 * \param a2Delemiter which sign will delemiter the key-value-pairs between other delemiters
52 */
53 ValueExplode(const QString&aCommand,const char aDelemiter = '&',const char a2Delemiter='=');
54 //! destructor
55 virtual ~ValueExplode();
56 //! assigen operator
57 /*!
58 * \return a list of substrings
59 */
60 operator const tvaluelist& (){return m_LastParsed;}
61};
62
63ValueExplode::~ValueExplode()
64{
65}
66
67ValueExplode::ValueExplode(const QString&aCommand,const char aDelemiter,const char a2Delemiter)
68 :m_LastParsed(),m_Command(aCommand)
69{
70 mDelemiter = aDelemiter;
71 m2Delemiter = a2Delemiter;
72 splitit();
73}
74
75void ValueExplode::splitit()
76{
77 QString iLine;
78 m_LastParsed.clear();
79 if (mDelemiter.isEmpty()||m2Delemiter.isEmpty()) {
80 m_LastParsed.append(tkeyvalues(m_Command,""));
81 return;
82 }
83 int pos,pos2,startpos;
84 startpos = 0;
85 iLine = m_Command;
86 while ( (pos = iLine.find(mDelemiter,startpos))!=-1) {
87 pos2 = iLine.find(m2Delemiter,startpos);
88 if (pos2==-1||pos2>pos) {
89 m_LastParsed.append(tkeyvalues(iLine.mid(startpos,pos-startpos),""));
90 } else {
91 m_LastParsed.append(tkeyvalues(iLine.mid(startpos,pos2-startpos),iLine.mid(pos2+1,pos-pos2-1)));
92 }
93 startpos = pos+1;
94 }
95 if (startpos<iLine.length()) {
96 pos2 = iLine.find(m2Delemiter,startpos);
97 if (pos2==-1) {
98 m_LastParsed.append(tkeyvalues(iLine.mid(startpos),""));
99 } else {
100 m_LastParsed.append(tkeyvalues(iLine.mid(startpos,pos2-startpos),iLine.mid(pos2+1)));
101 }
102 }
103}
104
26OpieMail::OpieMail( QWidget *parent, const char *name, WFlags ) 105OpieMail::OpieMail( QWidget *parent, const char *name, WFlags )
27 : MainWindow( parent, name, WStyle_ContextHelp ) 106 : MainWindow( parent, name, WStyle_ContextHelp )
28{ 107{
29 setup_signalblocking(); 108 setup_signalblocking();
30 settings = new Settings(); 109 settings = new Settings();
31 110
32 folderView->populate( settings->getAccounts() ); 111 folderView->populate( settings->getAccounts() );
112#if 1
113 tvaluelist s = ValueExplode("a=1&b=holladiewaldfee&c=3&d=&e=3450");
114 for (int i = 0; i < s.count();++i) {
115 odebug<<"Key: " << s[i].key << " Value: " << s[i].data << oendl;
116 }
117#endif
33} 118}
34 119
35OpieMail::~OpieMail() 120OpieMail::~OpieMail()
36{ 121{
37 if (settings) delete settings; 122 if (settings) delete settings;
38} 123}
39 124
40void OpieMail::setup_signalblocking() 125void OpieMail::setup_signalblocking()
41{ 126{
42 /* for networking we must block SIGPIPE and Co. */ 127 /* for networking we must block SIGPIPE and Co. */
43 struct sigaction blocking_action,temp_action; 128 struct sigaction blocking_action,temp_action;
44 blocking_action.sa_handler = SIG_IGN; 129 blocking_action.sa_handler = SIG_IGN;
45 sigemptyset(&(blocking_action.sa_mask)); 130 sigemptyset(&(blocking_action.sa_mask));
46 blocking_action.sa_flags = 0; 131 blocking_action.sa_flags = 0;
47 sigaction(SIGPIPE,&blocking_action,&temp_action); 132 sigaction(SIGPIPE,&blocking_action,&temp_action);
48} 133}
49 134
50void OpieMail::appMessage(const QCString &msg, const QByteArray &data) 135void OpieMail::appMessage(const QCString &msg, const QByteArray &data)
51{ 136{
52 // copied from old mail2 137 // copied from old mail2
53 if (msg == "writeMail(QString,QString)") 138 if (msg == "writeMail(QString,QString)")
54 { 139 {
55 QDataStream stream(data,IO_ReadOnly); 140 QDataStream stream(data,IO_ReadOnly);
56 QString name, email; 141 QString name, email;
57 stream >> name >> email; 142 stream >> name >> email;
58 // removing the whitespaces at beginning and end is needed! 143 // removing the whitespaces at beginning and end is needed!
59 slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace()); 144 slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace());
60 } 145 }
61 else if (msg == "newMail()") 146 else if (msg == "newMail()")
62 { 147 {
63 slotComposeMail(); 148 slotComposeMail();
64 } 149 }
65} 150}
66 151
67/** 152/**
68 * Konqueror calls us with the mailto:name@address 153 * Konqueror calls us with the mailto:name@address
69 */ 154 */
70void OpieMail::setDocument(const QString& mail) 155void OpieMail::setDocument(const QString& mail)
71{ 156{
72 /* 157 /*
73 * It looks like a mailto address, lets try it 158 * It looks like a mailto address, lets try it
74 */ 159 */
75 if( mail.startsWith(QString::fromLatin1("mailto:")) ) 160 if( mail.startsWith(QString::fromLatin1("mailto:")) )
76 slotwriteMail(QString::null, mail.mid(7)); 161 slotwriteMail(QString::null, mail.mid(7));
77} 162}
78 163
79void OpieMail::slotwriteMail(const QString&name,const QString&email) 164void OpieMail::slotwriteMail(const QString&name,const QString&email)
80{ 165{
81 ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp ); 166 ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp );
82 if (!email.isEmpty()) 167 if (!email.isEmpty())
83 { 168 {
84 if (!name.isEmpty()) 169 if (!name.isEmpty())
85 { 170 {
86 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); 171 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">");
87 } 172 }
88 else 173 else
89 { 174 {
90 compose.setTo(email); 175 compose.setTo(email);
91 } 176 }
92 } 177 }
93 compose.slotAdjustColumns(); 178 compose.slotAdjustColumns();
94 QPEApplication::execDialog( &compose ); 179 QPEApplication::execDialog( &compose );
95} 180}
96 181
97void OpieMail::slotComposeMail() 182void OpieMail::slotComposeMail()
98{ 183{
99 odebug << "Compose Mail" << oendl; 184 odebug << "Compose Mail" << oendl;
100 slotwriteMail(0l,0l); 185 slotwriteMail(0l,0l);
101} 186}
102 187
103void OpieMail::slotSendQueued() 188void OpieMail::slotSendQueued()
104{ 189{
105 odebug << "Send Queued" << oendl; 190 odebug << "Send Queued" << oendl;
106 SMTPaccount *smtp = 0; 191 SMTPaccount *smtp = 0;
107 192
108 QList<Account> list = settings->getAccounts(); 193 QList<Account> list = settings->getAccounts();
109 QList<SMTPaccount> smtpList; 194 QList<SMTPaccount> smtpList;
110 smtpList.setAutoDelete(false); 195 smtpList.setAutoDelete(false);
111 Account *it; 196 Account *it;
112 for ( it = list.first(); it; it = list.next() ) 197 for ( it = list.first(); it; it = list.next() )
113 { 198 {
114 if ( it->getType() == MAILLIB::A_SMTP ) 199 if ( it->getType() == MAILLIB::A_SMTP )
115 { 200 {
116 smtp = static_cast<SMTPaccount *>(it); 201 smtp = static_cast<SMTPaccount *>(it);
117 smtpList.append(smtp); 202 smtpList.append(smtp);
118 } 203 }
119 } 204 }
120 if (smtpList.count()==0) 205 if (smtpList.count()==0)
121 { 206 {
122 QMessageBox::information(0,tr("Info"),tr("Define a smtp account first")); 207 QMessageBox::information(0,tr("Info"),tr("Define a smtp account first"));
123 return; 208 return;
124 } 209 }
125 if (smtpList.count()==1) 210 if (smtpList.count()==1)
126 { 211 {
127 smtp = smtpList.at(0); 212 smtp = smtpList.at(0);
128 } 213 }
129 else 214 else
130 { 215 {
131 smtp = 0; 216 smtp = 0;
132 selectsmtp selsmtp; 217 selectsmtp selsmtp;
133 selsmtp.setSelectionlist(&smtpList); 218 selsmtp.setSelectionlist(&smtpList);
134 if ( QPEApplication::execDialog( &selsmtp ) == QDialog::Accepted ) 219 if ( QPEApplication::execDialog( &selsmtp ) == QDialog::Accepted )
135 { 220 {
136 smtp = selsmtp.selected_smtp(); 221 smtp = selsmtp.selected_smtp();
137 } 222 }
138 } 223 }
139 if (smtp) 224 if (smtp)
140 { 225 {
141 SMTPwrapper * wrap = new SMTPwrapper(smtp); 226 SMTPwrapper * wrap = new SMTPwrapper(smtp);
142 if ( wrap->flushOutbox() ) 227 if ( wrap->flushOutbox() )
143 { 228 {
144 QMessageBox::information(0,tr("Info"),tr("Mail queue flushed")); 229 QMessageBox::information(0,tr("Info"),tr("Mail queue flushed"));
145 } 230 }
146 delete wrap; 231 delete wrap;
147 } 232 }
148} 233}
149 234
150void OpieMail::slotSearchMails() 235void OpieMail::slotSearchMails()
151{ 236{
152 odebug << "Search Mails" << oendl; 237 odebug << "Search Mails" << oendl;
153} 238}
154 239
155void OpieMail::slotEditSettings() 240void OpieMail::slotEditSettings()
156{ 241{
157 SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp ); 242 SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp );
158 QPEApplication::execDialog( &settingsDialog ); 243 QPEApplication::execDialog( &settingsDialog );
159} 244}
160 245
161void OpieMail::slotEditAccounts() 246void OpieMail::slotEditAccounts()
162{ 247{
163 odebug << "Edit Accounts" << oendl; 248 odebug << "Edit Accounts" << oendl;
164 EditAccounts eaDialog( settings, this, 0, true, WStyle_ContextHelp ); 249 EditAccounts eaDialog( settings, this, 0, true, WStyle_ContextHelp );
165 eaDialog.slotAdjustColumns(); 250 eaDialog.slotAdjustColumns();
166 QPEApplication::execDialog( &eaDialog ); 251 QPEApplication::execDialog( &eaDialog );
167 if ( settings ) delete settings; 252 if ( settings ) delete settings;
168 settings = new Settings(); 253 settings = new Settings();
169 254
170 folderView->populate( settings->getAccounts() ); 255 folderView->populate( settings->getAccounts() );
171} 256}
172 257
173void OpieMail::displayMail() 258void OpieMail::displayMail()
174{ 259{
175 QListViewItem*item = mailView->currentItem(); 260 QListViewItem*item = mailView->currentItem();
176 if (!item) return; 261 if (!item) return;
177 RecMailP mail = ((MailListViewItem*)item)->data(); 262 RecMailP mail = ((MailListViewItem*)item)->data();
178 RecBodyP body = folderView->fetchBody(mail); 263 RecBodyP body = folderView->fetchBody(mail);
179 ViewMail readMail( this,"", Qt::WType_Modal | WStyle_ContextHelp ); 264 ViewMail readMail( this,"", Qt::WType_Modal | WStyle_ContextHelp );
180 readMail.setBody( body ); 265 readMail.setBody( body );
181 readMail.setMail( mail ); 266 readMail.setMail( mail );
182 readMail.showMaximized(); 267 readMail.showMaximized();
183 readMail.exec(); 268 readMail.exec();
184 269
185 if ( readMail.deleted ) 270 if ( readMail.deleted )
186 { 271 {
187 folderView->refreshCurrent(); 272 folderView->refreshCurrent();
188 } 273 }
189 else 274 else
190 { 275 {
191 ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "" ) ); 276 ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "" ) );
192 } 277 }
193} 278}
194 279
195void OpieMail::slotDeleteMail() 280void OpieMail::slotDeleteMail()
196{ 281{
197 if (!mailView->currentItem()) return; 282 if (!mailView->currentItem()) return;
198 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); 283 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data();
199 if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 284 if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
200 { 285 {
201 mail->Wrapper()->deleteMail( mail ); 286 mail->Wrapper()->deleteMail( mail );
202 folderView->refreshCurrent(); 287 folderView->refreshCurrent();
203 } 288 }
204} 289}
205 290
206void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int ) 291void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int )
207{ 292{
208 if (!mailView->currentItem()) return; 293 if (!mailView->currentItem()) return;
209 MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType(); 294 MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType();
210 /* just the RIGHT button - or hold on pda */ 295 /* just the RIGHT button - or hold on pda */
211 if (button!=2) {return;} 296 if (button!=2) {return;}
212 odebug << "Event right/hold" << oendl; 297 odebug << "Event right/hold" << oendl;
213 if (!item) return; 298 if (!item) return;
214 QPopupMenu *m = new QPopupMenu(0); 299 QPopupMenu *m = new QPopupMenu(0);
215 if (m) 300 if (m)
216 { 301 {
217 if (mailtype==MAILLIB::A_NNTP) { 302 if (mailtype==MAILLIB::A_NNTP) {
218 m->insertItem(tr("Read this posting"),this,SLOT(displayMail())); 303 m->insertItem(tr("Read this posting"),this,SLOT(displayMail()));
219// m->insertItem(tr("Copy this posting"),this,SLOT(slotMoveCopyMail())); 304// m->insertItem(tr("Copy this posting"),this,SLOT(slotMoveCopyMail()));
220 } else { 305 } else {
221 if (folderView->currentisDraft()) { 306 if (folderView->currentisDraft()) {
222 m->insertItem(tr("Edit this mail"),this,SLOT(reEditMail())); 307 m->insertItem(tr("Edit this mail"),this,SLOT(reEditMail()));
223 } 308 }
224 m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); 309 m->insertItem(tr("Read this mail"),this,SLOT(displayMail()));
225 m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); 310 m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail()));
226 m->insertItem(tr("Copy/Move this mail"),this,SLOT(slotMoveCopyMail())); 311 m->insertItem(tr("Copy/Move this mail"),this,SLOT(slotMoveCopyMail()));
227 } 312 }
228 m->setFocus(); 313 m->setFocus();
229 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 314 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
230 delete m; 315 delete m;
231 } 316 }
232} 317}
233 318
234void OpieMail::slotShowFolders( bool show ) 319void OpieMail::slotShowFolders( bool show )
235{ 320{
236 odebug << "Show Folders" << oendl; 321 odebug << "Show Folders" << oendl;
237 if ( show && folderView->isHidden() ) 322 if ( show && folderView->isHidden() )
238 { 323 {
239 odebug << "-> showing" << oendl; 324 odebug << "-> showing" << oendl;
240 folderView->show(); 325 folderView->show();
241 } 326 }
242 else if ( !show && !folderView->isHidden() ) 327 else if ( !show && !folderView->isHidden() )
243 { 328 {
244 odebug << "-> hiding" << oendl; 329 odebug << "-> hiding" << oendl;
245 folderView->hide(); 330 folderView->hide();
246 } 331 }
247} 332}
248 333
249void OpieMail::refreshMailView(const QValueList<RecMailP>&list) 334void OpieMail::refreshMailView(const QValueList<RecMailP>&list)
250{ 335{
251 MailListViewItem*item = 0; 336 MailListViewItem*item = 0;
252 mailView->clear(); 337 mailView->clear();
253 338
254 QValueList<RecMailP>::ConstIterator it; 339 QValueList<RecMailP>::ConstIterator it;
255 for (it = list.begin(); it != list.end();++it) 340 for (it = list.begin(); it != list.end();++it)
256 { 341 {
257 item = new MailListViewItem(mailView,item); 342 item = new MailListViewItem(mailView,item);
258 item->storeData((*it)); 343 item->storeData((*it));
259 item->showEntry(); 344 item->showEntry();
260 } 345 }
261} 346}
262 347
263void OpieMail::mailLeftClicked(int button, QListViewItem *item,const QPoint&,int ) 348void OpieMail::mailLeftClicked(int button, QListViewItem *item,const QPoint&,int )
264{ 349{
265 /* just LEFT button - or tap with stylus on pda */ 350 /* just LEFT button - or tap with stylus on pda */
266 if (button!=1) return; 351 if (button!=1) return;
267 if (!item) return; 352 if (!item) return;
268 if (folderView->currentisDraft()) { 353 if (folderView->currentisDraft()) {
269 reEditMail(); 354 reEditMail();
270 } else { 355 } else {
271 displayMail(); 356 displayMail();
272 } 357 }
273} 358}
274 359
275void OpieMail::slotMoveCopyMail() 360void OpieMail::slotMoveCopyMail()
276{ 361{
277 if (!mailView->currentItem()) return; 362 if (!mailView->currentItem()) return;
278 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); 363 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data();
279 AbstractMail*targetMail = 0; 364 AbstractMail*targetMail = 0;
280 QString targetFolder = ""; 365 QString targetFolder = "";
281 Selectstore sels; 366 Selectstore sels;
282 folderView->setupFolderselect(&sels); 367 folderView->setupFolderselect(&sels);
283 if (!sels.exec()) return; 368 if (!sels.exec()) return;
284 targetMail = sels.currentMail(); 369 targetMail = sels.currentMail();
285 targetFolder = sels.currentFolder(); 370 targetFolder = sels.currentFolder();
286 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || 371 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) ||
287 targetFolder.isEmpty()) 372 targetFolder.isEmpty())
288 { 373 {
289 return; 374 return;
290 } 375 }
291 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 376 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
292 { 377 {
293 QMessageBox::critical(0,tr("Error creating new Folder"), 378 QMessageBox::critical(0,tr("Error creating new Folder"),
294 tr("<center>Error while creating<br>new folder - breaking.</center>")); 379 tr("<center>Error while creating<br>new folder - breaking.</center>"));
295 return; 380 return;
296 } 381 }
297 mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails()); 382 mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails());
298 folderView->refreshCurrent(); 383 folderView->refreshCurrent();
299} 384}
300 385
301void OpieMail::reEditMail() 386void OpieMail::reEditMail()
302{ 387{
303 if (!mailView->currentItem()) return; 388 if (!mailView->currentItem()) return;
304 389
305 ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp ); 390 ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp );
306 compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data()); 391 compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data());
307 compose.slotAdjustColumns(); 392 compose.slotAdjustColumns();
308 QPEApplication::execDialog( &compose ); 393 QPEApplication::execDialog( &compose );
309} 394}