summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2003-04-06 17:45:00 (UTC)
committer llornkcor <llornkcor>2003-04-06 17:45:00 (UTC)
commit70b1ff1a3f134d75d1539f269d52b34e6762684d (patch) (unidiff)
tree28c1b3d0c03e8c0188f014dfe094645d1ddfef5f
parent75e8f29020e267d1013a79839831035073b4eeae (diff)
downloadopie-70b1ff1a3f134d75d1539f269d52b34e6762684d.zip
opie-70b1ff1a3f134d75d1539f269d52b34e6762684d.tar.gz
opie-70b1ff1a3f134d75d1539f269d52b34e6762684d.tar.bz2
move malit to head again, since it is working
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mailit/README83
-rw-r--r--noncore/net/mailit/addatt.cpp209
-rw-r--r--noncore/net/mailit/addatt.h70
-rw-r--r--noncore/net/mailit/addresslist.cpp167
-rw-r--r--noncore/net/mailit/addresslist.h59
-rw-r--r--noncore/net/mailit/editaccount.cpp120
-rw-r--r--noncore/net/mailit/editaccount.h66
-rw-r--r--noncore/net/mailit/emailclient.cpp858
-rw-r--r--noncore/net/mailit/emailclient.h149
-rw-r--r--noncore/net/mailit/emailhandler.cpp589
-rw-r--r--noncore/net/mailit/emailhandler.h147
-rw-r--r--noncore/net/mailit/emaillistitem.cpp92
-rw-r--r--noncore/net/mailit/emaillistitem.h44
-rw-r--r--noncore/net/mailit/getmail.xpm21
-rw-r--r--noncore/net/mailit/mailit.pro44
-rw-r--r--noncore/net/mailit/mailitwindow.cpp132
-rw-r--r--noncore/net/mailit/mailitwindow.h58
-rw-r--r--noncore/net/mailit/maillist.cpp131
-rw-r--r--noncore/net/mailit/maillist.h50
-rw-r--r--noncore/net/mailit/main.cpp29
-rw-r--r--noncore/net/mailit/md5.c251
-rw-r--r--noncore/net/mailit/md5.h55
-rw-r--r--noncore/net/mailit/opie-mailit.control9
-rw-r--r--noncore/net/mailit/popclient.cpp375
-rw-r--r--noncore/net/mailit/popclient.h76
-rw-r--r--noncore/net/mailit/readmail.cpp326
-rw-r--r--noncore/net/mailit/readmail.h86
-rw-r--r--noncore/net/mailit/resource.cpp136
-rw-r--r--noncore/net/mailit/resource.h80
-rw-r--r--noncore/net/mailit/sendmail.xpm20
-rw-r--r--noncore/net/mailit/smtpclient.cpp163
-rw-r--r--noncore/net/mailit/smtpclient.h75
-rw-r--r--noncore/net/mailit/textparser.cpp294
-rw-r--r--noncore/net/mailit/textparser.h85
-rw-r--r--noncore/net/mailit/viewatt.cpp109
-rw-r--r--noncore/net/mailit/viewatt.h46
-rw-r--r--noncore/net/mailit/writemail.cpp299
-rw-r--r--noncore/net/mailit/writemail.h91
-rw-r--r--noncore/unsupported/mailit/README83
-rw-r--r--noncore/unsupported/mailit/addatt.cpp209
-rw-r--r--noncore/unsupported/mailit/addatt.h70
-rw-r--r--noncore/unsupported/mailit/addresslist.cpp167
-rw-r--r--noncore/unsupported/mailit/addresslist.h59
-rw-r--r--noncore/unsupported/mailit/editaccount.cpp120
-rw-r--r--noncore/unsupported/mailit/editaccount.h66
-rw-r--r--noncore/unsupported/mailit/emailclient.cpp858
-rw-r--r--noncore/unsupported/mailit/emailclient.h149
-rw-r--r--noncore/unsupported/mailit/emailhandler.cpp589
-rw-r--r--noncore/unsupported/mailit/emailhandler.h147
-rw-r--r--noncore/unsupported/mailit/emaillistitem.cpp92
-rw-r--r--noncore/unsupported/mailit/emaillistitem.h44
-rw-r--r--noncore/unsupported/mailit/getmail.xpm21
-rw-r--r--noncore/unsupported/mailit/mailit.pro44
-rw-r--r--noncore/unsupported/mailit/mailitwindow.cpp132
-rw-r--r--noncore/unsupported/mailit/mailitwindow.h58
-rw-r--r--noncore/unsupported/mailit/maillist.cpp131
-rw-r--r--noncore/unsupported/mailit/maillist.h50
-rw-r--r--noncore/unsupported/mailit/main.cpp29
-rw-r--r--noncore/unsupported/mailit/md5.c251
-rw-r--r--noncore/unsupported/mailit/md5.h55
-rw-r--r--noncore/unsupported/mailit/opie-mailit.control9
-rw-r--r--noncore/unsupported/mailit/popclient.cpp375
-rw-r--r--noncore/unsupported/mailit/popclient.h76
-rw-r--r--noncore/unsupported/mailit/readmail.cpp326
-rw-r--r--noncore/unsupported/mailit/readmail.h86
-rw-r--r--noncore/unsupported/mailit/resource.cpp136
-rw-r--r--noncore/unsupported/mailit/resource.h80
-rw-r--r--noncore/unsupported/mailit/sendmail.xpm20
-rw-r--r--noncore/unsupported/mailit/smtpclient.cpp163
-rw-r--r--noncore/unsupported/mailit/smtpclient.h75
-rw-r--r--noncore/unsupported/mailit/textparser.cpp294
-rw-r--r--noncore/unsupported/mailit/textparser.h85
-rw-r--r--noncore/unsupported/mailit/viewatt.cpp109
-rw-r--r--noncore/unsupported/mailit/viewatt.h46
-rw-r--r--noncore/unsupported/mailit/writemail.cpp299
-rw-r--r--noncore/unsupported/mailit/writemail.h91
76 files changed, 11388 insertions, 0 deletions
diff --git a/noncore/net/mailit/README b/noncore/net/mailit/README
new file mode 100644
index 0000000..01781b4
--- a/dev/null
+++ b/noncore/net/mailit/README
@@ -0,0 +1,83 @@
1Issues regarding Mailit
2-----------------------
3
4Mailit is still in development and is lacking some
5features to make it completely usable. Listed below are the
6most important issues.
7
8Due to the development status, numerous messages are passed too
9the console during usage of the program.
10No messages are deleted from the POP server after retrival.
11
12Synchronization:
13---------------------
14Works by comparing the last known size of the mailbox on the server
15to the current size.
16Possible problem: If a popserver shuffles the order of the mails
17when it receives a new mail, mailit won't know since it only uses
18the messagecount as a reference. If this occurs, turn sync off in
19the account settings.
20Haven't encountered this problem on the currently tested servers,
21but if it turns out that several servers do this, it will be resolved.
22
23Mail parsing
24------------
25Parsing of MIME-encoded email works for all currently tested cases.
26BASE64 decoding works.
27Attatchments are saved in the enclosure subdirectory of qtmail
28(in the Documents directory). You can install the files to the documents
29folder (creates a doclnk)
30Adding enclosures is limited to the preselected directories, and they
31are not really correct at the moment (trivial issue awaiting decision
32of fileplacements in QPE)
33attatched pictures will be displayed (jpg dependant on qte compilation)
34
35
36SMTP
37----
38The SMTP-client now supports attatchments, but it's not completly done.
39Encoding works, but it doesn't examine the file to check what type of
40file you are attatching. In other words, if it doesn't know that you
41are attatching a picture, the mime setting for content type could be
42wrong. Mail clients with inline viewing of pictures (like hotmail) could
43have a problem with displaying the mail correctly.
44(Should be fixed soon)
45
46You can now have multiple recipients.
47
48
49POP
50---
51The popclient connects to the all accounts in turn, downloads all headers
52and emails smaller than 2000 bytes. After its done, it reconnects
53and downloads the mails that were too big (> 2000)
54The to-be-downloaded mails are sorted according to size. If you view
55a mail, it is shifted to the front of the queue. Deleting a mail(header)
56while the download is in progress will remove it from the queue of
57mails to download (except if the mail is currently in transfer)
58You may exit mailit during a transfer of mails/headers. Next time
59you reconnect to the same server it will continue downloading from
60where it left off.
61
62You can now choose between getting mail from only one account or all.
63The get all option is just added and not fully testet yet. Get from
64a single account should work fine. The current way of downloading
65does not work well without sync turned on if you keep old mails in
66the inbox.
67
68Experienced some problems with servers reporting mail size less and
69bigger than actual size. Don't know whats causing this yet, but I
70have added a workaround. It now scans the mail for endofmail
71definition ("\r\n.\r\n"), disregarding size.
72
73
74Saving/Retrieving mail
75----------------------
76The inbox is saved and retrieved. Any mail not sent from the outbox
77is not saved (will of course be added)
78
79Miscelaneous issues
80-------------------
81Numerous cosmetic changes, including icons (which are temporary)
82
83Very little error checking is done on usertyped variables.
diff --git a/noncore/net/mailit/addatt.cpp b/noncore/net/mailit/addatt.cpp
new file mode 100644
index 0000000..c030e36
--- a/dev/null
+++ b/noncore/net/mailit/addatt.cpp
@@ -0,0 +1,209 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qlayout.h>
21#include <qdir.h>
22#include <qstringlist.h>
23#include "resource.h"
24#include "addatt.h"
25
26FileItem::FileItem(QListView *parent, QFileInfo fileInfo, QString fileType)
27 : QListViewItem(parent)
28{
29 file = fileInfo;
30 type = fileType;
31
32 setText(0, fileInfo.baseName());
33
34 if (fileType == "Picture") {
35 setPixmap(0, Resource::loadPixmap("pixmap"));
36 } else if (fileType == "Document") {
37 setPixmap(0, Resource::loadPixmap("txt"));
38 } else if (fileType == "Sound") {
39 setPixmap(0, Resource::loadPixmap("play"));
40 } else if (fileType == "Movie") {
41 setPixmap(0, Resource::loadPixmap("MPEGPlayer"));
42 } else if (fileType == "File") {
43 setPixmap(0, Resource::loadPixmap("exec"));
44 }
45}
46
47QFileInfo FileItem::getFileInfo()
48{
49 return file;
50}
51
52QString FileItem::getFileType()
53{
54 return type;
55}
56
57AddAtt::AddAtt(QWidget *parent, const char *name, WFlags f)
58 : QDialog(parent, name, f)
59{
60 setCaption("Adding attatchments");
61
62 QGridLayout *top = new QGridLayout(this, 3, 2);
63
64 fileCategoryButton = new QPushButton(this);
65 attatchButton = new QPushButton("Attatch ->", this);
66 removeButton = new QPushButton("Remove", this);
67
68 fileCategories = new QPopupMenu(fileCategoryButton);
69 fileCategoryButton->setPopup(fileCategories);
70 fileCategories->insertItem("Document");
71 fileCategories->insertItem("Picture");
72 fileCategories->insertItem("Sound");
73 fileCategories->insertItem("Movie");
74 fileCategories->insertItem("File");
75
76 fileCategoryButton->setText("Document");
77 top->addWidget(fileCategoryButton, 0, 0);
78 top->addWidget(attatchButton, 2, 0);
79 top->addWidget(removeButton, 2, 1);
80
81 connect(fileCategories, SIGNAL(activated(int)), this,
82 SLOT(fileCategorySelected(int)) );
83 connect(attatchButton, SIGNAL(clicked()), this,
84 SLOT(addAttatchment()) );
85 connect(removeButton, SIGNAL(clicked()), this,
86 SLOT(removeAttatchment()) );
87
88 listView = new QListView(this, "AttView");
89 listView->addColumn("Documents");
90 connect(listView, SIGNAL(doubleClicked(QListViewItem *)), this,
91 SLOT(addAttatchment()) );
92
93 attView = new QListView(this, "Selected");
94 attView->addColumn("Attatched");
95 connect(attView, SIGNAL(doubleClicked(QListViewItem *)), this,
96 SLOT(removeAttatchment()) );
97
98 top->addWidget(listView, 1,0);
99 top->addWidget(attView, 1,1);
100
101 clear();
102}
103
104void AddAtt::clear()
105{
106 attView->clear();
107 getFiles();
108 modified = FALSE;
109}
110
111void AddAtt::fileCategorySelected(int id)
112{
113 fileCategoryButton->setText(fileCategories->text(id));
114 getFiles();
115}
116
117void AddAtt::addAttatchment()
118{
119 QFileInfo info;
120 QString type;
121
122 if (listView->selectedItem() != NULL) {
123 item = (FileItem *) listView->selectedItem();
124 info = item->getFileInfo();
125 type = item->getFileType();
126 item = new FileItem(attView, info, type);
127 }
128 modified = TRUE;
129}
130
131void AddAtt::removeAttatchment()
132{
133 if (attView->selectedItem() != NULL) {
134 attView->takeItem(attView->selectedItem());
135 }
136 modified = TRUE;
137}
138
139void AddAtt::reject()
140{
141 if (modified) {
142 attView->clear();
143 modified = FALSE;
144 }
145}
146
147void AddAtt::accept()
148{
149 modified = FALSE;
150 hide();
151}
152
153void AddAtt::getFiles()
154{
155 QString path, selected;
156 QDir *dir;
157
158 listView->clear();
159
160 selected = fileCategoryButton->text();
161 if (selected == "Picture") {
162 path = "../pics/";
163 } else if (selected == "Document") {
164 path = "" ; //sub-dirs not decided
165 } else if (selected == "Sound") {
166 path = "../sounds/"; //sub-dirs not decided
167 } else if (selected == "Movie") {
168 path = ""; //sub-dirs not decided
169 } else if (selected == "File") {
170 path = ""; //sub-dirs not decided
171 }
172
173 dir = new QDir(path);
174 dir->setFilter(QDir::Files);
175 const QFileInfoList *dirInfoList = dir->entryInfoList();
176
177 QFileInfoListIterator it(*dirInfoList); // create list iterator
178
179 while ( (fi=it.current()) ) { // for each file...
180 item = new FileItem(listView, *fi, selected);
181 ++it; // goto next list element
182 }
183}
184
185QStringList AddAtt::returnAttatchedFiles()
186{
187 QFileInfo info;
188 QStringList list;
189
190 item = (FileItem *) attView->firstChild();
191 while (item != NULL) {
192 info = item->getFileInfo();
193 list += info.filePath();
194 item = (FileItem *) item->nextSibling();
195 }
196 return list;
197}
198
199QStringList AddAtt::returnFileTypes()
200{
201 QStringList list;
202
203 item = (FileItem *) attView->firstChild();
204 while (item != NULL) {
205 list += item->getFileType();
206 item = (FileItem *) item->nextSibling();
207 }
208 return list;
209}
diff --git a/noncore/net/mailit/addatt.h b/noncore/net/mailit/addatt.h
new file mode 100644
index 0000000..867c905
--- a/dev/null
+++ b/noncore/net/mailit/addatt.h
@@ -0,0 +1,70 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef ADDATT_H
21#define ADDATT_H
22
23#include <qdialog.h>
24#include <qlistview.h>
25#include <qpushbutton.h>
26#include <qpopupmenu.h>
27#include <qstring.h>
28#include <qfileinfo.h>
29#include <qstringlist.h>
30
31class FileItem : public QListViewItem
32{
33public:
34 FileItem(QListView *parent, QFileInfo fileInfo, QString fileType);
35 QFileInfo getFileInfo();
36 QString getFileType();
37
38private:
39 QFileInfo file;
40 QString type;
41};
42
43class AddAtt : public QDialog
44{
45 Q_OBJECT
46
47public:
48 AddAtt(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
49 QStringList returnAttatchedFiles();
50 QStringList returnFileTypes();
51 void getFiles();
52 void clear();
53
54public slots:
55 void fileCategorySelected(int);
56 void addAttatchment();
57 void removeAttatchment();
58 void reject();
59 void accept();
60
61private:
62 FileItem *item;
63 QListView *listView, *attView;
64 QPushButton *fileCategoryButton, *attatchButton, *removeButton;
65 QPopupMenu *fileCategories;
66 bool modified;
67 QFileInfo *fi;
68};
69
70#endif
diff --git a/noncore/net/mailit/addresslist.cpp b/noncore/net/mailit/addresslist.cpp
new file mode 100644
index 0000000..1cf2562
--- a/dev/null
+++ b/noncore/net/mailit/addresslist.cpp
@@ -0,0 +1,167 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qfile.h>
21#include <qtextstream.h>
22
23#include "addresslist.h"
24
25AddressList::AddressList(QString file)
26{
27 addresses.setAutoDelete(TRUE);
28 filename = file;
29 read();
30 dirty = FALSE;
31}
32
33AddressList::~AddressList()
34{
35 write();
36 addresses.clear();
37}
38
39void AddressList::addContact(QString email, QString name)
40{
41 //skip if not a valid email address,
42 if (email.find( '@') == -1)
43 return;
44
45 if ( ! containsEmail(email) ) {
46 Contact *in = new Contact;
47 in->email = email;
48 in->name = name;
49 addresses.append(in);
50 dirty = TRUE;
51 }
52}
53
54bool AddressList::containsEmail(QString email)
55{
56 return ( getEmailRef(email) != -1 );
57}
58
59bool AddressList::containsName(QString name)
60{
61 return ( getNameRef(name) != -1 );
62}
63
64QString AddressList::getNameByEmail(QString email)
65{
66 int pos = getEmailRef(email);
67 if (pos != -1) {
68 Contact *ptr = addresses.at(pos);
69 return ptr->name;
70 }
71
72 return NULL;
73}
74
75QString AddressList::getEmailByName(QString name)
76{
77 int pos = getNameRef(name);
78 if (pos != -1) {
79 Contact *ptr = addresses.at(pos);
80 return ptr->email;
81 }
82
83 return NULL;
84}
85
86int AddressList::getEmailRef(QString email)
87{
88 int pos = 0;
89 Contact *ptr;
90
91 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) {
92 if (ptr->email == email)
93 return pos;
94 pos++;
95 }
96 return -1;
97}
98
99int AddressList::getNameRef(QString name)
100{
101 int pos = 0;
102 Contact *ptr;
103
104 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) {
105 if (ptr->name == name)
106 return pos;
107 pos++;
108 }
109 return -1;
110}
111
112QList<Contact>* AddressList::getContactList()
113{
114 return &addresses;
115}
116
117void AddressList::read()
118{
119 QFile f(filename);
120 QString lineEmail, lineName, email, name;
121
122 if (! f.open(IO_ReadOnly) )
123 return;
124
125 QTextStream stream(&f);
126
127 while (! stream.atEnd() ) {
128 lineEmail = stream.readLine();
129 if (! stream.atEnd() )
130 lineName = stream.readLine();
131 else return;
132
133 email = getRightString(lineEmail);
134 name = getRightString(lineName);
135 addContact(email, name);
136 }
137 f.close();
138}
139
140QString AddressList::getRightString(QString in)
141{
142 QString out = "";
143
144 int pos = in.find('=');
145 if (pos != -1) {
146 out = in.mid(pos+1).stripWhiteSpace();
147 }
148 return out;
149}
150
151void AddressList::write()
152{
153 if ( (addresses.count() == 0) || (!dirty) )
154 return;
155
156 QFile f(filename);
157 if (! f.open(IO_WriteOnly) )
158 return;
159
160 QTextStream stream(&f);
161 Contact *ptr;
162 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) {
163 stream << "email = " + ptr->email + "\n";
164 stream << "name = " + ptr->name + "\n";
165 }
166 f.close();
167}
diff --git a/noncore/net/mailit/addresslist.h b/noncore/net/mailit/addresslist.h
new file mode 100644
index 0000000..e87d6f1
--- a/dev/null
+++ b/noncore/net/mailit/addresslist.h
@@ -0,0 +1,59 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef ADDRESSLIST_H
21#define ADDRESSLIST_H
22
23#include <qobject.h>
24#include <qlist.h>
25
26struct Contact
27{
28 QString email;
29 QString name;
30};
31
32class AddressList : public QObject
33{
34 Q_OBJECT
35
36public:
37 AddressList(QString file);
38 ~AddressList();
39 void addContact(QString email, QString name);
40 bool containsEmail(QString email);
41 bool containsName(QString name);
42 QString getNameByEmail(QString email);
43 QString getEmailByName(QString name);
44 QList<Contact>* getContactList();
45 void write();
46
47private:
48 int getEmailRef(QString email);
49 int getNameRef(QString name);
50 QString getRightString(QString in);
51 void read();
52
53private:
54 QList<Contact> addresses;
55 QString filename;
56 bool dirty;
57};
58
59#endif
diff --git a/noncore/net/mailit/editaccount.cpp b/noncore/net/mailit/editaccount.cpp
new file mode 100644
index 0000000..c4f95ea
--- a/dev/null
+++ b/noncore/net/mailit/editaccount.cpp
@@ -0,0 +1,120 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18***
19**********************************************************************/
20
21#include "editaccount.h"
22
23EditAccount::EditAccount( QWidget* parent, const char* name, WFlags fl )
24 : QDialog(parent, name, fl)
25{
26 setCaption( tr("Edit Account") );
27 init();
28 popPasswInput->setEchoMode(QLineEdit::Password);
29}
30
31void EditAccount::setAccount(MailAccount *in, bool newOne)
32{
33 account = in;
34 if (newOne) {
35 accountNameInput->setText("");
36 nameInput->setText("");
37 emailInput->setText("");
38 popUserInput->setText("");
39 popPasswInput->setText("");
40 popServerInput->setText("");
41 smtpServerInput->setText("");
42 syncCheckBox->setChecked(TRUE);
43
44 setCaption( tr("Create new Account") );
45 } else {
46 accountNameInput->setText(account->accountName);
47 nameInput->setText(account->name);
48 emailInput->setText(account->emailAddress);
49 popUserInput->setText(account->popUserName);
50 popPasswInput->setText(account->popPasswd);
51 popServerInput->setText(account->popServer);
52 smtpServerInput->setText(account->smtpServer);
53 syncCheckBox->setChecked(account->synchronize);
54 }
55}
56
57void EditAccount::init()
58{
59 grid = new QGridLayout(this);
60 grid->setSpacing( 6 );
61 grid->setMargin( 11 );
62
63 accountNameInputLabel = new QLabel(tr("Account name"), this);
64 grid->addWidget( accountNameInputLabel, 0, 0 );
65 accountNameInput = new QLineEdit( this, "account nameInput" );
66 grid->addWidget( accountNameInput, 0, 1 );
67
68 nameInputLabel = new QLabel(tr("Your name"), this);
69 grid->addWidget( nameInputLabel, 1, 0 );
70 nameInput = new QLineEdit( this, "nameInput" );
71 grid->addWidget( nameInput, 1, 1 );
72
73 emailInputLabel = new QLabel("Email", this);
74 grid->addWidget(emailInputLabel, 2, 0 );
75 emailInput = new QLineEdit( this, "emailInput" );
76 grid->addWidget( emailInput, 2, 1 );
77
78 popUserInputLabel = new QLabel("POP username", this);
79 grid->addWidget( popUserInputLabel, 3, 0 );
80 popUserInput = new QLineEdit( this, "popUserInput" );
81 grid->addWidget( popUserInput, 3, 1 );
82
83 popPasswInputLabel = new QLabel( "POP password", this);
84 grid->addWidget( popPasswInputLabel, 4, 0 );
85 popPasswInput = new QLineEdit( this, "popPasswInput" );
86 grid->addWidget( popPasswInput, 4, 1 );
87
88 popServerInputLabel = new QLabel("POP server", this);
89 grid->addWidget( popServerInputLabel, 5, 0 );
90 popServerInput = new QLineEdit( this, "popServerInput" );
91 grid->addWidget( popServerInput, 5, 1 );
92
93 smtpServerInputLabel = new QLabel("SMTP server", this );
94 grid->addWidget( smtpServerInputLabel, 6, 0 );
95 smtpServerInput = new QLineEdit( this, "smtpServerInput" );
96 grid->addWidget( smtpServerInput, 6, 1 );
97
98 syncCheckBox = new QCheckBox( tr( "Synchronize with server" ), this);
99 syncCheckBox->setChecked( TRUE );
100 grid->addMultiCellWidget( syncCheckBox, 7, 7, 0, 1 );
101}
102
103
104void EditAccount::accept()
105{
106 account->accountName = accountNameInput->text();
107 account->name = nameInput->text();
108 account->emailAddress = emailInput->text();
109 account->popUserName = popUserInput->text();
110 account->popPasswd = popPasswInput->text();
111 account->popServer = popServerInput->text();
112 account->smtpServer = smtpServerInput->text();
113 account->synchronize = syncCheckBox->isChecked();
114
115 QDialog::accept();
116}
117
118void EditAccount::reject()
119{
120}
diff --git a/noncore/net/mailit/editaccount.h b/noncore/net/mailit/editaccount.h
new file mode 100644
index 0000000..7a90e50
--- a/dev/null
+++ b/noncore/net/mailit/editaccount.h
@@ -0,0 +1,66 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef EDITACCOUNT_H
21#define EDITACCOUNT_H
22
23#include <qdialog.h>
24#include <qlabel.h>
25#include <qlineedit.h>
26#include <qcheckbox.h>
27#include <qlayout.h>
28#include "emailhandler.h"
29
30class EditAccount : public QDialog
31{
32 Q_OBJECT
33
34public:
35 EditAccount( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
36 void setAccount(MailAccount *in, bool newOne = TRUE);
37 void init();
38
39public slots:
40 void accept();
41 void reject();
42
43private:
44 MailAccount thisAccount, *account;
45
46 QLabel *accountNameInputLabel;
47 QLabel *nameInputLabel;
48 QLabel *emailInputLabel;
49 QLabel *popUserInputLabel;
50 QLabel *popPasswInputLabel;
51 QLabel *popServerInputLabel;
52 QLabel *smtpServerInputLabel;
53
54 QLineEdit *accountNameInput;
55 QLineEdit *nameInput;
56 QLineEdit *emailInput;
57 QLineEdit *popUserInput;
58 QLineEdit *popPasswInput;
59 QLineEdit *popServerInput;
60 QLineEdit *smtpServerInput;
61 QCheckBox *syncCheckBox;
62
63 QGridLayout *grid;
64};
65
66#endif
diff --git a/noncore/net/mailit/emailclient.cpp b/noncore/net/mailit/emailclient.cpp
new file mode 100644
index 0000000..7ba5c75
--- a/dev/null
+++ b/noncore/net/mailit/emailclient.cpp
@@ -0,0 +1,858 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qapplication.h>
21#include <qmessagebox.h>
22#include <qfile.h>
23#include <qcheckbox.h>
24#include <qmenubar.h>
25#include <qaction.h>
26#include "resource.h"
27#include "emailclient.h"
28
29QCollection::Item AccountList::newItem(QCollection::Item d)
30{
31 return dupl( (MailAccount *) d);
32}
33
34MailAccount* AccountList::dupl(MailAccount *in)
35{
36 ac = new MailAccount(*in);
37 return ac;
38}
39
40EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl )
41 : QMainWindow( parent, name, fl )
42{
43 emailHandler = new EmailHandler();
44 addressList = new AddressList( getPath(FALSE) + "mail_adr");
45
46 sending = FALSE;
47 receiving = FALSE;
48 previewingMail = FALSE;
49 mailIdCount = 1;
50 accountIdCount = 1;
51 allAccounts = FALSE;
52
53 init();
54
55 connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) );
56
57 connect(emailHandler, SIGNAL(smtpError(int)), this,
58 SLOT(smtpError(int)) );
59 connect(emailHandler, SIGNAL(popError(int)), this,
60 SLOT(popError(int)) );
61
62 connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemSelected()) );
63 connect(outboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(outboxItemSelected()) );
64
65 connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this,
66 SLOT(mailArrived(const Email &, bool)) );
67 connect(emailHandler, SIGNAL(mailTransfered(int)), this,
68 SLOT(allMailArrived(int)) );
69
70 mailconf = new Config("mailit");
71 //In case Synchronize is not defined in settings.txt
72
73 readSettings();
74
75 updateAccounts();
76
77 lineShift = "\n";
78 readMail();
79 lineShift = "\r\n";
80
81}
82
83
84EmailClient::~EmailClient()
85{
86 //needs to be moved from destructor to closewindow event
87 saveMail(getPath(FALSE) + "inbox.txt", inboxView);
88 //does not currently work. Defining outbox in the same
89 //format as inbox is not a good solution as they have
90 //different properties
91 saveMail(getPath(FALSE) + "outbox.txt", outboxView);
92 saveSettings();
93
94 mailconf->write();
95 delete mailconf;
96
97}
98
99void EmailClient::init()
100{
101 statusBar = new QStatusBar(this);
102 statusBar->setSizeGripEnabled(FALSE);
103
104 status1Label = new QLabel( tr("Idle"), statusBar);
105 status2Label = new QLabel("", statusBar);
106 connect(emailHandler, SIGNAL(updatePopStatus(const QString &)),
107 status2Label, SLOT(setText(const QString &)) );
108 connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)),
109 status2Label, SLOT(setText(const QString &)) );
110
111 progressBar = new QProgressBar(statusBar);
112 connect(emailHandler, SIGNAL(mailboxSize(int)),
113 this, SLOT(setTotalSize(int)) );
114 connect(emailHandler, SIGNAL(currentMailSize(int)),
115 this, SLOT(setMailSize(int)) );
116 connect(emailHandler, SIGNAL(downloadedSize(int)),
117 this, SLOT(setDownloadedSize(int)) );
118
119 statusBar->addWidget(status1Label);
120 statusBar->addWidget(progressBar);
121 statusBar->addWidget(status2Label);
122
123 setToolBarsMovable(FALSE);
124
125 bar = new QToolBar(this);
126 bar->setHorizontalStretchable( TRUE );
127
128 mb = new QMenuBar( bar );
129
130 QPopupMenu *mail = new QPopupMenu(mb);
131 mb->insertItem( tr( "&Mail" ), mail);
132
133 QPopupMenu *configure = new QPopupMenu(mb);
134 mb->insertItem( tr( "Accounts" ), configure);
135
136 selectAccountMenu = new QPopupMenu(mb);
137 editAccountMenu = new QPopupMenu(mb);
138 deleteAccountMenu = new QPopupMenu(mb);
139
140 mail->insertItem(tr("Get Mail in"), selectAccountMenu);
141 configure->insertItem(tr("Edit account"), editAccountMenu);
142 configure->insertItem(tr("Delete account"), deleteAccountMenu);
143
144 bar = new QToolBar(this);
145
146 getMailButton = new QAction(tr("Get all mail"), QPixmap("getmail.xpm"), QString::null, 0, this, 0);
147 connect(getMailButton, SIGNAL(activated()), this, SLOT(getAllNewMail()) );
148 getMailButton->addTo(bar);
149 getMailButton->addTo(mail);
150
151 sendMailButton = new QAction(tr("Send mail"), QPixmap("sendmail.xpm"), QString::null, 0, this, 0);
152 connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) );
153 sendMailButton->addTo(bar);
154 sendMailButton->addTo(mail);
155
156 composeButton = new QAction(tr("Compose"), Resource::loadPixmap("new"), QString::null, 0, this, 0);
157 connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) );
158 composeButton->addTo(bar);
159 composeButton->addTo(mail);
160
161 cancelButton = new QAction(tr("Cancel transfer"), Resource::loadPixmap("reset"), QString::null, 0, this, 0);
162 connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) );
163 cancelButton->addTo(mail);
164 cancelButton->setEnabled(FALSE);
165
166 mailboxView = new QTabWidget( this, "mailboxView" );
167
168 QWidget* widget = new QWidget( mailboxView, "widget" );
169 grid_2 = new QGridLayout( widget );
170// grid_2->setSpacing(6);
171// grid_2->setMargin( 11 );
172
173 inboxView = new QListView( widget, "inboxView" );
174 inboxView->addColumn( tr( "From" ) );
175 inboxView->addColumn( tr( "Subject" ) );
176 inboxView->addColumn( tr( "Date" ) );
177 inboxView->setMinimumSize( QSize( 0, 0 ) );
178 inboxView->setAllColumnsShowFocus(TRUE);
179
180 grid_2->addWidget( inboxView, 2, 0 );
181 mailboxView->insertTab( widget, tr( "Inbox" ) );
182
183 QWidget* widget_2 = new QWidget( mailboxView, "widget_2" );
184 grid_3 = new QGridLayout( widget_2 );
185// grid_3->setSpacing(6);
186// grid_3->setMargin( 11 );
187
188 outboxView = new QListView( widget_2, "outboxView" );
189 outboxView->addColumn( tr( "To" ) );
190 outboxView->addColumn( tr( "Subject" ) );
191 outboxView->setAllColumnsShowFocus(TRUE);
192
193 grid_3->addWidget( outboxView, 0, 0 );
194 mailboxView->insertTab( widget_2, tr( "Outbox" ) );
195
196 setCentralWidget(mailboxView);
197}
198
199void EmailClient::compose()
200{
201 emit composeRequested();
202}
203
204void EmailClient::cancel()
205{
206 emailHandler->cancel();
207}
208
209AddressList* EmailClient::getAdrListRef()
210{
211 return addressList;
212}
213
214//this needs to be rewritten to syncronize with outboxView
215void EmailClient::enqueMail(const Email &mail)
216{
217 if (accountList.count() > 0) {
218 currentAccount = accountList.first();
219 qWarning("using account " + currentAccount->name);
220 }
221
222 Email addMail = mail;
223 addMail.from = currentAccount->name;
224 addMail.fromMail = currentAccount->emailAddress;
225 addMail.rawMail.prepend("From: " + addMail.from + "<" + addMail.fromMail + ">\n");
226 item = new EmailListItem(outboxView, addMail, false);
227
228}
229
230void EmailClient::sendQuedMail()
231{
232 int count = 0;
233
234 if (accountList.count() == 0) {
235 QMessageBox::warning(qApp->activeWindow(),
236 "No account selected", "You must create an account", "OK\n");
237 return;
238 }
239 //traverse listview, find messages to send
240 if (! sending) {
241 item = (EmailListItem *) outboxView->firstChild();
242 if (item != NULL) {
243 while (item != NULL) {
244 quedMessages.append(item->getMail());
245 item = (EmailListItem *) item->nextSibling();
246 count++;
247 }
248 setMailAccount();
249 emailHandler->sendMail(&quedMessages);
250 sending = TRUE;
251 sendMailButton->setEnabled(FALSE);
252 cancelButton->setEnabled(TRUE);
253 } else {
254 qWarning("sendQuedMail(): no messages to send");
255 }
256 }
257}
258
259void EmailClient::setMailAccount()
260{
261 emailHandler->setAccount(*currentAccount);
262}
263
264void EmailClient::mailSent()
265{
266 sending = FALSE;
267 sendMailButton->setEnabled(TRUE);
268
269 quedMessages.clear();
270 outboxView->clear(); //should be moved to an sentBox
271}
272
273void EmailClient::getNewMail() {
274
275 if (accountList.count() == 0) {
276 QMessageBox::warning(qApp->activeWindow(),"No account selected",
277 "You must create an account", "OK\n");
278 return;
279 }
280
281 setMailAccount();
282
283 receiving = TRUE;
284 previewingMail = TRUE;
285 getMailButton->setEnabled(FALSE);
286 cancelButton->setEnabled(TRUE);
287 selectAccountMenu->setEnabled(FALSE);
288
289 status1Label->setText(currentAccount->accountName + " headers");
290 progressBar->reset();
291
292 //get any previous mails not downloaded and add to queue
293 mailDownloadList.clear();
294 Email *mailPtr;
295 item = (EmailListItem *) inboxView->firstChild();
296 while (item != NULL) {
297 mailPtr = item->getMail();
298 if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) {
299 mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size);
300 }
301 item = (EmailListItem *) item->nextSibling();
302 }
303
304 emailHandler->getMailHeaders();
305}
306
307void EmailClient::getAllNewMail()
308{
309 allAccounts = TRUE;
310 currentAccount = accountList.first();
311 getNewMail();
312}
313
314void EmailClient::mailArrived(const Email &mail, bool fromDisk)
315{
316 Enclosure *ePtr;
317 Email newMail;
318 int thisMailId;
319 emailHandler->parse(mail.rawMail, lineShift, &newMail);
320
321 mailconf->setGroup(newMail.id);
322
323 if (fromDisk) {
324 newMail.downloaded = mailconf->readBoolEntry("downloaded");
325 newMail.size = mailconf->readNumEntry("size");
326 newMail.serverId = mailconf->readNumEntry("serverid");
327 newMail.fromAccountId = mailconf->readNumEntry("fromaccountid");
328 } else { //mail arrived from server
329 newMail.serverId = mail.serverId;
330 newMail.size = mail.size;
331 newMail.downloaded = mail.downloaded;
332
333 newMail.fromAccountId = currentAccount->id;
334 mailconf->writeEntry("fromaccountid", newMail.fromAccountId);
335 }
336
337 //add if read or not
338 newMail.read = mailconf->readBoolEntry("mailread");
339
340 //check if new mail
341 if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) {
342 thisMailId = mailIdCount;
343 mailIdCount++;
344
345 //set server count, so that if the user aborts, the new
346 //header is not reloaded
347 if (currentAccount->synchronize)
348 currentAccount->lastServerMailCount++;
349
350 mailconf->writeEntry("internalmailid", thisMailId);
351 mailconf->writeEntry("downloaded", newMail.downloaded);
352 mailconf->writeEntry("size", (int) newMail.size);
353 mailconf->writeEntry("serverid", newMail.serverId);
354
355 addressList->addContact(newMail.fromMail, newMail.from);
356 } else if (!fromDisk) { //body to header arrived
357 mailconf->writeEntry("downloaded", TRUE);
358 }
359 QString stringMailId;
360 stringMailId.setNum(thisMailId);
361 //se if any attatchments needs to be stored
362 for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) {
363 QString stringId;
364 stringId.setNum(ePtr->id);
365
366 int id = mailconf->readNumEntry("enclosureid_" + stringId);
367 if (id != ePtr->id) { //new entry
368 mailconf->writeEntry("enclosureid_" + stringId, ePtr->id);
369 mailconf->writeEntry("name_" + stringId, ePtr->originalName);
370 mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType);
371 mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute);
372 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
373 mailconf->writeEntry("installed_" + stringId, FALSE);
374
375 ePtr->name = stringMailId + "_" + stringId;
376 ePtr->path = getPath(TRUE);
377 if (emailHandler->getEnclosure(ePtr)) { //file saved
378 ePtr->saved = TRUE;
379 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
380 mailconf->writeEntry("filename_" + stringId, ePtr->name);
381 mailconf->writeEntry("path_" + stringId, ePtr->path);
382 } else {
383 ePtr->saved = FALSE;
384 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
385 }
386 } else {
387 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId);
388 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId);
389 if (ePtr->saved) {
390 ePtr->name = mailconf->readEntry("filename_" + stringId);
391 ePtr->path = mailconf->readEntry("path_" + stringId);
392 }
393 }
394 }
395 if (!previewingMail && !fromDisk) {
396 Email *mailPtr;
397 item = (EmailListItem *) inboxView->firstChild();
398 while (item != NULL) {
399 mailPtr = item->getMail();
400 if (mailPtr->id == newMail.id) {
401 item->setMail(newMail);
402 emit mailUpdated(item->getMail());
403 }
404 item = (EmailListItem *) item->nextSibling();
405 }
406 } else {
407 item = new EmailListItem(inboxView, newMail, TRUE);
408 if (!newMail.downloaded)
409 mailDownloadList.sizeInsert(newMail.serverId, newMail.size);
410 }
411
412}
413
414void EmailClient::allMailArrived(int count)
415{
416 // not previewing means all mailtransfer has been done
417 if (!previewingMail) {
418 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) {
419 emit newCaption("Mailit - " + currentAccount->accountName);
420 getNewMail();
421 return;
422 } else {
423 allAccounts = FALSE;
424 receiving = FALSE;
425 getMailButton->setEnabled(TRUE);
426 cancelButton->setEnabled(FALSE);
427 selectAccountMenu->setEnabled(TRUE);
428 status1Label->setText("Idle");
429
430 progressBar->reset();
431 return;
432 }
433 }
434
435 // all headers downloaded from server, start downloading remaining mails
436 previewingMail = FALSE;
437 status1Label->setText(currentAccount->accountName);
438 progressBar->reset();
439
440 emailHandler->getMailByList(&mailDownloadList);
441}
442
443void EmailClient::moveMailFront(Email *mailPtr)
444{
445 if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) {
446 mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size);
447 }
448}
449
450void EmailClient::smtpError(int code)
451{
452 QString temp;
453
454 if (code == ErrUnknownResponse)
455 temp = "Unknown response from server";
456
457 if (code == QSocket::ErrHostNotFound)
458 temp = "host not found";
459 if (code == QSocket::ErrConnectionRefused)
460 temp = "connection refused";
461 if (code == QSocket::ErrSocketRead)
462 temp = "socket packet error";
463
464 if (code != ErrCancel) {
465 QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n");
466 } else {
467 status2Label->setText("Aborted by user");
468 }
469
470 sending = FALSE;
471 sendMailButton->setEnabled(TRUE);
472 cancelButton->setEnabled(FALSE);
473 quedMessages.clear();
474}
475
476void EmailClient::popError(int code)
477{
478 QString temp;
479
480 if (code == ErrUnknownResponse)
481 temp = "Unknown response from server";
482 if (code == ErrLoginFailed)
483 temp = "Login failed\nCheck user name and password";
484
485 if (code == QSocket::ErrHostNotFound)
486 temp = "host not found";
487 if (code == QSocket::ErrConnectionRefused)
488 temp = "connection refused";
489 if (code == QSocket::ErrSocketRead)
490 temp = "socket packet error";
491
492 if (code != ErrCancel) {
493 QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n");
494 } else {
495 status2Label->setText("Aborted by user");
496 }
497
498 receiving = FALSE;
499 getMailButton->setEnabled(TRUE);
500 cancelButton->setEnabled(FALSE);
501 selectAccountMenu->setEnabled(TRUE);
502}
503
504void EmailClient::inboxItemSelected()
505{
506 item = (EmailListItem*) inboxView->selectedItem();
507 if (item != NULL) {
508 emit viewEmail(inboxView, item->getMail());
509 }
510}
511
512void EmailClient::outboxItemSelected()
513{
514 item = (EmailListItem*) outboxView->selectedItem();
515 if (item != NULL) {
516 emit viewEmail(outboxView, item->getMail());
517 }
518
519}
520
521void EmailClient::readMail()
522{
523 Email mail;
524 int start, stop;
525 QString s, del;
526
527 QFile f(getPath(FALSE) + "inbox.txt");
528// QFileInfo fi(f);
529 qDebug( f.name());
530
531 if ( f.open(IO_ReadOnly) ) { // file opened successfully
532 QTextStream t( &f ); // use a text stream
533 s = t.read();
534 f.close();
535
536 start = 0;
537 del = "\n.\n";
538 while ((uint) start < s.length()) {
539 stop = s.find(del, start);
540 if (stop == -1)
541 stop = s.length() - del.length();
542
543 mail.rawMail = s.mid(start, stop + del.length() - start );
544 start = stop + del.length();
545 mailArrived(mail, TRUE);
546 }
547 }
548
549 QFile fo(getPath(FALSE) + "outbox.txt");
550 if ( fo.open(IO_ReadOnly) ) { // file opened successfully
551 QTextStream t( &fo ); // use a text stream
552 s = t.read();
553 fo.close();
554
555 start = 0;
556 del = "\n.\n";
557 while ((uint) start < s.length()) {
558 stop = s.find(del, start);
559 if (stop == -1)
560 stop = s.length() - del.length();
561
562 mail.rawMail = s.mid(start, stop + del.length() - start );
563 start = stop + del.length();
564 emailHandler->parse(mail.rawMail, lineShift, &mail);
565 mail.sent = false;
566 mail.received = false;
567 enqueMail(mail);
568
569 }
570 }
571}
572
573void EmailClient::saveMail(QString fileName, QListView *view)
574{
575 QFile f(fileName);
576 Email *mail;
577
578 if (! f.open(IO_WriteOnly) ) {
579 qWarning("could not open file");
580 return;
581 }
582 item = (EmailListItem *) view->firstChild();
583 qDebug (QString("Write : ") );
584 QTextStream t(&f);
585 while (item != NULL) {
586 mail = item->getMail();
587 qDebug(mail->rawMail);
588 qDebug(mail->recipients.first());
589 t << mail->rawMail;
590
591 mailconf->setGroup(mail->id);
592 mailconf->writeEntry("mailread", mail->read);
593
594 item = (EmailListItem *) item->nextSibling();
595 }
596 f.close();
597}
598
599//paths for mailit, is settings, inbox, enclosures
600QString EmailClient::getPath(bool enclosurePath)
601{
602 QString basePath = "qtmail";
603 QString enclosures = "enclosures";
604
605 QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath);
606 if ( !dir.exists() )
607 dir.mkdir( dir.path() );
608
609 if (enclosurePath) {
610 dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures);
611
612 if ( !dir.exists() )
613 dir.mkdir( dir.path() );
614
615 return (dir.path() + "/");
616
617 }
618 return (dir.path() + "/");
619}
620
621void EmailClient::readSettings()
622{
623 TextParser *p;
624 QString s;
625 int pos, accountPos, y;
626 QFile f( getPath(FALSE) + "settings.txt");
627
628 if ( f.open(IO_ReadOnly) ) { // file opened successfully
629 QTextStream t( &f ); // use a text stream
630 s = t.read();
631 f.close();
632
633 p = new TextParser(s, "\n");
634
635 accountPos = 0;
636 while ( (accountPos = p->find("ACCOUNTSTART",';', accountPos, TRUE)) != -1 ) {
637 accountPos++;
638 if ( (pos = p->find("ACCOUNTNAME",':', accountPos, TRUE)) != -1 )
639 account.accountName = p->getString(& ++pos, 'z', TRUE);
640 if ( (pos = p->find("NAME",':', accountPos, TRUE)) != -1)
641 account.name = p->getString(& ++pos, 'z', TRUE);
642 if ( (pos = p->find("EMAIL",':', accountPos, TRUE)) != -1)
643 account.emailAddress = p->getString(& ++pos, 'z', TRUE);
644 if ( (pos = p->find("POPUSER",':', accountPos, TRUE)) != -1)
645 account.popUserName = p->getString(& ++pos, 'z', TRUE);
646 if ( (pos = p->find("POPPASSWORD",':', accountPos, TRUE)) != -1)
647 account.popPasswd = p->getString(& ++pos, 'z', TRUE);
648 if ( (pos = p->find("POPSERVER",':', accountPos, TRUE)) != -1)
649 account.popServer = p->getString(& ++pos, 'z', TRUE);
650 if ( (pos = p->find("SMTPSERVER",':', accountPos, TRUE)) != -1)
651 account.smtpServer = p->getString(& ++pos, 'z', TRUE);
652 if ( (pos = p->find("ACCOUNTID",':', accountPos, TRUE)) != -1) {
653 s = p->getString(& ++pos, 'z', TRUE);
654 account.id = s.toInt();
655 }
656
657 account.lastServerMailCount = 0;
658 account.synchronize = FALSE;
659 if ( (pos = p->find("SYNCHRONIZE",':', accountPos, TRUE)) != -1) {
660 if (p->getString(& ++pos, 'z', TRUE).upper() == "YES") {
661 account.synchronize = TRUE;
662 if ( (pos = p->find("LASTSERVERMAILCOUNT",':', accountPos, TRUE)) != -1) {
663 s = p->getString(& ++pos, 'z', TRUE);
664 account.lastServerMailCount = s.toInt();
665 }
666 }
667 }
668 accountList.append(&account);
669 }
670 delete p;
671 }
672 mailconf->setGroup("mailitglobal");
673 if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) {
674 mailIdCount = y;
675 }
676 if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) {
677 accountIdCount = y;
678 }
679}
680
681void EmailClient::saveSettings()
682{
683 QString temp;
684 QFile f( getPath(FALSE) + "settings.txt");
685 MailAccount *accountPtr;
686
687 if (! f.open(IO_WriteOnly) ) {
688 qWarning("could not save settings file");
689 return;
690 }
691 QTextStream t(&f);
692 t << "#Settings for QPE Mailit program\n";
693
694 for (accountPtr = accountList.first(); accountPtr != 0;
695 accountPtr = accountList.next()) {
696
697 t << "accountStart;\n";
698 t << "AccountName: " + accountPtr->accountName + "\n";
699 t << "Name: " + accountPtr->name + "\n";
700 t << "Email: " + accountPtr->emailAddress + "\n";
701 t << "POPUser: " + accountPtr->popUserName + "\n";
702 t << "POPPAssword: " + accountPtr->popPasswd + "\n";
703 t << "POPServer: " + accountPtr->popServer + "\n";
704 t << "SMTPServer: " + accountPtr->smtpServer + "\n";
705 t << "AccountId: " << accountPtr->id << "\n";
706 if (accountPtr->synchronize) {
707 t << "Synchronize: Yes\n";
708 t << "LastServerMailCount: ";
709 t << accountPtr->lastServerMailCount << "\n";
710 } else {
711 t << "Synchronize: No\n";
712 }
713 t << "accountEnd;\n";
714 }
715 f.close();
716
717 mailconf->setGroup("mailitglobal");
718 mailconf->writeEntry("mailidcount", mailIdCount);
719 mailconf->writeEntry("accountidcount", accountIdCount);
720}
721
722void EmailClient::selectAccount(int id)
723{
724 if (accountList.count() > 0) {
725 currentAccount = accountList.at(id);
726 emit newCaption("Mailit - " + currentAccount->accountName);
727 getNewMail();
728 } else {
729 emit newCaption("Mailit ! No account defined");
730 }
731}
732
733void EmailClient::editAccount(int id)
734{
735 MailAccount *newAccount;
736
737 editAccountView = new EditAccount(this, "account", TRUE);
738 if (id == newAccountId) { //new account
739 newAccount = new MailAccount;
740 editAccountView->setAccount(newAccount);
741 } else {
742 newAccount = accountList.at(id);
743 editAccountView->setAccount(newAccount, FALSE);
744 }
745
746 editAccountView->showMaximized();
747 editAccountView->exec();
748
749 if (editAccountView->result() == QDialog::Accepted) {
750 if (id == newAccountId) {
751 newAccount->id = accountIdCount;
752 accountIdCount++;
753 accountList.append(newAccount);
754 updateAccounts();
755 } else {
756 updateAccounts();
757 }
758 }
759
760 delete editAccountView;
761}
762
763void EmailClient::deleteAccount(int id)
764{
765 MailAccount *newAccount;
766 QString message;
767
768 newAccount = accountList.at(id);
769 message = "Delete account:\n" + newAccount->accountName;
770 switch( QMessageBox::warning( this, "Mailit", message,
771 "Yes", "No", 0, 0, 1 ) ) {
772
773 case 0: accountList.remove(id);
774 updateAccounts();
775 break;
776 case 1:
777 break;
778 }
779}
780
781void EmailClient::updateAccounts()
782{
783 MailAccount *accountPtr;
784
785 //rebuild menus, clear all first
786 editAccountMenu->clear();
787 selectAccountMenu->clear();
788 deleteAccountMenu->clear();
789
790 newAccountId = editAccountMenu->insertItem("New", this,
791 SLOT(editAccount(int)) );
792 editAccountMenu->insertSeparator();
793
794 idCount = 0;
795 for (accountPtr = accountList.first(); accountPtr != 0;
796 accountPtr = accountList.next()) {
797
798 editAccountMenu->insertItem(accountPtr->accountName,
799 this, SLOT(editAccount(int)), 0, idCount);
800 selectAccountMenu->insertItem(accountPtr->accountName,
801 this, SLOT(selectAccount(int)), 0, idCount);
802 deleteAccountMenu->insertItem(accountPtr->accountName,
803 this, SLOT(deleteAccount(int)), 0, idCount);
804 idCount++;
805 }
806}
807
808void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox)
809{
810 Email *mPtr;
811 Enclosure *ePtr;
812
813 if (inbox) {
814 mPtr = mailItem->getMail();
815
816 //if mail is in queue for download, remove it from
817 //queue if possible
818 if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) {
819 if ( !mPtr->downloaded )
820 mailDownloadList.remove(mPtr->serverId, mPtr->size);
821 }
822
823 mailconf->setGroup(mPtr->id);
824 mailconf->clearGroup();
825
826 //delete any temporary attatchemnts storing
827 for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) {
828 if (ePtr->saved) {
829 QFile::remove( (ePtr->path + ePtr->name) );
830 }
831 }
832 inboxView->takeItem(mailItem);
833 } else {
834 outboxView->takeItem(mailItem);
835 }
836}
837
838void EmailClient::setMailSize(int size)
839{
840 progressBar->reset();
841 progressBar->setTotalSteps(size);
842}
843
844void EmailClient::setTotalSize(int size)
845{
846
847}
848
849void EmailClient::setDownloadedSize(int size)
850{
851 int total = progressBar->totalSteps();
852
853 if (size < total) {
854 progressBar->setProgress(size);
855 } else {
856 progressBar->setProgress(total);
857 }
858}
diff --git a/noncore/net/mailit/emailclient.h b/noncore/net/mailit/emailclient.h
new file mode 100644
index 0000000..135bfaa
--- a/dev/null
+++ b/noncore/net/mailit/emailclient.h
@@ -0,0 +1,149 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef EMAILCLIENT_H
21#define EMAILCLIENT_H
22
23#include <qlist.h>
24#include <qcstring.h>
25#include <qmainwindow.h>
26
27#include <qtoolbar.h>
28#include <qcheckbox.h>
29#include <qlabel.h>
30#include <qlineedit.h>
31#include <qlistview.h>
32#include <qtabwidget.h>
33#include <qaction.h>
34#include <qlayout.h>
35#include <qtooltip.h>
36#include <qimage.h>
37#include <qpixmap.h>
38#include <qstringlist.h>
39#include <qprogressbar.h>
40#include <qstatusbar.h>
41#include <qdir.h>
42#include <stdlib.h>
43
44#include "emailhandler.h"
45#include "emaillistitem.h"
46#include "textparser.h"
47#include "editaccount.h"
48#include "maillist.h"
49#include "addresslist.h"
50
51#include <qpe/config.h>
52
53class AccountList : public QList<MailAccount>
54{
55public:
56 Item newItem(Item d);
57private:
58 MailAccount* dupl(MailAccount *in);
59 MailAccount *ac;
60};
61
62//class EmailClient : public EmailClientBase
63class EmailClient : public QMainWindow
64{
65 Q_OBJECT
66
67public:
68 EmailClient( QWidget* parent, const char* name, WFlags fl = 0 );
69 ~EmailClient();
70 AddressList* getAdrListRef();
71
72signals:
73 void composeRequested();
74 void viewEmail(QListView *, Email *);
75 void mailUpdated(Email *);
76 void newCaption(const QString &);
77
78public slots:
79 void compose();
80 void cancel();
81 void enqueMail(const Email &mail);
82 void setMailAccount();
83 void sendQuedMail();
84 void mailSent();
85 void getNewMail();
86 void getAllNewMail();
87 void smtpError(int code);
88 void popError(int code);
89 void inboxItemSelected();
90 void outboxItemSelected();
91 void mailArrived(const Email &mail, bool fromDisk);
92 void allMailArrived(int);
93 void saveMail(QString fileName, QListView *view);
94 void selectAccount(int);
95 void editAccount(int);
96 void updateAccounts();
97 void deleteAccount(int);
98 void deleteMail(EmailListItem *mailItem, bool &inbox);
99 void setTotalSize(int);
100 void setMailSize(int);
101 void setDownloadedSize(int);
102 void moveMailFront(Email *mailPtr);
103
104private:
105 void init();
106 void readMail();
107 QString getPath(bool enclosurePath);
108 void readSettings();
109 void saveSettings();
110
111private:
112 Config *mailconf;
113 int newAccountId, idCount, mailIdCount;
114 int accountIdCount;
115 AccountList accountList;
116 AddressList *addressList;
117
118 EditAccount *editAccountView;
119 EmailListItem *item;
120 EmailHandler *emailHandler;
121 QList<Email> quedMessages;
122 MailList mailDownloadList;
123 bool sending, receiving, previewingMail, allAccounts;
124 QString lineShift;
125 MailAccount account, *currentAccount;
126
127 QToolBar *bar;
128 QProgressBar *progressBar;
129 QStatusBar *statusBar;
130 QLabel *status1Label, *status2Label;
131 QAction *getMailButton;
132 QAction *sendMailButton;
133 QAction *composeButton;
134 QAction *cancelButton;
135
136 QMenuBar *mb;
137 QPopupMenu *selectAccountMenu;
138 QPopupMenu *editAccountMenu;
139 QPopupMenu *deleteAccountMenu;
140
141 QTabWidget* mailboxView;
142 QListView* inboxView;
143 QListView* outboxView;
144
145 QGridLayout* grid_2;
146 QGridLayout* grid_3;
147};
148
149#endif // EMAILCLIENT_H
diff --git a/noncore/net/mailit/emailhandler.cpp b/noncore/net/mailit/emailhandler.cpp
new file mode 100644
index 0000000..a086dfc
--- a/dev/null
+++ b/noncore/net/mailit/emailhandler.cpp
@@ -0,0 +1,589 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qfileinfo.h>
21#include <stdlib.h>
22#include <qapplication.h>
23#include <qmessagebox.h>
24#include <qcstring.h>
25#include "emailhandler.h"
26#include <qpe/applnk.h>
27#include <qpe/filemanager.h>
28
29QCollection::Item EnclosureList::newItem(QCollection::Item d)
30{
31 return dupl( (Enclosure *) d);
32}
33
34Enclosure* EnclosureList::dupl(Enclosure *in)
35{
36 ac = new Enclosure(*in);
37 return ac;
38}
39
40EmailHandler::EmailHandler()
41{
42 smtpClient = new SmtpClient();
43 popClient = new PopClient();
44
45 connect(smtpClient, SIGNAL(errorOccurred(int)), this,
46 SIGNAL(smtpError(int)) );
47 connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) );
48 connect(smtpClient, SIGNAL(updateStatus(const QString &)), this,
49 SIGNAL(updateSmtpStatus(const QString &)) );
50
51 connect(popClient, SIGNAL(errorOccurred(int)), this,
52 SIGNAL(popError(int)) );
53 connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)),
54 this, SLOT(messageArrived(const QString &, int, uint, bool)) );
55 connect(popClient, SIGNAL(updateStatus(const QString &)), this,
56 SIGNAL(updatePopStatus(const QString &)) );
57 connect(popClient, SIGNAL(mailTransfered(int)), this,
58 SIGNAL(mailTransfered(int)) );
59
60
61 //relaying size information
62 connect(popClient, SIGNAL(currentMailSize(int)),
63 this, SIGNAL(currentMailSize(int)) );
64 connect(popClient, SIGNAL(downloadedSize(int)),
65 this, SIGNAL(downloadedSize(int)) );
66}
67
68void EmailHandler::sendMail(QList<Email> *mailList)
69{
70 Email *currentMail;
71 QString temp;
72 QString userName = mailAccount.name;
73 userName += " <" + mailAccount.emailAddress + ">";
74
75 for (currentMail = mailList->first(); currentMail != 0;
76 currentMail = mailList->next()) {
77
78 if (encodeMime(currentMail) == 0) {
79 smtpClient->addMail(userName, currentMail->subject,
80 currentMail->recipients, currentMail->rawMail);
81 } else { //error
82 temp = tr("Could not locate all files in \nmail with subject: ") +
83 currentMail->subject;
84 temp += tr("\nMail has NOT been sent");
85 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n"));
86
87 }
88 }
89 smtpClient->newConnection(mailAccount.smtpServer, 25);
90}
91
92void EmailHandler::setAccount(MailAccount account)
93{
94 mailAccount = account;
95}
96
97void EmailHandler::getMail()
98{
99 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
100 if (mailAccount.synchronize) {
101 popClient->setSynchronize(mailAccount.lastServerMailCount);
102 } else {
103 popClient->removeSynchronize();
104 }
105
106 headers = FALSE;
107 popClient->headersOnly(headers, 0);
108 popClient->newConnection(mailAccount.popServer, 110);
109}
110
111void EmailHandler::getMailHeaders()
112{
113 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
114 if (mailAccount.synchronize) {
115 popClient->setSynchronize(mailAccount.lastServerMailCount);
116 } else {
117 popClient->removeSynchronize();
118 }
119
120 headers = TRUE;
121 popClient->headersOnly(headers, 2000); //less than 2000, download all
122 popClient->newConnection(mailAccount.popServer, 110);
123}
124
125void EmailHandler::getMailByList(MailList *mailList)
126{
127 if (mailList->count() == 0) { //should not occur though
128 emit mailTransfered(0);
129 return;
130 }
131
132 headers = FALSE;
133 popClient->headersOnly(FALSE, 0);
134 popClient->newConnection(mailAccount.popServer, 110);
135 popClient->setSelectedMails(mailList);
136}
137
138void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete)
139{
140 Email mail;
141
142 mail.rawMail = message;
143 mail.serverId = id;
144 mail.size = size;
145 mail.downloaded = complete;
146
147 emit mailArrived(mail, FALSE);
148}
149
150bool EmailHandler::parse(QString in, QString lineShift, Email *mail)
151{
152 QString temp, boundary;
153 int pos;
154 QString delimiter, header, body, mimeHeader, mimeBody;
155 QString content, contentType, contentAttribute, id, encoding;
156 QString fileName, storedName;
157 int enclosureId = 0;
158
159 mail->rawMail = in;
160 mail->received = TRUE;
161 mail->files.setAutoDelete(TRUE);
162
163 temp = lineShift + "." + lineShift;
164
165 if (in.right(temp.length()) != temp) {
166 qWarning(in.right(temp.length()));
167 qWarning(" . added at end of email as separator");
168 mail->rawMail += temp;
169 }
170
171
172 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n"
173 pos = in.find(delimiter, 0, FALSE);
174 header = in.left(pos);
175 body = in.right(in.length() - pos - delimiter.length());
176 if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n'))
177 body.truncate(body.length()-2);
178
179 TextParser p(header, lineShift);
180
181 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) {
182 pos++;
183 if (p.separatorAt(pos) == ' ') {
184 mail->from = p.getString(&pos, '<');
185 mail->from = mail->from.stripWhiteSpace();
186 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) {
187 mail->from = mail->from.left(mail->from.length() - 1);
188 mail->from = mail->from.right(mail->from.length() - 1);
189 }
190 pos++;
191 mail->fromMail = p.getString(&pos, '>');
192 } else {
193 if ((p.separatorAt(pos) == '<')
194 || (p.separatorAt(pos) == ' ')) //No name.. nasty
195 pos++;
196 pos++;
197 mail->fromMail = p.getString(&pos, 'z', TRUE);
198 if (mail->fromMail.at(mail->fromMail.length()-1) == '>')
199 mail->fromMail.truncate(mail->fromMail.length() - 1);
200 mail->from=mail->fromMail;
201 }
202 }
203 if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) {
204 pos++;
205 mail->subject = p.getString(&pos, 'z', TRUE);
206 }
207 if ((pos = p.find("DATE",':', 0, TRUE)) != -1) {
208 pos++;
209 mail->date = p.getString(&pos, 'z', true);
210 }
211 if ((pos = p.find("TO",':', 0, TRUE)) != -1) {
212 pos++;
213 mail->recipients.append (p.getString(&pos, 'z', TRUE) );
214 }
215 if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) {
216 pos++;
217 if ( (p.wordAt(pos).upper() == "ID") &&
218 (p.separatorAt(pos) == ':') ) {
219
220 id = p.getString(&pos, 'z', TRUE);
221 mail->id = id;
222 }
223 }
224
225 pos = 0;
226 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) {
227 pos++;
228 if ( (p.wordAt(pos).upper() == "VERSION") &&
229 (p.separatorAt(pos) == ':') ) {
230 pos++;
231 if (p.getString(&pos, 'z', true) == "1.0") {
232 mail->mimeType = 1;
233 }
234 }
235 }
236
237 if (mail->mimeType == 1) {
238 boundary = "";
239 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) {
240 pos++;
241 boundary = p.getString(&pos, 'z', true);
242 if (boundary[0] == '"') {
243 boundary = boundary.left(boundary.length() - 1); //strip "
244 boundary = boundary.right(boundary.length() - 1); //strip "
245 }
246 boundary = "--" + boundary; //create boundary field
247 }
248
249 if (boundary == "") { //fooled by Mime-Version
250 mail->body = body;
251 mail->bodyPlain = body;
252 return mail;
253 }
254
255 while (body.length() > 0) {
256 pos = body.find(boundary, 0, FALSE);
257 pos = body.find(delimiter, pos, FALSE);
258 mimeHeader = body.left(pos);
259 mimeBody = body.right(body.length() - pos - delimiter.length());
260 TextParser bp(mimeHeader, lineShift);
261
262 contentType = "";
263 contentAttribute = "";
264 fileName = "";
265 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) {
266 pos++;
267 if ( (bp.wordAt(pos).upper() == "TYPE") &&
268 (bp.separatorAt(pos) == ':') ) {
269 contentType = bp.nextWord().upper();
270 if (bp.nextSeparator() == '/')
271 contentAttribute = bp.nextWord().upper();
272 content = contentType + "/" + contentAttribute;
273 }
274 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) {
275 pos++;
276 encoding = bp.getString(&pos, 'z', TRUE);
277 }
278
279 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) {
280 pos++;
281 fileName = bp.getString(&pos, 'z', TRUE);
282 fileName = fileName.right(fileName.length() - 1);
283 fileName = fileName.left(fileName.length() - 1);
284 }
285
286 }
287 pos = mimeBody.find(boundary, 0, FALSE);
288 if (pos == -1) //should not occur, malformed mail
289 pos = mimeBody.length();
290 body = mimeBody.right(mimeBody.length() - pos);
291 mimeBody = mimeBody.left(pos);
292
293 if (fileName != "") { //attatchments of some type, audio, image etc.
294
295 Enclosure e;
296 e.id = enclosureId;
297 e.originalName = fileName;
298 e.contentType = contentType;
299 e.contentAttribute = contentAttribute;
300 e.encoding = encoding;
301 e.body = mimeBody;
302 e.saved = FALSE;
303 mail->addEnclosure(&e);
304 enclosureId++;
305
306 } else if (contentType == "TEXT") {
307 if (contentAttribute == "PLAIN") {
308 mail->body = mimeBody;
309 mail->bodyPlain = mimeBody;
310 }
311 if (contentAttribute == "HTML") {
312 mail->body = mimeBody;
313 }
314 }
315 }
316 } else {
317 mail->bodyPlain = body;
318 mail->body = body;
319 }
320 return TRUE;
321}
322
323bool EmailHandler::getEnclosure(Enclosure *ePtr)
324{
325 QFile f(ePtr->path + ePtr->name);
326 char src[4];
327 char *destPtr;
328 QByteArray buffer;
329 uint bufCount, pos, decodedCount, size, x;
330
331 if (! f.open(IO_WriteOnly) ) {
332 qWarning("could not save: " + ePtr->path + ePtr->name);
333 return FALSE;
334 }
335
336 if (ePtr->encoding.upper() == "BASE64") {
337 size = (ePtr->body.length() * 3 / 4); //approximate size (always above)
338 buffer.resize(size);
339 bufCount = 0;
340 pos = 0;
341 destPtr = buffer.data();
342
343 while (pos < ePtr->body.length()) {
344 decodedCount = 4;
345 x = 0;
346 while ( (x < 4) && (pos < ePtr->body.length()) ) {
347 src[x] = ePtr->body[pos].latin1();
348 pos++;
349 if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ')
350 x--;
351 x++;
352 }
353 if (x > 1) {
354 decodedCount = parse64base(src, destPtr);
355 destPtr += decodedCount;
356 bufCount += decodedCount;
357 }
358 }
359
360 buffer.resize(bufCount); //set correct length of file
361 f.writeBlock(buffer);
362 } else {
363 QTextStream t(&f);
364 t << ePtr->body;
365 }
366 return TRUE;
367}
368
369int EmailHandler::parse64base(char *src, char *bufOut) {
370
371 char c, z;
372 char li[4];
373 int processed;
374
375 //conversion table withouth table...
376 for (int x = 0; x < 4; x++) {
377 c = src[x];
378
379 if ( (int) c >= 'A' && (int) c <= 'Z')
380 li[x] = (int) c - (int) 'A';
381 if ( (int) c >= 'a' && (int) c <= 'z')
382 li[x] = (int) c - (int) 'a' + 26;
383 if ( (int) c >= '0' && (int) c <= '9')
384 li[x] = (int) c - (int) '0' + 52;
385 if (c == '+')
386 li[x] = 62;
387 if (c == '/')
388 li[x] = 63;
389 }
390
391 processed = 1;
392 bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits
393 bufOut[0] <<= 2;
394 z = li[1] >> 4;
395 bufOut[0] = bufOut[0] | z; //first byte retrived
396
397 if (src[2] != '=') {
398 bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits
399 bufOut[1] <<= 4;
400 z = li[2] >> 2;
401 bufOut[1] = bufOut[1] | z; //second byte retrived
402 processed++;
403
404 if (src[3] != '=') {
405 bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits
406 bufOut[2] <<= 6;
407 z = li[3];
408 bufOut[2] = bufOut[2] | z; //third byte retrieved
409 processed++;
410 }
411 }
412 return processed;
413}
414
415int EmailHandler::encodeMime(Email *mail) {
416 QString fileName, fileType, contentType, newBody, boundary;
417 Enclosure *ePtr;
418
419 QString userName = mailAccount.name;
420 userName += " <" + mailAccount.emailAddress + ">";
421
422 //add standard headers
423 newBody = "From: " + userName + "\r\nTo: ";
424 for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) {
425 newBody += *it + " ";
426 }
427 newBody += "\r\nSubject: " + mail->subject + "\r\n";
428
429 if (mail->files.count() == 0) { //just a simple mail
430 newBody += "\r\n" + mail->body;
431 mail->rawMail = newBody;
432 return 0;
433 }
434
435 //Build mime encoded mail
436 boundary = "-----4345=next_bound=0495----";
437
438 newBody += "Mime-Version: 1.0\r\n";
439 newBody += "Content-Type: multipart/mixed; boundary=\"" +
440 boundary + "\"\r\n\r\n";
441
442 newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n";
443 newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n";
444 newBody += mail->body;
445
446 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
447 fileName = ePtr->originalName;
448 fileType = ePtr->contentType;
449 QFileInfo fi(fileName);
450
451 // This specification of contentType is temporary
452 contentType = "";
453 if (fileType == "Picture") {
454 contentType = "image/x-image";
455 } else if (fileType == "Document") {
456 contentType = "text/plain";
457 } else if (fileType == "Sound") {
458 contentType = "audio/x-wav";
459 } else if (fileType == "Movie") {
460 contentType = "video/mpeg";
461 } else {
462 contentType = "application/octet-stream";
463 }
464
465 newBody += "\r\n\r\n--" + boundary + "\r\n";
466 newBody += "Content-Type: " + contentType + "; name=\"" +
467 fi.fileName() + "\"\r\n";
468 newBody += "Content-Transfer-Encoding: base64\r\n";
469 newBody += "Content-Disposition: inline; filename=\"" +
470 fi.fileName() + "\"\r\n\r\n";
471
472 if (encodeFile(fileName, &newBody) == -1) //file not found?
473 return -1;
474 }
475
476 newBody += "\r\n\r\n--" + boundary + "--";
477 mail->rawMail = newBody;
478
479 return 0;
480}
481
482int EmailHandler::encodeFile(QString fileName, QString *toBody)
483{
484 char *fileData;
485 char *dataPtr;
486 QString temp;
487 uint dataSize, count;
488 QFile f(fileName);
489
490 if (! f.open(IO_ReadOnly) ) {
491 qWarning("could not open file: " + fileName);
492 return -1;
493 }
494 QTextStream s(&f);
495 dataSize = f.size();
496 fileData = (char *) malloc(dataSize + 3);
497 s.readRawBytes(fileData, dataSize);
498
499 temp = "";
500 dataPtr = fileData;
501 count = 0;
502 while (dataSize > 0) {
503 if (dataSize < 3) {
504 encode64base(dataPtr, &temp, dataSize);
505 dataSize = 0;
506 } else {
507 encode64base(dataPtr, &temp, 3);
508 dataSize -= 3;
509 dataPtr += 3;
510 count += 4;
511 }
512 if (count > 72) {
513 count = 0;
514 temp += "\r\n";
515 }
516 }
517 toBody->append(temp);
518
519 delete(fileData);
520 f.close();
521 return 0;
522}
523
524void EmailHandler::encode64base(char *src, QString *dest, int len)
525{
526 QString temp;
527 uchar c;
528 uchar bufOut[4];
529
530 bufOut[0] = src[0];
531 bufOut[0] >>= 2; //Done byte 0
532
533 bufOut[1] = src[0];
534 bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits
535 bufOut[1] <<= 4; //copy up 4 places
536 if (len > 1) {
537 c = src[1];
538 } else {
539 c = 0;
540 }
541
542 c = c & (16 + 32 + 64 + 128);
543 c >>= 4;
544 bufOut[1] = bufOut[1] | c; //Done byte 1
545
546 bufOut[2] = src[1];
547 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8);
548 bufOut[2] <<= 2;
549 if (len > 2) {
550 c = src[2];
551 } else {
552 c = 0;
553 }
554 c >>= 6;
555 bufOut[2] = bufOut[2] | c;
556
557 bufOut[3] = src[2];
558 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32);
559
560 if (len == 1) {
561 bufOut[2] = 64;
562 bufOut[3] = 64;
563 }
564 if (len == 2) {
565 bufOut[3] = 64;
566 }
567 for (int x = 0; x < 4; x++) {
568 if (bufOut[x] <= 25)
569 bufOut[x] += (uint) 'A';
570 else if (bufOut[x] >= 26 && bufOut[x] <= 51)
571 bufOut[x] += (uint) 'a' - 26;
572 else if (bufOut[x] >= 52 && bufOut[x] <= 61)
573 bufOut[x] += (uint) '0' - 52;
574 else if (bufOut[x] == 62)
575 bufOut[x] = '+';
576 else if (bufOut[x] == 63)
577 bufOut[x] = '/';
578 else if (bufOut[x] == 64)
579 bufOut[x] = '=';
580
581 dest->append(bufOut[x]);
582 }
583}
584
585void EmailHandler::cancel()
586{
587 popClient->errorHandling(ErrCancel);
588 smtpClient->errorHandling(ErrCancel);
589}
diff --git a/noncore/net/mailit/emailhandler.h b/noncore/net/mailit/emailhandler.h
new file mode 100644
index 0000000..17c4414
--- a/dev/null
+++ b/noncore/net/mailit/emailhandler.h
@@ -0,0 +1,147 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef EmailHandler_H
21#define EmailHandler_H
22
23#include <qobject.h>
24#include <qstring.h>
25#include <qdatetime.h>
26#include <qlist.h>
27#include <qstringlist.h>
28#include <qfile.h>
29#include <qstringlist.h>
30#include <qcollection.h>
31
32#include "smtpclient.h"
33#include "popclient.h"
34#include "textparser.h"
35#include "maillist.h"
36
37struct Enclosure
38{
39 int id;
40 QString originalName;
41 QString name;
42 QString path;
43 QString contentType;
44 QString contentAttribute;
45 QString encoding;
46 QString body; //might use to much mem. check!!
47 bool saved, installed;
48};
49
50class EnclosureList : public QList<Enclosure>
51{
52public:
53 Item newItem(Item d);
54private:
55 Enclosure* dupl(Enclosure *in);
56 Enclosure *ac;
57};
58
59struct Email
60{
61 QString id;
62 QString from;
63 QString fromMail;
64 QStringList recipients;
65 QStringList carbonCopies;
66 QString date;
67 QString subject;
68 QString body;
69 QString bodyPlain;
70 bool sent, received, read, downloaded;
71 QString rawMail;
72 int mimeType; //1 = Mime 1.0
73 int serverId;
74 int internalId;
75 int fromAccountId;
76 QString contentType; //0 = text
77 QString contentAttribute; //0 = plain, 1 = html
78 EnclosureList files;
79 uint size;
80
81 void addEnclosure(Enclosure *e)
82 {
83 files.append(e);
84 }
85};
86
87struct MailAccount
88{
89 QString accountName;
90 QString name;
91 QString emailAddress;
92 QString popUserName;
93 QString popPasswd;
94 QString popServer;
95 QString smtpServer;
96 bool synchronize;
97 int lastServerMailCount;
98 int id;
99};
100
101 const int ErrUnknownResponse = 1001;
102 const int ErrLoginFailed = 1002;
103 const int ErrCancel = 1003;
104
105
106class EmailHandler : public QObject
107{
108 Q_OBJECT
109
110public:
111 EmailHandler();
112 void setAccount(MailAccount account);
113 void sendMail(QList<Email> *mailList);
114 void getMail();
115 void getMailHeaders();
116 void getMailByList(MailList *mailList);
117 bool parse(QString in, QString lineShift, Email *mail);
118 bool getEnclosure(Enclosure *ePtr);
119 int parse64base(char *src, char *dest);
120 int encodeMime(Email *mail);
121 int encodeFile(QString fileName, QString *toBody);
122 void encode64base(char *src, QString *dest, int len);
123 void cancel();
124
125signals:
126 void mailSent();
127 void smtpError(int);
128 void popError(int);
129 void mailArrived(const Email &, bool);
130 void updatePopStatus(const QString &);
131 void updateSmtpStatus(const QString &);
132 void mailTransfered(int);
133 void mailboxSize(int);
134 void currentMailSize(int);
135 void downloadedSize(int);
136
137public slots:
138 void messageArrived(const QString &, int id, uint size, bool complete);
139
140private:
141 MailAccount mailAccount;
142 SmtpClient *smtpClient;
143 PopClient *popClient;
144 bool headers;
145};
146
147#endif
diff --git a/noncore/net/mailit/emaillistitem.cpp b/noncore/net/mailit/emaillistitem.cpp
new file mode 100644
index 0000000..d47b0b7
--- a/dev/null
+++ b/noncore/net/mailit/emaillistitem.cpp
@@ -0,0 +1,92 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qstring.h>
21#include "emaillistitem.h"
22
23EmailListItem::EmailListItem(QListView *parent, Email mailIn, bool inbox)
24 : QListViewItem(parent)
25{
26 QString temp;
27
28 mail = mailIn;
29
30 if (inbox) {
31 setText(0, mail.from);
32 } else {
33 QStringList::Iterator it = mail.recipients.begin();
34 temp = *it;
35 if (mail.recipients.count() > 1)
36 temp += "...";
37 setText(0, temp);
38 }
39 setText(1, mail.subject);
40
41 selected = FALSE;
42}
43
44Email* EmailListItem::getMail()
45{
46 return &mail;
47}
48
49void EmailListItem::setMail(Email newMail)
50{
51 mail = newMail;
52 repaint();
53}
54
55void EmailListItem::setItemSelected(bool enable)
56{
57 selected = enable;
58 setSelected(enable);
59 repaint();
60}
61
62bool EmailListItem::isItemSelected()
63{
64 return selected;
65}
66
67void EmailListItem::paintCell( QPainter *p, const QColorGroup &cg,
68 int column, int width, int alignment )
69{
70
71 QColorGroup _cg( cg );
72 QColor c = _cg.text();
73
74 if ( (! mail.read) && (mail.received) )
75 _cg.setColor( QColorGroup::Text, Qt::blue);
76 if (!mail.downloaded)
77 _cg.setColor( QColorGroup::Text, Qt::red);
78
79 /*if (selected) {
80 _cg.setColor(QColorGroup::Base, Qt::blue);
81 _cg.setColor(QColorGroup::Text, Qt::yellow);
82 if (isSelected()) {
83 _cg.setColor(QColorGroup::HighlightedText, Qt::yellow);
84 } else {
85 _cg.setColor(QColorGroup::Highlight, Qt::blue);
86 }
87 }
88 */
89 QListViewItem::paintCell( p, _cg, column, width, alignment );
90
91 _cg.setColor( QColorGroup::Text, c );
92}
diff --git a/noncore/net/mailit/emaillistitem.h b/noncore/net/mailit/emaillistitem.h
new file mode 100644
index 0000000..642932c
--- a/dev/null
+++ b/noncore/net/mailit/emaillistitem.h
@@ -0,0 +1,44 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef EMAILLISTITEM_H
21#define EMAILLISTITEM_H
22
23#include <qlistview.h>
24#include "emailhandler.h"
25
26class EmailListItem: public QListViewItem
27{
28public:
29 EmailListItem(QListView *parent, Email mailIn, bool inbox);
30 Email* getMail();
31 void setMail(Email newMail);
32 void setItemSelected(bool enable);
33 bool isItemSelected();
34 bool itemSelected();
35
36protected:
37 void paintCell( QPainter *p, const QColorGroup &cg,
38 int column, int width, int alignment );
39private:
40 Email mail;
41 bool selected;
42};
43
44#endif
diff --git a/noncore/net/mailit/getmail.xpm b/noncore/net/mailit/getmail.xpm
new file mode 100644
index 0000000..d294656
--- a/dev/null
+++ b/noncore/net/mailit/getmail.xpm
@@ -0,0 +1,21 @@
1/* XPM */
2static char*getmail[]={
3"16 13 5 1",
4"# c #040404",
5"a c #c3c3c3",
6"c c #000000",
7". c None",
8"b c #ffffff",
9".........###....",
10"........#...#.#.",
11".............##.",
12"............###.",
13"................",
14"..............aa",
15".bbbbbbbbbbbbbba",
16".bbbcbbcbbbcccba",
17".bbcbccbbbbcbcba",
18".bbbbbbbbbbcccba",
19".bbcbcccbbbbbbba",
20".bbbcbbbbbbbbbba",
21".bbbbbbbbbbbbbba"};
diff --git a/noncore/net/mailit/mailit.pro b/noncore/net/mailit/mailit.pro
new file mode 100644
index 0000000..653f2e2
--- a/dev/null
+++ b/noncore/net/mailit/mailit.pro
@@ -0,0 +1,44 @@
1TEMPLATE = app
2CONFIG = qt warn_on release
3HEADERS = emailclient.h \
4 emailhandler.h \
5 emaillistitem.h \
6 mailitwindow.h \
7 md5.h \
8 popclient.h \
9 readmail.h \
10 smtpclient.h \
11 writemail.h \
12 textparser.h \
13 viewatt.h \
14 addatt.h \
15 editaccount.h \
16 maillist.h \
17 addresslist.h
18SOURCES = emailclient.cpp \
19 emailhandler.cpp \
20 emaillistitem.cpp \
21 mailitwindow.cpp \
22 main.cpp \
23 md5.c \
24 popclient.cpp \
25 readmail.cpp \
26 smtpclient.cpp \
27 writemail.cpp \
28 textparser.cpp \
29 viewatt.cpp \
30 addatt.cpp \
31 editaccount.cpp \
32 maillist.cpp \
33 addresslist.cpp
34
35DESTDIR = ../bin
36INCLUDEPATH += $(QPEDIR)/include:../library
37DEPENDPATH += $(QPEDIR)/include:../library
38LIBS += -lqpe
39# -lssl
40MOC_DIR=qpeobj
41OBJECTS_DIR=qpeobj
42DESTDIR=$(OPIEDIR)/bin
43
44include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/net/mailit/mailitwindow.cpp b/noncore/net/mailit/mailitwindow.cpp
new file mode 100644
index 0000000..f9b6de2
--- a/dev/null
+++ b/noncore/net/mailit/mailitwindow.cpp
@@ -0,0 +1,132 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "mailitwindow.h"
21
22MailItWindow::MailItWindow(QWidget *parent, const char *name, WFlags fl)
23 : QMainWindow(parent, name, fl)
24{
25 currentCaption = "Mailit";
26 setCaption(tr(currentCaption));
27 views = new QWidgetStack(this);
28 setCentralWidget(views);
29
30 emailClient = new EmailClient(views, "client");
31 writeMail = new WriteMail(views, "writing");
32 readMail = new ReadMail(views, "reading");
33
34 views->raiseWidget(emailClient);
35
36 connect(emailClient, SIGNAL(composeRequested()),
37 this, SLOT(compose()) );
38 connect(emailClient, SIGNAL(viewEmail(QListView *, Email *)), this,
39 SLOT(viewMail(QListView *, Email *)) );
40 connect(emailClient, SIGNAL(mailUpdated(Email *)), this,
41 SLOT(updateMailView(Email *)) );
42
43 connect(writeMail, SIGNAL(cancelMail()), this, SLOT(showEmailClient()) );
44 connect(writeMail, SIGNAL(sendMailRequested(const Email &)), this,
45 SLOT(showEmailClient()) );
46 connect(writeMail, SIGNAL(sendMailRequested(const Email &)), emailClient,
47 SLOT(enqueMail(const Email &)) );
48
49 connect(readMail, SIGNAL(cancelView()), this, SLOT(showEmailClient()) );
50 connect(readMail, SIGNAL(replyRequested(Email &)), this,
51 SLOT(composeReply(Email &)) );
52 connect(readMail, SIGNAL(removeItem(EmailListItem *, bool &)), emailClient,
53 SLOT(deleteMail(EmailListItem *, bool &)) );
54 connect(readMail, SIGNAL(viewingMail(Email *)), emailClient,
55 SLOT(moveMailFront(Email *)) );
56
57 connect(emailClient, SIGNAL(newCaption(const QString &)),
58 this, SLOT(updateCaption(const QString &)) );
59 viewingMail = FALSE;
60}
61
62MailItWindow::~MailItWindow()
63{
64}
65
66void MailItWindow::closeEvent(QCloseEvent *e)
67{
68 if (views->visibleWidget() == emailClient) {
69 e->accept();
70 } else {
71 showEmailClient();
72 }
73}
74
75void MailItWindow::compose()
76{
77 viewingMail = FALSE;
78 emailClient->hide();
79 readMail->hide();
80 views->raiseWidget(writeMail);
81 writeMail->setAddressList(emailClient->getAdrListRef());
82 setCaption( tr( "Write mail" ) );
83}
84
85void MailItWindow::composeReply(Email &mail)
86{
87 compose();
88 writeMail->reply(mail);
89}
90
91void MailItWindow::showEmailClient()
92{
93 viewingMail = FALSE;
94 writeMail->hide();
95 readMail->hide();
96 views->raiseWidget(emailClient);
97 setCaption( tr(currentCaption) );
98}
99
100void MailItWindow::viewMail(QListView *view, Email *mail)
101{
102 viewingMail = TRUE;
103 emailClient->hide();
104 readMail->update(view, mail);
105 views->raiseWidget(readMail);
106 setCaption( tr( "Examine mail" ) );
107}
108
109void MailItWindow::updateMailView(Email *mail)
110{
111 if (viewingMail) {
112 readMail->mailUpdated(mail);
113 }
114}
115
116void MailItWindow::updateCaption(const QString &newCaption)
117{
118 currentCaption = newCaption;
119 setCaption(tr(currentCaption));
120}
121
122void MailItWindow::setDocument(const QString &_address)
123{
124 // strip leading 'mailto:'
125 QString address = _address;
126 if (address.startsWith("mailto:"))
127 address = address.mid(6);
128
129 compose();
130 writeMail->setRecipient(address);
131}
132
diff --git a/noncore/net/mailit/mailitwindow.h b/noncore/net/mailit/mailitwindow.h
new file mode 100644
index 0000000..667960b
--- a/dev/null
+++ b/noncore/net/mailit/mailitwindow.h
@@ -0,0 +1,58 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef MailItWindow_H
21#define MailItWindow_H
22
23#include <qmainwindow.h>
24#include <qwidgetstack.h>
25#include <qevent.h>
26//#include <qlayout.h>
27#include "emailclient.h"
28#include "writemail.h"
29#include "readmail.h"
30#include "addresslist.h"
31
32class MailItWindow: public QMainWindow
33{
34 Q_OBJECT
35public:
36 MailItWindow(QWidget *parent = 0, const char *name = 0, WFlags fl = 0);
37 ~MailItWindow();
38
39public slots:
40 void compose();
41 void composeReply(Email &);
42 void showEmailClient();
43 void viewMail(QListView *, Email *mail);
44 void updateMailView(Email *mail);
45 void closeEvent(QCloseEvent *e);
46 void updateCaption(const QString &);
47 void setDocument(const QString &);
48
49private:
50 EmailClient *emailClient;
51 WriteMail *writeMail;
52 ReadMail *readMail;
53 QWidgetStack *views;
54 QString currentCaption;
55 bool viewingMail;
56};
57
58#endif
diff --git a/noncore/net/mailit/maillist.cpp b/noncore/net/mailit/maillist.cpp
new file mode 100644
index 0000000..b5325a9
--- a/dev/null
+++ b/noncore/net/mailit/maillist.cpp
@@ -0,0 +1,131 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "maillist.h"
21
22void MailList::clear()
23{
24 sortedList.setAutoDelete(TRUE);
25 sortedList.clear();
26 currentPos = 0;
27}
28
29int MailList::count()
30{
31 return sortedList.count();
32}
33
34int* MailList::first()
35{
36 dList *mPtr;
37
38 if (sortedList.count() == 0)
39 return NULL;
40
41 mPtr = sortedList.at(0);
42 currentPos = 1;
43 return &(mPtr->serverId);
44}
45
46int* MailList::next()
47{
48 dList *mPtr;
49
50 if ( (currentPos) >= sortedList.count())
51 return NULL;
52
53 mPtr = sortedList.at(currentPos);
54 currentPos++;
55 return &(mPtr->serverId);
56}
57
58void MailList::sizeInsert(int serverId, uint size)
59{
60 dList *tempPtr;
61 int x;
62
63 dList *newEntry = new dList;
64 newEntry->serverId = serverId;
65 newEntry->size = size;
66
67 for (tempPtr = sortedList.first(); tempPtr != NULL; tempPtr = sortedList.next() ) {
68 if (newEntry->size < tempPtr->size) {
69 x = sortedList.at();
70 sortedList.insert(x, newEntry);
71 return;
72 }
73 }
74 sortedList.append(newEntry);
75}
76
77void MailList::moveFront(int serverId, uint size)
78{
79 dList *currentPtr;
80 uint tempPos;
81 QString temp;
82
83 tempPos = currentPos;
84 if ( tempPos >= sortedList.count() )
85 return;
86 currentPtr = sortedList.at(tempPos);
87 while ( ((tempPos+1) < sortedList.count()) && ( currentPtr->serverId != serverId) ) {
88 tempPos++;
89 currentPtr = sortedList.at(tempPos);
90 }
91
92 if ( (currentPtr != NULL) && (currentPtr->serverId == serverId) ) {
93 temp.setNum(currentPtr->serverId);
94 qWarning("moved to front, message: " + temp);
95
96 dList *itemPtr = sortedList.take(tempPos);
97 sortedList.insert(currentPos, itemPtr);
98 }
99
100}
101
102//only works if mail is not already in download
103bool MailList::remove(int serverId, uint size)
104{
105 dList *currentPtr;
106 uint tempPos;
107 QString temp;
108
109 tempPos = currentPos;
110 if ( tempPos >=sortedList.count() )
111 return FALSE;
112 currentPtr = sortedList.at(tempPos);
113 while ( ((tempPos + 1) < sortedList.count()) && ( currentPtr->serverId != serverId) ) {
114 tempPos++;
115 currentPtr = sortedList.at(tempPos);
116 }
117
118 if ( (currentPtr != NULL) && (currentPtr->serverId == serverId) ) {
119 temp.setNum(currentPtr->serverId);
120 qWarning("deleted message: " + temp);
121 sortedList.remove(tempPos);
122
123 return TRUE;
124 }
125 return FALSE;
126}
127
128void MailList::insert(int pos, int serverId, uint size)
129{
130 //sortedList.insert(pos, mPtr);
131}
diff --git a/noncore/net/mailit/maillist.h b/noncore/net/mailit/maillist.h
new file mode 100644
index 0000000..ec996df
--- a/dev/null
+++ b/noncore/net/mailit/maillist.h
@@ -0,0 +1,50 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef MAILLIST_H
21#define MAILLIST_H
22
23#include <qobject.h>
24#include <qlist.h>
25
26struct dList{
27 int serverId;
28 uint size;
29};
30
31class MailList : public QObject
32{
33 Q_OBJECT
34
35public:
36 void clear();
37 int count();
38 int* first();
39 int* next();
40 void sizeInsert(int serverId, uint size);
41 void moveFront(int serverId, uint size);
42 bool remove(int serverId, uint size);
43 void insert(int pos, int serverId, uint size);
44
45private:
46 QList<dList> sortedList;
47 uint currentPos;
48};
49
50#endif
diff --git a/noncore/net/mailit/main.cpp b/noncore/net/mailit/main.cpp
new file mode 100644
index 0000000..3a3e1fc
--- a/dev/null
+++ b/noncore/net/mailit/main.cpp
@@ -0,0 +1,29 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qpe/qpeapplication.h>
21#include "mailitwindow.h"
22
23int main(int argc, char* argv[])
24{
25 QPEApplication a( argc, argv );
26 MailItWindow mw(0, 0);
27 a.showMainDocumentWidget(&mw);
28 return a.exec();
29}
diff --git a/noncore/net/mailit/md5.c b/noncore/net/mailit/md5.c
new file mode 100644
index 0000000..611f151
--- a/dev/null
+++ b/noncore/net/mailit/md5.c
@@ -0,0 +1,251 @@
1/*
2 * This code implements the MD5 message-digest algorithm.
3 * The algorithm is due to Ron Rivest. This code was
4 * written by Colin Plumb in 1993, no copyright is claimed.
5 * This code is in the public domain; do with it what you wish.
6 *
7 * Equivalent code is available from RSA Data Security, Inc.
8 * This code has been tested against that, and is equivalent,
9 * except that you don't need to include two pages of legalese
10 * with every copy.
11 *
12 * To compute the message digest of a chunk of bytes, declare an
13 * MD5Context structure, pass it to MD5Init, call MD5Update as
14 * needed on buffers full of bytes, and then call MD5Final, which
15 * will fill a supplied 16-byte array with the digest.
16 *
17 * Changed so as no longer to depend on Colin Plumb's `usual.h' header
18 * definitions; now uses stuff from dpkg's config.h.
19 * - Ian Jackson <ijackson@nyx.cs.du.edu>.
20 * Still in the public domain.
21 *
22 * md5_buffer added by Steven Fuller
23 * Still in the public domain.
24 */
25
26 #include <string.h> /* for memcpy() */
27
28#include "md5.h"
29
30#ifdef WORDS_BIGENDIAN
31void
32byteSwap(UWORD32 *buf, unsigned words)
33{
34 md5byte *p = (md5byte *)buf;
35
36 do {
37 *buf++ = (UWORD32)((unsigned)p[3] << 8 | p[2]) << 16 |
38 ((unsigned)p[1] << 8 | p[0]);
39 p += 4;
40 } while (--words);
41}
42#else
43#define byteSwap(buf,words)
44#endif
45
46/* md5_buffer frontend added for AvP */
47void md5_buffer(char const *buffer, unsigned int len, char *digest)
48{
49 struct MD5Context md5c;
50
51 MD5Init(&md5c);
52 MD5Update(&md5c, (md5byte const *)buffer, len);
53 MD5Final((md5byte *)digest, &md5c);
54 }
55
56/*
57 * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
58 * initialization constants.
59 */
60void
61MD5Init(struct MD5Context *ctx)
62{
63 ctx->buf[0] = 0x67452301;
64 ctx->buf[1] = 0xefcdab89;
65 ctx->buf[2] = 0x98badcfe;
66 ctx->buf[3] = 0x10325476;
67
68 ctx->bytes[0] = 0;
69 ctx->bytes[1] = 0;
70}
71
72/*
73 * Update context to reflect the concatenation of another buffer full
74 * of bytes.
75 */
76void
77MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len)
78{
79 UWORD32 t;
80
81 /* Update byte count */
82
83 t = ctx->bytes[0];
84 if ((ctx->bytes[0] = t + len) < t)
85 ctx->bytes[1]++;/* Carry from low to high */
86
87 t = 64 - (t & 0x3f);/* Space available in ctx->in (at least 1) */
88 if (t > len) {
89 memcpy((md5byte *)ctx->in + 64 - t, buf, len);
90 return;
91 }
92 /* First chunk is an odd size */
93 memcpy((md5byte *)ctx->in + 64 - t, buf, t);
94 byteSwap(ctx->in, 16);
95 MD5Transform(ctx->buf, ctx->in);
96 buf += t;
97 len -= t;
98
99 /* Process data in 64-byte chunks */
100 while (len >= 64) {
101 memcpy(ctx->in, buf, 64);
102 byteSwap(ctx->in, 16);
103 MD5Transform(ctx->buf, ctx->in);
104 buf += 64;
105 len -= 64;
106 }
107
108 /* Handle any remaining bytes of data. */
109 memcpy(ctx->in, buf, len);
110}
111
112/*
113 * Final wrapup - pad to 64-byte boundary with the bit pattern
114 * 1 0* (64-bit count of bits processed, MSB-first)
115 */
116void
117MD5Final(md5byte digest[16], struct MD5Context *ctx)
118{
119 int count = ctx->bytes[0] & 0x3f;/* Number of bytes in ctx->in */
120 md5byte *p = (md5byte *)ctx->in + count;
121
122 /* Set the first char of padding to 0x80. There is always room. */
123 *p++ = 0x80;
124
125 /* Bytes of padding needed to make 56 bytes (-8..55) */
126 count = 56 - 1 - count;
127
128 if (count < 0) {/* Padding forces an extra block */
129 memset(p, 0, count + 8);
130 byteSwap(ctx->in, 16);
131 MD5Transform(ctx->buf, ctx->in);
132 p = (md5byte *)ctx->in;
133 count = 56;
134 }
135 memset(p, 0, count);
136 byteSwap(ctx->in, 14);
137
138 /* Append length in bits and transform */
139 ctx->in[14] = ctx->bytes[0] << 3;
140 ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
141 MD5Transform(ctx->buf, ctx->in);
142
143 byteSwap(ctx->buf, 4);
144 memcpy(digest, ctx->buf, 16);
145 memset(ctx, 0, sizeof(ctx));/* In case it's sensitive */
146}
147
148#ifndef ASM_MD5
149
150/* The four core functions - F1 is optimized somewhat */
151
152/* #define F1(x, y, z) (x & y | ~x & z) */
153#define F1(x, y, z) (z ^ (x & (y ^ z)))
154#define F2(x, y, z) F1(z, x, y)
155#define F3(x, y, z) (x ^ y ^ z)
156#define F4(x, y, z) (y ^ (x | ~z))
157
158/* This is the central step in the MD5 algorithm. */
159#define MD5STEP(f,w,x,y,z,in,s) \
160 (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
161
162/*
163 * The core of the MD5 algorithm, this alters an existing MD5 hash to
164 * reflect the addition of 16 longwords of new data. MD5Update blocks
165 * the data and converts bytes into longwords for this routine.
166 */
167void
168MD5Transform(UWORD32 buf[4], UWORD32 const in[16])
169{
170 register UWORD32 a, b, c, d;
171
172 a = buf[0];
173 b = buf[1];
174 c = buf[2];
175 d = buf[3];
176
177 MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
178 MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
179 MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
180 MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
181 MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
182 MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
183 MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
184 MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
185 MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
186 MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
187 MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
188 MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
189 MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
190 MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
191 MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
192 MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
193
194 MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
195 MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
196 MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
197 MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
198 MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
199 MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
200 MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
201 MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
202 MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
203 MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
204 MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
205 MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
206 MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
207 MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
208 MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
209 MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
210
211 MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
212 MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
213 MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
214 MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
215 MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
216 MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
217 MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
218 MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
219 MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
220 MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
221 MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
222 MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
223 MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
224 MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
225 MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
226 MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
227
228 MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
229 MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
230 MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
231 MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
232 MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
233 MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
234 MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
235 MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
236 MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
237 MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
238 MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
239 MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
240 MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
241 MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
242 MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
243 MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
244
245 buf[0] += a;
246 buf[1] += b;
247 buf[2] += c;
248 buf[3] += d;
249}
250
251#endif
diff --git a/noncore/net/mailit/md5.h b/noncore/net/mailit/md5.h
new file mode 100644
index 0000000..7e22494
--- a/dev/null
+++ b/noncore/net/mailit/md5.h
@@ -0,0 +1,55 @@
1/*
2 * This is the header file for the MD5 message-digest algorithm.
3 * The algorithm is due to Ron Rivest. This code was
4 * written by Colin Plumb in 1993, no copyright is claimed.
5 * This code is in the public domain; do with it what you wish.
6 *
7 * Equivalent code is available from RSA Data Security, Inc.
8 * This code has been tested against that, and is equivalent,
9 * except that you don't need to include two pages of legalese
10 * with every copy.
11 *
12 * To compute the message digest of a chunk of bytes, declare an
13 * MD5Context structure, pass it to MD5Init, call MD5Update as
14 * needed on buffers full of bytes, and then call MD5Final, which
15 * will fill a supplied 16-byte array with the digest.
16 *
17 * Changed so as no longer to depend on Colin Plumb's `usual.h'
18 * header definitions; now uses stuff from dpkg's config.h
19 * - Ian Jackson <ijackson@nyx.cs.du.edu>.
20 * Still in the public domain.
21 *
22 * md5_buffer added by Steven Fuller
23 * Still in the public domain.
24 */
25
26#ifndef MD5_H
27#define MD5_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33typedef unsigned int UWORD32;
34
35#define md5byte unsigned char
36
37struct MD5Context {
38 UWORD32 buf[4];
39 UWORD32 bytes[2];
40 UWORD32 in[16];
41};
42
43void MD5Init(struct MD5Context *context);
44void MD5Update(struct MD5Context *context, md5byte const *buf, unsigned len);
45void MD5Final(unsigned char digest[16], struct MD5Context *context);
46void MD5Transform(UWORD32 buf[4], UWORD32 const in[16]);
47
48/* md5_buffer frontend added for AvP */
49void md5_buffer(char const *buffer, unsigned int len, char *digest);
50
51#ifdef __cplusplus
52};
53#endif
54
55#endif /* !MD5_H */
diff --git a/noncore/net/mailit/opie-mailit.control b/noncore/net/mailit/opie-mailit.control
new file mode 100644
index 0000000..db9c23d
--- a/dev/null
+++ b/noncore/net/mailit/opie-mailit.control
@@ -0,0 +1,9 @@
1Files: bin/mailit apps/Applications/mailit.desktop pics/EMail.png
2Priority: optional
3Section: opie
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $OPIE_VERSION-$SUB_VERSION
7Depends: opie-base
8Description: EMail
9 A simple POP3 email client for the Qt Palmtop environment.
diff --git a/noncore/net/mailit/popclient.cpp b/noncore/net/mailit/popclient.cpp
new file mode 100644
index 0000000..a406af2
--- a/dev/null
+++ b/noncore/net/mailit/popclient.cpp
@@ -0,0 +1,375 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "popclient.h"
21#include "emailhandler.h"
22//#define APOP_TEST
23
24extern "C" {
25#include "md5.h"
26}
27
28#include <qcstring.h>
29
30PopClient::PopClient()
31{
32 socket = new QSocket(this, "popClient");
33 connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int)));
34 connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished()));
35 connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData()));
36
37 stream = new QTextStream(socket);
38
39 receiving = FALSE;
40 synchronize = FALSE;
41 lastSync = 0;
42 headerLimit = 0;
43 preview = FALSE;
44}
45
46PopClient::~PopClient()
47{
48 delete socket;
49 delete stream;
50}
51
52void PopClient::newConnection(QString target, int port)
53{
54 if (receiving) {
55 qWarning("socket in use, connection refused");
56 return;
57 }
58
59 status = Init;
60
61 socket->connectToHost(target, port);
62 receiving = TRUE;
63 selected = FALSE;
64
65 emit updateStatus("DNS lookup");
66}
67
68void PopClient::setAccount(QString popUser, QString popPasswd)
69{
70 popUserName = popUser;
71 popPassword = popPasswd;
72}
73
74void PopClient::setSynchronize(int lastCount)
75{
76 synchronize = TRUE;
77 lastSync = lastCount;
78}
79
80void PopClient::removeSynchronize()
81{
82 synchronize = FALSE;
83 lastSync = 0;
84}
85
86void PopClient::headersOnly(bool headers, int limit)
87{
88 preview = headers;
89 headerLimit = limit;
90}
91
92void PopClient::setSelectedMails(MailList *list)
93{
94 selected = TRUE;
95 mailList = list;
96}
97
98void PopClient::connectionEstablished()
99{
100 emit updateStatus("Connection established");
101}
102
103void PopClient::errorHandling(int status)
104{
105 emit updateStatus("Error Occured");
106 emit errorOccurred(status);
107 socket->close();
108 receiving = FALSE;
109}
110
111void PopClient::incomingData()
112{
113 QString response, temp, temp2, timeStamp;
114 QString md5Source;
115 int start, end;
116// char *md5Digest;
117 char md5Digest[16];
118// if ( !socket->canReadLine() )
119// return;
120
121 response = socket->readLine();
122 qDebug(response +" %d", status);
123
124 switch(status) {
125 //logging in
126 case Init: {
127#ifdef APOP_TEST
128 start = response.find('<',0);
129 end = response.find('>', start);
130 if( start >= 0 && end > start )
131 {
132 timeStamp = response.mid( start , end - start + 1);
133 md5Source = timeStamp + popPassword;
134 qDebug( md5Source);
135// for( int i = 0; i < md5Source.length(); i++) {
136// buff[i] = (QChar)md5Source[i];
137// }
138
139 md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]);
140// md5_buffer(char const *buffer, unsigned int len, char *digest);
141
142// MD5_Init( &ctx);
143// MD5_Update( &ctx, buff, sizeof( buff) );
144// MD5_Final( md5Digest, &ctx);
145// MD5( buff, md5Source.length(), md5Digest);
146
147 for(int j =0;j < MD5_DIGEST_LENGTH ;j++)
148 {
149 printf("%x", md5Digest[j]);
150 }
151 printf("\n");
152// qDebug(md5Digest);
153 *stream << "APOP " << popUserName << " " << md5Digest << "\r\n";
154 // qDebug("%s", stream);
155 status = Stat;
156 }
157 else
158#endif
159 {
160 timeStamp = "";
161 *stream << "USER " << popUserName << "\r\n";
162 status = Pass;
163 }
164
165 break;
166 }
167 //password shhh. don't tell anyone (implement APOP...)
168 case Pass: {
169 *stream << "PASS " << popPassword << "\r\n";
170 status = Stat;
171 break;
172 }
173 //ask for number of messages
174 case Stat: {
175 if (response[0] == '+') {
176 *stream << "STAT" << "\r\n";
177 status = Mcnt;
178 } else errorHandling(ErrLoginFailed);
179 break;
180 }
181 //get count of messages, eg "+OK 4 900.." -> int 4
182 case Mcnt: {
183 if (response[0] == '+') {
184 temp = response.replace(0, 4, "");
185 int x = temp.find(" ", 0);
186 temp.truncate((uint) x);
187 newMessages = temp.toInt();
188 messageCount = 1;
189 status = List;
190
191 if (synchronize) {
192 //messages deleted from server, reload all
193 if (newMessages < lastSync)
194 lastSync = 0;
195 messageCount = lastSync + 1;
196 }
197
198 if (selected) {
199 int *ptr = mailList->first();
200 if (ptr != 0) {
201 newMessages++; //to ensure no early jumpout
202 messageCount = *(mailList->first());
203 } else newMessages = 0;
204 }
205 } else errorHandling(ErrUnknownResponse);
206 }
207 //Read message number x, count upwards to messageCount
208 case List: {
209 if (messageCount <= newMessages) {
210 *stream << "LIST " << messageCount << "\r\n";
211 status = Size;
212 temp2.setNum(newMessages - lastSync);
213 temp.setNum(messageCount - lastSync);
214 if (!selected) {
215 emit updateStatus("Retrieving " + temp + "/" + temp2);
216 } else {
217 //completing a previously closed transfer
218 if ( (messageCount - lastSync) <= 0) {
219 temp.setNum(messageCount);
220 emit updateStatus("Previous message " + temp);
221 } else {
222 emit updateStatus("Completing message " + temp);
223 }
224 }
225 break;
226 } else {
227 emit updateStatus("No new Messages");
228 status = Quit;
229 }
230 }
231 //get size of message, eg "500 characters in message.." -> int 500
232 case Size: {
233 if (status != Quit) { //because of idiotic switch
234 if (response[0] == '+') {
235 temp = response.replace(0, 4, "");
236 int x = temp.find(" ", 0);
237 temp = temp.right(temp.length() - ((uint) x + 1) );
238 mailSize = temp.toInt();
239 emit currentMailSize(mailSize);
240
241 status = Retr;
242 } else {
243 qWarning(response);
244 errorHandling(ErrUnknownResponse);
245 }
246 }
247 }
248 //Read message number x, count upwards to messageCount
249 case Retr: {
250 if (status != Quit) {
251 if (!preview || mailSize <= headerLimit) {
252 *stream << "RETR " << messageCount << "\r\n";
253 } else { //only header
254 *stream << "TOP " << messageCount << " 0\r\n";
255 }
256 messageCount++;
257 status = Ignore;
258 break;
259 } }
260 case Ignore: {
261 if (status != Quit) { //because of idiotic switch
262 if (response[0] == '+') {
263 message = "";
264 status = Read;
265 if (!socket->canReadLine()) //sync. problems
266 break;
267 response = socket->readLine();
268 } else errorHandling(ErrUnknownResponse);
269 }
270 }
271 //add all incoming lines to body. When size is reached, send
272 //message, and go back to read new message
273 case Read: {
274 if (status != Quit) { //because of idiotic switch
275 message += response;
276 while ( socket->canReadLine() ) {
277 response = socket->readLine();
278 message += response;
279 }
280 emit downloadedSize(message.length());
281 int x = message.find("\r\n.\r\n",-5);
282 if (x == -1) {
283 break;
284 } else { //message reach entire size
285 //complete mail downloaded
286 if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){
287 emit newMessage(message, messageCount-1, mailSize, TRUE);
288 } else { //incomplete mail downloaded
289 emit newMessage(message, messageCount-1, mailSize, FALSE);
290 }
291 if (messageCount > newMessages) //that was the last message
292 status = Quit;
293 else { //ask for new message
294 if (selected) { //grab next from queue
295 int *ptr = mailList->next();
296 if (ptr != 0) {
297 messageCount = *ptr;
298 *stream << "LIST " << messageCount << "\r\n";
299 status = Size;
300 //completing a previously closed transfer
301 if ( (messageCount - lastSync) <= 0) {
302 temp.setNum(messageCount);
303 emit updateStatus("Previous message " + temp);
304 } else {
305 temp.setNum(messageCount - lastSync);
306 emit updateStatus("Completing message " + temp);
307 }
308 break;
309 } else {
310 newMessages--;
311 status = Quit;
312 }
313 } else {
314 *stream << "LIST " << messageCount << "\r\n";
315 status = Size;
316 temp2.setNum(newMessages - lastSync);
317 temp.setNum(messageCount - lastSync);
318 emit updateStatus("Retrieving " + temp + "/" + temp2);
319
320 break;
321 }
322 }
323 }
324 if (status != Quit)
325 break;
326 }
327 }
328 case Quit: {
329 *stream << "Quit\r\n";
330 status = Done;
331 int newM = newMessages - lastSync;
332 if (newM > 0) {
333 temp.setNum(newM);
334 emit updateStatus(temp + " new messages");
335 } else {
336 emit updateStatus("No new messages");
337 }
338
339 socket->close();
340 receiving = FALSE;
341 emit mailTransfered(newM);
342 break;
343 }
344 }
345
346}
347
348// if( bAPOPAuthentication )
349// {
350// if( m_strTimeStamp.IsEmpty() )
351// {
352// SetLastError("Apop error!");
353// return false;
354// }
355// strMD5Source = m_strTimeStamp+pszPassword;
356// strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() );
357// sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst);
358// ret = send(m_sPop3Socket , msg , strlen(msg) , NULL);
359// if(ret == SOCKET_ERROR)
360// {
361// SetLastError("Socket error!");
362// m_bSocketOK = false;
363// m_bConnected = false;
364// return false;
365// }
366// if( !GetSocketResult(&strResult , COMMAND_END_FLAG) )
367// return false;
368// if( 0 == strResult.Find('-' , 0) )
369// {
370// SetLastError("Username or Password error!");
371// return false;
372// }
373// m_bConnected = true;
374
375// }
diff --git a/noncore/net/mailit/popclient.h b/noncore/net/mailit/popclient.h
new file mode 100644
index 0000000..10b71ab
--- a/dev/null
+++ b/noncore/net/mailit/popclient.h
@@ -0,0 +1,76 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef PopClient_H
21#define PopClient_H
22
23#include <stdio.h>
24#include <qsocket.h>
25#include <qstring.h>
26#include <qobject.h>
27#include <qtextstream.h>
28#include <qlist.h>
29#include "maillist.h"
30
31class PopClient: public QObject
32{
33 Q_OBJECT
34
35public:
36 PopClient();
37 ~PopClient();
38 void newConnection(QString target, int port);
39 void setAccount(QString popUser, QString popPasswd);
40 void setSynchronize(int lastCount);
41 void removeSynchronize();
42 void headersOnly(bool headers, int limit);
43 void setSelectedMails(MailList *list);
44
45signals:
46 void newMessage(const QString &, int, uint, bool);
47 void errorOccurred(int status);
48 void updateStatus(const QString &);
49 void mailTransfered(int);
50 void mailboxSize(int);
51 void currentMailSize(int);
52 void downloadedSize(int);
53
54public slots:
55 void errorHandling(int);
56
57protected slots:
58 void connectionEstablished();
59 void incomingData();
60
61private:
62 QSocket *socket;
63 QTextStream *stream;
64 enum transferStatus
65 {
66 Init, Pass, Stat, Mcnt, Read, List, Size, Retr, Acks,
67 Quit, Done, Ignore
68 };
69 int status, lastSync;
70 int messageCount, newMessages, mailSize, headerLimit;
71 bool receiving, synchronize, preview, selected;
72 QString popUserName, popPassword, message;
73 MailList *mailList;
74};
75
76#endif
diff --git a/noncore/net/mailit/readmail.cpp b/noncore/net/mailit/readmail.cpp
new file mode 100644
index 0000000..4954f34
--- a/dev/null
+++ b/noncore/net/mailit/readmail.cpp
@@ -0,0 +1,326 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "readmail.h"
21#include <qimage.h>
22#include <qmime.h>
23#include <qaction.h>
24#include "resource.h"
25
26ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl )
27 : QMainWindow(parent, name, fl)
28{
29 plainTxt = FALSE;
30
31 init();
32 viewAtt = new ViewAtt(0, "View Attatchments");
33}
34
35ReadMail::~ReadMail()
36{
37 delete emailView->mimeSourceFactory();
38 delete viewAtt;
39}
40
41void ReadMail::init()
42{
43 setToolBarsMovable(FALSE);
44
45 bar = new QToolBar(this);
46 bar->setHorizontalStretchable( TRUE );
47
48 menu = new QMenuBar( bar );
49
50 viewMenu = new QPopupMenu(menu);
51 menu->insertItem( tr( "&View" ), viewMenu);
52
53 mailMenu = new QPopupMenu(menu);
54 menu->insertItem( tr( "&Mail" ), mailMenu);
55
56 bar = new QToolBar(this);
57
58 //reply dependant on viewing inbox
59 replyButton = new QAction( tr( "Reply" ), Resource::loadPixmap( "pass" ),
60 QString::null, 0, this, 0 );
61 connect(replyButton, SIGNAL(activated()), this, SLOT(reply()) );
62
63 previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 );
64 connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) );
65 previousButton->addTo(bar);
66 previousButton->addTo(viewMenu);
67
68 nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 );
69 connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) );
70 nextButton->addTo(bar);
71 nextButton->addTo(viewMenu);
72
73 attatchmentsButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
74 connect( attatchmentsButton, SIGNAL( activated() ), this,
75 SLOT( viewAttatchments() ) );
76 attatchmentsButton->addTo(bar);
77 attatchmentsButton->addTo(viewMenu);
78
79 plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0, TRUE);
80 connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) );
81 plainTextButton->addTo(bar);
82 plainTextButton->addTo(viewMenu);
83
84 deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 );
85 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) );
86 deleteButton->addTo(bar);
87 deleteButton->addTo(mailMenu);
88
89 viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close()));
90
91 emailView = new QTextView( this, "emailView" );
92 setCentralWidget(emailView);
93
94 mime = new QMimeSourceFactory();
95 emailView->setMimeSourceFactory(mime);
96}
97
98void ReadMail::updateView()
99{
100 Enclosure *ePtr;
101 QString mailStringSize;
102 QString text, temp;
103
104 mail->read = TRUE; //mark as read
105 inbox = mail->received;
106
107 replyButton->removeFrom(mailMenu);
108 replyButton->removeFrom(bar);
109
110 if (inbox == TRUE) {
111 replyButton->addTo(bar);
112 replyButton->addTo(mailMenu);
113
114 if (!mail->downloaded) {
115 //report currently viewed mail so that it will be
116 //placed first in the queue of new mails to download
117 emit viewingMail(mail);
118
119 double mailSize = (double) mail->size;
120 if (mailSize < 1024) {
121 mailStringSize.setNum(mailSize);
122 mailStringSize += " Bytes";
123 } else if (mailSize < 1024*1024) {
124 mailStringSize.setNum( (mailSize / 1024), 'g', 2 );
125 mailStringSize += " Kb";
126 } else {
127 mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3);
128 mailStringSize += " Mb";
129 }
130 }
131 }
132
133 QMimeSourceFactory *mime = emailView->mimeSourceFactory();
134
135 if (! plainTxt) { //use RichText, inline pics etc.
136 emailView->setTextFormat(QTextView::RichText);
137 text = "<b><big><center><font color=\"blue\">" + mail->subject
138 +"</font></center></big></b><br>";
139 text += "<b>From: </b>" + mail->from + " <i>" +
140 mail->fromMail + "</i><br>";
141
142 text +="<b>To: </b>";
143 for (QStringList::Iterator it = mail->recipients.begin();
144 it != mail->recipients.end(); ++it ) {
145 text += *it + " ";
146 }
147 text += "<br>" + mail->date;
148
149 if (mail->files.count() > 0) {
150 text += "<br><b>Attatchments: </b>";
151
152 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
153 text += ePtr->originalName + " ";
154 }
155 text += "<hr><br>" + mail->body;
156
157 if (inbox) {
158 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
159
160 text += "<br><hr><b>Attatchment: </b>" +
161 ePtr->originalName + "<hr>";
162
163 if (ePtr->contentType == "TEXT") {
164 QFile f(ePtr->path + ePtr->name);
165
166 if (f.open(IO_ReadOnly) ) {
167 QTextStream t(&f);
168 temp = t.read();
169 text += temp + "<br>";
170 f.close();
171 } else {
172 text += "<b>Could not locate file</b><br>";
173 }
174
175 }
176 if (ePtr->contentType == "IMAGE") {
177 // temp.setNum(emailView->width());//get display width
178 // text += "<img width=" + temp +" src =""" +
179 // ePtr->originalName + """> </img>";
180 text += "<img src =""" +
181 ePtr->originalName + """> </img>";
182 mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) ));
183 }
184 }
185 }
186 } else {
187 if (mail->downloaded || !inbox) {
188 text += "<hr><br>" + mail->body;
189 } else {
190 text += "<hr><br><b> Awaiting download </b><br>";
191 text += "Size of mail: " + mailStringSize;
192 }
193 }
194 emailView->setText(text);
195 } else { // show plain txt mail
196 emailView->setTextFormat(QTextView::PlainText);
197 text = "Subject: " + mail->subject + "\n";
198 text += "From: " + mail->from + " " + mail->fromMail + "\n";
199 text += "To: ";
200 for (QStringList::Iterator it = mail->recipients.begin();
201 it != mail->recipients.end(); ++it ) {
202 text += *it + " ";
203 }
204 text += "\nDate: " + mail->date + "\n";
205 if (mail->files.count() > 0) {
206 text += "Attatchments: ";
207 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
208 text += ePtr->originalName + " ";
209 }
210 text += "\n\n";
211 } else text += "\n";
212
213 if (!inbox) {
214 text += mail->body;
215 } else if (mail->downloaded) {
216 text += mail->bodyPlain;
217 } else {
218 text += "\nAwaiting download\n";
219 text += "Size of mail: " + mailStringSize;
220 }
221
222 emailView->setText(text);
223 }
224
225 if (mail->files.count() == 0)
226 attatchmentsButton->setEnabled(FALSE);
227 else attatchmentsButton->setEnabled(TRUE);
228
229 setCaption("Examining mail: " + mail->subject);
230}
231
232//update view with current EmailListItem (item)
233void ReadMail::update(QListView *thisView, Email *mailIn)
234{
235 view = thisView;
236 item = (EmailListItem *) view->selectedItem();
237 mail = mailIn;
238 updateView();
239 updateButtons();
240}
241
242void ReadMail::mailUpdated(Email *mailIn)
243{
244 if (mailIn == mail) {
245 updateView();
246 } else {
247 updateButtons();
248 }
249}
250
251void ReadMail::close()
252{
253 emit cancelView();
254}
255
256//gets next item in listview, exits if there is no next
257void ReadMail::next()
258{
259 item = (EmailListItem *) item->nextSibling();
260 if (item != NULL) {
261 mail = item->getMail();
262 updateView();
263 }
264 updateButtons();
265}
266
267//gets previous item in listview, exits if there is no previous
268void ReadMail::previous()
269{
270 item = (EmailListItem *) item->itemAbove();
271 if (item != NULL) {
272 mail = item->getMail();
273 updateView();
274 }
275 updateButtons();
276}
277
278//deletes item, tries bringing up next or previous, exits if unsucessful
279void ReadMail::deleteItem()
280{
281 EmailListItem *temp = item;
282 temp = (EmailListItem *) item->nextSibling();//trybelow
283 if (temp == NULL)
284 temp = (EmailListItem *) item->itemAbove(); //try above
285
286 emit removeItem(item, inbox);
287
288 item = temp;
289 if (item != NULL) { //more items in list
290 mail = item->getMail();
291 updateView();
292 updateButtons();
293 } else close(); //no more items to see
294}
295
296void ReadMail::updateButtons()
297{
298 EmailListItem *temp;
299
300 temp = item;
301 if ((EmailListItem *) temp->nextSibling() == NULL)
302 nextButton->setEnabled(FALSE);
303 else nextButton->setEnabled(TRUE);
304
305 temp = item;
306 if ((EmailListItem *) temp->itemAbove() == NULL)
307 previousButton->setEnabled(FALSE);
308 else previousButton->setEnabled(TRUE);
309}
310
311void ReadMail::shiftText()
312{
313 plainTxt = ! plainTxt;
314 updateView();
315}
316
317void ReadMail::viewAttatchments()
318{
319 viewAtt->update(mail, inbox);
320 viewAtt->showMaximized();
321}
322
323void ReadMail::reply()
324{
325 emit replyRequested(*mail);
326}
diff --git a/noncore/net/mailit/readmail.h b/noncore/net/mailit/readmail.h
new file mode 100644
index 0000000..d0bb067
--- a/dev/null
+++ b/noncore/net/mailit/readmail.h
@@ -0,0 +1,86 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef READMAIL_H
21#define READMAIL_H
22
23#include <qaction.h>
24#include <qmainwindow.h>
25#include <qmenubar.h>
26#include <qpopupmenu.h>
27#include <qlabel.h>
28#include <qlistview.h>
29#include <qlayout.h>
30#include <qtextview.h>
31
32#include "emailhandler.h"
33#include "emaillistitem.h"
34#include "viewatt.h"
35
36class ReadMail : public QMainWindow
37{
38 Q_OBJECT
39
40public:
41 ReadMail( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
42 ~ReadMail();
43 void update(QListView *thisView, Email *mailIn);
44 void updateView();
45 void mailUpdated(Email *mailIn);
46
47signals:
48 void cancelView();
49 void replyRequested(Email &);
50 void removeItem(EmailListItem *, bool &);
51 void viewingMail(Email *);
52
53public slots:
54 void close();
55 void next();
56 void previous();
57 void deleteItem();
58 void shiftText();
59 void viewAttatchments();
60 void reply();
61
62private:
63 void init();
64 void updateButtons();
65
66private:
67 QListView *view;
68 EmailListItem *item;
69 bool plainTxt, inbox;
70 Email *mail;
71 ViewAtt *viewAtt;
72
73 QToolBar *bar;
74 QMenuBar *menu;
75 QPopupMenu *viewMenu, *mailMenu;
76 QAction *deleteButton;
77 QMimeSourceFactory *mime;
78 QAction *plainTextButton;
79 QAction *nextButton;
80 QTextView *emailView;
81 QAction *attatchmentsButton;
82 QAction *previousButton;
83 QAction *replyButton;
84};
85
86#endif // READMAIL_H
diff --git a/noncore/net/mailit/resource.cpp b/noncore/net/mailit/resource.cpp
new file mode 100644
index 0000000..dc19880
--- a/dev/null
+++ b/noncore/net/mailit/resource.cpp
@@ -0,0 +1,136 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "qpeapplication.h"
22#include "resource.h"
23#include <qdir.h>
24#include <qfile.h>
25#include <qregexp.h>
26#include <qpixmapcache.h>
27#include <qpainter.h>
28
29#include "inlinepics_p.h"
30
31/*!
32 \class Resource resource.h
33 \brief The Resource class provides access to named resources.
34
35 The resources may be provided from files or other sources.
36*/
37
38/*!
39 \fn Resource::Resource()
40 \internal
41*/
42
43/*!
44 Returns the QPixmap named \a pix. You should avoid including
45 any filename type extension (eg. .png, .xpm).
46*/
47QPixmap Resource::loadPixmap( const QString &pix )
48{
49 QPixmap pm;
50 QString key="QPE_"+pix;
51 if ( !QPixmapCache::find(key,pm) ) {
52 pm.convertFromImage(loadImage(pix));
53 QPixmapCache::insert(key,pm);
54 }
55 return pm;
56}
57
58/*!
59 Returns the QBitmap named \a pix. You should avoid including
60 any filename type extension (eg. .png, .xpm).
61*/
62QBitmap Resource::loadBitmap( const QString &pix )
63{
64 QBitmap bm;
65 bm = loadPixmap(pix);
66 return bm;
67}
68
69/*!
70 Returns the filename of a pixmap named \a pix. You should avoid including
71 any filename type extension (eg. .png, .xpm).
72
73 Normally you will use loadPixmap() rather than this function.
74*/
75QString Resource::findPixmap( const QString &pix )
76{
77 QString picsPath = QPEApplication::qpeDir() + "pics/";
78
79 if ( QFile( picsPath + pix + ".png").exists() )
80 return picsPath + pix + ".png";
81 else if ( QFile( picsPath + pix + ".xpm").exists() )
82 return picsPath + pix + ".xpm";
83 else if ( QFile( picsPath + pix ).exists() )
84 return picsPath + pix;
85
86 //qDebug("Cannot find pixmap: %s", pix.latin1());
87 return QString();
88}
89
90/*!
91 Returns a sound file for a sound named \a name.
92 You should avoid including any filename type extension (eg. .wav, .au, .mp3).
93*/
94QString Resource::findSound( const QString &name )
95{
96 QString picsPath = QPEApplication::qpeDir() + "sounds/";
97
98 QString result;
99 if ( QFile( (result = picsPath + name + ".wav") ).exists() )
100 return result;
101
102 return QString();
103}
104
105/*!
106 Returns a list of all sound names.
107*/
108QStringList Resource::allSounds()
109{
110 QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" );
111 QStringList entries = resourcedir.entryList();
112 QStringList result;
113 for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i)
114 result.append((*i).replace(QRegExp("\\.wav"),""));
115 return result;
116}
117
118/*!
119 Returns the QImage named \a name. You should avoid including
120 any filename type extension (eg. .png, .xpm).
121*/
122QImage Resource::loadImage( const QString &name)
123{
124 QImage img = qembed_findImage(name.latin1());
125 if ( img.isNull() )
126 return QImage(findPixmap(name));
127 return img;
128}
129
130/*!
131 \fn QIconSet Resource::loadIconSet( const QString &name )
132
133 Returns a QIconSet for the pixmap named \a name. A disabled icon is
134 generated that conforms to the Qtopia look & feel. You should avoid
135 including any filename type extension (eg. .png, .xpm).
136*/
diff --git a/noncore/net/mailit/resource.h b/noncore/net/mailit/resource.h
new file mode 100644
index 0000000..982c58a
--- a/dev/null
+++ b/noncore/net/mailit/resource.h
@@ -0,0 +1,80 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef PIXMAPLOADER_H
21#define PIXMAPLOADER_H
22
23#include <qimage.h>
24#include <qbitmap.h>
25#include <qiconset.h>
26#include <qstringlist.h>
27
28class Resource
29{
30public:
31 Resource() {}
32
33 static QImage loadImage( const QString &name);
34
35 static QPixmap loadPixmap( const QString &name );
36 static QBitmap loadBitmap( const QString &name );
37 static QString findPixmap( const QString &name );
38
39 static QIconSet loadIconSet( const QString &name );
40
41 static QString findSound( const QString &name );
42 static QStringList allSounds();
43};
44
45// Inline for compatibility with SHARP ROMs
46inline QIconSet Resource::loadIconSet( const QString &pix )
47{
48 QImage img = loadImage( pix );
49 QPixmap pm;
50 pm.convertFromImage( img );
51 QIconSet is( pm );
52 QIconSet::Size size = pm.width() <= 22 ? QIconSet::Small : QIconSet::Large;
53
54 QPixmap dpm = loadPixmap( pix + "_disabled" );
55
56 #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps
57 if ( dpm.isNull() ) {
58 QImage dimg( img.width(), img.height(), 32 );
59 for ( int y = 0; y < img.height(); y++ ) {
60 for ( int x = 0; x < img.width(); x++ ) {
61 QRgb p = img.pixel( x, y );
62 uint a = (p & 0xff000000) / 3;
63 p = (p & 0x00ffffff) | (a & 0xff000000);
64 dimg.setPixel( x, y, p );
65 }
66 }
67
68 dimg.setAlphaBuffer( TRUE );
69 dpm.convertFromImage( dimg );
70 }
71#endif
72
73 if ( !dpm.isNull() )
74 is.setPixmap( dpm, size, QIconSet::Disabled );
75
76 return is;
77}
78
79
80#endif
diff --git a/noncore/net/mailit/sendmail.xpm b/noncore/net/mailit/sendmail.xpm
new file mode 100644
index 0000000..2803793
--- a/dev/null
+++ b/noncore/net/mailit/sendmail.xpm
@@ -0,0 +1,20 @@
1/* XPM */
2static char*sendmail[]={
3"16 13 4 1",
4"a c #c3c3c3",
5"# c #000000",
6". c None",
7"b c #ffffff",
8".....#####aaa...",
9"....####aaaaa.a.",
10"....#.###...aaa.",
11"....#..###..aaa.",
12".......###......",
13"..............aa",
14".bbbbbbbbbbbbbba",
15".bbb#bb#bbb###ba",
16".bb#b##bbbb#b#ba",
17".bbbbbbbbbb###ba",
18".bb#b###bbbbbbba",
19".bbb#bbbbbbbbbba",
20".bbbbbbbbbbbbbba"};
diff --git a/noncore/net/mailit/smtpclient.cpp b/noncore/net/mailit/smtpclient.cpp
new file mode 100644
index 0000000..7bb7933
--- a/dev/null
+++ b/noncore/net/mailit/smtpclient.cpp
@@ -0,0 +1,163 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "smtpclient.h"
21#include "emailhandler.h"
22
23SmtpClient::SmtpClient()
24{
25 socket = new QSocket(this, "smtpClient");
26 stream = new QTextStream(socket);
27 mailList.setAutoDelete(TRUE);
28
29 connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int)));
30 connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished()));
31 connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData()));
32
33 sending = FALSE;
34}
35
36SmtpClient::~SmtpClient()
37{
38 delete socket;
39 delete stream;
40}
41
42void SmtpClient::newConnection(QString target, int port)
43{
44 if (sending) {
45 qWarning("socket in use, connection refused");
46 return;
47 }
48
49 status = Init;
50 sending = TRUE;
51 socket->connectToHost(target, port);
52
53 emit updateStatus("DNS lookup");
54}
55
56void SmtpClient::addMail(QString from, QString subject, QStringList to, QString body)
57{
58 RawEmail *mail = new RawEmail;
59
60 mail->from = from;
61 mail->subject = subject;
62 mail->to = to;
63 mail->body = body;
64
65 mailList.append(mail);
66}
67
68void SmtpClient::connectionEstablished()
69{
70 emit updateStatus("Connection established");
71
72}
73
74void SmtpClient::errorHandling(int status)
75{
76 emit errorOccurred(status);
77 socket->close();
78 mailList.clear();
79 sending = FALSE;
80}
81
82void SmtpClient::incomingData()
83{
84 QString response;
85
86 if (!socket->canReadLine())
87 return;
88
89 response = socket->readLine();
90
91 switch(status) {
92 case Init: {
93 if (response[0] == '2') {
94 status = From;
95 mailPtr = mailList.first();
96 *stream << "HELO there\r\n";
97 } else errorHandling(ErrUnknownResponse);
98 break;
99 }
100 case From: {
101 if (response[0] == '2') {
102 *stream << "MAIL FROM: <" << mailPtr->from << ">\r\n";
103 status = Recv;
104 } else errorHandling(ErrUnknownResponse);
105 break;
106 }
107 case Recv: {
108 if (response[0] == '2') {
109 it = mailPtr->to.begin();
110 if (it == NULL)
111 errorHandling(ErrUnknownResponse);
112 *stream << "RCPT TO: <" << *it << ">\r\n";
113 status = MRcv;
114 } else errorHandling(ErrUnknownResponse);
115 break;
116 }
117 case MRcv: {
118 if (response[0] == '2') {
119 it++;
120 if ( it != mailPtr->to.end() ) {
121 *stream << "RCPT TO: <" << *it << ">\r\n";
122 break;
123 } else {
124 status = Data;
125 }
126 } else errorHandling(ErrUnknownResponse);
127 }
128 case Data: {
129 if (response[0] == '2') {
130 *stream << "DATA\r\n";
131 status = Body;
132 emit updateStatus("Sending: " + mailPtr->subject);
133 } else errorHandling(ErrUnknownResponse);
134 break;
135 }
136 case Body: {
137 if (response[0] == '3') {
138 *stream << mailPtr->body << "\r\n.\r\n";
139 mailPtr = mailList.next();
140 if (mailPtr != NULL) {
141 status = From;
142 } else {
143 status = Quit;
144 }
145 } else errorHandling(ErrUnknownResponse);
146 break;
147 }
148 case Quit: {
149 if (response[0] == '2') {
150 *stream << "QUIT\r\n";
151 status = Done;
152 QString temp;
153 temp.setNum(mailList.count());
154 emit updateStatus("Sent " + temp + " messages");
155 emit mailSent();
156 mailList.clear();
157 sending = FALSE;
158 socket->close();
159 } else errorHandling(ErrUnknownResponse);
160 break;
161 }
162 }
163}
diff --git a/noncore/net/mailit/smtpclient.h b/noncore/net/mailit/smtpclient.h
new file mode 100644
index 0000000..ca65af4
--- a/dev/null
+++ b/noncore/net/mailit/smtpclient.h
@@ -0,0 +1,75 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef SmtpClient_H
21#define SmtpClient_H
22
23//#include <stdio.h>
24#include <qsocket.h>
25#include <qstring.h>
26#include <qobject.h>
27#include <qtextstream.h>
28#include <qstringlist.h>
29#include <qlist.h>
30
31struct RawEmail
32{
33 QString from;
34 QString subject;
35 QStringList to;
36 QString body;
37};
38
39class SmtpClient: public QObject
40{
41 Q_OBJECT
42
43public:
44 SmtpClient();
45 ~SmtpClient();
46 void newConnection(QString target, int port);
47 void addMail(QString from, QString subject, QStringList to, QString body);
48
49signals:
50 void errorOccurred(int);
51 void updateStatus(const QString &);
52 void mailSent();
53
54public slots:
55 void errorHandling(int);
56
57protected slots:
58 void connectionEstablished();
59 void incomingData();
60
61private:
62 QSocket *socket;
63 QTextStream *stream;
64 enum transferStatus
65 {
66 Init, From, Recv, MRcv, Data, Body, Quit, Done
67 };
68 int status;
69 QList<RawEmail> mailList;
70 RawEmail *mailPtr;
71 bool sending;
72 QStringList::Iterator it;
73};
74
75#endif
diff --git a/noncore/net/mailit/textparser.cpp b/noncore/net/mailit/textparser.cpp
new file mode 100644
index 0000000..f082417
--- a/dev/null
+++ b/noncore/net/mailit/textparser.cpp
@@ -0,0 +1,294 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "textparser.h"
21
22TextParser::TextParser(QString in, QString lineBreak)
23{
24 data = in;
25 lineSep = lineBreak;
26
27 init();
28 createSeparators();
29 split();
30}
31
32TextParser::TextParser(QString in, QString lineBreak, QString sep)
33{
34 data = in;
35 lineSep = lineBreak;
36
37 init();
38 separators = sep;
39 split();
40}
41
42void TextParser::init()
43{
44 lineCount = 0;
45 linePos = 0;
46 totalElmCount = 0;
47 separatorPos = -1; //not initialized
48 wordPos = -1; //not initialized
49 sepAtLine = 0;
50 sepAtPosElm = -1; //such that nextSep equals 0
51 wordAtLine = 0;
52 wordAtPosElm = -1; //such that nextWord equals 0
53 atLine = 0;
54 atPosElm = 0;
55}
56
57void TextParser::createSeparators()
58{
59 separators = " @#,.:;<>*/(){}|'?-+=_";
60}
61
62 /*Returns pos of given search criteria, -1 if not found */
63int TextParser::find(QString target, QChar sep, int pos, bool upperCase)
64{
65 int atLine = 0, atPosElm = 0;
66
67 for (int x = 0; x < totalElmCount; x++) {
68 if (x >= pos) {
69 if (upperCase) {
70 if ((splitDone[atLine].elm[atPosElm].str.upper() == target) &&
71 (splitDone[atLine].elm[atPosElm].separator == sep))
72 return x;
73 } else {
74 if ((splitDone[atLine].elm[atPosElm].str == target) &&
75 (splitDone[atLine].elm[atPosElm].separator == sep))
76 return x;
77 }
78 }
79 atPosElm++;
80 if (atPosElm >= splitDone[atLine].elmCount) { //new Line
81 atLine++;
82 atPosElm = 0;
83 }
84 }
85
86 return -1;
87}
88
89int TextParser::elmCount()
90{
91 return totalElmCount;
92}
93
94QChar TextParser::separatorAt(int pos)
95{
96 if (getLineReference(pos, &sepAtLine, &sepAtPosElm) == -1)
97 return QChar::null;
98
99 separatorPos = pos;
100 return splitDone[sepAtLine].elm[sepAtPosElm].separator;
101}
102
103QChar TextParser::nextSeparator()
104{
105 sepAtPosElm++;
106 if (splitDone[sepAtLine].elmCount <= sepAtPosElm) {
107 sepAtLine++;
108 sepAtPosElm = 0;
109 }
110
111 separatorPos++;
112 return splitDone[sepAtLine].elm[sepAtPosElm].separator;
113}
114
115bool TextParser::hasNextSeparator()
116{
117 return ((separatorPos+1) < totalElmCount);
118}
119
120QString TextParser::wordAt(int pos)
121{
122 if (getLineReference(pos, &wordAtLine, &wordAtPosElm) == -1)
123 return NULL;
124
125 wordPos = pos;
126 return splitDone[wordAtLine].elm[wordAtPosElm].str;
127}
128
129QString TextParser::nextWord()
130{
131 wordAtPosElm++;
132 if (splitDone[wordAtLine].elmCount <= wordAtPosElm) {
133 wordAtLine++;
134 wordAtPosElm = 0;
135 }
136
137 wordPos++;
138 return splitDone[wordAtLine].elm[wordAtPosElm].str;
139}
140
141bool TextParser::hasNextWord()
142{
143 return ((wordPos + 1) < totalElmCount);
144}
145
146QString TextParser::getString(int *pos, QChar stop, bool lineEnd = false)
147{
148 QString returnStr = wordAt(*pos);
149 QChar chr = separatorAt(*pos);
150 QString s;
151
152 if (returnStr == "")
153 return "";
154 if (chr == stop)
155 return returnStr;
156
157 if (!lineEnd) {
158 while ((chr != stop) && hasNextWord()) {
159 returnStr.append(chr);
160 returnStr += nextWord();
161 chr = nextSeparator();
162 }
163 } else { //copy from pos to end of line
164 getLineReference(*pos, &atLine, &atPosElm);
165 returnStr = "";
166 while (atPosElm < splitDone[atLine].elmCount) {
167 if (splitDone[atLine].elm[atPosElm].str != "") {
168 returnStr += splitDone[atLine].elm[atPosElm].str;
169 }
170 chr = splitDone[atLine].elm[atPosElm].separator;
171 if (!chr.isNull() && (int) chr != 0) {
172 returnStr.append(splitDone[atLine].elm[atPosElm].separator);
173 }
174 atPosElm++;
175 }
176 }
177
178 *pos = wordPos;
179 return returnStr;
180}
181
182QString TextParser::getNextLine()
183{
184 atLine++;
185 atPosElm = 0;
186 if (atLine < lineCount)
187 return splitDone[atLine].str;
188 return "";
189}
190
191bool TextParser::hasNextLine()
192{
193 if (atLine+1 < lineCount)
194 return TRUE;;
195 return FALSE;
196}
197
198int TextParser::endLinePos(int pos)
199{
200 if ( (getLineReference(pos, &atLine, &atPosElm)) == -1)
201 return -1;
202
203 return (pos + (splitDone[atLine].elmCount - atPosElm) + 1);
204}
205
206int TextParser::getLineReference(int pos, int *line, int *inLinePos)
207{
208 int currentPos = 0;
209
210 for (int x = 0; x < lineCount; x++) {
211 if ( currentPos + splitDone[x].elmCount > pos) {
212 *line = x;
213 *inLinePos = pos - currentPos;
214 return 0; //pos found okay
215 }
216 currentPos += splitDone[x].elmCount;
217 }
218 return -1; //no reference found
219}
220
221void TextParser::split()
222{
223 t_splitLine newLine;
224
225 while ((uint) linePos < data.length()) {
226 newLine = nextLine();
227 splitDone[lineCount] = splitLine(newLine);
228 totalElmCount += splitDone[lineCount].elmCount;
229 lineCount++;
230 }
231}
232
233t_splitLine TextParser::splitLine(t_splitLine line)
234{
235 uint pos = 0;
236 uint elmCount = 0;
237 t_splitLine tempLine = line;
238
239 tempLine.str = line.str.simplifyWhiteSpace();
240 tempLine.elm[0].str = "";
241 while ( pos < line.str.length() ) {
242 if ( isSeparator(tempLine.str[pos]) ) {
243 tempLine.elm[elmCount].separator = tempLine.str[pos];
244 elmCount++;
245 pos++;
246 while (tempLine.str[pos] == ' ')
247 pos++;
248 if (pos > line.str.length())
249 elmCount--;
250 tempLine.elm[elmCount].str = "";
251 } else {
252 if (!tempLine.str[pos].isNull())
253 tempLine.elm[elmCount].str += tempLine.str[pos];
254 pos++;
255 }
256 }
257
258 tempLine.elmCount = elmCount + 1;
259 return tempLine;
260}
261
262bool TextParser::isSeparator(QChar chr)
263{
264 for (uint x = 0; x < separators.length(); x++) {
265 if (chr == separators[x])
266 return true;
267 }
268 return false;
269}
270
271t_splitLine TextParser::nextLine()
272{
273 int newLinePos;
274 t_splitLine lineType;
275
276 newLinePos = data.find(lineSep, linePos);
277
278 lineType.lineType = NewLine;
279 lineType.str = "";
280
281 if (newLinePos == -1) {
282 newLinePos = data.length();
283 lineType.lineType = LastLine;
284 }
285
286 for (int x = linePos; x < newLinePos; x++)
287 lineType.str += data[x];
288
289 linePos = newLinePos;
290 if ((uint) linePos < data.length()) //if not EOF, add length of lineSep
291 linePos += lineSep.length();
292
293 return lineType;
294}
diff --git a/noncore/net/mailit/textparser.h b/noncore/net/mailit/textparser.h
new file mode 100644
index 0000000..016effb
--- a/dev/null
+++ b/noncore/net/mailit/textparser.h
@@ -0,0 +1,85 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qobject.h>
21#include <qstring.h>
22
23#ifndef TEXTPARSER_H
24#define TEXTPARSER_H
25
26enum t_strType { Word, Number};
27enum t_lineType {NewLine, LastLine};
28
29 const uint MAX_ELEMENTS = 200; //Should be dynamic
30 const uint MAX_LINES = 500; //Should be dynamic
31
32struct t_splitElm
33{
34 QChar separator;
35 int strType;
36 QString str;
37};
38
39struct t_splitLine
40{
41 t_lineType lineType;
42 QString str; //a bit redundant...
43 t_splitElm elm[MAX_ELEMENTS];
44 int elmCount;
45};
46
47class TextParser: public QObject
48{
49 Q_OBJECT
50
51public:
52 TextParser(QString in, QString lineBreak);
53 TextParser(QString in, QString lineBreak, QString sep);
54 int find(QString target, QChar sep, int pos, bool upperCase);
55 int elmCount();
56 QChar separatorAt(int pos);
57 QChar nextSeparator();
58 bool hasNextSeparator();
59 QString wordAt(int pos);
60 QString nextWord();
61 bool hasNextWord();
62 QString getString(int *pos, QChar stop, bool lineEnd = false);
63 QString getNextLine();
64 bool hasNextLine();
65 int endLinePos(int pos);
66
67private:
68 void init();
69 void createSeparators();
70 t_splitLine nextLine();
71 void split();
72 t_splitLine splitLine(t_splitLine line);
73 bool isSeparator(QChar chr);
74 t_splitLine splitDone[MAX_LINES];
75 int getLineReference(int pos, int *line, int *inLinePos);
76
77 int lineCount, linePos, totalElmCount;
78 int separatorPos, wordPos;
79 QString data, separators, lineSep;
80 int sepAtLine, sepAtPosElm;
81 int wordAtLine, wordAtPosElm;
82 int atLine, atPosElm;
83};
84
85#endif
diff --git a/noncore/net/mailit/viewatt.cpp b/noncore/net/mailit/viewatt.cpp
new file mode 100644
index 0000000..86f119f
--- a/dev/null
+++ b/noncore/net/mailit/viewatt.cpp
@@ -0,0 +1,109 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "resource.h"
21#include "viewatt.h"
22#include <qpe/applnk.h>
23
24ViewAtt::ViewAtt(QWidget *parent, const char *name, WFlags f)
25 : QMainWindow(parent, name, f)
26{
27 setCaption("Exploring attatchments");
28
29 setToolBarsMovable( FALSE );
30 bar = new QToolBar(this);
31 installButton = new QAction( tr( "Install" ), Resource::loadPixmap( "exec" ), QString::null, CTRL + Key_C, this, 0 );
32 connect(installButton, SIGNAL(activated()), this, SLOT(install()) );
33
34 listView = new QListView(this, "AttView");
35 listView->addColumn( "Attatchment" );
36 listView->addColumn( "Type" );
37 listView->addColumn( "Installed" );
38 setCentralWidget(listView);
39}
40
41void ViewAtt::update(Email *mailIn, bool inbox)
42{
43 QListViewItem *item;
44 Enclosure *ePtr;
45
46 listView->clear();
47 if (inbox) {
48 bar->clear();
49 installButton->addTo( bar );
50 bar->show();
51 } else {
52 bar->hide();
53 }
54
55 mail = mailIn;
56 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
57
58 QString isInstalled = "No";
59 if (ePtr->installed)
60 isInstalled = "Yes";
61 item = new QListViewItem(listView, ePtr->originalName, ePtr->contentType, isInstalled);
62
63 if (ePtr->contentType == "TEXT") {
64 actions = new QAction( tr("View"), Resource::loadPixmap("TextEditor"), QString::null, CTRL + Key_C, this, 0);
65 actions->addTo(bar);
66 item->setPixmap(0, Resource::loadPixmap("txt"));
67 }
68 if (ePtr->contentType == "AUDIO") {
69 actions = new QAction( tr("Play"), Resource::loadPixmap("SoundPlayer"), QString::null, CTRL + Key_C, this, 0);
70 actions->addTo(bar);
71 item->setPixmap(0, Resource::loadPixmap("play"));
72 }
73 if (ePtr->contentType == "IMAGE") {
74 actions = new QAction( tr("Show"), Resource::loadPixmap("pixmap"), QString::null, CTRL + Key_C, this, 0);
75 actions->addTo(bar);
76 item->setPixmap(0, Resource::loadPixmap("pixmap"));
77 }
78 }
79}
80
81void ViewAtt::install()
82{
83 Enclosure *ePtr, *selPtr;
84 QListViewItem *item;
85 QString filename;
86 DocLnk d;
87
88 item = listView->selectedItem();
89 if (item != NULL) {
90 filename = item->text(0);
91 selPtr = NULL;
92 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
93 if (ePtr->originalName == filename)
94 selPtr = ePtr;
95 }
96
97 if (selPtr == NULL) {
98 qWarning("Internal error, file is not installed to documents");
99 return;
100 }
101
102 d.setName(selPtr->originalName);
103 d.setFile(selPtr->path + selPtr->name);
104 d.setType(selPtr->contentType + "/" + selPtr->contentAttribute);
105 d.writeLink();
106 selPtr->installed = TRUE;
107 item->setText(2, "Yes");
108 }
109}
diff --git a/noncore/net/mailit/viewatt.h b/noncore/net/mailit/viewatt.h
new file mode 100644
index 0000000..9e43407
--- a/dev/null
+++ b/noncore/net/mailit/viewatt.h
@@ -0,0 +1,46 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef VIEWATT_H
21#define VIEWATT_H
22
23#include <qmainwindow.h>
24#include <qtoolbar.h>
25#include <qaction.h>
26#include <qlistview.h>
27#include "emailhandler.h"
28
29class ViewAtt : public QMainWindow
30{
31 Q_OBJECT
32
33public:
34 ViewAtt(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
35 void update(Email *mailIn, bool inbox);
36
37public slots:
38 void install();
39
40private:
41 QListView *listView;
42 QToolBar *bar;
43 QAction *installButton, *actions;
44 Email *mail;
45};
46#endif
diff --git a/noncore/net/mailit/writemail.cpp b/noncore/net/mailit/writemail.cpp
new file mode 100644
index 0000000..1a7185e
--- a/dev/null
+++ b/noncore/net/mailit/writemail.cpp
@@ -0,0 +1,299 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qmessagebox.h>
21#include "writemail.h"
22#include "resource.h"
23
24WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl )
25 : QMainWindow( parent, name, fl )
26{
27 showingAddressList = FALSE;
28 init();
29
30 addAtt = new AddAtt(0, "Add Attatchments");
31}
32
33WriteMail::~WriteMail()
34{
35 delete addAtt;
36}
37
38void WriteMail::setAddressList(AddressList *list)
39{
40 Contact *cPtr;
41
42 addressList = list;
43
44 addressView->clear();
45 QList<Contact> *cListPtr = addressList->getContactList();
46 QListViewItem *item;
47 for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) {
48 item = new QListViewItem(addressView, cPtr->email, cPtr->name);
49 }
50}
51
52void WriteMail::init()
53{
54 setToolBarsMovable(FALSE);
55
56 bar = new QToolBar(this);
57 bar->setHorizontalStretchable( TRUE );
58
59 menu = new QMenuBar( bar );
60
61 mailMenu = new QPopupMenu(menu);
62 menu->insertItem( tr( "&Mail" ), mailMenu);
63 addMenu = new QPopupMenu(menu);
64 menu->insertItem( tr( "&Add" ), addMenu);
65
66 bar = new QToolBar(this);
67 attatchButton = new QAction(tr("Attatchment"), Resource::loadPixmap("fileopen"), QString::null, 0, this, 0);
68 attatchButton->addTo(bar);
69 attatchButton->addTo(addMenu);
70 connect( attatchButton, SIGNAL( activated() ), this, SLOT( attatchFile() ) );
71
72 confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0);
73 confirmButton->addTo(bar);
74 confirmButton->addTo(mailMenu);
75 connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) );
76
77 newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0);
78 newButton->addTo(mailMenu);
79 connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) );
80
81 widget = new QWidget(this, "widget");
82 grid = new QGridLayout( widget );
83
84 recipientsBox = new QComboBox( FALSE, widget, "toLabel" );
85 recipientsBox->insertItem( tr( "To:" ) );
86 recipientsBox->insertItem( tr( "CC:" ) );
87 recipientsBox->setCurrentItem(0);
88 grid->addWidget( recipientsBox, 0, 0 );
89
90 subjetLabel = new QLabel( widget, "subjetLabel" );
91 subjetLabel->setText( tr( "Subject:" ) );
92
93 grid->addWidget( subjetLabel, 1, 0 );
94
95 ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" );
96 ToolButton13_2->setText( tr( "..." ) );
97 grid->addWidget( ToolButton13_2, 1, 2 );
98
99 subjectInput = new QLineEdit( widget, "subjectInput" );
100 grid->addWidget( subjectInput, 1, 1 );
101
102 toInput = new QLineEdit( widget, "toInput" );
103 grid->addWidget( toInput, 0, 1 );
104
105 addressButton = new QToolButton( widget, "addressButton" );
106 addressButton->setPixmap( Resource::loadPixmap("AddressBook") );
107 addressButton->setToggleButton(TRUE);
108 grid->addWidget( addressButton, 0, 2 );
109 connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) );
110
111 emailInput = new QMultiLineEdit( widget, "emailInput" );
112 grid->addMultiCellWidget( emailInput, 2, 2, 0, 2);
113
114 addressView = new QListView( widget, "addressView");
115 addressView->addColumn("Email");
116 addressView->addColumn("Name");
117 addressView->setAllColumnsShowFocus(TRUE);
118 addressView->setMultiSelection(TRUE);
119 addressView->hide();
120 grid->addMultiCellWidget( addressView, 3, 3, 0, 2);
121
122 okButton = new QToolButton(bar, "ok");
123 okButton->setPixmap( Resource::loadPixmap("enter") );
124 okButton->hide();
125 connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) );
126
127 setCentralWidget(widget);
128}
129
130void WriteMail::reject()
131{
132 emit cancelMail();
133}
134
135// need to insert date
136void WriteMail::accept()
137{
138 QStringList attatchedFiles, attatchmentsType;
139 int idCount = 0;
140
141 if (toInput->text() == "") {
142 QMessageBox::warning(this,"No recipient", "Send mail to whom?", "OK\n");
143 return;
144 }
145 if (! getRecipients() ) {
146 QMessageBox::warning(this,"Incorrect recipient separator",
147 "Recipients must be separated by ;\nand be valid emailaddresses", "OK\n");
148 return;
149 }
150 mail.subject = subjectInput->text();
151 mail.body = emailInput->text();
152 mail.sent = false;
153 mail.received = false;
154 mail.rawMail = "To: ";
155
156 for (QStringList::Iterator it = mail.recipients.begin();
157 it != mail.recipients.end(); ++it) {
158
159 mail.rawMail += (*it);
160 mail.rawMail += ",\n";
161 }
162 mail.rawMail.truncate(mail.rawMail.length()-2);
163 mail.rawMail += mail.from;
164 mail.rawMail += "\nSubject: ";
165 mail.rawMail += mail.subject;
166 mail.rawMail += "\n\n";
167
168 attatchedFiles = addAtt->returnAttatchedFiles();
169 attatchmentsType = addAtt->returnFileTypes();
170
171 QStringList::Iterator itType = attatchmentsType.begin();
172
173 Enclosure e;
174 for ( QStringList::Iterator it = attatchedFiles.begin();
175 it != attatchedFiles.end(); ++it ) {
176
177 e.id = idCount;
178 e.originalName = (*it).latin1();
179 e.contentType = (*itType).latin1();
180 e.contentAttribute = (*itType).latin1();
181 e.saved = TRUE;
182 mail.addEnclosure(&e);
183
184 itType++;
185 idCount++;
186 }
187 mail.rawMail += mail.body;
188 mail.rawMail += "\n";
189 mail.rawMail += ".\n";
190 emit sendMailRequested(mail);
191 addAtt->clear();
192}
193
194void WriteMail::getAddress()
195{
196 showingAddressList = !showingAddressList;
197
198 if (showingAddressList) {
199 emailInput->hide();
200 addressView->show();
201 okButton->show();
202
203 } else {
204 addressView->hide();
205 okButton->hide();
206 emailInput->show();
207 }
208}
209
210void WriteMail::attatchFile()
211{
212 addAtt->showMaximized();
213}
214
215void WriteMail::reply(Email replyMail)
216{
217 int pos;
218
219 mail = replyMail;
220 mail.files.clear();
221
222 toInput->setText(mail.fromMail);
223 subjectInput->setText("Re: " + mail.subject);
224
225 pos = 0;
226 mail.body.insert(pos, ">>");
227 while (pos != -1) {
228 pos = mail.body.find('\n', pos);
229 if (pos != -1)
230 mail.body.insert(++pos, ">>");
231 }
232
233 emailInput->setText(mail.body);
234}
235
236bool WriteMail::getRecipients()
237{
238 QString str, temp;
239 int pos = 0;
240
241 mail.recipients.clear();
242
243 temp = toInput->text();
244 while ( (pos = temp.find(';')) != -1) {
245 str = temp.left(pos).stripWhiteSpace();
246 temp = temp.right(temp.length() - (pos + 1));
247 if ( str.find('@') == -1)
248 return false;
249 mail.recipients.append(str);
250 addressList->addContact(str, "");
251 }
252 temp = temp.stripWhiteSpace();
253 if ( temp.find('@') == -1)
254 return false;
255 mail.recipients.append(temp);
256 addressList->addContact(temp, "");
257
258 return TRUE;
259}
260
261
262void WriteMail::addRecipients()
263{
264 QString recipients = "";
265
266 mail.recipients.clear();
267 QListViewItem *item = addressView->firstChild();
268 while (item != NULL) {
269 if ( item->isSelected() ) {
270 if (recipients == "") {
271 recipients = item->text(0);
272 } else {
273 recipients += "; " + item->text(0);
274 }
275 }
276 item = item->nextSibling();
277 }
278 toInput->setText(recipients);
279
280 addressView->hide();
281 okButton->hide();
282 emailInput->show();
283 addressButton->setOn(FALSE);
284 showingAddressList = !showingAddressList;
285}
286
287void WriteMail::setRecipient(const QString &recipient)
288{
289 toInput->setText(recipient);
290}
291
292void WriteMail::newMail()
293{
294 toInput->clear();
295 subjectInput->clear();
296 emailInput->clear();
297 //to clear selected
298 setAddressList(addressList);
299}
diff --git a/noncore/net/mailit/writemail.h b/noncore/net/mailit/writemail.h
new file mode 100644
index 0000000..dd12063
--- a/dev/null
+++ b/noncore/net/mailit/writemail.h
@@ -0,0 +1,91 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef WRITEMAIL_H
21#define WRITEMAIL_H
22
23#include <qmainwindow.h>
24#include <qaction.h>
25#include <qlabel.h>
26#include <qtoolbar.h>
27#include <qtoolbutton.h>
28#include <qmenubar.h>
29#include <qlayout.h>
30#include <qlineedit.h>
31#include <qmultilineedit.h>
32#include <qlistview.h>
33#include <qcombobox.h>
34
35#include "emailhandler.h"
36#include "addresslist.h"
37#include "addatt.h"
38
39class WriteMail : public QMainWindow
40{
41 Q_OBJECT
42
43public:
44 WriteMail( QWidget* parent, const char* name, WFlags fl = 0 );
45 ~WriteMail();
46 void reply(Email replyMail);
47 void setRecipient(const QString &recipient);
48 void setAddressList(AddressList *list);
49
50signals:
51 void sendMailRequested(const Email &mail);
52 void cancelMail();
53
54public slots:
55 void getAddress();
56 void attatchFile();
57 void addRecipients();
58 void newMail();
59 void accept();
60 void reject();
61
62private:
63 bool getRecipients();
64 void init();
65
66 Email mail;
67 AddAtt *addAtt;
68 AddressList *addressList;
69 bool showingAddressList;
70
71 QToolBar *bar;
72 QMenuBar *menu;
73 QPopupMenu *addMenu, *mailMenu;
74 QListView *addressView;
75
76 QToolButton *okButton;
77 QWidget *widget;
78 QAction *attatchButton;
79 QAction *confirmButton;
80 QAction *newButton;
81 QLabel* subjetLabel;
82 QToolButton* ToolButton13_2;
83 QComboBox* recipientsBox;
84 QLineEdit *subjectInput;
85 QLineEdit *toInput;
86 QToolButton* addressButton;
87 QMultiLineEdit* emailInput;
88 QGridLayout* grid;
89};
90
91#endif // WRITEMAIL_H
diff --git a/noncore/unsupported/mailit/README b/noncore/unsupported/mailit/README
new file mode 100644
index 0000000..01781b4
--- a/dev/null
+++ b/noncore/unsupported/mailit/README
@@ -0,0 +1,83 @@
1Issues regarding Mailit
2-----------------------
3
4Mailit is still in development and is lacking some
5features to make it completely usable. Listed below are the
6most important issues.
7
8Due to the development status, numerous messages are passed too
9the console during usage of the program.
10No messages are deleted from the POP server after retrival.
11
12Synchronization:
13---------------------
14Works by comparing the last known size of the mailbox on the server
15to the current size.
16Possible problem: If a popserver shuffles the order of the mails
17when it receives a new mail, mailit won't know since it only uses
18the messagecount as a reference. If this occurs, turn sync off in
19the account settings.
20Haven't encountered this problem on the currently tested servers,
21but if it turns out that several servers do this, it will be resolved.
22
23Mail parsing
24------------
25Parsing of MIME-encoded email works for all currently tested cases.
26BASE64 decoding works.
27Attatchments are saved in the enclosure subdirectory of qtmail
28(in the Documents directory). You can install the files to the documents
29folder (creates a doclnk)
30Adding enclosures is limited to the preselected directories, and they
31are not really correct at the moment (trivial issue awaiting decision
32of fileplacements in QPE)
33attatched pictures will be displayed (jpg dependant on qte compilation)
34
35
36SMTP
37----
38The SMTP-client now supports attatchments, but it's not completly done.
39Encoding works, but it doesn't examine the file to check what type of
40file you are attatching. In other words, if it doesn't know that you
41are attatching a picture, the mime setting for content type could be
42wrong. Mail clients with inline viewing of pictures (like hotmail) could
43have a problem with displaying the mail correctly.
44(Should be fixed soon)
45
46You can now have multiple recipients.
47
48
49POP
50---
51The popclient connects to the all accounts in turn, downloads all headers
52and emails smaller than 2000 bytes. After its done, it reconnects
53and downloads the mails that were too big (> 2000)
54The to-be-downloaded mails are sorted according to size. If you view
55a mail, it is shifted to the front of the queue. Deleting a mail(header)
56while the download is in progress will remove it from the queue of
57mails to download (except if the mail is currently in transfer)
58You may exit mailit during a transfer of mails/headers. Next time
59you reconnect to the same server it will continue downloading from
60where it left off.
61
62You can now choose between getting mail from only one account or all.
63The get all option is just added and not fully testet yet. Get from
64a single account should work fine. The current way of downloading
65does not work well without sync turned on if you keep old mails in
66the inbox.
67
68Experienced some problems with servers reporting mail size less and
69bigger than actual size. Don't know whats causing this yet, but I
70have added a workaround. It now scans the mail for endofmail
71definition ("\r\n.\r\n"), disregarding size.
72
73
74Saving/Retrieving mail
75----------------------
76The inbox is saved and retrieved. Any mail not sent from the outbox
77is not saved (will of course be added)
78
79Miscelaneous issues
80-------------------
81Numerous cosmetic changes, including icons (which are temporary)
82
83Very little error checking is done on usertyped variables.
diff --git a/noncore/unsupported/mailit/addatt.cpp b/noncore/unsupported/mailit/addatt.cpp
new file mode 100644
index 0000000..c030e36
--- a/dev/null
+++ b/noncore/unsupported/mailit/addatt.cpp
@@ -0,0 +1,209 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qlayout.h>
21#include <qdir.h>
22#include <qstringlist.h>
23#include "resource.h"
24#include "addatt.h"
25
26FileItem::FileItem(QListView *parent, QFileInfo fileInfo, QString fileType)
27 : QListViewItem(parent)
28{
29 file = fileInfo;
30 type = fileType;
31
32 setText(0, fileInfo.baseName());
33
34 if (fileType == "Picture") {
35 setPixmap(0, Resource::loadPixmap("pixmap"));
36 } else if (fileType == "Document") {
37 setPixmap(0, Resource::loadPixmap("txt"));
38 } else if (fileType == "Sound") {
39 setPixmap(0, Resource::loadPixmap("play"));
40 } else if (fileType == "Movie") {
41 setPixmap(0, Resource::loadPixmap("MPEGPlayer"));
42 } else if (fileType == "File") {
43 setPixmap(0, Resource::loadPixmap("exec"));
44 }
45}
46
47QFileInfo FileItem::getFileInfo()
48{
49 return file;
50}
51
52QString FileItem::getFileType()
53{
54 return type;
55}
56
57AddAtt::AddAtt(QWidget *parent, const char *name, WFlags f)
58 : QDialog(parent, name, f)
59{
60 setCaption("Adding attatchments");
61
62 QGridLayout *top = new QGridLayout(this, 3, 2);
63
64 fileCategoryButton = new QPushButton(this);
65 attatchButton = new QPushButton("Attatch ->", this);
66 removeButton = new QPushButton("Remove", this);
67
68 fileCategories = new QPopupMenu(fileCategoryButton);
69 fileCategoryButton->setPopup(fileCategories);
70 fileCategories->insertItem("Document");
71 fileCategories->insertItem("Picture");
72 fileCategories->insertItem("Sound");
73 fileCategories->insertItem("Movie");
74 fileCategories->insertItem("File");
75
76 fileCategoryButton->setText("Document");
77 top->addWidget(fileCategoryButton, 0, 0);
78 top->addWidget(attatchButton, 2, 0);
79 top->addWidget(removeButton, 2, 1);
80
81 connect(fileCategories, SIGNAL(activated(int)), this,
82 SLOT(fileCategorySelected(int)) );
83 connect(attatchButton, SIGNAL(clicked()), this,
84 SLOT(addAttatchment()) );
85 connect(removeButton, SIGNAL(clicked()), this,
86 SLOT(removeAttatchment()) );
87
88 listView = new QListView(this, "AttView");
89 listView->addColumn("Documents");
90 connect(listView, SIGNAL(doubleClicked(QListViewItem *)), this,
91 SLOT(addAttatchment()) );
92
93 attView = new QListView(this, "Selected");
94 attView->addColumn("Attatched");
95 connect(attView, SIGNAL(doubleClicked(QListViewItem *)), this,
96 SLOT(removeAttatchment()) );
97
98 top->addWidget(listView, 1,0);
99 top->addWidget(attView, 1,1);
100
101 clear();
102}
103
104void AddAtt::clear()
105{
106 attView->clear();
107 getFiles();
108 modified = FALSE;
109}
110
111void AddAtt::fileCategorySelected(int id)
112{
113 fileCategoryButton->setText(fileCategories->text(id));
114 getFiles();
115}
116
117void AddAtt::addAttatchment()
118{
119 QFileInfo info;
120 QString type;
121
122 if (listView->selectedItem() != NULL) {
123 item = (FileItem *) listView->selectedItem();
124 info = item->getFileInfo();
125 type = item->getFileType();
126 item = new FileItem(attView, info, type);
127 }
128 modified = TRUE;
129}
130
131void AddAtt::removeAttatchment()
132{
133 if (attView->selectedItem() != NULL) {
134 attView->takeItem(attView->selectedItem());
135 }
136 modified = TRUE;
137}
138
139void AddAtt::reject()
140{
141 if (modified) {
142 attView->clear();
143 modified = FALSE;
144 }
145}
146
147void AddAtt::accept()
148{
149 modified = FALSE;
150 hide();
151}
152
153void AddAtt::getFiles()
154{
155 QString path, selected;
156 QDir *dir;
157
158 listView->clear();
159
160 selected = fileCategoryButton->text();
161 if (selected == "Picture") {
162 path = "../pics/";
163 } else if (selected == "Document") {
164 path = "" ; //sub-dirs not decided
165 } else if (selected == "Sound") {
166 path = "../sounds/"; //sub-dirs not decided
167 } else if (selected == "Movie") {
168 path = ""; //sub-dirs not decided
169 } else if (selected == "File") {
170 path = ""; //sub-dirs not decided
171 }
172
173 dir = new QDir(path);
174 dir->setFilter(QDir::Files);
175 const QFileInfoList *dirInfoList = dir->entryInfoList();
176
177 QFileInfoListIterator it(*dirInfoList); // create list iterator
178
179 while ( (fi=it.current()) ) { // for each file...
180 item = new FileItem(listView, *fi, selected);
181 ++it; // goto next list element
182 }
183}
184
185QStringList AddAtt::returnAttatchedFiles()
186{
187 QFileInfo info;
188 QStringList list;
189
190 item = (FileItem *) attView->firstChild();
191 while (item != NULL) {
192 info = item->getFileInfo();
193 list += info.filePath();
194 item = (FileItem *) item->nextSibling();
195 }
196 return list;
197}
198
199QStringList AddAtt::returnFileTypes()
200{
201 QStringList list;
202
203 item = (FileItem *) attView->firstChild();
204 while (item != NULL) {
205 list += item->getFileType();
206 item = (FileItem *) item->nextSibling();
207 }
208 return list;
209}
diff --git a/noncore/unsupported/mailit/addatt.h b/noncore/unsupported/mailit/addatt.h
new file mode 100644
index 0000000..867c905
--- a/dev/null
+++ b/noncore/unsupported/mailit/addatt.h
@@ -0,0 +1,70 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef ADDATT_H
21#define ADDATT_H
22
23#include <qdialog.h>
24#include <qlistview.h>
25#include <qpushbutton.h>
26#include <qpopupmenu.h>
27#include <qstring.h>
28#include <qfileinfo.h>
29#include <qstringlist.h>
30
31class FileItem : public QListViewItem
32{
33public:
34 FileItem(QListView *parent, QFileInfo fileInfo, QString fileType);
35 QFileInfo getFileInfo();
36 QString getFileType();
37
38private:
39 QFileInfo file;
40 QString type;
41};
42
43class AddAtt : public QDialog
44{
45 Q_OBJECT
46
47public:
48 AddAtt(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
49 QStringList returnAttatchedFiles();
50 QStringList returnFileTypes();
51 void getFiles();
52 void clear();
53
54public slots:
55 void fileCategorySelected(int);
56 void addAttatchment();
57 void removeAttatchment();
58 void reject();
59 void accept();
60
61private:
62 FileItem *item;
63 QListView *listView, *attView;
64 QPushButton *fileCategoryButton, *attatchButton, *removeButton;
65 QPopupMenu *fileCategories;
66 bool modified;
67 QFileInfo *fi;
68};
69
70#endif
diff --git a/noncore/unsupported/mailit/addresslist.cpp b/noncore/unsupported/mailit/addresslist.cpp
new file mode 100644
index 0000000..1cf2562
--- a/dev/null
+++ b/noncore/unsupported/mailit/addresslist.cpp
@@ -0,0 +1,167 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qfile.h>
21#include <qtextstream.h>
22
23#include "addresslist.h"
24
25AddressList::AddressList(QString file)
26{
27 addresses.setAutoDelete(TRUE);
28 filename = file;
29 read();
30 dirty = FALSE;
31}
32
33AddressList::~AddressList()
34{
35 write();
36 addresses.clear();
37}
38
39void AddressList::addContact(QString email, QString name)
40{
41 //skip if not a valid email address,
42 if (email.find( '@') == -1)
43 return;
44
45 if ( ! containsEmail(email) ) {
46 Contact *in = new Contact;
47 in->email = email;
48 in->name = name;
49 addresses.append(in);
50 dirty = TRUE;
51 }
52}
53
54bool AddressList::containsEmail(QString email)
55{
56 return ( getEmailRef(email) != -1 );
57}
58
59bool AddressList::containsName(QString name)
60{
61 return ( getNameRef(name) != -1 );
62}
63
64QString AddressList::getNameByEmail(QString email)
65{
66 int pos = getEmailRef(email);
67 if (pos != -1) {
68 Contact *ptr = addresses.at(pos);
69 return ptr->name;
70 }
71
72 return NULL;
73}
74
75QString AddressList::getEmailByName(QString name)
76{
77 int pos = getNameRef(name);
78 if (pos != -1) {
79 Contact *ptr = addresses.at(pos);
80 return ptr->email;
81 }
82
83 return NULL;
84}
85
86int AddressList::getEmailRef(QString email)
87{
88 int pos = 0;
89 Contact *ptr;
90
91 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) {
92 if (ptr->email == email)
93 return pos;
94 pos++;
95 }
96 return -1;
97}
98
99int AddressList::getNameRef(QString name)
100{
101 int pos = 0;
102 Contact *ptr;
103
104 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) {
105 if (ptr->name == name)
106 return pos;
107 pos++;
108 }
109 return -1;
110}
111
112QList<Contact>* AddressList::getContactList()
113{
114 return &addresses;
115}
116
117void AddressList::read()
118{
119 QFile f(filename);
120 QString lineEmail, lineName, email, name;
121
122 if (! f.open(IO_ReadOnly) )
123 return;
124
125 QTextStream stream(&f);
126
127 while (! stream.atEnd() ) {
128 lineEmail = stream.readLine();
129 if (! stream.atEnd() )
130 lineName = stream.readLine();
131 else return;
132
133 email = getRightString(lineEmail);
134 name = getRightString(lineName);
135 addContact(email, name);
136 }
137 f.close();
138}
139
140QString AddressList::getRightString(QString in)
141{
142 QString out = "";
143
144 int pos = in.find('=');
145 if (pos != -1) {
146 out = in.mid(pos+1).stripWhiteSpace();
147 }
148 return out;
149}
150
151void AddressList::write()
152{
153 if ( (addresses.count() == 0) || (!dirty) )
154 return;
155
156 QFile f(filename);
157 if (! f.open(IO_WriteOnly) )
158 return;
159
160 QTextStream stream(&f);
161 Contact *ptr;
162 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) {
163 stream << "email = " + ptr->email + "\n";
164 stream << "name = " + ptr->name + "\n";
165 }
166 f.close();
167}
diff --git a/noncore/unsupported/mailit/addresslist.h b/noncore/unsupported/mailit/addresslist.h
new file mode 100644
index 0000000..e87d6f1
--- a/dev/null
+++ b/noncore/unsupported/mailit/addresslist.h
@@ -0,0 +1,59 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef ADDRESSLIST_H
21#define ADDRESSLIST_H
22
23#include <qobject.h>
24#include <qlist.h>
25
26struct Contact
27{
28 QString email;
29 QString name;
30};
31
32class AddressList : public QObject
33{
34 Q_OBJECT
35
36public:
37 AddressList(QString file);
38 ~AddressList();
39 void addContact(QString email, QString name);
40 bool containsEmail(QString email);
41 bool containsName(QString name);
42 QString getNameByEmail(QString email);
43 QString getEmailByName(QString name);
44 QList<Contact>* getContactList();
45 void write();
46
47private:
48 int getEmailRef(QString email);
49 int getNameRef(QString name);
50 QString getRightString(QString in);
51 void read();
52
53private:
54 QList<Contact> addresses;
55 QString filename;
56 bool dirty;
57};
58
59#endif
diff --git a/noncore/unsupported/mailit/editaccount.cpp b/noncore/unsupported/mailit/editaccount.cpp
new file mode 100644
index 0000000..c4f95ea
--- a/dev/null
+++ b/noncore/unsupported/mailit/editaccount.cpp
@@ -0,0 +1,120 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18***
19**********************************************************************/
20
21#include "editaccount.h"
22
23EditAccount::EditAccount( QWidget* parent, const char* name, WFlags fl )
24 : QDialog(parent, name, fl)
25{
26 setCaption( tr("Edit Account") );
27 init();
28 popPasswInput->setEchoMode(QLineEdit::Password);
29}
30
31void EditAccount::setAccount(MailAccount *in, bool newOne)
32{
33 account = in;
34 if (newOne) {
35 accountNameInput->setText("");
36 nameInput->setText("");
37 emailInput->setText("");
38 popUserInput->setText("");
39 popPasswInput->setText("");
40 popServerInput->setText("");
41 smtpServerInput->setText("");
42 syncCheckBox->setChecked(TRUE);
43
44 setCaption( tr("Create new Account") );
45 } else {
46 accountNameInput->setText(account->accountName);
47 nameInput->setText(account->name);
48 emailInput->setText(account->emailAddress);
49 popUserInput->setText(account->popUserName);
50 popPasswInput->setText(account->popPasswd);
51 popServerInput->setText(account->popServer);
52 smtpServerInput->setText(account->smtpServer);
53 syncCheckBox->setChecked(account->synchronize);
54 }
55}
56
57void EditAccount::init()
58{
59 grid = new QGridLayout(this);
60 grid->setSpacing( 6 );
61 grid->setMargin( 11 );
62
63 accountNameInputLabel = new QLabel(tr("Account name"), this);
64 grid->addWidget( accountNameInputLabel, 0, 0 );
65 accountNameInput = new QLineEdit( this, "account nameInput" );
66 grid->addWidget( accountNameInput, 0, 1 );
67
68 nameInputLabel = new QLabel(tr("Your name"), this);
69 grid->addWidget( nameInputLabel, 1, 0 );
70 nameInput = new QLineEdit( this, "nameInput" );
71 grid->addWidget( nameInput, 1, 1 );
72
73 emailInputLabel = new QLabel("Email", this);
74 grid->addWidget(emailInputLabel, 2, 0 );
75 emailInput = new QLineEdit( this, "emailInput" );
76 grid->addWidget( emailInput, 2, 1 );
77
78 popUserInputLabel = new QLabel("POP username", this);
79 grid->addWidget( popUserInputLabel, 3, 0 );
80 popUserInput = new QLineEdit( this, "popUserInput" );
81 grid->addWidget( popUserInput, 3, 1 );
82
83 popPasswInputLabel = new QLabel( "POP password", this);
84 grid->addWidget( popPasswInputLabel, 4, 0 );
85 popPasswInput = new QLineEdit( this, "popPasswInput" );
86 grid->addWidget( popPasswInput, 4, 1 );
87
88 popServerInputLabel = new QLabel("POP server", this);
89 grid->addWidget( popServerInputLabel, 5, 0 );
90 popServerInput = new QLineEdit( this, "popServerInput" );
91 grid->addWidget( popServerInput, 5, 1 );
92
93 smtpServerInputLabel = new QLabel("SMTP server", this );
94 grid->addWidget( smtpServerInputLabel, 6, 0 );
95 smtpServerInput = new QLineEdit( this, "smtpServerInput" );
96 grid->addWidget( smtpServerInput, 6, 1 );
97
98 syncCheckBox = new QCheckBox( tr( "Synchronize with server" ), this);
99 syncCheckBox->setChecked( TRUE );
100 grid->addMultiCellWidget( syncCheckBox, 7, 7, 0, 1 );
101}
102
103
104void EditAccount::accept()
105{
106 account->accountName = accountNameInput->text();
107 account->name = nameInput->text();
108 account->emailAddress = emailInput->text();
109 account->popUserName = popUserInput->text();
110 account->popPasswd = popPasswInput->text();
111 account->popServer = popServerInput->text();
112 account->smtpServer = smtpServerInput->text();
113 account->synchronize = syncCheckBox->isChecked();
114
115 QDialog::accept();
116}
117
118void EditAccount::reject()
119{
120}
diff --git a/noncore/unsupported/mailit/editaccount.h b/noncore/unsupported/mailit/editaccount.h
new file mode 100644
index 0000000..7a90e50
--- a/dev/null
+++ b/noncore/unsupported/mailit/editaccount.h
@@ -0,0 +1,66 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef EDITACCOUNT_H
21#define EDITACCOUNT_H
22
23#include <qdialog.h>
24#include <qlabel.h>
25#include <qlineedit.h>
26#include <qcheckbox.h>
27#include <qlayout.h>
28#include "emailhandler.h"
29
30class EditAccount : public QDialog
31{
32 Q_OBJECT
33
34public:
35 EditAccount( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
36 void setAccount(MailAccount *in, bool newOne = TRUE);
37 void init();
38
39public slots:
40 void accept();
41 void reject();
42
43private:
44 MailAccount thisAccount, *account;
45
46 QLabel *accountNameInputLabel;
47 QLabel *nameInputLabel;
48 QLabel *emailInputLabel;
49 QLabel *popUserInputLabel;
50 QLabel *popPasswInputLabel;
51 QLabel *popServerInputLabel;
52 QLabel *smtpServerInputLabel;
53
54 QLineEdit *accountNameInput;
55 QLineEdit *nameInput;
56 QLineEdit *emailInput;
57 QLineEdit *popUserInput;
58 QLineEdit *popPasswInput;
59 QLineEdit *popServerInput;
60 QLineEdit *smtpServerInput;
61 QCheckBox *syncCheckBox;
62
63 QGridLayout *grid;
64};
65
66#endif
diff --git a/noncore/unsupported/mailit/emailclient.cpp b/noncore/unsupported/mailit/emailclient.cpp
new file mode 100644
index 0000000..7ba5c75
--- a/dev/null
+++ b/noncore/unsupported/mailit/emailclient.cpp
@@ -0,0 +1,858 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qapplication.h>
21#include <qmessagebox.h>
22#include <qfile.h>
23#include <qcheckbox.h>
24#include <qmenubar.h>
25#include <qaction.h>
26#include "resource.h"
27#include "emailclient.h"
28
29QCollection::Item AccountList::newItem(QCollection::Item d)
30{
31 return dupl( (MailAccount *) d);
32}
33
34MailAccount* AccountList::dupl(MailAccount *in)
35{
36 ac = new MailAccount(*in);
37 return ac;
38}
39
40EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl )
41 : QMainWindow( parent, name, fl )
42{
43 emailHandler = new EmailHandler();
44 addressList = new AddressList( getPath(FALSE) + "mail_adr");
45
46 sending = FALSE;
47 receiving = FALSE;
48 previewingMail = FALSE;
49 mailIdCount = 1;
50 accountIdCount = 1;
51 allAccounts = FALSE;
52
53 init();
54
55 connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) );
56
57 connect(emailHandler, SIGNAL(smtpError(int)), this,
58 SLOT(smtpError(int)) );
59 connect(emailHandler, SIGNAL(popError(int)), this,
60 SLOT(popError(int)) );
61
62 connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemSelected()) );
63 connect(outboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(outboxItemSelected()) );
64
65 connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this,
66 SLOT(mailArrived(const Email &, bool)) );
67 connect(emailHandler, SIGNAL(mailTransfered(int)), this,
68 SLOT(allMailArrived(int)) );
69
70 mailconf = new Config("mailit");
71 //In case Synchronize is not defined in settings.txt
72
73 readSettings();
74
75 updateAccounts();
76
77 lineShift = "\n";
78 readMail();
79 lineShift = "\r\n";
80
81}
82
83
84EmailClient::~EmailClient()
85{
86 //needs to be moved from destructor to closewindow event
87 saveMail(getPath(FALSE) + "inbox.txt", inboxView);
88 //does not currently work. Defining outbox in the same
89 //format as inbox is not a good solution as they have
90 //different properties
91 saveMail(getPath(FALSE) + "outbox.txt", outboxView);
92 saveSettings();
93
94 mailconf->write();
95 delete mailconf;
96
97}
98
99void EmailClient::init()
100{
101 statusBar = new QStatusBar(this);
102 statusBar->setSizeGripEnabled(FALSE);
103
104 status1Label = new QLabel( tr("Idle"), statusBar);
105 status2Label = new QLabel("", statusBar);
106 connect(emailHandler, SIGNAL(updatePopStatus(const QString &)),
107 status2Label, SLOT(setText(const QString &)) );
108 connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)),
109 status2Label, SLOT(setText(const QString &)) );
110
111 progressBar = new QProgressBar(statusBar);
112 connect(emailHandler, SIGNAL(mailboxSize(int)),
113 this, SLOT(setTotalSize(int)) );
114 connect(emailHandler, SIGNAL(currentMailSize(int)),
115 this, SLOT(setMailSize(int)) );
116 connect(emailHandler, SIGNAL(downloadedSize(int)),
117 this, SLOT(setDownloadedSize(int)) );
118
119 statusBar->addWidget(status1Label);
120 statusBar->addWidget(progressBar);
121 statusBar->addWidget(status2Label);
122
123 setToolBarsMovable(FALSE);
124
125 bar = new QToolBar(this);
126 bar->setHorizontalStretchable( TRUE );
127
128 mb = new QMenuBar( bar );
129
130 QPopupMenu *mail = new QPopupMenu(mb);
131 mb->insertItem( tr( "&Mail" ), mail);
132
133 QPopupMenu *configure = new QPopupMenu(mb);
134 mb->insertItem( tr( "Accounts" ), configure);
135
136 selectAccountMenu = new QPopupMenu(mb);
137 editAccountMenu = new QPopupMenu(mb);
138 deleteAccountMenu = new QPopupMenu(mb);
139
140 mail->insertItem(tr("Get Mail in"), selectAccountMenu);
141 configure->insertItem(tr("Edit account"), editAccountMenu);
142 configure->insertItem(tr("Delete account"), deleteAccountMenu);
143
144 bar = new QToolBar(this);
145
146 getMailButton = new QAction(tr("Get all mail"), QPixmap("getmail.xpm"), QString::null, 0, this, 0);
147 connect(getMailButton, SIGNAL(activated()), this, SLOT(getAllNewMail()) );
148 getMailButton->addTo(bar);
149 getMailButton->addTo(mail);
150
151 sendMailButton = new QAction(tr("Send mail"), QPixmap("sendmail.xpm"), QString::null, 0, this, 0);
152 connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) );
153 sendMailButton->addTo(bar);
154 sendMailButton->addTo(mail);
155
156 composeButton = new QAction(tr("Compose"), Resource::loadPixmap("new"), QString::null, 0, this, 0);
157 connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) );
158 composeButton->addTo(bar);
159 composeButton->addTo(mail);
160
161 cancelButton = new QAction(tr("Cancel transfer"), Resource::loadPixmap("reset"), QString::null, 0, this, 0);
162 connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) );
163 cancelButton->addTo(mail);
164 cancelButton->setEnabled(FALSE);
165
166 mailboxView = new QTabWidget( this, "mailboxView" );
167
168 QWidget* widget = new QWidget( mailboxView, "widget" );
169 grid_2 = new QGridLayout( widget );
170// grid_2->setSpacing(6);
171// grid_2->setMargin( 11 );
172
173 inboxView = new QListView( widget, "inboxView" );
174 inboxView->addColumn( tr( "From" ) );
175 inboxView->addColumn( tr( "Subject" ) );
176 inboxView->addColumn( tr( "Date" ) );
177 inboxView->setMinimumSize( QSize( 0, 0 ) );
178 inboxView->setAllColumnsShowFocus(TRUE);
179
180 grid_2->addWidget( inboxView, 2, 0 );
181 mailboxView->insertTab( widget, tr( "Inbox" ) );
182
183 QWidget* widget_2 = new QWidget( mailboxView, "widget_2" );
184 grid_3 = new QGridLayout( widget_2 );
185// grid_3->setSpacing(6);
186// grid_3->setMargin( 11 );
187
188 outboxView = new QListView( widget_2, "outboxView" );
189 outboxView->addColumn( tr( "To" ) );
190 outboxView->addColumn( tr( "Subject" ) );
191 outboxView->setAllColumnsShowFocus(TRUE);
192
193 grid_3->addWidget( outboxView, 0, 0 );
194 mailboxView->insertTab( widget_2, tr( "Outbox" ) );
195
196 setCentralWidget(mailboxView);
197}
198
199void EmailClient::compose()
200{
201 emit composeRequested();
202}
203
204void EmailClient::cancel()
205{
206 emailHandler->cancel();
207}
208
209AddressList* EmailClient::getAdrListRef()
210{
211 return addressList;
212}
213
214//this needs to be rewritten to syncronize with outboxView
215void EmailClient::enqueMail(const Email &mail)
216{
217 if (accountList.count() > 0) {
218 currentAccount = accountList.first();
219 qWarning("using account " + currentAccount->name);
220 }
221
222 Email addMail = mail;
223 addMail.from = currentAccount->name;
224 addMail.fromMail = currentAccount->emailAddress;
225 addMail.rawMail.prepend("From: " + addMail.from + "<" + addMail.fromMail + ">\n");
226 item = new EmailListItem(outboxView, addMail, false);
227
228}
229
230void EmailClient::sendQuedMail()
231{
232 int count = 0;
233
234 if (accountList.count() == 0) {
235 QMessageBox::warning(qApp->activeWindow(),
236 "No account selected", "You must create an account", "OK\n");
237 return;
238 }
239 //traverse listview, find messages to send
240 if (! sending) {
241 item = (EmailListItem *) outboxView->firstChild();
242 if (item != NULL) {
243 while (item != NULL) {
244 quedMessages.append(item->getMail());
245 item = (EmailListItem *) item->nextSibling();
246 count++;
247 }
248 setMailAccount();
249 emailHandler->sendMail(&quedMessages);
250 sending = TRUE;
251 sendMailButton->setEnabled(FALSE);
252 cancelButton->setEnabled(TRUE);
253 } else {
254 qWarning("sendQuedMail(): no messages to send");
255 }
256 }
257}
258
259void EmailClient::setMailAccount()
260{
261 emailHandler->setAccount(*currentAccount);
262}
263
264void EmailClient::mailSent()
265{
266 sending = FALSE;
267 sendMailButton->setEnabled(TRUE);
268
269 quedMessages.clear();
270 outboxView->clear(); //should be moved to an sentBox
271}
272
273void EmailClient::getNewMail() {
274
275 if (accountList.count() == 0) {
276 QMessageBox::warning(qApp->activeWindow(),"No account selected",
277 "You must create an account", "OK\n");
278 return;
279 }
280
281 setMailAccount();
282
283 receiving = TRUE;
284 previewingMail = TRUE;
285 getMailButton->setEnabled(FALSE);
286 cancelButton->setEnabled(TRUE);
287 selectAccountMenu->setEnabled(FALSE);
288
289 status1Label->setText(currentAccount->accountName + " headers");
290 progressBar->reset();
291
292 //get any previous mails not downloaded and add to queue
293 mailDownloadList.clear();
294 Email *mailPtr;
295 item = (EmailListItem *) inboxView->firstChild();
296 while (item != NULL) {
297 mailPtr = item->getMail();
298 if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) {
299 mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size);
300 }
301 item = (EmailListItem *) item->nextSibling();
302 }
303
304 emailHandler->getMailHeaders();
305}
306
307void EmailClient::getAllNewMail()
308{
309 allAccounts = TRUE;
310 currentAccount = accountList.first();
311 getNewMail();
312}
313
314void EmailClient::mailArrived(const Email &mail, bool fromDisk)
315{
316 Enclosure *ePtr;
317 Email newMail;
318 int thisMailId;
319 emailHandler->parse(mail.rawMail, lineShift, &newMail);
320
321 mailconf->setGroup(newMail.id);
322
323 if (fromDisk) {
324 newMail.downloaded = mailconf->readBoolEntry("downloaded");
325 newMail.size = mailconf->readNumEntry("size");
326 newMail.serverId = mailconf->readNumEntry("serverid");
327 newMail.fromAccountId = mailconf->readNumEntry("fromaccountid");
328 } else { //mail arrived from server
329 newMail.serverId = mail.serverId;
330 newMail.size = mail.size;
331 newMail.downloaded = mail.downloaded;
332
333 newMail.fromAccountId = currentAccount->id;
334 mailconf->writeEntry("fromaccountid", newMail.fromAccountId);
335 }
336
337 //add if read or not
338 newMail.read = mailconf->readBoolEntry("mailread");
339
340 //check if new mail
341 if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) {
342 thisMailId = mailIdCount;
343 mailIdCount++;
344
345 //set server count, so that if the user aborts, the new
346 //header is not reloaded
347 if (currentAccount->synchronize)
348 currentAccount->lastServerMailCount++;
349
350 mailconf->writeEntry("internalmailid", thisMailId);
351 mailconf->writeEntry("downloaded", newMail.downloaded);
352 mailconf->writeEntry("size", (int) newMail.size);
353 mailconf->writeEntry("serverid", newMail.serverId);
354
355 addressList->addContact(newMail.fromMail, newMail.from);
356 } else if (!fromDisk) { //body to header arrived
357 mailconf->writeEntry("downloaded", TRUE);
358 }
359 QString stringMailId;
360 stringMailId.setNum(thisMailId);
361 //se if any attatchments needs to be stored
362 for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) {
363 QString stringId;
364 stringId.setNum(ePtr->id);
365
366 int id = mailconf->readNumEntry("enclosureid_" + stringId);
367 if (id != ePtr->id) { //new entry
368 mailconf->writeEntry("enclosureid_" + stringId, ePtr->id);
369 mailconf->writeEntry("name_" + stringId, ePtr->originalName);
370 mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType);
371 mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute);
372 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
373 mailconf->writeEntry("installed_" + stringId, FALSE);
374
375 ePtr->name = stringMailId + "_" + stringId;
376 ePtr->path = getPath(TRUE);
377 if (emailHandler->getEnclosure(ePtr)) { //file saved
378 ePtr->saved = TRUE;
379 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
380 mailconf->writeEntry("filename_" + stringId, ePtr->name);
381 mailconf->writeEntry("path_" + stringId, ePtr->path);
382 } else {
383 ePtr->saved = FALSE;
384 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
385 }
386 } else {
387 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId);
388 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId);
389 if (ePtr->saved) {
390 ePtr->name = mailconf->readEntry("filename_" + stringId);
391 ePtr->path = mailconf->readEntry("path_" + stringId);
392 }
393 }
394 }
395 if (!previewingMail && !fromDisk) {
396 Email *mailPtr;
397 item = (EmailListItem *) inboxView->firstChild();
398 while (item != NULL) {
399 mailPtr = item->getMail();
400 if (mailPtr->id == newMail.id) {
401 item->setMail(newMail);
402 emit mailUpdated(item->getMail());
403 }
404 item = (EmailListItem *) item->nextSibling();
405 }
406 } else {
407 item = new EmailListItem(inboxView, newMail, TRUE);
408 if (!newMail.downloaded)
409 mailDownloadList.sizeInsert(newMail.serverId, newMail.size);
410 }
411
412}
413
414void EmailClient::allMailArrived(int count)
415{
416 // not previewing means all mailtransfer has been done
417 if (!previewingMail) {
418 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) {
419 emit newCaption("Mailit - " + currentAccount->accountName);
420 getNewMail();
421 return;
422 } else {
423 allAccounts = FALSE;
424 receiving = FALSE;
425 getMailButton->setEnabled(TRUE);
426 cancelButton->setEnabled(FALSE);
427 selectAccountMenu->setEnabled(TRUE);
428 status1Label->setText("Idle");
429
430 progressBar->reset();
431 return;
432 }
433 }
434
435 // all headers downloaded from server, start downloading remaining mails
436 previewingMail = FALSE;
437 status1Label->setText(currentAccount->accountName);
438 progressBar->reset();
439
440 emailHandler->getMailByList(&mailDownloadList);
441}
442
443void EmailClient::moveMailFront(Email *mailPtr)
444{
445 if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) {
446 mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size);
447 }
448}
449
450void EmailClient::smtpError(int code)
451{
452 QString temp;
453
454 if (code == ErrUnknownResponse)
455 temp = "Unknown response from server";
456
457 if (code == QSocket::ErrHostNotFound)
458 temp = "host not found";
459 if (code == QSocket::ErrConnectionRefused)
460 temp = "connection refused";
461 if (code == QSocket::ErrSocketRead)
462 temp = "socket packet error";
463
464 if (code != ErrCancel) {
465 QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n");
466 } else {
467 status2Label->setText("Aborted by user");
468 }
469
470 sending = FALSE;
471 sendMailButton->setEnabled(TRUE);
472 cancelButton->setEnabled(FALSE);
473 quedMessages.clear();
474}
475
476void EmailClient::popError(int code)
477{
478 QString temp;
479
480 if (code == ErrUnknownResponse)
481 temp = "Unknown response from server";
482 if (code == ErrLoginFailed)
483 temp = "Login failed\nCheck user name and password";
484
485 if (code == QSocket::ErrHostNotFound)
486 temp = "host not found";
487 if (code == QSocket::ErrConnectionRefused)
488 temp = "connection refused";
489 if (code == QSocket::ErrSocketRead)
490 temp = "socket packet error";
491
492 if (code != ErrCancel) {
493 QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n");
494 } else {
495 status2Label->setText("Aborted by user");
496 }
497
498 receiving = FALSE;
499 getMailButton->setEnabled(TRUE);
500 cancelButton->setEnabled(FALSE);
501 selectAccountMenu->setEnabled(TRUE);
502}
503
504void EmailClient::inboxItemSelected()
505{
506 item = (EmailListItem*) inboxView->selectedItem();
507 if (item != NULL) {
508 emit viewEmail(inboxView, item->getMail());
509 }
510}
511
512void EmailClient::outboxItemSelected()
513{
514 item = (EmailListItem*) outboxView->selectedItem();
515 if (item != NULL) {
516 emit viewEmail(outboxView, item->getMail());
517 }
518
519}
520
521void EmailClient::readMail()
522{
523 Email mail;
524 int start, stop;
525 QString s, del;
526
527 QFile f(getPath(FALSE) + "inbox.txt");
528// QFileInfo fi(f);
529 qDebug( f.name());
530
531 if ( f.open(IO_ReadOnly) ) { // file opened successfully
532 QTextStream t( &f ); // use a text stream
533 s = t.read();
534 f.close();
535
536 start = 0;
537 del = "\n.\n";
538 while ((uint) start < s.length()) {
539 stop = s.find(del, start);
540 if (stop == -1)
541 stop = s.length() - del.length();
542
543 mail.rawMail = s.mid(start, stop + del.length() - start );
544 start = stop + del.length();
545 mailArrived(mail, TRUE);
546 }
547 }
548
549 QFile fo(getPath(FALSE) + "outbox.txt");
550 if ( fo.open(IO_ReadOnly) ) { // file opened successfully
551 QTextStream t( &fo ); // use a text stream
552 s = t.read();
553 fo.close();
554
555 start = 0;
556 del = "\n.\n";
557 while ((uint) start < s.length()) {
558 stop = s.find(del, start);
559 if (stop == -1)
560 stop = s.length() - del.length();
561
562 mail.rawMail = s.mid(start, stop + del.length() - start );
563 start = stop + del.length();
564 emailHandler->parse(mail.rawMail, lineShift, &mail);
565 mail.sent = false;
566 mail.received = false;
567 enqueMail(mail);
568
569 }
570 }
571}
572
573void EmailClient::saveMail(QString fileName, QListView *view)
574{
575 QFile f(fileName);
576 Email *mail;
577
578 if (! f.open(IO_WriteOnly) ) {
579 qWarning("could not open file");
580 return;
581 }
582 item = (EmailListItem *) view->firstChild();
583 qDebug (QString("Write : ") );
584 QTextStream t(&f);
585 while (item != NULL) {
586 mail = item->getMail();
587 qDebug(mail->rawMail);
588 qDebug(mail->recipients.first());
589 t << mail->rawMail;
590
591 mailconf->setGroup(mail->id);
592 mailconf->writeEntry("mailread", mail->read);
593
594 item = (EmailListItem *) item->nextSibling();
595 }
596 f.close();
597}
598
599//paths for mailit, is settings, inbox, enclosures
600QString EmailClient::getPath(bool enclosurePath)
601{
602 QString basePath = "qtmail";
603 QString enclosures = "enclosures";
604
605 QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath);
606 if ( !dir.exists() )
607 dir.mkdir( dir.path() );
608
609 if (enclosurePath) {
610 dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures);
611
612 if ( !dir.exists() )
613 dir.mkdir( dir.path() );
614
615 return (dir.path() + "/");
616
617 }
618 return (dir.path() + "/");
619}
620
621void EmailClient::readSettings()
622{
623 TextParser *p;
624 QString s;
625 int pos, accountPos, y;
626 QFile f( getPath(FALSE) + "settings.txt");
627
628 if ( f.open(IO_ReadOnly) ) { // file opened successfully
629 QTextStream t( &f ); // use a text stream
630 s = t.read();
631 f.close();
632
633 p = new TextParser(s, "\n");
634
635 accountPos = 0;
636 while ( (accountPos = p->find("ACCOUNTSTART",';', accountPos, TRUE)) != -1 ) {
637 accountPos++;
638 if ( (pos = p->find("ACCOUNTNAME",':', accountPos, TRUE)) != -1 )
639 account.accountName = p->getString(& ++pos, 'z', TRUE);
640 if ( (pos = p->find("NAME",':', accountPos, TRUE)) != -1)
641 account.name = p->getString(& ++pos, 'z', TRUE);
642 if ( (pos = p->find("EMAIL",':', accountPos, TRUE)) != -1)
643 account.emailAddress = p->getString(& ++pos, 'z', TRUE);
644 if ( (pos = p->find("POPUSER",':', accountPos, TRUE)) != -1)
645 account.popUserName = p->getString(& ++pos, 'z', TRUE);
646 if ( (pos = p->find("POPPASSWORD",':', accountPos, TRUE)) != -1)
647 account.popPasswd = p->getString(& ++pos, 'z', TRUE);
648 if ( (pos = p->find("POPSERVER",':', accountPos, TRUE)) != -1)
649 account.popServer = p->getString(& ++pos, 'z', TRUE);
650 if ( (pos = p->find("SMTPSERVER",':', accountPos, TRUE)) != -1)
651 account.smtpServer = p->getString(& ++pos, 'z', TRUE);
652 if ( (pos = p->find("ACCOUNTID",':', accountPos, TRUE)) != -1) {
653 s = p->getString(& ++pos, 'z', TRUE);
654 account.id = s.toInt();
655 }
656
657 account.lastServerMailCount = 0;
658 account.synchronize = FALSE;
659 if ( (pos = p->find("SYNCHRONIZE",':', accountPos, TRUE)) != -1) {
660 if (p->getString(& ++pos, 'z', TRUE).upper() == "YES") {
661 account.synchronize = TRUE;
662 if ( (pos = p->find("LASTSERVERMAILCOUNT",':', accountPos, TRUE)) != -1) {
663 s = p->getString(& ++pos, 'z', TRUE);
664 account.lastServerMailCount = s.toInt();
665 }
666 }
667 }
668 accountList.append(&account);
669 }
670 delete p;
671 }
672 mailconf->setGroup("mailitglobal");
673 if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) {
674 mailIdCount = y;
675 }
676 if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) {
677 accountIdCount = y;
678 }
679}
680
681void EmailClient::saveSettings()
682{
683 QString temp;
684 QFile f( getPath(FALSE) + "settings.txt");
685 MailAccount *accountPtr;
686
687 if (! f.open(IO_WriteOnly) ) {
688 qWarning("could not save settings file");
689 return;
690 }
691 QTextStream t(&f);
692 t << "#Settings for QPE Mailit program\n";
693
694 for (accountPtr = accountList.first(); accountPtr != 0;
695 accountPtr = accountList.next()) {
696
697 t << "accountStart;\n";
698 t << "AccountName: " + accountPtr->accountName + "\n";
699 t << "Name: " + accountPtr->name + "\n";
700 t << "Email: " + accountPtr->emailAddress + "\n";
701 t << "POPUser: " + accountPtr->popUserName + "\n";
702 t << "POPPAssword: " + accountPtr->popPasswd + "\n";
703 t << "POPServer: " + accountPtr->popServer + "\n";
704 t << "SMTPServer: " + accountPtr->smtpServer + "\n";
705 t << "AccountId: " << accountPtr->id << "\n";
706 if (accountPtr->synchronize) {
707 t << "Synchronize: Yes\n";
708 t << "LastServerMailCount: ";
709 t << accountPtr->lastServerMailCount << "\n";
710 } else {
711 t << "Synchronize: No\n";
712 }
713 t << "accountEnd;\n";
714 }
715 f.close();
716
717 mailconf->setGroup("mailitglobal");
718 mailconf->writeEntry("mailidcount", mailIdCount);
719 mailconf->writeEntry("accountidcount", accountIdCount);
720}
721
722void EmailClient::selectAccount(int id)
723{
724 if (accountList.count() > 0) {
725 currentAccount = accountList.at(id);
726 emit newCaption("Mailit - " + currentAccount->accountName);
727 getNewMail();
728 } else {
729 emit newCaption("Mailit ! No account defined");
730 }
731}
732
733void EmailClient::editAccount(int id)
734{
735 MailAccount *newAccount;
736
737 editAccountView = new EditAccount(this, "account", TRUE);
738 if (id == newAccountId) { //new account
739 newAccount = new MailAccount;
740 editAccountView->setAccount(newAccount);
741 } else {
742 newAccount = accountList.at(id);
743 editAccountView->setAccount(newAccount, FALSE);
744 }
745
746 editAccountView->showMaximized();
747 editAccountView->exec();
748
749 if (editAccountView->result() == QDialog::Accepted) {
750 if (id == newAccountId) {
751 newAccount->id = accountIdCount;
752 accountIdCount++;
753 accountList.append(newAccount);
754 updateAccounts();
755 } else {
756 updateAccounts();
757 }
758 }
759
760 delete editAccountView;
761}
762
763void EmailClient::deleteAccount(int id)
764{
765 MailAccount *newAccount;
766 QString message;
767
768 newAccount = accountList.at(id);
769 message = "Delete account:\n" + newAccount->accountName;
770 switch( QMessageBox::warning( this, "Mailit", message,
771 "Yes", "No", 0, 0, 1 ) ) {
772
773 case 0: accountList.remove(id);
774 updateAccounts();
775 break;
776 case 1:
777 break;
778 }
779}
780
781void EmailClient::updateAccounts()
782{
783 MailAccount *accountPtr;
784
785 //rebuild menus, clear all first
786 editAccountMenu->clear();
787 selectAccountMenu->clear();
788 deleteAccountMenu->clear();
789
790 newAccountId = editAccountMenu->insertItem("New", this,
791 SLOT(editAccount(int)) );
792 editAccountMenu->insertSeparator();
793
794 idCount = 0;
795 for (accountPtr = accountList.first(); accountPtr != 0;
796 accountPtr = accountList.next()) {
797
798 editAccountMenu->insertItem(accountPtr->accountName,
799 this, SLOT(editAccount(int)), 0, idCount);
800 selectAccountMenu->insertItem(accountPtr->accountName,
801 this, SLOT(selectAccount(int)), 0, idCount);
802 deleteAccountMenu->insertItem(accountPtr->accountName,
803 this, SLOT(deleteAccount(int)), 0, idCount);
804 idCount++;
805 }
806}
807
808void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox)
809{
810 Email *mPtr;
811 Enclosure *ePtr;
812
813 if (inbox) {
814 mPtr = mailItem->getMail();
815
816 //if mail is in queue for download, remove it from
817 //queue if possible
818 if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) {
819 if ( !mPtr->downloaded )
820 mailDownloadList.remove(mPtr->serverId, mPtr->size);
821 }
822
823 mailconf->setGroup(mPtr->id);
824 mailconf->clearGroup();
825
826 //delete any temporary attatchemnts storing
827 for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) {
828 if (ePtr->saved) {
829 QFile::remove( (ePtr->path + ePtr->name) );
830 }
831 }
832 inboxView->takeItem(mailItem);
833 } else {
834 outboxView->takeItem(mailItem);
835 }
836}
837
838void EmailClient::setMailSize(int size)
839{
840 progressBar->reset();
841 progressBar->setTotalSteps(size);
842}
843
844void EmailClient::setTotalSize(int size)
845{
846
847}
848
849void EmailClient::setDownloadedSize(int size)
850{
851 int total = progressBar->totalSteps();
852
853 if (size < total) {
854 progressBar->setProgress(size);
855 } else {
856 progressBar->setProgress(total);
857 }
858}
diff --git a/noncore/unsupported/mailit/emailclient.h b/noncore/unsupported/mailit/emailclient.h
new file mode 100644
index 0000000..135bfaa
--- a/dev/null
+++ b/noncore/unsupported/mailit/emailclient.h
@@ -0,0 +1,149 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef EMAILCLIENT_H
21#define EMAILCLIENT_H
22
23#include <qlist.h>
24#include <qcstring.h>
25#include <qmainwindow.h>
26
27#include <qtoolbar.h>
28#include <qcheckbox.h>
29#include <qlabel.h>
30#include <qlineedit.h>
31#include <qlistview.h>
32#include <qtabwidget.h>
33#include <qaction.h>
34#include <qlayout.h>
35#include <qtooltip.h>
36#include <qimage.h>
37#include <qpixmap.h>
38#include <qstringlist.h>
39#include <qprogressbar.h>
40#include <qstatusbar.h>
41#include <qdir.h>
42#include <stdlib.h>
43
44#include "emailhandler.h"
45#include "emaillistitem.h"
46#include "textparser.h"
47#include "editaccount.h"
48#include "maillist.h"
49#include "addresslist.h"
50
51#include <qpe/config.h>
52
53class AccountList : public QList<MailAccount>
54{
55public:
56 Item newItem(Item d);
57private:
58 MailAccount* dupl(MailAccount *in);
59 MailAccount *ac;
60};
61
62//class EmailClient : public EmailClientBase
63class EmailClient : public QMainWindow
64{
65 Q_OBJECT
66
67public:
68 EmailClient( QWidget* parent, const char* name, WFlags fl = 0 );
69 ~EmailClient();
70 AddressList* getAdrListRef();
71
72signals:
73 void composeRequested();
74 void viewEmail(QListView *, Email *);
75 void mailUpdated(Email *);
76 void newCaption(const QString &);
77
78public slots:
79 void compose();
80 void cancel();
81 void enqueMail(const Email &mail);
82 void setMailAccount();
83 void sendQuedMail();
84 void mailSent();
85 void getNewMail();
86 void getAllNewMail();
87 void smtpError(int code);
88 void popError(int code);
89 void inboxItemSelected();
90 void outboxItemSelected();
91 void mailArrived(const Email &mail, bool fromDisk);
92 void allMailArrived(int);
93 void saveMail(QString fileName, QListView *view);
94 void selectAccount(int);
95 void editAccount(int);
96 void updateAccounts();
97 void deleteAccount(int);
98 void deleteMail(EmailListItem *mailItem, bool &inbox);
99 void setTotalSize(int);
100 void setMailSize(int);
101 void setDownloadedSize(int);
102 void moveMailFront(Email *mailPtr);
103
104private:
105 void init();
106 void readMail();
107 QString getPath(bool enclosurePath);
108 void readSettings();
109 void saveSettings();
110
111private:
112 Config *mailconf;
113 int newAccountId, idCount, mailIdCount;
114 int accountIdCount;
115 AccountList accountList;
116 AddressList *addressList;
117
118 EditAccount *editAccountView;
119 EmailListItem *item;
120 EmailHandler *emailHandler;
121 QList<Email> quedMessages;
122 MailList mailDownloadList;
123 bool sending, receiving, previewingMail, allAccounts;
124 QString lineShift;
125 MailAccount account, *currentAccount;
126
127 QToolBar *bar;
128 QProgressBar *progressBar;
129 QStatusBar *statusBar;
130 QLabel *status1Label, *status2Label;
131 QAction *getMailButton;
132 QAction *sendMailButton;
133 QAction *composeButton;
134 QAction *cancelButton;
135
136 QMenuBar *mb;
137 QPopupMenu *selectAccountMenu;
138 QPopupMenu *editAccountMenu;
139 QPopupMenu *deleteAccountMenu;
140
141 QTabWidget* mailboxView;
142 QListView* inboxView;
143 QListView* outboxView;
144
145 QGridLayout* grid_2;
146 QGridLayout* grid_3;
147};
148
149#endif // EMAILCLIENT_H
diff --git a/noncore/unsupported/mailit/emailhandler.cpp b/noncore/unsupported/mailit/emailhandler.cpp
new file mode 100644
index 0000000..a086dfc
--- a/dev/null
+++ b/noncore/unsupported/mailit/emailhandler.cpp
@@ -0,0 +1,589 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qfileinfo.h>
21#include <stdlib.h>
22#include <qapplication.h>
23#include <qmessagebox.h>
24#include <qcstring.h>
25#include "emailhandler.h"
26#include <qpe/applnk.h>
27#include <qpe/filemanager.h>
28
29QCollection::Item EnclosureList::newItem(QCollection::Item d)
30{
31 return dupl( (Enclosure *) d);
32}
33
34Enclosure* EnclosureList::dupl(Enclosure *in)
35{
36 ac = new Enclosure(*in);
37 return ac;
38}
39
40EmailHandler::EmailHandler()
41{
42 smtpClient = new SmtpClient();
43 popClient = new PopClient();
44
45 connect(smtpClient, SIGNAL(errorOccurred(int)), this,
46 SIGNAL(smtpError(int)) );
47 connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) );
48 connect(smtpClient, SIGNAL(updateStatus(const QString &)), this,
49 SIGNAL(updateSmtpStatus(const QString &)) );
50
51 connect(popClient, SIGNAL(errorOccurred(int)), this,
52 SIGNAL(popError(int)) );
53 connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)),
54 this, SLOT(messageArrived(const QString &, int, uint, bool)) );
55 connect(popClient, SIGNAL(updateStatus(const QString &)), this,
56 SIGNAL(updatePopStatus(const QString &)) );
57 connect(popClient, SIGNAL(mailTransfered(int)), this,
58 SIGNAL(mailTransfered(int)) );
59
60
61 //relaying size information
62 connect(popClient, SIGNAL(currentMailSize(int)),
63 this, SIGNAL(currentMailSize(int)) );
64 connect(popClient, SIGNAL(downloadedSize(int)),
65 this, SIGNAL(downloadedSize(int)) );
66}
67
68void EmailHandler::sendMail(QList<Email> *mailList)
69{
70 Email *currentMail;
71 QString temp;
72 QString userName = mailAccount.name;
73 userName += " <" + mailAccount.emailAddress + ">";
74
75 for (currentMail = mailList->first(); currentMail != 0;
76 currentMail = mailList->next()) {
77
78 if (encodeMime(currentMail) == 0) {
79 smtpClient->addMail(userName, currentMail->subject,
80 currentMail->recipients, currentMail->rawMail);
81 } else { //error
82 temp = tr("Could not locate all files in \nmail with subject: ") +
83 currentMail->subject;
84 temp += tr("\nMail has NOT been sent");
85 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n"));
86
87 }
88 }
89 smtpClient->newConnection(mailAccount.smtpServer, 25);
90}
91
92void EmailHandler::setAccount(MailAccount account)
93{
94 mailAccount = account;
95}
96
97void EmailHandler::getMail()
98{
99 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
100 if (mailAccount.synchronize) {
101 popClient->setSynchronize(mailAccount.lastServerMailCount);
102 } else {
103 popClient->removeSynchronize();
104 }
105
106 headers = FALSE;
107 popClient->headersOnly(headers, 0);
108 popClient->newConnection(mailAccount.popServer, 110);
109}
110
111void EmailHandler::getMailHeaders()
112{
113 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
114 if (mailAccount.synchronize) {
115 popClient->setSynchronize(mailAccount.lastServerMailCount);
116 } else {
117 popClient->removeSynchronize();
118 }
119
120 headers = TRUE;
121 popClient->headersOnly(headers, 2000); //less than 2000, download all
122 popClient->newConnection(mailAccount.popServer, 110);
123}
124
125void EmailHandler::getMailByList(MailList *mailList)
126{
127 if (mailList->count() == 0) { //should not occur though
128 emit mailTransfered(0);
129 return;
130 }
131
132 headers = FALSE;
133 popClient->headersOnly(FALSE, 0);
134 popClient->newConnection(mailAccount.popServer, 110);
135 popClient->setSelectedMails(mailList);
136}
137
138void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete)
139{
140 Email mail;
141
142 mail.rawMail = message;
143 mail.serverId = id;
144 mail.size = size;
145 mail.downloaded = complete;
146
147 emit mailArrived(mail, FALSE);
148}
149
150bool EmailHandler::parse(QString in, QString lineShift, Email *mail)
151{
152 QString temp, boundary;
153 int pos;
154 QString delimiter, header, body, mimeHeader, mimeBody;
155 QString content, contentType, contentAttribute, id, encoding;
156 QString fileName, storedName;
157 int enclosureId = 0;
158
159 mail->rawMail = in;
160 mail->received = TRUE;
161 mail->files.setAutoDelete(TRUE);
162
163 temp = lineShift + "." + lineShift;
164
165 if (in.right(temp.length()) != temp) {
166 qWarning(in.right(temp.length()));
167 qWarning(" . added at end of email as separator");
168 mail->rawMail += temp;
169 }
170
171
172 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n"
173 pos = in.find(delimiter, 0, FALSE);
174 header = in.left(pos);
175 body = in.right(in.length() - pos - delimiter.length());
176 if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n'))
177 body.truncate(body.length()-2);
178
179 TextParser p(header, lineShift);
180
181 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) {
182 pos++;
183 if (p.separatorAt(pos) == ' ') {
184 mail->from = p.getString(&pos, '<');
185 mail->from = mail->from.stripWhiteSpace();
186 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) {
187 mail->from = mail->from.left(mail->from.length() - 1);
188 mail->from = mail->from.right(mail->from.length() - 1);
189 }
190 pos++;
191 mail->fromMail = p.getString(&pos, '>');
192 } else {
193 if ((p.separatorAt(pos) == '<')
194 || (p.separatorAt(pos) == ' ')) //No name.. nasty
195 pos++;
196 pos++;
197 mail->fromMail = p.getString(&pos, 'z', TRUE);
198 if (mail->fromMail.at(mail->fromMail.length()-1) == '>')
199 mail->fromMail.truncate(mail->fromMail.length() - 1);
200 mail->from=mail->fromMail;
201 }
202 }
203 if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) {
204 pos++;
205 mail->subject = p.getString(&pos, 'z', TRUE);
206 }
207 if ((pos = p.find("DATE",':', 0, TRUE)) != -1) {
208 pos++;
209 mail->date = p.getString(&pos, 'z', true);
210 }
211 if ((pos = p.find("TO",':', 0, TRUE)) != -1) {
212 pos++;
213 mail->recipients.append (p.getString(&pos, 'z', TRUE) );
214 }
215 if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) {
216 pos++;
217 if ( (p.wordAt(pos).upper() == "ID") &&
218 (p.separatorAt(pos) == ':') ) {
219
220 id = p.getString(&pos, 'z', TRUE);
221 mail->id = id;
222 }
223 }
224
225 pos = 0;
226 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) {
227 pos++;
228 if ( (p.wordAt(pos).upper() == "VERSION") &&
229 (p.separatorAt(pos) == ':') ) {
230 pos++;
231 if (p.getString(&pos, 'z', true) == "1.0") {
232 mail->mimeType = 1;
233 }
234 }
235 }
236
237 if (mail->mimeType == 1) {
238 boundary = "";
239 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) {
240 pos++;
241 boundary = p.getString(&pos, 'z', true);
242 if (boundary[0] == '"') {
243 boundary = boundary.left(boundary.length() - 1); //strip "
244 boundary = boundary.right(boundary.length() - 1); //strip "
245 }
246 boundary = "--" + boundary; //create boundary field
247 }
248
249 if (boundary == "") { //fooled by Mime-Version
250 mail->body = body;
251 mail->bodyPlain = body;
252 return mail;
253 }
254
255 while (body.length() > 0) {
256 pos = body.find(boundary, 0, FALSE);
257 pos = body.find(delimiter, pos, FALSE);
258 mimeHeader = body.left(pos);
259 mimeBody = body.right(body.length() - pos - delimiter.length());
260 TextParser bp(mimeHeader, lineShift);
261
262 contentType = "";
263 contentAttribute = "";
264 fileName = "";
265 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) {
266 pos++;
267 if ( (bp.wordAt(pos).upper() == "TYPE") &&
268 (bp.separatorAt(pos) == ':') ) {
269 contentType = bp.nextWord().upper();
270 if (bp.nextSeparator() == '/')
271 contentAttribute = bp.nextWord().upper();
272 content = contentType + "/" + contentAttribute;
273 }
274 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) {
275 pos++;
276 encoding = bp.getString(&pos, 'z', TRUE);
277 }
278
279 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) {
280 pos++;
281 fileName = bp.getString(&pos, 'z', TRUE);
282 fileName = fileName.right(fileName.length() - 1);
283 fileName = fileName.left(fileName.length() - 1);
284 }
285
286 }
287 pos = mimeBody.find(boundary, 0, FALSE);
288 if (pos == -1) //should not occur, malformed mail
289 pos = mimeBody.length();
290 body = mimeBody.right(mimeBody.length() - pos);
291 mimeBody = mimeBody.left(pos);
292
293 if (fileName != "") { //attatchments of some type, audio, image etc.
294
295 Enclosure e;
296 e.id = enclosureId;
297 e.originalName = fileName;
298 e.contentType = contentType;
299 e.contentAttribute = contentAttribute;
300 e.encoding = encoding;
301 e.body = mimeBody;
302 e.saved = FALSE;
303 mail->addEnclosure(&e);
304 enclosureId++;
305
306 } else if (contentType == "TEXT") {
307 if (contentAttribute == "PLAIN") {
308 mail->body = mimeBody;
309 mail->bodyPlain = mimeBody;
310 }
311 if (contentAttribute == "HTML") {
312 mail->body = mimeBody;
313 }
314 }
315 }
316 } else {
317 mail->bodyPlain = body;
318 mail->body = body;
319 }
320 return TRUE;
321}
322
323bool EmailHandler::getEnclosure(Enclosure *ePtr)
324{
325 QFile f(ePtr->path + ePtr->name);
326 char src[4];
327 char *destPtr;
328 QByteArray buffer;
329 uint bufCount, pos, decodedCount, size, x;
330
331 if (! f.open(IO_WriteOnly) ) {
332 qWarning("could not save: " + ePtr->path + ePtr->name);
333 return FALSE;
334 }
335
336 if (ePtr->encoding.upper() == "BASE64") {
337 size = (ePtr->body.length() * 3 / 4); //approximate size (always above)
338 buffer.resize(size);
339 bufCount = 0;
340 pos = 0;
341 destPtr = buffer.data();
342
343 while (pos < ePtr->body.length()) {
344 decodedCount = 4;
345 x = 0;
346 while ( (x < 4) && (pos < ePtr->body.length()) ) {
347 src[x] = ePtr->body[pos].latin1();
348 pos++;
349 if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ')
350 x--;
351 x++;
352 }
353 if (x > 1) {
354 decodedCount = parse64base(src, destPtr);
355 destPtr += decodedCount;
356 bufCount += decodedCount;
357 }
358 }
359
360 buffer.resize(bufCount); //set correct length of file
361 f.writeBlock(buffer);
362 } else {
363 QTextStream t(&f);
364 t << ePtr->body;
365 }
366 return TRUE;
367}
368
369int EmailHandler::parse64base(char *src, char *bufOut) {
370
371 char c, z;
372 char li[4];
373 int processed;
374
375 //conversion table withouth table...
376 for (int x = 0; x < 4; x++) {
377 c = src[x];
378
379 if ( (int) c >= 'A' && (int) c <= 'Z')
380 li[x] = (int) c - (int) 'A';
381 if ( (int) c >= 'a' && (int) c <= 'z')
382 li[x] = (int) c - (int) 'a' + 26;
383 if ( (int) c >= '0' && (int) c <= '9')
384 li[x] = (int) c - (int) '0' + 52;
385 if (c == '+')
386 li[x] = 62;
387 if (c == '/')
388 li[x] = 63;
389 }
390
391 processed = 1;
392 bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits
393 bufOut[0] <<= 2;
394 z = li[1] >> 4;
395 bufOut[0] = bufOut[0] | z; //first byte retrived
396
397 if (src[2] != '=') {
398 bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits
399 bufOut[1] <<= 4;
400 z = li[2] >> 2;
401 bufOut[1] = bufOut[1] | z; //second byte retrived
402 processed++;
403
404 if (src[3] != '=') {
405 bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits
406 bufOut[2] <<= 6;
407 z = li[3];
408 bufOut[2] = bufOut[2] | z; //third byte retrieved
409 processed++;
410 }
411 }
412 return processed;
413}
414
415int EmailHandler::encodeMime(Email *mail) {
416 QString fileName, fileType, contentType, newBody, boundary;
417 Enclosure *ePtr;
418
419 QString userName = mailAccount.name;
420 userName += " <" + mailAccount.emailAddress + ">";
421
422 //add standard headers
423 newBody = "From: " + userName + "\r\nTo: ";
424 for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) {
425 newBody += *it + " ";
426 }
427 newBody += "\r\nSubject: " + mail->subject + "\r\n";
428
429 if (mail->files.count() == 0) { //just a simple mail
430 newBody += "\r\n" + mail->body;
431 mail->rawMail = newBody;
432 return 0;
433 }
434
435 //Build mime encoded mail
436 boundary = "-----4345=next_bound=0495----";
437
438 newBody += "Mime-Version: 1.0\r\n";
439 newBody += "Content-Type: multipart/mixed; boundary=\"" +
440 boundary + "\"\r\n\r\n";
441
442 newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n";
443 newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n";
444 newBody += mail->body;
445
446 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
447 fileName = ePtr->originalName;
448 fileType = ePtr->contentType;
449 QFileInfo fi(fileName);
450
451 // This specification of contentType is temporary
452 contentType = "";
453 if (fileType == "Picture") {
454 contentType = "image/x-image";
455 } else if (fileType == "Document") {
456 contentType = "text/plain";
457 } else if (fileType == "Sound") {
458 contentType = "audio/x-wav";
459 } else if (fileType == "Movie") {
460 contentType = "video/mpeg";
461 } else {
462 contentType = "application/octet-stream";
463 }
464
465 newBody += "\r\n\r\n--" + boundary + "\r\n";
466 newBody += "Content-Type: " + contentType + "; name=\"" +
467 fi.fileName() + "\"\r\n";
468 newBody += "Content-Transfer-Encoding: base64\r\n";
469 newBody += "Content-Disposition: inline; filename=\"" +
470 fi.fileName() + "\"\r\n\r\n";
471
472 if (encodeFile(fileName, &newBody) == -1) //file not found?
473 return -1;
474 }
475
476 newBody += "\r\n\r\n--" + boundary + "--";
477 mail->rawMail = newBody;
478
479 return 0;
480}
481
482int EmailHandler::encodeFile(QString fileName, QString *toBody)
483{
484 char *fileData;
485 char *dataPtr;
486 QString temp;
487 uint dataSize, count;
488 QFile f(fileName);
489
490 if (! f.open(IO_ReadOnly) ) {
491 qWarning("could not open file: " + fileName);
492 return -1;
493 }
494 QTextStream s(&f);
495 dataSize = f.size();
496 fileData = (char *) malloc(dataSize + 3);
497 s.readRawBytes(fileData, dataSize);
498
499 temp = "";
500 dataPtr = fileData;
501 count = 0;
502 while (dataSize > 0) {
503 if (dataSize < 3) {
504 encode64base(dataPtr, &temp, dataSize);
505 dataSize = 0;
506 } else {
507 encode64base(dataPtr, &temp, 3);
508 dataSize -= 3;
509 dataPtr += 3;
510 count += 4;
511 }
512 if (count > 72) {
513 count = 0;
514 temp += "\r\n";
515 }
516 }
517 toBody->append(temp);
518
519 delete(fileData);
520 f.close();
521 return 0;
522}
523
524void EmailHandler::encode64base(char *src, QString *dest, int len)
525{
526 QString temp;
527 uchar c;
528 uchar bufOut[4];
529
530 bufOut[0] = src[0];
531 bufOut[0] >>= 2; //Done byte 0
532
533 bufOut[1] = src[0];
534 bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits
535 bufOut[1] <<= 4; //copy up 4 places
536 if (len > 1) {
537 c = src[1];
538 } else {
539 c = 0;
540 }
541
542 c = c & (16 + 32 + 64 + 128);
543 c >>= 4;
544 bufOut[1] = bufOut[1] | c; //Done byte 1
545
546 bufOut[2] = src[1];
547 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8);
548 bufOut[2] <<= 2;
549 if (len > 2) {
550 c = src[2];
551 } else {
552 c = 0;
553 }
554 c >>= 6;
555 bufOut[2] = bufOut[2] | c;
556
557 bufOut[3] = src[2];
558 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32);
559
560 if (len == 1) {
561 bufOut[2] = 64;
562 bufOut[3] = 64;
563 }
564 if (len == 2) {
565 bufOut[3] = 64;
566 }
567 for (int x = 0; x < 4; x++) {
568 if (bufOut[x] <= 25)
569 bufOut[x] += (uint) 'A';
570 else if (bufOut[x] >= 26 && bufOut[x] <= 51)
571 bufOut[x] += (uint) 'a' - 26;
572 else if (bufOut[x] >= 52 && bufOut[x] <= 61)
573 bufOut[x] += (uint) '0' - 52;
574 else if (bufOut[x] == 62)
575 bufOut[x] = '+';
576 else if (bufOut[x] == 63)
577 bufOut[x] = '/';
578 else if (bufOut[x] == 64)
579 bufOut[x] = '=';
580
581 dest->append(bufOut[x]);
582 }
583}
584
585void EmailHandler::cancel()
586{
587 popClient->errorHandling(ErrCancel);
588 smtpClient->errorHandling(ErrCancel);
589}
diff --git a/noncore/unsupported/mailit/emailhandler.h b/noncore/unsupported/mailit/emailhandler.h
new file mode 100644
index 0000000..17c4414
--- a/dev/null
+++ b/noncore/unsupported/mailit/emailhandler.h
@@ -0,0 +1,147 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef EmailHandler_H
21#define EmailHandler_H
22
23#include <qobject.h>
24#include <qstring.h>
25#include <qdatetime.h>
26#include <qlist.h>
27#include <qstringlist.h>
28#include <qfile.h>
29#include <qstringlist.h>
30#include <qcollection.h>
31
32#include "smtpclient.h"
33#include "popclient.h"
34#include "textparser.h"
35#include "maillist.h"
36
37struct Enclosure
38{
39 int id;
40 QString originalName;
41 QString name;
42 QString path;
43 QString contentType;
44 QString contentAttribute;
45 QString encoding;
46 QString body; //might use to much mem. check!!
47 bool saved, installed;
48};
49
50class EnclosureList : public QList<Enclosure>
51{
52public:
53 Item newItem(Item d);
54private:
55 Enclosure* dupl(Enclosure *in);
56 Enclosure *ac;
57};
58
59struct Email
60{
61 QString id;
62 QString from;
63 QString fromMail;
64 QStringList recipients;
65 QStringList carbonCopies;
66 QString date;
67 QString subject;
68 QString body;
69 QString bodyPlain;
70 bool sent, received, read, downloaded;
71 QString rawMail;
72 int mimeType; //1 = Mime 1.0
73 int serverId;
74 int internalId;
75 int fromAccountId;
76 QString contentType; //0 = text
77 QString contentAttribute; //0 = plain, 1 = html
78 EnclosureList files;
79 uint size;
80
81 void addEnclosure(Enclosure *e)
82 {
83 files.append(e);
84 }
85};
86
87struct MailAccount
88{
89 QString accountName;
90 QString name;
91 QString emailAddress;
92 QString popUserName;
93 QString popPasswd;
94 QString popServer;
95 QString smtpServer;
96 bool synchronize;
97 int lastServerMailCount;
98 int id;
99};
100
101 const int ErrUnknownResponse = 1001;
102 const int ErrLoginFailed = 1002;
103 const int ErrCancel = 1003;
104
105
106class EmailHandler : public QObject
107{
108 Q_OBJECT
109
110public:
111 EmailHandler();
112 void setAccount(MailAccount account);
113 void sendMail(QList<Email> *mailList);
114 void getMail();
115 void getMailHeaders();
116 void getMailByList(MailList *mailList);
117 bool parse(QString in, QString lineShift, Email *mail);
118 bool getEnclosure(Enclosure *ePtr);
119 int parse64base(char *src, char *dest);
120 int encodeMime(Email *mail);
121 int encodeFile(QString fileName, QString *toBody);
122 void encode64base(char *src, QString *dest, int len);
123 void cancel();
124
125signals:
126 void mailSent();
127 void smtpError(int);
128 void popError(int);
129 void mailArrived(const Email &, bool);
130 void updatePopStatus(const QString &);
131 void updateSmtpStatus(const QString &);
132 void mailTransfered(int);
133 void mailboxSize(int);
134 void currentMailSize(int);
135 void downloadedSize(int);
136
137public slots:
138 void messageArrived(const QString &, int id, uint size, bool complete);
139
140private:
141 MailAccount mailAccount;
142 SmtpClient *smtpClient;
143 PopClient *popClient;
144 bool headers;
145};
146
147#endif
diff --git a/noncore/unsupported/mailit/emaillistitem.cpp b/noncore/unsupported/mailit/emaillistitem.cpp
new file mode 100644
index 0000000..d47b0b7
--- a/dev/null
+++ b/noncore/unsupported/mailit/emaillistitem.cpp
@@ -0,0 +1,92 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qstring.h>
21#include "emaillistitem.h"
22
23EmailListItem::EmailListItem(QListView *parent, Email mailIn, bool inbox)
24 : QListViewItem(parent)
25{
26 QString temp;
27
28 mail = mailIn;
29
30 if (inbox) {
31 setText(0, mail.from);
32 } else {
33 QStringList::Iterator it = mail.recipients.begin();
34 temp = *it;
35 if (mail.recipients.count() > 1)
36 temp += "...";
37 setText(0, temp);
38 }
39 setText(1, mail.subject);
40
41 selected = FALSE;
42}
43
44Email* EmailListItem::getMail()
45{
46 return &mail;
47}
48
49void EmailListItem::setMail(Email newMail)
50{
51 mail = newMail;
52 repaint();
53}
54
55void EmailListItem::setItemSelected(bool enable)
56{
57 selected = enable;
58 setSelected(enable);
59 repaint();
60}
61
62bool EmailListItem::isItemSelected()
63{
64 return selected;
65}
66
67void EmailListItem::paintCell( QPainter *p, const QColorGroup &cg,
68 int column, int width, int alignment )
69{
70
71 QColorGroup _cg( cg );
72 QColor c = _cg.text();
73
74 if ( (! mail.read) && (mail.received) )
75 _cg.setColor( QColorGroup::Text, Qt::blue);
76 if (!mail.downloaded)
77 _cg.setColor( QColorGroup::Text, Qt::red);
78
79 /*if (selected) {
80 _cg.setColor(QColorGroup::Base, Qt::blue);
81 _cg.setColor(QColorGroup::Text, Qt::yellow);
82 if (isSelected()) {
83 _cg.setColor(QColorGroup::HighlightedText, Qt::yellow);
84 } else {
85 _cg.setColor(QColorGroup::Highlight, Qt::blue);
86 }
87 }
88 */
89 QListViewItem::paintCell( p, _cg, column, width, alignment );
90
91 _cg.setColor( QColorGroup::Text, c );
92}
diff --git a/noncore/unsupported/mailit/emaillistitem.h b/noncore/unsupported/mailit/emaillistitem.h
new file mode 100644
index 0000000..642932c
--- a/dev/null
+++ b/noncore/unsupported/mailit/emaillistitem.h
@@ -0,0 +1,44 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef EMAILLISTITEM_H
21#define EMAILLISTITEM_H
22
23#include <qlistview.h>
24#include "emailhandler.h"
25
26class EmailListItem: public QListViewItem
27{
28public:
29 EmailListItem(QListView *parent, Email mailIn, bool inbox);
30 Email* getMail();
31 void setMail(Email newMail);
32 void setItemSelected(bool enable);
33 bool isItemSelected();
34 bool itemSelected();
35
36protected:
37 void paintCell( QPainter *p, const QColorGroup &cg,
38 int column, int width, int alignment );
39private:
40 Email mail;
41 bool selected;
42};
43
44#endif
diff --git a/noncore/unsupported/mailit/getmail.xpm b/noncore/unsupported/mailit/getmail.xpm
new file mode 100644
index 0000000..d294656
--- a/dev/null
+++ b/noncore/unsupported/mailit/getmail.xpm
@@ -0,0 +1,21 @@
1/* XPM */
2static char*getmail[]={
3"16 13 5 1",
4"# c #040404",
5"a c #c3c3c3",
6"c c #000000",
7". c None",
8"b c #ffffff",
9".........###....",
10"........#...#.#.",
11".............##.",
12"............###.",
13"................",
14"..............aa",
15".bbbbbbbbbbbbbba",
16".bbbcbbcbbbcccba",
17".bbcbccbbbbcbcba",
18".bbbbbbbbbbcccba",
19".bbcbcccbbbbbbba",
20".bbbcbbbbbbbbbba",
21".bbbbbbbbbbbbbba"};
diff --git a/noncore/unsupported/mailit/mailit.pro b/noncore/unsupported/mailit/mailit.pro
new file mode 100644
index 0000000..653f2e2
--- a/dev/null
+++ b/noncore/unsupported/mailit/mailit.pro
@@ -0,0 +1,44 @@
1TEMPLATE = app
2CONFIG = qt warn_on release
3HEADERS = emailclient.h \
4 emailhandler.h \
5 emaillistitem.h \
6 mailitwindow.h \
7 md5.h \
8 popclient.h \
9 readmail.h \
10 smtpclient.h \
11 writemail.h \
12 textparser.h \
13 viewatt.h \
14 addatt.h \
15 editaccount.h \
16 maillist.h \
17 addresslist.h
18SOURCES = emailclient.cpp \
19 emailhandler.cpp \
20 emaillistitem.cpp \
21 mailitwindow.cpp \
22 main.cpp \
23 md5.c \
24 popclient.cpp \
25 readmail.cpp \
26 smtpclient.cpp \
27 writemail.cpp \
28 textparser.cpp \
29 viewatt.cpp \
30 addatt.cpp \
31 editaccount.cpp \
32 maillist.cpp \
33 addresslist.cpp
34
35DESTDIR = ../bin
36INCLUDEPATH += $(QPEDIR)/include:../library
37DEPENDPATH += $(QPEDIR)/include:../library
38LIBS += -lqpe
39# -lssl
40MOC_DIR=qpeobj
41OBJECTS_DIR=qpeobj
42DESTDIR=$(OPIEDIR)/bin
43
44include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/unsupported/mailit/mailitwindow.cpp b/noncore/unsupported/mailit/mailitwindow.cpp
new file mode 100644
index 0000000..f9b6de2
--- a/dev/null
+++ b/noncore/unsupported/mailit/mailitwindow.cpp
@@ -0,0 +1,132 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "mailitwindow.h"
21
22MailItWindow::MailItWindow(QWidget *parent, const char *name, WFlags fl)
23 : QMainWindow(parent, name, fl)
24{
25 currentCaption = "Mailit";
26 setCaption(tr(currentCaption));
27 views = new QWidgetStack(this);
28 setCentralWidget(views);
29
30 emailClient = new EmailClient(views, "client");
31 writeMail = new WriteMail(views, "writing");
32 readMail = new ReadMail(views, "reading");
33
34 views->raiseWidget(emailClient);
35
36 connect(emailClient, SIGNAL(composeRequested()),
37 this, SLOT(compose()) );
38 connect(emailClient, SIGNAL(viewEmail(QListView *, Email *)), this,
39 SLOT(viewMail(QListView *, Email *)) );
40 connect(emailClient, SIGNAL(mailUpdated(Email *)), this,
41 SLOT(updateMailView(Email *)) );
42
43 connect(writeMail, SIGNAL(cancelMail()), this, SLOT(showEmailClient()) );
44 connect(writeMail, SIGNAL(sendMailRequested(const Email &)), this,
45 SLOT(showEmailClient()) );
46 connect(writeMail, SIGNAL(sendMailRequested(const Email &)), emailClient,
47 SLOT(enqueMail(const Email &)) );
48
49 connect(readMail, SIGNAL(cancelView()), this, SLOT(showEmailClient()) );
50 connect(readMail, SIGNAL(replyRequested(Email &)), this,
51 SLOT(composeReply(Email &)) );
52 connect(readMail, SIGNAL(removeItem(EmailListItem *, bool &)), emailClient,
53 SLOT(deleteMail(EmailListItem *, bool &)) );
54 connect(readMail, SIGNAL(viewingMail(Email *)), emailClient,
55 SLOT(moveMailFront(Email *)) );
56
57 connect(emailClient, SIGNAL(newCaption(const QString &)),
58 this, SLOT(updateCaption(const QString &)) );
59 viewingMail = FALSE;
60}
61
62MailItWindow::~MailItWindow()
63{
64}
65
66void MailItWindow::closeEvent(QCloseEvent *e)
67{
68 if (views->visibleWidget() == emailClient) {
69 e->accept();
70 } else {
71 showEmailClient();
72 }
73}
74
75void MailItWindow::compose()
76{
77 viewingMail = FALSE;
78 emailClient->hide();
79 readMail->hide();
80 views->raiseWidget(writeMail);
81 writeMail->setAddressList(emailClient->getAdrListRef());
82 setCaption( tr( "Write mail" ) );
83}
84
85void MailItWindow::composeReply(Email &mail)
86{
87 compose();
88 writeMail->reply(mail);
89}
90
91void MailItWindow::showEmailClient()
92{
93 viewingMail = FALSE;
94 writeMail->hide();
95 readMail->hide();
96 views->raiseWidget(emailClient);
97 setCaption( tr(currentCaption) );
98}
99
100void MailItWindow::viewMail(QListView *view, Email *mail)
101{
102 viewingMail = TRUE;
103 emailClient->hide();
104 readMail->update(view, mail);
105 views->raiseWidget(readMail);
106 setCaption( tr( "Examine mail" ) );
107}
108
109void MailItWindow::updateMailView(Email *mail)
110{
111 if (viewingMail) {
112 readMail->mailUpdated(mail);
113 }
114}
115
116void MailItWindow::updateCaption(const QString &newCaption)
117{
118 currentCaption = newCaption;
119 setCaption(tr(currentCaption));
120}
121
122void MailItWindow::setDocument(const QString &_address)
123{
124 // strip leading 'mailto:'
125 QString address = _address;
126 if (address.startsWith("mailto:"))
127 address = address.mid(6);
128
129 compose();
130 writeMail->setRecipient(address);
131}
132
diff --git a/noncore/unsupported/mailit/mailitwindow.h b/noncore/unsupported/mailit/mailitwindow.h
new file mode 100644
index 0000000..667960b
--- a/dev/null
+++ b/noncore/unsupported/mailit/mailitwindow.h
@@ -0,0 +1,58 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef MailItWindow_H
21#define MailItWindow_H
22
23#include <qmainwindow.h>
24#include <qwidgetstack.h>
25#include <qevent.h>
26//#include <qlayout.h>
27#include "emailclient.h"
28#include "writemail.h"
29#include "readmail.h"
30#include "addresslist.h"
31
32class MailItWindow: public QMainWindow
33{
34 Q_OBJECT
35public:
36 MailItWindow(QWidget *parent = 0, const char *name = 0, WFlags fl = 0);
37 ~MailItWindow();
38
39public slots:
40 void compose();
41 void composeReply(Email &);
42 void showEmailClient();
43 void viewMail(QListView *, Email *mail);
44 void updateMailView(Email *mail);
45 void closeEvent(QCloseEvent *e);
46 void updateCaption(const QString &);
47 void setDocument(const QString &);
48
49private:
50 EmailClient *emailClient;
51 WriteMail *writeMail;
52 ReadMail *readMail;
53 QWidgetStack *views;
54 QString currentCaption;
55 bool viewingMail;
56};
57
58#endif
diff --git a/noncore/unsupported/mailit/maillist.cpp b/noncore/unsupported/mailit/maillist.cpp
new file mode 100644
index 0000000..b5325a9
--- a/dev/null
+++ b/noncore/unsupported/mailit/maillist.cpp
@@ -0,0 +1,131 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "maillist.h"
21
22void MailList::clear()
23{
24 sortedList.setAutoDelete(TRUE);
25 sortedList.clear();
26 currentPos = 0;
27}
28
29int MailList::count()
30{
31 return sortedList.count();
32}
33
34int* MailList::first()
35{
36 dList *mPtr;
37
38 if (sortedList.count() == 0)
39 return NULL;
40
41 mPtr = sortedList.at(0);
42 currentPos = 1;
43 return &(mPtr->serverId);
44}
45
46int* MailList::next()
47{
48 dList *mPtr;
49
50 if ( (currentPos) >= sortedList.count())
51 return NULL;
52
53 mPtr = sortedList.at(currentPos);
54 currentPos++;
55 return &(mPtr->serverId);
56}
57
58void MailList::sizeInsert(int serverId, uint size)
59{
60 dList *tempPtr;
61 int x;
62
63 dList *newEntry = new dList;
64 newEntry->serverId = serverId;
65 newEntry->size = size;
66
67 for (tempPtr = sortedList.first(); tempPtr != NULL; tempPtr = sortedList.next() ) {
68 if (newEntry->size < tempPtr->size) {
69 x = sortedList.at();
70 sortedList.insert(x, newEntry);
71 return;
72 }
73 }
74 sortedList.append(newEntry);
75}
76
77void MailList::moveFront(int serverId, uint size)
78{
79 dList *currentPtr;
80 uint tempPos;
81 QString temp;
82
83 tempPos = currentPos;
84 if ( tempPos >= sortedList.count() )
85 return;
86 currentPtr = sortedList.at(tempPos);
87 while ( ((tempPos+1) < sortedList.count()) && ( currentPtr->serverId != serverId) ) {
88 tempPos++;
89 currentPtr = sortedList.at(tempPos);
90 }
91
92 if ( (currentPtr != NULL) && (currentPtr->serverId == serverId) ) {
93 temp.setNum(currentPtr->serverId);
94 qWarning("moved to front, message: " + temp);
95
96 dList *itemPtr = sortedList.take(tempPos);
97 sortedList.insert(currentPos, itemPtr);
98 }
99
100}
101
102//only works if mail is not already in download
103bool MailList::remove(int serverId, uint size)
104{
105 dList *currentPtr;
106 uint tempPos;
107 QString temp;
108
109 tempPos = currentPos;
110 if ( tempPos >=sortedList.count() )
111 return FALSE;
112 currentPtr = sortedList.at(tempPos);
113 while ( ((tempPos + 1) < sortedList.count()) && ( currentPtr->serverId != serverId) ) {
114 tempPos++;
115 currentPtr = sortedList.at(tempPos);
116 }
117
118 if ( (currentPtr != NULL) && (currentPtr->serverId == serverId) ) {
119 temp.setNum(currentPtr->serverId);
120 qWarning("deleted message: " + temp);
121 sortedList.remove(tempPos);
122
123 return TRUE;
124 }
125 return FALSE;
126}
127
128void MailList::insert(int pos, int serverId, uint size)
129{
130 //sortedList.insert(pos, mPtr);
131}
diff --git a/noncore/unsupported/mailit/maillist.h b/noncore/unsupported/mailit/maillist.h
new file mode 100644
index 0000000..ec996df
--- a/dev/null
+++ b/noncore/unsupported/mailit/maillist.h
@@ -0,0 +1,50 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef MAILLIST_H
21#define MAILLIST_H
22
23#include <qobject.h>
24#include <qlist.h>
25
26struct dList{
27 int serverId;
28 uint size;
29};
30
31class MailList : public QObject
32{
33 Q_OBJECT
34
35public:
36 void clear();
37 int count();
38 int* first();
39 int* next();
40 void sizeInsert(int serverId, uint size);
41 void moveFront(int serverId, uint size);
42 bool remove(int serverId, uint size);
43 void insert(int pos, int serverId, uint size);
44
45private:
46 QList<dList> sortedList;
47 uint currentPos;
48};
49
50#endif
diff --git a/noncore/unsupported/mailit/main.cpp b/noncore/unsupported/mailit/main.cpp
new file mode 100644
index 0000000..3a3e1fc
--- a/dev/null
+++ b/noncore/unsupported/mailit/main.cpp
@@ -0,0 +1,29 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qpe/qpeapplication.h>
21#include "mailitwindow.h"
22
23int main(int argc, char* argv[])
24{
25 QPEApplication a( argc, argv );
26 MailItWindow mw(0, 0);
27 a.showMainDocumentWidget(&mw);
28 return a.exec();
29}
diff --git a/noncore/unsupported/mailit/md5.c b/noncore/unsupported/mailit/md5.c
new file mode 100644
index 0000000..611f151
--- a/dev/null
+++ b/noncore/unsupported/mailit/md5.c
@@ -0,0 +1,251 @@
1/*
2 * This code implements the MD5 message-digest algorithm.
3 * The algorithm is due to Ron Rivest. This code was
4 * written by Colin Plumb in 1993, no copyright is claimed.
5 * This code is in the public domain; do with it what you wish.
6 *
7 * Equivalent code is available from RSA Data Security, Inc.
8 * This code has been tested against that, and is equivalent,
9 * except that you don't need to include two pages of legalese
10 * with every copy.
11 *
12 * To compute the message digest of a chunk of bytes, declare an
13 * MD5Context structure, pass it to MD5Init, call MD5Update as
14 * needed on buffers full of bytes, and then call MD5Final, which
15 * will fill a supplied 16-byte array with the digest.
16 *
17 * Changed so as no longer to depend on Colin Plumb's `usual.h' header
18 * definitions; now uses stuff from dpkg's config.h.
19 * - Ian Jackson <ijackson@nyx.cs.du.edu>.
20 * Still in the public domain.
21 *
22 * md5_buffer added by Steven Fuller
23 * Still in the public domain.
24 */
25
26 #include <string.h> /* for memcpy() */
27
28#include "md5.h"
29
30#ifdef WORDS_BIGENDIAN
31void
32byteSwap(UWORD32 *buf, unsigned words)
33{
34 md5byte *p = (md5byte *)buf;
35
36 do {
37 *buf++ = (UWORD32)((unsigned)p[3] << 8 | p[2]) << 16 |
38 ((unsigned)p[1] << 8 | p[0]);
39 p += 4;
40 } while (--words);
41}
42#else
43#define byteSwap(buf,words)
44#endif
45
46/* md5_buffer frontend added for AvP */
47void md5_buffer(char const *buffer, unsigned int len, char *digest)
48{
49 struct MD5Context md5c;
50
51 MD5Init(&md5c);
52 MD5Update(&md5c, (md5byte const *)buffer, len);
53 MD5Final((md5byte *)digest, &md5c);
54 }
55
56/*
57 * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
58 * initialization constants.
59 */
60void
61MD5Init(struct MD5Context *ctx)
62{
63 ctx->buf[0] = 0x67452301;
64 ctx->buf[1] = 0xefcdab89;
65 ctx->buf[2] = 0x98badcfe;
66 ctx->buf[3] = 0x10325476;
67
68 ctx->bytes[0] = 0;
69 ctx->bytes[1] = 0;
70}
71
72/*
73 * Update context to reflect the concatenation of another buffer full
74 * of bytes.
75 */
76void
77MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len)
78{
79 UWORD32 t;
80
81 /* Update byte count */
82
83 t = ctx->bytes[0];
84 if ((ctx->bytes[0] = t + len) < t)
85 ctx->bytes[1]++;/* Carry from low to high */
86
87 t = 64 - (t & 0x3f);/* Space available in ctx->in (at least 1) */
88 if (t > len) {
89 memcpy((md5byte *)ctx->in + 64 - t, buf, len);
90 return;
91 }
92 /* First chunk is an odd size */
93 memcpy((md5byte *)ctx->in + 64 - t, buf, t);
94 byteSwap(ctx->in, 16);
95 MD5Transform(ctx->buf, ctx->in);
96 buf += t;
97 len -= t;
98
99 /* Process data in 64-byte chunks */
100 while (len >= 64) {
101 memcpy(ctx->in, buf, 64);
102 byteSwap(ctx->in, 16);
103 MD5Transform(ctx->buf, ctx->in);
104 buf += 64;
105 len -= 64;
106 }
107
108 /* Handle any remaining bytes of data. */
109 memcpy(ctx->in, buf, len);
110}
111
112/*
113 * Final wrapup - pad to 64-byte boundary with the bit pattern
114 * 1 0* (64-bit count of bits processed, MSB-first)
115 */
116void
117MD5Final(md5byte digest[16], struct MD5Context *ctx)
118{
119 int count = ctx->bytes[0] & 0x3f;/* Number of bytes in ctx->in */
120 md5byte *p = (md5byte *)ctx->in + count;
121
122 /* Set the first char of padding to 0x80. There is always room. */
123 *p++ = 0x80;
124
125 /* Bytes of padding needed to make 56 bytes (-8..55) */
126 count = 56 - 1 - count;
127
128 if (count < 0) {/* Padding forces an extra block */
129 memset(p, 0, count + 8);
130 byteSwap(ctx->in, 16);
131 MD5Transform(ctx->buf, ctx->in);
132 p = (md5byte *)ctx->in;
133 count = 56;
134 }
135 memset(p, 0, count);
136 byteSwap(ctx->in, 14);
137
138 /* Append length in bits and transform */
139 ctx->in[14] = ctx->bytes[0] << 3;
140 ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
141 MD5Transform(ctx->buf, ctx->in);
142
143 byteSwap(ctx->buf, 4);
144 memcpy(digest, ctx->buf, 16);
145 memset(ctx, 0, sizeof(ctx));/* In case it's sensitive */
146}
147
148#ifndef ASM_MD5
149
150/* The four core functions - F1 is optimized somewhat */
151
152/* #define F1(x, y, z) (x & y | ~x & z) */
153#define F1(x, y, z) (z ^ (x & (y ^ z)))
154#define F2(x, y, z) F1(z, x, y)
155#define F3(x, y, z) (x ^ y ^ z)
156#define F4(x, y, z) (y ^ (x | ~z))
157
158/* This is the central step in the MD5 algorithm. */
159#define MD5STEP(f,w,x,y,z,in,s) \
160 (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
161
162/*
163 * The core of the MD5 algorithm, this alters an existing MD5 hash to
164 * reflect the addition of 16 longwords of new data. MD5Update blocks
165 * the data and converts bytes into longwords for this routine.
166 */
167void
168MD5Transform(UWORD32 buf[4], UWORD32 const in[16])
169{
170 register UWORD32 a, b, c, d;
171
172 a = buf[0];
173 b = buf[1];
174 c = buf[2];
175 d = buf[3];
176
177 MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
178 MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
179 MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
180 MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
181 MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
182 MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
183 MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
184 MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
185 MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
186 MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
187 MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
188 MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
189 MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
190 MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
191 MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
192 MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
193
194 MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
195 MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
196 MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
197 MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
198 MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
199 MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
200 MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
201 MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
202 MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
203 MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
204 MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
205 MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
206 MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
207 MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
208 MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
209 MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
210
211 MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
212 MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
213 MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
214 MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
215 MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
216 MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
217 MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
218 MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
219 MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
220 MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
221 MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
222 MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
223 MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
224 MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
225 MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
226 MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
227
228 MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
229 MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
230 MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
231 MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
232 MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
233 MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
234 MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
235 MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
236 MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
237 MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
238 MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
239 MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
240 MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
241 MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
242 MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
243 MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
244
245 buf[0] += a;
246 buf[1] += b;
247 buf[2] += c;
248 buf[3] += d;
249}
250
251#endif
diff --git a/noncore/unsupported/mailit/md5.h b/noncore/unsupported/mailit/md5.h
new file mode 100644
index 0000000..7e22494
--- a/dev/null
+++ b/noncore/unsupported/mailit/md5.h
@@ -0,0 +1,55 @@
1/*
2 * This is the header file for the MD5 message-digest algorithm.
3 * The algorithm is due to Ron Rivest. This code was
4 * written by Colin Plumb in 1993, no copyright is claimed.
5 * This code is in the public domain; do with it what you wish.
6 *
7 * Equivalent code is available from RSA Data Security, Inc.
8 * This code has been tested against that, and is equivalent,
9 * except that you don't need to include two pages of legalese
10 * with every copy.
11 *
12 * To compute the message digest of a chunk of bytes, declare an
13 * MD5Context structure, pass it to MD5Init, call MD5Update as
14 * needed on buffers full of bytes, and then call MD5Final, which
15 * will fill a supplied 16-byte array with the digest.
16 *
17 * Changed so as no longer to depend on Colin Plumb's `usual.h'
18 * header definitions; now uses stuff from dpkg's config.h
19 * - Ian Jackson <ijackson@nyx.cs.du.edu>.
20 * Still in the public domain.
21 *
22 * md5_buffer added by Steven Fuller
23 * Still in the public domain.
24 */
25
26#ifndef MD5_H
27#define MD5_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33typedef unsigned int UWORD32;
34
35#define md5byte unsigned char
36
37struct MD5Context {
38 UWORD32 buf[4];
39 UWORD32 bytes[2];
40 UWORD32 in[16];
41};
42
43void MD5Init(struct MD5Context *context);
44void MD5Update(struct MD5Context *context, md5byte const *buf, unsigned len);
45void MD5Final(unsigned char digest[16], struct MD5Context *context);
46void MD5Transform(UWORD32 buf[4], UWORD32 const in[16]);
47
48/* md5_buffer frontend added for AvP */
49void md5_buffer(char const *buffer, unsigned int len, char *digest);
50
51#ifdef __cplusplus
52};
53#endif
54
55#endif /* !MD5_H */
diff --git a/noncore/unsupported/mailit/opie-mailit.control b/noncore/unsupported/mailit/opie-mailit.control
new file mode 100644
index 0000000..db9c23d
--- a/dev/null
+++ b/noncore/unsupported/mailit/opie-mailit.control
@@ -0,0 +1,9 @@
1Files: bin/mailit apps/Applications/mailit.desktop pics/EMail.png
2Priority: optional
3Section: opie
4Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm
6Version: $OPIE_VERSION-$SUB_VERSION
7Depends: opie-base
8Description: EMail
9 A simple POP3 email client for the Qt Palmtop environment.
diff --git a/noncore/unsupported/mailit/popclient.cpp b/noncore/unsupported/mailit/popclient.cpp
new file mode 100644
index 0000000..a406af2
--- a/dev/null
+++ b/noncore/unsupported/mailit/popclient.cpp
@@ -0,0 +1,375 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "popclient.h"
21#include "emailhandler.h"
22//#define APOP_TEST
23
24extern "C" {
25#include "md5.h"
26}
27
28#include <qcstring.h>
29
30PopClient::PopClient()
31{
32 socket = new QSocket(this, "popClient");
33 connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int)));
34 connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished()));
35 connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData()));
36
37 stream = new QTextStream(socket);
38
39 receiving = FALSE;
40 synchronize = FALSE;
41 lastSync = 0;
42 headerLimit = 0;
43 preview = FALSE;
44}
45
46PopClient::~PopClient()
47{
48 delete socket;
49 delete stream;
50}
51
52void PopClient::newConnection(QString target, int port)
53{
54 if (receiving) {
55 qWarning("socket in use, connection refused");
56 return;
57 }
58
59 status = Init;
60
61 socket->connectToHost(target, port);
62 receiving = TRUE;
63 selected = FALSE;
64
65 emit updateStatus("DNS lookup");
66}
67
68void PopClient::setAccount(QString popUser, QString popPasswd)
69{
70 popUserName = popUser;
71 popPassword = popPasswd;
72}
73
74void PopClient::setSynchronize(int lastCount)
75{
76 synchronize = TRUE;
77 lastSync = lastCount;
78}
79
80void PopClient::removeSynchronize()
81{
82 synchronize = FALSE;
83 lastSync = 0;
84}
85
86void PopClient::headersOnly(bool headers, int limit)
87{
88 preview = headers;
89 headerLimit = limit;
90}
91
92void PopClient::setSelectedMails(MailList *list)
93{
94 selected = TRUE;
95 mailList = list;
96}
97
98void PopClient::connectionEstablished()
99{
100 emit updateStatus("Connection established");
101}
102
103void PopClient::errorHandling(int status)
104{
105 emit updateStatus("Error Occured");
106 emit errorOccurred(status);
107 socket->close();
108 receiving = FALSE;
109}
110
111void PopClient::incomingData()
112{
113 QString response, temp, temp2, timeStamp;
114 QString md5Source;
115 int start, end;
116// char *md5Digest;
117 char md5Digest[16];
118// if ( !socket->canReadLine() )
119// return;
120
121 response = socket->readLine();
122 qDebug(response +" %d", status);
123
124 switch(status) {
125 //logging in
126 case Init: {
127#ifdef APOP_TEST
128 start = response.find('<',0);
129 end = response.find('>', start);
130 if( start >= 0 && end > start )
131 {
132 timeStamp = response.mid( start , end - start + 1);
133 md5Source = timeStamp + popPassword;
134 qDebug( md5Source);
135// for( int i = 0; i < md5Source.length(); i++) {
136// buff[i] = (QChar)md5Source[i];
137// }
138
139 md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]);
140// md5_buffer(char const *buffer, unsigned int len, char *digest);
141
142// MD5_Init( &ctx);
143// MD5_Update( &ctx, buff, sizeof( buff) );
144// MD5_Final( md5Digest, &ctx);
145// MD5( buff, md5Source.length(), md5Digest);
146
147 for(int j =0;j < MD5_DIGEST_LENGTH ;j++)
148 {
149 printf("%x", md5Digest[j]);
150 }
151 printf("\n");
152// qDebug(md5Digest);
153 *stream << "APOP " << popUserName << " " << md5Digest << "\r\n";
154 // qDebug("%s", stream);
155 status = Stat;
156 }
157 else
158#endif
159 {
160 timeStamp = "";
161 *stream << "USER " << popUserName << "\r\n";
162 status = Pass;
163 }
164
165 break;
166 }
167 //password shhh. don't tell anyone (implement APOP...)
168 case Pass: {
169 *stream << "PASS " << popPassword << "\r\n";
170 status = Stat;
171 break;
172 }
173 //ask for number of messages
174 case Stat: {
175 if (response[0] == '+') {
176 *stream << "STAT" << "\r\n";
177 status = Mcnt;
178 } else errorHandling(ErrLoginFailed);
179 break;
180 }
181 //get count of messages, eg "+OK 4 900.." -> int 4
182 case Mcnt: {
183 if (response[0] == '+') {
184 temp = response.replace(0, 4, "");
185 int x = temp.find(" ", 0);
186 temp.truncate((uint) x);
187 newMessages = temp.toInt();
188 messageCount = 1;
189 status = List;
190
191 if (synchronize) {
192 //messages deleted from server, reload all
193 if (newMessages < lastSync)
194 lastSync = 0;
195 messageCount = lastSync + 1;
196 }
197
198 if (selected) {
199 int *ptr = mailList->first();
200 if (ptr != 0) {
201 newMessages++; //to ensure no early jumpout
202 messageCount = *(mailList->first());
203 } else newMessages = 0;
204 }
205 } else errorHandling(ErrUnknownResponse);
206 }
207 //Read message number x, count upwards to messageCount
208 case List: {
209 if (messageCount <= newMessages) {
210 *stream << "LIST " << messageCount << "\r\n";
211 status = Size;
212 temp2.setNum(newMessages - lastSync);
213 temp.setNum(messageCount - lastSync);
214 if (!selected) {
215 emit updateStatus("Retrieving " + temp + "/" + temp2);
216 } else {
217 //completing a previously closed transfer
218 if ( (messageCount - lastSync) <= 0) {
219 temp.setNum(messageCount);
220 emit updateStatus("Previous message " + temp);
221 } else {
222 emit updateStatus("Completing message " + temp);
223 }
224 }
225 break;
226 } else {
227 emit updateStatus("No new Messages");
228 status = Quit;
229 }
230 }
231 //get size of message, eg "500 characters in message.." -> int 500
232 case Size: {
233 if (status != Quit) { //because of idiotic switch
234 if (response[0] == '+') {
235 temp = response.replace(0, 4, "");
236 int x = temp.find(" ", 0);
237 temp = temp.right(temp.length() - ((uint) x + 1) );
238 mailSize = temp.toInt();
239 emit currentMailSize(mailSize);
240
241 status = Retr;
242 } else {
243 qWarning(response);
244 errorHandling(ErrUnknownResponse);
245 }
246 }
247 }
248 //Read message number x, count upwards to messageCount
249 case Retr: {
250 if (status != Quit) {
251 if (!preview || mailSize <= headerLimit) {
252 *stream << "RETR " << messageCount << "\r\n";
253 } else { //only header
254 *stream << "TOP " << messageCount << " 0\r\n";
255 }
256 messageCount++;
257 status = Ignore;
258 break;
259 } }
260 case Ignore: {
261 if (status != Quit) { //because of idiotic switch
262 if (response[0] == '+') {
263 message = "";
264 status = Read;
265 if (!socket->canReadLine()) //sync. problems
266 break;
267 response = socket->readLine();
268 } else errorHandling(ErrUnknownResponse);
269 }
270 }
271 //add all incoming lines to body. When size is reached, send
272 //message, and go back to read new message
273 case Read: {
274 if (status != Quit) { //because of idiotic switch
275 message += response;
276 while ( socket->canReadLine() ) {
277 response = socket->readLine();
278 message += response;
279 }
280 emit downloadedSize(message.length());
281 int x = message.find("\r\n.\r\n",-5);
282 if (x == -1) {
283 break;
284 } else { //message reach entire size
285 //complete mail downloaded
286 if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){
287 emit newMessage(message, messageCount-1, mailSize, TRUE);
288 } else { //incomplete mail downloaded
289 emit newMessage(message, messageCount-1, mailSize, FALSE);
290 }
291 if (messageCount > newMessages) //that was the last message
292 status = Quit;
293 else { //ask for new message
294 if (selected) { //grab next from queue
295 int *ptr = mailList->next();
296 if (ptr != 0) {
297 messageCount = *ptr;
298 *stream << "LIST " << messageCount << "\r\n";
299 status = Size;
300 //completing a previously closed transfer
301 if ( (messageCount - lastSync) <= 0) {
302 temp.setNum(messageCount);
303 emit updateStatus("Previous message " + temp);
304 } else {
305 temp.setNum(messageCount - lastSync);
306 emit updateStatus("Completing message " + temp);
307 }
308 break;
309 } else {
310 newMessages--;
311 status = Quit;
312 }
313 } else {
314 *stream << "LIST " << messageCount << "\r\n";
315 status = Size;
316 temp2.setNum(newMessages - lastSync);
317 temp.setNum(messageCount - lastSync);
318 emit updateStatus("Retrieving " + temp + "/" + temp2);
319
320 break;
321 }
322 }
323 }
324 if (status != Quit)
325 break;
326 }
327 }
328 case Quit: {
329 *stream << "Quit\r\n";
330 status = Done;
331 int newM = newMessages - lastSync;
332 if (newM > 0) {
333 temp.setNum(newM);
334 emit updateStatus(temp + " new messages");
335 } else {
336 emit updateStatus("No new messages");
337 }
338
339 socket->close();
340 receiving = FALSE;
341 emit mailTransfered(newM);
342 break;
343 }
344 }
345
346}
347
348// if( bAPOPAuthentication )
349// {
350// if( m_strTimeStamp.IsEmpty() )
351// {
352// SetLastError("Apop error!");
353// return false;
354// }
355// strMD5Source = m_strTimeStamp+pszPassword;
356// strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() );
357// sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst);
358// ret = send(m_sPop3Socket , msg , strlen(msg) , NULL);
359// if(ret == SOCKET_ERROR)
360// {
361// SetLastError("Socket error!");
362// m_bSocketOK = false;
363// m_bConnected = false;
364// return false;
365// }
366// if( !GetSocketResult(&strResult , COMMAND_END_FLAG) )
367// return false;
368// if( 0 == strResult.Find('-' , 0) )
369// {
370// SetLastError("Username or Password error!");
371// return false;
372// }
373// m_bConnected = true;
374
375// }
diff --git a/noncore/unsupported/mailit/popclient.h b/noncore/unsupported/mailit/popclient.h
new file mode 100644
index 0000000..10b71ab
--- a/dev/null
+++ b/noncore/unsupported/mailit/popclient.h
@@ -0,0 +1,76 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef PopClient_H
21#define PopClient_H
22
23#include <stdio.h>
24#include <qsocket.h>
25#include <qstring.h>
26#include <qobject.h>
27#include <qtextstream.h>
28#include <qlist.h>
29#include "maillist.h"
30
31class PopClient: public QObject
32{
33 Q_OBJECT
34
35public:
36 PopClient();
37 ~PopClient();
38 void newConnection(QString target, int port);
39 void setAccount(QString popUser, QString popPasswd);
40 void setSynchronize(int lastCount);
41 void removeSynchronize();
42 void headersOnly(bool headers, int limit);
43 void setSelectedMails(MailList *list);
44
45signals:
46 void newMessage(const QString &, int, uint, bool);
47 void errorOccurred(int status);
48 void updateStatus(const QString &);
49 void mailTransfered(int);
50 void mailboxSize(int);
51 void currentMailSize(int);
52 void downloadedSize(int);
53
54public slots:
55 void errorHandling(int);
56
57protected slots:
58 void connectionEstablished();
59 void incomingData();
60
61private:
62 QSocket *socket;
63 QTextStream *stream;
64 enum transferStatus
65 {
66 Init, Pass, Stat, Mcnt, Read, List, Size, Retr, Acks,
67 Quit, Done, Ignore
68 };
69 int status, lastSync;
70 int messageCount, newMessages, mailSize, headerLimit;
71 bool receiving, synchronize, preview, selected;
72 QString popUserName, popPassword, message;
73 MailList *mailList;
74};
75
76#endif
diff --git a/noncore/unsupported/mailit/readmail.cpp b/noncore/unsupported/mailit/readmail.cpp
new file mode 100644
index 0000000..4954f34
--- a/dev/null
+++ b/noncore/unsupported/mailit/readmail.cpp
@@ -0,0 +1,326 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "readmail.h"
21#include <qimage.h>
22#include <qmime.h>
23#include <qaction.h>
24#include "resource.h"
25
26ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl )
27 : QMainWindow(parent, name, fl)
28{
29 plainTxt = FALSE;
30
31 init();
32 viewAtt = new ViewAtt(0, "View Attatchments");
33}
34
35ReadMail::~ReadMail()
36{
37 delete emailView->mimeSourceFactory();
38 delete viewAtt;
39}
40
41void ReadMail::init()
42{
43 setToolBarsMovable(FALSE);
44
45 bar = new QToolBar(this);
46 bar->setHorizontalStretchable( TRUE );
47
48 menu = new QMenuBar( bar );
49
50 viewMenu = new QPopupMenu(menu);
51 menu->insertItem( tr( "&View" ), viewMenu);
52
53 mailMenu = new QPopupMenu(menu);
54 menu->insertItem( tr( "&Mail" ), mailMenu);
55
56 bar = new QToolBar(this);
57
58 //reply dependant on viewing inbox
59 replyButton = new QAction( tr( "Reply" ), Resource::loadPixmap( "pass" ),
60 QString::null, 0, this, 0 );
61 connect(replyButton, SIGNAL(activated()), this, SLOT(reply()) );
62
63 previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 );
64 connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) );
65 previousButton->addTo(bar);
66 previousButton->addTo(viewMenu);
67
68 nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 );
69 connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) );
70 nextButton->addTo(bar);
71 nextButton->addTo(viewMenu);
72
73 attatchmentsButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
74 connect( attatchmentsButton, SIGNAL( activated() ), this,
75 SLOT( viewAttatchments() ) );
76 attatchmentsButton->addTo(bar);
77 attatchmentsButton->addTo(viewMenu);
78
79 plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0, TRUE);
80 connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) );
81 plainTextButton->addTo(bar);
82 plainTextButton->addTo(viewMenu);
83
84 deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 );
85 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) );
86 deleteButton->addTo(bar);
87 deleteButton->addTo(mailMenu);
88
89 viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close()));
90
91 emailView = new QTextView( this, "emailView" );
92 setCentralWidget(emailView);
93
94 mime = new QMimeSourceFactory();
95 emailView->setMimeSourceFactory(mime);
96}
97
98void ReadMail::updateView()
99{
100 Enclosure *ePtr;
101 QString mailStringSize;
102 QString text, temp;
103
104 mail->read = TRUE; //mark as read
105 inbox = mail->received;
106
107 replyButton->removeFrom(mailMenu);
108 replyButton->removeFrom(bar);
109
110 if (inbox == TRUE) {
111 replyButton->addTo(bar);
112 replyButton->addTo(mailMenu);
113
114 if (!mail->downloaded) {
115 //report currently viewed mail so that it will be
116 //placed first in the queue of new mails to download
117 emit viewingMail(mail);
118
119 double mailSize = (double) mail->size;
120 if (mailSize < 1024) {
121 mailStringSize.setNum(mailSize);
122 mailStringSize += " Bytes";
123 } else if (mailSize < 1024*1024) {
124 mailStringSize.setNum( (mailSize / 1024), 'g', 2 );
125 mailStringSize += " Kb";
126 } else {
127 mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3);
128 mailStringSize += " Mb";
129 }
130 }
131 }
132
133 QMimeSourceFactory *mime = emailView->mimeSourceFactory();
134
135 if (! plainTxt) { //use RichText, inline pics etc.
136 emailView->setTextFormat(QTextView::RichText);
137 text = "<b><big><center><font color=\"blue\">" + mail->subject
138 +"</font></center></big></b><br>";
139 text += "<b>From: </b>" + mail->from + " <i>" +
140 mail->fromMail + "</i><br>";
141
142 text +="<b>To: </b>";
143 for (QStringList::Iterator it = mail->recipients.begin();
144 it != mail->recipients.end(); ++it ) {
145 text += *it + " ";
146 }
147 text += "<br>" + mail->date;
148
149 if (mail->files.count() > 0) {
150 text += "<br><b>Attatchments: </b>";
151
152 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
153 text += ePtr->originalName + " ";
154 }
155 text += "<hr><br>" + mail->body;
156
157 if (inbox) {
158 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
159
160 text += "<br><hr><b>Attatchment: </b>" +
161 ePtr->originalName + "<hr>";
162
163 if (ePtr->contentType == "TEXT") {
164 QFile f(ePtr->path + ePtr->name);
165
166 if (f.open(IO_ReadOnly) ) {
167 QTextStream t(&f);
168 temp = t.read();
169 text += temp + "<br>";
170 f.close();
171 } else {
172 text += "<b>Could not locate file</b><br>";
173 }
174
175 }
176 if (ePtr->contentType == "IMAGE") {
177 // temp.setNum(emailView->width());//get display width
178 // text += "<img width=" + temp +" src =""" +
179 // ePtr->originalName + """> </img>";
180 text += "<img src =""" +
181 ePtr->originalName + """> </img>";
182 mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) ));
183 }
184 }
185 }
186 } else {
187 if (mail->downloaded || !inbox) {
188 text += "<hr><br>" + mail->body;
189 } else {
190 text += "<hr><br><b> Awaiting download </b><br>";
191 text += "Size of mail: " + mailStringSize;
192 }
193 }
194 emailView->setText(text);
195 } else { // show plain txt mail
196 emailView->setTextFormat(QTextView::PlainText);
197 text = "Subject: " + mail->subject + "\n";
198 text += "From: " + mail->from + " " + mail->fromMail + "\n";
199 text += "To: ";
200 for (QStringList::Iterator it = mail->recipients.begin();
201 it != mail->recipients.end(); ++it ) {
202 text += *it + " ";
203 }
204 text += "\nDate: " + mail->date + "\n";
205 if (mail->files.count() > 0) {
206 text += "Attatchments: ";
207 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
208 text += ePtr->originalName + " ";
209 }
210 text += "\n\n";
211 } else text += "\n";
212
213 if (!inbox) {
214 text += mail->body;
215 } else if (mail->downloaded) {
216 text += mail->bodyPlain;
217 } else {
218 text += "\nAwaiting download\n";
219 text += "Size of mail: " + mailStringSize;
220 }
221
222 emailView->setText(text);
223 }
224
225 if (mail->files.count() == 0)
226 attatchmentsButton->setEnabled(FALSE);
227 else attatchmentsButton->setEnabled(TRUE);
228
229 setCaption("Examining mail: " + mail->subject);
230}
231
232//update view with current EmailListItem (item)
233void ReadMail::update(QListView *thisView, Email *mailIn)
234{
235 view = thisView;
236 item = (EmailListItem *) view->selectedItem();
237 mail = mailIn;
238 updateView();
239 updateButtons();
240}
241
242void ReadMail::mailUpdated(Email *mailIn)
243{
244 if (mailIn == mail) {
245 updateView();
246 } else {
247 updateButtons();
248 }
249}
250
251void ReadMail::close()
252{
253 emit cancelView();
254}
255
256//gets next item in listview, exits if there is no next
257void ReadMail::next()
258{
259 item = (EmailListItem *) item->nextSibling();
260 if (item != NULL) {
261 mail = item->getMail();
262 updateView();
263 }
264 updateButtons();
265}
266
267//gets previous item in listview, exits if there is no previous
268void ReadMail::previous()
269{
270 item = (EmailListItem *) item->itemAbove();
271 if (item != NULL) {
272 mail = item->getMail();
273 updateView();
274 }
275 updateButtons();
276}
277
278//deletes item, tries bringing up next or previous, exits if unsucessful
279void ReadMail::deleteItem()
280{
281 EmailListItem *temp = item;
282 temp = (EmailListItem *) item->nextSibling();//trybelow
283 if (temp == NULL)
284 temp = (EmailListItem *) item->itemAbove(); //try above
285
286 emit removeItem(item, inbox);
287
288 item = temp;
289 if (item != NULL) { //more items in list
290 mail = item->getMail();
291 updateView();
292 updateButtons();
293 } else close(); //no more items to see
294}
295
296void ReadMail::updateButtons()
297{
298 EmailListItem *temp;
299
300 temp = item;
301 if ((EmailListItem *) temp->nextSibling() == NULL)
302 nextButton->setEnabled(FALSE);
303 else nextButton->setEnabled(TRUE);
304
305 temp = item;
306 if ((EmailListItem *) temp->itemAbove() == NULL)
307 previousButton->setEnabled(FALSE);
308 else previousButton->setEnabled(TRUE);
309}
310
311void ReadMail::shiftText()
312{
313 plainTxt = ! plainTxt;
314 updateView();
315}
316
317void ReadMail::viewAttatchments()
318{
319 viewAtt->update(mail, inbox);
320 viewAtt->showMaximized();
321}
322
323void ReadMail::reply()
324{
325 emit replyRequested(*mail);
326}
diff --git a/noncore/unsupported/mailit/readmail.h b/noncore/unsupported/mailit/readmail.h
new file mode 100644
index 0000000..d0bb067
--- a/dev/null
+++ b/noncore/unsupported/mailit/readmail.h
@@ -0,0 +1,86 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef READMAIL_H
21#define READMAIL_H
22
23#include <qaction.h>
24#include <qmainwindow.h>
25#include <qmenubar.h>
26#include <qpopupmenu.h>
27#include <qlabel.h>
28#include <qlistview.h>
29#include <qlayout.h>
30#include <qtextview.h>
31
32#include "emailhandler.h"
33#include "emaillistitem.h"
34#include "viewatt.h"
35
36class ReadMail : public QMainWindow
37{
38 Q_OBJECT
39
40public:
41 ReadMail( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
42 ~ReadMail();
43 void update(QListView *thisView, Email *mailIn);
44 void updateView();
45 void mailUpdated(Email *mailIn);
46
47signals:
48 void cancelView();
49 void replyRequested(Email &);
50 void removeItem(EmailListItem *, bool &);
51 void viewingMail(Email *);
52
53public slots:
54 void close();
55 void next();
56 void previous();
57 void deleteItem();
58 void shiftText();
59 void viewAttatchments();
60 void reply();
61
62private:
63 void init();
64 void updateButtons();
65
66private:
67 QListView *view;
68 EmailListItem *item;
69 bool plainTxt, inbox;
70 Email *mail;
71 ViewAtt *viewAtt;
72
73 QToolBar *bar;
74 QMenuBar *menu;
75 QPopupMenu *viewMenu, *mailMenu;
76 QAction *deleteButton;
77 QMimeSourceFactory *mime;
78 QAction *plainTextButton;
79 QAction *nextButton;
80 QTextView *emailView;
81 QAction *attatchmentsButton;
82 QAction *previousButton;
83 QAction *replyButton;
84};
85
86#endif // READMAIL_H
diff --git a/noncore/unsupported/mailit/resource.cpp b/noncore/unsupported/mailit/resource.cpp
new file mode 100644
index 0000000..dc19880
--- a/dev/null
+++ b/noncore/unsupported/mailit/resource.cpp
@@ -0,0 +1,136 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "qpeapplication.h"
22#include "resource.h"
23#include <qdir.h>
24#include <qfile.h>
25#include <qregexp.h>
26#include <qpixmapcache.h>
27#include <qpainter.h>
28
29#include "inlinepics_p.h"
30
31/*!
32 \class Resource resource.h
33 \brief The Resource class provides access to named resources.
34
35 The resources may be provided from files or other sources.
36*/
37
38/*!
39 \fn Resource::Resource()
40 \internal
41*/
42
43/*!
44 Returns the QPixmap named \a pix. You should avoid including
45 any filename type extension (eg. .png, .xpm).
46*/
47QPixmap Resource::loadPixmap( const QString &pix )
48{
49 QPixmap pm;
50 QString key="QPE_"+pix;
51 if ( !QPixmapCache::find(key,pm) ) {
52 pm.convertFromImage(loadImage(pix));
53 QPixmapCache::insert(key,pm);
54 }
55 return pm;
56}
57
58/*!
59 Returns the QBitmap named \a pix. You should avoid including
60 any filename type extension (eg. .png, .xpm).
61*/
62QBitmap Resource::loadBitmap( const QString &pix )
63{
64 QBitmap bm;
65 bm = loadPixmap(pix);
66 return bm;
67}
68
69/*!
70 Returns the filename of a pixmap named \a pix. You should avoid including
71 any filename type extension (eg. .png, .xpm).
72
73 Normally you will use loadPixmap() rather than this function.
74*/
75QString Resource::findPixmap( const QString &pix )
76{
77 QString picsPath = QPEApplication::qpeDir() + "pics/";
78
79 if ( QFile( picsPath + pix + ".png").exists() )
80 return picsPath + pix + ".png";
81 else if ( QFile( picsPath + pix + ".xpm").exists() )
82 return picsPath + pix + ".xpm";
83 else if ( QFile( picsPath + pix ).exists() )
84 return picsPath + pix;
85
86 //qDebug("Cannot find pixmap: %s", pix.latin1());
87 return QString();
88}
89
90/*!
91 Returns a sound file for a sound named \a name.
92 You should avoid including any filename type extension (eg. .wav, .au, .mp3).
93*/
94QString Resource::findSound( const QString &name )
95{
96 QString picsPath = QPEApplication::qpeDir() + "sounds/";
97
98 QString result;
99 if ( QFile( (result = picsPath + name + ".wav") ).exists() )
100 return result;
101
102 return QString();
103}
104
105/*!
106 Returns a list of all sound names.
107*/
108QStringList Resource::allSounds()
109{
110 QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" );
111 QStringList entries = resourcedir.entryList();
112 QStringList result;
113 for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i)
114 result.append((*i).replace(QRegExp("\\.wav"),""));
115 return result;
116}
117
118/*!
119 Returns the QImage named \a name. You should avoid including
120 any filename type extension (eg. .png, .xpm).
121*/
122QImage Resource::loadImage( const QString &name)
123{
124 QImage img = qembed_findImage(name.latin1());
125 if ( img.isNull() )
126 return QImage(findPixmap(name));
127 return img;
128}
129
130/*!
131 \fn QIconSet Resource::loadIconSet( const QString &name )
132
133 Returns a QIconSet for the pixmap named \a name. A disabled icon is
134 generated that conforms to the Qtopia look & feel. You should avoid
135 including any filename type extension (eg. .png, .xpm).
136*/
diff --git a/noncore/unsupported/mailit/resource.h b/noncore/unsupported/mailit/resource.h
new file mode 100644
index 0000000..982c58a
--- a/dev/null
+++ b/noncore/unsupported/mailit/resource.h
@@ -0,0 +1,80 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef PIXMAPLOADER_H
21#define PIXMAPLOADER_H
22
23#include <qimage.h>
24#include <qbitmap.h>
25#include <qiconset.h>
26#include <qstringlist.h>
27
28class Resource
29{
30public:
31 Resource() {}
32
33 static QImage loadImage( const QString &name);
34
35 static QPixmap loadPixmap( const QString &name );
36 static QBitmap loadBitmap( const QString &name );
37 static QString findPixmap( const QString &name );
38
39 static QIconSet loadIconSet( const QString &name );
40
41 static QString findSound( const QString &name );
42 static QStringList allSounds();
43};
44
45// Inline for compatibility with SHARP ROMs
46inline QIconSet Resource::loadIconSet( const QString &pix )
47{
48 QImage img = loadImage( pix );
49 QPixmap pm;
50 pm.convertFromImage( img );
51 QIconSet is( pm );
52 QIconSet::Size size = pm.width() <= 22 ? QIconSet::Small : QIconSet::Large;
53
54 QPixmap dpm = loadPixmap( pix + "_disabled" );
55
56 #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps
57 if ( dpm.isNull() ) {
58 QImage dimg( img.width(), img.height(), 32 );
59 for ( int y = 0; y < img.height(); y++ ) {
60 for ( int x = 0; x < img.width(); x++ ) {
61 QRgb p = img.pixel( x, y );
62 uint a = (p & 0xff000000) / 3;
63 p = (p & 0x00ffffff) | (a & 0xff000000);
64 dimg.setPixel( x, y, p );
65 }
66 }
67
68 dimg.setAlphaBuffer( TRUE );
69 dpm.convertFromImage( dimg );
70 }
71#endif
72
73 if ( !dpm.isNull() )
74 is.setPixmap( dpm, size, QIconSet::Disabled );
75
76 return is;
77}
78
79
80#endif
diff --git a/noncore/unsupported/mailit/sendmail.xpm b/noncore/unsupported/mailit/sendmail.xpm
new file mode 100644
index 0000000..2803793
--- a/dev/null
+++ b/noncore/unsupported/mailit/sendmail.xpm
@@ -0,0 +1,20 @@
1/* XPM */
2static char*sendmail[]={
3"16 13 4 1",
4"a c #c3c3c3",
5"# c #000000",
6". c None",
7"b c #ffffff",
8".....#####aaa...",
9"....####aaaaa.a.",
10"....#.###...aaa.",
11"....#..###..aaa.",
12".......###......",
13"..............aa",
14".bbbbbbbbbbbbbba",
15".bbb#bb#bbb###ba",
16".bb#b##bbbb#b#ba",
17".bbbbbbbbbb###ba",
18".bb#b###bbbbbbba",
19".bbb#bbbbbbbbbba",
20".bbbbbbbbbbbbbba"};
diff --git a/noncore/unsupported/mailit/smtpclient.cpp b/noncore/unsupported/mailit/smtpclient.cpp
new file mode 100644
index 0000000..7bb7933
--- a/dev/null
+++ b/noncore/unsupported/mailit/smtpclient.cpp
@@ -0,0 +1,163 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "smtpclient.h"
21#include "emailhandler.h"
22
23SmtpClient::SmtpClient()
24{
25 socket = new QSocket(this, "smtpClient");
26 stream = new QTextStream(socket);
27 mailList.setAutoDelete(TRUE);
28
29 connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int)));
30 connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished()));
31 connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData()));
32
33 sending = FALSE;
34}
35
36SmtpClient::~SmtpClient()
37{
38 delete socket;
39 delete stream;
40}
41
42void SmtpClient::newConnection(QString target, int port)
43{
44 if (sending) {
45 qWarning("socket in use, connection refused");
46 return;
47 }
48
49 status = Init;
50 sending = TRUE;
51 socket->connectToHost(target, port);
52
53 emit updateStatus("DNS lookup");
54}
55
56void SmtpClient::addMail(QString from, QString subject, QStringList to, QString body)
57{
58 RawEmail *mail = new RawEmail;
59
60 mail->from = from;
61 mail->subject = subject;
62 mail->to = to;
63 mail->body = body;
64
65 mailList.append(mail);
66}
67
68void SmtpClient::connectionEstablished()
69{
70 emit updateStatus("Connection established");
71
72}
73
74void SmtpClient::errorHandling(int status)
75{
76 emit errorOccurred(status);
77 socket->close();
78 mailList.clear();
79 sending = FALSE;
80}
81
82void SmtpClient::incomingData()
83{
84 QString response;
85
86 if (!socket->canReadLine())
87 return;
88
89 response = socket->readLine();
90
91 switch(status) {
92 case Init: {
93 if (response[0] == '2') {
94 status = From;
95 mailPtr = mailList.first();
96 *stream << "HELO there\r\n";
97 } else errorHandling(ErrUnknownResponse);
98 break;
99 }
100 case From: {
101 if (response[0] == '2') {
102 *stream << "MAIL FROM: <" << mailPtr->from << ">\r\n";
103 status = Recv;
104 } else errorHandling(ErrUnknownResponse);
105 break;
106 }
107 case Recv: {
108 if (response[0] == '2') {
109 it = mailPtr->to.begin();
110 if (it == NULL)
111 errorHandling(ErrUnknownResponse);
112 *stream << "RCPT TO: <" << *it << ">\r\n";
113 status = MRcv;
114 } else errorHandling(ErrUnknownResponse);
115 break;
116 }
117 case MRcv: {
118 if (response[0] == '2') {
119 it++;
120 if ( it != mailPtr->to.end() ) {
121 *stream << "RCPT TO: <" << *it << ">\r\n";
122 break;
123 } else {
124 status = Data;
125 }
126 } else errorHandling(ErrUnknownResponse);
127 }
128 case Data: {
129 if (response[0] == '2') {
130 *stream << "DATA\r\n";
131 status = Body;
132 emit updateStatus("Sending: " + mailPtr->subject);
133 } else errorHandling(ErrUnknownResponse);
134 break;
135 }
136 case Body: {
137 if (response[0] == '3') {
138 *stream << mailPtr->body << "\r\n.\r\n";
139 mailPtr = mailList.next();
140 if (mailPtr != NULL) {
141 status = From;
142 } else {
143 status = Quit;
144 }
145 } else errorHandling(ErrUnknownResponse);
146 break;
147 }
148 case Quit: {
149 if (response[0] == '2') {
150 *stream << "QUIT\r\n";
151 status = Done;
152 QString temp;
153 temp.setNum(mailList.count());
154 emit updateStatus("Sent " + temp + " messages");
155 emit mailSent();
156 mailList.clear();
157 sending = FALSE;
158 socket->close();
159 } else errorHandling(ErrUnknownResponse);
160 break;
161 }
162 }
163}
diff --git a/noncore/unsupported/mailit/smtpclient.h b/noncore/unsupported/mailit/smtpclient.h
new file mode 100644
index 0000000..ca65af4
--- a/dev/null
+++ b/noncore/unsupported/mailit/smtpclient.h
@@ -0,0 +1,75 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef SmtpClient_H
21#define SmtpClient_H
22
23//#include <stdio.h>
24#include <qsocket.h>
25#include <qstring.h>
26#include <qobject.h>
27#include <qtextstream.h>
28#include <qstringlist.h>
29#include <qlist.h>
30
31struct RawEmail
32{
33 QString from;
34 QString subject;
35 QStringList to;
36 QString body;
37};
38
39class SmtpClient: public QObject
40{
41 Q_OBJECT
42
43public:
44 SmtpClient();
45 ~SmtpClient();
46 void newConnection(QString target, int port);
47 void addMail(QString from, QString subject, QStringList to, QString body);
48
49signals:
50 void errorOccurred(int);
51 void updateStatus(const QString &);
52 void mailSent();
53
54public slots:
55 void errorHandling(int);
56
57protected slots:
58 void connectionEstablished();
59 void incomingData();
60
61private:
62 QSocket *socket;
63 QTextStream *stream;
64 enum transferStatus
65 {
66 Init, From, Recv, MRcv, Data, Body, Quit, Done
67 };
68 int status;
69 QList<RawEmail> mailList;
70 RawEmail *mailPtr;
71 bool sending;
72 QStringList::Iterator it;
73};
74
75#endif
diff --git a/noncore/unsupported/mailit/textparser.cpp b/noncore/unsupported/mailit/textparser.cpp
new file mode 100644
index 0000000..f082417
--- a/dev/null
+++ b/noncore/unsupported/mailit/textparser.cpp
@@ -0,0 +1,294 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "textparser.h"
21
22TextParser::TextParser(QString in, QString lineBreak)
23{
24 data = in;
25 lineSep = lineBreak;
26
27 init();
28 createSeparators();
29 split();
30}
31
32TextParser::TextParser(QString in, QString lineBreak, QString sep)
33{
34 data = in;
35 lineSep = lineBreak;
36
37 init();
38 separators = sep;
39 split();
40}
41
42void TextParser::init()
43{
44 lineCount = 0;
45 linePos = 0;
46 totalElmCount = 0;
47 separatorPos = -1; //not initialized
48 wordPos = -1; //not initialized
49 sepAtLine = 0;
50 sepAtPosElm = -1; //such that nextSep equals 0
51 wordAtLine = 0;
52 wordAtPosElm = -1; //such that nextWord equals 0
53 atLine = 0;
54 atPosElm = 0;
55}
56
57void TextParser::createSeparators()
58{
59 separators = " @#,.:;<>*/(){}|'?-+=_";
60}
61
62 /*Returns pos of given search criteria, -1 if not found */
63int TextParser::find(QString target, QChar sep, int pos, bool upperCase)
64{
65 int atLine = 0, atPosElm = 0;
66
67 for (int x = 0; x < totalElmCount; x++) {
68 if (x >= pos) {
69 if (upperCase) {
70 if ((splitDone[atLine].elm[atPosElm].str.upper() == target) &&
71 (splitDone[atLine].elm[atPosElm].separator == sep))
72 return x;
73 } else {
74 if ((splitDone[atLine].elm[atPosElm].str == target) &&
75 (splitDone[atLine].elm[atPosElm].separator == sep))
76 return x;
77 }
78 }
79 atPosElm++;
80 if (atPosElm >= splitDone[atLine].elmCount) { //new Line
81 atLine++;
82 atPosElm = 0;
83 }
84 }
85
86 return -1;
87}
88
89int TextParser::elmCount()
90{
91 return totalElmCount;
92}
93
94QChar TextParser::separatorAt(int pos)
95{
96 if (getLineReference(pos, &sepAtLine, &sepAtPosElm) == -1)
97 return QChar::null;
98
99 separatorPos = pos;
100 return splitDone[sepAtLine].elm[sepAtPosElm].separator;
101}
102
103QChar TextParser::nextSeparator()
104{
105 sepAtPosElm++;
106 if (splitDone[sepAtLine].elmCount <= sepAtPosElm) {
107 sepAtLine++;
108 sepAtPosElm = 0;
109 }
110
111 separatorPos++;
112 return splitDone[sepAtLine].elm[sepAtPosElm].separator;
113}
114
115bool TextParser::hasNextSeparator()
116{
117 return ((separatorPos+1) < totalElmCount);
118}
119
120QString TextParser::wordAt(int pos)
121{
122 if (getLineReference(pos, &wordAtLine, &wordAtPosElm) == -1)
123 return NULL;
124
125 wordPos = pos;
126 return splitDone[wordAtLine].elm[wordAtPosElm].str;
127}
128
129QString TextParser::nextWord()
130{
131 wordAtPosElm++;
132 if (splitDone[wordAtLine].elmCount <= wordAtPosElm) {
133 wordAtLine++;
134 wordAtPosElm = 0;
135 }
136
137 wordPos++;
138 return splitDone[wordAtLine].elm[wordAtPosElm].str;
139}
140
141bool TextParser::hasNextWord()
142{
143 return ((wordPos + 1) < totalElmCount);
144}
145
146QString TextParser::getString(int *pos, QChar stop, bool lineEnd = false)
147{
148 QString returnStr = wordAt(*pos);
149 QChar chr = separatorAt(*pos);
150 QString s;
151
152 if (returnStr == "")
153 return "";
154 if (chr == stop)
155 return returnStr;
156
157 if (!lineEnd) {
158 while ((chr != stop) && hasNextWord()) {
159 returnStr.append(chr);
160 returnStr += nextWord();
161 chr = nextSeparator();
162 }
163 } else { //copy from pos to end of line
164 getLineReference(*pos, &atLine, &atPosElm);
165 returnStr = "";
166 while (atPosElm < splitDone[atLine].elmCount) {
167 if (splitDone[atLine].elm[atPosElm].str != "") {
168 returnStr += splitDone[atLine].elm[atPosElm].str;
169 }
170 chr = splitDone[atLine].elm[atPosElm].separator;
171 if (!chr.isNull() && (int) chr != 0) {
172 returnStr.append(splitDone[atLine].elm[atPosElm].separator);
173 }
174 atPosElm++;
175 }
176 }
177
178 *pos = wordPos;
179 return returnStr;
180}
181
182QString TextParser::getNextLine()
183{
184 atLine++;
185 atPosElm = 0;
186 if (atLine < lineCount)
187 return splitDone[atLine].str;
188 return "";
189}
190
191bool TextParser::hasNextLine()
192{
193 if (atLine+1 < lineCount)
194 return TRUE;;
195 return FALSE;
196}
197
198int TextParser::endLinePos(int pos)
199{
200 if ( (getLineReference(pos, &atLine, &atPosElm)) == -1)
201 return -1;
202
203 return (pos + (splitDone[atLine].elmCount - atPosElm) + 1);
204}
205
206int TextParser::getLineReference(int pos, int *line, int *inLinePos)
207{
208 int currentPos = 0;
209
210 for (int x = 0; x < lineCount; x++) {
211 if ( currentPos + splitDone[x].elmCount > pos) {
212 *line = x;
213 *inLinePos = pos - currentPos;
214 return 0; //pos found okay
215 }
216 currentPos += splitDone[x].elmCount;
217 }
218 return -1; //no reference found
219}
220
221void TextParser::split()
222{
223 t_splitLine newLine;
224
225 while ((uint) linePos < data.length()) {
226 newLine = nextLine();
227 splitDone[lineCount] = splitLine(newLine);
228 totalElmCount += splitDone[lineCount].elmCount;
229 lineCount++;
230 }
231}
232
233t_splitLine TextParser::splitLine(t_splitLine line)
234{
235 uint pos = 0;
236 uint elmCount = 0;
237 t_splitLine tempLine = line;
238
239 tempLine.str = line.str.simplifyWhiteSpace();
240 tempLine.elm[0].str = "";
241 while ( pos < line.str.length() ) {
242 if ( isSeparator(tempLine.str[pos]) ) {
243 tempLine.elm[elmCount].separator = tempLine.str[pos];
244 elmCount++;
245 pos++;
246 while (tempLine.str[pos] == ' ')
247 pos++;
248 if (pos > line.str.length())
249 elmCount--;
250 tempLine.elm[elmCount].str = "";
251 } else {
252 if (!tempLine.str[pos].isNull())
253 tempLine.elm[elmCount].str += tempLine.str[pos];
254 pos++;
255 }
256 }
257
258 tempLine.elmCount = elmCount + 1;
259 return tempLine;
260}
261
262bool TextParser::isSeparator(QChar chr)
263{
264 for (uint x = 0; x < separators.length(); x++) {
265 if (chr == separators[x])
266 return true;
267 }
268 return false;
269}
270
271t_splitLine TextParser::nextLine()
272{
273 int newLinePos;
274 t_splitLine lineType;
275
276 newLinePos = data.find(lineSep, linePos);
277
278 lineType.lineType = NewLine;
279 lineType.str = "";
280
281 if (newLinePos == -1) {
282 newLinePos = data.length();
283 lineType.lineType = LastLine;
284 }
285
286 for (int x = linePos; x < newLinePos; x++)
287 lineType.str += data[x];
288
289 linePos = newLinePos;
290 if ((uint) linePos < data.length()) //if not EOF, add length of lineSep
291 linePos += lineSep.length();
292
293 return lineType;
294}
diff --git a/noncore/unsupported/mailit/textparser.h b/noncore/unsupported/mailit/textparser.h
new file mode 100644
index 0000000..016effb
--- a/dev/null
+++ b/noncore/unsupported/mailit/textparser.h
@@ -0,0 +1,85 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qobject.h>
21#include <qstring.h>
22
23#ifndef TEXTPARSER_H
24#define TEXTPARSER_H
25
26enum t_strType { Word, Number};
27enum t_lineType {NewLine, LastLine};
28
29 const uint MAX_ELEMENTS = 200; //Should be dynamic
30 const uint MAX_LINES = 500; //Should be dynamic
31
32struct t_splitElm
33{
34 QChar separator;
35 int strType;
36 QString str;
37};
38
39struct t_splitLine
40{
41 t_lineType lineType;
42 QString str; //a bit redundant...
43 t_splitElm elm[MAX_ELEMENTS];
44 int elmCount;
45};
46
47class TextParser: public QObject
48{
49 Q_OBJECT
50
51public:
52 TextParser(QString in, QString lineBreak);
53 TextParser(QString in, QString lineBreak, QString sep);
54 int find(QString target, QChar sep, int pos, bool upperCase);
55 int elmCount();
56 QChar separatorAt(int pos);
57 QChar nextSeparator();
58 bool hasNextSeparator();
59 QString wordAt(int pos);
60 QString nextWord();
61 bool hasNextWord();
62 QString getString(int *pos, QChar stop, bool lineEnd = false);
63 QString getNextLine();
64 bool hasNextLine();
65 int endLinePos(int pos);
66
67private:
68 void init();
69 void createSeparators();
70 t_splitLine nextLine();
71 void split();
72 t_splitLine splitLine(t_splitLine line);
73 bool isSeparator(QChar chr);
74 t_splitLine splitDone[MAX_LINES];
75 int getLineReference(int pos, int *line, int *inLinePos);
76
77 int lineCount, linePos, totalElmCount;
78 int separatorPos, wordPos;
79 QString data, separators, lineSep;
80 int sepAtLine, sepAtPosElm;
81 int wordAtLine, wordAtPosElm;
82 int atLine, atPosElm;
83};
84
85#endif
diff --git a/noncore/unsupported/mailit/viewatt.cpp b/noncore/unsupported/mailit/viewatt.cpp
new file mode 100644
index 0000000..86f119f
--- a/dev/null
+++ b/noncore/unsupported/mailit/viewatt.cpp
@@ -0,0 +1,109 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "resource.h"
21#include "viewatt.h"
22#include <qpe/applnk.h>
23
24ViewAtt::ViewAtt(QWidget *parent, const char *name, WFlags f)
25 : QMainWindow(parent, name, f)
26{
27 setCaption("Exploring attatchments");
28
29 setToolBarsMovable( FALSE );
30 bar = new QToolBar(this);
31 installButton = new QAction( tr( "Install" ), Resource::loadPixmap( "exec" ), QString::null, CTRL + Key_C, this, 0 );
32 connect(installButton, SIGNAL(activated()), this, SLOT(install()) );
33
34 listView = new QListView(this, "AttView");
35 listView->addColumn( "Attatchment" );
36 listView->addColumn( "Type" );
37 listView->addColumn( "Installed" );
38 setCentralWidget(listView);
39}
40
41void ViewAtt::update(Email *mailIn, bool inbox)
42{
43 QListViewItem *item;
44 Enclosure *ePtr;
45
46 listView->clear();
47 if (inbox) {
48 bar->clear();
49 installButton->addTo( bar );
50 bar->show();
51 } else {
52 bar->hide();
53 }
54
55 mail = mailIn;
56 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
57
58 QString isInstalled = "No";
59 if (ePtr->installed)
60 isInstalled = "Yes";
61 item = new QListViewItem(listView, ePtr->originalName, ePtr->contentType, isInstalled);
62
63 if (ePtr->contentType == "TEXT") {
64 actions = new QAction( tr("View"), Resource::loadPixmap("TextEditor"), QString::null, CTRL + Key_C, this, 0);
65 actions->addTo(bar);
66 item->setPixmap(0, Resource::loadPixmap("txt"));
67 }
68 if (ePtr->contentType == "AUDIO") {
69 actions = new QAction( tr("Play"), Resource::loadPixmap("SoundPlayer"), QString::null, CTRL + Key_C, this, 0);
70 actions->addTo(bar);
71 item->setPixmap(0, Resource::loadPixmap("play"));
72 }
73 if (ePtr->contentType == "IMAGE") {
74 actions = new QAction( tr("Show"), Resource::loadPixmap("pixmap"), QString::null, CTRL + Key_C, this, 0);
75 actions->addTo(bar);
76 item->setPixmap(0, Resource::loadPixmap("pixmap"));
77 }
78 }
79}
80
81void ViewAtt::install()
82{
83 Enclosure *ePtr, *selPtr;
84 QListViewItem *item;
85 QString filename;
86 DocLnk d;
87
88 item = listView->selectedItem();
89 if (item != NULL) {
90 filename = item->text(0);
91 selPtr = NULL;
92 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
93 if (ePtr->originalName == filename)
94 selPtr = ePtr;
95 }
96
97 if (selPtr == NULL) {
98 qWarning("Internal error, file is not installed to documents");
99 return;
100 }
101
102 d.setName(selPtr->originalName);
103 d.setFile(selPtr->path + selPtr->name);
104 d.setType(selPtr->contentType + "/" + selPtr->contentAttribute);
105 d.writeLink();
106 selPtr->installed = TRUE;
107 item->setText(2, "Yes");
108 }
109}
diff --git a/noncore/unsupported/mailit/viewatt.h b/noncore/unsupported/mailit/viewatt.h
new file mode 100644
index 0000000..9e43407
--- a/dev/null
+++ b/noncore/unsupported/mailit/viewatt.h
@@ -0,0 +1,46 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef VIEWATT_H
21#define VIEWATT_H
22
23#include <qmainwindow.h>
24#include <qtoolbar.h>
25#include <qaction.h>
26#include <qlistview.h>
27#include "emailhandler.h"
28
29class ViewAtt : public QMainWindow
30{
31 Q_OBJECT
32
33public:
34 ViewAtt(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
35 void update(Email *mailIn, bool inbox);
36
37public slots:
38 void install();
39
40private:
41 QListView *listView;
42 QToolBar *bar;
43 QAction *installButton, *actions;
44 Email *mail;
45};
46#endif
diff --git a/noncore/unsupported/mailit/writemail.cpp b/noncore/unsupported/mailit/writemail.cpp
new file mode 100644
index 0000000..1a7185e
--- a/dev/null
+++ b/noncore/unsupported/mailit/writemail.cpp
@@ -0,0 +1,299 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qmessagebox.h>
21#include "writemail.h"
22#include "resource.h"
23
24WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl )
25 : QMainWindow( parent, name, fl )
26{
27 showingAddressList = FALSE;
28 init();
29
30 addAtt = new AddAtt(0, "Add Attatchments");
31}
32
33WriteMail::~WriteMail()
34{
35 delete addAtt;
36}
37
38void WriteMail::setAddressList(AddressList *list)
39{
40 Contact *cPtr;
41
42 addressList = list;
43
44 addressView->clear();
45 QList<Contact> *cListPtr = addressList->getContactList();
46 QListViewItem *item;
47 for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) {
48 item = new QListViewItem(addressView, cPtr->email, cPtr->name);
49 }
50}
51
52void WriteMail::init()
53{
54 setToolBarsMovable(FALSE);
55
56 bar = new QToolBar(this);
57 bar->setHorizontalStretchable( TRUE );
58
59 menu = new QMenuBar( bar );
60
61 mailMenu = new QPopupMenu(menu);
62 menu->insertItem( tr( "&Mail" ), mailMenu);
63 addMenu = new QPopupMenu(menu);
64 menu->insertItem( tr( "&Add" ), addMenu);
65
66 bar = new QToolBar(this);
67 attatchButton = new QAction(tr("Attatchment"), Resource::loadPixmap("fileopen"), QString::null, 0, this, 0);
68 attatchButton->addTo(bar);
69 attatchButton->addTo(addMenu);
70 connect( attatchButton, SIGNAL( activated() ), this, SLOT( attatchFile() ) );
71
72 confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0);
73 confirmButton->addTo(bar);
74 confirmButton->addTo(mailMenu);
75 connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) );
76
77 newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0);
78 newButton->addTo(mailMenu);
79 connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) );
80
81 widget = new QWidget(this, "widget");
82 grid = new QGridLayout( widget );
83
84 recipientsBox = new QComboBox( FALSE, widget, "toLabel" );
85 recipientsBox->insertItem( tr( "To:" ) );
86 recipientsBox->insertItem( tr( "CC:" ) );
87 recipientsBox->setCurrentItem(0);
88 grid->addWidget( recipientsBox, 0, 0 );
89
90 subjetLabel = new QLabel( widget, "subjetLabel" );
91 subjetLabel->setText( tr( "Subject:" ) );
92
93 grid->addWidget( subjetLabel, 1, 0 );
94
95 ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" );
96 ToolButton13_2->setText( tr( "..." ) );
97 grid->addWidget( ToolButton13_2, 1, 2 );
98
99 subjectInput = new QLineEdit( widget, "subjectInput" );
100 grid->addWidget( subjectInput, 1, 1 );
101
102 toInput = new QLineEdit( widget, "toInput" );
103 grid->addWidget( toInput, 0, 1 );
104
105 addressButton = new QToolButton( widget, "addressButton" );
106 addressButton->setPixmap( Resource::loadPixmap("AddressBook") );
107 addressButton->setToggleButton(TRUE);
108 grid->addWidget( addressButton, 0, 2 );
109 connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) );
110
111 emailInput = new QMultiLineEdit( widget, "emailInput" );
112 grid->addMultiCellWidget( emailInput, 2, 2, 0, 2);
113
114 addressView = new QListView( widget, "addressView");
115 addressView->addColumn("Email");
116 addressView->addColumn("Name");
117 addressView->setAllColumnsShowFocus(TRUE);
118 addressView->setMultiSelection(TRUE);
119 addressView->hide();
120 grid->addMultiCellWidget( addressView, 3, 3, 0, 2);
121
122 okButton = new QToolButton(bar, "ok");
123 okButton->setPixmap( Resource::loadPixmap("enter") );
124 okButton->hide();
125 connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) );
126
127 setCentralWidget(widget);
128}
129
130void WriteMail::reject()
131{
132 emit cancelMail();
133}
134
135// need to insert date
136void WriteMail::accept()
137{
138 QStringList attatchedFiles, attatchmentsType;
139 int idCount = 0;
140
141 if (toInput->text() == "") {
142 QMessageBox::warning(this,"No recipient", "Send mail to whom?", "OK\n");
143 return;
144 }
145 if (! getRecipients() ) {
146 QMessageBox::warning(this,"Incorrect recipient separator",
147 "Recipients must be separated by ;\nand be valid emailaddresses", "OK\n");
148 return;
149 }
150 mail.subject = subjectInput->text();
151 mail.body = emailInput->text();
152 mail.sent = false;
153 mail.received = false;
154 mail.rawMail = "To: ";
155
156 for (QStringList::Iterator it = mail.recipients.begin();
157 it != mail.recipients.end(); ++it) {
158
159 mail.rawMail += (*it);
160 mail.rawMail += ",\n";
161 }
162 mail.rawMail.truncate(mail.rawMail.length()-2);
163 mail.rawMail += mail.from;
164 mail.rawMail += "\nSubject: ";
165 mail.rawMail += mail.subject;
166 mail.rawMail += "\n\n";
167
168 attatchedFiles = addAtt->returnAttatchedFiles();
169 attatchmentsType = addAtt->returnFileTypes();
170
171 QStringList::Iterator itType = attatchmentsType.begin();
172
173 Enclosure e;
174 for ( QStringList::Iterator it = attatchedFiles.begin();
175 it != attatchedFiles.end(); ++it ) {
176
177 e.id = idCount;
178 e.originalName = (*it).latin1();
179 e.contentType = (*itType).latin1();
180 e.contentAttribute = (*itType).latin1();
181 e.saved = TRUE;
182 mail.addEnclosure(&e);
183
184 itType++;
185 idCount++;
186 }
187 mail.rawMail += mail.body;
188 mail.rawMail += "\n";
189 mail.rawMail += ".\n";
190 emit sendMailRequested(mail);
191 addAtt->clear();
192}
193
194void WriteMail::getAddress()
195{
196 showingAddressList = !showingAddressList;
197
198 if (showingAddressList) {
199 emailInput->hide();
200 addressView->show();
201 okButton->show();
202
203 } else {
204 addressView->hide();
205 okButton->hide();
206 emailInput->show();
207 }
208}
209
210void WriteMail::attatchFile()
211{
212 addAtt->showMaximized();
213}
214
215void WriteMail::reply(Email replyMail)
216{
217 int pos;
218
219 mail = replyMail;
220 mail.files.clear();
221
222 toInput->setText(mail.fromMail);
223 subjectInput->setText("Re: " + mail.subject);
224
225 pos = 0;
226 mail.body.insert(pos, ">>");
227 while (pos != -1) {
228 pos = mail.body.find('\n', pos);
229 if (pos != -1)
230 mail.body.insert(++pos, ">>");
231 }
232
233 emailInput->setText(mail.body);
234}
235
236bool WriteMail::getRecipients()
237{
238 QString str, temp;
239 int pos = 0;
240
241 mail.recipients.clear();
242
243 temp = toInput->text();
244 while ( (pos = temp.find(';')) != -1) {
245 str = temp.left(pos).stripWhiteSpace();
246 temp = temp.right(temp.length() - (pos + 1));
247 if ( str.find('@') == -1)
248 return false;
249 mail.recipients.append(str);
250 addressList->addContact(str, "");
251 }
252 temp = temp.stripWhiteSpace();
253 if ( temp.find('@') == -1)
254 return false;
255 mail.recipients.append(temp);
256 addressList->addContact(temp, "");
257
258 return TRUE;
259}
260
261
262void WriteMail::addRecipients()
263{
264 QString recipients = "";
265
266 mail.recipients.clear();
267 QListViewItem *item = addressView->firstChild();
268 while (item != NULL) {
269 if ( item->isSelected() ) {
270 if (recipients == "") {
271 recipients = item->text(0);
272 } else {
273 recipients += "; " + item->text(0);
274 }
275 }
276 item = item->nextSibling();
277 }
278 toInput->setText(recipients);
279
280 addressView->hide();
281 okButton->hide();
282 emailInput->show();
283 addressButton->setOn(FALSE);
284 showingAddressList = !showingAddressList;
285}
286
287void WriteMail::setRecipient(const QString &recipient)
288{
289 toInput->setText(recipient);
290}
291
292void WriteMail::newMail()
293{
294 toInput->clear();
295 subjectInput->clear();
296 emailInput->clear();
297 //to clear selected
298 setAddressList(addressList);
299}
diff --git a/noncore/unsupported/mailit/writemail.h b/noncore/unsupported/mailit/writemail.h
new file mode 100644
index 0000000..dd12063
--- a/dev/null
+++ b/noncore/unsupported/mailit/writemail.h
@@ -0,0 +1,91 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef WRITEMAIL_H
21#define WRITEMAIL_H
22
23#include <qmainwindow.h>
24#include <qaction.h>
25#include <qlabel.h>
26#include <qtoolbar.h>
27#include <qtoolbutton.h>
28#include <qmenubar.h>
29#include <qlayout.h>
30#include <qlineedit.h>
31#include <qmultilineedit.h>
32#include <qlistview.h>
33#include <qcombobox.h>
34
35#include "emailhandler.h"
36#include "addresslist.h"
37#include "addatt.h"
38
39class WriteMail : public QMainWindow
40{
41 Q_OBJECT
42
43public:
44 WriteMail( QWidget* parent, const char* name, WFlags fl = 0 );
45 ~WriteMail();
46 void reply(Email replyMail);
47 void setRecipient(const QString &recipient);
48 void setAddressList(AddressList *list);
49
50signals:
51 void sendMailRequested(const Email &mail);
52 void cancelMail();
53
54public slots:
55 void getAddress();
56 void attatchFile();
57 void addRecipients();
58 void newMail();
59 void accept();
60 void reject();
61
62private:
63 bool getRecipients();
64 void init();
65
66 Email mail;
67 AddAtt *addAtt;
68 AddressList *addressList;
69 bool showingAddressList;
70
71 QToolBar *bar;
72 QMenuBar *menu;
73 QPopupMenu *addMenu, *mailMenu;
74 QListView *addressView;
75
76 QToolButton *okButton;
77 QWidget *widget;
78 QAction *attatchButton;
79 QAction *confirmButton;
80 QAction *newButton;
81 QLabel* subjetLabel;
82 QToolButton* ToolButton13_2;
83 QComboBox* recipientsBox;
84 QLineEdit *subjectInput;
85 QLineEdit *toInput;
86 QToolButton* addressButton;
87 QMultiLineEdit* emailInput;
88 QGridLayout* grid;
89};
90
91#endif // WRITEMAIL_H