summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mailit/addatt.cpp6
-rw-r--r--noncore/net/mailit/addresslist.cpp22
-rw-r--r--noncore/net/mailit/addresslist.h3
-rw-r--r--noncore/net/mailit/editaccount.cpp27
-rw-r--r--noncore/net/mailit/editaccount.h5
-rw-r--r--noncore/net/mailit/emailclient.cpp12
-rw-r--r--noncore/net/mailit/emailhandler.cpp19
-rw-r--r--noncore/net/mailit/emailhandler.h1
-rw-r--r--noncore/net/mailit/emaillistitem.cpp5
-rw-r--r--noncore/net/mailit/mailit.pro17
-rw-r--r--noncore/net/mailit/readmail.cpp2
-rw-r--r--noncore/net/mailit/writemail.cpp2
-rw-r--r--noncore/unsupported/mailit/addatt.cpp6
-rw-r--r--noncore/unsupported/mailit/addresslist.cpp22
-rw-r--r--noncore/unsupported/mailit/addresslist.h3
-rw-r--r--noncore/unsupported/mailit/editaccount.cpp27
-rw-r--r--noncore/unsupported/mailit/editaccount.h5
-rw-r--r--noncore/unsupported/mailit/emailclient.cpp12
-rw-r--r--noncore/unsupported/mailit/emailhandler.cpp19
-rw-r--r--noncore/unsupported/mailit/emailhandler.h1
-rw-r--r--noncore/unsupported/mailit/emaillistitem.cpp5
-rw-r--r--noncore/unsupported/mailit/mailit.pro17
-rw-r--r--noncore/unsupported/mailit/readmail.cpp2
-rw-r--r--noncore/unsupported/mailit/writemail.cpp2
24 files changed, 156 insertions, 86 deletions
diff --git a/noncore/net/mailit/addatt.cpp b/noncore/net/mailit/addatt.cpp
index c8be865..d268f1f 100644
--- a/noncore/net/mailit/addatt.cpp
+++ b/noncore/net/mailit/addatt.cpp
@@ -1,224 +1,224 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qlayout.h> 20#include <qlayout.h>
21#include <qhbox.h> 21#include <qhbox.h>
22#include <qdir.h> 22#include <qdir.h>
23#include <qstringlist.h> 23#include <qstringlist.h>
24#include "resource.h" 24#include <qpe/resource.h>
25#include "addatt.h" 25#include "addatt.h"
26 26
27FileItem::FileItem(QListView *parent, DocLnk* dl) 27FileItem::FileItem(QListView *parent, DocLnk* dl)
28 : QListViewItem(parent) 28 : QListViewItem(parent)
29{ 29{
30 /*file = fileInfo; 30 /*file = fileInfo;
31 type = fileType;*/ 31 type = fileType;*/
32 32
33 doclnk=dl; 33 doclnk=dl;
34 34
35 setText(0, doclnk->name()); 35 setText(0, doclnk->name());
36 36
37 /*if (fileType == "Picture") { 37 /*if (fileType == "Picture") {
38 setPixmap(0, Resource::loadPixmap("pixmap")); 38 setPixmap(0, Resource::loadPixmap("pixmap"));
39 } else if (fileType == "Document") { 39 } else if (fileType == "Document") {
40 setPixmap(0, Resource::loadPixmap("txt")); 40 setPixmap(0, Resource::loadPixmap("txt"));
41 } else if (fileType == "Sound") { 41 } else if (fileType == "Sound") {
42 setPixmap(0, Resource::loadPixmap("play")); 42 setPixmap(0, Resource::loadPixmap("play"));
43 } else if (fileType == "Movie") { 43 } else if (fileType == "Movie") {
44 setPixmap(0, Resource::loadPixmap("MPEGPlayer")); 44 setPixmap(0, Resource::loadPixmap("MPEGPlayer"));
45 } else if (fileType == "File") { 45 } else if (fileType == "File") {
46 setPixmap(0, Resource::loadPixmap("exec")); 46 setPixmap(0, Resource::loadPixmap("exec"));
47 }*/ 47 }*/
48} 48}
49 49
50FileItem::~FileItem() 50FileItem::~FileItem()
51{ 51{
52 if (doclnk!=NULL) delete doclnk; 52 if (doclnk!=NULL) delete doclnk;
53 doclnk=NULL; 53 doclnk=NULL;
54} 54}
55 55
56AddAtt::AddAtt(QWidget *parent, const char *name, WFlags f) 56AddAtt::AddAtt(QWidget *parent, const char *name, WFlags f)
57 : QDialog(parent, name, f) 57 : QDialog(parent, name, f)
58{ 58{
59 setCaption("Adding attatchments"); 59 setCaption("Adding attatchments");
60 60
61 QGridLayout *top = new QGridLayout(this, 1,1 ); 61 QGridLayout *top = new QGridLayout(this, 1,1 );
62 62
63 QHBox *buttons=new QHBox(this); 63 QHBox *buttons=new QHBox(this);
64 /*fileCategoryButton = new QPushButton(this);*/ 64 /*fileCategoryButton = new QPushButton(this);*/
65 attatchButton = new QPushButton("Attatch ->", buttons); 65 attatchButton = new QPushButton(tr("Attatch..."), buttons);
66 removeButton = new QPushButton("Remove", buttons); 66 removeButton = new QPushButton(tr("Remove"), buttons);
67 67
68 /*fileCategories = new QPopupMenu(fileCategoryButton); 68 /*fileCategories = new QPopupMenu(fileCategoryButton);
69 fileCategoryButton->setPopup(fileCategories); 69 fileCategoryButton->setPopup(fileCategories);
70 fileCategories->insertItem("Document"); 70 fileCategories->insertItem("Document");
71 fileCategories->insertItem("Picture"); 71 fileCategories->insertItem("Picture");
72 fileCategories->insertItem("Sound"); 72 fileCategories->insertItem("Sound");
73 fileCategories->insertItem("Movie"); 73 fileCategories->insertItem("Movie");
74 fileCategories->insertItem("File"); 74 fileCategories->insertItem("File");
75 75
76 fileCategoryButton->setText("Document"); 76 fileCategoryButton->setText("Document");
77 top->addWidget(fileCategoryButton, 0, 0);*/ 77 top->addWidget(fileCategoryButton, 0, 0);*/
78 78
79 79
80 top->addWidget(buttons,1,0); 80 top->addWidget(buttons,1,0);
81 //buttons->addWidget(attatchButton,0,0); 81 //buttons->addWidget(attatchButton,0,0);
82 //buttons->addWidget(removeButton,0,1); 82 //buttons->addWidget(removeButton,0,1);
83 83
84 //connect(fileCategories, SIGNAL(activated(int)), this, 84 //connect(fileCategories, SIGNAL(activated(int)), this,
85 //SLOT(fileCategorySelected(int)) );*/ 85 //SLOT(fileCategorySelected(int)) );*/
86 connect(attatchButton, SIGNAL(clicked()), this, 86 connect(attatchButton, SIGNAL(clicked()), this,
87 SLOT(addAttatchment()) ); 87 SLOT(addAttatchment()) );
88 connect(removeButton, SIGNAL(clicked()), this, 88 connect(removeButton, SIGNAL(clicked()), this,
89 SLOT(removeAttatchment()) ); 89 SLOT(removeAttatchment()) );
90 90
91 /*listView = new QListView(this, "AttView"); 91 /*listView = new QListView(this, "AttView");
92 listView->addColumn("Documents");* 92 listView->addColumn("Documents");*
93 connect(listView, SIGNAL(doubleClicked(QListViewItem *)), this, 93 connect(listView, SIGNAL(doubleClicked(QListViewItem *)), this,
94 SLOT(addAttatchment()) );*/ 94 SLOT(addAttatchment()) );*/
95 95
96 96
97 attView = new QListView(this, "Selected"); 97 attView = new QListView(this, "Selected");
98 attView->addColumn(tr("Attached")); 98 attView->addColumn(tr("Attached"));
99 attView->addColumn(tr("File type")); 99 attView->addColumn(tr("File type"));
100 connect(attView, SIGNAL(doubleClicked(QListViewItem *)), this, 100 connect(attView, SIGNAL(doubleClicked(QListViewItem *)), this,
101 SLOT(removeAttatchment()) ); 101 SLOT(removeAttatchment()) );
102 102
103 //top->addWidget(ofs, 0,0); 103 //top->addWidget(ofs, 0,0);
104 top->addWidget(attView, 0,0); 104 top->addWidget(attView, 0,0);
105 105
106 clear(); 106 clear();
107 107
108 108
109} 109}
110 110
111void AddAtt::clear() 111void AddAtt::clear()
112{ 112{
113 attView->clear(); 113 attView->clear();
114 //getFiles(); 114 //getFiles();
115 modified = FALSE; 115 modified = FALSE;
116} 116}
117 117
118/*void AddAtt::fileCategorySelected(int id) 118/*void AddAtt::fileCategorySelected(int id)
119{ 119{
120 fileCategoryButton->setText(fileCategories->text(id)); 120 fileCategoryButton->setText(fileCategories->text(id));
121 getFiles(); 121 getFiles();
122}*/ 122}*/
123 123
124void AddAtt::addAttatchment() 124void AddAtt::addAttatchment()
125 { 125 {
126 OFileDialog ofs("Attachments",this,0,0,"/root/Documents"); 126 OFileDialog ofs("Attachments",this,0,0,"/root/Documents");
127 127
128 ofs.showMaximized(); 128 ofs.showMaximized();
129 129
130 if (ofs.exec()==QDialog::Accepted) 130 if (ofs.exec()==QDialog::Accepted)
131 { 131 {
132 DocLnk* dl=new DocLnk(ofs.selectedDocument()); 132 DocLnk* dl=new DocLnk(ofs.selectedDocument());
133 FileItem* fi=new FileItem(attView,dl); 133 FileItem* fi=new FileItem(attView,dl);
134 fi->setPixmap(0,dl->pixmap()); 134 fi->setPixmap(0,dl->pixmap());
135 fi->setText(1,dl->type()); 135 fi->setText(1,dl->type());
136 attView->insertItem(fi); 136 attView->insertItem(fi);
137 modified = TRUE; 137 modified = TRUE;
138 } 138 }
139} 139}
140 140
141void AddAtt::removeAttatchment() 141void AddAtt::removeAttatchment()
142{ 142{
143 if (attView->selectedItem() != NULL) 143 if (attView->selectedItem() != NULL)
144 { 144 {
145 attView->takeItem(attView->selectedItem()); 145 attView->takeItem(attView->selectedItem());
146 } 146 }
147 modified = TRUE; 147 modified = TRUE;
148} 148}
149 149
150void AddAtt::reject() 150void AddAtt::reject()
151{ 151{
152 if (modified) { 152 if (modified) {
153 attView->clear(); 153 attView->clear();
154 modified = FALSE; 154 modified = FALSE;
155 } 155 }
156} 156}
157 157
158void AddAtt::accept() 158void AddAtt::accept()
159{ 159{
160 modified = FALSE; 160 modified = FALSE;
161 hide(); 161 hide();
162} 162}
163 163
164void AddAtt::getFiles() 164void AddAtt::getFiles()
165{ 165{
166 QString path, selected; 166 QString path, selected;
167 167
168 /*listView->clear(); 168 /*listView->clear();
169 169
170 selected = fileCategoryButton->text(); 170 selected = fileCategoryButton->text();
171 if (selected == "Picture") { 171 if (selected == "Picture") {
172 path = "../pics/"; 172 path = "../pics/";
173 } else if (selected == "Document") { 173 } else if (selected == "Document") {
174 path = "" ; //sub-dirs not decided 174 path = "" ; //sub-dirs not decided
175 } else if (selected == "Sound") { 175 } else if (selected == "Sound") {
176 path = "../sounds/"; //sub-dirs not decided 176 path = "../sounds/"; //sub-dirs not decided
177 } else if (selected == "Movie") { 177 } else if (selected == "Movie") {
178 path = ""; //sub-dirs not decided 178 path = ""; //sub-dirs not decided
179 } else if (selected == "File") { 179 } else if (selected == "File") {
180 path = ""; //sub-dirs not decided 180 path = ""; //sub-dirs not decided
181 } 181 }
182 182
183 dir = new QDir(path); 183 dir = new QDir(path);
184 dir->setFilter(QDir::Files); 184 dir->setFilter(QDir::Files);
185 const QFileInfoList *dirInfoList = dir->entryInfoList(); 185 const QFileInfoList *dirInfoList = dir->entryInfoList();
186 186
187 QFileInfoListIterator it(*dirInfoList); // create list iterator 187 QFileInfoListIterator it(*dirInfoList); // create list iterator
188 188
189 while ( (fi=it.current()) ) { // for each file... 189 while ( (fi=it.current()) ) { // for each file...
190 item = new FileItem(lis+ütView, *fi, selected); 190 item = new FileItem(lis+ütView, *fi, selected);
191 ++it; // goto next list element 191 ++it; // goto next list element
192 }*/ 192 }*/
193} 193}
194 194
195QStringList AddAtt::returnAttatchedFiles() 195QStringList AddAtt::returnAttatchedFiles()
196{ 196{
197 QFileInfo info; 197 QFileInfo info;
198 QStringList list; 198 QStringList list;
199 199
200 item = (FileItem *) attView->firstChild(); 200 item = (FileItem *) attView->firstChild();
201 201
202 202
203 while (item != NULL) { 203 while (item != NULL) {
204 DocLnk* dl=item->getDocLnk(); 204 DocLnk* dl=item->getDocLnk();
205 list+=dl->file(); 205 list+=dl->file();
206 /*info = item->getFileInfo(); 206 /*info = item->getFileInfo();
207 list += info.filePath();*/ 207 list += info.filePath();*/
208 item = (FileItem *) item->nextSibling(); 208 item = (FileItem *) item->nextSibling();
209 } 209 }
210 return list; 210 return list;
211} 211}
212 212
213QStringList AddAtt::returnFileTypes() 213QStringList AddAtt::returnFileTypes()
214{ 214{
215 QStringList list; 215 QStringList list;
216 216
217 item = (FileItem *) attView->firstChild(); 217 item = (FileItem *) attView->firstChild();
218 218
219 while (item != NULL) { 219 while (item != NULL) {
220 list += item->getDocLnk()->type(); 220 list += item->getDocLnk()->type();
221 item = (FileItem *) item->nextSibling(); 221 item = (FileItem *) item->nextSibling();
222 } 222 }
223 return list; 223 return list;
224} 224}
diff --git a/noncore/net/mailit/addresslist.cpp b/noncore/net/mailit/addresslist.cpp
index 43e3830..9fe558a 100644
--- a/noncore/net/mailit/addresslist.cpp
+++ b/noncore/net/mailit/addresslist.cpp
@@ -1,181 +1,161 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qfile.h> 20#include <qfile.h>
21#include <qtextstream.h> 21#include <qtextstream.h>
22#include <opie/ocontactaccess.h> 22#include <opie/ocontactaccess.h>
23#include <opie/ocontact.h> 23#include <opie/ocontact.h>
24 24
25#include "addresslist.h" 25#include "addresslist.h"
26 26
27AddressList::AddressList(QString file) 27AddressList::AddressList()
28{ 28{
29 addresses.setAutoDelete(TRUE); 29 addresses.setAutoDelete(TRUE);
30 filename = file;
31 read(); 30 read();
32 dirty = FALSE; 31 dirty = FALSE;
33} 32}
34 33
35AddressList::~AddressList() 34AddressList::~AddressList()
36{ 35{
37 write();
38 addresses.clear(); 36 addresses.clear();
39} 37}
40 38
41void AddressList::addContact(QString email, QString name) 39void AddressList::addContact(QString email, QString name)
42{ 40{
43 //skip if not a valid email address, 41 //skip if not a valid email address,
44 if (email.find( '@') == -1) 42 if (email.find( '@') == -1)
45 return; 43 return;
46 44
47 if ( ! containsEmail(email) ) { 45 if ( ! containsEmail(email) ) {
48 Contact *in = new Contact; 46 Contact *in = new Contact;
49 in->email = email; 47 in->email = email;
50 in->name = name; 48 in->name = name;
51 addresses.append(in); 49 addresses.append(in);
52 dirty = TRUE; 50 dirty = TRUE;
53 } 51 }
54} 52}
55 53
56bool AddressList::containsEmail(QString email) 54bool AddressList::containsEmail(QString email)
57{ 55{
58 return ( getEmailRef(email) != -1 ); 56 return ( getEmailRef(email) != -1 );
59} 57}
60 58
61bool AddressList::containsName(QString name) 59bool AddressList::containsName(QString name)
62{ 60{
63 return ( getNameRef(name) != -1 ); 61 return ( getNameRef(name) != -1 );
64} 62}
65 63
66QString AddressList::getNameByEmail(QString email) 64QString AddressList::getNameByEmail(QString email)
67{ 65{
68 int pos = getEmailRef(email); 66 int pos = getEmailRef(email);
69 if (pos != -1) { 67 if (pos != -1) {
70 Contact *ptr = addresses.at(pos); 68 Contact *ptr = addresses.at(pos);
71 return ptr->name; 69 return ptr->name;
72 } 70 }
73 71
74 return NULL; 72 return NULL;
75} 73}
76 74
77QString AddressList::getEmailByName(QString name) 75QString AddressList::getEmailByName(QString name)
78{ 76{
79 int pos = getNameRef(name); 77 int pos = getNameRef(name);
80 if (pos != -1) { 78 if (pos != -1) {
81 Contact *ptr = addresses.at(pos); 79 Contact *ptr = addresses.at(pos);
82 return ptr->email; 80 return ptr->email;
83 } 81 }
84 82
85 return NULL; 83 return NULL;
86} 84}
87 85
88int AddressList::getEmailRef(QString email) 86int AddressList::getEmailRef(QString email)
89{ 87{
90 int pos = 0; 88 int pos = 0;
91 Contact *ptr; 89 Contact *ptr;
92 90
93 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) { 91 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) {
94 if (ptr->email == email) 92 if (ptr->email == email)
95 return pos; 93 return pos;
96 pos++; 94 pos++;
97 } 95 }
98 return -1; 96 return -1;
99} 97}
100 98
101int AddressList::getNameRef(QString name) 99int AddressList::getNameRef(QString name)
102{ 100{
103 int pos = 0; 101 int pos = 0;
104 Contact *ptr; 102 Contact *ptr;
105 103
106 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) { 104 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) {
107 if (ptr->name == name) 105 if (ptr->name == name)
108 return pos; 106 return pos;
109 pos++; 107 pos++;
110 } 108 }
111 return -1; 109 return -1;
112} 110}
113 111
114QList<Contact>* AddressList::getContactList() 112QList<Contact>* AddressList::getContactList()
115{ 113{
116 return &addresses; 114 return &addresses;
117} 115}
118 116
119void AddressList::read() 117void AddressList::read()
120{ 118{
121 OContactAccess::List::Iterator it; 119 OContactAccess::List::Iterator it;
122 120
123 //QFile f(filename);
124 QString lineEmail, lineName, email, name; 121 QString lineEmail, lineName, email, name;
125 OContactAccess m_contactdb("mailit"); 122 OContactAccess m_contactdb("mailit");
126 OContactAccess::List m_list = m_contactdb.sorted( true, 0, 0, 0 ); 123 OContactAccess::List m_list = m_contactdb.sorted( true, 0, 0, 0 );
127 //OContact* oc; 124 //OContact* oc;
128 125
129 for ( it = m_list.begin(); it != m_list.end(); ++it ) 126 for ( it = m_list.begin(); it != m_list.end(); ++it )
130 { 127 {
131 //oc=(OContact*) it; 128 //oc=(OContact*) it;
132 if ((*it).defaultEmail().length()!=0) 129 if ((*it).defaultEmail().length()!=0)
133 addContact((*it).defaultEmail(),(*it).fullName()); 130 addContact((*it).defaultEmail(),(*it).fullName());
134 } 131 }
135 132
136 /*if (! f.open(IO_ReadOnly) ) 133 /*if (! f.open(IO_ReadOnly) )
137 return; 134 return;
138 135
139 QTextStream stream(&f); 136 QTextStream stream(&f);
140 137
141 while (! stream.atEnd() ) { 138 while (! stream.atEnd() ) {
142 lineEmail = stream.readLine(); 139 lineEmail = stream.readLine();
143 if (! stream.atEnd() ) 140 if (! stream.atEnd() )
144 lineName = stream.readLine(); 141 lineName = stream.readLine();
145 else return; 142 else return;
146 143
147 email = getRightString(lineEmail); 144 email = getRightString(lineEmail);
148 name = getRightString(lineName); 145 name = getRightString(lineName);
149 addContact(email, name); 146 addContact(email, name);
150 } 147 }
151 f.close();*/ 148 f.close();*/
152} 149}
153 150
154QString AddressList::getRightString(QString in) 151QString AddressList::getRightString(QString in)
155{ 152{
156 QString out = ""; 153 QString out = "";
157 154
158 int pos = in.find('='); 155 int pos = in.find('=');
159 if (pos != -1) { 156 if (pos != -1) {
160 out = in.mid(pos+1).stripWhiteSpace(); 157 out = in.mid(pos+1).stripWhiteSpace();
161 } 158 }
162 return out; 159 return out;
163} 160}
164 161
165void AddressList::write()
166{
167 if ( (addresses.count() == 0) || (!dirty) )
168 return;
169
170 QFile f(filename);
171 if (! f.open(IO_WriteOnly) )
172 return;
173
174 QTextStream stream(&f);
175 Contact *ptr;
176 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) {
177 stream << "email = " + ptr->email + "\n";
178 stream << "name = " + ptr->name + "\n";
179 }
180 f.close();
181}
diff --git a/noncore/net/mailit/addresslist.h b/noncore/net/mailit/addresslist.h
index e87d6f1..99cef9a 100644
--- a/noncore/net/mailit/addresslist.h
+++ b/noncore/net/mailit/addresslist.h
@@ -1,59 +1,58 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef ADDRESSLIST_H 20#ifndef ADDRESSLIST_H
21#define ADDRESSLIST_H 21#define ADDRESSLIST_H
22 22
23#include <qobject.h> 23#include <qobject.h>
24#include <qlist.h> 24#include <qlist.h>
25 25
26struct Contact 26struct Contact
27{ 27{
28 QString email; 28 QString email;
29 QString name; 29 QString name;
30}; 30};
31 31
32class AddressList : public QObject 32class AddressList : public QObject
33{ 33{
34 Q_OBJECT 34 Q_OBJECT
35 35
36public: 36public:
37 AddressList(QString file); 37 AddressList();
38 ~AddressList(); 38 ~AddressList();
39 void addContact(QString email, QString name); 39 void addContact(QString email, QString name);
40 bool containsEmail(QString email); 40 bool containsEmail(QString email);
41 bool containsName(QString name); 41 bool containsName(QString name);
42 QString getNameByEmail(QString email); 42 QString getNameByEmail(QString email);
43 QString getEmailByName(QString name); 43 QString getEmailByName(QString name);
44 QList<Contact>* getContactList(); 44 QList<Contact>* getContactList();
45 void write();
46 45
47private: 46private:
48 int getEmailRef(QString email); 47 int getEmailRef(QString email);
49 int getNameRef(QString name); 48 int getNameRef(QString name);
50 QString getRightString(QString in); 49 QString getRightString(QString in);
51 void read(); 50 void read();
52 51
53private: 52private:
54 QList<Contact> addresses; 53 QList<Contact> addresses;
55 QString filename; 54 QString filename;
56 bool dirty; 55 bool dirty;
57}; 56};
58 57
59#endif 58#endif
diff --git a/noncore/net/mailit/editaccount.cpp b/noncore/net/mailit/editaccount.cpp
index c4f95ea..c0afbb2 100644
--- a/noncore/net/mailit/editaccount.cpp
+++ b/noncore/net/mailit/editaccount.cpp
@@ -1,120 +1,133 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18*** 18***
19**********************************************************************/ 19**********************************************************************/
20 20
21#include <qhbox.h>
21#include "editaccount.h" 22#include "editaccount.h"
22 23
23EditAccount::EditAccount( QWidget* parent, const char* name, WFlags fl ) 24EditAccount::EditAccount( QWidget* parent, const char* name, WFlags fl )
24 : QDialog(parent, name, fl) 25 : QDialog(parent, name, fl)
25{ 26{
26 setCaption( tr("Edit Account") ); 27 setCaption( tr("Edit Account") );
27 init(); 28 init();
28 popPasswInput->setEchoMode(QLineEdit::Password); 29 popPasswInput->setEchoMode(QLineEdit::Password);
29} 30}
30 31
31void EditAccount::setAccount(MailAccount *in, bool newOne) 32void EditAccount::setAccount(MailAccount *in, bool newOne)
32{ 33{
33 account = in; 34 account = in;
34 if (newOne) { 35 if (newOne) {
35 accountNameInput->setText(""); 36 accountNameInput->setText("");
36 nameInput->setText(""); 37 nameInput->setText("");
37 emailInput->setText(""); 38 emailInput->setText("");
38 popUserInput->setText(""); 39 popUserInput->setText("");
39 popPasswInput->setText(""); 40 popPasswInput->setText("");
40 popServerInput->setText(""); 41 popServerInput->setText("");
41 smtpServerInput->setText(""); 42 smtpServerInput->setText("");
42 syncCheckBox->setChecked(TRUE); 43 syncCheckBox->setChecked(TRUE);
44 syncLimitInput->setValue(2);
43 45
44 setCaption( tr("Create new Account") ); 46 setCaption( tr("Create new Account") );
45 } else { 47 } else {
46 accountNameInput->setText(account->accountName); 48 accountNameInput->setText(account->accountName);
47 nameInput->setText(account->name); 49 nameInput->setText(account->name);
48 emailInput->setText(account->emailAddress); 50 emailInput->setText(account->emailAddress);
49 popUserInput->setText(account->popUserName); 51 popUserInput->setText(account->popUserName);
50 popPasswInput->setText(account->popPasswd); 52 popPasswInput->setText(account->popPasswd);
51 popServerInput->setText(account->popServer); 53 popServerInput->setText(account->popServer);
52 smtpServerInput->setText(account->smtpServer); 54 smtpServerInput->setText(account->smtpServer);
53 syncCheckBox->setChecked(account->synchronize); 55 syncCheckBox->setChecked(account->synchronize);
56 syncLimitInput->setValue(account->syncLimit/1000);
54 } 57 }
55} 58}
56 59
57void EditAccount::init() 60void EditAccount::init()
58{ 61{
59 grid = new QGridLayout(this); 62 grid = new QGridLayout(this);
60 grid->setSpacing( 6 ); 63 grid->setSpacing( 6 );
61 grid->setMargin( 11 ); 64 grid->setMargin( 11 );
62 65
63 accountNameInputLabel = new QLabel(tr("Account name"), this); 66 accountNameInputLabel = new QLabel(tr("Account name"), this);
64 grid->addWidget( accountNameInputLabel, 0, 0 ); 67 grid->addWidget( accountNameInputLabel, 0, 0 );
65 accountNameInput = new QLineEdit( this, "account nameInput" ); 68 accountNameInput = new QLineEdit( this, "account nameInput" );
66 grid->addWidget( accountNameInput, 0, 1 ); 69 grid->addWidget( accountNameInput, 0, 1 );
67 70
68 nameInputLabel = new QLabel(tr("Your name"), this); 71 nameInputLabel = new QLabel(tr("Your name"), this);
69 grid->addWidget( nameInputLabel, 1, 0 ); 72 grid->addWidget( nameInputLabel, 1, 0 );
70 nameInput = new QLineEdit( this, "nameInput" ); 73 nameInput = new QLineEdit( this, "nameInput" );
71 grid->addWidget( nameInput, 1, 1 ); 74 grid->addWidget( nameInput, 1, 1 );
72 75
73 emailInputLabel = new QLabel("Email", this); 76 emailInputLabel = new QLabel(tr("Email"), this);
74 grid->addWidget(emailInputLabel, 2, 0 ); 77 grid->addWidget(emailInputLabel, 2, 0 );
75 emailInput = new QLineEdit( this, "emailInput" ); 78 emailInput = new QLineEdit( this, "emailInput" );
76 grid->addWidget( emailInput, 2, 1 ); 79 grid->addWidget( emailInput, 2, 1 );
77 80
78 popUserInputLabel = new QLabel("POP username", this); 81 popUserInputLabel = new QLabel(tr("POP username"), this);
79 grid->addWidget( popUserInputLabel, 3, 0 ); 82 grid->addWidget( popUserInputLabel, 3, 0 );
80 popUserInput = new QLineEdit( this, "popUserInput" ); 83 popUserInput = new QLineEdit( this, "popUserInput" );
81 grid->addWidget( popUserInput, 3, 1 ); 84 grid->addWidget( popUserInput, 3, 1 );
82 85
83 popPasswInputLabel = new QLabel( "POP password", this); 86 popPasswInputLabel = new QLabel( tr("POP password"), this);
84 grid->addWidget( popPasswInputLabel, 4, 0 ); 87 grid->addWidget( popPasswInputLabel, 4, 0 );
85 popPasswInput = new QLineEdit( this, "popPasswInput" ); 88 popPasswInput = new QLineEdit( this, "popPasswInput" );
86 grid->addWidget( popPasswInput, 4, 1 ); 89 grid->addWidget( popPasswInput, 4, 1 );
87 90
88 popServerInputLabel = new QLabel("POP server", this); 91 popServerInputLabel = new QLabel(tr("POP server"), this);
89 grid->addWidget( popServerInputLabel, 5, 0 ); 92 grid->addWidget( popServerInputLabel, 5, 0 );
90 popServerInput = new QLineEdit( this, "popServerInput" ); 93 popServerInput = new QLineEdit( this, "popServerInput" );
91 grid->addWidget( popServerInput, 5, 1 ); 94 grid->addWidget( popServerInput, 5, 1 );
92 95
93 smtpServerInputLabel = new QLabel("SMTP server", this ); 96 smtpServerInputLabel = new QLabel(tr("SMTP server"), this );
94 grid->addWidget( smtpServerInputLabel, 6, 0 ); 97 grid->addWidget( smtpServerInputLabel, 6, 0 );
95 smtpServerInput = new QLineEdit( this, "smtpServerInput" ); 98 smtpServerInput = new QLineEdit( this, "smtpServerInput" );
96 grid->addWidget( smtpServerInput, 6, 1 ); 99 grid->addWidget( smtpServerInput, 6, 1 );
97 100
98 syncCheckBox = new QCheckBox( tr( "Synchronize with server" ), this); 101 QHBox* syncBox=new QHBox(this);
102 grid->addWidget( syncBox, 7, 1 );
103
104 syncCheckBox = new QCheckBox( tr( "Synchronize" ), this);
99 syncCheckBox->setChecked( TRUE ); 105 syncCheckBox->setChecked( TRUE );
100 grid->addMultiCellWidget( syncCheckBox, 7, 7, 0, 1 ); 106 grid->addWidget( syncCheckBox,7,0);
107
108 syncLimitInputLabel = new QLabel(tr("Mail Size (k)"), syncBox);
109 //syncBox->addWidget( syncLimitInputLabel);
110 syncLimitInput = new QSpinBox( syncBox, "syncSize" );
111 //syncBox->addWidget(syncLimitInput);
112
101} 113}
102 114
103 115
104void EditAccount::accept() 116void EditAccount::accept()
105{ 117{
106 account->accountName = accountNameInput->text(); 118 account->accountName = accountNameInput->text();
107 account->name = nameInput->text(); 119 account->name = nameInput->text();
108 account->emailAddress = emailInput->text(); 120 account->emailAddress = emailInput->text();
109 account->popUserName = popUserInput->text(); 121 account->popUserName = popUserInput->text();
110 account->popPasswd = popPasswInput->text(); 122 account->popPasswd = popPasswInput->text();
111 account->popServer = popServerInput->text(); 123 account->popServer = popServerInput->text();
112 account->smtpServer = smtpServerInput->text(); 124 account->smtpServer = smtpServerInput->text();
113 account->synchronize = syncCheckBox->isChecked(); 125 account->synchronize = syncCheckBox->isChecked();
126 account->syncLimit = syncLimitInput->value()*1000;//Display in kB
114 127
115 QDialog::accept(); 128 QDialog::accept();
116} 129}
117 130
118void EditAccount::reject() 131void EditAccount::reject()
119{ 132{
120} 133}
diff --git a/noncore/net/mailit/editaccount.h b/noncore/net/mailit/editaccount.h
index 7a90e50..1e15047 100644
--- a/noncore/net/mailit/editaccount.h
+++ b/noncore/net/mailit/editaccount.h
@@ -1,66 +1,69 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef EDITACCOUNT_H 20#ifndef EDITACCOUNT_H
21#define EDITACCOUNT_H 21#define EDITACCOUNT_H
22 22
23#include <qdialog.h> 23#include <qdialog.h>
24#include <qlabel.h> 24#include <qlabel.h>
25#include <qlineedit.h> 25#include <qlineedit.h>
26#include <qcheckbox.h> 26#include <qcheckbox.h>
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qspinbox.h>
28#include "emailhandler.h" 29#include "emailhandler.h"
29 30
30class EditAccount : public QDialog 31class EditAccount : public QDialog
31{ 32{
32 Q_OBJECT 33 Q_OBJECT
33 34
34public: 35public:
35 EditAccount( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 36 EditAccount( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
36 void setAccount(MailAccount *in, bool newOne = TRUE); 37 void setAccount(MailAccount *in, bool newOne = TRUE);
37 void init(); 38 void init();
38 39
39public slots: 40public slots:
40 void accept(); 41 void accept();
41 void reject(); 42 void reject();
42 43
43private: 44private:
44 MailAccount thisAccount, *account; 45 MailAccount thisAccount, *account;
45 46
46 QLabel *accountNameInputLabel; 47 QLabel *accountNameInputLabel;
47 QLabel *nameInputLabel; 48 QLabel *nameInputLabel;
48 QLabel *emailInputLabel; 49 QLabel *emailInputLabel;
49 QLabel *popUserInputLabel; 50 QLabel *popUserInputLabel;
50 QLabel *popPasswInputLabel; 51 QLabel *popPasswInputLabel;
51 QLabel *popServerInputLabel; 52 QLabel *popServerInputLabel;
52 QLabel *smtpServerInputLabel; 53 QLabel *smtpServerInputLabel;
53 54 QLabel *syncLimitInputLabel;
55
54 QLineEdit *accountNameInput; 56 QLineEdit *accountNameInput;
55 QLineEdit *nameInput; 57 QLineEdit *nameInput;
56 QLineEdit *emailInput; 58 QLineEdit *emailInput;
57 QLineEdit *popUserInput; 59 QLineEdit *popUserInput;
58 QLineEdit *popPasswInput; 60 QLineEdit *popPasswInput;
59 QLineEdit *popServerInput; 61 QLineEdit *popServerInput;
60 QLineEdit *smtpServerInput; 62 QLineEdit *smtpServerInput;
63 QSpinBox *syncLimitInput;
61 QCheckBox *syncCheckBox; 64 QCheckBox *syncCheckBox;
62 65
63 QGridLayout *grid; 66 QGridLayout *grid;
64}; 67};
65 68
66#endif 69#endif
diff --git a/noncore/net/mailit/emailclient.cpp b/noncore/net/mailit/emailclient.cpp
index 2943986..6612541 100644
--- a/noncore/net/mailit/emailclient.cpp
+++ b/noncore/net/mailit/emailclient.cpp
@@ -1,864 +1,872 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qapplication.h> 20#include <qapplication.h>
21#include <qmessagebox.h> 21#include <qmessagebox.h>
22#include <qfile.h> 22#include <qfile.h>
23#include <qcheckbox.h> 23#include <qcheckbox.h>
24#include <qmenubar.h> 24#include <qmenubar.h>
25#include <qaction.h> 25#include <qaction.h>
26#include "resource.h" 26#include <qpe/resource.h>
27#include "emailclient.h" 27#include "emailclient.h"
28 28
29QCollection::Item AccountList::newItem(QCollection::Item d) 29QCollection::Item AccountList::newItem(QCollection::Item d)
30{ 30{
31 return dupl( (MailAccount *) d); 31 return dupl( (MailAccount *) d);
32} 32}
33 33
34MailAccount* AccountList::dupl(MailAccount *in) 34MailAccount* AccountList::dupl(MailAccount *in)
35{ 35{
36 ac = new MailAccount(*in); 36 ac = new MailAccount(*in);
37 return ac; 37 return ac;
38} 38}
39 39
40EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl ) 40EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl )
41 : QMainWindow( parent, name, fl ) 41 : QMainWindow( parent, name, fl )
42{ 42{
43 emailHandler = new EmailHandler(); 43 emailHandler = new EmailHandler();
44 addressList = new AddressList( getPath(FALSE) + "mail_adr"); 44 addressList = new AddressList();
45 45
46 sending = FALSE; 46 sending = FALSE;
47 receiving = FALSE; 47 receiving = FALSE;
48 previewingMail = FALSE; 48 previewingMail = FALSE;
49 mailIdCount = 1; 49 mailIdCount = 1;
50 accountIdCount = 1; 50 accountIdCount = 1;
51 allAccounts = FALSE; 51 allAccounts = FALSE;
52 52
53 init(); 53 init();
54 54
55 connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) ); 55 connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) );
56 56
57 connect(emailHandler, SIGNAL(smtpError(int)), this, 57 connect(emailHandler, SIGNAL(smtpError(int)), this,
58 SLOT(smtpError(int)) ); 58 SLOT(smtpError(int)) );
59 connect(emailHandler, SIGNAL(popError(int)), this, 59 connect(emailHandler, SIGNAL(popError(int)), this,
60 SLOT(popError(int)) ); 60 SLOT(popError(int)) );
61 61
62 connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemSelected()) ); 62 connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemSelected()) );
63 connect(outboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(outboxItemSelected()) ); 63 connect(outboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(outboxItemSelected()) );
64 64
65 connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this, 65 connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this,
66 SLOT(mailArrived(const Email &, bool)) ); 66 SLOT(mailArrived(const Email &, bool)) );
67 connect(emailHandler, SIGNAL(mailTransfered(int)), this, 67 connect(emailHandler, SIGNAL(mailTransfered(int)), this,
68 SLOT(allMailArrived(int)) ); 68 SLOT(allMailArrived(int)) );
69 69
70 mailconf = new Config("mailit"); 70 mailconf = new Config("mailit");
71 //In case Synchronize is not defined in settings.txt 71 //In case Synchronize is not defined in settings.txt
72 72
73 readSettings(); 73 readSettings();
74 74
75 updateAccounts(); 75 updateAccounts();
76 76
77 lineShift = "\n"; 77 lineShift = "\n";
78 readMail(); 78 readMail();
79 lineShift = "\r\n"; 79 lineShift = "\r\n";
80 80
81} 81}
82 82
83 83
84EmailClient::~EmailClient() 84EmailClient::~EmailClient()
85{ 85{
86 //needs to be moved from destructor to closewindow event 86 //needs to be moved from destructor to closewindow event
87 saveMail(getPath(FALSE) + "inbox.txt", inboxView); 87 saveMail(getPath(FALSE) + "inbox.txt", inboxView);
88 //does not currently work. Defining outbox in the same 88 //does not currently work. Defining outbox in the same
89 //format as inbox is not a good solution as they have 89 //format as inbox is not a good solution as they have
90 //different properties 90 //different properties
91 saveMail(getPath(FALSE) + "outbox.txt", outboxView); 91 saveMail(getPath(FALSE) + "outbox.txt", outboxView);
92 saveSettings(); 92 saveSettings();
93 93
94 mailconf->write(); 94 mailconf->write();
95 delete mailconf; 95 delete mailconf;
96 96
97} 97}
98 98
99void EmailClient::init() 99void EmailClient::init()
100{ 100{
101 statusBar = new QStatusBar(this); 101 statusBar = new QStatusBar(this);
102 statusBar->setSizeGripEnabled(FALSE); 102 statusBar->setSizeGripEnabled(FALSE);
103 103
104 status1Label = new QLabel( tr("Idle"), statusBar); 104 status1Label = new QLabel( tr("Idle"), statusBar);
105 status2Label = new QLabel("", statusBar); 105 status2Label = new QLabel("", statusBar);
106 connect(emailHandler, SIGNAL(updatePopStatus(const QString &)), 106 connect(emailHandler, SIGNAL(updatePopStatus(const QString &)),
107 status2Label, SLOT(setText(const QString &)) ); 107 status2Label, SLOT(setText(const QString &)) );
108 connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)), 108 connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)),
109 status2Label, SLOT(setText(const QString &)) ); 109 status2Label, SLOT(setText(const QString &)) );
110 110
111 progressBar = new QProgressBar(statusBar); 111 progressBar = new QProgressBar(statusBar);
112 connect(emailHandler, SIGNAL(mailboxSize(int)), 112 connect(emailHandler, SIGNAL(mailboxSize(int)),
113 this, SLOT(setTotalSize(int)) ); 113 this, SLOT(setTotalSize(int)) );
114 connect(emailHandler, SIGNAL(currentMailSize(int)), 114 connect(emailHandler, SIGNAL(currentMailSize(int)),
115 this, SLOT(setMailSize(int)) ); 115 this, SLOT(setMailSize(int)) );
116 connect(emailHandler, SIGNAL(downloadedSize(int)), 116 connect(emailHandler, SIGNAL(downloadedSize(int)),
117 this, SLOT(setDownloadedSize(int)) ); 117 this, SLOT(setDownloadedSize(int)) );
118 118
119 statusBar->addWidget(status1Label); 119 statusBar->addWidget(status1Label);
120 statusBar->addWidget(progressBar); 120 statusBar->addWidget(progressBar);
121 statusBar->addWidget(status2Label); 121 statusBar->addWidget(status2Label);
122 122
123 setToolBarsMovable(FALSE); 123 setToolBarsMovable(FALSE);
124 124
125 bar = new QToolBar(this); 125 bar = new QToolBar(this);
126 bar->setHorizontalStretchable( TRUE ); 126 bar->setHorizontalStretchable( TRUE );
127 127
128 mb = new QMenuBar( bar ); 128 mb = new QMenuBar( bar );
129 129
130 QPopupMenu *mail = new QPopupMenu(mb); 130 QPopupMenu *mail = new QPopupMenu(mb);
131 mb->insertItem( tr( "&Mail" ), mail); 131 mb->insertItem( tr( "&Mail" ), mail);
132 132
133 QPopupMenu *configure = new QPopupMenu(mb); 133 QPopupMenu *configure = new QPopupMenu(mb);
134 mb->insertItem( tr( "Accounts" ), configure); 134 mb->insertItem( tr( "Accounts" ), configure);
135 135
136 selectAccountMenu = new QPopupMenu(mb); 136 selectAccountMenu = new QPopupMenu(mb);
137 editAccountMenu = new QPopupMenu(mb); 137 editAccountMenu = new QPopupMenu(mb);
138 deleteAccountMenu = new QPopupMenu(mb); 138 deleteAccountMenu = new QPopupMenu(mb);
139 139
140 mail->insertItem(tr("Get Mail in"), selectAccountMenu); 140 mail->insertItem(tr("Get Mail in"), selectAccountMenu);
141 configure->insertItem(tr("Edit account"), editAccountMenu); 141 configure->insertItem(tr("Edit account"), editAccountMenu);
142 configure->insertItem(tr("Delete account"), deleteAccountMenu); 142 configure->insertItem(tr("Delete account"), deleteAccountMenu);
143 143
144 bar = new QToolBar(this); 144 bar = new QToolBar(this);
145 145
146 getMailButton = new QAction(tr("Get all mail"), Resource::loadPixmap("mailit/getmail"), QString::null, 0, this, 0); 146 getMailButton = new QAction(tr("Get all mail"), Resource::loadPixmap("mailit/getmail"), QString::null, 0, this, 0);
147 connect(getMailButton, SIGNAL(activated()), this, SLOT(getAllNewMail()) ); 147 connect(getMailButton, SIGNAL(activated()), this, SLOT(getAllNewMail()) );
148 getMailButton->addTo(bar); 148 getMailButton->addTo(bar);
149 getMailButton->addTo(mail); 149 getMailButton->addTo(mail);
150 150
151 sendMailButton = new QAction(tr("Send mail"), Resource::loadPixmap("mailit/sendqueue"), QString::null, 0, this, 0); 151 sendMailButton = new QAction(tr("Send mail"), Resource::loadPixmap("mailit/sendqueue"), QString::null, 0, this, 0);
152 connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) ); 152 connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) );
153 sendMailButton->addTo(bar); 153 sendMailButton->addTo(bar);
154 sendMailButton->addTo(mail); 154 sendMailButton->addTo(mail);
155 155
156 composeButton = new QAction(tr("Compose"), Resource::loadPixmap("new"), QString::null, 0, this, 0); 156 composeButton = new QAction(tr("Compose"), Resource::loadPixmap("new"), QString::null, 0, this, 0);
157 connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) ); 157 connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) );
158 composeButton->addTo(bar); 158 composeButton->addTo(bar);
159 composeButton->addTo(mail); 159 composeButton->addTo(mail);
160 160
161 cancelButton = new QAction(tr("Cancel transfer"), Resource::loadPixmap("close"), QString::null, 0, this, 0); 161 cancelButton = new QAction(tr("Cancel transfer"), Resource::loadPixmap("close"), QString::null, 0, this, 0);
162 connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) ); 162 connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) );
163 cancelButton->addTo(mail); 163 cancelButton->addTo(mail);
164 cancelButton->addTo(bar); 164 cancelButton->addTo(bar);
165 cancelButton->setEnabled(FALSE); 165 cancelButton->setEnabled(FALSE);
166 166
167 mailboxView = new OTabWidget( this, "mailboxView" ); 167 mailboxView = new OTabWidget( this, "mailboxView" );
168 168
169 QWidget* widget = new QWidget( mailboxView, "widget" ); 169 QWidget* widget = new QWidget( mailboxView, "widget" );
170 grid_2 = new QGridLayout( widget ); 170 grid_2 = new QGridLayout( widget );
171// grid_2->setSpacing(6); 171// grid_2->setSpacing(6);
172// grid_2->setMargin( 11 ); 172// grid_2->setMargin( 11 );
173 173
174 inboxView = new QListView( widget, "inboxView" ); 174 inboxView = new QListView( widget, "inboxView" );
175 inboxView->addColumn( tr( "From" ) ); 175 inboxView->addColumn( tr( "From" ) );
176 inboxView->addColumn( tr( "Subject" ) ); 176 inboxView->addColumn( tr( "Subject" ) );
177 inboxView->addColumn( tr( "Date" ) ); 177 inboxView->addColumn( tr( "Date" ) );
178 inboxView->setMinimumSize( QSize( 0, 0 ) ); 178 inboxView->setMinimumSize( QSize( 0, 0 ) );
179 inboxView->setAllColumnsShowFocus(TRUE); 179 inboxView->setAllColumnsShowFocus(TRUE);
180 180
181 grid_2->addWidget( inboxView, 2, 0 ); 181 grid_2->addWidget( inboxView, 2, 0 );
182 mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) ); 182 mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) );
183 183
184 QWidget* widget_2 = new QWidget( mailboxView, "widget_2" ); 184 QWidget* widget_2 = new QWidget( mailboxView, "widget_2" );
185 grid_3 = new QGridLayout( widget_2 ); 185 grid_3 = new QGridLayout( widget_2 );
186// grid_3->setSpacing(6); 186// grid_3->setSpacing(6);
187// grid_3->setMargin( 11 ); 187// grid_3->setMargin( 11 );
188 188
189 outboxView = new QListView( widget_2, "outboxView" ); 189 outboxView = new QListView( widget_2, "outboxView" );
190 outboxView->addColumn( tr( "To" ) ); 190 outboxView->addColumn( tr( "To" ) );
191 outboxView->addColumn( tr( "Subject" ) ); 191 outboxView->addColumn( tr( "Subject" ) );
192 outboxView->setAllColumnsShowFocus(TRUE); 192 outboxView->setAllColumnsShowFocus(TRUE);
193 193
194 grid_3->addWidget( outboxView, 0, 0 ); 194 grid_3->addWidget( outboxView, 0, 0 );
195 mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) ); 195 mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) );
196 196
197 setCentralWidget(mailboxView); 197 setCentralWidget(mailboxView);
198} 198}
199 199
200void EmailClient::compose() 200void EmailClient::compose()
201{ 201{
202 emit composeRequested(); 202 emit composeRequested();
203} 203}
204 204
205void EmailClient::cancel() 205void EmailClient::cancel()
206{ 206{
207 emailHandler->cancel(); 207 emailHandler->cancel();
208} 208}
209 209
210AddressList* EmailClient::getAdrListRef() 210AddressList* EmailClient::getAdrListRef()
211{ 211{
212 return addressList; 212 return addressList;
213} 213}
214 214
215//this needs to be rewritten to syncronize with outboxView 215//this needs to be rewritten to syncronize with outboxView
216void EmailClient::enqueMail(const Email &mail) 216void EmailClient::enqueMail(const Email &mail)
217{ 217{
218 if (accountList.count() == 0) { 218 if (accountList.count() == 0) {
219 QMessageBox::warning(qApp->activeWindow(), 219 QMessageBox::warning(qApp->activeWindow(),
220 tr("No account selected"), tr("You must create an account"), "OK\n"); 220 tr("No account selected"), tr("You must create an account"), "OK\n");
221 return; 221 return;
222 } 222 }
223 223
224 if (accountList.count() > 0) { 224 if (accountList.count() > 0) {
225 currentAccount = accountList.first(); 225 currentAccount = accountList.first();
226 qWarning("using account " + currentAccount->name); 226 qWarning("using account " + currentAccount->name);
227 } 227 }
228 228
229 Email addMail = mail; 229 Email addMail = mail;
230 addMail.from = currentAccount->name; 230 addMail.from = currentAccount->name;
231 addMail.fromMail = currentAccount->emailAddress; 231 addMail.fromMail = currentAccount->emailAddress;
232 addMail.rawMail.prepend("From: " + addMail.from + "<" + addMail.fromMail + ">\n"); 232 addMail.rawMail.prepend("From: " + addMail.from + "<" + addMail.fromMail + ">\n");
233 item = new EmailListItem(outboxView, addMail, false); 233 item = new EmailListItem(outboxView, addMail, false);
234 234
235} 235}
236 236
237void EmailClient::sendQuedMail() 237void EmailClient::sendQuedMail()
238{ 238{
239 int count = 0; 239 int count = 0;
240 240
241 if (accountList.count() == 0) { 241 if (accountList.count() == 0) {
242 QMessageBox::warning(qApp->activeWindow(), "No account selected", "You must create an account", "OK\n"); 242 QMessageBox::warning(qApp->activeWindow(), "No account selected", "You must create an account", "OK\n");
243 return; 243 return;
244 } 244 }
245 //traverse listview, find messages to send 245 //traverse listview, find messages to send
246 if (! sending) { 246 if (! sending) {
247 item = (EmailListItem *) outboxView->firstChild(); 247 item = (EmailListItem *) outboxView->firstChild();
248 if (item != NULL) { 248 if (item != NULL) {
249 while (item != NULL) { 249 while (item != NULL) {
250 quedMessages.append(item->getMail()); 250 quedMessages.append(item->getMail());
251 item = (EmailListItem *) item->nextSibling(); 251 item = (EmailListItem *) item->nextSibling();
252 count++; 252 count++;
253 } 253 }
254 setMailAccount(); 254 setMailAccount();
255 emailHandler->sendMail(&quedMessages); 255 emailHandler->sendMail(&quedMessages);
256 sending = TRUE; 256 sending = TRUE;
257 sendMailButton->setEnabled(FALSE); 257 sendMailButton->setEnabled(FALSE);
258 cancelButton->setEnabled(TRUE); 258 cancelButton->setEnabled(TRUE);
259 } else { 259 } else {
260 qWarning("sendQuedMail(): no messages to send"); 260 qWarning("sendQuedMail(): no messages to send");
261 } 261 }
262 } 262 }
263} 263}
264 264
265void EmailClient::setMailAccount() 265void EmailClient::setMailAccount()
266{ 266{
267 emailHandler->setAccount(*currentAccount); 267 emailHandler->setAccount(*currentAccount);
268} 268}
269 269
270void EmailClient::mailSent() 270void EmailClient::mailSent()
271{ 271{
272 sending = FALSE; 272 sending = FALSE;
273 sendMailButton->setEnabled(TRUE); 273 sendMailButton->setEnabled(TRUE);
274 274
275 quedMessages.clear(); 275 quedMessages.clear();
276 outboxView->clear(); //should be moved to an sentBox 276 outboxView->clear(); //should be moved to an sentBox
277} 277}
278 278
279void EmailClient::getNewMail() { 279void EmailClient::getNewMail() {
280 280
281 if (accountList.count() == 0) { 281 if (accountList.count() == 0) {
282 QMessageBox::warning(qApp->activeWindow(),"No account selected", 282 QMessageBox::warning(qApp->activeWindow(),"No account selected",
283 "You must create an account", "OK\n"); 283 "You must create an account", "OK\n");
284 return; 284 return;
285 } 285 }
286 286
287 setMailAccount(); 287 setMailAccount();
288 288
289 receiving = TRUE; 289 receiving = TRUE;
290 previewingMail = TRUE; 290 previewingMail = TRUE;
291 getMailButton->setEnabled(FALSE); 291 getMailButton->setEnabled(FALSE);
292 cancelButton->setEnabled(TRUE); 292 cancelButton->setEnabled(TRUE);
293 selectAccountMenu->setEnabled(FALSE); 293 selectAccountMenu->setEnabled(FALSE);
294 294
295 status1Label->setText(currentAccount->accountName + " headers"); 295 status1Label->setText(currentAccount->accountName + " headers");
296 progressBar->reset(); 296 progressBar->reset();
297 297
298 //get any previous mails not downloaded and add to queue 298 //get any previous mails not downloaded and add to queue
299 mailDownloadList.clear(); 299 mailDownloadList.clear();
300 Email *mailPtr; 300 Email *mailPtr;
301 item = (EmailListItem *) inboxView->firstChild(); 301 item = (EmailListItem *) inboxView->firstChild();
302 while (item != NULL) { 302 while (item != NULL) {
303 mailPtr = item->getMail(); 303 mailPtr = item->getMail();
304 if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { 304 if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) {
305 mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); 305 mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size);
306 } 306 }
307 item = (EmailListItem *) item->nextSibling(); 307 item = (EmailListItem *) item->nextSibling();
308 } 308 }
309 309
310 emailHandler->getMailHeaders(); 310 emailHandler->getMailHeaders();
311} 311}
312 312
313void EmailClient::getAllNewMail() 313void EmailClient::getAllNewMail()
314{ 314{
315 allAccounts = TRUE; 315 allAccounts = TRUE;
316 currentAccount = accountList.first(); 316 currentAccount = accountList.first();
317 getNewMail(); 317 getNewMail();
318} 318}
319 319
320void EmailClient::mailArrived(const Email &mail, bool fromDisk) 320void EmailClient::mailArrived(const Email &mail, bool fromDisk)
321{ 321{
322 Enclosure *ePtr; 322 Enclosure *ePtr;
323 Email newMail; 323 Email newMail;
324 int thisMailId; 324 int thisMailId;
325 emailHandler->parse(mail.rawMail, lineShift, &newMail); 325 emailHandler->parse(mail.rawMail, lineShift, &newMail);
326 326
327 mailconf->setGroup(newMail.id); 327 mailconf->setGroup(newMail.id);
328 328
329 if (fromDisk) { 329 if (fromDisk) {
330 newMail.downloaded = mailconf->readBoolEntry("downloaded"); 330 newMail.downloaded = mailconf->readBoolEntry("downloaded");
331 newMail.size = mailconf->readNumEntry("size"); 331 newMail.size = mailconf->readNumEntry("size");
332 newMail.serverId = mailconf->readNumEntry("serverid"); 332 newMail.serverId = mailconf->readNumEntry("serverid");
333 newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); 333 newMail.fromAccountId = mailconf->readNumEntry("fromaccountid");
334 } else { //mail arrived from server 334 } else { //mail arrived from server
335 newMail.serverId = mail.serverId; 335 newMail.serverId = mail.serverId;
336 newMail.size = mail.size; 336 newMail.size = mail.size;
337 newMail.downloaded = mail.downloaded; 337 newMail.downloaded = mail.downloaded;
338 338
339 newMail.fromAccountId = currentAccount->id; 339 newMail.fromAccountId = currentAccount->id;
340 mailconf->writeEntry("fromaccountid", newMail.fromAccountId); 340 mailconf->writeEntry("fromaccountid", newMail.fromAccountId);
341 } 341 }
342 342
343 //add if read or not 343 //add if read or not
344 newMail.read = mailconf->readBoolEntry("mailread"); 344 newMail.read = mailconf->readBoolEntry("mailread");
345 345
346 //check if new mail 346 //check if new mail
347 if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { 347 if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) {
348 thisMailId = mailIdCount; 348 thisMailId = mailIdCount;
349 mailIdCount++; 349 mailIdCount++;
350 350
351 //set server count, so that if the user aborts, the new 351 //set server count, so that if the user aborts, the new
352 //header is not reloaded 352 //header is not reloaded
353 if (currentAccount->synchronize) 353 if (currentAccount->synchronize)
354 currentAccount->lastServerMailCount++; 354 currentAccount->lastServerMailCount++;
355 355
356 mailconf->writeEntry("internalmailid", thisMailId); 356 mailconf->writeEntry("internalmailid", thisMailId);
357 mailconf->writeEntry("downloaded", newMail.downloaded); 357 mailconf->writeEntry("downloaded", newMail.downloaded);
358 mailconf->writeEntry("size", (int) newMail.size); 358 mailconf->writeEntry("size", (int) newMail.size);
359 mailconf->writeEntry("serverid", newMail.serverId); 359 mailconf->writeEntry("serverid", newMail.serverId);
360 360
361 addressList->addContact(newMail.fromMail, newMail.from); 361 addressList->addContact(newMail.fromMail, newMail.from);
362 } else if (!fromDisk) { //body to header arrived 362 } else if (!fromDisk) { //body to header arrived
363 mailconf->writeEntry("downloaded", TRUE); 363 mailconf->writeEntry("downloaded", TRUE);
364 } 364 }
365 QString stringMailId; 365 QString stringMailId;
366 stringMailId.setNum(thisMailId); 366 stringMailId.setNum(thisMailId);
367 //se if any attatchments needs to be stored 367 //se if any attatchments needs to be stored
368 for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { 368 for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) {
369 QString stringId; 369 QString stringId;
370 stringId.setNum(ePtr->id); 370 stringId.setNum(ePtr->id);
371 371
372 int id = mailconf->readNumEntry("enclosureid_" + stringId); 372 int id = mailconf->readNumEntry("enclosureid_" + stringId);
373 if (id != ePtr->id) { //new entry 373 if (id != ePtr->id) { //new entry
374 mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); 374 mailconf->writeEntry("enclosureid_" + stringId, ePtr->id);
375 mailconf->writeEntry("name_" + stringId, ePtr->originalName); 375 mailconf->writeEntry("name_" + stringId, ePtr->originalName);
376 mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); 376 mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType);
377 mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); 377 mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute);
378 mailconf->writeEntry("saved_" + stringId, ePtr->saved); 378 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
379 mailconf->writeEntry("installed_" + stringId, FALSE); 379 mailconf->writeEntry("installed_" + stringId, FALSE);
380 380
381 ePtr->name = stringMailId + "_" + stringId; 381 ePtr->name = stringMailId + "_" + stringId;
382 ePtr->path = getPath(TRUE); 382 ePtr->path = getPath(TRUE);
383 if (emailHandler->getEnclosure(ePtr)) { //file saved 383 if (emailHandler->getEnclosure(ePtr)) { //file saved
384 ePtr->saved = TRUE; 384 ePtr->saved = TRUE;
385 mailconf->writeEntry("saved_" + stringId, ePtr->saved); 385 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
386 mailconf->writeEntry("filename_" + stringId, ePtr->name); 386 mailconf->writeEntry("filename_" + stringId, ePtr->name);
387 mailconf->writeEntry("path_" + stringId, ePtr->path); 387 mailconf->writeEntry("path_" + stringId, ePtr->path);
388 } else { 388 } else {
389 ePtr->saved = FALSE; 389 ePtr->saved = FALSE;
390 mailconf->writeEntry("saved_" + stringId, ePtr->saved); 390 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
391 } 391 }
392 } else { 392 } else {
393 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); 393 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId);
394 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); 394 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId);
395 if (ePtr->saved) { 395 if (ePtr->saved) {
396 ePtr->name = mailconf->readEntry("filename_" + stringId); 396 ePtr->name = mailconf->readEntry("filename_" + stringId);
397 ePtr->path = mailconf->readEntry("path_" + stringId); 397 ePtr->path = mailconf->readEntry("path_" + stringId);
398 } 398 }
399 } 399 }
400 } 400 }
401 if (!previewingMail && !fromDisk) { 401 if (!previewingMail && !fromDisk) {
402 Email *mailPtr; 402 Email *mailPtr;
403 item = (EmailListItem *) inboxView->firstChild(); 403 item = (EmailListItem *) inboxView->firstChild();
404 while (item != NULL) { 404 while (item != NULL) {
405 mailPtr = item->getMail(); 405 mailPtr = item->getMail();
406 if (mailPtr->id == newMail.id) { 406 if (mailPtr->id == newMail.id) {
407 item->setMail(newMail); 407 item->setMail(newMail);
408 emit mailUpdated(item->getMail()); 408 emit mailUpdated(item->getMail());
409 } 409 }
410 item = (EmailListItem *) item->nextSibling(); 410 item = (EmailListItem *) item->nextSibling();
411 } 411 }
412 } else { 412 } else {
413 item = new EmailListItem(inboxView, newMail, TRUE); 413 item = new EmailListItem(inboxView, newMail, TRUE);
414 if (!newMail.downloaded) 414 if (!newMail.downloaded)
415 mailDownloadList.sizeInsert(newMail.serverId, newMail.size); 415 mailDownloadList.sizeInsert(newMail.serverId, newMail.size);
416 } 416 }
417 417
418} 418}
419 419
420void EmailClient::allMailArrived(int count) 420void EmailClient::allMailArrived(int count)
421{ 421{
422 // not previewing means all mailtransfer has been done 422 // not previewing means all mailtransfer has been done
423 if (!previewingMail) { 423 if (!previewingMail) {
424 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { 424 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) {
425 emit newCaption("Mailit - " + currentAccount->accountName); 425 emit newCaption("Mailit - " + currentAccount->accountName);
426 getNewMail(); 426 getNewMail();
427 return; 427 return;
428 } else { 428 } else {
429 allAccounts = FALSE; 429 allAccounts = FALSE;
430 receiving = FALSE; 430 receiving = FALSE;
431 getMailButton->setEnabled(TRUE); 431 getMailButton->setEnabled(TRUE);
432 cancelButton->setEnabled(FALSE); 432 cancelButton->setEnabled(FALSE);
433 selectAccountMenu->setEnabled(TRUE); 433 selectAccountMenu->setEnabled(TRUE);
434 status1Label->setText("Idle"); 434 status1Label->setText("Idle");
435 435
436 progressBar->reset(); 436 progressBar->reset();
437 return; 437 return;
438 } 438 }
439 } 439 }
440 440
441 // all headers downloaded from server, start downloading remaining mails 441 // all headers downloaded from server, start downloading remaining mails
442 previewingMail = FALSE; 442 previewingMail = FALSE;
443 status1Label->setText(currentAccount->accountName); 443 status1Label->setText(currentAccount->accountName);
444 progressBar->reset(); 444 progressBar->reset();
445 445
446 emailHandler->getMailByList(&mailDownloadList); 446 emailHandler->getMailByList(&mailDownloadList);
447} 447}
448 448
449void EmailClient::moveMailFront(Email *mailPtr) 449void EmailClient::moveMailFront(Email *mailPtr)
450{ 450{
451 if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { 451 if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) {
452 mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); 452 mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size);
453 } 453 }
454} 454}
455 455
456void EmailClient::smtpError(int code) 456void EmailClient::smtpError(int code)
457{ 457{
458 QString temp; 458 QString temp;
459 459
460 if (code == ErrUnknownResponse) 460 if (code == ErrUnknownResponse)
461 temp = "Unknown response from server"; 461 temp = "Unknown response from server";
462 462
463 if (code == QSocket::ErrHostNotFound) 463 if (code == QSocket::ErrHostNotFound)
464 temp = "host not found"; 464 temp = "host not found";
465 if (code == QSocket::ErrConnectionRefused) 465 if (code == QSocket::ErrConnectionRefused)
466 temp = "connection refused"; 466 temp = "connection refused";
467 if (code == QSocket::ErrSocketRead) 467 if (code == QSocket::ErrSocketRead)
468 temp = "socket packet error"; 468 temp = "socket packet error";
469 469
470 if (code != ErrCancel) { 470 if (code != ErrCancel) {
471 QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); 471 QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n");
472 } else { 472 } else {
473 status2Label->setText("Aborted by user"); 473 status2Label->setText("Aborted by user");
474 } 474 }
475 475
476 sending = FALSE; 476 sending = FALSE;
477 sendMailButton->setEnabled(TRUE); 477 sendMailButton->setEnabled(TRUE);
478 cancelButton->setEnabled(FALSE); 478 cancelButton->setEnabled(FALSE);
479 quedMessages.clear(); 479 quedMessages.clear();
480} 480}
481 481
482void EmailClient::popError(int code) 482void EmailClient::popError(int code)
483{ 483{
484 QString temp; 484 QString temp;
485 485
486 if (code == ErrUnknownResponse) 486 if (code == ErrUnknownResponse)
487 temp = "Unknown response from server"; 487 temp = "Unknown response from server";
488 if (code == ErrLoginFailed) 488 if (code == ErrLoginFailed)
489 temp = "Login failed\nCheck user name and password"; 489 temp = "Login failed\nCheck user name and password";
490 490
491 if (code == QSocket::ErrHostNotFound) 491 if (code == QSocket::ErrHostNotFound)
492 temp = "host not found"; 492 temp = "host not found";
493 if (code == QSocket::ErrConnectionRefused) 493 if (code == QSocket::ErrConnectionRefused)
494 temp = "connection refused"; 494 temp = "connection refused";
495 if (code == QSocket::ErrSocketRead) 495 if (code == QSocket::ErrSocketRead)
496 temp = "socket packet error"; 496 temp = "socket packet error";
497 497
498 if (code != ErrCancel) { 498 if (code != ErrCancel) {
499 QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n"); 499 QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n");
500 } else { 500 } else {
501 status2Label->setText("Aborted by user"); 501 status2Label->setText("Aborted by user");
502 } 502 }
503 503
504 receiving = FALSE; 504 receiving = FALSE;
505 getMailButton->setEnabled(TRUE); 505 getMailButton->setEnabled(TRUE);
506 cancelButton->setEnabled(FALSE); 506 cancelButton->setEnabled(FALSE);
507 selectAccountMenu->setEnabled(TRUE); 507 selectAccountMenu->setEnabled(TRUE);
508} 508}
509 509
510void EmailClient::inboxItemSelected() 510void EmailClient::inboxItemSelected()
511{ 511{
512 item = (EmailListItem*) inboxView->selectedItem(); 512 item = (EmailListItem*) inboxView->selectedItem();
513 if (item != NULL) { 513 if (item != NULL) {
514 emit viewEmail(inboxView, item->getMail()); 514 emit viewEmail(inboxView, item->getMail());
515 } 515 }
516} 516}
517 517
518void EmailClient::outboxItemSelected() 518void EmailClient::outboxItemSelected()
519{ 519{
520 item = (EmailListItem*) outboxView->selectedItem(); 520 item = (EmailListItem*) outboxView->selectedItem();
521 if (item != NULL) { 521 if (item != NULL) {
522 emit viewEmail(outboxView, item->getMail()); 522 emit viewEmail(outboxView, item->getMail());
523 } 523 }
524 524
525} 525}
526 526
527void EmailClient::readMail() 527void EmailClient::readMail()
528{ 528{
529 Email mail; 529 Email mail;
530 int start, stop; 530 int start, stop;
531 QString s, del; 531 QString s, del;
532 532
533 QFile f(getPath(FALSE) + "inbox.txt"); 533 QFile f(getPath(FALSE) + "inbox.txt");
534// QFileInfo fi(f); 534// QFileInfo fi(f);
535 qDebug( f.name()); 535 qDebug( f.name());
536 536
537 if ( f.open(IO_ReadOnly) ) { // file opened successfully 537 if ( f.open(IO_ReadOnly) ) { // file opened successfully
538 QTextStream t( &f ); // use a text stream 538 QTextStream t( &f ); // use a text stream
539 s = t.read(); 539 s = t.read();
540 f.close(); 540 f.close();
541 541
542 start = 0; 542 start = 0;
543 del = "\n.\n"; 543 del = "\n.\n";
544 while ((uint) start < s.length()) { 544 while ((uint) start < s.length()) {
545 stop = s.find(del, start); 545 stop = s.find(del, start);
546 if (stop == -1) 546 if (stop == -1)
547 stop = s.length() - del.length(); 547 stop = s.length() - del.length();
548 548
549 mail.rawMail = s.mid(start, stop + del.length() - start ); 549 mail.rawMail = s.mid(start, stop + del.length() - start );
550 start = stop + del.length(); 550 start = stop + del.length();
551 mailArrived(mail, TRUE); 551 mailArrived(mail, TRUE);
552 } 552 }
553 } 553 }
554 554
555 QFile fo(getPath(FALSE) + "outbox.txt"); 555 QFile fo(getPath(FALSE) + "outbox.txt");
556 if ( fo.open(IO_ReadOnly) ) { // file opened successfully 556 if ( fo.open(IO_ReadOnly) ) { // file opened successfully
557 QTextStream t( &fo ); // use a text stream 557 QTextStream t( &fo ); // use a text stream
558 s = t.read(); 558 s = t.read();
559 fo.close(); 559 fo.close();
560 560
561 start = 0; 561 start = 0;
562 del = "\n.\n"; 562 del = "\n.\n";
563 while ((uint) start < s.length()) { 563 while ((uint) start < s.length()) {
564 stop = s.find(del, start); 564 stop = s.find(del, start);
565 if (stop == -1) 565 if (stop == -1)
566 stop = s.length() - del.length(); 566 stop = s.length() - del.length();
567 567
568 mail.rawMail = s.mid(start, stop + del.length() - start ); 568 mail.rawMail = s.mid(start, stop + del.length() - start );
569 start = stop + del.length(); 569 start = stop + del.length();
570 emailHandler->parse(mail.rawMail, lineShift, &mail); 570 emailHandler->parse(mail.rawMail, lineShift, &mail);
571 mail.sent = false; 571 mail.sent = false;
572 mail.received = false; 572 mail.received = false;
573 enqueMail(mail); 573 enqueMail(mail);
574 574
575 } 575 }
576 } 576 }
577} 577}
578 578
579void EmailClient::saveMail(QString fileName, QListView *view) 579void EmailClient::saveMail(QString fileName, QListView *view)
580{ 580{
581 QFile f(fileName); 581 QFile f(fileName);
582 Email *mail; 582 Email *mail;
583 583
584 if (! f.open(IO_WriteOnly) ) { 584 if (! f.open(IO_WriteOnly) ) {
585 qWarning("could not open file"); 585 qWarning("could not open file");
586 return; 586 return;
587 } 587 }
588 item = (EmailListItem *) view->firstChild(); 588 item = (EmailListItem *) view->firstChild();
589 qDebug (QString("Write : ") ); 589 qDebug (QString("Write : ") );
590 QTextStream t(&f); 590 QTextStream t(&f);
591 while (item != NULL) { 591 while (item != NULL) {
592 mail = item->getMail(); 592 mail = item->getMail();
593 qDebug(mail->rawMail); 593 qDebug(mail->rawMail);
594 qDebug(mail->recipients.first()); 594 qDebug(mail->recipients.first());
595 t << mail->rawMail; 595 t << mail->rawMail;
596 596
597 mailconf->setGroup(mail->id); 597 mailconf->setGroup(mail->id);
598 mailconf->writeEntry("mailread", mail->read); 598 mailconf->writeEntry("mailread", mail->read);
599 599
600 item = (EmailListItem *) item->nextSibling(); 600 item = (EmailListItem *) item->nextSibling();
601 } 601 }
602 f.close(); 602 f.close();
603} 603}
604 604
605//paths for mailit, is settings, inbox, enclosures 605//paths for mailit, is settings, inbox, enclosures
606QString EmailClient::getPath(bool enclosurePath) 606QString EmailClient::getPath(bool enclosurePath)
607{ 607{
608 QString basePath = "qtmail"; 608 QString basePath = "qtmail";
609 QString enclosures = "enclosures"; 609 QString enclosures = "enclosures";
610 610
611 QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); 611 QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath);
612 if ( !dir.exists() ) 612 if ( !dir.exists() )
613 dir.mkdir( dir.path() ); 613 dir.mkdir( dir.path() );
614 614
615 if (enclosurePath) { 615 if (enclosurePath) {
616 dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); 616 dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures);
617 617
618 if ( !dir.exists() ) 618 if ( !dir.exists() )
619 dir.mkdir( dir.path() ); 619 dir.mkdir( dir.path() );
620 620
621 return (dir.path() + "/"); 621 return (dir.path() + "/");
622 622
623 } 623 }
624 return (dir.path() + "/"); 624 return (dir.path() + "/");
625} 625}
626 626
627void EmailClient::readSettings() 627void EmailClient::readSettings()
628{ 628{
629 TextParser *p; 629 TextParser *p;
630 QString s; 630 QString s;
631 int pos, accountPos, y; 631 int pos, accountPos, y;
632 QFile f( getPath(FALSE) + "settings.txt"); 632 QFile f( getPath(FALSE) + "settings.txt");
633 633
634 if ( f.open(IO_ReadOnly) ) { // file opened successfully 634 if ( f.open(IO_ReadOnly) ) { // file opened successfully
635 QTextStream t( &f ); // use a text stream 635 QTextStream t( &f ); // use a text stream
636 s = t.read(); 636 s = t.read();
637 f.close(); 637 f.close();
638 638
639 p = new TextParser(s, "\n"); 639 p = new TextParser(s, "\n");
640 640
641 accountPos = 0; 641 accountPos = 0;
642 while ( (accountPos = p->find("ACCOUNTSTART",';', accountPos, TRUE)) != -1 ) { 642 while ( (accountPos = p->find("ACCOUNTSTART",';', accountPos, TRUE)) != -1 ) {
643 accountPos++; 643 accountPos++;
644 if ( (pos = p->find("ACCOUNTNAME",':', accountPos, TRUE)) != -1 ) 644 if ( (pos = p->find("ACCOUNTNAME",':', accountPos, TRUE)) != -1 )
645 account.accountName = p->getString(& ++pos, 'z', TRUE); 645 account.accountName = p->getString(& ++pos, 'z', TRUE);
646 if ( (pos = p->find("NAME",':', accountPos, TRUE)) != -1) 646 if ( (pos = p->find("NAME",':', accountPos, TRUE)) != -1)
647 account.name = p->getString(& ++pos, 'z', TRUE); 647 account.name = p->getString(& ++pos, 'z', TRUE);
648 if ( (pos = p->find("EMAIL",':', accountPos, TRUE)) != -1) 648 if ( (pos = p->find("EMAIL",':', accountPos, TRUE)) != -1)
649 account.emailAddress = p->getString(& ++pos, 'z', TRUE); 649 account.emailAddress = p->getString(& ++pos, 'z', TRUE);
650 if ( (pos = p->find("POPUSER",':', accountPos, TRUE)) != -1) 650 if ( (pos = p->find("POPUSER",':', accountPos, TRUE)) != -1)
651 account.popUserName = p->getString(& ++pos, 'z', TRUE); 651 account.popUserName = p->getString(& ++pos, 'z', TRUE);
652 if ( (pos = p->find("POPPASSWORD",':', accountPos, TRUE)) != -1) 652 if ( (pos = p->find("POPPASSWORD",':', accountPos, TRUE)) != -1)
653 account.popPasswd = p->getString(& ++pos, 'z', TRUE); 653 account.popPasswd = p->getString(& ++pos, 'z', TRUE);
654 if ( (pos = p->find("POPSERVER",':', accountPos, TRUE)) != -1) 654 if ( (pos = p->find("POPSERVER",':', accountPos, TRUE)) != -1)
655 account.popServer = p->getString(& ++pos, 'z', TRUE); 655 account.popServer = p->getString(& ++pos, 'z', TRUE);
656 if ( (pos = p->find("SMTPSERVER",':', accountPos, TRUE)) != -1) 656 if ( (pos = p->find("SMTPSERVER",':', accountPos, TRUE)) != -1)
657 account.smtpServer = p->getString(& ++pos, 'z', TRUE); 657 account.smtpServer = p->getString(& ++pos, 'z', TRUE);
658 if ( (pos = p->find("ACCOUNTID",':', accountPos, TRUE)) != -1) { 658 if ( (pos = p->find("ACCOUNTID",':', accountPos, TRUE)) != -1) {
659 s = p->getString(& ++pos, 'z', TRUE); 659 s = p->getString(& ++pos, 'z', TRUE);
660 account.id = s.toInt(); 660 account.id = s.toInt();
661 } 661 }
662 662
663 account.lastServerMailCount = 0; 663 account.lastServerMailCount = 0;
664 account.synchronize = FALSE; 664 account.synchronize = FALSE;
665 if ( (pos = p->find("SYNCHRONIZE",':', accountPos, TRUE)) != -1) { 665 if ( (pos = p->find("SYNCHRONIZE",':', accountPos, TRUE)) != -1) {
666 if (p->getString(& ++pos, 'z', TRUE).upper() == "YES") { 666 if (p->getString(& ++pos, 'z', TRUE).upper() == "YES") {
667 account.synchronize = TRUE; 667 account.synchronize = TRUE;
668 if ( (pos = p->find("LASTSERVERMAILCOUNT",':', accountPos, TRUE)) != -1) { 668 if ( (pos = p->find("LASTSERVERMAILCOUNT",':', accountPos, TRUE)) != -1) {
669 s = p->getString(& ++pos, 'z', TRUE); 669 s = p->getString(& ++pos, 'z', TRUE);
670 account.lastServerMailCount = s.toInt(); 670 account.lastServerMailCount = s.toInt();
671 } 671 }
672 } 672 }
673 } 673 }
674
675 if ( (pos = p->find("SYNCLIMIT",':', accountPos, TRUE)) != -1) {
676 account.syncLimit = p->getString(& ++pos, 'z', TRUE).toInt();
677 }
678
679
674 accountList.append(&account); 680 accountList.append(&account);
675 } 681 }
676 delete p; 682 delete p;
677 } 683 }
678 mailconf->setGroup("mailitglobal"); 684 mailconf->setGroup("mailitglobal");
679 if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) { 685 if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) {
680 mailIdCount = y; 686 mailIdCount = y;
681 } 687 }
682 if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) { 688 if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) {
683 accountIdCount = y; 689 accountIdCount = y;
684 } 690 }
685} 691}
686 692
687void EmailClient::saveSettings() 693void EmailClient::saveSettings()
688{ 694{
689 QString temp; 695 QString temp;
690 QFile f( getPath(FALSE) + "settings.txt"); 696 QFile f( getPath(FALSE) + "settings.txt");
691 MailAccount *accountPtr; 697 MailAccount *accountPtr;
692 698
693 if (! f.open(IO_WriteOnly) ) { 699 if (! f.open(IO_WriteOnly) ) {
694 qWarning("could not save settings file"); 700 qWarning("could not save settings file");
695 return; 701 return;
696 } 702 }
697 QTextStream t(&f); 703 QTextStream t(&f);
698 t << "#Settings for QPE Mailit program\n"; 704 t << "#Settings for QPE Mailit program\n";
699 705
700 for (accountPtr = accountList.first(); accountPtr != 0; 706 for (accountPtr = accountList.first(); accountPtr != 0;
701 accountPtr = accountList.next()) { 707 accountPtr = accountList.next()) {
702 708
703 t << "accountStart;\n"; 709 t << "accountStart;\n";
704 t << "AccountName: " + accountPtr->accountName + "\n"; 710 t << "AccountName: " + accountPtr->accountName + "\n";
705 t << "Name: " + accountPtr->name + "\n"; 711 t << "Name: " + accountPtr->name + "\n";
706 t << "Email: " + accountPtr->emailAddress + "\n"; 712 t << "Email: " + accountPtr->emailAddress + "\n";
707 t << "POPUser: " + accountPtr->popUserName + "\n"; 713 t << "POPUser: " + accountPtr->popUserName + "\n";
708 t << "POPPAssword: " + accountPtr->popPasswd + "\n"; 714 t << "POPPAssword: " + accountPtr->popPasswd + "\n";
709 t << "POPServer: " + accountPtr->popServer + "\n"; 715 t << "POPServer: " + accountPtr->popServer + "\n";
710 t << "SMTPServer: " + accountPtr->smtpServer + "\n"; 716 t << "SMTPServer: " + accountPtr->smtpServer + "\n";
711 t << "AccountId: " << accountPtr->id << "\n"; 717 t << "AccountId: " << accountPtr->id << "\n";
712 if (accountPtr->synchronize) { 718 if (accountPtr->synchronize) {
713 t << "Synchronize: Yes\n"; 719 t << "Synchronize: Yes\n";
714 t << "LastServerMailCount: "; 720 t << "LastServerMailCount: ";
715 t << accountPtr->lastServerMailCount << "\n"; 721 t << accountPtr->lastServerMailCount << "\n";
716 } else { 722 } else {
717 t << "Synchronize: No\n"; 723 t << "Synchronize: No\n";
718 } 724 }
725 t << "SyncLimit: ";
726 t << accountPtr->syncLimit << "\n";
719 t << "accountEnd;\n"; 727 t << "accountEnd;\n";
720 } 728 }
721 f.close(); 729 f.close();
722 730
723 mailconf->setGroup("mailitglobal"); 731 mailconf->setGroup("mailitglobal");
724 mailconf->writeEntry("mailidcount", mailIdCount); 732 mailconf->writeEntry("mailidcount", mailIdCount);
725 mailconf->writeEntry("accountidcount", accountIdCount); 733 mailconf->writeEntry("accountidcount", accountIdCount);
726} 734}
727 735
728void EmailClient::selectAccount(int id) 736void EmailClient::selectAccount(int id)
729{ 737{
730 if (accountList.count() > 0) { 738 if (accountList.count() > 0) {
731 currentAccount = accountList.at(id); 739 currentAccount = accountList.at(id);
732 emit newCaption("Mailit - " + currentAccount->accountName); 740 emit newCaption("Mailit - " + currentAccount->accountName);
733 getNewMail(); 741 getNewMail();
734 } else { 742 } else {
735 emit newCaption("Mailit ! No account defined"); 743 emit newCaption("Mailit ! No account defined");
736 } 744 }
737} 745}
738 746
739void EmailClient::editAccount(int id) 747void EmailClient::editAccount(int id)
740{ 748{
741 MailAccount *newAccount; 749 MailAccount *newAccount;
742 750
743 editAccountView = new EditAccount(this, "account", TRUE); 751 editAccountView = new EditAccount(this, "account", TRUE);
744 if (id == newAccountId) { //new account 752 if (id == newAccountId) { //new account
745 newAccount = new MailAccount; 753 newAccount = new MailAccount;
746 editAccountView->setAccount(newAccount); 754 editAccountView->setAccount(newAccount);
747 } else { 755 } else {
748 newAccount = accountList.at(id); 756 newAccount = accountList.at(id);
749 editAccountView->setAccount(newAccount, FALSE); 757 editAccountView->setAccount(newAccount, FALSE);
750 } 758 }
751 759
752 editAccountView->showMaximized(); 760 editAccountView->showMaximized();
753 editAccountView->exec(); 761 editAccountView->exec();
754 762
755 if (editAccountView->result() == QDialog::Accepted) { 763 if (editAccountView->result() == QDialog::Accepted) {
756 if (id == newAccountId) { 764 if (id == newAccountId) {
757 newAccount->id = accountIdCount; 765 newAccount->id = accountIdCount;
758 accountIdCount++; 766 accountIdCount++;
759 accountList.append(newAccount); 767 accountList.append(newAccount);
760 updateAccounts(); 768 updateAccounts();
761 } else { 769 } else {
762 updateAccounts(); 770 updateAccounts();
763 } 771 }
764 } 772 }
765 773
766 delete editAccountView; 774 delete editAccountView;
767} 775}
768 776
769void EmailClient::deleteAccount(int id) 777void EmailClient::deleteAccount(int id)
770{ 778{
771 MailAccount *newAccount; 779 MailAccount *newAccount;
772 QString message; 780 QString message;
773 781
774 newAccount = accountList.at(id); 782 newAccount = accountList.at(id);
775 message = "Delete account:\n" + newAccount->accountName; 783 message = "Delete account:\n" + newAccount->accountName;
776 switch( QMessageBox::warning( this, "Mailit", message, 784 switch( QMessageBox::warning( this, "Mailit", message,
777 "Yes", "No", 0, 0, 1 ) ) { 785 "Yes", "No", 0, 0, 1 ) ) {
778 786
779 case 0: accountList.remove(id); 787 case 0: accountList.remove(id);
780 updateAccounts(); 788 updateAccounts();
781 break; 789 break;
782 case 1: 790 case 1:
783 break; 791 break;
784 } 792 }
785} 793}
786 794
787void EmailClient::updateAccounts() 795void EmailClient::updateAccounts()
788{ 796{
789 MailAccount *accountPtr; 797 MailAccount *accountPtr;
790 798
791 //rebuild menus, clear all first 799 //rebuild menus, clear all first
792 editAccountMenu->clear(); 800 editAccountMenu->clear();
793 selectAccountMenu->clear(); 801 selectAccountMenu->clear();
794 deleteAccountMenu->clear(); 802 deleteAccountMenu->clear();
795 803
796 newAccountId = editAccountMenu->insertItem("New", this, 804 newAccountId = editAccountMenu->insertItem("New", this,
797 SLOT(editAccount(int)) ); 805 SLOT(editAccount(int)) );
798 editAccountMenu->insertSeparator(); 806 editAccountMenu->insertSeparator();
799 807
800 idCount = 0; 808 idCount = 0;
801 for (accountPtr = accountList.first(); accountPtr != 0; 809 for (accountPtr = accountList.first(); accountPtr != 0;
802 accountPtr = accountList.next()) { 810 accountPtr = accountList.next()) {
803 811
804 editAccountMenu->insertItem(accountPtr->accountName, 812 editAccountMenu->insertItem(accountPtr->accountName,
805 this, SLOT(editAccount(int)), 0, idCount); 813 this, SLOT(editAccount(int)), 0, idCount);
806 selectAccountMenu->insertItem(accountPtr->accountName, 814 selectAccountMenu->insertItem(accountPtr->accountName,
807 this, SLOT(selectAccount(int)), 0, idCount); 815 this, SLOT(selectAccount(int)), 0, idCount);
808 deleteAccountMenu->insertItem(accountPtr->accountName, 816 deleteAccountMenu->insertItem(accountPtr->accountName,
809 this, SLOT(deleteAccount(int)), 0, idCount); 817 this, SLOT(deleteAccount(int)), 0, idCount);
810 idCount++; 818 idCount++;
811 } 819 }
812} 820}
813 821
814void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) 822void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox)
815{ 823{
816 Email *mPtr; 824 Email *mPtr;
817 Enclosure *ePtr; 825 Enclosure *ePtr;
818 826
819 if (inbox) { 827 if (inbox) {
820 mPtr = mailItem->getMail(); 828 mPtr = mailItem->getMail();
821 829
822 //if mail is in queue for download, remove it from 830 //if mail is in queue for download, remove it from
823 //queue if possible 831 //queue if possible
824 if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { 832 if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) {
825 if ( !mPtr->downloaded ) 833 if ( !mPtr->downloaded )
826 mailDownloadList.remove(mPtr->serverId, mPtr->size); 834 mailDownloadList.remove(mPtr->serverId, mPtr->size);
827 } 835 }
828 836
829 mailconf->setGroup(mPtr->id); 837 mailconf->setGroup(mPtr->id);
830 mailconf->clearGroup(); 838 mailconf->clearGroup();
831 839
832 //delete any temporary attatchemnts storing 840 //delete any temporary attatchemnts storing
833 for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { 841 for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) {
834 if (ePtr->saved) { 842 if (ePtr->saved) {
835 QFile::remove( (ePtr->path + ePtr->name) ); 843 QFile::remove( (ePtr->path + ePtr->name) );
836 } 844 }
837 } 845 }
838 inboxView->takeItem(mailItem); 846 inboxView->takeItem(mailItem);
839 } else { 847 } else {
840 outboxView->takeItem(mailItem); 848 outboxView->takeItem(mailItem);
841 } 849 }
842} 850}
843 851
844void EmailClient::setMailSize(int size) 852void EmailClient::setMailSize(int size)
845{ 853{
846 progressBar->reset(); 854 progressBar->reset();
847 progressBar->setTotalSteps(size); 855 progressBar->setTotalSteps(size);
848} 856}
849 857
850void EmailClient::setTotalSize(int size) 858void EmailClient::setTotalSize(int size)
851{ 859{
852 860
853} 861}
854 862
855void EmailClient::setDownloadedSize(int size) 863void EmailClient::setDownloadedSize(int size)
856{ 864{
857 int total = progressBar->totalSteps(); 865 int total = progressBar->totalSteps();
858 866
859 if (size < total) { 867 if (size < total) {
860 progressBar->setProgress(size); 868 progressBar->setProgress(size);
861 } else { 869 } else {
862 progressBar->setProgress(total); 870 progressBar->setProgress(total);
863 } 871 }
864} 872}
diff --git a/noncore/net/mailit/emailhandler.cpp b/noncore/net/mailit/emailhandler.cpp
index 1be16d4..9c1c814 100644
--- a/noncore/net/mailit/emailhandler.cpp
+++ b/noncore/net/mailit/emailhandler.cpp
@@ -1,592 +1,601 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qfileinfo.h> 20#include <qfileinfo.h>
21#include <stdlib.h> 21#include <stdlib.h>
22#include <qapplication.h> 22#include <qapplication.h>
23#include <qmessagebox.h> 23#include <qmessagebox.h>
24#include <qcstring.h> 24#include <qcstring.h>
25#include "emailhandler.h" 25#include "emailhandler.h"
26#include <qpe/applnk.h> 26#include <qpe/applnk.h>
27#include <qpe/filemanager.h> 27#include <qpe/filemanager.h>
28 28
29QCollection::Item EnclosureList::newItem(QCollection::Item d) 29QCollection::Item EnclosureList::newItem(QCollection::Item d)
30{ 30{
31 return dupl( (Enclosure *) d); 31 return dupl( (Enclosure *) d);
32} 32}
33 33
34Enclosure* EnclosureList::dupl(Enclosure *in) 34Enclosure* EnclosureList::dupl(Enclosure *in)
35{ 35{
36 ac = new Enclosure(*in); 36 ac = new Enclosure(*in);
37 return ac; 37 return ac;
38} 38}
39 39
40EmailHandler::EmailHandler() 40EmailHandler::EmailHandler()
41{ 41{
42 smtpClient = new SmtpClient(); 42 smtpClient = new SmtpClient();
43 popClient = new PopClient(); 43 popClient = new PopClient();
44 44
45 connect(smtpClient, SIGNAL(errorOccurred(int)), this, 45 connect(smtpClient, SIGNAL(errorOccurred(int)), this,
46 SIGNAL(smtpError(int)) ); 46 SIGNAL(smtpError(int)) );
47 connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); 47 connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) );
48 connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, 48 connect(smtpClient, SIGNAL(updateStatus(const QString &)), this,
49 SIGNAL(updateSmtpStatus(const QString &)) ); 49 SIGNAL(updateSmtpStatus(const QString &)) );
50 50
51 connect(popClient, SIGNAL(errorOccurred(int)), this, 51 connect(popClient, SIGNAL(errorOccurred(int)), this,
52 SIGNAL(popError(int)) ); 52 SIGNAL(popError(int)) );
53 connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), 53 connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)),
54 this, SLOT(messageArrived(const QString &, int, uint, bool)) ); 54 this, SLOT(messageArrived(const QString &, int, uint, bool)) );
55 connect(popClient, SIGNAL(updateStatus(const QString &)), this, 55 connect(popClient, SIGNAL(updateStatus(const QString &)), this,
56 SIGNAL(updatePopStatus(const QString &)) ); 56 SIGNAL(updatePopStatus(const QString &)) );
57 connect(popClient, SIGNAL(mailTransfered(int)), this, 57 connect(popClient, SIGNAL(mailTransfered(int)), this,
58 SIGNAL(mailTransfered(int)) ); 58 SIGNAL(mailTransfered(int)) );
59 59
60 60
61 //relaying size information 61 //relaying size information
62 connect(popClient, SIGNAL(currentMailSize(int)), 62 connect(popClient, SIGNAL(currentMailSize(int)),
63 this, SIGNAL(currentMailSize(int)) ); 63 this, SIGNAL(currentMailSize(int)) );
64 connect(popClient, SIGNAL(downloadedSize(int)), 64 connect(popClient, SIGNAL(downloadedSize(int)),
65 this, SIGNAL(downloadedSize(int)) ); 65 this, SIGNAL(downloadedSize(int)) );
66} 66}
67 67
68void EmailHandler::sendMail(QList<Email> *mailList) 68void EmailHandler::sendMail(QList<Email> *mailList)
69{ 69{
70 Email *currentMail; 70 Email *currentMail;
71 QString temp; 71 QString temp;
72 QString userName = mailAccount.name; 72 QString userName = mailAccount.name;
73 userName += " <" + mailAccount.emailAddress + ">"; 73 userName += " <" + mailAccount.emailAddress + ">";
74 74
75 for (currentMail = mailList->first(); currentMail != 0; 75 for (currentMail = mailList->first(); currentMail != 0;
76 currentMail = mailList->next()) { 76 currentMail = mailList->next()) {
77 77
78 if (encodeMime(currentMail) == 0) { 78 if (encodeMime(currentMail) == 0) {
79 smtpClient->addMail(userName, currentMail->subject, 79 smtpClient->addMail(userName, currentMail->subject,
80 currentMail->recipients, currentMail->rawMail); 80 currentMail->recipients, currentMail->rawMail);
81 } else { //error 81 } else { //error
82 temp = tr("Could not locate all files in \nmail with subject: ") + 82 temp = tr("Could not locate all files in \nmail with subject: ") +
83 currentMail->subject; 83 currentMail->subject;
84 temp += tr("\nMail has NOT been sent"); 84 temp += tr("\nMail has NOT been sent");
85 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); 85 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n"));
86 86
87 } 87 }
88 } 88 }
89 smtpClient->newConnection(mailAccount.smtpServer, 25); 89 smtpClient->newConnection(mailAccount.smtpServer, 25);
90} 90}
91 91
92void EmailHandler::setAccount(MailAccount account) 92void EmailHandler::setAccount(MailAccount account)
93{ 93{
94 mailAccount = account; 94 mailAccount = account;
95} 95}
96 96
97void EmailHandler::getMail() 97void EmailHandler::getMail()
98{ 98{
99 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); 99 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
100 if (mailAccount.synchronize) { 100 if (mailAccount.synchronize) {
101 popClient->setSynchronize(mailAccount.lastServerMailCount); 101 popClient->setSynchronize(mailAccount.lastServerMailCount);
102 } else { 102 } else {
103 popClient->removeSynchronize(); 103 popClient->removeSynchronize();
104 } 104 }
105 105
106 headers = FALSE; 106 headers = FALSE;
107 popClient->headersOnly(headers, 0); 107 popClient->headersOnly(headers, 0);
108 popClient->newConnection(mailAccount.popServer, 110); 108 popClient->newConnection(mailAccount.popServer, 110);
109} 109}
110 110
111void EmailHandler::getMailHeaders() 111void EmailHandler::getMailHeaders()
112{ 112{
113 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); 113 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
114 if (mailAccount.synchronize) { 114 if (mailAccount.synchronize) {
115 popClient->setSynchronize(mailAccount.lastServerMailCount); 115 popClient->setSynchronize(mailAccount.lastServerMailCount);
116 } else { 116 } else {
117 popClient->removeSynchronize(); 117 popClient->removeSynchronize();
118 } 118 }
119 119
120 headers = TRUE; 120 headers = TRUE;
121 popClient->headersOnly(headers, 2000); //less than 2000, download all 121 popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all
122 popClient->newConnection(mailAccount.popServer, 110); 122 popClient->newConnection(mailAccount.popServer, 110);
123} 123}
124 124
125void EmailHandler::getMailByList(MailList *mailList) 125void EmailHandler::getMailByList(MailList *mailList)
126{ 126{
127 if (mailList->count() == 0) { //should not occur though 127 if (mailList->count() == 0) { //should not occur though
128 emit mailTransfered(0); 128 emit mailTransfered(0);
129 return; 129 return;
130 } 130 }
131 131
132 headers = FALSE; 132 headers = FALSE;
133 popClient->headersOnly(FALSE, 0); 133 popClient->headersOnly(FALSE, 0);
134 popClient->newConnection(mailAccount.popServer, 110); 134 popClient->newConnection(mailAccount.popServer, 110);
135 popClient->setSelectedMails(mailList); 135 popClient->setSelectedMails(mailList);
136} 136}
137 137
138void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) 138void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete)
139{ 139{
140 Email mail; 140 Email mail;
141 141
142 mail.rawMail = message; 142 mail.rawMail = message;
143 mail.serverId = id; 143 mail.serverId = id;
144 mail.size = size; 144 mail.size = size;
145 mail.downloaded = complete; 145 mail.downloaded = complete;
146 146
147 emit mailArrived(mail, FALSE); 147 emit mailArrived(mail, FALSE);
148} 148}
149 149
150bool EmailHandler::parse(QString in, QString lineShift, Email *mail) 150bool EmailHandler::parse(QString in, QString lineShift, Email *mail)
151{ 151{
152 QString temp, boundary; 152 QString temp, boundary;
153 int pos; 153 int pos;
154 QString delimiter, header, body, mimeHeader, mimeBody; 154 QString delimiter, header, body, mimeHeader, mimeBody;
155 QString content, contentType, contentAttribute, id, encoding; 155 QString content, contentType, contentAttribute, id, encoding;
156 QString fileName, storedName; 156 QString fileName, storedName;
157 int enclosureId = 0; 157 int enclosureId = 0;
158 158
159 mail->rawMail = in; 159 mail->rawMail = in;
160 mail->received = TRUE; 160 mail->received = TRUE;
161 mail->files.setAutoDelete(TRUE); 161 mail->files.setAutoDelete(TRUE);
162 162
163 temp = lineShift + "." + lineShift; 163 temp = lineShift + "." + lineShift;
164 164
165 if (in.right(temp.length()) != temp) { 165 if (in.right(temp.length()) != temp) {
166 qWarning(in.right(temp.length())); 166 qWarning(in.right(temp.length()));
167 qWarning(" . added at end of email as separator"); 167 qWarning(" . added at end of email as separator");
168 mail->rawMail += temp; 168 mail->rawMail += temp;
169 } 169 }
170 170
171 171
172 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" 172 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n"
173 pos = in.find(delimiter, 0, FALSE); 173 pos = in.find(delimiter, 0, FALSE);
174 header = in.left(pos); 174 header = in.left(pos);
175 body = in.right(in.length() - pos - delimiter.length()); 175 body = in.right(in.length() - pos - delimiter.length());
176 if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) 176 if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n'))
177 body.truncate(body.length()-2); 177 body.truncate(body.length()-2);
178 178
179 TextParser p(header, lineShift); 179 TextParser p(header, lineShift);
180 180
181 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { 181 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) {
182 pos++; 182 pos++;
183 if (p.separatorAt(pos) == ' ') { 183 if (p.separatorAt(pos) == ' ') {
184 mail->from = p.getString(&pos, '<', false); 184 mail->from = p.getString(&pos, '<', false);
185 mail->from = mail->from.stripWhiteSpace(); 185 mail->from = mail->from.stripWhiteSpace();
186 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { 186 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) {
187 mail->from = mail->from.left(mail->from.length() - 1); 187 mail->from = mail->from.left(mail->from.length() - 1);
188 mail->from = mail->from.right(mail->from.length() - 1); 188 mail->from = mail->from.right(mail->from.length() - 1);
189 } 189 }
190 pos++; 190 pos++;
191 mail->fromMail = p.getString(&pos, '>', false); 191 mail->fromMail = p.getString(&pos, '>', false);
192 } else { 192 } else {
193 if ((p.separatorAt(pos) == '<') 193 if ((p.separatorAt(pos) == '<')
194 || (p.separatorAt(pos) == ' ')) //No name.. nasty 194 || (p.separatorAt(pos) == ' ')) //No name.. nasty
195 pos++; 195 pos++;
196 pos++; 196 pos++;
197 mail->fromMail = p.getString(&pos, 'z', TRUE); 197 mail->fromMail = p.getString(&pos, 'z', TRUE);
198 if (mail->fromMail.at(mail->fromMail.length()-1) == '>') 198 if (mail->fromMail.at(mail->fromMail.length()-1) == '>')
199 mail->fromMail.truncate(mail->fromMail.length() - 1); 199 mail->fromMail.truncate(mail->fromMail.length() - 1);
200 mail->from=mail->fromMail; 200 mail->from=mail->fromMail;
201 } 201 }
202 } 202 }
203
204 //@@@ToDo: Rewrite the parser as To: stops at the first occurence- which is Delivered-To:
205 if (pos = p.find("TO",':', pos, TRUE) != -1)
206 {
207 pos++;
208 mail->recipients.append (p.getString(&pos, 'z', TRUE) );
209 }
210
211
212
203 if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { 213 if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) {
204 pos++; 214 pos++;
205 mail->subject = p.getString(&pos, 'z', TRUE); 215 mail->subject = p.getString(&pos, 'z', TRUE);
206 } 216 }
207 if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { 217 if ((pos = p.find("DATE",':', 0, TRUE)) != -1) {
208 pos++; 218 pos++;
209 mail->date = p.getString(&pos, 'z', true); 219 mail->date = p.getString(&pos, 'z', true);
210 } 220 }
211 if ((pos = p.find("TO",':', 0, TRUE)) != -1) { 221
212 pos++; 222
213 mail->recipients.append (p.getString(&pos, 'z', TRUE) ); 223
214 }
215 if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { 224 if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) {
216 pos++; 225 pos++;
217 if ( (p.wordAt(pos).upper() == "ID") && 226 if ( (p.wordAt(pos).upper() == "ID") &&
218 (p.separatorAt(pos) == ':') ) { 227 (p.separatorAt(pos) == ':') ) {
219 228
220 id = p.getString(&pos, 'z', TRUE); 229 id = p.getString(&pos, 'z', TRUE);
221 mail->id = id; 230 mail->id = id;
222 } 231 }
223 } 232 }
224 233
225 pos = 0; 234 pos = 0;
226 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { 235 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) {
227 pos++; 236 pos++;
228 if ( (p.wordAt(pos).upper() == "VERSION") && 237 if ( (p.wordAt(pos).upper() == "VERSION") &&
229 (p.separatorAt(pos) == ':') ) { 238 (p.separatorAt(pos) == ':') ) {
230 pos++; 239 pos++;
231 if (p.getString(&pos, 'z', true) == "1.0") { 240 if (p.getString(&pos, 'z', true) == "1.0") {
232 mail->mimeType = 1; 241 mail->mimeType = 1;
233 } 242 }
234 } 243 }
235 } 244 }
236 245
237 if (mail->mimeType == 1) { 246 if (mail->mimeType == 1) {
238 boundary = ""; 247 boundary = "";
239 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { 248 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) {
240 pos++; 249 pos++;
241 boundary = p.getString(&pos, 'z', true); 250 boundary = p.getString(&pos, 'z', true);
242 if (boundary[0] == '"') { 251 if (boundary[0] == '"') {
243 boundary = boundary.left(boundary.length() - 1); //strip " 252 boundary = boundary.left(boundary.length() - 1); //strip "
244 boundary = boundary.right(boundary.length() - 1); //strip " 253 boundary = boundary.right(boundary.length() - 1); //strip "
245 } 254 }
246 boundary = "--" + boundary; //create boundary field 255 boundary = "--" + boundary; //create boundary field
247 } 256 }
248 257
249 if (boundary == "") { //fooled by Mime-Version 258 if (boundary == "") { //fooled by Mime-Version
250 mail->body = body; 259 mail->body = body;
251 mail->bodyPlain = body; 260 mail->bodyPlain = body;
252 return mail; 261 return mail;
253 } 262 }
254 263
255 while (body.length() > 0) { 264 while (body.length() > 0) {
256 pos = body.find(boundary, 0, FALSE); 265 pos = body.find(boundary, 0, FALSE);
257 pos = body.find(delimiter, pos, FALSE); 266 pos = body.find(delimiter, pos, FALSE);
258 mimeHeader = body.left(pos); 267 mimeHeader = body.left(pos);
259 mimeBody = body.right(body.length() - pos - delimiter.length()); 268 mimeBody = body.right(body.length() - pos - delimiter.length());
260 TextParser bp(mimeHeader, lineShift); 269 TextParser bp(mimeHeader, lineShift);
261 270
262 contentType = ""; 271 contentType = "";
263 contentAttribute = ""; 272 contentAttribute = "";
264 fileName = ""; 273 fileName = "";
265 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) { 274 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) {
266 pos++; 275 pos++;
267 if ( (bp.wordAt(pos).upper() == "TYPE") && 276 if ( (bp.wordAt(pos).upper() == "TYPE") &&
268 (bp.separatorAt(pos) == ':') ) { 277 (bp.separatorAt(pos) == ':') ) {
269 contentType = bp.nextWord().upper(); 278 contentType = bp.nextWord().upper();
270 if (bp.nextSeparator() == '/') 279 if (bp.nextSeparator() == '/')
271 contentAttribute = bp.nextWord().upper(); 280 contentAttribute = bp.nextWord().upper();
272 content = contentType + "/" + contentAttribute; 281 content = contentType + "/" + contentAttribute;
273 } 282 }
274 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) { 283 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) {
275 pos++; 284 pos++;
276 encoding = bp.getString(&pos, 'z', TRUE); 285 encoding = bp.getString(&pos, 'z', TRUE);
277 } 286 }
278 287
279 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) { 288 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) {
280 pos++; 289 pos++;
281 fileName = bp.getString(&pos, 'z', TRUE); 290 fileName = bp.getString(&pos, 'z', TRUE);
282 fileName = fileName.right(fileName.length() - 1); 291 fileName = fileName.right(fileName.length() - 1);
283 fileName = fileName.left(fileName.length() - 1); 292 fileName = fileName.left(fileName.length() - 1);
284 } 293 }
285 294
286 } 295 }
287 pos = mimeBody.find(boundary, 0, FALSE); 296 pos = mimeBody.find(boundary, 0, FALSE);
288 if (pos == -1) //should not occur, malformed mail 297 if (pos == -1) //should not occur, malformed mail
289 pos = mimeBody.length(); 298 pos = mimeBody.length();
290 body = mimeBody.right(mimeBody.length() - pos); 299 body = mimeBody.right(mimeBody.length() - pos);
291 mimeBody = mimeBody.left(pos); 300 mimeBody = mimeBody.left(pos);
292 301
293 if (fileName != "") { //attatchments of some type, audio, image etc. 302 if (fileName != "") { //attatchments of some type, audio, image etc.
294 303
295 Enclosure e; 304 Enclosure e;
296 e.id = enclosureId; 305 e.id = enclosureId;
297 e.originalName = fileName; 306 e.originalName = fileName;
298 e.contentType = contentType; 307 e.contentType = contentType;
299 e.contentAttribute = contentAttribute; 308 e.contentAttribute = contentAttribute;
300 e.encoding = encoding; 309 e.encoding = encoding;
301 e.body = mimeBody; 310 e.body = mimeBody;
302 e.saved = FALSE; 311 e.saved = FALSE;
303 mail->addEnclosure(&e); 312 mail->addEnclosure(&e);
304 enclosureId++; 313 enclosureId++;
305 314
306 } else if (contentType == "TEXT") { 315 } else if (contentType == "TEXT") {
307 if (contentAttribute == "PLAIN") { 316 if (contentAttribute == "PLAIN") {
308 mail->body = mimeBody; 317 mail->body = mimeBody;
309 mail->bodyPlain = mimeBody; 318 mail->bodyPlain = mimeBody;
310 } 319 }
311 if (contentAttribute == "HTML") { 320 if (contentAttribute == "HTML") {
312 mail->body = mimeBody; 321 mail->body = mimeBody;
313 } 322 }
314 } 323 }
315 } 324 }
316 } else { 325 } else {
317 mail->bodyPlain = body; 326 mail->bodyPlain = body;
318 mail->body = body; 327 mail->body = body;
319 } 328 }
320 return TRUE; 329 return TRUE;
321} 330}
322 331
323bool EmailHandler::getEnclosure(Enclosure *ePtr) 332bool EmailHandler::getEnclosure(Enclosure *ePtr)
324{ 333{
325 QFile f(ePtr->path + ePtr->name); 334 QFile f(ePtr->path + ePtr->name);
326 char src[4]; 335 char src[4];
327 char *destPtr; 336 char *destPtr;
328 QByteArray buffer; 337 QByteArray buffer;
329 uint bufCount, pos, decodedCount, size, x; 338 uint bufCount, pos, decodedCount, size, x;
330 339
331 if (! f.open(IO_WriteOnly) ) { 340 if (! f.open(IO_WriteOnly) ) {
332 qWarning("could not save: " + ePtr->path + ePtr->name); 341 qWarning("could not save: " + ePtr->path + ePtr->name);
333 return FALSE; 342 return FALSE;
334 } 343 }
335 344
336 if (ePtr->encoding.upper() == "BASE64") { 345 if (ePtr->encoding.upper() == "BASE64") {
337 size = (ePtr->body.length() * 3 / 4); //approximate size (always above) 346 size = (ePtr->body.length() * 3 / 4); //approximate size (always above)
338 buffer.resize(size); 347 buffer.resize(size);
339 bufCount = 0; 348 bufCount = 0;
340 pos = 0; 349 pos = 0;
341 destPtr = buffer.data(); 350 destPtr = buffer.data();
342 351
343 while (pos < ePtr->body.length()) { 352 while (pos < ePtr->body.length()) {
344 decodedCount = 4; 353 decodedCount = 4;
345 x = 0; 354 x = 0;
346 while ( (x < 4) && (pos < ePtr->body.length()) ) { 355 while ( (x < 4) && (pos < ePtr->body.length()) ) {
347 src[x] = ePtr->body[pos].latin1(); 356 src[x] = ePtr->body[pos].latin1();
348 pos++; 357 pos++;
349 if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ') 358 if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ')
350 x--; 359 x--;
351 x++; 360 x++;
352 } 361 }
353 if (x > 1) { 362 if (x > 1) {
354 decodedCount = parse64base(src, destPtr); 363 decodedCount = parse64base(src, destPtr);
355 destPtr += decodedCount; 364 destPtr += decodedCount;
356 bufCount += decodedCount; 365 bufCount += decodedCount;
357 } 366 }
358 } 367 }
359 368
360 buffer.resize(bufCount); //set correct length of file 369 buffer.resize(bufCount); //set correct length of file
361 f.writeBlock(buffer); 370 f.writeBlock(buffer);
362 } else { 371 } else {
363 QTextStream t(&f); 372 QTextStream t(&f);
364 t << ePtr->body; 373 t << ePtr->body;
365 } 374 }
366 return TRUE; 375 return TRUE;
367} 376}
368 377
369int EmailHandler::parse64base(char *src, char *bufOut) { 378int EmailHandler::parse64base(char *src, char *bufOut) {
370 379
371 char c, z; 380 char c, z;
372 char li[4]; 381 char li[4];
373 int processed; 382 int processed;
374 383
375 //conversion table withouth table... 384 //conversion table withouth table...
376 for (int x = 0; x < 4; x++) { 385 for (int x = 0; x < 4; x++) {
377 c = src[x]; 386 c = src[x];
378 387
379 if ( (int) c >= 'A' && (int) c <= 'Z') 388 if ( (int) c >= 'A' && (int) c <= 'Z')
380 li[x] = (int) c - (int) 'A'; 389 li[x] = (int) c - (int) 'A';
381 if ( (int) c >= 'a' && (int) c <= 'z') 390 if ( (int) c >= 'a' && (int) c <= 'z')
382 li[x] = (int) c - (int) 'a' + 26; 391 li[x] = (int) c - (int) 'a' + 26;
383 if ( (int) c >= '0' && (int) c <= '9') 392 if ( (int) c >= '0' && (int) c <= '9')
384 li[x] = (int) c - (int) '0' + 52; 393 li[x] = (int) c - (int) '0' + 52;
385 if (c == '+') 394 if (c == '+')
386 li[x] = 62; 395 li[x] = 62;
387 if (c == '/') 396 if (c == '/')
388 li[x] = 63; 397 li[x] = 63;
389 } 398 }
390 399
391 processed = 1; 400 processed = 1;
392 bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits 401 bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits
393 bufOut[0] <<= 2; 402 bufOut[0] <<= 2;
394 z = li[1] >> 4; 403 z = li[1] >> 4;
395 bufOut[0] = bufOut[0] | z; //first byte retrived 404 bufOut[0] = bufOut[0] | z; //first byte retrived
396 405
397 if (src[2] != '=') { 406 if (src[2] != '=') {
398 bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits 407 bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits
399 bufOut[1] <<= 4; 408 bufOut[1] <<= 4;
400 z = li[2] >> 2; 409 z = li[2] >> 2;
401 bufOut[1] = bufOut[1] | z; //second byte retrived 410 bufOut[1] = bufOut[1] | z; //second byte retrived
402 processed++; 411 processed++;
403 412
404 if (src[3] != '=') { 413 if (src[3] != '=') {
405 bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits 414 bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits
406 bufOut[2] <<= 6; 415 bufOut[2] <<= 6;
407 z = li[3]; 416 z = li[3];
408 bufOut[2] = bufOut[2] | z; //third byte retrieved 417 bufOut[2] = bufOut[2] | z; //third byte retrieved
409 processed++; 418 processed++;
410 } 419 }
411 } 420 }
412 return processed; 421 return processed;
413} 422}
414 423
415int EmailHandler::encodeMime(Email *mail) 424int EmailHandler::encodeMime(Email *mail)
416{ 425{
417 426
418 QString fileName, fileType, contentType, newBody, boundary; 427 QString fileName, fileType, contentType, newBody, boundary;
419 Enclosure *ePtr; 428 Enclosure *ePtr;
420 429
421 QString userName = mailAccount.name; 430 QString userName = mailAccount.name;
422 if (userName.length()>0)//only embrace it if there is a user name 431 if (userName.length()>0)//only embrace it if there is a user name
423 userName += " <" + mailAccount.emailAddress + ">"; 432 userName += " <" + mailAccount.emailAddress + ">";
424 433
425 //add standard headers 434 //add standard headers
426 newBody = "From: " + userName + "\r\nTo: "; 435 newBody = "From: " + userName + "\r\nTo: ";
427 for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) { 436 for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) {
428 newBody += *it + " "; 437 newBody += *it + " ";
429 } 438 }
430 newBody += "\r\nSubject: " + mail->subject + "\r\n"; 439 newBody += "\r\nSubject: " + mail->subject + "\r\n";
431 440
432 if (mail->files.count() == 0) { //just a simple mail 441 if (mail->files.count() == 0) { //just a simple mail
433 newBody += "\r\n" + mail->body; 442 newBody += "\r\n" + mail->body;
434 mail->rawMail = newBody; 443 mail->rawMail = newBody;
435 return 0; 444 return 0;
436 } 445 }
437 446
438 //Build mime encoded mail 447 //Build mime encoded mail
439 boundary = "-----4345=next_bound=0495----"; 448 boundary = "-----4345=next_bound=0495----";
440 449
441 newBody += "Mime-Version: 1.0\r\n"; 450 newBody += "Mime-Version: 1.0\r\n";
442 newBody += "Content-Type: multipart/mixed; boundary=\"" + 451 newBody += "Content-Type: multipart/mixed; boundary=\"" +
443 boundary + "\"\r\n\r\n"; 452 boundary + "\"\r\n\r\n";
444 453
445 newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n"; 454 newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n";
446 newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n"; 455 newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n";
447 newBody += mail->body; 456 newBody += mail->body;
448 457
449 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 458 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
450 fileName = ePtr->originalName; 459 fileName = ePtr->originalName;
451 fileType = ePtr->contentType; 460 fileType = ePtr->contentType;
452 QFileInfo fi(fileName); 461 QFileInfo fi(fileName);
453 462
454 // This specification of contentType is temporary 463 // This specification of contentType is temporary
455 contentType = ""; 464 contentType = "";
456 if (fileType == "Picture") { 465 if (fileType == "Picture") {
457 contentType = "image/x-image"; 466 contentType = "image/x-image";
458 } else if (fileType == "Document") { 467 } else if (fileType == "Document") {
459 contentType = "text/plain"; 468 contentType = "text/plain";
460 } else if (fileType == "Sound") { 469 } else if (fileType == "Sound") {
461 contentType = "audio/x-wav"; 470 contentType = "audio/x-wav";
462 } else if (fileType == "Movie") { 471 } else if (fileType == "Movie") {
463 contentType = "video/mpeg"; 472 contentType = "video/mpeg";
464 } else { 473 } else {
465 contentType = "application/octet-stream"; 474 contentType = "application/octet-stream";
466 } 475 }
467 476
468 newBody += "\r\n\r\n--" + boundary + "\r\n"; 477 newBody += "\r\n\r\n--" + boundary + "\r\n";
469 newBody += "Content-Type: " + contentType + "; name=\"" + 478 newBody += "Content-Type: " + contentType + "; name=\"" +
470 fi.fileName() + "\"\r\n"; 479 fi.fileName() + "\"\r\n";
471 newBody += "Content-Transfer-Encoding: base64\r\n"; 480 newBody += "Content-Transfer-Encoding: base64\r\n";
472 newBody += "Content-Disposition: inline; filename=\"" + 481 newBody += "Content-Disposition: inline; filename=\"" +
473 fi.fileName() + "\"\r\n\r\n"; 482 fi.fileName() + "\"\r\n\r\n";
474 483
475 if (encodeFile(fileName, &newBody) == -1) //file not found? 484 if (encodeFile(fileName, &newBody) == -1) //file not found?
476 return -1; 485 return -1;
477 } 486 }
478 487
479 newBody += "\r\n\r\n--" + boundary + "--"; 488 newBody += "\r\n\r\n--" + boundary + "--";
480 mail->rawMail = newBody; 489 mail->rawMail = newBody;
481 490
482 return 0; 491 return 0;
483} 492}
484 493
485int EmailHandler::encodeFile(QString fileName, QString *toBody) 494int EmailHandler::encodeFile(QString fileName, QString *toBody)
486{ 495{
487 char *fileData; 496 char *fileData;
488 char *dataPtr; 497 char *dataPtr;
489 QString temp; 498 QString temp;
490 uint dataSize, count; 499 uint dataSize, count;
491 QFile f(fileName); 500 QFile f(fileName);
492 501
493 if (! f.open(IO_ReadOnly) ) { 502 if (! f.open(IO_ReadOnly) ) {
494 qWarning("could not open file: " + fileName); 503 qWarning("could not open file: " + fileName);
495 return -1; 504 return -1;
496 } 505 }
497 QTextStream s(&f); 506 QTextStream s(&f);
498 dataSize = f.size(); 507 dataSize = f.size();
499 fileData = (char *) malloc(dataSize + 3); 508 fileData = (char *) malloc(dataSize + 3);
500 s.readRawBytes(fileData, dataSize); 509 s.readRawBytes(fileData, dataSize);
501 510
502 temp = ""; 511 temp = "";
503 dataPtr = fileData; 512 dataPtr = fileData;
504 count = 0; 513 count = 0;
505 while (dataSize > 0) { 514 while (dataSize > 0) {
506 if (dataSize < 3) { 515 if (dataSize < 3) {
507 encode64base(dataPtr, &temp, dataSize); 516 encode64base(dataPtr, &temp, dataSize);
508 dataSize = 0; 517 dataSize = 0;
509 } else { 518 } else {
510 encode64base(dataPtr, &temp, 3); 519 encode64base(dataPtr, &temp, 3);
511 dataSize -= 3; 520 dataSize -= 3;
512 dataPtr += 3; 521 dataPtr += 3;
513 count += 4; 522 count += 4;
514 } 523 }
515 if (count > 72) { 524 if (count > 72) {
516 count = 0; 525 count = 0;
517 temp += "\r\n"; 526 temp += "\r\n";
518 } 527 }
519 } 528 }
520 toBody->append(temp); 529 toBody->append(temp);
521 530
522 delete(fileData); 531 delete(fileData);
523 f.close(); 532 f.close();
524 return 0; 533 return 0;
525} 534}
526 535
527void EmailHandler::encode64base(char *src, QString *dest, int len) 536void EmailHandler::encode64base(char *src, QString *dest, int len)
528{ 537{
529 QString temp; 538 QString temp;
530 uchar c; 539 uchar c;
531 uchar bufOut[4]; 540 uchar bufOut[4];
532 541
533 bufOut[0] = src[0]; 542 bufOut[0] = src[0];
534 bufOut[0] >>= 2; //Done byte 0 543 bufOut[0] >>= 2; //Done byte 0
535 544
536 bufOut[1] = src[0]; 545 bufOut[1] = src[0];
537 bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits 546 bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits
538 bufOut[1] <<= 4; //copy up 4 places 547 bufOut[1] <<= 4; //copy up 4 places
539 if (len > 1) { 548 if (len > 1) {
540 c = src[1]; 549 c = src[1];
541 } else { 550 } else {
542 c = 0; 551 c = 0;
543 } 552 }
544 553
545 c = c & (16 + 32 + 64 + 128); 554 c = c & (16 + 32 + 64 + 128);
546 c >>= 4; 555 c >>= 4;
547 bufOut[1] = bufOut[1] | c; //Done byte 1 556 bufOut[1] = bufOut[1] | c; //Done byte 1
548 557
549 bufOut[2] = src[1]; 558 bufOut[2] = src[1];
550 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8); 559 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8);
551 bufOut[2] <<= 2; 560 bufOut[2] <<= 2;
552 if (len > 2) { 561 if (len > 2) {
553 c = src[2]; 562 c = src[2];
554 } else { 563 } else {
555 c = 0; 564 c = 0;
556 } 565 }
557 c >>= 6; 566 c >>= 6;
558 bufOut[2] = bufOut[2] | c; 567 bufOut[2] = bufOut[2] | c;
559 568
560 bufOut[3] = src[2]; 569 bufOut[3] = src[2];
561 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32); 570 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32);
562 571
563 if (len == 1) { 572 if (len == 1) {
564 bufOut[2] = 64; 573 bufOut[2] = 64;
565 bufOut[3] = 64; 574 bufOut[3] = 64;
566 } 575 }
567 if (len == 2) { 576 if (len == 2) {
568 bufOut[3] = 64; 577 bufOut[3] = 64;
569 } 578 }
570 for (int x = 0; x < 4; x++) { 579 for (int x = 0; x < 4; x++) {
571 if (bufOut[x] <= 25) 580 if (bufOut[x] <= 25)
572 bufOut[x] += (uint) 'A'; 581 bufOut[x] += (uint) 'A';
573 else if (bufOut[x] >= 26 && bufOut[x] <= 51) 582 else if (bufOut[x] >= 26 && bufOut[x] <= 51)
574 bufOut[x] += (uint) 'a' - 26; 583 bufOut[x] += (uint) 'a' - 26;
575 else if (bufOut[x] >= 52 && bufOut[x] <= 61) 584 else if (bufOut[x] >= 52 && bufOut[x] <= 61)
576 bufOut[x] += (uint) '0' - 52; 585 bufOut[x] += (uint) '0' - 52;
577 else if (bufOut[x] == 62) 586 else if (bufOut[x] == 62)
578 bufOut[x] = '+'; 587 bufOut[x] = '+';
579 else if (bufOut[x] == 63) 588 else if (bufOut[x] == 63)
580 bufOut[x] = '/'; 589 bufOut[x] = '/';
581 else if (bufOut[x] == 64) 590 else if (bufOut[x] == 64)
582 bufOut[x] = '='; 591 bufOut[x] = '=';
583 592
584 dest->append(bufOut[x]); 593 dest->append(bufOut[x]);
585 } 594 }
586} 595}
587 596
588void EmailHandler::cancel() 597void EmailHandler::cancel()
589{ 598{
590 popClient->errorHandling(ErrCancel); 599 popClient->errorHandling(ErrCancel);
591 smtpClient->errorHandling(ErrCancel); 600 smtpClient->errorHandling(ErrCancel);
592} 601}
diff --git a/noncore/net/mailit/emailhandler.h b/noncore/net/mailit/emailhandler.h
index 17c4414..e47fd9a 100644
--- a/noncore/net/mailit/emailhandler.h
+++ b/noncore/net/mailit/emailhandler.h
@@ -1,147 +1,148 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef EmailHandler_H 20#ifndef EmailHandler_H
21#define EmailHandler_H 21#define EmailHandler_H
22 22
23#include <qobject.h> 23#include <qobject.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qdatetime.h> 25#include <qdatetime.h>
26#include <qlist.h> 26#include <qlist.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qfile.h> 28#include <qfile.h>
29#include <qstringlist.h> 29#include <qstringlist.h>
30#include <qcollection.h> 30#include <qcollection.h>
31 31
32#include "smtpclient.h" 32#include "smtpclient.h"
33#include "popclient.h" 33#include "popclient.h"
34#include "textparser.h" 34#include "textparser.h"
35#include "maillist.h" 35#include "maillist.h"
36 36
37struct Enclosure 37struct Enclosure
38{ 38{
39 int id; 39 int id;
40 QString originalName; 40 QString originalName;
41 QString name; 41 QString name;
42 QString path; 42 QString path;
43 QString contentType; 43 QString contentType;
44 QString contentAttribute; 44 QString contentAttribute;
45 QString encoding; 45 QString encoding;
46 QString body; //might use to much mem. check!! 46 QString body; //might use to much mem. check!!
47 bool saved, installed; 47 bool saved, installed;
48}; 48};
49 49
50class EnclosureList : public QList<Enclosure> 50class EnclosureList : public QList<Enclosure>
51{ 51{
52public: 52public:
53 Item newItem(Item d); 53 Item newItem(Item d);
54private: 54private:
55 Enclosure* dupl(Enclosure *in); 55 Enclosure* dupl(Enclosure *in);
56 Enclosure *ac; 56 Enclosure *ac;
57}; 57};
58 58
59struct Email 59struct Email
60{ 60{
61 QString id; 61 QString id;
62 QString from; 62 QString from;
63 QString fromMail; 63 QString fromMail;
64 QStringList recipients; 64 QStringList recipients;
65 QStringList carbonCopies; 65 QStringList carbonCopies;
66 QString date; 66 QString date;
67 QString subject; 67 QString subject;
68 QString body; 68 QString body;
69 QString bodyPlain; 69 QString bodyPlain;
70 bool sent, received, read, downloaded; 70 bool sent, received, read, downloaded;
71 QString rawMail; 71 QString rawMail;
72 int mimeType; //1 = Mime 1.0 72 int mimeType; //1 = Mime 1.0
73 int serverId; 73 int serverId;
74 int internalId; 74 int internalId;
75 int fromAccountId; 75 int fromAccountId;
76 QString contentType; //0 = text 76 QString contentType; //0 = text
77 QString contentAttribute; //0 = plain, 1 = html 77 QString contentAttribute; //0 = plain, 1 = html
78 EnclosureList files; 78 EnclosureList files;
79 uint size; 79 uint size;
80 80
81 void addEnclosure(Enclosure *e) 81 void addEnclosure(Enclosure *e)
82 { 82 {
83 files.append(e); 83 files.append(e);
84 } 84 }
85}; 85};
86 86
87struct MailAccount 87struct MailAccount
88{ 88{
89 QString accountName; 89 QString accountName;
90 QString name; 90 QString name;
91 QString emailAddress; 91 QString emailAddress;
92 QString popUserName; 92 QString popUserName;
93 QString popPasswd; 93 QString popPasswd;
94 QString popServer; 94 QString popServer;
95 QString smtpServer; 95 QString smtpServer;
96 bool synchronize; 96 bool synchronize;
97 int syncLimit;
97 int lastServerMailCount; 98 int lastServerMailCount;
98 int id; 99 int id;
99}; 100};
100 101
101 const int ErrUnknownResponse = 1001; 102 const int ErrUnknownResponse = 1001;
102 const int ErrLoginFailed = 1002; 103 const int ErrLoginFailed = 1002;
103 const int ErrCancel = 1003; 104 const int ErrCancel = 1003;
104 105
105 106
106class EmailHandler : public QObject 107class EmailHandler : public QObject
107{ 108{
108 Q_OBJECT 109 Q_OBJECT
109 110
110public: 111public:
111 EmailHandler(); 112 EmailHandler();
112 void setAccount(MailAccount account); 113 void setAccount(MailAccount account);
113 void sendMail(QList<Email> *mailList); 114 void sendMail(QList<Email> *mailList);
114 void getMail(); 115 void getMail();
115 void getMailHeaders(); 116 void getMailHeaders();
116 void getMailByList(MailList *mailList); 117 void getMailByList(MailList *mailList);
117 bool parse(QString in, QString lineShift, Email *mail); 118 bool parse(QString in, QString lineShift, Email *mail);
118 bool getEnclosure(Enclosure *ePtr); 119 bool getEnclosure(Enclosure *ePtr);
119 int parse64base(char *src, char *dest); 120 int parse64base(char *src, char *dest);
120 int encodeMime(Email *mail); 121 int encodeMime(Email *mail);
121 int encodeFile(QString fileName, QString *toBody); 122 int encodeFile(QString fileName, QString *toBody);
122 void encode64base(char *src, QString *dest, int len); 123 void encode64base(char *src, QString *dest, int len);
123 void cancel(); 124 void cancel();
124 125
125signals: 126signals:
126 void mailSent(); 127 void mailSent();
127 void smtpError(int); 128 void smtpError(int);
128 void popError(int); 129 void popError(int);
129 void mailArrived(const Email &, bool); 130 void mailArrived(const Email &, bool);
130 void updatePopStatus(const QString &); 131 void updatePopStatus(const QString &);
131 void updateSmtpStatus(const QString &); 132 void updateSmtpStatus(const QString &);
132 void mailTransfered(int); 133 void mailTransfered(int);
133 void mailboxSize(int); 134 void mailboxSize(int);
134 void currentMailSize(int); 135 void currentMailSize(int);
135 void downloadedSize(int); 136 void downloadedSize(int);
136 137
137public slots: 138public slots:
138 void messageArrived(const QString &, int id, uint size, bool complete); 139 void messageArrived(const QString &, int id, uint size, bool complete);
139 140
140private: 141private:
141 MailAccount mailAccount; 142 MailAccount mailAccount;
142 SmtpClient *smtpClient; 143 SmtpClient *smtpClient;
143 PopClient *popClient; 144 PopClient *popClient;
144 bool headers; 145 bool headers;
145}; 146};
146 147
147#endif 148#endif
diff --git a/noncore/net/mailit/emaillistitem.cpp b/noncore/net/mailit/emaillistitem.cpp
index d47b0b7..a325766 100644
--- a/noncore/net/mailit/emaillistitem.cpp
+++ b/noncore/net/mailit/emaillistitem.cpp
@@ -1,92 +1,97 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qstring.h> 20#include <qstring.h>
21#include <qpe/resource.h>
21#include "emaillistitem.h" 22#include "emaillistitem.h"
22 23
23EmailListItem::EmailListItem(QListView *parent, Email mailIn, bool inbox) 24EmailListItem::EmailListItem(QListView *parent, Email mailIn, bool inbox)
24 : QListViewItem(parent) 25 : QListViewItem(parent)
25{ 26{
26 QString temp; 27 QString temp;
27 28
28 mail = mailIn; 29 mail = mailIn;
29 30
30 if (inbox) { 31 if (inbox) {
31 setText(0, mail.from); 32 setText(0, mail.from);
32 } else { 33 } else {
33 QStringList::Iterator it = mail.recipients.begin(); 34 QStringList::Iterator it = mail.recipients.begin();
34 temp = *it; 35 temp = *it;
35 if (mail.recipients.count() > 1) 36 if (mail.recipients.count() > 1)
36 temp += "..."; 37 temp += "...";
37 setText(0, temp); 38 setText(0, temp);
38 } 39 }
39 setText(1, mail.subject); 40 setText(1, mail.subject);
40 41
42 if (mailIn.files.count()>0)
43 {
44 setPixmap(0, Resource::loadPixmap("mailit/attach"));
45 }
41 selected = FALSE; 46 selected = FALSE;
42} 47}
43 48
44Email* EmailListItem::getMail() 49Email* EmailListItem::getMail()
45{ 50{
46 return &mail; 51 return &mail;
47} 52}
48 53
49void EmailListItem::setMail(Email newMail) 54void EmailListItem::setMail(Email newMail)
50{ 55{
51 mail = newMail; 56 mail = newMail;
52 repaint(); 57 repaint();
53} 58}
54 59
55void EmailListItem::setItemSelected(bool enable) 60void EmailListItem::setItemSelected(bool enable)
56{ 61{
57 selected = enable; 62 selected = enable;
58 setSelected(enable); 63 setSelected(enable);
59 repaint(); 64 repaint();
60} 65}
61 66
62bool EmailListItem::isItemSelected() 67bool EmailListItem::isItemSelected()
63{ 68{
64 return selected; 69 return selected;
65} 70}
66 71
67void EmailListItem::paintCell( QPainter *p, const QColorGroup &cg, 72void EmailListItem::paintCell( QPainter *p, const QColorGroup &cg,
68 int column, int width, int alignment ) 73 int column, int width, int alignment )
69{ 74{
70 75
71 QColorGroup _cg( cg ); 76 QColorGroup _cg( cg );
72 QColor c = _cg.text(); 77 QColor c = _cg.text();
73 78
74 if ( (! mail.read) && (mail.received) ) 79 if ( (! mail.read) && (mail.received) )
75 _cg.setColor( QColorGroup::Text, Qt::blue); 80 _cg.setColor( QColorGroup::Text, Qt::blue);
76 if (!mail.downloaded) 81 if (!mail.downloaded)
77 _cg.setColor( QColorGroup::Text, Qt::red); 82 _cg.setColor( QColorGroup::Text, Qt::red);
78 83
79 /*if (selected) { 84 /*if (selected) {
80 _cg.setColor(QColorGroup::Base, Qt::blue); 85 _cg.setColor(QColorGroup::Base, Qt::blue);
81 _cg.setColor(QColorGroup::Text, Qt::yellow); 86 _cg.setColor(QColorGroup::Text, Qt::yellow);
82 if (isSelected()) { 87 if (isSelected()) {
83 _cg.setColor(QColorGroup::HighlightedText, Qt::yellow); 88 _cg.setColor(QColorGroup::HighlightedText, Qt::yellow);
84 } else { 89 } else {
85 _cg.setColor(QColorGroup::Highlight, Qt::blue); 90 _cg.setColor(QColorGroup::Highlight, Qt::blue);
86 } 91 }
87 } 92 }
88 */ 93 */
89 QListViewItem::paintCell( p, _cg, column, width, alignment ); 94 QListViewItem::paintCell( p, _cg, column, width, alignment );
90 95
91 _cg.setColor( QColorGroup::Text, c ); 96 _cg.setColor( QColorGroup::Text, c );
92} 97}
diff --git a/noncore/net/mailit/mailit.pro b/noncore/net/mailit/mailit.pro
index a404884..b262f9a 100644
--- a/noncore/net/mailit/mailit.pro
+++ b/noncore/net/mailit/mailit.pro
@@ -1,43 +1,60 @@
1TEMPLATE = app 1TEMPLATE = app
2CONFIG = qt warn_on release 2CONFIG = qt warn_on release
3HEADERS = emailclient.h \ 3HEADERS = emailclient.h \
4 emailhandler.h \ 4 emailhandler.h \
5 emaillistitem.h \ 5 emaillistitem.h \
6 mailitwindow.h \ 6 mailitwindow.h \
7 md5.h \ 7 md5.h \
8 popclient.h \ 8 popclient.h \
9 readmail.h \ 9 readmail.h \
10 smtpclient.h \ 10 smtpclient.h \
11 writemail.h \ 11 writemail.h \
12 textparser.h \ 12 textparser.h \
13 viewatt.h \ 13 viewatt.h \
14 addatt.h \ 14 addatt.h \
15 editaccount.h \ 15 editaccount.h \
16 maillist.h \ 16 maillist.h \
17 addresslist.h 17 addresslist.h
18SOURCES = emailclient.cpp \ 18SOURCES = emailclient.cpp \
19 emailhandler.cpp \ 19 emailhandler.cpp \
20 emaillistitem.cpp \ 20 emaillistitem.cpp \
21 mailitwindow.cpp \ 21 mailitwindow.cpp \
22 main.cpp \ 22 main.cpp \
23 md5.c \ 23 md5.c \
24 popclient.cpp \ 24 popclient.cpp \
25 readmail.cpp \ 25 readmail.cpp \
26 smtpclient.cpp \ 26 smtpclient.cpp \
27 writemail.cpp \ 27 writemail.cpp \
28 textparser.cpp \ 28 textparser.cpp \
29 viewatt.cpp \ 29 viewatt.cpp \
30 addatt.cpp \ 30 addatt.cpp \
31 editaccount.cpp \ 31 editaccount.cpp \
32 maillist.cpp \ 32 maillist.cpp \
33 addresslist.cpp 33 addresslist.cpp
34 34
35INCLUDEPATH += $(OPIEDIR)/include 35INCLUDEPATH += $(OPIEDIR)/include
36DEPENDPATH += $(OPIEDIR)/include 36DEPENDPATH += $(OPIEDIR)/include
37LIBS += -lqpe -lopie 37LIBS += -lqpe -lopie
38# -lssl 38# -lssl
39MOC_DIR=qpeobj 39MOC_DIR=qpeobj
40OBJECTS_DIR=qpeobj 40OBJECTS_DIR=qpeobj
41DESTDIR=$(OPIEDIR)/bin 41DESTDIR=$(OPIEDIR)/bin
42 42
43TRANSLATIONS = ../../../i18n/de/mailit.ts \
44 ../../../i18n/da/mailit.ts \
45 ../../../i18n/xx/mailit.ts \
46 ../../../i18n/en/mailit.ts \
47 ../../../i18n/es/mailit.ts \
48 ../../../i18n/fr/mailit.ts \
49 ../../../i18n/hu/mailit.ts \
50 ../../../i18n/ja/mailit.ts \
51 ../../../i18n/ko/mailit.ts \
52 ../../../i18n/no/mailit.ts \
53 ../../../i18n/pl/mailit.ts \
54 ../../../i18n/pt/mailit.ts \
55 ../../../i18n/pt_BR/mailit.ts \
56 ../../../i18n/sl/mailit.ts \
57 ../../../i18n/zh_CN/mailit.ts \
58 ../../../i18n/zh_TW/mailit.ts
59
43include ( $(OPIEDIR)/include.pro ) 60include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/net/mailit/readmail.cpp b/noncore/net/mailit/readmail.cpp
index 2011ecf..a5e7147 100644
--- a/noncore/net/mailit/readmail.cpp
+++ b/noncore/net/mailit/readmail.cpp
@@ -1,326 +1,326 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "readmail.h" 20#include "readmail.h"
21#include <qimage.h> 21#include <qimage.h>
22#include <qmime.h> 22#include <qmime.h>
23#include <qaction.h> 23#include <qaction.h>
24#include "resource.h" 24#include <qpe/resource.h>
25 25
26ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl ) 26ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl )
27 : QMainWindow(parent, name, fl) 27 : QMainWindow(parent, name, fl)
28{ 28{
29 plainTxt = FALSE; 29 plainTxt = FALSE;
30 30
31 init(); 31 init();
32 viewAtt = new ViewAtt(0, "View Attatchments"); 32 viewAtt = new ViewAtt(0, "View Attatchments");
33} 33}
34 34
35ReadMail::~ReadMail() 35ReadMail::~ReadMail()
36{ 36{
37 delete emailView->mimeSourceFactory(); 37 delete emailView->mimeSourceFactory();
38 delete viewAtt; 38 delete viewAtt;
39} 39}
40 40
41void ReadMail::init() 41void ReadMail::init()
42{ 42{
43 setToolBarsMovable(FALSE); 43 setToolBarsMovable(FALSE);
44 44
45 bar = new QToolBar(this); 45 bar = new QToolBar(this);
46 bar->setHorizontalStretchable( TRUE ); 46 bar->setHorizontalStretchable( TRUE );
47 47
48 menu = new QMenuBar( bar ); 48 menu = new QMenuBar( bar );
49 49
50 viewMenu = new QPopupMenu(menu); 50 viewMenu = new QPopupMenu(menu);
51 menu->insertItem( tr( "&View" ), viewMenu); 51 menu->insertItem( tr( "&View" ), viewMenu);
52 52
53 mailMenu = new QPopupMenu(menu); 53 mailMenu = new QPopupMenu(menu);
54 menu->insertItem( tr( "&Mail" ), mailMenu); 54 menu->insertItem( tr( "&Mail" ), mailMenu);
55 55
56 bar = new QToolBar(this); 56 bar = new QToolBar(this);
57 57
58 //reply dependant on viewing inbox 58 //reply dependant on viewing inbox
59 replyButton = new QAction( tr( "Reply" ), Resource::loadPixmap( "mailit/reply" ), 59 replyButton = new QAction( tr( "Reply" ), Resource::loadPixmap( "mailit/reply" ),
60 QString::null, 0, this, 0 ); 60 QString::null, 0, this, 0 );
61 connect(replyButton, SIGNAL(activated()), this, SLOT(reply()) ); 61 connect(replyButton, SIGNAL(activated()), this, SLOT(reply()) );
62 62
63 previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); 63 previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 );
64 connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) ); 64 connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) );
65 previousButton->addTo(bar); 65 previousButton->addTo(bar);
66 previousButton->addTo(viewMenu); 66 previousButton->addTo(viewMenu);
67 67
68 nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 ); 68 nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 );
69 connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) ); 69 connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) );
70 nextButton->addTo(bar); 70 nextButton->addTo(bar);
71 nextButton->addTo(viewMenu); 71 nextButton->addTo(viewMenu);
72 72
73 attatchmentsButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "mailit/attach" ), QString::null, 0, this, 0 ); 73 attatchmentsButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "mailit/attach" ), QString::null, 0, this, 0 );
74 connect( attatchmentsButton, SIGNAL( activated() ), this, 74 connect( attatchmentsButton, SIGNAL( activated() ), this,
75 SLOT( viewAttatchments() ) ); 75 SLOT( viewAttatchments() ) );
76 attatchmentsButton->addTo(bar); 76 attatchmentsButton->addTo(bar);
77 attatchmentsButton->addTo(viewMenu); 77 attatchmentsButton->addTo(viewMenu);
78 78
79 plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "DocsIcon" ), QString::null, 0, this, 0, TRUE); 79 plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "DocsIcon" ), QString::null, 0, this, 0, TRUE);
80 connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) ); 80 connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) );
81 plainTextButton->addTo(bar); 81 plainTextButton->addTo(bar);
82 plainTextButton->addTo(viewMenu); 82 plainTextButton->addTo(viewMenu);
83 83
84 deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); 84 deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 );
85 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); 85 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) );
86 deleteButton->addTo(bar); 86 deleteButton->addTo(bar);
87 deleteButton->addTo(mailMenu); 87 deleteButton->addTo(mailMenu);
88 88
89 viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close())); 89 viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close()));
90 90
91 emailView = new QTextView( this, "emailView" ); 91 emailView = new QTextView( this, "emailView" );
92 setCentralWidget(emailView); 92 setCentralWidget(emailView);
93 93
94 mime = new QMimeSourceFactory(); 94 mime = new QMimeSourceFactory();
95 emailView->setMimeSourceFactory(mime); 95 emailView->setMimeSourceFactory(mime);
96} 96}
97 97
98void ReadMail::updateView() 98void ReadMail::updateView()
99{ 99{
100 Enclosure *ePtr; 100 Enclosure *ePtr;
101 QString mailStringSize; 101 QString mailStringSize;
102 QString text, temp; 102 QString text, temp;
103 103
104 mail->read = TRUE; //mark as read 104 mail->read = TRUE; //mark as read
105 inbox = mail->received; 105 inbox = mail->received;
106 106
107 replyButton->removeFrom(mailMenu); 107 replyButton->removeFrom(mailMenu);
108 replyButton->removeFrom(bar); 108 replyButton->removeFrom(bar);
109 109
110 if (inbox == TRUE) { 110 if (inbox == TRUE) {
111 replyButton->addTo(bar); 111 replyButton->addTo(bar);
112 replyButton->addTo(mailMenu); 112 replyButton->addTo(mailMenu);
113 113
114 if (!mail->downloaded) { 114 if (!mail->downloaded) {
115 //report currently viewed mail so that it will be 115 //report currently viewed mail so that it will be
116 //placed first in the queue of new mails to download 116 //placed first in the queue of new mails to download
117 emit viewingMail(mail); 117 emit viewingMail(mail);
118 118
119 double mailSize = (double) mail->size; 119 double mailSize = (double) mail->size;
120 if (mailSize < 1024) { 120 if (mailSize < 1024) {
121 mailStringSize.setNum(mailSize); 121 mailStringSize.setNum(mailSize);
122 mailStringSize += " Bytes"; 122 mailStringSize += " Bytes";
123 } else if (mailSize < 1024*1024) { 123 } else if (mailSize < 1024*1024) {
124 mailStringSize.setNum( (mailSize / 1024), 'g', 2 ); 124 mailStringSize.setNum( (mailSize / 1024), 'g', 2 );
125 mailStringSize += " Kb"; 125 mailStringSize += " Kb";
126 } else { 126 } else {
127 mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3); 127 mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3);
128 mailStringSize += " Mb"; 128 mailStringSize += " Mb";
129 } 129 }
130 } 130 }
131 } 131 }
132 132
133 QMimeSourceFactory *mime = emailView->mimeSourceFactory(); 133 QMimeSourceFactory *mime = emailView->mimeSourceFactory();
134 134
135 if (! plainTxt) { //use RichText, inline pics etc. 135 if (! plainTxt) { //use RichText, inline pics etc.
136 emailView->setTextFormat(QTextView::RichText); 136 emailView->setTextFormat(QTextView::RichText);
137 text = "<b><big><center><font color=\"blue\">" + mail->subject 137 text = "<b><big><center><font color=\"blue\">" + mail->subject
138 +"</font></center></big></b><br>"; 138 +"</font></center></big></b><br>";
139 text += "<b>From: </b>" + mail->from + " <i>" + 139 text += "<b>From: </b>" + mail->from + " <i>" +
140 mail->fromMail + "</i><br>"; 140 mail->fromMail + "</i><br>";
141 141
142 text +="<b>To: </b>"; 142 text +="<b>To: </b>";
143 for (QStringList::Iterator it = mail->recipients.begin(); 143 for (QStringList::Iterator it = mail->recipients.begin();
144 it != mail->recipients.end(); ++it ) { 144 it != mail->recipients.end(); ++it ) {
145 text += *it + " "; 145 text += *it + " ";
146 } 146 }
147 text += "<br>" + mail->date; 147 text += "<br>" + mail->date;
148 148
149 if (mail->files.count() > 0) { 149 if (mail->files.count() > 0) {
150 text += "<br><b>Attatchments: </b>"; 150 text += "<br><b>Attatchments: </b>";
151 151
152 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 152 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
153 text += ePtr->originalName + " "; 153 text += ePtr->originalName + " ";
154 } 154 }
155 text += "<hr><br>" + mail->body; 155 text += "<hr><br>" + mail->body;
156 156
157 if (inbox) { 157 if (inbox) {
158 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 158 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
159 159
160 text += "<br><hr><b>Attatchment: </b>" + 160 text += "<br><hr><b>Attatchment: </b>" +
161 ePtr->originalName + "<hr>"; 161 ePtr->originalName + "<hr>";
162 162
163 if (ePtr->contentType == "TEXT") { 163 if (ePtr->contentType == "TEXT") {
164 QFile f(ePtr->path + ePtr->name); 164 QFile f(ePtr->path + ePtr->name);
165 165
166 if (f.open(IO_ReadOnly) ) { 166 if (f.open(IO_ReadOnly) ) {
167 QTextStream t(&f); 167 QTextStream t(&f);
168 temp = t.read(); 168 temp = t.read();
169 text += temp + "<br>"; 169 text += temp + "<br>";
170 f.close(); 170 f.close();
171 } else { 171 } else {
172 text += "<b>Could not locate file</b><br>"; 172 text += "<b>Could not locate file</b><br>";
173 } 173 }
174 174
175 } 175 }
176 if (ePtr->contentType == "IMAGE") { 176 if (ePtr->contentType == "IMAGE") {
177 // temp.setNum(emailView->width());//get display width 177 // temp.setNum(emailView->width());//get display width
178 // text += "<img width=" + temp +" src =""" + 178 // text += "<img width=" + temp +" src =""" +
179 // ePtr->originalName + """> </img>"; 179 // ePtr->originalName + """> </img>";
180 text += "<img src =""" + 180 text += "<img src =""" +
181 ePtr->originalName + """> </img>"; 181 ePtr->originalName + """> </img>";
182 mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) )); 182 mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) ));
183 } 183 }
184 } 184 }
185 } 185 }
186 } else { 186 } else {
187 if (mail->downloaded || !inbox) { 187 if (mail->downloaded || !inbox) {
188 text += "<hr><br>" + mail->body; 188 text += "<hr><br>" + mail->body;
189 } else { 189 } else {
190 text += "<hr><br><b> Awaiting download </b><br>"; 190 text += "<hr><br><b> Awaiting download </b><br>";
191 text += "Size of mail: " + mailStringSize; 191 text += "Size of mail: " + mailStringSize;
192 } 192 }
193 } 193 }
194 emailView->setText(text); 194 emailView->setText(text);
195 } else { // show plain txt mail 195 } else { // show plain txt mail
196 emailView->setTextFormat(QTextView::PlainText); 196 emailView->setTextFormat(QTextView::PlainText);
197 text = "Subject: " + mail->subject + "\n"; 197 text = "Subject: " + mail->subject + "\n";
198 text += "From: " + mail->from + " " + mail->fromMail + "\n"; 198 text += "From: " + mail->from + " " + mail->fromMail + "\n";
199 text += "To: "; 199 text += "To: ";
200 for (QStringList::Iterator it = mail->recipients.begin(); 200 for (QStringList::Iterator it = mail->recipients.begin();
201 it != mail->recipients.end(); ++it ) { 201 it != mail->recipients.end(); ++it ) {
202 text += *it + " "; 202 text += *it + " ";
203 } 203 }
204 text += "\nDate: " + mail->date + "\n"; 204 text += "\nDate: " + mail->date + "\n";
205 if (mail->files.count() > 0) { 205 if (mail->files.count() > 0) {
206 text += "Attatchments: "; 206 text += "Attatchments: ";
207 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 207 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
208 text += ePtr->originalName + " "; 208 text += ePtr->originalName + " ";
209 } 209 }
210 text += "\n\n"; 210 text += "\n\n";
211 } else text += "\n"; 211 } else text += "\n";
212 212
213 if (!inbox) { 213 if (!inbox) {
214 text += mail->body; 214 text += mail->body;
215 } else if (mail->downloaded) { 215 } else if (mail->downloaded) {
216 text += mail->bodyPlain; 216 text += mail->bodyPlain;
217 } else { 217 } else {
218 text += "\nAwaiting download\n"; 218 text += "\nAwaiting download\n";
219 text += "Size of mail: " + mailStringSize; 219 text += "Size of mail: " + mailStringSize;
220 } 220 }
221 221
222 emailView->setText(text); 222 emailView->setText(text);
223 } 223 }
224 224
225 if (mail->files.count() == 0) 225 if (mail->files.count() == 0)
226 attatchmentsButton->setEnabled(FALSE); 226 attatchmentsButton->setEnabled(FALSE);
227 else attatchmentsButton->setEnabled(TRUE); 227 else attatchmentsButton->setEnabled(TRUE);
228 228
229 setCaption("Examining mail: " + mail->subject); 229 setCaption("Examining mail: " + mail->subject);
230} 230}
231 231
232//update view with current EmailListItem (item) 232//update view with current EmailListItem (item)
233void ReadMail::update(QListView *thisView, Email *mailIn) 233void ReadMail::update(QListView *thisView, Email *mailIn)
234{ 234{
235 view = thisView; 235 view = thisView;
236 item = (EmailListItem *) view->selectedItem(); 236 item = (EmailListItem *) view->selectedItem();
237 mail = mailIn; 237 mail = mailIn;
238 updateView(); 238 updateView();
239 updateButtons(); 239 updateButtons();
240} 240}
241 241
242void ReadMail::mailUpdated(Email *mailIn) 242void ReadMail::mailUpdated(Email *mailIn)
243{ 243{
244 if (mailIn == mail) { 244 if (mailIn == mail) {
245 updateView(); 245 updateView();
246 } else { 246 } else {
247 updateButtons(); 247 updateButtons();
248 } 248 }
249} 249}
250 250
251void ReadMail::close() 251void ReadMail::close()
252{ 252{
253 emit cancelView(); 253 emit cancelView();
254} 254}
255 255
256//gets next item in listview, exits if there is no next 256//gets next item in listview, exits if there is no next
257void ReadMail::next() 257void ReadMail::next()
258{ 258{
259 item = (EmailListItem *) item->nextSibling(); 259 item = (EmailListItem *) item->nextSibling();
260 if (item != NULL) { 260 if (item != NULL) {
261 mail = item->getMail(); 261 mail = item->getMail();
262 updateView(); 262 updateView();
263 } 263 }
264 updateButtons(); 264 updateButtons();
265} 265}
266 266
267//gets previous item in listview, exits if there is no previous 267//gets previous item in listview, exits if there is no previous
268void ReadMail::previous() 268void ReadMail::previous()
269{ 269{
270 item = (EmailListItem *) item->itemAbove(); 270 item = (EmailListItem *) item->itemAbove();
271 if (item != NULL) { 271 if (item != NULL) {
272 mail = item->getMail(); 272 mail = item->getMail();
273 updateView(); 273 updateView();
274 } 274 }
275 updateButtons(); 275 updateButtons();
276} 276}
277 277
278//deletes item, tries bringing up next or previous, exits if unsucessful 278//deletes item, tries bringing up next or previous, exits if unsucessful
279void ReadMail::deleteItem() 279void ReadMail::deleteItem()
280{ 280{
281 EmailListItem *temp = item; 281 EmailListItem *temp = item;
282 temp = (EmailListItem *) item->nextSibling();//trybelow 282 temp = (EmailListItem *) item->nextSibling();//trybelow
283 if (temp == NULL) 283 if (temp == NULL)
284 temp = (EmailListItem *) item->itemAbove(); //try above 284 temp = (EmailListItem *) item->itemAbove(); //try above
285 285
286 emit removeItem(item, inbox); 286 emit removeItem(item, inbox);
287 287
288 item = temp; 288 item = temp;
289 if (item != NULL) { //more items in list 289 if (item != NULL) { //more items in list
290 mail = item->getMail(); 290 mail = item->getMail();
291 updateView(); 291 updateView();
292 updateButtons(); 292 updateButtons();
293 } else close(); //no more items to see 293 } else close(); //no more items to see
294} 294}
295 295
296void ReadMail::updateButtons() 296void ReadMail::updateButtons()
297{ 297{
298 EmailListItem *temp; 298 EmailListItem *temp;
299 299
300 temp = item; 300 temp = item;
301 if ((EmailListItem *) temp->nextSibling() == NULL) 301 if ((EmailListItem *) temp->nextSibling() == NULL)
302 nextButton->setEnabled(FALSE); 302 nextButton->setEnabled(FALSE);
303 else nextButton->setEnabled(TRUE); 303 else nextButton->setEnabled(TRUE);
304 304
305 temp = item; 305 temp = item;
306 if ((EmailListItem *) temp->itemAbove() == NULL) 306 if ((EmailListItem *) temp->itemAbove() == NULL)
307 previousButton->setEnabled(FALSE); 307 previousButton->setEnabled(FALSE);
308 else previousButton->setEnabled(TRUE); 308 else previousButton->setEnabled(TRUE);
309} 309}
310 310
311void ReadMail::shiftText() 311void ReadMail::shiftText()
312{ 312{
313 plainTxt = ! plainTxt; 313 plainTxt = ! plainTxt;
314 updateView(); 314 updateView();
315} 315}
316 316
317void ReadMail::viewAttatchments() 317void ReadMail::viewAttatchments()
318{ 318{
319 viewAtt->update(mail, inbox); 319 viewAtt->update(mail, inbox);
320 viewAtt->showMaximized(); 320 viewAtt->showMaximized();
321} 321}
322 322
323void ReadMail::reply() 323void ReadMail::reply()
324{ 324{
325 emit replyRequested(*mail); 325 emit replyRequested(*mail);
326} 326}
diff --git a/noncore/net/mailit/writemail.cpp b/noncore/net/mailit/writemail.cpp
index a45cfd2..38a2596 100644
--- a/noncore/net/mailit/writemail.cpp
+++ b/noncore/net/mailit/writemail.cpp
@@ -1,298 +1,298 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qmessagebox.h> 20#include <qmessagebox.h>
21#include "writemail.h" 21#include "writemail.h"
22#include "resource.h" 22#include <qpe/resource.h>
23 23
24WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl ) 24WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl )
25 : QMainWindow( parent, name, fl ) 25 : QMainWindow( parent, name, fl )
26{ 26{
27 showingAddressList = FALSE; 27 showingAddressList = FALSE;
28 init(); 28 init();
29 29
30 addAtt = new AddAtt(0, "Add Attatchments"); 30 addAtt = new AddAtt(0, "Add Attatchments");
31} 31}
32 32
33WriteMail::~WriteMail() 33WriteMail::~WriteMail()
34{ 34{
35 delete addAtt; 35 delete addAtt;
36} 36}
37 37
38void WriteMail::setAddressList(AddressList *list) 38void WriteMail::setAddressList(AddressList *list)
39{ 39{
40 Contact *cPtr; 40 Contact *cPtr;
41 41
42 addressList = list; 42 addressList = list;
43 43
44 addressView->clear(); 44 addressView->clear();
45 QList<Contact> *cListPtr = addressList->getContactList(); 45 QList<Contact> *cListPtr = addressList->getContactList();
46 QListViewItem *item; 46 QListViewItem *item;
47 for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) { 47 for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) {
48 item = new QListViewItem(addressView, cPtr->name, cPtr->email); 48 item = new QListViewItem(addressView, cPtr->name, cPtr->email);
49 } 49 }
50} 50}
51 51
52void WriteMail::init() 52void WriteMail::init()
53{ 53{
54 setToolBarsMovable(FALSE); 54 setToolBarsMovable(FALSE);
55 55
56 bar = new QToolBar(this); 56 bar = new QToolBar(this);
57 bar->setHorizontalStretchable( TRUE ); 57 bar->setHorizontalStretchable( TRUE );
58 58
59 menu = new QMenuBar( bar ); 59 menu = new QMenuBar( bar );
60 60
61 mailMenu = new QPopupMenu(menu); 61 mailMenu = new QPopupMenu(menu);
62 menu->insertItem( tr( "&Mail" ), mailMenu); 62 menu->insertItem( tr( "&Mail" ), mailMenu);
63 addMenu = new QPopupMenu(menu); 63 addMenu = new QPopupMenu(menu);
64 menu->insertItem( tr( "&Add" ), addMenu); 64 menu->insertItem( tr( "&Add" ), addMenu);
65 65
66 bar = new QToolBar(this); 66 bar = new QToolBar(this);
67 attatchButton = new QAction(tr("Attatchment"), Resource::loadPixmap("mailit/attach"), QString::null, 0, this, 0); 67 attatchButton = new QAction(tr("Attatchment"), Resource::loadPixmap("mailit/attach"), QString::null, 0, this, 0);
68 attatchButton->addTo(bar); 68 attatchButton->addTo(bar);
69 attatchButton->addTo(addMenu); 69 attatchButton->addTo(addMenu);
70 connect( attatchButton, SIGNAL( activated() ), this, SLOT( attatchFile() ) ); 70 connect( attatchButton, SIGNAL( activated() ), this, SLOT( attatchFile() ) );
71 71
72 confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0); 72 confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0);
73 confirmButton->addTo(bar); 73 confirmButton->addTo(bar);
74 confirmButton->addTo(mailMenu); 74 confirmButton->addTo(mailMenu);
75 connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) ); 75 connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) );
76 76
77 newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0); 77 newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0);
78 newButton->addTo(mailMenu); 78 newButton->addTo(mailMenu);
79 connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) ); 79 connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) );
80 80
81 widget = new QWidget(this, "widget"); 81 widget = new QWidget(this, "widget");
82 grid = new QGridLayout( widget ); 82 grid = new QGridLayout( widget );
83 83
84 recipientsBox = new QComboBox( FALSE, widget, "toLabel" ); 84 recipientsBox = new QComboBox( FALSE, widget, "toLabel" );
85 recipientsBox->insertItem( tr( "To:" ) ); 85 recipientsBox->insertItem( tr( "To:" ) );
86 recipientsBox->insertItem( tr( "CC:" ) ); 86 recipientsBox->insertItem( tr( "CC:" ) );
87 recipientsBox->setCurrentItem(0); 87 recipientsBox->setCurrentItem(0);
88 grid->addWidget( recipientsBox, 0, 0 ); 88 grid->addWidget( recipientsBox, 0, 0 );
89 89
90 subjetLabel = new QLabel( widget, "subjetLabel" ); 90 subjetLabel = new QLabel( widget, "subjetLabel" );
91 subjetLabel->setText( tr( "Subject:" ) ); 91 subjetLabel->setText( tr( "Subject:" ) );
92 92
93 grid->addWidget( subjetLabel, 1, 0 ); 93 grid->addWidget( subjetLabel, 1, 0 );
94 94
95 ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" ); 95 ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" );
96 ToolButton13_2->setText( tr( "..." ) ); 96 ToolButton13_2->setText( tr( "..." ) );
97 grid->addWidget( ToolButton13_2, 1, 2 ); 97 grid->addWidget( ToolButton13_2, 1, 2 );
98 98
99 subjectInput = new QLineEdit( widget, "subjectInput" ); 99 subjectInput = new QLineEdit( widget, "subjectInput" );
100 grid->addWidget( subjectInput, 1, 1 ); 100 grid->addWidget( subjectInput, 1, 1 );
101 101
102 toInput = new QLineEdit( widget, "toInput" ); 102 toInput = new QLineEdit( widget, "toInput" );
103 grid->addWidget( toInput, 0, 1 ); 103 grid->addWidget( toInput, 0, 1 );
104 104
105 addressButton = new QToolButton( widget, "addressButton" ); 105 addressButton = new QToolButton( widget, "addressButton" );
106 addressButton->setPixmap( Resource::loadPixmap("AddressBook") ); 106 addressButton->setPixmap( Resource::loadPixmap("AddressBook") );
107 addressButton->setToggleButton(TRUE); 107 addressButton->setToggleButton(TRUE);
108 grid->addWidget( addressButton, 0, 2 ); 108 grid->addWidget( addressButton, 0, 2 );
109 connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) ); 109 connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) );
110 110
111 emailInput = new QMultiLineEdit( widget, "emailInput" ); 111 emailInput = new QMultiLineEdit( widget, "emailInput" );
112 grid->addMultiCellWidget( emailInput, 2, 2, 0, 2); 112 grid->addMultiCellWidget( emailInput, 2, 2, 0, 2);
113 113
114 114
115 addressView = new QListView( widget, "addressView"); 115 addressView = new QListView( widget, "addressView");
116 addressView->addColumn("Name"); 116 addressView->addColumn("Name");
117 addressView->addColumn("EMail"); 117 addressView->addColumn("EMail");
118 addressView->setAllColumnsShowFocus(TRUE); 118 addressView->setAllColumnsShowFocus(TRUE);
119 addressView->setMultiSelection(TRUE); 119 addressView->setMultiSelection(TRUE);
120 addressView->hide(); 120 addressView->hide();
121 grid->addMultiCellWidget( addressView, 3, 3, 0, 2); 121 grid->addMultiCellWidget( addressView, 3, 3, 0, 2);
122 122
123 okButton = new QToolButton(bar, "ok"); 123 okButton = new QToolButton(bar, "ok");
124 okButton->setPixmap( Resource::loadPixmap("enter") ); 124 okButton->setPixmap( Resource::loadPixmap("enter") );
125 okButton->hide(); 125 okButton->hide();
126 connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) ); 126 connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) );
127 127
128 setCentralWidget(widget); 128 setCentralWidget(widget);
129} 129}
130 130
131void WriteMail::reject() 131void WriteMail::reject()
132{ 132{
133 emit cancelMail(); 133 emit cancelMail();
134} 134}
135 135
136// need to insert date 136// need to insert date
137void WriteMail::accept() 137void WriteMail::accept()
138{ 138{
139 QStringList attatchedFiles, attatchmentsType; 139 QStringList attatchedFiles, attatchmentsType;
140 int idCount = 0; 140 int idCount = 0;
141 141
142 if (toInput->text() == "") { 142 if (toInput->text() == "") {
143 QMessageBox::warning(this,"No recipient", "Send mail to whom?", "OK\n"); 143 QMessageBox::warning(this,"No recipient", "Send mail to whom?", "OK\n");
144 return; 144 return;
145 } 145 }
146 if (! getRecipients() ) { 146 if (! getRecipients() ) {
147 QMessageBox::warning(this,"Incorrect recipient separator", 147 QMessageBox::warning(this,"Incorrect recipient separator",
148 "Recipients must be separated by ;\nand be valid emailaddresses", "OK\n"); 148 "Recipients must be separated by ;\nand be valid emailaddresses", "OK\n");
149 return; 149 return;
150 } 150 }
151 mail.subject = subjectInput->text(); 151 mail.subject = subjectInput->text();
152 mail.body = emailInput->text(); 152 mail.body = emailInput->text();
153 mail.sent = false; 153 mail.sent = false;
154 mail.received = false; 154 mail.received = false;
155 mail.rawMail = "To: "; 155 mail.rawMail = "To: ";
156 156
157 for (QStringList::Iterator it = mail.recipients.begin(); 157 for (QStringList::Iterator it = mail.recipients.begin();
158 it != mail.recipients.end(); ++it) { 158 it != mail.recipients.end(); ++it) {
159 159
160 mail.rawMail += (*it); 160 mail.rawMail += (*it);
161 mail.rawMail += ",\n"; 161 mail.rawMail += ",\n";
162 } 162 }
163 mail.rawMail.truncate(mail.rawMail.length()-2); 163 mail.rawMail.truncate(mail.rawMail.length()-2);
164 mail.rawMail += mail.from; 164 mail.rawMail += mail.from;
165 mail.rawMail += "\nSubject: "; 165 mail.rawMail += "\nSubject: ";
166 mail.rawMail += mail.subject; 166 mail.rawMail += mail.subject;
167 mail.rawMail += "\n\n"; 167 mail.rawMail += "\n\n";
168 168
169 attatchedFiles = addAtt->returnAttatchedFiles(); 169 attatchedFiles = addAtt->returnAttatchedFiles();
170 attatchmentsType = addAtt->returnFileTypes(); 170 attatchmentsType = addAtt->returnFileTypes();
171 171
172 QStringList::Iterator itType = attatchmentsType.begin(); 172 QStringList::Iterator itType = attatchmentsType.begin();
173 173
174 Enclosure e; 174 Enclosure e;
175 for ( QStringList::Iterator it = attatchedFiles.begin(); it != attatchedFiles.end(); ++it ) { 175 for ( QStringList::Iterator it = attatchedFiles.begin(); it != attatchedFiles.end(); ++it ) {
176 e.id = idCount; 176 e.id = idCount;
177 e.originalName = (*it).latin1(); 177 e.originalName = (*it).latin1();
178 e.contentType = (*itType).latin1(); 178 e.contentType = (*itType).latin1();
179 e.contentAttribute = (*itType).latin1(); 179 e.contentAttribute = (*itType).latin1();
180 e.saved = TRUE; 180 e.saved = TRUE;
181 mail.addEnclosure(&e); 181 mail.addEnclosure(&e);
182 182
183 itType++; 183 itType++;
184 idCount++; 184 idCount++;
185 } 185 }
186 mail.rawMail += mail.body; 186 mail.rawMail += mail.body;
187 mail.rawMail += "\n"; 187 mail.rawMail += "\n";
188 mail.rawMail += ".\n"; 188 mail.rawMail += ".\n";
189 emit sendMailRequested(mail); 189 emit sendMailRequested(mail);
190 addAtt->clear(); 190 addAtt->clear();
191} 191}
192 192
193void WriteMail::getAddress() 193void WriteMail::getAddress()
194{ 194{
195 showingAddressList = !showingAddressList; 195 showingAddressList = !showingAddressList;
196 196
197 if (showingAddressList) { 197 if (showingAddressList) {
198 emailInput->hide(); 198 emailInput->hide();
199 addressView->show(); 199 addressView->show();
200 okButton->show(); 200 okButton->show();
201 201
202 } else { 202 } else {
203 addressView->hide(); 203 addressView->hide();
204 okButton->hide(); 204 okButton->hide();
205 emailInput->show(); 205 emailInput->show();
206 } 206 }
207} 207}
208 208
209void WriteMail::attatchFile() 209void WriteMail::attatchFile()
210{ 210{
211 addAtt->showMaximized(); 211 addAtt->showMaximized();
212} 212}
213 213
214void WriteMail::reply(Email replyMail) 214void WriteMail::reply(Email replyMail)
215{ 215{
216 int pos; 216 int pos;
217 217
218 mail = replyMail; 218 mail = replyMail;
219 mail.files.clear(); 219 mail.files.clear();
220 220
221 toInput->setText(mail.fromMail); 221 toInput->setText(mail.fromMail);
222 subjectInput->setText("Re: " + mail.subject); 222 subjectInput->setText("Re: " + mail.subject);
223 223
224 pos = 0; 224 pos = 0;
225 mail.body.insert(pos, ">>"); 225 mail.body.insert(pos, ">>");
226 while (pos != -1) { 226 while (pos != -1) {
227 pos = mail.body.find('\n', pos); 227 pos = mail.body.find('\n', pos);
228 if (pos != -1) 228 if (pos != -1)
229 mail.body.insert(++pos, ">>"); 229 mail.body.insert(++pos, ">>");
230 } 230 }
231 231
232 emailInput->setText(mail.body); 232 emailInput->setText(mail.body);
233} 233}
234 234
235bool WriteMail::getRecipients() 235bool WriteMail::getRecipients()
236{ 236{
237 QString str, temp; 237 QString str, temp;
238 int pos = 0; 238 int pos = 0;
239 239
240 mail.recipients.clear(); 240 mail.recipients.clear();
241 241
242 temp = toInput->text(); 242 temp = toInput->text();
243 while ( (pos = temp.find(';')) != -1) { 243 while ( (pos = temp.find(';')) != -1) {
244 str = temp.left(pos).stripWhiteSpace(); 244 str = temp.left(pos).stripWhiteSpace();
245 temp = temp.right(temp.length() - (pos + 1)); 245 temp = temp.right(temp.length() - (pos + 1));
246 if ( str.find('@') == -1) 246 if ( str.find('@') == -1)
247 return false; 247 return false;
248 mail.recipients.append(str); 248 mail.recipients.append(str);
249 addressList->addContact(str, ""); 249 addressList->addContact(str, "");
250 } 250 }
251 temp = temp.stripWhiteSpace(); 251 temp = temp.stripWhiteSpace();
252 if ( temp.find('@') == -1) 252 if ( temp.find('@') == -1)
253 return false; 253 return false;
254 mail.recipients.append(temp); 254 mail.recipients.append(temp);
255 addressList->addContact(temp, ""); 255 addressList->addContact(temp, "");
256 256
257 return TRUE; 257 return TRUE;
258} 258}
259 259
260 260
261void WriteMail::addRecipients() 261void WriteMail::addRecipients()
262{ 262{
263 QString recipients = ""; 263 QString recipients = "";
264 264
265 mail.recipients.clear(); 265 mail.recipients.clear();
266 QListViewItem *item = addressView->firstChild(); 266 QListViewItem *item = addressView->firstChild();
267 while (item != NULL) { 267 while (item != NULL) {
268 if ( item->isSelected() ) { 268 if ( item->isSelected() ) {
269 if (recipients == "") { 269 if (recipients == "") {
270 recipients = item->text(0); 270 recipients = item->text(0);
271 } else { 271 } else {
272 recipients += "; " + item->text(0); 272 recipients += "; " + item->text(0);
273 } 273 }
274 } 274 }
275 item = item->nextSibling(); 275 item = item->nextSibling();
276 } 276 }
277 toInput->setText(recipients); 277 toInput->setText(recipients);
278 278
279 addressView->hide(); 279 addressView->hide();
280 okButton->hide(); 280 okButton->hide();
281 emailInput->show(); 281 emailInput->show();
282 addressButton->setOn(FALSE); 282 addressButton->setOn(FALSE);
283 showingAddressList = !showingAddressList; 283 showingAddressList = !showingAddressList;
284} 284}
285 285
286void WriteMail::setRecipient(const QString &recipient) 286void WriteMail::setRecipient(const QString &recipient)
287{ 287{
288 toInput->setText(recipient); 288 toInput->setText(recipient);
289} 289}
290 290
291void WriteMail::newMail() 291void WriteMail::newMail()
292{ 292{
293 toInput->clear(); 293 toInput->clear();
294 subjectInput->clear(); 294 subjectInput->clear();
295 emailInput->clear(); 295 emailInput->clear();
296 //to clear selected 296 //to clear selected
297 setAddressList(addressList); 297 setAddressList(addressList);
298} 298}
diff --git a/noncore/unsupported/mailit/addatt.cpp b/noncore/unsupported/mailit/addatt.cpp
index c8be865..d268f1f 100644
--- a/noncore/unsupported/mailit/addatt.cpp
+++ b/noncore/unsupported/mailit/addatt.cpp
@@ -1,224 +1,224 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qlayout.h> 20#include <qlayout.h>
21#include <qhbox.h> 21#include <qhbox.h>
22#include <qdir.h> 22#include <qdir.h>
23#include <qstringlist.h> 23#include <qstringlist.h>
24#include "resource.h" 24#include <qpe/resource.h>
25#include "addatt.h" 25#include "addatt.h"
26 26
27FileItem::FileItem(QListView *parent, DocLnk* dl) 27FileItem::FileItem(QListView *parent, DocLnk* dl)
28 : QListViewItem(parent) 28 : QListViewItem(parent)
29{ 29{
30 /*file = fileInfo; 30 /*file = fileInfo;
31 type = fileType;*/ 31 type = fileType;*/
32 32
33 doclnk=dl; 33 doclnk=dl;
34 34
35 setText(0, doclnk->name()); 35 setText(0, doclnk->name());
36 36
37 /*if (fileType == "Picture") { 37 /*if (fileType == "Picture") {
38 setPixmap(0, Resource::loadPixmap("pixmap")); 38 setPixmap(0, Resource::loadPixmap("pixmap"));
39 } else if (fileType == "Document") { 39 } else if (fileType == "Document") {
40 setPixmap(0, Resource::loadPixmap("txt")); 40 setPixmap(0, Resource::loadPixmap("txt"));
41 } else if (fileType == "Sound") { 41 } else if (fileType == "Sound") {
42 setPixmap(0, Resource::loadPixmap("play")); 42 setPixmap(0, Resource::loadPixmap("play"));
43 } else if (fileType == "Movie") { 43 } else if (fileType == "Movie") {
44 setPixmap(0, Resource::loadPixmap("MPEGPlayer")); 44 setPixmap(0, Resource::loadPixmap("MPEGPlayer"));
45 } else if (fileType == "File") { 45 } else if (fileType == "File") {
46 setPixmap(0, Resource::loadPixmap("exec")); 46 setPixmap(0, Resource::loadPixmap("exec"));
47 }*/ 47 }*/
48} 48}
49 49
50FileItem::~FileItem() 50FileItem::~FileItem()
51{ 51{
52 if (doclnk!=NULL) delete doclnk; 52 if (doclnk!=NULL) delete doclnk;
53 doclnk=NULL; 53 doclnk=NULL;
54} 54}
55 55
56AddAtt::AddAtt(QWidget *parent, const char *name, WFlags f) 56AddAtt::AddAtt(QWidget *parent, const char *name, WFlags f)
57 : QDialog(parent, name, f) 57 : QDialog(parent, name, f)
58{ 58{
59 setCaption("Adding attatchments"); 59 setCaption("Adding attatchments");
60 60
61 QGridLayout *top = new QGridLayout(this, 1,1 ); 61 QGridLayout *top = new QGridLayout(this, 1,1 );
62 62
63 QHBox *buttons=new QHBox(this); 63 QHBox *buttons=new QHBox(this);
64 /*fileCategoryButton = new QPushButton(this);*/ 64 /*fileCategoryButton = new QPushButton(this);*/
65 attatchButton = new QPushButton("Attatch ->", buttons); 65 attatchButton = new QPushButton(tr("Attatch..."), buttons);
66 removeButton = new QPushButton("Remove", buttons); 66 removeButton = new QPushButton(tr("Remove"), buttons);
67 67
68 /*fileCategories = new QPopupMenu(fileCategoryButton); 68 /*fileCategories = new QPopupMenu(fileCategoryButton);
69 fileCategoryButton->setPopup(fileCategories); 69 fileCategoryButton->setPopup(fileCategories);
70 fileCategories->insertItem("Document"); 70 fileCategories->insertItem("Document");
71 fileCategories->insertItem("Picture"); 71 fileCategories->insertItem("Picture");
72 fileCategories->insertItem("Sound"); 72 fileCategories->insertItem("Sound");
73 fileCategories->insertItem("Movie"); 73 fileCategories->insertItem("Movie");
74 fileCategories->insertItem("File"); 74 fileCategories->insertItem("File");
75 75
76 fileCategoryButton->setText("Document"); 76 fileCategoryButton->setText("Document");
77 top->addWidget(fileCategoryButton, 0, 0);*/ 77 top->addWidget(fileCategoryButton, 0, 0);*/
78 78
79 79
80 top->addWidget(buttons,1,0); 80 top->addWidget(buttons,1,0);
81 //buttons->addWidget(attatchButton,0,0); 81 //buttons->addWidget(attatchButton,0,0);
82 //buttons->addWidget(removeButton,0,1); 82 //buttons->addWidget(removeButton,0,1);
83 83
84 //connect(fileCategories, SIGNAL(activated(int)), this, 84 //connect(fileCategories, SIGNAL(activated(int)), this,
85 //SLOT(fileCategorySelected(int)) );*/ 85 //SLOT(fileCategorySelected(int)) );*/
86 connect(attatchButton, SIGNAL(clicked()), this, 86 connect(attatchButton, SIGNAL(clicked()), this,
87 SLOT(addAttatchment()) ); 87 SLOT(addAttatchment()) );
88 connect(removeButton, SIGNAL(clicked()), this, 88 connect(removeButton, SIGNAL(clicked()), this,
89 SLOT(removeAttatchment()) ); 89 SLOT(removeAttatchment()) );
90 90
91 /*listView = new QListView(this, "AttView"); 91 /*listView = new QListView(this, "AttView");
92 listView->addColumn("Documents");* 92 listView->addColumn("Documents");*
93 connect(listView, SIGNAL(doubleClicked(QListViewItem *)), this, 93 connect(listView, SIGNAL(doubleClicked(QListViewItem *)), this,
94 SLOT(addAttatchment()) );*/ 94 SLOT(addAttatchment()) );*/
95 95
96 96
97 attView = new QListView(this, "Selected"); 97 attView = new QListView(this, "Selected");
98 attView->addColumn(tr("Attached")); 98 attView->addColumn(tr("Attached"));
99 attView->addColumn(tr("File type")); 99 attView->addColumn(tr("File type"));
100 connect(attView, SIGNAL(doubleClicked(QListViewItem *)), this, 100 connect(attView, SIGNAL(doubleClicked(QListViewItem *)), this,
101 SLOT(removeAttatchment()) ); 101 SLOT(removeAttatchment()) );
102 102
103 //top->addWidget(ofs, 0,0); 103 //top->addWidget(ofs, 0,0);
104 top->addWidget(attView, 0,0); 104 top->addWidget(attView, 0,0);
105 105
106 clear(); 106 clear();
107 107
108 108
109} 109}
110 110
111void AddAtt::clear() 111void AddAtt::clear()
112{ 112{
113 attView->clear(); 113 attView->clear();
114 //getFiles(); 114 //getFiles();
115 modified = FALSE; 115 modified = FALSE;
116} 116}
117 117
118/*void AddAtt::fileCategorySelected(int id) 118/*void AddAtt::fileCategorySelected(int id)
119{ 119{
120 fileCategoryButton->setText(fileCategories->text(id)); 120 fileCategoryButton->setText(fileCategories->text(id));
121 getFiles(); 121 getFiles();
122}*/ 122}*/
123 123
124void AddAtt::addAttatchment() 124void AddAtt::addAttatchment()
125 { 125 {
126 OFileDialog ofs("Attachments",this,0,0,"/root/Documents"); 126 OFileDialog ofs("Attachments",this,0,0,"/root/Documents");
127 127
128 ofs.showMaximized(); 128 ofs.showMaximized();
129 129
130 if (ofs.exec()==QDialog::Accepted) 130 if (ofs.exec()==QDialog::Accepted)
131 { 131 {
132 DocLnk* dl=new DocLnk(ofs.selectedDocument()); 132 DocLnk* dl=new DocLnk(ofs.selectedDocument());
133 FileItem* fi=new FileItem(attView,dl); 133 FileItem* fi=new FileItem(attView,dl);
134 fi->setPixmap(0,dl->pixmap()); 134 fi->setPixmap(0,dl->pixmap());
135 fi->setText(1,dl->type()); 135 fi->setText(1,dl->type());
136 attView->insertItem(fi); 136 attView->insertItem(fi);
137 modified = TRUE; 137 modified = TRUE;
138 } 138 }
139} 139}
140 140
141void AddAtt::removeAttatchment() 141void AddAtt::removeAttatchment()
142{ 142{
143 if (attView->selectedItem() != NULL) 143 if (attView->selectedItem() != NULL)
144 { 144 {
145 attView->takeItem(attView->selectedItem()); 145 attView->takeItem(attView->selectedItem());
146 } 146 }
147 modified = TRUE; 147 modified = TRUE;
148} 148}
149 149
150void AddAtt::reject() 150void AddAtt::reject()
151{ 151{
152 if (modified) { 152 if (modified) {
153 attView->clear(); 153 attView->clear();
154 modified = FALSE; 154 modified = FALSE;
155 } 155 }
156} 156}
157 157
158void AddAtt::accept() 158void AddAtt::accept()
159{ 159{
160 modified = FALSE; 160 modified = FALSE;
161 hide(); 161 hide();
162} 162}
163 163
164void AddAtt::getFiles() 164void AddAtt::getFiles()
165{ 165{
166 QString path, selected; 166 QString path, selected;
167 167
168 /*listView->clear(); 168 /*listView->clear();
169 169
170 selected = fileCategoryButton->text(); 170 selected = fileCategoryButton->text();
171 if (selected == "Picture") { 171 if (selected == "Picture") {
172 path = "../pics/"; 172 path = "../pics/";
173 } else if (selected == "Document") { 173 } else if (selected == "Document") {
174 path = "" ; //sub-dirs not decided 174 path = "" ; //sub-dirs not decided
175 } else if (selected == "Sound") { 175 } else if (selected == "Sound") {
176 path = "../sounds/"; //sub-dirs not decided 176 path = "../sounds/"; //sub-dirs not decided
177 } else if (selected == "Movie") { 177 } else if (selected == "Movie") {
178 path = ""; //sub-dirs not decided 178 path = ""; //sub-dirs not decided
179 } else if (selected == "File") { 179 } else if (selected == "File") {
180 path = ""; //sub-dirs not decided 180 path = ""; //sub-dirs not decided
181 } 181 }
182 182
183 dir = new QDir(path); 183 dir = new QDir(path);
184 dir->setFilter(QDir::Files); 184 dir->setFilter(QDir::Files);
185 const QFileInfoList *dirInfoList = dir->entryInfoList(); 185 const QFileInfoList *dirInfoList = dir->entryInfoList();
186 186
187 QFileInfoListIterator it(*dirInfoList); // create list iterator 187 QFileInfoListIterator it(*dirInfoList); // create list iterator
188 188
189 while ( (fi=it.current()) ) { // for each file... 189 while ( (fi=it.current()) ) { // for each file...
190 item = new FileItem(lis+ütView, *fi, selected); 190 item = new FileItem(lis+ütView, *fi, selected);
191 ++it; // goto next list element 191 ++it; // goto next list element
192 }*/ 192 }*/
193} 193}
194 194
195QStringList AddAtt::returnAttatchedFiles() 195QStringList AddAtt::returnAttatchedFiles()
196{ 196{
197 QFileInfo info; 197 QFileInfo info;
198 QStringList list; 198 QStringList list;
199 199
200 item = (FileItem *) attView->firstChild(); 200 item = (FileItem *) attView->firstChild();
201 201
202 202
203 while (item != NULL) { 203 while (item != NULL) {
204 DocLnk* dl=item->getDocLnk(); 204 DocLnk* dl=item->getDocLnk();
205 list+=dl->file(); 205 list+=dl->file();
206 /*info = item->getFileInfo(); 206 /*info = item->getFileInfo();
207 list += info.filePath();*/ 207 list += info.filePath();*/
208 item = (FileItem *) item->nextSibling(); 208 item = (FileItem *) item->nextSibling();
209 } 209 }
210 return list; 210 return list;
211} 211}
212 212
213QStringList AddAtt::returnFileTypes() 213QStringList AddAtt::returnFileTypes()
214{ 214{
215 QStringList list; 215 QStringList list;
216 216
217 item = (FileItem *) attView->firstChild(); 217 item = (FileItem *) attView->firstChild();
218 218
219 while (item != NULL) { 219 while (item != NULL) {
220 list += item->getDocLnk()->type(); 220 list += item->getDocLnk()->type();
221 item = (FileItem *) item->nextSibling(); 221 item = (FileItem *) item->nextSibling();
222 } 222 }
223 return list; 223 return list;
224} 224}
diff --git a/noncore/unsupported/mailit/addresslist.cpp b/noncore/unsupported/mailit/addresslist.cpp
index 43e3830..9fe558a 100644
--- a/noncore/unsupported/mailit/addresslist.cpp
+++ b/noncore/unsupported/mailit/addresslist.cpp
@@ -1,181 +1,161 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qfile.h> 20#include <qfile.h>
21#include <qtextstream.h> 21#include <qtextstream.h>
22#include <opie/ocontactaccess.h> 22#include <opie/ocontactaccess.h>
23#include <opie/ocontact.h> 23#include <opie/ocontact.h>
24 24
25#include "addresslist.h" 25#include "addresslist.h"
26 26
27AddressList::AddressList(QString file) 27AddressList::AddressList()
28{ 28{
29 addresses.setAutoDelete(TRUE); 29 addresses.setAutoDelete(TRUE);
30 filename = file;
31 read(); 30 read();
32 dirty = FALSE; 31 dirty = FALSE;
33} 32}
34 33
35AddressList::~AddressList() 34AddressList::~AddressList()
36{ 35{
37 write();
38 addresses.clear(); 36 addresses.clear();
39} 37}
40 38
41void AddressList::addContact(QString email, QString name) 39void AddressList::addContact(QString email, QString name)
42{ 40{
43 //skip if not a valid email address, 41 //skip if not a valid email address,
44 if (email.find( '@') == -1) 42 if (email.find( '@') == -1)
45 return; 43 return;
46 44
47 if ( ! containsEmail(email) ) { 45 if ( ! containsEmail(email) ) {
48 Contact *in = new Contact; 46 Contact *in = new Contact;
49 in->email = email; 47 in->email = email;
50 in->name = name; 48 in->name = name;
51 addresses.append(in); 49 addresses.append(in);
52 dirty = TRUE; 50 dirty = TRUE;
53 } 51 }
54} 52}
55 53
56bool AddressList::containsEmail(QString email) 54bool AddressList::containsEmail(QString email)
57{ 55{
58 return ( getEmailRef(email) != -1 ); 56 return ( getEmailRef(email) != -1 );
59} 57}
60 58
61bool AddressList::containsName(QString name) 59bool AddressList::containsName(QString name)
62{ 60{
63 return ( getNameRef(name) != -1 ); 61 return ( getNameRef(name) != -1 );
64} 62}
65 63
66QString AddressList::getNameByEmail(QString email) 64QString AddressList::getNameByEmail(QString email)
67{ 65{
68 int pos = getEmailRef(email); 66 int pos = getEmailRef(email);
69 if (pos != -1) { 67 if (pos != -1) {
70 Contact *ptr = addresses.at(pos); 68 Contact *ptr = addresses.at(pos);
71 return ptr->name; 69 return ptr->name;
72 } 70 }
73 71
74 return NULL; 72 return NULL;
75} 73}
76 74
77QString AddressList::getEmailByName(QString name) 75QString AddressList::getEmailByName(QString name)
78{ 76{
79 int pos = getNameRef(name); 77 int pos = getNameRef(name);
80 if (pos != -1) { 78 if (pos != -1) {
81 Contact *ptr = addresses.at(pos); 79 Contact *ptr = addresses.at(pos);
82 return ptr->email; 80 return ptr->email;
83 } 81 }
84 82
85 return NULL; 83 return NULL;
86} 84}
87 85
88int AddressList::getEmailRef(QString email) 86int AddressList::getEmailRef(QString email)
89{ 87{
90 int pos = 0; 88 int pos = 0;
91 Contact *ptr; 89 Contact *ptr;
92 90
93 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) { 91 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) {
94 if (ptr->email == email) 92 if (ptr->email == email)
95 return pos; 93 return pos;
96 pos++; 94 pos++;
97 } 95 }
98 return -1; 96 return -1;
99} 97}
100 98
101int AddressList::getNameRef(QString name) 99int AddressList::getNameRef(QString name)
102{ 100{
103 int pos = 0; 101 int pos = 0;
104 Contact *ptr; 102 Contact *ptr;
105 103
106 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) { 104 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) {
107 if (ptr->name == name) 105 if (ptr->name == name)
108 return pos; 106 return pos;
109 pos++; 107 pos++;
110 } 108 }
111 return -1; 109 return -1;
112} 110}
113 111
114QList<Contact>* AddressList::getContactList() 112QList<Contact>* AddressList::getContactList()
115{ 113{
116 return &addresses; 114 return &addresses;
117} 115}
118 116
119void AddressList::read() 117void AddressList::read()
120{ 118{
121 OContactAccess::List::Iterator it; 119 OContactAccess::List::Iterator it;
122 120
123 //QFile f(filename);
124 QString lineEmail, lineName, email, name; 121 QString lineEmail, lineName, email, name;
125 OContactAccess m_contactdb("mailit"); 122 OContactAccess m_contactdb("mailit");
126 OContactAccess::List m_list = m_contactdb.sorted( true, 0, 0, 0 ); 123 OContactAccess::List m_list = m_contactdb.sorted( true, 0, 0, 0 );
127 //OContact* oc; 124 //OContact* oc;
128 125
129 for ( it = m_list.begin(); it != m_list.end(); ++it ) 126 for ( it = m_list.begin(); it != m_list.end(); ++it )
130 { 127 {
131 //oc=(OContact*) it; 128 //oc=(OContact*) it;
132 if ((*it).defaultEmail().length()!=0) 129 if ((*it).defaultEmail().length()!=0)
133 addContact((*it).defaultEmail(),(*it).fullName()); 130 addContact((*it).defaultEmail(),(*it).fullName());
134 } 131 }
135 132
136 /*if (! f.open(IO_ReadOnly) ) 133 /*if (! f.open(IO_ReadOnly) )
137 return; 134 return;
138 135
139 QTextStream stream(&f); 136 QTextStream stream(&f);
140 137
141 while (! stream.atEnd() ) { 138 while (! stream.atEnd() ) {
142 lineEmail = stream.readLine(); 139 lineEmail = stream.readLine();
143 if (! stream.atEnd() ) 140 if (! stream.atEnd() )
144 lineName = stream.readLine(); 141 lineName = stream.readLine();
145 else return; 142 else return;
146 143
147 email = getRightString(lineEmail); 144 email = getRightString(lineEmail);
148 name = getRightString(lineName); 145 name = getRightString(lineName);
149 addContact(email, name); 146 addContact(email, name);
150 } 147 }
151 f.close();*/ 148 f.close();*/
152} 149}
153 150
154QString AddressList::getRightString(QString in) 151QString AddressList::getRightString(QString in)
155{ 152{
156 QString out = ""; 153 QString out = "";
157 154
158 int pos = in.find('='); 155 int pos = in.find('=');
159 if (pos != -1) { 156 if (pos != -1) {
160 out = in.mid(pos+1).stripWhiteSpace(); 157 out = in.mid(pos+1).stripWhiteSpace();
161 } 158 }
162 return out; 159 return out;
163} 160}
164 161
165void AddressList::write()
166{
167 if ( (addresses.count() == 0) || (!dirty) )
168 return;
169
170 QFile f(filename);
171 if (! f.open(IO_WriteOnly) )
172 return;
173
174 QTextStream stream(&f);
175 Contact *ptr;
176 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) {
177 stream << "email = " + ptr->email + "\n";
178 stream << "name = " + ptr->name + "\n";
179 }
180 f.close();
181}
diff --git a/noncore/unsupported/mailit/addresslist.h b/noncore/unsupported/mailit/addresslist.h
index e87d6f1..99cef9a 100644
--- a/noncore/unsupported/mailit/addresslist.h
+++ b/noncore/unsupported/mailit/addresslist.h
@@ -1,59 +1,58 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef ADDRESSLIST_H 20#ifndef ADDRESSLIST_H
21#define ADDRESSLIST_H 21#define ADDRESSLIST_H
22 22
23#include <qobject.h> 23#include <qobject.h>
24#include <qlist.h> 24#include <qlist.h>
25 25
26struct Contact 26struct Contact
27{ 27{
28 QString email; 28 QString email;
29 QString name; 29 QString name;
30}; 30};
31 31
32class AddressList : public QObject 32class AddressList : public QObject
33{ 33{
34 Q_OBJECT 34 Q_OBJECT
35 35
36public: 36public:
37 AddressList(QString file); 37 AddressList();
38 ~AddressList(); 38 ~AddressList();
39 void addContact(QString email, QString name); 39 void addContact(QString email, QString name);
40 bool containsEmail(QString email); 40 bool containsEmail(QString email);
41 bool containsName(QString name); 41 bool containsName(QString name);
42 QString getNameByEmail(QString email); 42 QString getNameByEmail(QString email);
43 QString getEmailByName(QString name); 43 QString getEmailByName(QString name);
44 QList<Contact>* getContactList(); 44 QList<Contact>* getContactList();
45 void write();
46 45
47private: 46private:
48 int getEmailRef(QString email); 47 int getEmailRef(QString email);
49 int getNameRef(QString name); 48 int getNameRef(QString name);
50 QString getRightString(QString in); 49 QString getRightString(QString in);
51 void read(); 50 void read();
52 51
53private: 52private:
54 QList<Contact> addresses; 53 QList<Contact> addresses;
55 QString filename; 54 QString filename;
56 bool dirty; 55 bool dirty;
57}; 56};
58 57
59#endif 58#endif
diff --git a/noncore/unsupported/mailit/editaccount.cpp b/noncore/unsupported/mailit/editaccount.cpp
index c4f95ea..c0afbb2 100644
--- a/noncore/unsupported/mailit/editaccount.cpp
+++ b/noncore/unsupported/mailit/editaccount.cpp
@@ -1,120 +1,133 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18*** 18***
19**********************************************************************/ 19**********************************************************************/
20 20
21#include <qhbox.h>
21#include "editaccount.h" 22#include "editaccount.h"
22 23
23EditAccount::EditAccount( QWidget* parent, const char* name, WFlags fl ) 24EditAccount::EditAccount( QWidget* parent, const char* name, WFlags fl )
24 : QDialog(parent, name, fl) 25 : QDialog(parent, name, fl)
25{ 26{
26 setCaption( tr("Edit Account") ); 27 setCaption( tr("Edit Account") );
27 init(); 28 init();
28 popPasswInput->setEchoMode(QLineEdit::Password); 29 popPasswInput->setEchoMode(QLineEdit::Password);
29} 30}
30 31
31void EditAccount::setAccount(MailAccount *in, bool newOne) 32void EditAccount::setAccount(MailAccount *in, bool newOne)
32{ 33{
33 account = in; 34 account = in;
34 if (newOne) { 35 if (newOne) {
35 accountNameInput->setText(""); 36 accountNameInput->setText("");
36 nameInput->setText(""); 37 nameInput->setText("");
37 emailInput->setText(""); 38 emailInput->setText("");
38 popUserInput->setText(""); 39 popUserInput->setText("");
39 popPasswInput->setText(""); 40 popPasswInput->setText("");
40 popServerInput->setText(""); 41 popServerInput->setText("");
41 smtpServerInput->setText(""); 42 smtpServerInput->setText("");
42 syncCheckBox->setChecked(TRUE); 43 syncCheckBox->setChecked(TRUE);
44 syncLimitInput->setValue(2);
43 45
44 setCaption( tr("Create new Account") ); 46 setCaption( tr("Create new Account") );
45 } else { 47 } else {
46 accountNameInput->setText(account->accountName); 48 accountNameInput->setText(account->accountName);
47 nameInput->setText(account->name); 49 nameInput->setText(account->name);
48 emailInput->setText(account->emailAddress); 50 emailInput->setText(account->emailAddress);
49 popUserInput->setText(account->popUserName); 51 popUserInput->setText(account->popUserName);
50 popPasswInput->setText(account->popPasswd); 52 popPasswInput->setText(account->popPasswd);
51 popServerInput->setText(account->popServer); 53 popServerInput->setText(account->popServer);
52 smtpServerInput->setText(account->smtpServer); 54 smtpServerInput->setText(account->smtpServer);
53 syncCheckBox->setChecked(account->synchronize); 55 syncCheckBox->setChecked(account->synchronize);
56 syncLimitInput->setValue(account->syncLimit/1000);
54 } 57 }
55} 58}
56 59
57void EditAccount::init() 60void EditAccount::init()
58{ 61{
59 grid = new QGridLayout(this); 62 grid = new QGridLayout(this);
60 grid->setSpacing( 6 ); 63 grid->setSpacing( 6 );
61 grid->setMargin( 11 ); 64 grid->setMargin( 11 );
62 65
63 accountNameInputLabel = new QLabel(tr("Account name"), this); 66 accountNameInputLabel = new QLabel(tr("Account name"), this);
64 grid->addWidget( accountNameInputLabel, 0, 0 ); 67 grid->addWidget( accountNameInputLabel, 0, 0 );
65 accountNameInput = new QLineEdit( this, "account nameInput" ); 68 accountNameInput = new QLineEdit( this, "account nameInput" );
66 grid->addWidget( accountNameInput, 0, 1 ); 69 grid->addWidget( accountNameInput, 0, 1 );
67 70
68 nameInputLabel = new QLabel(tr("Your name"), this); 71 nameInputLabel = new QLabel(tr("Your name"), this);
69 grid->addWidget( nameInputLabel, 1, 0 ); 72 grid->addWidget( nameInputLabel, 1, 0 );
70 nameInput = new QLineEdit( this, "nameInput" ); 73 nameInput = new QLineEdit( this, "nameInput" );
71 grid->addWidget( nameInput, 1, 1 ); 74 grid->addWidget( nameInput, 1, 1 );
72 75
73 emailInputLabel = new QLabel("Email", this); 76 emailInputLabel = new QLabel(tr("Email"), this);
74 grid->addWidget(emailInputLabel, 2, 0 ); 77 grid->addWidget(emailInputLabel, 2, 0 );
75 emailInput = new QLineEdit( this, "emailInput" ); 78 emailInput = new QLineEdit( this, "emailInput" );
76 grid->addWidget( emailInput, 2, 1 ); 79 grid->addWidget( emailInput, 2, 1 );
77 80
78 popUserInputLabel = new QLabel("POP username", this); 81 popUserInputLabel = new QLabel(tr("POP username"), this);
79 grid->addWidget( popUserInputLabel, 3, 0 ); 82 grid->addWidget( popUserInputLabel, 3, 0 );
80 popUserInput = new QLineEdit( this, "popUserInput" ); 83 popUserInput = new QLineEdit( this, "popUserInput" );
81 grid->addWidget( popUserInput, 3, 1 ); 84 grid->addWidget( popUserInput, 3, 1 );
82 85
83 popPasswInputLabel = new QLabel( "POP password", this); 86 popPasswInputLabel = new QLabel( tr("POP password"), this);
84 grid->addWidget( popPasswInputLabel, 4, 0 ); 87 grid->addWidget( popPasswInputLabel, 4, 0 );
85 popPasswInput = new QLineEdit( this, "popPasswInput" ); 88 popPasswInput = new QLineEdit( this, "popPasswInput" );
86 grid->addWidget( popPasswInput, 4, 1 ); 89 grid->addWidget( popPasswInput, 4, 1 );
87 90
88 popServerInputLabel = new QLabel("POP server", this); 91 popServerInputLabel = new QLabel(tr("POP server"), this);
89 grid->addWidget( popServerInputLabel, 5, 0 ); 92 grid->addWidget( popServerInputLabel, 5, 0 );
90 popServerInput = new QLineEdit( this, "popServerInput" ); 93 popServerInput = new QLineEdit( this, "popServerInput" );
91 grid->addWidget( popServerInput, 5, 1 ); 94 grid->addWidget( popServerInput, 5, 1 );
92 95
93 smtpServerInputLabel = new QLabel("SMTP server", this ); 96 smtpServerInputLabel = new QLabel(tr("SMTP server"), this );
94 grid->addWidget( smtpServerInputLabel, 6, 0 ); 97 grid->addWidget( smtpServerInputLabel, 6, 0 );
95 smtpServerInput = new QLineEdit( this, "smtpServerInput" ); 98 smtpServerInput = new QLineEdit( this, "smtpServerInput" );
96 grid->addWidget( smtpServerInput, 6, 1 ); 99 grid->addWidget( smtpServerInput, 6, 1 );
97 100
98 syncCheckBox = new QCheckBox( tr( "Synchronize with server" ), this); 101 QHBox* syncBox=new QHBox(this);
102 grid->addWidget( syncBox, 7, 1 );
103
104 syncCheckBox = new QCheckBox( tr( "Synchronize" ), this);
99 syncCheckBox->setChecked( TRUE ); 105 syncCheckBox->setChecked( TRUE );
100 grid->addMultiCellWidget( syncCheckBox, 7, 7, 0, 1 ); 106 grid->addWidget( syncCheckBox,7,0);
107
108 syncLimitInputLabel = new QLabel(tr("Mail Size (k)"), syncBox);
109 //syncBox->addWidget( syncLimitInputLabel);
110 syncLimitInput = new QSpinBox( syncBox, "syncSize" );
111 //syncBox->addWidget(syncLimitInput);
112
101} 113}
102 114
103 115
104void EditAccount::accept() 116void EditAccount::accept()
105{ 117{
106 account->accountName = accountNameInput->text(); 118 account->accountName = accountNameInput->text();
107 account->name = nameInput->text(); 119 account->name = nameInput->text();
108 account->emailAddress = emailInput->text(); 120 account->emailAddress = emailInput->text();
109 account->popUserName = popUserInput->text(); 121 account->popUserName = popUserInput->text();
110 account->popPasswd = popPasswInput->text(); 122 account->popPasswd = popPasswInput->text();
111 account->popServer = popServerInput->text(); 123 account->popServer = popServerInput->text();
112 account->smtpServer = smtpServerInput->text(); 124 account->smtpServer = smtpServerInput->text();
113 account->synchronize = syncCheckBox->isChecked(); 125 account->synchronize = syncCheckBox->isChecked();
126 account->syncLimit = syncLimitInput->value()*1000;//Display in kB
114 127
115 QDialog::accept(); 128 QDialog::accept();
116} 129}
117 130
118void EditAccount::reject() 131void EditAccount::reject()
119{ 132{
120} 133}
diff --git a/noncore/unsupported/mailit/editaccount.h b/noncore/unsupported/mailit/editaccount.h
index 7a90e50..1e15047 100644
--- a/noncore/unsupported/mailit/editaccount.h
+++ b/noncore/unsupported/mailit/editaccount.h
@@ -1,66 +1,69 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef EDITACCOUNT_H 20#ifndef EDITACCOUNT_H
21#define EDITACCOUNT_H 21#define EDITACCOUNT_H
22 22
23#include <qdialog.h> 23#include <qdialog.h>
24#include <qlabel.h> 24#include <qlabel.h>
25#include <qlineedit.h> 25#include <qlineedit.h>
26#include <qcheckbox.h> 26#include <qcheckbox.h>
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qspinbox.h>
28#include "emailhandler.h" 29#include "emailhandler.h"
29 30
30class EditAccount : public QDialog 31class EditAccount : public QDialog
31{ 32{
32 Q_OBJECT 33 Q_OBJECT
33 34
34public: 35public:
35 EditAccount( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 36 EditAccount( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
36 void setAccount(MailAccount *in, bool newOne = TRUE); 37 void setAccount(MailAccount *in, bool newOne = TRUE);
37 void init(); 38 void init();
38 39
39public slots: 40public slots:
40 void accept(); 41 void accept();
41 void reject(); 42 void reject();
42 43
43private: 44private:
44 MailAccount thisAccount, *account; 45 MailAccount thisAccount, *account;
45 46
46 QLabel *accountNameInputLabel; 47 QLabel *accountNameInputLabel;
47 QLabel *nameInputLabel; 48 QLabel *nameInputLabel;
48 QLabel *emailInputLabel; 49 QLabel *emailInputLabel;
49 QLabel *popUserInputLabel; 50 QLabel *popUserInputLabel;
50 QLabel *popPasswInputLabel; 51 QLabel *popPasswInputLabel;
51 QLabel *popServerInputLabel; 52 QLabel *popServerInputLabel;
52 QLabel *smtpServerInputLabel; 53 QLabel *smtpServerInputLabel;
53 54 QLabel *syncLimitInputLabel;
55
54 QLineEdit *accountNameInput; 56 QLineEdit *accountNameInput;
55 QLineEdit *nameInput; 57 QLineEdit *nameInput;
56 QLineEdit *emailInput; 58 QLineEdit *emailInput;
57 QLineEdit *popUserInput; 59 QLineEdit *popUserInput;
58 QLineEdit *popPasswInput; 60 QLineEdit *popPasswInput;
59 QLineEdit *popServerInput; 61 QLineEdit *popServerInput;
60 QLineEdit *smtpServerInput; 62 QLineEdit *smtpServerInput;
63 QSpinBox *syncLimitInput;
61 QCheckBox *syncCheckBox; 64 QCheckBox *syncCheckBox;
62 65
63 QGridLayout *grid; 66 QGridLayout *grid;
64}; 67};
65 68
66#endif 69#endif
diff --git a/noncore/unsupported/mailit/emailclient.cpp b/noncore/unsupported/mailit/emailclient.cpp
index 2943986..6612541 100644
--- a/noncore/unsupported/mailit/emailclient.cpp
+++ b/noncore/unsupported/mailit/emailclient.cpp
@@ -1,864 +1,872 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qapplication.h> 20#include <qapplication.h>
21#include <qmessagebox.h> 21#include <qmessagebox.h>
22#include <qfile.h> 22#include <qfile.h>
23#include <qcheckbox.h> 23#include <qcheckbox.h>
24#include <qmenubar.h> 24#include <qmenubar.h>
25#include <qaction.h> 25#include <qaction.h>
26#include "resource.h" 26#include <qpe/resource.h>
27#include "emailclient.h" 27#include "emailclient.h"
28 28
29QCollection::Item AccountList::newItem(QCollection::Item d) 29QCollection::Item AccountList::newItem(QCollection::Item d)
30{ 30{
31 return dupl( (MailAccount *) d); 31 return dupl( (MailAccount *) d);
32} 32}
33 33
34MailAccount* AccountList::dupl(MailAccount *in) 34MailAccount* AccountList::dupl(MailAccount *in)
35{ 35{
36 ac = new MailAccount(*in); 36 ac = new MailAccount(*in);
37 return ac; 37 return ac;
38} 38}
39 39
40EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl ) 40EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl )
41 : QMainWindow( parent, name, fl ) 41 : QMainWindow( parent, name, fl )
42{ 42{
43 emailHandler = new EmailHandler(); 43 emailHandler = new EmailHandler();
44 addressList = new AddressList( getPath(FALSE) + "mail_adr"); 44 addressList = new AddressList();
45 45
46 sending = FALSE; 46 sending = FALSE;
47 receiving = FALSE; 47 receiving = FALSE;
48 previewingMail = FALSE; 48 previewingMail = FALSE;
49 mailIdCount = 1; 49 mailIdCount = 1;
50 accountIdCount = 1; 50 accountIdCount = 1;
51 allAccounts = FALSE; 51 allAccounts = FALSE;
52 52
53 init(); 53 init();
54 54
55 connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) ); 55 connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) );
56 56
57 connect(emailHandler, SIGNAL(smtpError(int)), this, 57 connect(emailHandler, SIGNAL(smtpError(int)), this,
58 SLOT(smtpError(int)) ); 58 SLOT(smtpError(int)) );
59 connect(emailHandler, SIGNAL(popError(int)), this, 59 connect(emailHandler, SIGNAL(popError(int)), this,
60 SLOT(popError(int)) ); 60 SLOT(popError(int)) );
61 61
62 connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemSelected()) ); 62 connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemSelected()) );
63 connect(outboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(outboxItemSelected()) ); 63 connect(outboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(outboxItemSelected()) );
64 64
65 connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this, 65 connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this,
66 SLOT(mailArrived(const Email &, bool)) ); 66 SLOT(mailArrived(const Email &, bool)) );
67 connect(emailHandler, SIGNAL(mailTransfered(int)), this, 67 connect(emailHandler, SIGNAL(mailTransfered(int)), this,
68 SLOT(allMailArrived(int)) ); 68 SLOT(allMailArrived(int)) );
69 69
70 mailconf = new Config("mailit"); 70 mailconf = new Config("mailit");
71 //In case Synchronize is not defined in settings.txt 71 //In case Synchronize is not defined in settings.txt
72 72
73 readSettings(); 73 readSettings();
74 74
75 updateAccounts(); 75 updateAccounts();
76 76
77 lineShift = "\n"; 77 lineShift = "\n";
78 readMail(); 78 readMail();
79 lineShift = "\r\n"; 79 lineShift = "\r\n";
80 80
81} 81}
82 82
83 83
84EmailClient::~EmailClient() 84EmailClient::~EmailClient()
85{ 85{
86 //needs to be moved from destructor to closewindow event 86 //needs to be moved from destructor to closewindow event
87 saveMail(getPath(FALSE) + "inbox.txt", inboxView); 87 saveMail(getPath(FALSE) + "inbox.txt", inboxView);
88 //does not currently work. Defining outbox in the same 88 //does not currently work. Defining outbox in the same
89 //format as inbox is not a good solution as they have 89 //format as inbox is not a good solution as they have
90 //different properties 90 //different properties
91 saveMail(getPath(FALSE) + "outbox.txt", outboxView); 91 saveMail(getPath(FALSE) + "outbox.txt", outboxView);
92 saveSettings(); 92 saveSettings();
93 93
94 mailconf->write(); 94 mailconf->write();
95 delete mailconf; 95 delete mailconf;
96 96
97} 97}
98 98
99void EmailClient::init() 99void EmailClient::init()
100{ 100{
101 statusBar = new QStatusBar(this); 101 statusBar = new QStatusBar(this);
102 statusBar->setSizeGripEnabled(FALSE); 102 statusBar->setSizeGripEnabled(FALSE);
103 103
104 status1Label = new QLabel( tr("Idle"), statusBar); 104 status1Label = new QLabel( tr("Idle"), statusBar);
105 status2Label = new QLabel("", statusBar); 105 status2Label = new QLabel("", statusBar);
106 connect(emailHandler, SIGNAL(updatePopStatus(const QString &)), 106 connect(emailHandler, SIGNAL(updatePopStatus(const QString &)),
107 status2Label, SLOT(setText(const QString &)) ); 107 status2Label, SLOT(setText(const QString &)) );
108 connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)), 108 connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)),
109 status2Label, SLOT(setText(const QString &)) ); 109 status2Label, SLOT(setText(const QString &)) );
110 110
111 progressBar = new QProgressBar(statusBar); 111 progressBar = new QProgressBar(statusBar);
112 connect(emailHandler, SIGNAL(mailboxSize(int)), 112 connect(emailHandler, SIGNAL(mailboxSize(int)),
113 this, SLOT(setTotalSize(int)) ); 113 this, SLOT(setTotalSize(int)) );
114 connect(emailHandler, SIGNAL(currentMailSize(int)), 114 connect(emailHandler, SIGNAL(currentMailSize(int)),
115 this, SLOT(setMailSize(int)) ); 115 this, SLOT(setMailSize(int)) );
116 connect(emailHandler, SIGNAL(downloadedSize(int)), 116 connect(emailHandler, SIGNAL(downloadedSize(int)),
117 this, SLOT(setDownloadedSize(int)) ); 117 this, SLOT(setDownloadedSize(int)) );
118 118
119 statusBar->addWidget(status1Label); 119 statusBar->addWidget(status1Label);
120 statusBar->addWidget(progressBar); 120 statusBar->addWidget(progressBar);
121 statusBar->addWidget(status2Label); 121 statusBar->addWidget(status2Label);
122 122
123 setToolBarsMovable(FALSE); 123 setToolBarsMovable(FALSE);
124 124
125 bar = new QToolBar(this); 125 bar = new QToolBar(this);
126 bar->setHorizontalStretchable( TRUE ); 126 bar->setHorizontalStretchable( TRUE );
127 127
128 mb = new QMenuBar( bar ); 128 mb = new QMenuBar( bar );
129 129
130 QPopupMenu *mail = new QPopupMenu(mb); 130 QPopupMenu *mail = new QPopupMenu(mb);
131 mb->insertItem( tr( "&Mail" ), mail); 131 mb->insertItem( tr( "&Mail" ), mail);
132 132
133 QPopupMenu *configure = new QPopupMenu(mb); 133 QPopupMenu *configure = new QPopupMenu(mb);
134 mb->insertItem( tr( "Accounts" ), configure); 134 mb->insertItem( tr( "Accounts" ), configure);
135 135
136 selectAccountMenu = new QPopupMenu(mb); 136 selectAccountMenu = new QPopupMenu(mb);
137 editAccountMenu = new QPopupMenu(mb); 137 editAccountMenu = new QPopupMenu(mb);
138 deleteAccountMenu = new QPopupMenu(mb); 138 deleteAccountMenu = new QPopupMenu(mb);
139 139
140 mail->insertItem(tr("Get Mail in"), selectAccountMenu); 140 mail->insertItem(tr("Get Mail in"), selectAccountMenu);
141 configure->insertItem(tr("Edit account"), editAccountMenu); 141 configure->insertItem(tr("Edit account"), editAccountMenu);
142 configure->insertItem(tr("Delete account"), deleteAccountMenu); 142 configure->insertItem(tr("Delete account"), deleteAccountMenu);
143 143
144 bar = new QToolBar(this); 144 bar = new QToolBar(this);
145 145
146 getMailButton = new QAction(tr("Get all mail"), Resource::loadPixmap("mailit/getmail"), QString::null, 0, this, 0); 146 getMailButton = new QAction(tr("Get all mail"), Resource::loadPixmap("mailit/getmail"), QString::null, 0, this, 0);
147 connect(getMailButton, SIGNAL(activated()), this, SLOT(getAllNewMail()) ); 147 connect(getMailButton, SIGNAL(activated()), this, SLOT(getAllNewMail()) );
148 getMailButton->addTo(bar); 148 getMailButton->addTo(bar);
149 getMailButton->addTo(mail); 149 getMailButton->addTo(mail);
150 150
151 sendMailButton = new QAction(tr("Send mail"), Resource::loadPixmap("mailit/sendqueue"), QString::null, 0, this, 0); 151 sendMailButton = new QAction(tr("Send mail"), Resource::loadPixmap("mailit/sendqueue"), QString::null, 0, this, 0);
152 connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) ); 152 connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) );
153 sendMailButton->addTo(bar); 153 sendMailButton->addTo(bar);
154 sendMailButton->addTo(mail); 154 sendMailButton->addTo(mail);
155 155
156 composeButton = new QAction(tr("Compose"), Resource::loadPixmap("new"), QString::null, 0, this, 0); 156 composeButton = new QAction(tr("Compose"), Resource::loadPixmap("new"), QString::null, 0, this, 0);
157 connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) ); 157 connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) );
158 composeButton->addTo(bar); 158 composeButton->addTo(bar);
159 composeButton->addTo(mail); 159 composeButton->addTo(mail);
160 160
161 cancelButton = new QAction(tr("Cancel transfer"), Resource::loadPixmap("close"), QString::null, 0, this, 0); 161 cancelButton = new QAction(tr("Cancel transfer"), Resource::loadPixmap("close"), QString::null, 0, this, 0);
162 connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) ); 162 connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) );
163 cancelButton->addTo(mail); 163 cancelButton->addTo(mail);
164 cancelButton->addTo(bar); 164 cancelButton->addTo(bar);
165 cancelButton->setEnabled(FALSE); 165 cancelButton->setEnabled(FALSE);
166 166
167 mailboxView = new OTabWidget( this, "mailboxView" ); 167 mailboxView = new OTabWidget( this, "mailboxView" );
168 168
169 QWidget* widget = new QWidget( mailboxView, "widget" ); 169 QWidget* widget = new QWidget( mailboxView, "widget" );
170 grid_2 = new QGridLayout( widget ); 170 grid_2 = new QGridLayout( widget );
171// grid_2->setSpacing(6); 171// grid_2->setSpacing(6);
172// grid_2->setMargin( 11 ); 172// grid_2->setMargin( 11 );
173 173
174 inboxView = new QListView( widget, "inboxView" ); 174 inboxView = new QListView( widget, "inboxView" );
175 inboxView->addColumn( tr( "From" ) ); 175 inboxView->addColumn( tr( "From" ) );
176 inboxView->addColumn( tr( "Subject" ) ); 176 inboxView->addColumn( tr( "Subject" ) );
177 inboxView->addColumn( tr( "Date" ) ); 177 inboxView->addColumn( tr( "Date" ) );
178 inboxView->setMinimumSize( QSize( 0, 0 ) ); 178 inboxView->setMinimumSize( QSize( 0, 0 ) );
179 inboxView->setAllColumnsShowFocus(TRUE); 179 inboxView->setAllColumnsShowFocus(TRUE);
180 180
181 grid_2->addWidget( inboxView, 2, 0 ); 181 grid_2->addWidget( inboxView, 2, 0 );
182 mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) ); 182 mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) );
183 183
184 QWidget* widget_2 = new QWidget( mailboxView, "widget_2" ); 184 QWidget* widget_2 = new QWidget( mailboxView, "widget_2" );
185 grid_3 = new QGridLayout( widget_2 ); 185 grid_3 = new QGridLayout( widget_2 );
186// grid_3->setSpacing(6); 186// grid_3->setSpacing(6);
187// grid_3->setMargin( 11 ); 187// grid_3->setMargin( 11 );
188 188
189 outboxView = new QListView( widget_2, "outboxView" ); 189 outboxView = new QListView( widget_2, "outboxView" );
190 outboxView->addColumn( tr( "To" ) ); 190 outboxView->addColumn( tr( "To" ) );
191 outboxView->addColumn( tr( "Subject" ) ); 191 outboxView->addColumn( tr( "Subject" ) );
192 outboxView->setAllColumnsShowFocus(TRUE); 192 outboxView->setAllColumnsShowFocus(TRUE);
193 193
194 grid_3->addWidget( outboxView, 0, 0 ); 194 grid_3->addWidget( outboxView, 0, 0 );
195 mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) ); 195 mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) );
196 196
197 setCentralWidget(mailboxView); 197 setCentralWidget(mailboxView);
198} 198}
199 199
200void EmailClient::compose() 200void EmailClient::compose()
201{ 201{
202 emit composeRequested(); 202 emit composeRequested();
203} 203}
204 204
205void EmailClient::cancel() 205void EmailClient::cancel()
206{ 206{
207 emailHandler->cancel(); 207 emailHandler->cancel();
208} 208}
209 209
210AddressList* EmailClient::getAdrListRef() 210AddressList* EmailClient::getAdrListRef()
211{ 211{
212 return addressList; 212 return addressList;
213} 213}
214 214
215//this needs to be rewritten to syncronize with outboxView 215//this needs to be rewritten to syncronize with outboxView
216void EmailClient::enqueMail(const Email &mail) 216void EmailClient::enqueMail(const Email &mail)
217{ 217{
218 if (accountList.count() == 0) { 218 if (accountList.count() == 0) {
219 QMessageBox::warning(qApp->activeWindow(), 219 QMessageBox::warning(qApp->activeWindow(),
220 tr("No account selected"), tr("You must create an account"), "OK\n"); 220 tr("No account selected"), tr("You must create an account"), "OK\n");
221 return; 221 return;
222 } 222 }
223 223
224 if (accountList.count() > 0) { 224 if (accountList.count() > 0) {
225 currentAccount = accountList.first(); 225 currentAccount = accountList.first();
226 qWarning("using account " + currentAccount->name); 226 qWarning("using account " + currentAccount->name);
227 } 227 }
228 228
229 Email addMail = mail; 229 Email addMail = mail;
230 addMail.from = currentAccount->name; 230 addMail.from = currentAccount->name;
231 addMail.fromMail = currentAccount->emailAddress; 231 addMail.fromMail = currentAccount->emailAddress;
232 addMail.rawMail.prepend("From: " + addMail.from + "<" + addMail.fromMail + ">\n"); 232 addMail.rawMail.prepend("From: " + addMail.from + "<" + addMail.fromMail + ">\n");
233 item = new EmailListItem(outboxView, addMail, false); 233 item = new EmailListItem(outboxView, addMail, false);
234 234
235} 235}
236 236
237void EmailClient::sendQuedMail() 237void EmailClient::sendQuedMail()
238{ 238{
239 int count = 0; 239 int count = 0;
240 240
241 if (accountList.count() == 0) { 241 if (accountList.count() == 0) {
242 QMessageBox::warning(qApp->activeWindow(), "No account selected", "You must create an account", "OK\n"); 242 QMessageBox::warning(qApp->activeWindow(), "No account selected", "You must create an account", "OK\n");
243 return; 243 return;
244 } 244 }
245 //traverse listview, find messages to send 245 //traverse listview, find messages to send
246 if (! sending) { 246 if (! sending) {
247 item = (EmailListItem *) outboxView->firstChild(); 247 item = (EmailListItem *) outboxView->firstChild();
248 if (item != NULL) { 248 if (item != NULL) {
249 while (item != NULL) { 249 while (item != NULL) {
250 quedMessages.append(item->getMail()); 250 quedMessages.append(item->getMail());
251 item = (EmailListItem *) item->nextSibling(); 251 item = (EmailListItem *) item->nextSibling();
252 count++; 252 count++;
253 } 253 }
254 setMailAccount(); 254 setMailAccount();
255 emailHandler->sendMail(&quedMessages); 255 emailHandler->sendMail(&quedMessages);
256 sending = TRUE; 256 sending = TRUE;
257 sendMailButton->setEnabled(FALSE); 257 sendMailButton->setEnabled(FALSE);
258 cancelButton->setEnabled(TRUE); 258 cancelButton->setEnabled(TRUE);
259 } else { 259 } else {
260 qWarning("sendQuedMail(): no messages to send"); 260 qWarning("sendQuedMail(): no messages to send");
261 } 261 }
262 } 262 }
263} 263}
264 264
265void EmailClient::setMailAccount() 265void EmailClient::setMailAccount()
266{ 266{
267 emailHandler->setAccount(*currentAccount); 267 emailHandler->setAccount(*currentAccount);
268} 268}
269 269
270void EmailClient::mailSent() 270void EmailClient::mailSent()
271{ 271{
272 sending = FALSE; 272 sending = FALSE;
273 sendMailButton->setEnabled(TRUE); 273 sendMailButton->setEnabled(TRUE);
274 274
275 quedMessages.clear(); 275 quedMessages.clear();
276 outboxView->clear(); //should be moved to an sentBox 276 outboxView->clear(); //should be moved to an sentBox
277} 277}
278 278
279void EmailClient::getNewMail() { 279void EmailClient::getNewMail() {
280 280
281 if (accountList.count() == 0) { 281 if (accountList.count() == 0) {
282 QMessageBox::warning(qApp->activeWindow(),"No account selected", 282 QMessageBox::warning(qApp->activeWindow(),"No account selected",
283 "You must create an account", "OK\n"); 283 "You must create an account", "OK\n");
284 return; 284 return;
285 } 285 }
286 286
287 setMailAccount(); 287 setMailAccount();
288 288
289 receiving = TRUE; 289 receiving = TRUE;
290 previewingMail = TRUE; 290 previewingMail = TRUE;
291 getMailButton->setEnabled(FALSE); 291 getMailButton->setEnabled(FALSE);
292 cancelButton->setEnabled(TRUE); 292 cancelButton->setEnabled(TRUE);
293 selectAccountMenu->setEnabled(FALSE); 293 selectAccountMenu->setEnabled(FALSE);
294 294
295 status1Label->setText(currentAccount->accountName + " headers"); 295 status1Label->setText(currentAccount->accountName + " headers");
296 progressBar->reset(); 296 progressBar->reset();
297 297
298 //get any previous mails not downloaded and add to queue 298 //get any previous mails not downloaded and add to queue
299 mailDownloadList.clear(); 299 mailDownloadList.clear();
300 Email *mailPtr; 300 Email *mailPtr;
301 item = (EmailListItem *) inboxView->firstChild(); 301 item = (EmailListItem *) inboxView->firstChild();
302 while (item != NULL) { 302 while (item != NULL) {
303 mailPtr = item->getMail(); 303 mailPtr = item->getMail();
304 if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { 304 if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) {
305 mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); 305 mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size);
306 } 306 }
307 item = (EmailListItem *) item->nextSibling(); 307 item = (EmailListItem *) item->nextSibling();
308 } 308 }
309 309
310 emailHandler->getMailHeaders(); 310 emailHandler->getMailHeaders();
311} 311}
312 312
313void EmailClient::getAllNewMail() 313void EmailClient::getAllNewMail()
314{ 314{
315 allAccounts = TRUE; 315 allAccounts = TRUE;
316 currentAccount = accountList.first(); 316 currentAccount = accountList.first();
317 getNewMail(); 317 getNewMail();
318} 318}
319 319
320void EmailClient::mailArrived(const Email &mail, bool fromDisk) 320void EmailClient::mailArrived(const Email &mail, bool fromDisk)
321{ 321{
322 Enclosure *ePtr; 322 Enclosure *ePtr;
323 Email newMail; 323 Email newMail;
324 int thisMailId; 324 int thisMailId;
325 emailHandler->parse(mail.rawMail, lineShift, &newMail); 325 emailHandler->parse(mail.rawMail, lineShift, &newMail);
326 326
327 mailconf->setGroup(newMail.id); 327 mailconf->setGroup(newMail.id);
328 328
329 if (fromDisk) { 329 if (fromDisk) {
330 newMail.downloaded = mailconf->readBoolEntry("downloaded"); 330 newMail.downloaded = mailconf->readBoolEntry("downloaded");
331 newMail.size = mailconf->readNumEntry("size"); 331 newMail.size = mailconf->readNumEntry("size");
332 newMail.serverId = mailconf->readNumEntry("serverid"); 332 newMail.serverId = mailconf->readNumEntry("serverid");
333 newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); 333 newMail.fromAccountId = mailconf->readNumEntry("fromaccountid");
334 } else { //mail arrived from server 334 } else { //mail arrived from server
335 newMail.serverId = mail.serverId; 335 newMail.serverId = mail.serverId;
336 newMail.size = mail.size; 336 newMail.size = mail.size;
337 newMail.downloaded = mail.downloaded; 337 newMail.downloaded = mail.downloaded;
338 338
339 newMail.fromAccountId = currentAccount->id; 339 newMail.fromAccountId = currentAccount->id;
340 mailconf->writeEntry("fromaccountid", newMail.fromAccountId); 340 mailconf->writeEntry("fromaccountid", newMail.fromAccountId);
341 } 341 }
342 342
343 //add if read or not 343 //add if read or not
344 newMail.read = mailconf->readBoolEntry("mailread"); 344 newMail.read = mailconf->readBoolEntry("mailread");
345 345
346 //check if new mail 346 //check if new mail
347 if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { 347 if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) {
348 thisMailId = mailIdCount; 348 thisMailId = mailIdCount;
349 mailIdCount++; 349 mailIdCount++;
350 350
351 //set server count, so that if the user aborts, the new 351 //set server count, so that if the user aborts, the new
352 //header is not reloaded 352 //header is not reloaded
353 if (currentAccount->synchronize) 353 if (currentAccount->synchronize)
354 currentAccount->lastServerMailCount++; 354 currentAccount->lastServerMailCount++;
355 355
356 mailconf->writeEntry("internalmailid", thisMailId); 356 mailconf->writeEntry("internalmailid", thisMailId);
357 mailconf->writeEntry("downloaded", newMail.downloaded); 357 mailconf->writeEntry("downloaded", newMail.downloaded);
358 mailconf->writeEntry("size", (int) newMail.size); 358 mailconf->writeEntry("size", (int) newMail.size);
359 mailconf->writeEntry("serverid", newMail.serverId); 359 mailconf->writeEntry("serverid", newMail.serverId);
360 360
361 addressList->addContact(newMail.fromMail, newMail.from); 361 addressList->addContact(newMail.fromMail, newMail.from);
362 } else if (!fromDisk) { //body to header arrived 362 } else if (!fromDisk) { //body to header arrived
363 mailconf->writeEntry("downloaded", TRUE); 363 mailconf->writeEntry("downloaded", TRUE);
364 } 364 }
365 QString stringMailId; 365 QString stringMailId;
366 stringMailId.setNum(thisMailId); 366 stringMailId.setNum(thisMailId);
367 //se if any attatchments needs to be stored 367 //se if any attatchments needs to be stored
368 for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { 368 for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) {
369 QString stringId; 369 QString stringId;
370 stringId.setNum(ePtr->id); 370 stringId.setNum(ePtr->id);
371 371
372 int id = mailconf->readNumEntry("enclosureid_" + stringId); 372 int id = mailconf->readNumEntry("enclosureid_" + stringId);
373 if (id != ePtr->id) { //new entry 373 if (id != ePtr->id) { //new entry
374 mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); 374 mailconf->writeEntry("enclosureid_" + stringId, ePtr->id);
375 mailconf->writeEntry("name_" + stringId, ePtr->originalName); 375 mailconf->writeEntry("name_" + stringId, ePtr->originalName);
376 mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); 376 mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType);
377 mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); 377 mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute);
378 mailconf->writeEntry("saved_" + stringId, ePtr->saved); 378 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
379 mailconf->writeEntry("installed_" + stringId, FALSE); 379 mailconf->writeEntry("installed_" + stringId, FALSE);
380 380
381 ePtr->name = stringMailId + "_" + stringId; 381 ePtr->name = stringMailId + "_" + stringId;
382 ePtr->path = getPath(TRUE); 382 ePtr->path = getPath(TRUE);
383 if (emailHandler->getEnclosure(ePtr)) { //file saved 383 if (emailHandler->getEnclosure(ePtr)) { //file saved
384 ePtr->saved = TRUE; 384 ePtr->saved = TRUE;
385 mailconf->writeEntry("saved_" + stringId, ePtr->saved); 385 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
386 mailconf->writeEntry("filename_" + stringId, ePtr->name); 386 mailconf->writeEntry("filename_" + stringId, ePtr->name);
387 mailconf->writeEntry("path_" + stringId, ePtr->path); 387 mailconf->writeEntry("path_" + stringId, ePtr->path);
388 } else { 388 } else {
389 ePtr->saved = FALSE; 389 ePtr->saved = FALSE;
390 mailconf->writeEntry("saved_" + stringId, ePtr->saved); 390 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
391 } 391 }
392 } else { 392 } else {
393 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); 393 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId);
394 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); 394 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId);
395 if (ePtr->saved) { 395 if (ePtr->saved) {
396 ePtr->name = mailconf->readEntry("filename_" + stringId); 396 ePtr->name = mailconf->readEntry("filename_" + stringId);
397 ePtr->path = mailconf->readEntry("path_" + stringId); 397 ePtr->path = mailconf->readEntry("path_" + stringId);
398 } 398 }
399 } 399 }
400 } 400 }
401 if (!previewingMail && !fromDisk) { 401 if (!previewingMail && !fromDisk) {
402 Email *mailPtr; 402 Email *mailPtr;
403 item = (EmailListItem *) inboxView->firstChild(); 403 item = (EmailListItem *) inboxView->firstChild();
404 while (item != NULL) { 404 while (item != NULL) {
405 mailPtr = item->getMail(); 405 mailPtr = item->getMail();
406 if (mailPtr->id == newMail.id) { 406 if (mailPtr->id == newMail.id) {
407 item->setMail(newMail); 407 item->setMail(newMail);
408 emit mailUpdated(item->getMail()); 408 emit mailUpdated(item->getMail());
409 } 409 }
410 item = (EmailListItem *) item->nextSibling(); 410 item = (EmailListItem *) item->nextSibling();
411 } 411 }
412 } else { 412 } else {
413 item = new EmailListItem(inboxView, newMail, TRUE); 413 item = new EmailListItem(inboxView, newMail, TRUE);
414 if (!newMail.downloaded) 414 if (!newMail.downloaded)
415 mailDownloadList.sizeInsert(newMail.serverId, newMail.size); 415 mailDownloadList.sizeInsert(newMail.serverId, newMail.size);
416 } 416 }
417 417
418} 418}
419 419
420void EmailClient::allMailArrived(int count) 420void EmailClient::allMailArrived(int count)
421{ 421{
422 // not previewing means all mailtransfer has been done 422 // not previewing means all mailtransfer has been done
423 if (!previewingMail) { 423 if (!previewingMail) {
424 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { 424 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) {
425 emit newCaption("Mailit - " + currentAccount->accountName); 425 emit newCaption("Mailit - " + currentAccount->accountName);
426 getNewMail(); 426 getNewMail();
427 return; 427 return;
428 } else { 428 } else {
429 allAccounts = FALSE; 429 allAccounts = FALSE;
430 receiving = FALSE; 430 receiving = FALSE;
431 getMailButton->setEnabled(TRUE); 431 getMailButton->setEnabled(TRUE);
432 cancelButton->setEnabled(FALSE); 432 cancelButton->setEnabled(FALSE);
433 selectAccountMenu->setEnabled(TRUE); 433 selectAccountMenu->setEnabled(TRUE);
434 status1Label->setText("Idle"); 434 status1Label->setText("Idle");
435 435
436 progressBar->reset(); 436 progressBar->reset();
437 return; 437 return;
438 } 438 }
439 } 439 }
440 440
441 // all headers downloaded from server, start downloading remaining mails 441 // all headers downloaded from server, start downloading remaining mails
442 previewingMail = FALSE; 442 previewingMail = FALSE;
443 status1Label->setText(currentAccount->accountName); 443 status1Label->setText(currentAccount->accountName);
444 progressBar->reset(); 444 progressBar->reset();
445 445
446 emailHandler->getMailByList(&mailDownloadList); 446 emailHandler->getMailByList(&mailDownloadList);
447} 447}
448 448
449void EmailClient::moveMailFront(Email *mailPtr) 449void EmailClient::moveMailFront(Email *mailPtr)
450{ 450{
451 if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { 451 if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) {
452 mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); 452 mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size);
453 } 453 }
454} 454}
455 455
456void EmailClient::smtpError(int code) 456void EmailClient::smtpError(int code)
457{ 457{
458 QString temp; 458 QString temp;
459 459
460 if (code == ErrUnknownResponse) 460 if (code == ErrUnknownResponse)
461 temp = "Unknown response from server"; 461 temp = "Unknown response from server";
462 462
463 if (code == QSocket::ErrHostNotFound) 463 if (code == QSocket::ErrHostNotFound)
464 temp = "host not found"; 464 temp = "host not found";
465 if (code == QSocket::ErrConnectionRefused) 465 if (code == QSocket::ErrConnectionRefused)
466 temp = "connection refused"; 466 temp = "connection refused";
467 if (code == QSocket::ErrSocketRead) 467 if (code == QSocket::ErrSocketRead)
468 temp = "socket packet error"; 468 temp = "socket packet error";
469 469
470 if (code != ErrCancel) { 470 if (code != ErrCancel) {
471 QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); 471 QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n");
472 } else { 472 } else {
473 status2Label->setText("Aborted by user"); 473 status2Label->setText("Aborted by user");
474 } 474 }
475 475
476 sending = FALSE; 476 sending = FALSE;
477 sendMailButton->setEnabled(TRUE); 477 sendMailButton->setEnabled(TRUE);
478 cancelButton->setEnabled(FALSE); 478 cancelButton->setEnabled(FALSE);
479 quedMessages.clear(); 479 quedMessages.clear();
480} 480}
481 481
482void EmailClient::popError(int code) 482void EmailClient::popError(int code)
483{ 483{
484 QString temp; 484 QString temp;
485 485
486 if (code == ErrUnknownResponse) 486 if (code == ErrUnknownResponse)
487 temp = "Unknown response from server"; 487 temp = "Unknown response from server";
488 if (code == ErrLoginFailed) 488 if (code == ErrLoginFailed)
489 temp = "Login failed\nCheck user name and password"; 489 temp = "Login failed\nCheck user name and password";
490 490
491 if (code == QSocket::ErrHostNotFound) 491 if (code == QSocket::ErrHostNotFound)
492 temp = "host not found"; 492 temp = "host not found";
493 if (code == QSocket::ErrConnectionRefused) 493 if (code == QSocket::ErrConnectionRefused)
494 temp = "connection refused"; 494 temp = "connection refused";
495 if (code == QSocket::ErrSocketRead) 495 if (code == QSocket::ErrSocketRead)
496 temp = "socket packet error"; 496 temp = "socket packet error";
497 497
498 if (code != ErrCancel) { 498 if (code != ErrCancel) {
499 QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n"); 499 QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n");
500 } else { 500 } else {
501 status2Label->setText("Aborted by user"); 501 status2Label->setText("Aborted by user");
502 } 502 }
503 503
504 receiving = FALSE; 504 receiving = FALSE;
505 getMailButton->setEnabled(TRUE); 505 getMailButton->setEnabled(TRUE);
506 cancelButton->setEnabled(FALSE); 506 cancelButton->setEnabled(FALSE);
507 selectAccountMenu->setEnabled(TRUE); 507 selectAccountMenu->setEnabled(TRUE);
508} 508}
509 509
510void EmailClient::inboxItemSelected() 510void EmailClient::inboxItemSelected()
511{ 511{
512 item = (EmailListItem*) inboxView->selectedItem(); 512 item = (EmailListItem*) inboxView->selectedItem();
513 if (item != NULL) { 513 if (item != NULL) {
514 emit viewEmail(inboxView, item->getMail()); 514 emit viewEmail(inboxView, item->getMail());
515 } 515 }
516} 516}
517 517
518void EmailClient::outboxItemSelected() 518void EmailClient::outboxItemSelected()
519{ 519{
520 item = (EmailListItem*) outboxView->selectedItem(); 520 item = (EmailListItem*) outboxView->selectedItem();
521 if (item != NULL) { 521 if (item != NULL) {
522 emit viewEmail(outboxView, item->getMail()); 522 emit viewEmail(outboxView, item->getMail());
523 } 523 }
524 524
525} 525}
526 526
527void EmailClient::readMail() 527void EmailClient::readMail()
528{ 528{
529 Email mail; 529 Email mail;
530 int start, stop; 530 int start, stop;
531 QString s, del; 531 QString s, del;
532 532
533 QFile f(getPath(FALSE) + "inbox.txt"); 533 QFile f(getPath(FALSE) + "inbox.txt");
534// QFileInfo fi(f); 534// QFileInfo fi(f);
535 qDebug( f.name()); 535 qDebug( f.name());
536 536
537 if ( f.open(IO_ReadOnly) ) { // file opened successfully 537 if ( f.open(IO_ReadOnly) ) { // file opened successfully
538 QTextStream t( &f ); // use a text stream 538 QTextStream t( &f ); // use a text stream
539 s = t.read(); 539 s = t.read();
540 f.close(); 540 f.close();
541 541
542 start = 0; 542 start = 0;
543 del = "\n.\n"; 543 del = "\n.\n";
544 while ((uint) start < s.length()) { 544 while ((uint) start < s.length()) {
545 stop = s.find(del, start); 545 stop = s.find(del, start);
546 if (stop == -1) 546 if (stop == -1)
547 stop = s.length() - del.length(); 547 stop = s.length() - del.length();
548 548
549 mail.rawMail = s.mid(start, stop + del.length() - start ); 549 mail.rawMail = s.mid(start, stop + del.length() - start );
550 start = stop + del.length(); 550 start = stop + del.length();
551 mailArrived(mail, TRUE); 551 mailArrived(mail, TRUE);
552 } 552 }
553 } 553 }
554 554
555 QFile fo(getPath(FALSE) + "outbox.txt"); 555 QFile fo(getPath(FALSE) + "outbox.txt");
556 if ( fo.open(IO_ReadOnly) ) { // file opened successfully 556 if ( fo.open(IO_ReadOnly) ) { // file opened successfully
557 QTextStream t( &fo ); // use a text stream 557 QTextStream t( &fo ); // use a text stream
558 s = t.read(); 558 s = t.read();
559 fo.close(); 559 fo.close();
560 560
561 start = 0; 561 start = 0;
562 del = "\n.\n"; 562 del = "\n.\n";
563 while ((uint) start < s.length()) { 563 while ((uint) start < s.length()) {
564 stop = s.find(del, start); 564 stop = s.find(del, start);
565 if (stop == -1) 565 if (stop == -1)
566 stop = s.length() - del.length(); 566 stop = s.length() - del.length();
567 567
568 mail.rawMail = s.mid(start, stop + del.length() - start ); 568 mail.rawMail = s.mid(start, stop + del.length() - start );
569 start = stop + del.length(); 569 start = stop + del.length();
570 emailHandler->parse(mail.rawMail, lineShift, &mail); 570 emailHandler->parse(mail.rawMail, lineShift, &mail);
571 mail.sent = false; 571 mail.sent = false;
572 mail.received = false; 572 mail.received = false;
573 enqueMail(mail); 573 enqueMail(mail);
574 574
575 } 575 }
576 } 576 }
577} 577}
578 578
579void EmailClient::saveMail(QString fileName, QListView *view) 579void EmailClient::saveMail(QString fileName, QListView *view)
580{ 580{
581 QFile f(fileName); 581 QFile f(fileName);
582 Email *mail; 582 Email *mail;
583 583
584 if (! f.open(IO_WriteOnly) ) { 584 if (! f.open(IO_WriteOnly) ) {
585 qWarning("could not open file"); 585 qWarning("could not open file");
586 return; 586 return;
587 } 587 }
588 item = (EmailListItem *) view->firstChild(); 588 item = (EmailListItem *) view->firstChild();
589 qDebug (QString("Write : ") ); 589 qDebug (QString("Write : ") );
590 QTextStream t(&f); 590 QTextStream t(&f);
591 while (item != NULL) { 591 while (item != NULL) {
592 mail = item->getMail(); 592 mail = item->getMail();
593 qDebug(mail->rawMail); 593 qDebug(mail->rawMail);
594 qDebug(mail->recipients.first()); 594 qDebug(mail->recipients.first());
595 t << mail->rawMail; 595 t << mail->rawMail;
596 596
597 mailconf->setGroup(mail->id); 597 mailconf->setGroup(mail->id);
598 mailconf->writeEntry("mailread", mail->read); 598 mailconf->writeEntry("mailread", mail->read);
599 599
600 item = (EmailListItem *) item->nextSibling(); 600 item = (EmailListItem *) item->nextSibling();
601 } 601 }
602 f.close(); 602 f.close();
603} 603}
604 604
605//paths for mailit, is settings, inbox, enclosures 605//paths for mailit, is settings, inbox, enclosures
606QString EmailClient::getPath(bool enclosurePath) 606QString EmailClient::getPath(bool enclosurePath)
607{ 607{
608 QString basePath = "qtmail"; 608 QString basePath = "qtmail";
609 QString enclosures = "enclosures"; 609 QString enclosures = "enclosures";
610 610
611 QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); 611 QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath);
612 if ( !dir.exists() ) 612 if ( !dir.exists() )
613 dir.mkdir( dir.path() ); 613 dir.mkdir( dir.path() );
614 614
615 if (enclosurePath) { 615 if (enclosurePath) {
616 dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); 616 dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures);
617 617
618 if ( !dir.exists() ) 618 if ( !dir.exists() )
619 dir.mkdir( dir.path() ); 619 dir.mkdir( dir.path() );
620 620
621 return (dir.path() + "/"); 621 return (dir.path() + "/");
622 622
623 } 623 }
624 return (dir.path() + "/"); 624 return (dir.path() + "/");
625} 625}
626 626
627void EmailClient::readSettings() 627void EmailClient::readSettings()
628{ 628{
629 TextParser *p; 629 TextParser *p;
630 QString s; 630 QString s;
631 int pos, accountPos, y; 631 int pos, accountPos, y;
632 QFile f( getPath(FALSE) + "settings.txt"); 632 QFile f( getPath(FALSE) + "settings.txt");
633 633
634 if ( f.open(IO_ReadOnly) ) { // file opened successfully 634 if ( f.open(IO_ReadOnly) ) { // file opened successfully
635 QTextStream t( &f ); // use a text stream 635 QTextStream t( &f ); // use a text stream
636 s = t.read(); 636 s = t.read();
637 f.close(); 637 f.close();
638 638
639 p = new TextParser(s, "\n"); 639 p = new TextParser(s, "\n");
640 640
641 accountPos = 0; 641 accountPos = 0;
642 while ( (accountPos = p->find("ACCOUNTSTART",';', accountPos, TRUE)) != -1 ) { 642 while ( (accountPos = p->find("ACCOUNTSTART",';', accountPos, TRUE)) != -1 ) {
643 accountPos++; 643 accountPos++;
644 if ( (pos = p->find("ACCOUNTNAME",':', accountPos, TRUE)) != -1 ) 644 if ( (pos = p->find("ACCOUNTNAME",':', accountPos, TRUE)) != -1 )
645 account.accountName = p->getString(& ++pos, 'z', TRUE); 645 account.accountName = p->getString(& ++pos, 'z', TRUE);
646 if ( (pos = p->find("NAME",':', accountPos, TRUE)) != -1) 646 if ( (pos = p->find("NAME",':', accountPos, TRUE)) != -1)
647 account.name = p->getString(& ++pos, 'z', TRUE); 647 account.name = p->getString(& ++pos, 'z', TRUE);
648 if ( (pos = p->find("EMAIL",':', accountPos, TRUE)) != -1) 648 if ( (pos = p->find("EMAIL",':', accountPos, TRUE)) != -1)
649 account.emailAddress = p->getString(& ++pos, 'z', TRUE); 649 account.emailAddress = p->getString(& ++pos, 'z', TRUE);
650 if ( (pos = p->find("POPUSER",':', accountPos, TRUE)) != -1) 650 if ( (pos = p->find("POPUSER",':', accountPos, TRUE)) != -1)
651 account.popUserName = p->getString(& ++pos, 'z', TRUE); 651 account.popUserName = p->getString(& ++pos, 'z', TRUE);
652 if ( (pos = p->find("POPPASSWORD",':', accountPos, TRUE)) != -1) 652 if ( (pos = p->find("POPPASSWORD",':', accountPos, TRUE)) != -1)
653 account.popPasswd = p->getString(& ++pos, 'z', TRUE); 653 account.popPasswd = p->getString(& ++pos, 'z', TRUE);
654 if ( (pos = p->find("POPSERVER",':', accountPos, TRUE)) != -1) 654 if ( (pos = p->find("POPSERVER",':', accountPos, TRUE)) != -1)
655 account.popServer = p->getString(& ++pos, 'z', TRUE); 655 account.popServer = p->getString(& ++pos, 'z', TRUE);
656 if ( (pos = p->find("SMTPSERVER",':', accountPos, TRUE)) != -1) 656 if ( (pos = p->find("SMTPSERVER",':', accountPos, TRUE)) != -1)
657 account.smtpServer = p->getString(& ++pos, 'z', TRUE); 657 account.smtpServer = p->getString(& ++pos, 'z', TRUE);
658 if ( (pos = p->find("ACCOUNTID",':', accountPos, TRUE)) != -1) { 658 if ( (pos = p->find("ACCOUNTID",':', accountPos, TRUE)) != -1) {
659 s = p->getString(& ++pos, 'z', TRUE); 659 s = p->getString(& ++pos, 'z', TRUE);
660 account.id = s.toInt(); 660 account.id = s.toInt();
661 } 661 }
662 662
663 account.lastServerMailCount = 0; 663 account.lastServerMailCount = 0;
664 account.synchronize = FALSE; 664 account.synchronize = FALSE;
665 if ( (pos = p->find("SYNCHRONIZE",':', accountPos, TRUE)) != -1) { 665 if ( (pos = p->find("SYNCHRONIZE",':', accountPos, TRUE)) != -1) {
666 if (p->getString(& ++pos, 'z', TRUE).upper() == "YES") { 666 if (p->getString(& ++pos, 'z', TRUE).upper() == "YES") {
667 account.synchronize = TRUE; 667 account.synchronize = TRUE;
668 if ( (pos = p->find("LASTSERVERMAILCOUNT",':', accountPos, TRUE)) != -1) { 668 if ( (pos = p->find("LASTSERVERMAILCOUNT",':', accountPos, TRUE)) != -1) {
669 s = p->getString(& ++pos, 'z', TRUE); 669 s = p->getString(& ++pos, 'z', TRUE);
670 account.lastServerMailCount = s.toInt(); 670 account.lastServerMailCount = s.toInt();
671 } 671 }
672 } 672 }
673 } 673 }
674
675 if ( (pos = p->find("SYNCLIMIT",':', accountPos, TRUE)) != -1) {
676 account.syncLimit = p->getString(& ++pos, 'z', TRUE).toInt();
677 }
678
679
674 accountList.append(&account); 680 accountList.append(&account);
675 } 681 }
676 delete p; 682 delete p;
677 } 683 }
678 mailconf->setGroup("mailitglobal"); 684 mailconf->setGroup("mailitglobal");
679 if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) { 685 if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) {
680 mailIdCount = y; 686 mailIdCount = y;
681 } 687 }
682 if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) { 688 if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) {
683 accountIdCount = y; 689 accountIdCount = y;
684 } 690 }
685} 691}
686 692
687void EmailClient::saveSettings() 693void EmailClient::saveSettings()
688{ 694{
689 QString temp; 695 QString temp;
690 QFile f( getPath(FALSE) + "settings.txt"); 696 QFile f( getPath(FALSE) + "settings.txt");
691 MailAccount *accountPtr; 697 MailAccount *accountPtr;
692 698
693 if (! f.open(IO_WriteOnly) ) { 699 if (! f.open(IO_WriteOnly) ) {
694 qWarning("could not save settings file"); 700 qWarning("could not save settings file");
695 return; 701 return;
696 } 702 }
697 QTextStream t(&f); 703 QTextStream t(&f);
698 t << "#Settings for QPE Mailit program\n"; 704 t << "#Settings for QPE Mailit program\n";
699 705
700 for (accountPtr = accountList.first(); accountPtr != 0; 706 for (accountPtr = accountList.first(); accountPtr != 0;
701 accountPtr = accountList.next()) { 707 accountPtr = accountList.next()) {
702 708
703 t << "accountStart;\n"; 709 t << "accountStart;\n";
704 t << "AccountName: " + accountPtr->accountName + "\n"; 710 t << "AccountName: " + accountPtr->accountName + "\n";
705 t << "Name: " + accountPtr->name + "\n"; 711 t << "Name: " + accountPtr->name + "\n";
706 t << "Email: " + accountPtr->emailAddress + "\n"; 712 t << "Email: " + accountPtr->emailAddress + "\n";
707 t << "POPUser: " + accountPtr->popUserName + "\n"; 713 t << "POPUser: " + accountPtr->popUserName + "\n";
708 t << "POPPAssword: " + accountPtr->popPasswd + "\n"; 714 t << "POPPAssword: " + accountPtr->popPasswd + "\n";
709 t << "POPServer: " + accountPtr->popServer + "\n"; 715 t << "POPServer: " + accountPtr->popServer + "\n";
710 t << "SMTPServer: " + accountPtr->smtpServer + "\n"; 716 t << "SMTPServer: " + accountPtr->smtpServer + "\n";
711 t << "AccountId: " << accountPtr->id << "\n"; 717 t << "AccountId: " << accountPtr->id << "\n";
712 if (accountPtr->synchronize) { 718 if (accountPtr->synchronize) {
713 t << "Synchronize: Yes\n"; 719 t << "Synchronize: Yes\n";
714 t << "LastServerMailCount: "; 720 t << "LastServerMailCount: ";
715 t << accountPtr->lastServerMailCount << "\n"; 721 t << accountPtr->lastServerMailCount << "\n";
716 } else { 722 } else {
717 t << "Synchronize: No\n"; 723 t << "Synchronize: No\n";
718 } 724 }
725 t << "SyncLimit: ";
726 t << accountPtr->syncLimit << "\n";
719 t << "accountEnd;\n"; 727 t << "accountEnd;\n";
720 } 728 }
721 f.close(); 729 f.close();
722 730
723 mailconf->setGroup("mailitglobal"); 731 mailconf->setGroup("mailitglobal");
724 mailconf->writeEntry("mailidcount", mailIdCount); 732 mailconf->writeEntry("mailidcount", mailIdCount);
725 mailconf->writeEntry("accountidcount", accountIdCount); 733 mailconf->writeEntry("accountidcount", accountIdCount);
726} 734}
727 735
728void EmailClient::selectAccount(int id) 736void EmailClient::selectAccount(int id)
729{ 737{
730 if (accountList.count() > 0) { 738 if (accountList.count() > 0) {
731 currentAccount = accountList.at(id); 739 currentAccount = accountList.at(id);
732 emit newCaption("Mailit - " + currentAccount->accountName); 740 emit newCaption("Mailit - " + currentAccount->accountName);
733 getNewMail(); 741 getNewMail();
734 } else { 742 } else {
735 emit newCaption("Mailit ! No account defined"); 743 emit newCaption("Mailit ! No account defined");
736 } 744 }
737} 745}
738 746
739void EmailClient::editAccount(int id) 747void EmailClient::editAccount(int id)
740{ 748{
741 MailAccount *newAccount; 749 MailAccount *newAccount;
742 750
743 editAccountView = new EditAccount(this, "account", TRUE); 751 editAccountView = new EditAccount(this, "account", TRUE);
744 if (id == newAccountId) { //new account 752 if (id == newAccountId) { //new account
745 newAccount = new MailAccount; 753 newAccount = new MailAccount;
746 editAccountView->setAccount(newAccount); 754 editAccountView->setAccount(newAccount);
747 } else { 755 } else {
748 newAccount = accountList.at(id); 756 newAccount = accountList.at(id);
749 editAccountView->setAccount(newAccount, FALSE); 757 editAccountView->setAccount(newAccount, FALSE);
750 } 758 }
751 759
752 editAccountView->showMaximized(); 760 editAccountView->showMaximized();
753 editAccountView->exec(); 761 editAccountView->exec();
754 762
755 if (editAccountView->result() == QDialog::Accepted) { 763 if (editAccountView->result() == QDialog::Accepted) {
756 if (id == newAccountId) { 764 if (id == newAccountId) {
757 newAccount->id = accountIdCount; 765 newAccount->id = accountIdCount;
758 accountIdCount++; 766 accountIdCount++;
759 accountList.append(newAccount); 767 accountList.append(newAccount);
760 updateAccounts(); 768 updateAccounts();
761 } else { 769 } else {
762 updateAccounts(); 770 updateAccounts();
763 } 771 }
764 } 772 }
765 773
766 delete editAccountView; 774 delete editAccountView;
767} 775}
768 776
769void EmailClient::deleteAccount(int id) 777void EmailClient::deleteAccount(int id)
770{ 778{
771 MailAccount *newAccount; 779 MailAccount *newAccount;
772 QString message; 780 QString message;
773 781
774 newAccount = accountList.at(id); 782 newAccount = accountList.at(id);
775 message = "Delete account:\n" + newAccount->accountName; 783 message = "Delete account:\n" + newAccount->accountName;
776 switch( QMessageBox::warning( this, "Mailit", message, 784 switch( QMessageBox::warning( this, "Mailit", message,
777 "Yes", "No", 0, 0, 1 ) ) { 785 "Yes", "No", 0, 0, 1 ) ) {
778 786
779 case 0: accountList.remove(id); 787 case 0: accountList.remove(id);
780 updateAccounts(); 788 updateAccounts();
781 break; 789 break;
782 case 1: 790 case 1:
783 break; 791 break;
784 } 792 }
785} 793}
786 794
787void EmailClient::updateAccounts() 795void EmailClient::updateAccounts()
788{ 796{
789 MailAccount *accountPtr; 797 MailAccount *accountPtr;
790 798
791 //rebuild menus, clear all first 799 //rebuild menus, clear all first
792 editAccountMenu->clear(); 800 editAccountMenu->clear();
793 selectAccountMenu->clear(); 801 selectAccountMenu->clear();
794 deleteAccountMenu->clear(); 802 deleteAccountMenu->clear();
795 803
796 newAccountId = editAccountMenu->insertItem("New", this, 804 newAccountId = editAccountMenu->insertItem("New", this,
797 SLOT(editAccount(int)) ); 805 SLOT(editAccount(int)) );
798 editAccountMenu->insertSeparator(); 806 editAccountMenu->insertSeparator();
799 807
800 idCount = 0; 808 idCount = 0;
801 for (accountPtr = accountList.first(); accountPtr != 0; 809 for (accountPtr = accountList.first(); accountPtr != 0;
802 accountPtr = accountList.next()) { 810 accountPtr = accountList.next()) {
803 811
804 editAccountMenu->insertItem(accountPtr->accountName, 812 editAccountMenu->insertItem(accountPtr->accountName,
805 this, SLOT(editAccount(int)), 0, idCount); 813 this, SLOT(editAccount(int)), 0, idCount);
806 selectAccountMenu->insertItem(accountPtr->accountName, 814 selectAccountMenu->insertItem(accountPtr->accountName,
807 this, SLOT(selectAccount(int)), 0, idCount); 815 this, SLOT(selectAccount(int)), 0, idCount);
808 deleteAccountMenu->insertItem(accountPtr->accountName, 816 deleteAccountMenu->insertItem(accountPtr->accountName,
809 this, SLOT(deleteAccount(int)), 0, idCount); 817 this, SLOT(deleteAccount(int)), 0, idCount);
810 idCount++; 818 idCount++;
811 } 819 }
812} 820}
813 821
814void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) 822void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox)
815{ 823{
816 Email *mPtr; 824 Email *mPtr;
817 Enclosure *ePtr; 825 Enclosure *ePtr;
818 826
819 if (inbox) { 827 if (inbox) {
820 mPtr = mailItem->getMail(); 828 mPtr = mailItem->getMail();
821 829
822 //if mail is in queue for download, remove it from 830 //if mail is in queue for download, remove it from
823 //queue if possible 831 //queue if possible
824 if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { 832 if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) {
825 if ( !mPtr->downloaded ) 833 if ( !mPtr->downloaded )
826 mailDownloadList.remove(mPtr->serverId, mPtr->size); 834 mailDownloadList.remove(mPtr->serverId, mPtr->size);
827 } 835 }
828 836
829 mailconf->setGroup(mPtr->id); 837 mailconf->setGroup(mPtr->id);
830 mailconf->clearGroup(); 838 mailconf->clearGroup();
831 839
832 //delete any temporary attatchemnts storing 840 //delete any temporary attatchemnts storing
833 for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { 841 for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) {
834 if (ePtr->saved) { 842 if (ePtr->saved) {
835 QFile::remove( (ePtr->path + ePtr->name) ); 843 QFile::remove( (ePtr->path + ePtr->name) );
836 } 844 }
837 } 845 }
838 inboxView->takeItem(mailItem); 846 inboxView->takeItem(mailItem);
839 } else { 847 } else {
840 outboxView->takeItem(mailItem); 848 outboxView->takeItem(mailItem);
841 } 849 }
842} 850}
843 851
844void EmailClient::setMailSize(int size) 852void EmailClient::setMailSize(int size)
845{ 853{
846 progressBar->reset(); 854 progressBar->reset();
847 progressBar->setTotalSteps(size); 855 progressBar->setTotalSteps(size);
848} 856}
849 857
850void EmailClient::setTotalSize(int size) 858void EmailClient::setTotalSize(int size)
851{ 859{
852 860
853} 861}
854 862
855void EmailClient::setDownloadedSize(int size) 863void EmailClient::setDownloadedSize(int size)
856{ 864{
857 int total = progressBar->totalSteps(); 865 int total = progressBar->totalSteps();
858 866
859 if (size < total) { 867 if (size < total) {
860 progressBar->setProgress(size); 868 progressBar->setProgress(size);
861 } else { 869 } else {
862 progressBar->setProgress(total); 870 progressBar->setProgress(total);
863 } 871 }
864} 872}
diff --git a/noncore/unsupported/mailit/emailhandler.cpp b/noncore/unsupported/mailit/emailhandler.cpp
index 1be16d4..9c1c814 100644
--- a/noncore/unsupported/mailit/emailhandler.cpp
+++ b/noncore/unsupported/mailit/emailhandler.cpp
@@ -1,592 +1,601 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qfileinfo.h> 20#include <qfileinfo.h>
21#include <stdlib.h> 21#include <stdlib.h>
22#include <qapplication.h> 22#include <qapplication.h>
23#include <qmessagebox.h> 23#include <qmessagebox.h>
24#include <qcstring.h> 24#include <qcstring.h>
25#include "emailhandler.h" 25#include "emailhandler.h"
26#include <qpe/applnk.h> 26#include <qpe/applnk.h>
27#include <qpe/filemanager.h> 27#include <qpe/filemanager.h>
28 28
29QCollection::Item EnclosureList::newItem(QCollection::Item d) 29QCollection::Item EnclosureList::newItem(QCollection::Item d)
30{ 30{
31 return dupl( (Enclosure *) d); 31 return dupl( (Enclosure *) d);
32} 32}
33 33
34Enclosure* EnclosureList::dupl(Enclosure *in) 34Enclosure* EnclosureList::dupl(Enclosure *in)
35{ 35{
36 ac = new Enclosure(*in); 36 ac = new Enclosure(*in);
37 return ac; 37 return ac;
38} 38}
39 39
40EmailHandler::EmailHandler() 40EmailHandler::EmailHandler()
41{ 41{
42 smtpClient = new SmtpClient(); 42 smtpClient = new SmtpClient();
43 popClient = new PopClient(); 43 popClient = new PopClient();
44 44
45 connect(smtpClient, SIGNAL(errorOccurred(int)), this, 45 connect(smtpClient, SIGNAL(errorOccurred(int)), this,
46 SIGNAL(smtpError(int)) ); 46 SIGNAL(smtpError(int)) );
47 connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); 47 connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) );
48 connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, 48 connect(smtpClient, SIGNAL(updateStatus(const QString &)), this,
49 SIGNAL(updateSmtpStatus(const QString &)) ); 49 SIGNAL(updateSmtpStatus(const QString &)) );
50 50
51 connect(popClient, SIGNAL(errorOccurred(int)), this, 51 connect(popClient, SIGNAL(errorOccurred(int)), this,
52 SIGNAL(popError(int)) ); 52 SIGNAL(popError(int)) );
53 connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), 53 connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)),
54 this, SLOT(messageArrived(const QString &, int, uint, bool)) ); 54 this, SLOT(messageArrived(const QString &, int, uint, bool)) );
55 connect(popClient, SIGNAL(updateStatus(const QString &)), this, 55 connect(popClient, SIGNAL(updateStatus(const QString &)), this,
56 SIGNAL(updatePopStatus(const QString &)) ); 56 SIGNAL(updatePopStatus(const QString &)) );
57 connect(popClient, SIGNAL(mailTransfered(int)), this, 57 connect(popClient, SIGNAL(mailTransfered(int)), this,
58 SIGNAL(mailTransfered(int)) ); 58 SIGNAL(mailTransfered(int)) );
59 59
60 60
61 //relaying size information 61 //relaying size information
62 connect(popClient, SIGNAL(currentMailSize(int)), 62 connect(popClient, SIGNAL(currentMailSize(int)),
63 this, SIGNAL(currentMailSize(int)) ); 63 this, SIGNAL(currentMailSize(int)) );
64 connect(popClient, SIGNAL(downloadedSize(int)), 64 connect(popClient, SIGNAL(downloadedSize(int)),
65 this, SIGNAL(downloadedSize(int)) ); 65 this, SIGNAL(downloadedSize(int)) );
66} 66}
67 67
68void EmailHandler::sendMail(QList<Email> *mailList) 68void EmailHandler::sendMail(QList<Email> *mailList)
69{ 69{
70 Email *currentMail; 70 Email *currentMail;
71 QString temp; 71 QString temp;
72 QString userName = mailAccount.name; 72 QString userName = mailAccount.name;
73 userName += " <" + mailAccount.emailAddress + ">"; 73 userName += " <" + mailAccount.emailAddress + ">";
74 74
75 for (currentMail = mailList->first(); currentMail != 0; 75 for (currentMail = mailList->first(); currentMail != 0;
76 currentMail = mailList->next()) { 76 currentMail = mailList->next()) {
77 77
78 if (encodeMime(currentMail) == 0) { 78 if (encodeMime(currentMail) == 0) {
79 smtpClient->addMail(userName, currentMail->subject, 79 smtpClient->addMail(userName, currentMail->subject,
80 currentMail->recipients, currentMail->rawMail); 80 currentMail->recipients, currentMail->rawMail);
81 } else { //error 81 } else { //error
82 temp = tr("Could not locate all files in \nmail with subject: ") + 82 temp = tr("Could not locate all files in \nmail with subject: ") +
83 currentMail->subject; 83 currentMail->subject;
84 temp += tr("\nMail has NOT been sent"); 84 temp += tr("\nMail has NOT been sent");
85 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); 85 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n"));
86 86
87 } 87 }
88 } 88 }
89 smtpClient->newConnection(mailAccount.smtpServer, 25); 89 smtpClient->newConnection(mailAccount.smtpServer, 25);
90} 90}
91 91
92void EmailHandler::setAccount(MailAccount account) 92void EmailHandler::setAccount(MailAccount account)
93{ 93{
94 mailAccount = account; 94 mailAccount = account;
95} 95}
96 96
97void EmailHandler::getMail() 97void EmailHandler::getMail()
98{ 98{
99 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); 99 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
100 if (mailAccount.synchronize) { 100 if (mailAccount.synchronize) {
101 popClient->setSynchronize(mailAccount.lastServerMailCount); 101 popClient->setSynchronize(mailAccount.lastServerMailCount);
102 } else { 102 } else {
103 popClient->removeSynchronize(); 103 popClient->removeSynchronize();
104 } 104 }
105 105
106 headers = FALSE; 106 headers = FALSE;
107 popClient->headersOnly(headers, 0); 107 popClient->headersOnly(headers, 0);
108 popClient->newConnection(mailAccount.popServer, 110); 108 popClient->newConnection(mailAccount.popServer, 110);
109} 109}
110 110
111void EmailHandler::getMailHeaders() 111void EmailHandler::getMailHeaders()
112{ 112{
113 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); 113 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
114 if (mailAccount.synchronize) { 114 if (mailAccount.synchronize) {
115 popClient->setSynchronize(mailAccount.lastServerMailCount); 115 popClient->setSynchronize(mailAccount.lastServerMailCount);
116 } else { 116 } else {
117 popClient->removeSynchronize(); 117 popClient->removeSynchronize();
118 } 118 }
119 119
120 headers = TRUE; 120 headers = TRUE;
121 popClient->headersOnly(headers, 2000); //less than 2000, download all 121 popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all
122 popClient->newConnection(mailAccount.popServer, 110); 122 popClient->newConnection(mailAccount.popServer, 110);
123} 123}
124 124
125void EmailHandler::getMailByList(MailList *mailList) 125void EmailHandler::getMailByList(MailList *mailList)
126{ 126{
127 if (mailList->count() == 0) { //should not occur though 127 if (mailList->count() == 0) { //should not occur though
128 emit mailTransfered(0); 128 emit mailTransfered(0);
129 return; 129 return;
130 } 130 }
131 131
132 headers = FALSE; 132 headers = FALSE;
133 popClient->headersOnly(FALSE, 0); 133 popClient->headersOnly(FALSE, 0);
134 popClient->newConnection(mailAccount.popServer, 110); 134 popClient->newConnection(mailAccount.popServer, 110);
135 popClient->setSelectedMails(mailList); 135 popClient->setSelectedMails(mailList);
136} 136}
137 137
138void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) 138void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete)
139{ 139{
140 Email mail; 140 Email mail;
141 141
142 mail.rawMail = message; 142 mail.rawMail = message;
143 mail.serverId = id; 143 mail.serverId = id;
144 mail.size = size; 144 mail.size = size;
145 mail.downloaded = complete; 145 mail.downloaded = complete;
146 146
147 emit mailArrived(mail, FALSE); 147 emit mailArrived(mail, FALSE);
148} 148}
149 149
150bool EmailHandler::parse(QString in, QString lineShift, Email *mail) 150bool EmailHandler::parse(QString in, QString lineShift, Email *mail)
151{ 151{
152 QString temp, boundary; 152 QString temp, boundary;
153 int pos; 153 int pos;
154 QString delimiter, header, body, mimeHeader, mimeBody; 154 QString delimiter, header, body, mimeHeader, mimeBody;
155 QString content, contentType, contentAttribute, id, encoding; 155 QString content, contentType, contentAttribute, id, encoding;
156 QString fileName, storedName; 156 QString fileName, storedName;
157 int enclosureId = 0; 157 int enclosureId = 0;
158 158
159 mail->rawMail = in; 159 mail->rawMail = in;
160 mail->received = TRUE; 160 mail->received = TRUE;
161 mail->files.setAutoDelete(TRUE); 161 mail->files.setAutoDelete(TRUE);
162 162
163 temp = lineShift + "." + lineShift; 163 temp = lineShift + "." + lineShift;
164 164
165 if (in.right(temp.length()) != temp) { 165 if (in.right(temp.length()) != temp) {
166 qWarning(in.right(temp.length())); 166 qWarning(in.right(temp.length()));
167 qWarning(" . added at end of email as separator"); 167 qWarning(" . added at end of email as separator");
168 mail->rawMail += temp; 168 mail->rawMail += temp;
169 } 169 }
170 170
171 171
172 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" 172 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n"
173 pos = in.find(delimiter, 0, FALSE); 173 pos = in.find(delimiter, 0, FALSE);
174 header = in.left(pos); 174 header = in.left(pos);
175 body = in.right(in.length() - pos - delimiter.length()); 175 body = in.right(in.length() - pos - delimiter.length());
176 if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) 176 if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n'))
177 body.truncate(body.length()-2); 177 body.truncate(body.length()-2);
178 178
179 TextParser p(header, lineShift); 179 TextParser p(header, lineShift);
180 180
181 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { 181 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) {
182 pos++; 182 pos++;
183 if (p.separatorAt(pos) == ' ') { 183 if (p.separatorAt(pos) == ' ') {
184 mail->from = p.getString(&pos, '<', false); 184 mail->from = p.getString(&pos, '<', false);
185 mail->from = mail->from.stripWhiteSpace(); 185 mail->from = mail->from.stripWhiteSpace();
186 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { 186 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) {
187 mail->from = mail->from.left(mail->from.length() - 1); 187 mail->from = mail->from.left(mail->from.length() - 1);
188 mail->from = mail->from.right(mail->from.length() - 1); 188 mail->from = mail->from.right(mail->from.length() - 1);
189 } 189 }
190 pos++; 190 pos++;
191 mail->fromMail = p.getString(&pos, '>', false); 191 mail->fromMail = p.getString(&pos, '>', false);
192 } else { 192 } else {
193 if ((p.separatorAt(pos) == '<') 193 if ((p.separatorAt(pos) == '<')
194 || (p.separatorAt(pos) == ' ')) //No name.. nasty 194 || (p.separatorAt(pos) == ' ')) //No name.. nasty
195 pos++; 195 pos++;
196 pos++; 196 pos++;
197 mail->fromMail = p.getString(&pos, 'z', TRUE); 197 mail->fromMail = p.getString(&pos, 'z', TRUE);
198 if (mail->fromMail.at(mail->fromMail.length()-1) == '>') 198 if (mail->fromMail.at(mail->fromMail.length()-1) == '>')
199 mail->fromMail.truncate(mail->fromMail.length() - 1); 199 mail->fromMail.truncate(mail->fromMail.length() - 1);
200 mail->from=mail->fromMail; 200 mail->from=mail->fromMail;
201 } 201 }
202 } 202 }
203
204 //@@@ToDo: Rewrite the parser as To: stops at the first occurence- which is Delivered-To:
205 if (pos = p.find("TO",':', pos, TRUE) != -1)
206 {
207 pos++;
208 mail->recipients.append (p.getString(&pos, 'z', TRUE) );
209 }
210
211
212
203 if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { 213 if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) {
204 pos++; 214 pos++;
205 mail->subject = p.getString(&pos, 'z', TRUE); 215 mail->subject = p.getString(&pos, 'z', TRUE);
206 } 216 }
207 if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { 217 if ((pos = p.find("DATE",':', 0, TRUE)) != -1) {
208 pos++; 218 pos++;
209 mail->date = p.getString(&pos, 'z', true); 219 mail->date = p.getString(&pos, 'z', true);
210 } 220 }
211 if ((pos = p.find("TO",':', 0, TRUE)) != -1) { 221
212 pos++; 222
213 mail->recipients.append (p.getString(&pos, 'z', TRUE) ); 223
214 }
215 if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { 224 if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) {
216 pos++; 225 pos++;
217 if ( (p.wordAt(pos).upper() == "ID") && 226 if ( (p.wordAt(pos).upper() == "ID") &&
218 (p.separatorAt(pos) == ':') ) { 227 (p.separatorAt(pos) == ':') ) {
219 228
220 id = p.getString(&pos, 'z', TRUE); 229 id = p.getString(&pos, 'z', TRUE);
221 mail->id = id; 230 mail->id = id;
222 } 231 }
223 } 232 }
224 233
225 pos = 0; 234 pos = 0;
226 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { 235 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) {
227 pos++; 236 pos++;
228 if ( (p.wordAt(pos).upper() == "VERSION") && 237 if ( (p.wordAt(pos).upper() == "VERSION") &&
229 (p.separatorAt(pos) == ':') ) { 238 (p.separatorAt(pos) == ':') ) {
230 pos++; 239 pos++;
231 if (p.getString(&pos, 'z', true) == "1.0") { 240 if (p.getString(&pos, 'z', true) == "1.0") {
232 mail->mimeType = 1; 241 mail->mimeType = 1;
233 } 242 }
234 } 243 }
235 } 244 }
236 245
237 if (mail->mimeType == 1) { 246 if (mail->mimeType == 1) {
238 boundary = ""; 247 boundary = "";
239 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { 248 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) {
240 pos++; 249 pos++;
241 boundary = p.getString(&pos, 'z', true); 250 boundary = p.getString(&pos, 'z', true);
242 if (boundary[0] == '"') { 251 if (boundary[0] == '"') {
243 boundary = boundary.left(boundary.length() - 1); //strip " 252 boundary = boundary.left(boundary.length() - 1); //strip "
244 boundary = boundary.right(boundary.length() - 1); //strip " 253 boundary = boundary.right(boundary.length() - 1); //strip "
245 } 254 }
246 boundary = "--" + boundary; //create boundary field 255 boundary = "--" + boundary; //create boundary field
247 } 256 }
248 257
249 if (boundary == "") { //fooled by Mime-Version 258 if (boundary == "") { //fooled by Mime-Version
250 mail->body = body; 259 mail->body = body;
251 mail->bodyPlain = body; 260 mail->bodyPlain = body;
252 return mail; 261 return mail;
253 } 262 }
254 263
255 while (body.length() > 0) { 264 while (body.length() > 0) {
256 pos = body.find(boundary, 0, FALSE); 265 pos = body.find(boundary, 0, FALSE);
257 pos = body.find(delimiter, pos, FALSE); 266 pos = body.find(delimiter, pos, FALSE);
258 mimeHeader = body.left(pos); 267 mimeHeader = body.left(pos);
259 mimeBody = body.right(body.length() - pos - delimiter.length()); 268 mimeBody = body.right(body.length() - pos - delimiter.length());
260 TextParser bp(mimeHeader, lineShift); 269 TextParser bp(mimeHeader, lineShift);
261 270
262 contentType = ""; 271 contentType = "";
263 contentAttribute = ""; 272 contentAttribute = "";
264 fileName = ""; 273 fileName = "";
265 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) { 274 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) {
266 pos++; 275 pos++;
267 if ( (bp.wordAt(pos).upper() == "TYPE") && 276 if ( (bp.wordAt(pos).upper() == "TYPE") &&
268 (bp.separatorAt(pos) == ':') ) { 277 (bp.separatorAt(pos) == ':') ) {
269 contentType = bp.nextWord().upper(); 278 contentType = bp.nextWord().upper();
270 if (bp.nextSeparator() == '/') 279 if (bp.nextSeparator() == '/')
271 contentAttribute = bp.nextWord().upper(); 280 contentAttribute = bp.nextWord().upper();
272 content = contentType + "/" + contentAttribute; 281 content = contentType + "/" + contentAttribute;
273 } 282 }
274 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) { 283 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) {
275 pos++; 284 pos++;
276 encoding = bp.getString(&pos, 'z', TRUE); 285 encoding = bp.getString(&pos, 'z', TRUE);
277 } 286 }
278 287
279 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) { 288 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) {
280 pos++; 289 pos++;
281 fileName = bp.getString(&pos, 'z', TRUE); 290 fileName = bp.getString(&pos, 'z', TRUE);
282 fileName = fileName.right(fileName.length() - 1); 291 fileName = fileName.right(fileName.length() - 1);
283 fileName = fileName.left(fileName.length() - 1); 292 fileName = fileName.left(fileName.length() - 1);
284 } 293 }
285 294
286 } 295 }
287 pos = mimeBody.find(boundary, 0, FALSE); 296 pos = mimeBody.find(boundary, 0, FALSE);
288 if (pos == -1) //should not occur, malformed mail 297 if (pos == -1) //should not occur, malformed mail
289 pos = mimeBody.length(); 298 pos = mimeBody.length();
290 body = mimeBody.right(mimeBody.length() - pos); 299 body = mimeBody.right(mimeBody.length() - pos);
291 mimeBody = mimeBody.left(pos); 300 mimeBody = mimeBody.left(pos);
292 301
293 if (fileName != "") { //attatchments of some type, audio, image etc. 302 if (fileName != "") { //attatchments of some type, audio, image etc.
294 303
295 Enclosure e; 304 Enclosure e;
296 e.id = enclosureId; 305 e.id = enclosureId;
297 e.originalName = fileName; 306 e.originalName = fileName;
298 e.contentType = contentType; 307 e.contentType = contentType;
299 e.contentAttribute = contentAttribute; 308 e.contentAttribute = contentAttribute;
300 e.encoding = encoding; 309 e.encoding = encoding;
301 e.body = mimeBody; 310 e.body = mimeBody;
302 e.saved = FALSE; 311 e.saved = FALSE;
303 mail->addEnclosure(&e); 312 mail->addEnclosure(&e);
304 enclosureId++; 313 enclosureId++;
305 314
306 } else if (contentType == "TEXT") { 315 } else if (contentType == "TEXT") {
307 if (contentAttribute == "PLAIN") { 316 if (contentAttribute == "PLAIN") {
308 mail->body = mimeBody; 317 mail->body = mimeBody;
309 mail->bodyPlain = mimeBody; 318 mail->bodyPlain = mimeBody;
310 } 319 }
311 if (contentAttribute == "HTML") { 320 if (contentAttribute == "HTML") {
312 mail->body = mimeBody; 321 mail->body = mimeBody;
313 } 322 }
314 } 323 }
315 } 324 }
316 } else { 325 } else {
317 mail->bodyPlain = body; 326 mail->bodyPlain = body;
318 mail->body = body; 327 mail->body = body;
319 } 328 }
320 return TRUE; 329 return TRUE;
321} 330}
322 331
323bool EmailHandler::getEnclosure(Enclosure *ePtr) 332bool EmailHandler::getEnclosure(Enclosure *ePtr)
324{ 333{
325 QFile f(ePtr->path + ePtr->name); 334 QFile f(ePtr->path + ePtr->name);
326 char src[4]; 335 char src[4];
327 char *destPtr; 336 char *destPtr;
328 QByteArray buffer; 337 QByteArray buffer;
329 uint bufCount, pos, decodedCount, size, x; 338 uint bufCount, pos, decodedCount, size, x;
330 339
331 if (! f.open(IO_WriteOnly) ) { 340 if (! f.open(IO_WriteOnly) ) {
332 qWarning("could not save: " + ePtr->path + ePtr->name); 341 qWarning("could not save: " + ePtr->path + ePtr->name);
333 return FALSE; 342 return FALSE;
334 } 343 }
335 344
336 if (ePtr->encoding.upper() == "BASE64") { 345 if (ePtr->encoding.upper() == "BASE64") {
337 size = (ePtr->body.length() * 3 / 4); //approximate size (always above) 346 size = (ePtr->body.length() * 3 / 4); //approximate size (always above)
338 buffer.resize(size); 347 buffer.resize(size);
339 bufCount = 0; 348 bufCount = 0;
340 pos = 0; 349 pos = 0;
341 destPtr = buffer.data(); 350 destPtr = buffer.data();
342 351
343 while (pos < ePtr->body.length()) { 352 while (pos < ePtr->body.length()) {
344 decodedCount = 4; 353 decodedCount = 4;
345 x = 0; 354 x = 0;
346 while ( (x < 4) && (pos < ePtr->body.length()) ) { 355 while ( (x < 4) && (pos < ePtr->body.length()) ) {
347 src[x] = ePtr->body[pos].latin1(); 356 src[x] = ePtr->body[pos].latin1();
348 pos++; 357 pos++;
349 if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ') 358 if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ')
350 x--; 359 x--;
351 x++; 360 x++;
352 } 361 }
353 if (x > 1) { 362 if (x > 1) {
354 decodedCount = parse64base(src, destPtr); 363 decodedCount = parse64base(src, destPtr);
355 destPtr += decodedCount; 364 destPtr += decodedCount;
356 bufCount += decodedCount; 365 bufCount += decodedCount;
357 } 366 }
358 } 367 }
359 368
360 buffer.resize(bufCount); //set correct length of file 369 buffer.resize(bufCount); //set correct length of file
361 f.writeBlock(buffer); 370 f.writeBlock(buffer);
362 } else { 371 } else {
363 QTextStream t(&f); 372 QTextStream t(&f);
364 t << ePtr->body; 373 t << ePtr->body;
365 } 374 }
366 return TRUE; 375 return TRUE;
367} 376}
368 377
369int EmailHandler::parse64base(char *src, char *bufOut) { 378int EmailHandler::parse64base(char *src, char *bufOut) {
370 379
371 char c, z; 380 char c, z;
372 char li[4]; 381 char li[4];
373 int processed; 382 int processed;
374 383
375 //conversion table withouth table... 384 //conversion table withouth table...
376 for (int x = 0; x < 4; x++) { 385 for (int x = 0; x < 4; x++) {
377 c = src[x]; 386 c = src[x];
378 387
379 if ( (int) c >= 'A' && (int) c <= 'Z') 388 if ( (int) c >= 'A' && (int) c <= 'Z')
380 li[x] = (int) c - (int) 'A'; 389 li[x] = (int) c - (int) 'A';
381 if ( (int) c >= 'a' && (int) c <= 'z') 390 if ( (int) c >= 'a' && (int) c <= 'z')
382 li[x] = (int) c - (int) 'a' + 26; 391 li[x] = (int) c - (int) 'a' + 26;
383 if ( (int) c >= '0' && (int) c <= '9') 392 if ( (int) c >= '0' && (int) c <= '9')
384 li[x] = (int) c - (int) '0' + 52; 393 li[x] = (int) c - (int) '0' + 52;
385 if (c == '+') 394 if (c == '+')
386 li[x] = 62; 395 li[x] = 62;
387 if (c == '/') 396 if (c == '/')
388 li[x] = 63; 397 li[x] = 63;
389 } 398 }
390 399
391 processed = 1; 400 processed = 1;
392 bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits 401 bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits
393 bufOut[0] <<= 2; 402 bufOut[0] <<= 2;
394 z = li[1] >> 4; 403 z = li[1] >> 4;
395 bufOut[0] = bufOut[0] | z; //first byte retrived 404 bufOut[0] = bufOut[0] | z; //first byte retrived
396 405
397 if (src[2] != '=') { 406 if (src[2] != '=') {
398 bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits 407 bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits
399 bufOut[1] <<= 4; 408 bufOut[1] <<= 4;
400 z = li[2] >> 2; 409 z = li[2] >> 2;
401 bufOut[1] = bufOut[1] | z; //second byte retrived 410 bufOut[1] = bufOut[1] | z; //second byte retrived
402 processed++; 411 processed++;
403 412
404 if (src[3] != '=') { 413 if (src[3] != '=') {
405 bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits 414 bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits
406 bufOut[2] <<= 6; 415 bufOut[2] <<= 6;
407 z = li[3]; 416 z = li[3];
408 bufOut[2] = bufOut[2] | z; //third byte retrieved 417 bufOut[2] = bufOut[2] | z; //third byte retrieved
409 processed++; 418 processed++;
410 } 419 }
411 } 420 }
412 return processed; 421 return processed;
413} 422}
414 423
415int EmailHandler::encodeMime(Email *mail) 424int EmailHandler::encodeMime(Email *mail)
416{ 425{
417 426
418 QString fileName, fileType, contentType, newBody, boundary; 427 QString fileName, fileType, contentType, newBody, boundary;
419 Enclosure *ePtr; 428 Enclosure *ePtr;
420 429
421 QString userName = mailAccount.name; 430 QString userName = mailAccount.name;
422 if (userName.length()>0)//only embrace it if there is a user name 431 if (userName.length()>0)//only embrace it if there is a user name
423 userName += " <" + mailAccount.emailAddress + ">"; 432 userName += " <" + mailAccount.emailAddress + ">";
424 433
425 //add standard headers 434 //add standard headers
426 newBody = "From: " + userName + "\r\nTo: "; 435 newBody = "From: " + userName + "\r\nTo: ";
427 for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) { 436 for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) {
428 newBody += *it + " "; 437 newBody += *it + " ";
429 } 438 }
430 newBody += "\r\nSubject: " + mail->subject + "\r\n"; 439 newBody += "\r\nSubject: " + mail->subject + "\r\n";
431 440
432 if (mail->files.count() == 0) { //just a simple mail 441 if (mail->files.count() == 0) { //just a simple mail
433 newBody += "\r\n" + mail->body; 442 newBody += "\r\n" + mail->body;
434 mail->rawMail = newBody; 443 mail->rawMail = newBody;
435 return 0; 444 return 0;
436 } 445 }
437 446
438 //Build mime encoded mail 447 //Build mime encoded mail
439 boundary = "-----4345=next_bound=0495----"; 448 boundary = "-----4345=next_bound=0495----";
440 449
441 newBody += "Mime-Version: 1.0\r\n"; 450 newBody += "Mime-Version: 1.0\r\n";
442 newBody += "Content-Type: multipart/mixed; boundary=\"" + 451 newBody += "Content-Type: multipart/mixed; boundary=\"" +
443 boundary + "\"\r\n\r\n"; 452 boundary + "\"\r\n\r\n";
444 453
445 newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n"; 454 newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n";
446 newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n"; 455 newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n";
447 newBody += mail->body; 456 newBody += mail->body;
448 457
449 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 458 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
450 fileName = ePtr->originalName; 459 fileName = ePtr->originalName;
451 fileType = ePtr->contentType; 460 fileType = ePtr->contentType;
452 QFileInfo fi(fileName); 461 QFileInfo fi(fileName);
453 462
454 // This specification of contentType is temporary 463 // This specification of contentType is temporary
455 contentType = ""; 464 contentType = "";
456 if (fileType == "Picture") { 465 if (fileType == "Picture") {
457 contentType = "image/x-image"; 466 contentType = "image/x-image";
458 } else if (fileType == "Document") { 467 } else if (fileType == "Document") {
459 contentType = "text/plain"; 468 contentType = "text/plain";
460 } else if (fileType == "Sound") { 469 } else if (fileType == "Sound") {
461 contentType = "audio/x-wav"; 470 contentType = "audio/x-wav";
462 } else if (fileType == "Movie") { 471 } else if (fileType == "Movie") {
463 contentType = "video/mpeg"; 472 contentType = "video/mpeg";
464 } else { 473 } else {
465 contentType = "application/octet-stream"; 474 contentType = "application/octet-stream";
466 } 475 }
467 476
468 newBody += "\r\n\r\n--" + boundary + "\r\n"; 477 newBody += "\r\n\r\n--" + boundary + "\r\n";
469 newBody += "Content-Type: " + contentType + "; name=\"" + 478 newBody += "Content-Type: " + contentType + "; name=\"" +
470 fi.fileName() + "\"\r\n"; 479 fi.fileName() + "\"\r\n";
471 newBody += "Content-Transfer-Encoding: base64\r\n"; 480 newBody += "Content-Transfer-Encoding: base64\r\n";
472 newBody += "Content-Disposition: inline; filename=\"" + 481 newBody += "Content-Disposition: inline; filename=\"" +
473 fi.fileName() + "\"\r\n\r\n"; 482 fi.fileName() + "\"\r\n\r\n";
474 483
475 if (encodeFile(fileName, &newBody) == -1) //file not found? 484 if (encodeFile(fileName, &newBody) == -1) //file not found?
476 return -1; 485 return -1;
477 } 486 }
478 487
479 newBody += "\r\n\r\n--" + boundary + "--"; 488 newBody += "\r\n\r\n--" + boundary + "--";
480 mail->rawMail = newBody; 489 mail->rawMail = newBody;
481 490
482 return 0; 491 return 0;
483} 492}
484 493
485int EmailHandler::encodeFile(QString fileName, QString *toBody) 494int EmailHandler::encodeFile(QString fileName, QString *toBody)
486{ 495{
487 char *fileData; 496 char *fileData;
488 char *dataPtr; 497 char *dataPtr;
489 QString temp; 498 QString temp;
490 uint dataSize, count; 499 uint dataSize, count;
491 QFile f(fileName); 500 QFile f(fileName);
492 501
493 if (! f.open(IO_ReadOnly) ) { 502 if (! f.open(IO_ReadOnly) ) {
494 qWarning("could not open file: " + fileName); 503 qWarning("could not open file: " + fileName);
495 return -1; 504 return -1;
496 } 505 }
497 QTextStream s(&f); 506 QTextStream s(&f);
498 dataSize = f.size(); 507 dataSize = f.size();
499 fileData = (char *) malloc(dataSize + 3); 508 fileData = (char *) malloc(dataSize + 3);
500 s.readRawBytes(fileData, dataSize); 509 s.readRawBytes(fileData, dataSize);
501 510
502 temp = ""; 511 temp = "";
503 dataPtr = fileData; 512 dataPtr = fileData;
504 count = 0; 513 count = 0;
505 while (dataSize > 0) { 514 while (dataSize > 0) {
506 if (dataSize < 3) { 515 if (dataSize < 3) {
507 encode64base(dataPtr, &temp, dataSize); 516 encode64base(dataPtr, &temp, dataSize);
508 dataSize = 0; 517 dataSize = 0;
509 } else { 518 } else {
510 encode64base(dataPtr, &temp, 3); 519 encode64base(dataPtr, &temp, 3);
511 dataSize -= 3; 520 dataSize -= 3;
512 dataPtr += 3; 521 dataPtr += 3;
513 count += 4; 522 count += 4;
514 } 523 }
515 if (count > 72) { 524 if (count > 72) {
516 count = 0; 525 count = 0;
517 temp += "\r\n"; 526 temp += "\r\n";
518 } 527 }
519 } 528 }
520 toBody->append(temp); 529 toBody->append(temp);
521 530
522 delete(fileData); 531 delete(fileData);
523 f.close(); 532 f.close();
524 return 0; 533 return 0;
525} 534}
526 535
527void EmailHandler::encode64base(char *src, QString *dest, int len) 536void EmailHandler::encode64base(char *src, QString *dest, int len)
528{ 537{
529 QString temp; 538 QString temp;
530 uchar c; 539 uchar c;
531 uchar bufOut[4]; 540 uchar bufOut[4];
532 541
533 bufOut[0] = src[0]; 542 bufOut[0] = src[0];
534 bufOut[0] >>= 2; //Done byte 0 543 bufOut[0] >>= 2; //Done byte 0
535 544
536 bufOut[1] = src[0]; 545 bufOut[1] = src[0];
537 bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits 546 bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits
538 bufOut[1] <<= 4; //copy up 4 places 547 bufOut[1] <<= 4; //copy up 4 places
539 if (len > 1) { 548 if (len > 1) {
540 c = src[1]; 549 c = src[1];
541 } else { 550 } else {
542 c = 0; 551 c = 0;
543 } 552 }
544 553
545 c = c & (16 + 32 + 64 + 128); 554 c = c & (16 + 32 + 64 + 128);
546 c >>= 4; 555 c >>= 4;
547 bufOut[1] = bufOut[1] | c; //Done byte 1 556 bufOut[1] = bufOut[1] | c; //Done byte 1
548 557
549 bufOut[2] = src[1]; 558 bufOut[2] = src[1];
550 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8); 559 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8);
551 bufOut[2] <<= 2; 560 bufOut[2] <<= 2;
552 if (len > 2) { 561 if (len > 2) {
553 c = src[2]; 562 c = src[2];
554 } else { 563 } else {
555 c = 0; 564 c = 0;
556 } 565 }
557 c >>= 6; 566 c >>= 6;
558 bufOut[2] = bufOut[2] | c; 567 bufOut[2] = bufOut[2] | c;
559 568
560 bufOut[3] = src[2]; 569 bufOut[3] = src[2];
561 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32); 570 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32);
562 571
563 if (len == 1) { 572 if (len == 1) {
564 bufOut[2] = 64; 573 bufOut[2] = 64;
565 bufOut[3] = 64; 574 bufOut[3] = 64;
566 } 575 }
567 if (len == 2) { 576 if (len == 2) {
568 bufOut[3] = 64; 577 bufOut[3] = 64;
569 } 578 }
570 for (int x = 0; x < 4; x++) { 579 for (int x = 0; x < 4; x++) {
571 if (bufOut[x] <= 25) 580 if (bufOut[x] <= 25)
572 bufOut[x] += (uint) 'A'; 581 bufOut[x] += (uint) 'A';
573 else if (bufOut[x] >= 26 && bufOut[x] <= 51) 582 else if (bufOut[x] >= 26 && bufOut[x] <= 51)
574 bufOut[x] += (uint) 'a' - 26; 583 bufOut[x] += (uint) 'a' - 26;
575 else if (bufOut[x] >= 52 && bufOut[x] <= 61) 584 else if (bufOut[x] >= 52 && bufOut[x] <= 61)
576 bufOut[x] += (uint) '0' - 52; 585 bufOut[x] += (uint) '0' - 52;
577 else if (bufOut[x] == 62) 586 else if (bufOut[x] == 62)
578 bufOut[x] = '+'; 587 bufOut[x] = '+';
579 else if (bufOut[x] == 63) 588 else if (bufOut[x] == 63)
580 bufOut[x] = '/'; 589 bufOut[x] = '/';
581 else if (bufOut[x] == 64) 590 else if (bufOut[x] == 64)
582 bufOut[x] = '='; 591 bufOut[x] = '=';
583 592
584 dest->append(bufOut[x]); 593 dest->append(bufOut[x]);
585 } 594 }
586} 595}
587 596
588void EmailHandler::cancel() 597void EmailHandler::cancel()
589{ 598{
590 popClient->errorHandling(ErrCancel); 599 popClient->errorHandling(ErrCancel);
591 smtpClient->errorHandling(ErrCancel); 600 smtpClient->errorHandling(ErrCancel);
592} 601}
diff --git a/noncore/unsupported/mailit/emailhandler.h b/noncore/unsupported/mailit/emailhandler.h
index 17c4414..e47fd9a 100644
--- a/noncore/unsupported/mailit/emailhandler.h
+++ b/noncore/unsupported/mailit/emailhandler.h
@@ -1,147 +1,148 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef EmailHandler_H 20#ifndef EmailHandler_H
21#define EmailHandler_H 21#define EmailHandler_H
22 22
23#include <qobject.h> 23#include <qobject.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qdatetime.h> 25#include <qdatetime.h>
26#include <qlist.h> 26#include <qlist.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qfile.h> 28#include <qfile.h>
29#include <qstringlist.h> 29#include <qstringlist.h>
30#include <qcollection.h> 30#include <qcollection.h>
31 31
32#include "smtpclient.h" 32#include "smtpclient.h"
33#include "popclient.h" 33#include "popclient.h"
34#include "textparser.h" 34#include "textparser.h"
35#include "maillist.h" 35#include "maillist.h"
36 36
37struct Enclosure 37struct Enclosure
38{ 38{
39 int id; 39 int id;
40 QString originalName; 40 QString originalName;
41 QString name; 41 QString name;
42 QString path; 42 QString path;
43 QString contentType; 43 QString contentType;
44 QString contentAttribute; 44 QString contentAttribute;
45 QString encoding; 45 QString encoding;
46 QString body; //might use to much mem. check!! 46 QString body; //might use to much mem. check!!
47 bool saved, installed; 47 bool saved, installed;
48}; 48};
49 49
50class EnclosureList : public QList<Enclosure> 50class EnclosureList : public QList<Enclosure>
51{ 51{
52public: 52public:
53 Item newItem(Item d); 53 Item newItem(Item d);
54private: 54private:
55 Enclosure* dupl(Enclosure *in); 55 Enclosure* dupl(Enclosure *in);
56 Enclosure *ac; 56 Enclosure *ac;
57}; 57};
58 58
59struct Email 59struct Email
60{ 60{
61 QString id; 61 QString id;
62 QString from; 62 QString from;
63 QString fromMail; 63 QString fromMail;
64 QStringList recipients; 64 QStringList recipients;
65 QStringList carbonCopies; 65 QStringList carbonCopies;
66 QString date; 66 QString date;
67 QString subject; 67 QString subject;
68 QString body; 68 QString body;
69 QString bodyPlain; 69 QString bodyPlain;
70 bool sent, received, read, downloaded; 70 bool sent, received, read, downloaded;
71 QString rawMail; 71 QString rawMail;
72 int mimeType; //1 = Mime 1.0 72 int mimeType; //1 = Mime 1.0
73 int serverId; 73 int serverId;
74 int internalId; 74 int internalId;
75 int fromAccountId; 75 int fromAccountId;
76 QString contentType; //0 = text 76 QString contentType; //0 = text
77 QString contentAttribute; //0 = plain, 1 = html 77 QString contentAttribute; //0 = plain, 1 = html
78 EnclosureList files; 78 EnclosureList files;
79 uint size; 79 uint size;
80 80
81 void addEnclosure(Enclosure *e) 81 void addEnclosure(Enclosure *e)
82 { 82 {
83 files.append(e); 83 files.append(e);
84 } 84 }
85}; 85};
86 86
87struct MailAccount 87struct MailAccount
88{ 88{
89 QString accountName; 89 QString accountName;
90 QString name; 90 QString name;
91 QString emailAddress; 91 QString emailAddress;
92 QString popUserName; 92 QString popUserName;
93 QString popPasswd; 93 QString popPasswd;
94 QString popServer; 94 QString popServer;
95 QString smtpServer; 95 QString smtpServer;
96 bool synchronize; 96 bool synchronize;
97 int syncLimit;
97 int lastServerMailCount; 98 int lastServerMailCount;
98 int id; 99 int id;
99}; 100};
100 101
101 const int ErrUnknownResponse = 1001; 102 const int ErrUnknownResponse = 1001;
102 const int ErrLoginFailed = 1002; 103 const int ErrLoginFailed = 1002;
103 const int ErrCancel = 1003; 104 const int ErrCancel = 1003;
104 105
105 106
106class EmailHandler : public QObject 107class EmailHandler : public QObject
107{ 108{
108 Q_OBJECT 109 Q_OBJECT
109 110
110public: 111public:
111 EmailHandler(); 112 EmailHandler();
112 void setAccount(MailAccount account); 113 void setAccount(MailAccount account);
113 void sendMail(QList<Email> *mailList); 114 void sendMail(QList<Email> *mailList);
114 void getMail(); 115 void getMail();
115 void getMailHeaders(); 116 void getMailHeaders();
116 void getMailByList(MailList *mailList); 117 void getMailByList(MailList *mailList);
117 bool parse(QString in, QString lineShift, Email *mail); 118 bool parse(QString in, QString lineShift, Email *mail);
118 bool getEnclosure(Enclosure *ePtr); 119 bool getEnclosure(Enclosure *ePtr);
119 int parse64base(char *src, char *dest); 120 int parse64base(char *src, char *dest);
120 int encodeMime(Email *mail); 121 int encodeMime(Email *mail);
121 int encodeFile(QString fileName, QString *toBody); 122 int encodeFile(QString fileName, QString *toBody);
122 void encode64base(char *src, QString *dest, int len); 123 void encode64base(char *src, QString *dest, int len);
123 void cancel(); 124 void cancel();
124 125
125signals: 126signals:
126 void mailSent(); 127 void mailSent();
127 void smtpError(int); 128 void smtpError(int);
128 void popError(int); 129 void popError(int);
129 void mailArrived(const Email &, bool); 130 void mailArrived(const Email &, bool);
130 void updatePopStatus(const QString &); 131 void updatePopStatus(const QString &);
131 void updateSmtpStatus(const QString &); 132 void updateSmtpStatus(const QString &);
132 void mailTransfered(int); 133 void mailTransfered(int);
133 void mailboxSize(int); 134 void mailboxSize(int);
134 void currentMailSize(int); 135 void currentMailSize(int);
135 void downloadedSize(int); 136 void downloadedSize(int);
136 137
137public slots: 138public slots:
138 void messageArrived(const QString &, int id, uint size, bool complete); 139 void messageArrived(const QString &, int id, uint size, bool complete);
139 140
140private: 141private:
141 MailAccount mailAccount; 142 MailAccount mailAccount;
142 SmtpClient *smtpClient; 143 SmtpClient *smtpClient;
143 PopClient *popClient; 144 PopClient *popClient;
144 bool headers; 145 bool headers;
145}; 146};
146 147
147#endif 148#endif
diff --git a/noncore/unsupported/mailit/emaillistitem.cpp b/noncore/unsupported/mailit/emaillistitem.cpp
index d47b0b7..a325766 100644
--- a/noncore/unsupported/mailit/emaillistitem.cpp
+++ b/noncore/unsupported/mailit/emaillistitem.cpp
@@ -1,92 +1,97 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qstring.h> 20#include <qstring.h>
21#include <qpe/resource.h>
21#include "emaillistitem.h" 22#include "emaillistitem.h"
22 23
23EmailListItem::EmailListItem(QListView *parent, Email mailIn, bool inbox) 24EmailListItem::EmailListItem(QListView *parent, Email mailIn, bool inbox)
24 : QListViewItem(parent) 25 : QListViewItem(parent)
25{ 26{
26 QString temp; 27 QString temp;
27 28
28 mail = mailIn; 29 mail = mailIn;
29 30
30 if (inbox) { 31 if (inbox) {
31 setText(0, mail.from); 32 setText(0, mail.from);
32 } else { 33 } else {
33 QStringList::Iterator it = mail.recipients.begin(); 34 QStringList::Iterator it = mail.recipients.begin();
34 temp = *it; 35 temp = *it;
35 if (mail.recipients.count() > 1) 36 if (mail.recipients.count() > 1)
36 temp += "..."; 37 temp += "...";
37 setText(0, temp); 38 setText(0, temp);
38 } 39 }
39 setText(1, mail.subject); 40 setText(1, mail.subject);
40 41
42 if (mailIn.files.count()>0)
43 {
44 setPixmap(0, Resource::loadPixmap("mailit/attach"));
45 }
41 selected = FALSE; 46 selected = FALSE;
42} 47}
43 48
44Email* EmailListItem::getMail() 49Email* EmailListItem::getMail()
45{ 50{
46 return &mail; 51 return &mail;
47} 52}
48 53
49void EmailListItem::setMail(Email newMail) 54void EmailListItem::setMail(Email newMail)
50{ 55{
51 mail = newMail; 56 mail = newMail;
52 repaint(); 57 repaint();
53} 58}
54 59
55void EmailListItem::setItemSelected(bool enable) 60void EmailListItem::setItemSelected(bool enable)
56{ 61{
57 selected = enable; 62 selected = enable;
58 setSelected(enable); 63 setSelected(enable);
59 repaint(); 64 repaint();
60} 65}
61 66
62bool EmailListItem::isItemSelected() 67bool EmailListItem::isItemSelected()
63{ 68{
64 return selected; 69 return selected;
65} 70}
66 71
67void EmailListItem::paintCell( QPainter *p, const QColorGroup &cg, 72void EmailListItem::paintCell( QPainter *p, const QColorGroup &cg,
68 int column, int width, int alignment ) 73 int column, int width, int alignment )
69{ 74{
70 75
71 QColorGroup _cg( cg ); 76 QColorGroup _cg( cg );
72 QColor c = _cg.text(); 77 QColor c = _cg.text();
73 78
74 if ( (! mail.read) && (mail.received) ) 79 if ( (! mail.read) && (mail.received) )
75 _cg.setColor( QColorGroup::Text, Qt::blue); 80 _cg.setColor( QColorGroup::Text, Qt::blue);
76 if (!mail.downloaded) 81 if (!mail.downloaded)
77 _cg.setColor( QColorGroup::Text, Qt::red); 82 _cg.setColor( QColorGroup::Text, Qt::red);
78 83
79 /*if (selected) { 84 /*if (selected) {
80 _cg.setColor(QColorGroup::Base, Qt::blue); 85 _cg.setColor(QColorGroup::Base, Qt::blue);
81 _cg.setColor(QColorGroup::Text, Qt::yellow); 86 _cg.setColor(QColorGroup::Text, Qt::yellow);
82 if (isSelected()) { 87 if (isSelected()) {
83 _cg.setColor(QColorGroup::HighlightedText, Qt::yellow); 88 _cg.setColor(QColorGroup::HighlightedText, Qt::yellow);
84 } else { 89 } else {
85 _cg.setColor(QColorGroup::Highlight, Qt::blue); 90 _cg.setColor(QColorGroup::Highlight, Qt::blue);
86 } 91 }
87 } 92 }
88 */ 93 */
89 QListViewItem::paintCell( p, _cg, column, width, alignment ); 94 QListViewItem::paintCell( p, _cg, column, width, alignment );
90 95
91 _cg.setColor( QColorGroup::Text, c ); 96 _cg.setColor( QColorGroup::Text, c );
92} 97}
diff --git a/noncore/unsupported/mailit/mailit.pro b/noncore/unsupported/mailit/mailit.pro
index a404884..b262f9a 100644
--- a/noncore/unsupported/mailit/mailit.pro
+++ b/noncore/unsupported/mailit/mailit.pro
@@ -1,43 +1,60 @@
1TEMPLATE = app 1TEMPLATE = app
2CONFIG = qt warn_on release 2CONFIG = qt warn_on release
3HEADERS = emailclient.h \ 3HEADERS = emailclient.h \
4 emailhandler.h \ 4 emailhandler.h \
5 emaillistitem.h \ 5 emaillistitem.h \
6 mailitwindow.h \ 6 mailitwindow.h \
7 md5.h \ 7 md5.h \
8 popclient.h \ 8 popclient.h \
9 readmail.h \ 9 readmail.h \
10 smtpclient.h \ 10 smtpclient.h \
11 writemail.h \ 11 writemail.h \
12 textparser.h \ 12 textparser.h \
13 viewatt.h \ 13 viewatt.h \
14 addatt.h \ 14 addatt.h \
15 editaccount.h \ 15 editaccount.h \
16 maillist.h \ 16 maillist.h \
17 addresslist.h 17 addresslist.h
18SOURCES = emailclient.cpp \ 18SOURCES = emailclient.cpp \
19 emailhandler.cpp \ 19 emailhandler.cpp \
20 emaillistitem.cpp \ 20 emaillistitem.cpp \
21 mailitwindow.cpp \ 21 mailitwindow.cpp \
22 main.cpp \ 22 main.cpp \
23 md5.c \ 23 md5.c \
24 popclient.cpp \ 24 popclient.cpp \
25 readmail.cpp \ 25 readmail.cpp \
26 smtpclient.cpp \ 26 smtpclient.cpp \
27 writemail.cpp \ 27 writemail.cpp \
28 textparser.cpp \ 28 textparser.cpp \
29 viewatt.cpp \ 29 viewatt.cpp \
30 addatt.cpp \ 30 addatt.cpp \
31 editaccount.cpp \ 31 editaccount.cpp \
32 maillist.cpp \ 32 maillist.cpp \
33 addresslist.cpp 33 addresslist.cpp
34 34
35INCLUDEPATH += $(OPIEDIR)/include 35INCLUDEPATH += $(OPIEDIR)/include
36DEPENDPATH += $(OPIEDIR)/include 36DEPENDPATH += $(OPIEDIR)/include
37LIBS += -lqpe -lopie 37LIBS += -lqpe -lopie
38# -lssl 38# -lssl
39MOC_DIR=qpeobj 39MOC_DIR=qpeobj
40OBJECTS_DIR=qpeobj 40OBJECTS_DIR=qpeobj
41DESTDIR=$(OPIEDIR)/bin 41DESTDIR=$(OPIEDIR)/bin
42 42
43TRANSLATIONS = ../../../i18n/de/mailit.ts \
44 ../../../i18n/da/mailit.ts \
45 ../../../i18n/xx/mailit.ts \
46 ../../../i18n/en/mailit.ts \
47 ../../../i18n/es/mailit.ts \
48 ../../../i18n/fr/mailit.ts \
49 ../../../i18n/hu/mailit.ts \
50 ../../../i18n/ja/mailit.ts \
51 ../../../i18n/ko/mailit.ts \
52 ../../../i18n/no/mailit.ts \
53 ../../../i18n/pl/mailit.ts \
54 ../../../i18n/pt/mailit.ts \
55 ../../../i18n/pt_BR/mailit.ts \
56 ../../../i18n/sl/mailit.ts \
57 ../../../i18n/zh_CN/mailit.ts \
58 ../../../i18n/zh_TW/mailit.ts
59
43include ( $(OPIEDIR)/include.pro ) 60include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/unsupported/mailit/readmail.cpp b/noncore/unsupported/mailit/readmail.cpp
index 2011ecf..a5e7147 100644
--- a/noncore/unsupported/mailit/readmail.cpp
+++ b/noncore/unsupported/mailit/readmail.cpp
@@ -1,326 +1,326 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "readmail.h" 20#include "readmail.h"
21#include <qimage.h> 21#include <qimage.h>
22#include <qmime.h> 22#include <qmime.h>
23#include <qaction.h> 23#include <qaction.h>
24#include "resource.h" 24#include <qpe/resource.h>
25 25
26ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl ) 26ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl )
27 : QMainWindow(parent, name, fl) 27 : QMainWindow(parent, name, fl)
28{ 28{
29 plainTxt = FALSE; 29 plainTxt = FALSE;
30 30
31 init(); 31 init();
32 viewAtt = new ViewAtt(0, "View Attatchments"); 32 viewAtt = new ViewAtt(0, "View Attatchments");
33} 33}
34 34
35ReadMail::~ReadMail() 35ReadMail::~ReadMail()
36{ 36{
37 delete emailView->mimeSourceFactory(); 37 delete emailView->mimeSourceFactory();
38 delete viewAtt; 38 delete viewAtt;
39} 39}
40 40
41void ReadMail::init() 41void ReadMail::init()
42{ 42{
43 setToolBarsMovable(FALSE); 43 setToolBarsMovable(FALSE);
44 44
45 bar = new QToolBar(this); 45 bar = new QToolBar(this);
46 bar->setHorizontalStretchable( TRUE ); 46 bar->setHorizontalStretchable( TRUE );
47 47
48 menu = new QMenuBar( bar ); 48 menu = new QMenuBar( bar );
49 49
50 viewMenu = new QPopupMenu(menu); 50 viewMenu = new QPopupMenu(menu);
51 menu->insertItem( tr( "&View" ), viewMenu); 51 menu->insertItem( tr( "&View" ), viewMenu);
52 52
53 mailMenu = new QPopupMenu(menu); 53 mailMenu = new QPopupMenu(menu);
54 menu->insertItem( tr( "&Mail" ), mailMenu); 54 menu->insertItem( tr( "&Mail" ), mailMenu);
55 55
56 bar = new QToolBar(this); 56 bar = new QToolBar(this);
57 57
58 //reply dependant on viewing inbox 58 //reply dependant on viewing inbox
59 replyButton = new QAction( tr( "Reply" ), Resource::loadPixmap( "mailit/reply" ), 59 replyButton = new QAction( tr( "Reply" ), Resource::loadPixmap( "mailit/reply" ),
60 QString::null, 0, this, 0 ); 60 QString::null, 0, this, 0 );
61 connect(replyButton, SIGNAL(activated()), this, SLOT(reply()) ); 61 connect(replyButton, SIGNAL(activated()), this, SLOT(reply()) );
62 62
63 previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); 63 previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 );
64 connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) ); 64 connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) );
65 previousButton->addTo(bar); 65 previousButton->addTo(bar);
66 previousButton->addTo(viewMenu); 66 previousButton->addTo(viewMenu);
67 67
68 nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 ); 68 nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 );
69 connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) ); 69 connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) );
70 nextButton->addTo(bar); 70 nextButton->addTo(bar);
71 nextButton->addTo(viewMenu); 71 nextButton->addTo(viewMenu);
72 72
73 attatchmentsButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "mailit/attach" ), QString::null, 0, this, 0 ); 73 attatchmentsButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "mailit/attach" ), QString::null, 0, this, 0 );
74 connect( attatchmentsButton, SIGNAL( activated() ), this, 74 connect( attatchmentsButton, SIGNAL( activated() ), this,
75 SLOT( viewAttatchments() ) ); 75 SLOT( viewAttatchments() ) );
76 attatchmentsButton->addTo(bar); 76 attatchmentsButton->addTo(bar);
77 attatchmentsButton->addTo(viewMenu); 77 attatchmentsButton->addTo(viewMenu);
78 78
79 plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "DocsIcon" ), QString::null, 0, this, 0, TRUE); 79 plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "DocsIcon" ), QString::null, 0, this, 0, TRUE);
80 connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) ); 80 connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) );
81 plainTextButton->addTo(bar); 81 plainTextButton->addTo(bar);
82 plainTextButton->addTo(viewMenu); 82 plainTextButton->addTo(viewMenu);
83 83
84 deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); 84 deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 );
85 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); 85 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) );
86 deleteButton->addTo(bar); 86 deleteButton->addTo(bar);
87 deleteButton->addTo(mailMenu); 87 deleteButton->addTo(mailMenu);
88 88
89 viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close())); 89 viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close()));
90 90
91 emailView = new QTextView( this, "emailView" ); 91 emailView = new QTextView( this, "emailView" );
92 setCentralWidget(emailView); 92 setCentralWidget(emailView);
93 93
94 mime = new QMimeSourceFactory(); 94 mime = new QMimeSourceFactory();
95 emailView->setMimeSourceFactory(mime); 95 emailView->setMimeSourceFactory(mime);
96} 96}
97 97
98void ReadMail::updateView() 98void ReadMail::updateView()
99{ 99{
100 Enclosure *ePtr; 100 Enclosure *ePtr;
101 QString mailStringSize; 101 QString mailStringSize;
102 QString text, temp; 102 QString text, temp;
103 103
104 mail->read = TRUE; //mark as read 104 mail->read = TRUE; //mark as read
105 inbox = mail->received; 105 inbox = mail->received;
106 106
107 replyButton->removeFrom(mailMenu); 107 replyButton->removeFrom(mailMenu);
108 replyButton->removeFrom(bar); 108 replyButton->removeFrom(bar);
109 109
110 if (inbox == TRUE) { 110 if (inbox == TRUE) {
111 replyButton->addTo(bar); 111 replyButton->addTo(bar);
112 replyButton->addTo(mailMenu); 112 replyButton->addTo(mailMenu);
113 113
114 if (!mail->downloaded) { 114 if (!mail->downloaded) {
115 //report currently viewed mail so that it will be 115 //report currently viewed mail so that it will be
116 //placed first in the queue of new mails to download 116 //placed first in the queue of new mails to download
117 emit viewingMail(mail); 117 emit viewingMail(mail);
118 118
119 double mailSize = (double) mail->size; 119 double mailSize = (double) mail->size;
120 if (mailSize < 1024) { 120 if (mailSize < 1024) {
121 mailStringSize.setNum(mailSize); 121 mailStringSize.setNum(mailSize);
122 mailStringSize += " Bytes"; 122 mailStringSize += " Bytes";
123 } else if (mailSize < 1024*1024) { 123 } else if (mailSize < 1024*1024) {
124 mailStringSize.setNum( (mailSize / 1024), 'g', 2 ); 124 mailStringSize.setNum( (mailSize / 1024), 'g', 2 );
125 mailStringSize += " Kb"; 125 mailStringSize += " Kb";
126 } else { 126 } else {
127 mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3); 127 mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3);
128 mailStringSize += " Mb"; 128 mailStringSize += " Mb";
129 } 129 }
130 } 130 }
131 } 131 }
132 132
133 QMimeSourceFactory *mime = emailView->mimeSourceFactory(); 133 QMimeSourceFactory *mime = emailView->mimeSourceFactory();
134 134
135 if (! plainTxt) { //use RichText, inline pics etc. 135 if (! plainTxt) { //use RichText, inline pics etc.
136 emailView->setTextFormat(QTextView::RichText); 136 emailView->setTextFormat(QTextView::RichText);
137 text = "<b><big><center><font color=\"blue\">" + mail->subject 137 text = "<b><big><center><font color=\"blue\">" + mail->subject
138 +"</font></center></big></b><br>"; 138 +"</font></center></big></b><br>";
139 text += "<b>From: </b>" + mail->from + " <i>" + 139 text += "<b>From: </b>" + mail->from + " <i>" +
140 mail->fromMail + "</i><br>"; 140 mail->fromMail + "</i><br>";
141 141
142 text +="<b>To: </b>"; 142 text +="<b>To: </b>";
143 for (QStringList::Iterator it = mail->recipients.begin(); 143 for (QStringList::Iterator it = mail->recipients.begin();
144 it != mail->recipients.end(); ++it ) { 144 it != mail->recipients.end(); ++it ) {
145 text += *it + " "; 145 text += *it + " ";
146 } 146 }
147 text += "<br>" + mail->date; 147 text += "<br>" + mail->date;
148 148
149 if (mail->files.count() > 0) { 149 if (mail->files.count() > 0) {
150 text += "<br><b>Attatchments: </b>"; 150 text += "<br><b>Attatchments: </b>";
151 151
152 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 152 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
153 text += ePtr->originalName + " "; 153 text += ePtr->originalName + " ";
154 } 154 }
155 text += "<hr><br>" + mail->body; 155 text += "<hr><br>" + mail->body;
156 156
157 if (inbox) { 157 if (inbox) {
158 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 158 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
159 159
160 text += "<br><hr><b>Attatchment: </b>" + 160 text += "<br><hr><b>Attatchment: </b>" +
161 ePtr->originalName + "<hr>"; 161 ePtr->originalName + "<hr>";
162 162
163 if (ePtr->contentType == "TEXT") { 163 if (ePtr->contentType == "TEXT") {
164 QFile f(ePtr->path + ePtr->name); 164 QFile f(ePtr->path + ePtr->name);
165 165
166 if (f.open(IO_ReadOnly) ) { 166 if (f.open(IO_ReadOnly) ) {
167 QTextStream t(&f); 167 QTextStream t(&f);
168 temp = t.read(); 168 temp = t.read();
169 text += temp + "<br>"; 169 text += temp + "<br>";
170 f.close(); 170 f.close();
171 } else { 171 } else {
172 text += "<b>Could not locate file</b><br>"; 172 text += "<b>Could not locate file</b><br>";
173 } 173 }
174 174
175 } 175 }
176 if (ePtr->contentType == "IMAGE") { 176 if (ePtr->contentType == "IMAGE") {
177 // temp.setNum(emailView->width());//get display width 177 // temp.setNum(emailView->width());//get display width
178 // text += "<img width=" + temp +" src =""" + 178 // text += "<img width=" + temp +" src =""" +
179 // ePtr->originalName + """> </img>"; 179 // ePtr->originalName + """> </img>";
180 text += "<img src =""" + 180 text += "<img src =""" +
181 ePtr->originalName + """> </img>"; 181 ePtr->originalName + """> </img>";
182 mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) )); 182 mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) ));
183 } 183 }
184 } 184 }
185 } 185 }
186 } else { 186 } else {
187 if (mail->downloaded || !inbox) { 187 if (mail->downloaded || !inbox) {
188 text += "<hr><br>" + mail->body; 188 text += "<hr><br>" + mail->body;
189 } else { 189 } else {
190 text += "<hr><br><b> Awaiting download </b><br>"; 190 text += "<hr><br><b> Awaiting download </b><br>";
191 text += "Size of mail: " + mailStringSize; 191 text += "Size of mail: " + mailStringSize;
192 } 192 }
193 } 193 }
194 emailView->setText(text); 194 emailView->setText(text);
195 } else { // show plain txt mail 195 } else { // show plain txt mail
196 emailView->setTextFormat(QTextView::PlainText); 196 emailView->setTextFormat(QTextView::PlainText);
197 text = "Subject: " + mail->subject + "\n"; 197 text = "Subject: " + mail->subject + "\n";
198 text += "From: " + mail->from + " " + mail->fromMail + "\n"; 198 text += "From: " + mail->from + " " + mail->fromMail + "\n";
199 text += "To: "; 199 text += "To: ";
200 for (QStringList::Iterator it = mail->recipients.begin(); 200 for (QStringList::Iterator it = mail->recipients.begin();
201 it != mail->recipients.end(); ++it ) { 201 it != mail->recipients.end(); ++it ) {
202 text += *it + " "; 202 text += *it + " ";
203 } 203 }
204 text += "\nDate: " + mail->date + "\n"; 204 text += "\nDate: " + mail->date + "\n";
205 if (mail->files.count() > 0) { 205 if (mail->files.count() > 0) {
206 text += "Attatchments: "; 206 text += "Attatchments: ";
207 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 207 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
208 text += ePtr->originalName + " "; 208 text += ePtr->originalName + " ";
209 } 209 }
210 text += "\n\n"; 210 text += "\n\n";
211 } else text += "\n"; 211 } else text += "\n";
212 212
213 if (!inbox) { 213 if (!inbox) {
214 text += mail->body; 214 text += mail->body;
215 } else if (mail->downloaded) { 215 } else if (mail->downloaded) {
216 text += mail->bodyPlain; 216 text += mail->bodyPlain;
217 } else { 217 } else {
218 text += "\nAwaiting download\n"; 218 text += "\nAwaiting download\n";
219 text += "Size of mail: " + mailStringSize; 219 text += "Size of mail: " + mailStringSize;
220 } 220 }
221 221
222 emailView->setText(text); 222 emailView->setText(text);
223 } 223 }
224 224
225 if (mail->files.count() == 0) 225 if (mail->files.count() == 0)
226 attatchmentsButton->setEnabled(FALSE); 226 attatchmentsButton->setEnabled(FALSE);
227 else attatchmentsButton->setEnabled(TRUE); 227 else attatchmentsButton->setEnabled(TRUE);
228 228
229 setCaption("Examining mail: " + mail->subject); 229 setCaption("Examining mail: " + mail->subject);
230} 230}
231 231
232//update view with current EmailListItem (item) 232//update view with current EmailListItem (item)
233void ReadMail::update(QListView *thisView, Email *mailIn) 233void ReadMail::update(QListView *thisView, Email *mailIn)
234{ 234{
235 view = thisView; 235 view = thisView;
236 item = (EmailListItem *) view->selectedItem(); 236 item = (EmailListItem *) view->selectedItem();
237 mail = mailIn; 237 mail = mailIn;
238 updateView(); 238 updateView();
239 updateButtons(); 239 updateButtons();
240} 240}
241 241
242void ReadMail::mailUpdated(Email *mailIn) 242void ReadMail::mailUpdated(Email *mailIn)
243{ 243{
244 if (mailIn == mail) { 244 if (mailIn == mail) {
245 updateView(); 245 updateView();
246 } else { 246 } else {
247 updateButtons(); 247 updateButtons();
248 } 248 }
249} 249}
250 250
251void ReadMail::close() 251void ReadMail::close()
252{ 252{
253 emit cancelView(); 253 emit cancelView();
254} 254}
255 255
256//gets next item in listview, exits if there is no next 256//gets next item in listview, exits if there is no next
257void ReadMail::next() 257void ReadMail::next()
258{ 258{
259 item = (EmailListItem *) item->nextSibling(); 259 item = (EmailListItem *) item->nextSibling();
260 if (item != NULL) { 260 if (item != NULL) {
261 mail = item->getMail(); 261 mail = item->getMail();
262 updateView(); 262 updateView();
263 } 263 }
264 updateButtons(); 264 updateButtons();
265} 265}
266 266
267//gets previous item in listview, exits if there is no previous 267//gets previous item in listview, exits if there is no previous
268void ReadMail::previous() 268void ReadMail::previous()
269{ 269{
270 item = (EmailListItem *) item->itemAbove(); 270 item = (EmailListItem *) item->itemAbove();
271 if (item != NULL) { 271 if (item != NULL) {
272 mail = item->getMail(); 272 mail = item->getMail();
273 updateView(); 273 updateView();
274 } 274 }
275 updateButtons(); 275 updateButtons();
276} 276}
277 277
278//deletes item, tries bringing up next or previous, exits if unsucessful 278//deletes item, tries bringing up next or previous, exits if unsucessful
279void ReadMail::deleteItem() 279void ReadMail::deleteItem()
280{ 280{
281 EmailListItem *temp = item; 281 EmailListItem *temp = item;
282 temp = (EmailListItem *) item->nextSibling();//trybelow 282 temp = (EmailListItem *) item->nextSibling();//trybelow
283 if (temp == NULL) 283 if (temp == NULL)
284 temp = (EmailListItem *) item->itemAbove(); //try above 284 temp = (EmailListItem *) item->itemAbove(); //try above
285 285
286 emit removeItem(item, inbox); 286 emit removeItem(item, inbox);
287 287
288 item = temp; 288 item = temp;
289 if (item != NULL) { //more items in list 289 if (item != NULL) { //more items in list
290 mail = item->getMail(); 290 mail = item->getMail();
291 updateView(); 291 updateView();
292 updateButtons(); 292 updateButtons();
293 } else close(); //no more items to see 293 } else close(); //no more items to see
294} 294}
295 295
296void ReadMail::updateButtons() 296void ReadMail::updateButtons()
297{ 297{
298 EmailListItem *temp; 298 EmailListItem *temp;
299 299
300 temp = item; 300 temp = item;
301 if ((EmailListItem *) temp->nextSibling() == NULL) 301 if ((EmailListItem *) temp->nextSibling() == NULL)
302 nextButton->setEnabled(FALSE); 302 nextButton->setEnabled(FALSE);
303 else nextButton->setEnabled(TRUE); 303 else nextButton->setEnabled(TRUE);
304 304
305 temp = item; 305 temp = item;
306 if ((EmailListItem *) temp->itemAbove() == NULL) 306 if ((EmailListItem *) temp->itemAbove() == NULL)
307 previousButton->setEnabled(FALSE); 307 previousButton->setEnabled(FALSE);
308 else previousButton->setEnabled(TRUE); 308 else previousButton->setEnabled(TRUE);
309} 309}
310 310
311void ReadMail::shiftText() 311void ReadMail::shiftText()
312{ 312{
313 plainTxt = ! plainTxt; 313 plainTxt = ! plainTxt;
314 updateView(); 314 updateView();
315} 315}
316 316
317void ReadMail::viewAttatchments() 317void ReadMail::viewAttatchments()
318{ 318{
319 viewAtt->update(mail, inbox); 319 viewAtt->update(mail, inbox);
320 viewAtt->showMaximized(); 320 viewAtt->showMaximized();
321} 321}
322 322
323void ReadMail::reply() 323void ReadMail::reply()
324{ 324{
325 emit replyRequested(*mail); 325 emit replyRequested(*mail);
326} 326}
diff --git a/noncore/unsupported/mailit/writemail.cpp b/noncore/unsupported/mailit/writemail.cpp
index a45cfd2..38a2596 100644
--- a/noncore/unsupported/mailit/writemail.cpp
+++ b/noncore/unsupported/mailit/writemail.cpp
@@ -1,298 +1,298 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qmessagebox.h> 20#include <qmessagebox.h>
21#include "writemail.h" 21#include "writemail.h"
22#include "resource.h" 22#include <qpe/resource.h>
23 23
24WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl ) 24WriteMail::WriteMail( QWidget* parent, const char* name, WFlags fl )
25 : QMainWindow( parent, name, fl ) 25 : QMainWindow( parent, name, fl )
26{ 26{
27 showingAddressList = FALSE; 27 showingAddressList = FALSE;
28 init(); 28 init();
29 29
30 addAtt = new AddAtt(0, "Add Attatchments"); 30 addAtt = new AddAtt(0, "Add Attatchments");
31} 31}
32 32
33WriteMail::~WriteMail() 33WriteMail::~WriteMail()
34{ 34{
35 delete addAtt; 35 delete addAtt;
36} 36}
37 37
38void WriteMail::setAddressList(AddressList *list) 38void WriteMail::setAddressList(AddressList *list)
39{ 39{
40 Contact *cPtr; 40 Contact *cPtr;
41 41
42 addressList = list; 42 addressList = list;
43 43
44 addressView->clear(); 44 addressView->clear();
45 QList<Contact> *cListPtr = addressList->getContactList(); 45 QList<Contact> *cListPtr = addressList->getContactList();
46 QListViewItem *item; 46 QListViewItem *item;
47 for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) { 47 for (cPtr = cListPtr->first(); cPtr != 0; cPtr = cListPtr->next() ) {
48 item = new QListViewItem(addressView, cPtr->name, cPtr->email); 48 item = new QListViewItem(addressView, cPtr->name, cPtr->email);
49 } 49 }
50} 50}
51 51
52void WriteMail::init() 52void WriteMail::init()
53{ 53{
54 setToolBarsMovable(FALSE); 54 setToolBarsMovable(FALSE);
55 55
56 bar = new QToolBar(this); 56 bar = new QToolBar(this);
57 bar->setHorizontalStretchable( TRUE ); 57 bar->setHorizontalStretchable( TRUE );
58 58
59 menu = new QMenuBar( bar ); 59 menu = new QMenuBar( bar );
60 60
61 mailMenu = new QPopupMenu(menu); 61 mailMenu = new QPopupMenu(menu);
62 menu->insertItem( tr( "&Mail" ), mailMenu); 62 menu->insertItem( tr( "&Mail" ), mailMenu);
63 addMenu = new QPopupMenu(menu); 63 addMenu = new QPopupMenu(menu);
64 menu->insertItem( tr( "&Add" ), addMenu); 64 menu->insertItem( tr( "&Add" ), addMenu);
65 65
66 bar = new QToolBar(this); 66 bar = new QToolBar(this);
67 attatchButton = new QAction(tr("Attatchment"), Resource::loadPixmap("mailit/attach"), QString::null, 0, this, 0); 67 attatchButton = new QAction(tr("Attatchment"), Resource::loadPixmap("mailit/attach"), QString::null, 0, this, 0);
68 attatchButton->addTo(bar); 68 attatchButton->addTo(bar);
69 attatchButton->addTo(addMenu); 69 attatchButton->addTo(addMenu);
70 connect( attatchButton, SIGNAL( activated() ), this, SLOT( attatchFile() ) ); 70 connect( attatchButton, SIGNAL( activated() ), this, SLOT( attatchFile() ) );
71 71
72 confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0); 72 confirmButton = new QAction(tr("Enque mail"), Resource::loadPixmap("OKButton"), QString::null, 0, this, 0);
73 confirmButton->addTo(bar); 73 confirmButton->addTo(bar);
74 confirmButton->addTo(mailMenu); 74 confirmButton->addTo(mailMenu);
75 connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) ); 75 connect( confirmButton, SIGNAL( activated() ), this, SLOT( accept() ) );
76 76
77 newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0); 77 newButton = new QAction(tr("New mail"), Resource::loadPixmap("new"), QString::null, 0, this, 0);
78 newButton->addTo(mailMenu); 78 newButton->addTo(mailMenu);
79 connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) ); 79 connect( newButton, SIGNAL( activated() ), this, SLOT( newMail() ) );
80 80
81 widget = new QWidget(this, "widget"); 81 widget = new QWidget(this, "widget");
82 grid = new QGridLayout( widget ); 82 grid = new QGridLayout( widget );
83 83
84 recipientsBox = new QComboBox( FALSE, widget, "toLabel" ); 84 recipientsBox = new QComboBox( FALSE, widget, "toLabel" );
85 recipientsBox->insertItem( tr( "To:" ) ); 85 recipientsBox->insertItem( tr( "To:" ) );
86 recipientsBox->insertItem( tr( "CC:" ) ); 86 recipientsBox->insertItem( tr( "CC:" ) );
87 recipientsBox->setCurrentItem(0); 87 recipientsBox->setCurrentItem(0);
88 grid->addWidget( recipientsBox, 0, 0 ); 88 grid->addWidget( recipientsBox, 0, 0 );
89 89
90 subjetLabel = new QLabel( widget, "subjetLabel" ); 90 subjetLabel = new QLabel( widget, "subjetLabel" );
91 subjetLabel->setText( tr( "Subject:" ) ); 91 subjetLabel->setText( tr( "Subject:" ) );
92 92
93 grid->addWidget( subjetLabel, 1, 0 ); 93 grid->addWidget( subjetLabel, 1, 0 );
94 94
95 ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" ); 95 ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" );
96 ToolButton13_2->setText( tr( "..." ) ); 96 ToolButton13_2->setText( tr( "..." ) );
97 grid->addWidget( ToolButton13_2, 1, 2 ); 97 grid->addWidget( ToolButton13_2, 1, 2 );
98 98
99 subjectInput = new QLineEdit( widget, "subjectInput" ); 99 subjectInput = new QLineEdit( widget, "subjectInput" );
100 grid->addWidget( subjectInput, 1, 1 ); 100 grid->addWidget( subjectInput, 1, 1 );
101 101
102 toInput = new QLineEdit( widget, "toInput" ); 102 toInput = new QLineEdit( widget, "toInput" );
103 grid->addWidget( toInput, 0, 1 ); 103 grid->addWidget( toInput, 0, 1 );
104 104
105 addressButton = new QToolButton( widget, "addressButton" ); 105 addressButton = new QToolButton( widget, "addressButton" );
106 addressButton->setPixmap( Resource::loadPixmap("AddressBook") ); 106 addressButton->setPixmap( Resource::loadPixmap("AddressBook") );
107 addressButton->setToggleButton(TRUE); 107 addressButton->setToggleButton(TRUE);
108 grid->addWidget( addressButton, 0, 2 ); 108 grid->addWidget( addressButton, 0, 2 );
109 connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) ); 109 connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) );
110 110
111 emailInput = new QMultiLineEdit( widget, "emailInput" ); 111 emailInput = new QMultiLineEdit( widget, "emailInput" );
112 grid->addMultiCellWidget( emailInput, 2, 2, 0, 2); 112 grid->addMultiCellWidget( emailInput, 2, 2, 0, 2);
113 113
114 114
115 addressView = new QListView( widget, "addressView"); 115 addressView = new QListView( widget, "addressView");
116 addressView->addColumn("Name"); 116 addressView->addColumn("Name");
117 addressView->addColumn("EMail"); 117 addressView->addColumn("EMail");
118 addressView->setAllColumnsShowFocus(TRUE); 118 addressView->setAllColumnsShowFocus(TRUE);
119 addressView->setMultiSelection(TRUE); 119 addressView->setMultiSelection(TRUE);
120 addressView->hide(); 120 addressView->hide();
121 grid->addMultiCellWidget( addressView, 3, 3, 0, 2); 121 grid->addMultiCellWidget( addressView, 3, 3, 0, 2);
122 122
123 okButton = new QToolButton(bar, "ok"); 123 okButton = new QToolButton(bar, "ok");
124 okButton->setPixmap( Resource::loadPixmap("enter") ); 124 okButton->setPixmap( Resource::loadPixmap("enter") );
125 okButton->hide(); 125 okButton->hide();
126 connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) ); 126 connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) );
127 127
128 setCentralWidget(widget); 128 setCentralWidget(widget);
129} 129}
130 130
131void WriteMail::reject() 131void WriteMail::reject()
132{ 132{
133 emit cancelMail(); 133 emit cancelMail();
134} 134}
135 135
136// need to insert date 136// need to insert date
137void WriteMail::accept() 137void WriteMail::accept()
138{ 138{
139 QStringList attatchedFiles, attatchmentsType; 139 QStringList attatchedFiles, attatchmentsType;
140 int idCount = 0; 140 int idCount = 0;
141 141
142 if (toInput->text() == "") { 142 if (toInput->text() == "") {
143 QMessageBox::warning(this,"No recipient", "Send mail to whom?", "OK\n"); 143 QMessageBox::warning(this,"No recipient", "Send mail to whom?", "OK\n");
144 return; 144 return;
145 } 145 }
146 if (! getRecipients() ) { 146 if (! getRecipients() ) {
147 QMessageBox::warning(this,"Incorrect recipient separator", 147 QMessageBox::warning(this,"Incorrect recipient separator",
148 "Recipients must be separated by ;\nand be valid emailaddresses", "OK\n"); 148 "Recipients must be separated by ;\nand be valid emailaddresses", "OK\n");
149 return; 149 return;
150 } 150 }
151 mail.subject = subjectInput->text(); 151 mail.subject = subjectInput->text();
152 mail.body = emailInput->text(); 152 mail.body = emailInput->text();
153 mail.sent = false; 153 mail.sent = false;
154 mail.received = false; 154 mail.received = false;
155 mail.rawMail = "To: "; 155 mail.rawMail = "To: ";
156 156
157 for (QStringList::Iterator it = mail.recipients.begin(); 157 for (QStringList::Iterator it = mail.recipients.begin();
158 it != mail.recipients.end(); ++it) { 158 it != mail.recipients.end(); ++it) {
159 159
160 mail.rawMail += (*it); 160 mail.rawMail += (*it);
161 mail.rawMail += ",\n"; 161 mail.rawMail += ",\n";
162 } 162 }
163 mail.rawMail.truncate(mail.rawMail.length()-2); 163 mail.rawMail.truncate(mail.rawMail.length()-2);
164 mail.rawMail += mail.from; 164 mail.rawMail += mail.from;
165 mail.rawMail += "\nSubject: "; 165 mail.rawMail += "\nSubject: ";
166 mail.rawMail += mail.subject; 166 mail.rawMail += mail.subject;
167 mail.rawMail += "\n\n"; 167 mail.rawMail += "\n\n";
168 168
169 attatchedFiles = addAtt->returnAttatchedFiles(); 169 attatchedFiles = addAtt->returnAttatchedFiles();
170 attatchmentsType = addAtt->returnFileTypes(); 170 attatchmentsType = addAtt->returnFileTypes();
171 171
172 QStringList::Iterator itType = attatchmentsType.begin(); 172 QStringList::Iterator itType = attatchmentsType.begin();
173 173
174 Enclosure e; 174 Enclosure e;
175 for ( QStringList::Iterator it = attatchedFiles.begin(); it != attatchedFiles.end(); ++it ) { 175 for ( QStringList::Iterator it = attatchedFiles.begin(); it != attatchedFiles.end(); ++it ) {
176 e.id = idCount; 176 e.id = idCount;
177 e.originalName = (*it).latin1(); 177 e.originalName = (*it).latin1();
178 e.contentType = (*itType).latin1(); 178 e.contentType = (*itType).latin1();
179 e.contentAttribute = (*itType).latin1(); 179 e.contentAttribute = (*itType).latin1();
180 e.saved = TRUE; 180 e.saved = TRUE;
181 mail.addEnclosure(&e); 181 mail.addEnclosure(&e);
182 182
183 itType++; 183 itType++;
184 idCount++; 184 idCount++;
185 } 185 }
186 mail.rawMail += mail.body; 186 mail.rawMail += mail.body;
187 mail.rawMail += "\n"; 187 mail.rawMail += "\n";
188 mail.rawMail += ".\n"; 188 mail.rawMail += ".\n";
189 emit sendMailRequested(mail); 189 emit sendMailRequested(mail);
190 addAtt->clear(); 190 addAtt->clear();
191} 191}
192 192
193void WriteMail::getAddress() 193void WriteMail::getAddress()
194{ 194{
195 showingAddressList = !showingAddressList; 195 showingAddressList = !showingAddressList;
196 196
197 if (showingAddressList) { 197 if (showingAddressList) {
198 emailInput->hide(); 198 emailInput->hide();
199 addressView->show(); 199 addressView->show();
200 okButton->show(); 200 okButton->show();
201 201
202 } else { 202 } else {
203 addressView->hide(); 203 addressView->hide();
204 okButton->hide(); 204 okButton->hide();
205 emailInput->show(); 205 emailInput->show();
206 } 206 }
207} 207}
208 208
209void WriteMail::attatchFile() 209void WriteMail::attatchFile()
210{ 210{
211 addAtt->showMaximized(); 211 addAtt->showMaximized();
212} 212}
213 213
214void WriteMail::reply(Email replyMail) 214void WriteMail::reply(Email replyMail)
215{ 215{
216 int pos; 216 int pos;
217 217
218 mail = replyMail; 218 mail = replyMail;
219 mail.files.clear(); 219 mail.files.clear();
220 220
221 toInput->setText(mail.fromMail); 221 toInput->setText(mail.fromMail);
222 subjectInput->setText("Re: " + mail.subject); 222 subjectInput->setText("Re: " + mail.subject);
223 223
224 pos = 0; 224 pos = 0;
225 mail.body.insert(pos, ">>"); 225 mail.body.insert(pos, ">>");
226 while (pos != -1) { 226 while (pos != -1) {
227 pos = mail.body.find('\n', pos); 227 pos = mail.body.find('\n', pos);
228 if (pos != -1) 228 if (pos != -1)
229 mail.body.insert(++pos, ">>"); 229 mail.body.insert(++pos, ">>");
230 } 230 }
231 231
232 emailInput->setText(mail.body); 232 emailInput->setText(mail.body);
233} 233}
234 234
235bool WriteMail::getRecipients() 235bool WriteMail::getRecipients()
236{ 236{
237 QString str, temp; 237 QString str, temp;
238 int pos = 0; 238 int pos = 0;
239 239
240 mail.recipients.clear(); 240 mail.recipients.clear();
241 241
242 temp = toInput->text(); 242 temp = toInput->text();
243 while ( (pos = temp.find(';')) != -1) { 243 while ( (pos = temp.find(';')) != -1) {
244 str = temp.left(pos).stripWhiteSpace(); 244 str = temp.left(pos).stripWhiteSpace();
245 temp = temp.right(temp.length() - (pos + 1)); 245 temp = temp.right(temp.length() - (pos + 1));
246 if ( str.find('@') == -1) 246 if ( str.find('@') == -1)
247 return false; 247 return false;
248 mail.recipients.append(str); 248 mail.recipients.append(str);
249 addressList->addContact(str, ""); 249 addressList->addContact(str, "");
250 } 250 }
251 temp = temp.stripWhiteSpace(); 251 temp = temp.stripWhiteSpace();
252 if ( temp.find('@') == -1) 252 if ( temp.find('@') == -1)
253 return false; 253 return false;
254 mail.recipients.append(temp); 254 mail.recipients.append(temp);
255 addressList->addContact(temp, ""); 255 addressList->addContact(temp, "");
256 256
257 return TRUE; 257 return TRUE;
258} 258}
259 259
260 260
261void WriteMail::addRecipients() 261void WriteMail::addRecipients()
262{ 262{
263 QString recipients = ""; 263 QString recipients = "";
264 264
265 mail.recipients.clear(); 265 mail.recipients.clear();
266 QListViewItem *item = addressView->firstChild(); 266 QListViewItem *item = addressView->firstChild();
267 while (item != NULL) { 267 while (item != NULL) {
268 if ( item->isSelected() ) { 268 if ( item->isSelected() ) {
269 if (recipients == "") { 269 if (recipients == "") {
270 recipients = item->text(0); 270 recipients = item->text(0);
271 } else { 271 } else {
272 recipients += "; " + item->text(0); 272 recipients += "; " + item->text(0);
273 } 273 }
274 } 274 }
275 item = item->nextSibling(); 275 item = item->nextSibling();
276 } 276 }
277 toInput->setText(recipients); 277 toInput->setText(recipients);
278 278
279 addressView->hide(); 279 addressView->hide();
280 okButton->hide(); 280 okButton->hide();
281 emailInput->show(); 281 emailInput->show();
282 addressButton->setOn(FALSE); 282 addressButton->setOn(FALSE);
283 showingAddressList = !showingAddressList; 283 showingAddressList = !showingAddressList;
284} 284}
285 285
286void WriteMail::setRecipient(const QString &recipient) 286void WriteMail::setRecipient(const QString &recipient)
287{ 287{
288 toInput->setText(recipient); 288 toInput->setText(recipient);
289} 289}
290 290
291void WriteMail::newMail() 291void WriteMail::newMail()
292{ 292{
293 toInput->clear(); 293 toInput->clear();
294 subjectInput->clear(); 294 subjectInput->clear();
295 emailInput->clear(); 295 emailInput->clear();
296 //to clear selected 296 //to clear selected
297 setAddressList(addressList); 297 setAddressList(addressList);
298} 298}