-rw-r--r-- | noncore/net/mail/opiemail.cpp | 87 |
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,108 +1,193 @@ | |||
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 | ||
24 | using namespace Opie::Core; | 26 | using namespace Opie::Core; |
25 | 27 | ||
28 | typedef QMapNode<QString,QString> tkeyvalues; | ||
29 | typedef QValueList<tkeyvalues> tvaluelist; | ||
30 | |||
31 | class ValueExplode | ||
32 | { | ||
33 | protected: | ||
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(){} | ||
46 | public: | ||
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 | |||
63 | ValueExplode::~ValueExplode() | ||
64 | { | ||
65 | } | ||
66 | |||
67 | ValueExplode::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 | |||
75 | void 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 | |||
26 | OpieMail::OpieMail( QWidget *parent, const char *name, WFlags ) | 105 | OpieMail::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 | ||
35 | OpieMail::~OpieMail() | 120 | OpieMail::~OpieMail() |
36 | { | 121 | { |
37 | if (settings) delete settings; | 122 | if (settings) delete settings; |
38 | } | 123 | } |
39 | 124 | ||
40 | void OpieMail::setup_signalblocking() | 125 | void 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 | ||
50 | void OpieMail::appMessage(const QCString &msg, const QByteArray &data) | 135 | void 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 | */ |
70 | void OpieMail::setDocument(const QString& mail) | 155 | void 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 | ||
79 | void OpieMail::slotwriteMail(const QString&name,const QString&email) | 164 | void 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 | ||
97 | void OpieMail::slotComposeMail() | 182 | void 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 | ||
103 | void OpieMail::slotSendQueued() | 188 | void 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(); |