summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/nntpwrapper.cpp15
-rw-r--r--noncore/net/mail/libmailwrapper/nntpwrapper.h2
-rw-r--r--noncore/net/mail/libmailwrapper/settings.cpp1
3 files changed, 11 insertions, 7 deletions
diff --git a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp
index ecdf848..798879d 100644
--- a/noncore/net/mail/libmailwrapper/nntpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/nntpwrapper.cpp
@@ -1,257 +1,262 @@
1#include "nntpwrapper.h" 1#include "nntpwrapper.h"
2#include "logindialog.h" 2#include "logindialog.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4 4
5#include <qfile.h> 5#include <qfile.h>
6 6
7#include <stdlib.h> 7#include <stdlib.h>
8 8
9#include <libetpan/libetpan.h> 9#include <libetpan/libetpan.h>
10 10
11 11
12#define HARD_MSG_SIZE_LIMIT 5242880 12#define HARD_MSG_SIZE_LIMIT 5242880
13 13
14NNTPwrapper::NNTPwrapper( NNTPaccount *a ) 14NNTPwrapper::NNTPwrapper( NNTPaccount *a )
15: Genericwrapper() { 15: Genericwrapper() {
16 account = a; 16 account = a;
17 m_nntp = NULL; 17 m_nntp = NULL;
18 msgTempName = a->getFileName()+"_msg_cache"; 18 msgTempName = a->getFileName()+"_msg_cache";
19 last_msg_id = 0; 19 last_msg_id = 0;
20} 20}
21 21
22NNTPwrapper::~NNTPwrapper() { 22NNTPwrapper::~NNTPwrapper() {
23 logout(); 23 logout();
24 QFile msg_cache(msgTempName); 24 QFile msg_cache(msgTempName);
25 if (msg_cache.exists()) { 25 if (msg_cache.exists()) {
26 msg_cache.remove(); 26 msg_cache.remove();
27 } 27 }
28} 28}
29 29
30void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) { 30void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) {
31 qDebug( "NNTP: %i of %i", current, maximum ); 31 qDebug( "NNTP: %i of %i", current, maximum );
32} 32}
33 33
34 34
35RecBody NNTPwrapper::fetchBody( const RecMail &mail ) { 35RecBody NNTPwrapper::fetchBody( const RecMail &mail ) {
36 int err = NEWSNNTP_NO_ERROR; 36 int err = NEWSNNTP_NO_ERROR;
37 char *message = 0; 37 char *message = 0;
38 size_t length = 0; 38 size_t length = 0;
39 39
40 login(); 40 login();
41 if ( !m_nntp ) { 41 if ( !m_nntp ) {
42 return RecBody(); 42 return RecBody();
43 } 43 }
44 44
45 RecBody body; 45 RecBody body;
46 mailmessage * mailmsg; 46 mailmessage * mailmsg;
47 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { 47 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
48 qDebug("Message to large: %i",mail.Msgsize()); 48 qDebug("Message to large: %i",mail.Msgsize());
49 return body; 49 return body;
50 } 50 }
51 51
52 QFile msg_cache(msgTempName); 52 QFile msg_cache(msgTempName);
53 53
54 cleanMimeCache(); 54 cleanMimeCache();
55 55
56 if (mail.getNumber()!=last_msg_id) { 56 if (mail.getNumber()!=last_msg_id) {
57 if (msg_cache.exists()) { 57 if (msg_cache.exists()) {
58 msg_cache.remove(); 58 msg_cache.remove();
59 } 59 }
60 msg_cache.open(IO_ReadWrite|IO_Truncate); 60 msg_cache.open(IO_ReadWrite|IO_Truncate);
61 last_msg_id = mail.getNumber(); 61 last_msg_id = mail.getNumber();
62 err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg); 62 err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg);
63 err = mailmessage_fetch(mailmsg,&message,&length); 63 err = mailmessage_fetch(mailmsg,&message,&length);
64 msg_cache.writeBlock(message,length); 64 msg_cache.writeBlock(message,length);
65 } else { 65 } else {
66 QString msg=""; 66 QString msg="";
67 msg_cache.open(IO_ReadOnly); 67 msg_cache.open(IO_ReadOnly);
68 message = new char[4096]; 68 message = new char[4096];
69 memset(message,0,4096); 69 memset(message,0,4096);
70 while (msg_cache.readBlock(message,4095)>0) { 70 while (msg_cache.readBlock(message,4095)>0) {
71 msg+=message; 71 msg+=message;
72 memset(message,0,4096); 72 memset(message,0,4096);
73 } 73 }
74 delete message; 74 delete message;
75 message = (char*)malloc(msg.length()+1*sizeof(char)); 75 message = (char*)malloc(msg.length()+1*sizeof(char));
76 memset(message,0,msg.length()+1); 76 memset(message,0,msg.length()+1);
77 memcpy(message,msg.latin1(),msg.length()); 77 memcpy(message,msg.latin1(),msg.length());
78 /* transform to libetpan stuff */ 78 /* transform to libetpan stuff */
79 mailmsg = mailmessage_new(); 79 mailmsg = mailmessage_new();
80 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 80 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
81 generic_message_t * msg_data; 81 generic_message_t * msg_data;
82 msg_data = (generic_message_t *)mailmsg->msg_data; 82 msg_data = (generic_message_t *)mailmsg->msg_data;
83 msg_data->msg_fetched = 1; 83 msg_data->msg_fetched = 1;
84 msg_data->msg_message = message; 84 msg_data->msg_message = message;
85 msg_data->msg_length = strlen(message); 85 msg_data->msg_length = strlen(message);
86 } 86 }
87 body = parseMail(mailmsg); 87 body = parseMail(mailmsg);
88 88
89 /* clean up */ 89 /* clean up */
90 if (mailmsg) 90 if (mailmsg)
91 mailmessage_free(mailmsg); 91 mailmessage_free(mailmsg);
92 if (message) 92 if (message)
93 free(message); 93 free(message);
94 94
95 return body; 95 return body;
96} 96}
97 97
98 98
99void NNTPwrapper::listMessages(const QString &, QList<RecMail> &target ) 99void NNTPwrapper::listMessages(const QString & which, QList<RecMail> &target )
100{ 100{
101 login(); 101 login();
102 if (!m_nntp) 102 if (!m_nntp)
103 return; 103 return;
104 uint32_t res_messages,res_recent,res_unseen; 104 uint32_t res_messages,res_recent,res_unseen;
105 mailsession_status_folder(m_nntp->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); 105 mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen);
106 parseList(target,m_nntp->sto_session,"INBOX"); 106 parseList(target,m_nntp->sto_session,which);
107} 107}
108 108
109void NNTPwrapper::login() 109void NNTPwrapper::login()
110{ 110{
111 if (account->getOffline()) 111 if (account->getOffline())
112 return; 112 return;
113 /* we'll hold the line */ 113 /* we'll hold the line */
114 if ( m_nntp != NULL ) 114 if ( m_nntp != NULL )
115 return; 115 return;
116 116
117 const char *server, *user, *pass; 117 const char *server, *user, *pass;
118 QString User,Pass; 118 QString User,Pass;
119 uint16_t port; 119 uint16_t port;
120 int err = NEWSNNTP_NO_ERROR; 120 int err = NEWSNNTP_NO_ERROR;
121 121
122 server = account->getServer().latin1(); 122 server = account->getServer().latin1();
123 port = account->getPort().toUInt(); 123 port = account->getPort().toUInt();
124 124
125 user = pass = 0; 125 user = pass = 0;
126 126
127 if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) { 127 if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) {
128 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 128 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
129 login.show(); 129 login.show();
130 if ( QDialog::Accepted == login.exec() ) { 130 if ( QDialog::Accepted == login.exec() ) {
131 // ok 131 // ok
132 User = login.getUser().latin1(); 132 User = login.getUser().latin1();
133 Pass = login.getPassword().latin1(); 133 Pass = login.getPassword().latin1();
134 } else { 134 } else {
135 // cancel 135 // cancel
136 qDebug( "NNTP: Login canceled" ); 136 qDebug( "NNTP: Login canceled" );
137 return; 137 return;
138 } 138 }
139 } else { 139 } else {
140 User = account->getUser().latin1(); 140 User = account->getUser().latin1();
141 Pass = account->getPassword().latin1(); 141 Pass = account->getPassword().latin1();
142 } 142 }
143 143
144 if (User.isEmpty()) { 144 if (User.isEmpty()) {
145 user=0; 145 user=0;
146 pass = 0; 146 pass = 0;
147 } else { 147 } else {
148 user=User.latin1(); 148 user=User.latin1();
149 pass=Pass.latin1(); 149 pass=Pass.latin1();
150 } 150 }
151 // bool ssl = account->getSSL(); 151 // bool ssl = account->getSSL();
152 152
153 m_nntp=mailstorage_new(NULL); 153 m_nntp=mailstorage_new(NULL);
154 154
155 int conntypeset = account->ConnectionType(); 155 int conntypeset = account->ConnectionType();
156 int conntype = 0; 156 int conntype = 0;
157 if ( conntypeset == 3 ) { 157 if ( conntypeset == 3 ) {
158 conntype = CONNECTION_TYPE_COMMAND; 158 conntype = CONNECTION_TYPE_COMMAND;
159 } else if ( conntypeset == 2 ) { 159 } else if ( conntypeset == 2 ) {
160 conntype = CONNECTION_TYPE_TLS; 160 conntype = CONNECTION_TYPE_TLS;
161 } else if ( conntypeset == 1 ) { 161 } else if ( conntypeset == 1 ) {
162 conntype = CONNECTION_TYPE_STARTTLS; 162 conntype = CONNECTION_TYPE_STARTTLS;
163 } else if ( conntypeset == 0 ) { 163 } else if ( conntypeset == 0 ) {
164 conntype = CONNECTION_TYPE_TRY_STARTTLS; 164 conntype = CONNECTION_TYPE_TRY_STARTTLS;
165 } 165 }
166 166
167 nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN, 167 nntp_mailstorage_init(m_nntp,(char*)server, port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN,
168 (char*)user,(char*)pass,0,0,0); 168 (char*)user,(char*)pass,0,0,0);
169 169
170 err = mailstorage_connect( m_nntp ); 170 err = mailstorage_connect( m_nntp );
171 171
172 if (err != NEWSNNTP_NO_ERROR) { 172 if (err != NEWSNNTP_NO_ERROR) {
173 qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) ); 173 qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) );
174 // Global::statusMessage(tr("Error initializing folder")); 174 // Global::statusMessage(tr("Error initializing folder"));
175 mailstorage_free(m_nntp); 175 mailstorage_free(m_nntp);
176 m_nntp = 0; 176 m_nntp = 0;
177 177
178 } 178 }
179 179
180} 180}
181 181
182void NNTPwrapper::logout() 182void NNTPwrapper::logout()
183{ 183{
184 int err = NEWSNNTP_NO_ERROR; 184 int err = NEWSNNTP_NO_ERROR;
185 if ( m_nntp == NULL ) 185 if ( m_nntp == NULL )
186 return; 186 return;
187 mailstorage_free(m_nntp); 187 mailstorage_free(m_nntp);
188 m_nntp = 0; 188 m_nntp = 0;
189} 189}
190 190
191QList<Folder>* NNTPwrapper::listFolders() { 191QList<Folder>* NNTPwrapper::listFolders() {
192 192
193 QList<Folder> * folders = new QList<Folder>(); 193 QList<Folder> * folders = new QList<Folder>();
194 folders->setAutoDelete( false ); 194 folders->setAutoDelete( false );
195 195 QStringList groups;
196// folders->append(inb); 196 if (account) {
197 groups = account->getGroups();
198 }
199 for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) {
200 folders->append(new Folder((*it),"."));
201 }
197 return folders; 202 return folders;
198} 203}
199 204
200 clist * NNTPwrapper::listAllNewsgroups() { 205 clist * NNTPwrapper::listAllNewsgroups() {
201 login(); 206 login();
202 clist *result = 0; 207 clist *result = 0;
203 clistcell *current; 208 clistcell *current;
204 newsnntp_group_description *list; 209 newsnntp_group_description *list;
205 if ( m_nntp ) { 210 if ( m_nntp ) {
206 mailsession * session = m_nntp->sto_session; 211 mailsession * session = m_nntp->sto_session;
207 newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; 212 newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session;
208 int err = newsnntp_list_newsgroups(news, NULL, &result); 213 int err = newsnntp_list_newsgroups(news, NULL, &result);
209 214
210 if ( err == NEWSNNTP_NO_ERROR ) { 215 if ( err == NEWSNNTP_NO_ERROR ) {
211 return result; 216 return result;
212 } 217 }
213 } 218 }
214} 219}
215 220
216void NNTPwrapper::answeredMail(const RecMail&) {} 221void NNTPwrapper::answeredMail(const RecMail&) {}
217 222
218void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { 223void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) {
219 login(); 224 login();
220 target_stat.message_count = 0; 225 target_stat.message_count = 0;
221 target_stat.message_unseen = 0; 226 target_stat.message_unseen = 0;
222 target_stat.message_recent = 0; 227 target_stat.message_recent = 0;
223 if (!m_nntp) 228 if (!m_nntp)
224 return; 229 return;
225 int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, 230 int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count,
226 &target_stat.message_recent,&target_stat.message_unseen); 231 &target_stat.message_recent,&target_stat.message_unseen);
227} 232}
228 233
229 234
230encodedString* NNTPwrapper::fetchRawBody(const RecMail&mail) { 235encodedString* NNTPwrapper::fetchRawBody(const RecMail&mail) {
231 char*target=0; 236 char*target=0;
232 size_t length=0; 237 size_t length=0;
233 encodedString*res = 0; 238 encodedString*res = 0;
234 mailmessage * mailmsg = 0; 239 mailmessage * mailmsg = 0;
235 int err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg); 240 int err = mailsession_get_message(m_nntp->sto_session, mail.getNumber(), &mailmsg);
236 err = mailmessage_fetch(mailmsg,&target,&length); 241 err = mailmessage_fetch(mailmsg,&target,&length);
237 if (mailmsg) 242 if (mailmsg)
238 mailmessage_free(mailmsg); 243 mailmessage_free(mailmsg);
239 if (target) { 244 if (target) {
240 res = new encodedString(target,length); 245 res = new encodedString(target,length);
241 } 246 }
242 return res; 247 return res;
243} 248}
244 249
245const QString&NNTPwrapper::getType()const { 250const QString&NNTPwrapper::getType()const {
246 return account->getType(); 251 return account->getType();
247} 252}
248 253
249const QString&NNTPwrapper::getName()const{ 254const QString&NNTPwrapper::getName()const{
250 return account->getAccountName(); 255 return account->getAccountName();
251} 256}
252 257
253void NNTPwrapper::deleteMail(const RecMail&mail) { 258void NNTPwrapper::deleteMail(const RecMail&mail) {
254} 259}
255 260
256int NNTPwrapper::deleteAllMail(const Folder*) { 261int NNTPwrapper::deleteAllMail(const Folder*) {
257} 262}
diff --git a/noncore/net/mail/libmailwrapper/nntpwrapper.h b/noncore/net/mail/libmailwrapper/nntpwrapper.h
index e4d4a37..e8e2cf4 100644
--- a/noncore/net/mail/libmailwrapper/nntpwrapper.h
+++ b/noncore/net/mail/libmailwrapper/nntpwrapper.h
@@ -1,48 +1,48 @@
1#ifndef __NNTPWRAPPER 1#ifndef __NNTPWRAPPER
2#define __NNTPWRAPPER 2#define __NNTPWRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include "genericwrapper.h" 5#include "genericwrapper.h"
6#include <qstring.h> 6#include <qstring.h>
7#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9class encodedString; 9class encodedString;
10struct mailstorage; 10struct mailstorage;
11struct mailfolder; 11struct mailfolder;
12 12
13class NNTPwrapper : public Genericwrapper 13class NNTPwrapper : public Genericwrapper
14{ 14{
15 15
16 Q_OBJECT 16 Q_OBJECT
17 17
18public: 18public:
19 NNTPwrapper( NNTPaccount *a ); 19 NNTPwrapper( NNTPaccount *a );
20 virtual ~NNTPwrapper(); 20 virtual ~NNTPwrapper();
21 21
22 /* mailbox will be ignored */ 22 /* mailbox will be ignored */
23 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 23 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
24 /* should only get the subscribed one */ 24 /* should only get the subscribed one */
25 virtual QList<Folder>* listFolders(); 25 virtual QList<Folder>* listFolders();
26 /* mailbox will be ignored */ 26 /* mailbox will be ignored */
27 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 27 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
28 clist * listAllNewsgroups(); 28 clist * listAllNewsgroups();
29 virtual void deleteMail(const RecMail&mail); 29 virtual void deleteMail(const RecMail&mail);
30 virtual void answeredMail(const RecMail&mail); 30 virtual void answeredMail(const RecMail&mail);
31 virtual int deleteAllMail(const Folder*); 31 virtual int deleteAllMail(const Folder*);
32 32
33 virtual RecBody fetchBody( const RecMail &mail ); 33 virtual RecBody fetchBody( const RecMail &mail );
34 virtual encodedString* fetchRawBody(const RecMail&mail); 34 virtual encodedString* fetchRawBody(const RecMail&mail);
35 virtual void logout(); 35 virtual void logout();
36 virtual const QString&getType()const; 36 virtual const QString&getType()const;
37 virtual const QString&getName()const; 37 virtual const QString&getName()const;
38 static void nntp_progress( size_t current, size_t maximum ); 38 static void nntp_progress( size_t current, size_t maximum );
39 39
40protected: 40protected:
41 void login(); 41 void login();
42 NNTPaccount *account; 42 NNTPaccount *account;
43 mailstorage* m_nntp; 43 mailstorage* m_nntp;
44 44
45 45
46}; 46};
47 47
48#endif 48#endif
diff --git a/noncore/net/mail/libmailwrapper/settings.cpp b/noncore/net/mail/libmailwrapper/settings.cpp
index f64c17d..0d34fd5 100644
--- a/noncore/net/mail/libmailwrapper/settings.cpp
+++ b/noncore/net/mail/libmailwrapper/settings.cpp
@@ -1,441 +1,440 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <qdir.h> 2#include <qdir.h>
3 3
4#include <qpe/config.h> 4#include <qpe/config.h>
5 5
6#include "settings.h" 6#include "settings.h"
7//#include "defines.h" 7//#include "defines.h"
8 8
9#define IMAP_PORT "143" 9#define IMAP_PORT "143"
10#define IMAP_SSL_PORT "993" 10#define IMAP_SSL_PORT "993"
11#define SMTP_PORT "25" 11#define SMTP_PORT "25"
12#define SMTP_SSL_PORT "465" 12#define SMTP_SSL_PORT "465"
13#define POP3_PORT "110" 13#define POP3_PORT "110"
14#define POP3_SSL_PORT "995" 14#define POP3_SSL_PORT "995"
15#define NNTP_PORT "119" 15#define NNTP_PORT "119"
16#define NNTP_SSL_PORT "563" 16#define NNTP_SSL_PORT "563"
17 17
18 18
19Settings::Settings() 19Settings::Settings()
20 : QObject() 20 : QObject()
21{ 21{
22 updateAccounts(); 22 updateAccounts();
23} 23}
24 24
25void Settings::checkDirectory() 25void Settings::checkDirectory()
26{ 26{
27 if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { 27 if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) {
28 system( "mkdir -p $HOME/Applications/opiemail" ); 28 system( "mkdir -p $HOME/Applications/opiemail" );
29 qDebug( "$HOME/Applications/opiemail created" ); 29 qDebug( "$HOME/Applications/opiemail created" );
30 } 30 }
31} 31}
32 32
33QList<Account> Settings::getAccounts() 33QList<Account> Settings::getAccounts()
34{ 34{
35 return accounts; 35 return accounts;
36} 36}
37 37
38void Settings::addAccount( Account *account ) 38void Settings::addAccount( Account *account )
39{ 39{
40 accounts.append( account ); 40 accounts.append( account );
41} 41}
42 42
43void Settings::delAccount( Account *account ) 43void Settings::delAccount( Account *account )
44{ 44{
45 accounts.remove( account ); 45 accounts.remove( account );
46 account->remove(); 46 account->remove();
47} 47}
48 48
49void Settings::updateAccounts() 49void Settings::updateAccounts()
50{ 50{
51 accounts.clear(); 51 accounts.clear();
52 QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); 52 QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" );
53 QStringList::Iterator it; 53 QStringList::Iterator it;
54 54
55 QStringList imap = dir.entryList( "imap-*" ); 55 QStringList imap = dir.entryList( "imap-*" );
56 for ( it = imap.begin(); it != imap.end(); it++ ) { 56 for ( it = imap.begin(); it != imap.end(); it++ ) {
57 qDebug( "Added IMAP account" ); 57 qDebug( "Added IMAP account" );
58 IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); 58 IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") );
59 accounts.append( account ); 59 accounts.append( account );
60 } 60 }
61 61
62 QStringList pop3 = dir.entryList( "pop3-*" ); 62 QStringList pop3 = dir.entryList( "pop3-*" );
63 for ( it = pop3.begin(); it != pop3.end(); it++ ) { 63 for ( it = pop3.begin(); it != pop3.end(); it++ ) {
64 qDebug( "Added POP account" ); 64 qDebug( "Added POP account" );
65 POP3account *account = new POP3account( (*it).replace(0, 5, "") ); 65 POP3account *account = new POP3account( (*it).replace(0, 5, "") );
66 accounts.append( account ); 66 accounts.append( account );
67 } 67 }
68 68
69 QStringList smtp = dir.entryList( "smtp-*" ); 69 QStringList smtp = dir.entryList( "smtp-*" );
70 for ( it = smtp.begin(); it != smtp.end(); it++ ) { 70 for ( it = smtp.begin(); it != smtp.end(); it++ ) {
71 qDebug( "Added SMTP account" ); 71 qDebug( "Added SMTP account" );
72 SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); 72 SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") );
73 accounts.append( account ); 73 accounts.append( account );
74 } 74 }
75 75
76 QStringList nntp = dir.entryList( "nntp-*" ); 76 QStringList nntp = dir.entryList( "nntp-*" );
77 for ( it = nntp.begin(); it != nntp.end(); it++ ) { 77 for ( it = nntp.begin(); it != nntp.end(); it++ ) {
78 qDebug( "Added NNTP account" ); 78 qDebug( "Added NNTP account" );
79 NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); 79 NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") );
80 accounts.append( account ); 80 accounts.append( account );
81 } 81 }
82 82
83 readAccounts(); 83 readAccounts();
84} 84}
85 85
86void Settings::saveAccounts() 86void Settings::saveAccounts()
87{ 87{
88 checkDirectory(); 88 checkDirectory();
89 Account *it; 89 Account *it;
90 90
91 for ( it = accounts.first(); it; it = accounts.next() ) { 91 for ( it = accounts.first(); it; it = accounts.next() ) {
92 it->save(); 92 it->save();
93 } 93 }
94} 94}
95 95
96void Settings::readAccounts() 96void Settings::readAccounts()
97{ 97{
98 checkDirectory(); 98 checkDirectory();
99 Account *it; 99 Account *it;
100 100
101 for ( it = accounts.first(); it; it = accounts.next() ) { 101 for ( it = accounts.first(); it; it = accounts.next() ) {
102 it->read(); 102 it->read();
103 } 103 }
104} 104}
105 105
106Account::Account() 106Account::Account()
107{ 107{
108 accountName = "changeMe"; 108 accountName = "changeMe";
109 type = "changeMe"; 109 type = "changeMe";
110 ssl = false; 110 ssl = false;
111 connectionType = 1; 111 connectionType = 1;
112 offline = false; 112 offline = false;
113} 113}
114 114
115void Account::remove() 115void Account::remove()
116{ 116{
117 QFile file( getFileName() ); 117 QFile file( getFileName() );
118 file.remove(); 118 file.remove();
119} 119}
120 120
121IMAPaccount::IMAPaccount() 121IMAPaccount::IMAPaccount()
122 : Account() 122 : Account()
123{ 123{
124 file = IMAPaccount::getUniqueFileName(); 124 file = IMAPaccount::getUniqueFileName();
125 accountName = "New IMAP Account"; 125 accountName = "New IMAP Account";
126 ssl = false; 126 ssl = false;
127 connectionType = 1; 127 connectionType = 1;
128 type = "IMAP"; 128 type = "IMAP";
129 port = IMAP_PORT; 129 port = IMAP_PORT;
130} 130}
131 131
132IMAPaccount::IMAPaccount( QString filename ) 132IMAPaccount::IMAPaccount( QString filename )
133 : Account() 133 : Account()
134{ 134{
135 file = filename; 135 file = filename;
136 accountName = "New IMAP Account"; 136 accountName = "New IMAP Account";
137 ssl = false; 137 ssl = false;
138 connectionType = 1; 138 connectionType = 1;
139 type = "IMAP"; 139 type = "IMAP";
140 port = IMAP_PORT; 140 port = IMAP_PORT;
141} 141}
142 142
143QString IMAPaccount::getUniqueFileName() 143QString IMAPaccount::getUniqueFileName()
144{ 144{
145 int num = 0; 145 int num = 0;
146 QString unique; 146 QString unique;
147 147
148 QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); 148 QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" );
149 149
150 QStringList imap = dir.entryList( "imap-*" ); 150 QStringList imap = dir.entryList( "imap-*" );
151 do { 151 do {
152 unique.setNum( num++ ); 152 unique.setNum( num++ );
153 } while ( imap.contains( "imap-" + unique ) > 0 ); 153 } while ( imap.contains( "imap-" + unique ) > 0 );
154 154
155 return unique; 155 return unique;
156} 156}
157 157
158void IMAPaccount::read() 158void IMAPaccount::read()
159{ 159{
160 Config *conf = new Config( getFileName(), Config::File ); 160 Config *conf = new Config( getFileName(), Config::File );
161 conf->setGroup( "IMAP Account" ); 161 conf->setGroup( "IMAP Account" );
162 accountName = conf->readEntry( "Account","" ); 162 accountName = conf->readEntry( "Account","" );
163 if (accountName.isNull()) accountName = ""; 163 if (accountName.isNull()) accountName = "";
164 server = conf->readEntry( "Server","" ); 164 server = conf->readEntry( "Server","" );
165 if (server.isNull()) server=""; 165 if (server.isNull()) server="";
166 port = conf->readEntry( "Port","" ); 166 port = conf->readEntry( "Port","" );
167 if (port.isNull()) port="143"; 167 if (port.isNull()) port="143";
168 connectionType = conf->readNumEntry( "ConnectionType" ); 168 connectionType = conf->readNumEntry( "ConnectionType" );
169 ssl = conf->readBoolEntry( "SSL",false ); 169 ssl = conf->readBoolEntry( "SSL",false );
170 user = conf->readEntry( "User","" ); 170 user = conf->readEntry( "User","" );
171 if (user.isNull()) user = ""; 171 if (user.isNull()) user = "";
172 password = conf->readEntryCrypt( "Password","" ); 172 password = conf->readEntryCrypt( "Password","" );
173 if (password.isNull()) password = ""; 173 if (password.isNull()) password = "";
174 prefix = conf->readEntry("MailPrefix",""); 174 prefix = conf->readEntry("MailPrefix","");
175 if (prefix.isNull()) prefix = ""; 175 if (prefix.isNull()) prefix = "";
176 offline = conf->readBoolEntry("Offline",false); 176 offline = conf->readBoolEntry("Offline",false);
177 delete conf; 177 delete conf;
178} 178}
179 179
180void IMAPaccount::save() 180void IMAPaccount::save()
181{ 181{
182 qDebug( "saving " + getFileName() ); 182 qDebug( "saving " + getFileName() );
183 Settings::checkDirectory(); 183 Settings::checkDirectory();
184 184
185 Config *conf = new Config( getFileName(), Config::File ); 185 Config *conf = new Config( getFileName(), Config::File );
186 conf->setGroup( "IMAP Account" ); 186 conf->setGroup( "IMAP Account" );
187 conf->writeEntry( "Account", accountName ); 187 conf->writeEntry( "Account", accountName );
188 conf->writeEntry( "Server", server ); 188 conf->writeEntry( "Server", server );
189 conf->writeEntry( "Port", port ); 189 conf->writeEntry( "Port", port );
190 conf->writeEntry( "SSL", ssl ); 190 conf->writeEntry( "SSL", ssl );
191 conf->writeEntry( "ConnectionType", connectionType ); 191 conf->writeEntry( "ConnectionType", connectionType );
192 conf->writeEntry( "User", user ); 192 conf->writeEntry( "User", user );
193 conf->writeEntryCrypt( "Password", password ); 193 conf->writeEntryCrypt( "Password", password );
194 conf->writeEntry( "MailPrefix",prefix); 194 conf->writeEntry( "MailPrefix",prefix);
195 conf->writeEntry( "Offline",offline); 195 conf->writeEntry( "Offline",offline);
196 conf->write(); 196 conf->write();
197 delete conf; 197 delete conf;
198} 198}
199 199
200 200
201QString IMAPaccount::getFileName() 201QString IMAPaccount::getFileName()
202{ 202{
203 return (QString) getenv( "HOME" ) + "/Applications/opiemail/imap-" + file; 203 return (QString) getenv( "HOME" ) + "/Applications/opiemail/imap-" + file;
204} 204}
205 205
206POP3account::POP3account() 206POP3account::POP3account()
207 : Account() 207 : Account()
208{ 208{
209 file = POP3account::getUniqueFileName(); 209 file = POP3account::getUniqueFileName();
210 accountName = "New POP3 Account"; 210 accountName = "New POP3 Account";
211 ssl = false; 211 ssl = false;
212 connectionType = 1; 212 connectionType = 1;
213 type = "POP3"; 213 type = "POP3";
214 port = POP3_PORT; 214 port = POP3_PORT;
215} 215}
216 216
217POP3account::POP3account( QString filename ) 217POP3account::POP3account( QString filename )
218 : Account() 218 : Account()
219{ 219{
220 file = filename; 220 file = filename;
221 accountName = "New POP3 Account"; 221 accountName = "New POP3 Account";
222 ssl = false; 222 ssl = false;
223 connectionType = 1; 223 connectionType = 1;
224 type = "POP3"; 224 type = "POP3";
225 port = POP3_PORT; 225 port = POP3_PORT;
226} 226}
227 227
228QString POP3account::getUniqueFileName() 228QString POP3account::getUniqueFileName()
229{ 229{
230 int num = 0; 230 int num = 0;
231 QString unique; 231 QString unique;
232 232
233 QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); 233 QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" );
234 234
235 QStringList imap = dir.entryList( "pop3-*" ); 235 QStringList imap = dir.entryList( "pop3-*" );
236 do { 236 do {
237 unique.setNum( num++ ); 237 unique.setNum( num++ );
238 } while ( imap.contains( "pop3-" + unique ) > 0 ); 238 } while ( imap.contains( "pop3-" + unique ) > 0 );
239 239
240 return unique; 240 return unique;
241} 241}
242 242
243void POP3account::read() 243void POP3account::read()
244{ 244{
245 Config *conf = new Config( getFileName(), Config::File ); 245 Config *conf = new Config( getFileName(), Config::File );
246 conf->setGroup( "POP3 Account" ); 246 conf->setGroup( "POP3 Account" );
247 accountName = conf->readEntry( "Account" ); 247 accountName = conf->readEntry( "Account" );
248 server = conf->readEntry( "Server" ); 248 server = conf->readEntry( "Server" );
249 port = conf->readEntry( "Port" ); 249 port = conf->readEntry( "Port" );
250 ssl = conf->readBoolEntry( "SSL" ); 250 ssl = conf->readBoolEntry( "SSL" );
251 connectionType = conf->readNumEntry( "ConnectionType" ); 251 connectionType = conf->readNumEntry( "ConnectionType" );
252 user = conf->readEntry( "User" ); 252 user = conf->readEntry( "User" );
253 password = conf->readEntryCrypt( "Password" ); 253 password = conf->readEntryCrypt( "Password" );
254 offline = conf->readBoolEntry("Offline",false); 254 offline = conf->readBoolEntry("Offline",false);
255 delete conf; 255 delete conf;
256} 256}
257 257
258void POP3account::save() 258void POP3account::save()
259{ 259{
260 qDebug( "saving " + getFileName() ); 260 qDebug( "saving " + getFileName() );
261 Settings::checkDirectory(); 261 Settings::checkDirectory();
262 262
263 Config *conf = new Config( getFileName(), Config::File ); 263 Config *conf = new Config( getFileName(), Config::File );
264 conf->setGroup( "POP3 Account" ); 264 conf->setGroup( "POP3 Account" );
265 conf->writeEntry( "Account", accountName ); 265 conf->writeEntry( "Account", accountName );
266 conf->writeEntry( "Server", server ); 266 conf->writeEntry( "Server", server );
267 conf->writeEntry( "Port", port ); 267 conf->writeEntry( "Port", port );
268 conf->writeEntry( "SSL", ssl ); 268 conf->writeEntry( "SSL", ssl );
269 conf->writeEntry( "ConnectionType", connectionType ); 269 conf->writeEntry( "ConnectionType", connectionType );
270 conf->writeEntry( "User", user ); 270 conf->writeEntry( "User", user );
271 conf->writeEntryCrypt( "Password", password ); 271 conf->writeEntryCrypt( "Password", password );
272 conf->writeEntry( "Offline",offline); 272 conf->writeEntry( "Offline",offline);
273 conf->write(); 273 conf->write();
274 delete conf; 274 delete conf;
275} 275}
276 276
277 277
278QString POP3account::getFileName() 278QString POP3account::getFileName()
279{ 279{
280 return (QString) getenv( "HOME" ) + "/Applications/opiemail/pop3-" + file; 280 return (QString) getenv( "HOME" ) + "/Applications/opiemail/pop3-" + file;
281} 281}
282 282
283SMTPaccount::SMTPaccount() 283SMTPaccount::SMTPaccount()
284 : Account() 284 : Account()
285{ 285{
286 file = SMTPaccount::getUniqueFileName(); 286 file = SMTPaccount::getUniqueFileName();
287 accountName = "New SMTP Account"; 287 accountName = "New SMTP Account";
288 ssl = false; 288 ssl = false;
289 connectionType = 1; 289 connectionType = 1;
290 login = false; 290 login = false;
291 useCC = false; 291 useCC = false;
292 useBCC = false; 292 useBCC = false;
293 useReply = false; 293 useReply = false;
294 type = "SMTP"; 294 type = "SMTP";
295 port = SMTP_PORT; 295 port = SMTP_PORT;
296} 296}
297 297
298SMTPaccount::SMTPaccount( QString filename ) 298SMTPaccount::SMTPaccount( QString filename )
299 : Account() 299 : Account()
300{ 300{
301 file = filename; 301 file = filename;
302 accountName = "New SMTP Account"; 302 accountName = "New SMTP Account";
303 ssl = false; 303 ssl = false;
304 connectionType = 1; 304 connectionType = 1;
305 login = false; 305 login = false;
306 type = "SMTP"; 306 type = "SMTP";
307 port = SMTP_PORT; 307 port = SMTP_PORT;
308} 308}
309 309
310QString SMTPaccount::getUniqueFileName() 310QString SMTPaccount::getUniqueFileName()
311{ 311{
312 int num = 0; 312 int num = 0;
313 QString unique; 313 QString unique;
314 314
315 QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); 315 QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" );
316 316
317 QStringList imap = dir.entryList( "smtp-*" ); 317 QStringList imap = dir.entryList( "smtp-*" );
318 do { 318 do {
319 unique.setNum( num++ ); 319 unique.setNum( num++ );
320 } while ( imap.contains( "smtp-" + unique ) > 0 ); 320 } while ( imap.contains( "smtp-" + unique ) > 0 );
321 321
322 return unique; 322 return unique;
323} 323}
324 324
325void SMTPaccount::read() 325void SMTPaccount::read()
326{ 326{
327 Config *conf = new Config( getFileName(), Config::File ); 327 Config *conf = new Config( getFileName(), Config::File );
328 conf->setGroup( "SMTP Account" ); 328 conf->setGroup( "SMTP Account" );
329 accountName = conf->readEntry( "Account" ); 329 accountName = conf->readEntry( "Account" );
330 server = conf->readEntry( "Server" ); 330 server = conf->readEntry( "Server" );
331 port = conf->readEntry( "Port" ); 331 port = conf->readEntry( "Port" );
332 ssl = conf->readBoolEntry( "SSL" ); 332 ssl = conf->readBoolEntry( "SSL" );
333 connectionType = conf->readNumEntry( "ConnectionType" ); 333 connectionType = conf->readNumEntry( "ConnectionType" );
334 login = conf->readBoolEntry( "Login" ); 334 login = conf->readBoolEntry( "Login" );
335 user = conf->readEntry( "User" ); 335 user = conf->readEntry( "User" );
336 password = conf->readEntryCrypt( "Password" ); 336 password = conf->readEntryCrypt( "Password" );
337 delete conf; 337 delete conf;
338} 338}
339 339
340void SMTPaccount::save() 340void SMTPaccount::save()
341{ 341{
342 qDebug( "saving " + getFileName() ); 342 qDebug( "saving " + getFileName() );
343 Settings::checkDirectory(); 343 Settings::checkDirectory();
344 344
345 Config *conf = new Config( getFileName(), Config::File ); 345 Config *conf = new Config( getFileName(), Config::File );
346 conf->setGroup( "SMTP Account" ); 346 conf->setGroup( "SMTP Account" );
347 conf->writeEntry( "Account", accountName ); 347 conf->writeEntry( "Account", accountName );
348 conf->writeEntry( "Server", server ); 348 conf->writeEntry( "Server", server );
349 conf->writeEntry( "Port", port ); 349 conf->writeEntry( "Port", port );
350 conf->writeEntry( "SSL", ssl ); 350 conf->writeEntry( "SSL", ssl );
351 conf->writeEntry( "ConnectionType", connectionType ); 351 conf->writeEntry( "ConnectionType", connectionType );
352 conf->writeEntry( "Login", login ); 352 conf->writeEntry( "Login", login );
353 conf->writeEntry( "User", user ); 353 conf->writeEntry( "User", user );
354 conf->writeEntryCrypt( "Password", password ); 354 conf->writeEntryCrypt( "Password", password );
355 conf->write(); 355 conf->write();
356 delete conf; 356 delete conf;
357} 357}
358 358
359 359
360QString SMTPaccount::getFileName() 360QString SMTPaccount::getFileName()
361{ 361{
362 return (QString) getenv( "HOME" ) + "/Applications/opiemail/smtp-" + file; 362 return (QString) getenv( "HOME" ) + "/Applications/opiemail/smtp-" + file;
363} 363}
364 364
365NNTPaccount::NNTPaccount() 365NNTPaccount::NNTPaccount()
366 : Account() 366 : Account()
367{ 367{
368 file = NNTPaccount::getUniqueFileName(); 368 file = NNTPaccount::getUniqueFileName();
369 accountName = "New NNTP Account"; 369 accountName = "New NNTP Account";
370 ssl = false; 370 ssl = false;
371 login = false; 371 login = false;
372 type = "NNTP"; 372 type = "NNTP";
373 port = NNTP_PORT; 373 port = NNTP_PORT;
374} 374}
375 375
376NNTPaccount::NNTPaccount( QString filename ) 376NNTPaccount::NNTPaccount( QString filename )
377 : Account() 377 : Account()
378{ 378{
379 file = filename; 379 file = filename;
380 accountName = "New NNTP Account"; 380 accountName = "New NNTP Account";
381 ssl = false; 381 ssl = false;
382 login = false; 382 login = false;
383 type = "NNTP"; 383 type = "NNTP";
384 port = NNTP_PORT; 384 port = NNTP_PORT;
385} 385}
386 386
387QString NNTPaccount::getUniqueFileName() 387QString NNTPaccount::getUniqueFileName()
388{ 388{
389 int num = 0; 389 int num = 0;
390 QString unique; 390 QString unique;
391 391
392 QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); 392 QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" );
393 393
394 QStringList imap = dir.entryList( "nntp-*" ); 394 QStringList imap = dir.entryList( "nntp-*" );
395 do { 395 do {
396 unique.setNum( num++ ); 396 unique.setNum( num++ );
397 } while ( imap.contains( "nntp-" + unique ) > 0 ); 397 } while ( imap.contains( "nntp-" + unique ) > 0 );
398 398
399 return unique; 399 return unique;
400} 400}
401 401
402void NNTPaccount::read() 402void NNTPaccount::read()
403{ 403{
404 Config *conf = new Config( getFileName(), Config::File ); 404 Config *conf = new Config( getFileName(), Config::File );
405 conf->setGroup( "NNTP Account" ); 405 conf->setGroup( "NNTP Account" );
406 accountName = conf->readEntry( "Account" ); 406 accountName = conf->readEntry( "Account" );
407 server = conf->readEntry( "Server" ); 407 server = conf->readEntry( "Server" );
408 port = conf->readEntry( "Port" ); 408 port = conf->readEntry( "Port" );
409 ssl = conf->readBoolEntry( "SSL" ); 409 ssl = conf->readBoolEntry( "SSL" );
410 login = conf->readBoolEntry( "Login" ); 410 login = conf->readBoolEntry( "Login" );
411 user = conf->readEntry( "User" ); 411 user = conf->readEntry( "User" );
412 password = conf->readEntryCrypt( "Password" ); 412 password = conf->readEntryCrypt( "Password" );
413 subscribedGroups = conf->readListEntry( "Subscribed", ',' ); 413 subscribedGroups = conf->readListEntry( "Subscribed", ',' );
414 delete conf; 414 delete conf;
415} 415}
416 416
417void NNTPaccount::save() 417void NNTPaccount::save()
418{ 418{
419 qDebug( "saving " + getFileName() ); 419 qDebug( "saving " + getFileName() );
420 Settings::checkDirectory(); 420 Settings::checkDirectory();
421 421
422 Config *conf = new Config( getFileName(), Config::File ); 422 Config *conf = new Config( getFileName(), Config::File );
423 conf->setGroup( "NNTP Account" ); 423 conf->setGroup( "NNTP Account" );
424 conf->writeEntry( "Account", accountName ); 424 conf->writeEntry( "Account", accountName );
425 conf->writeEntry( "Server", server ); 425 conf->writeEntry( "Server", server );
426 conf->writeEntry( "Port", port ); 426 conf->writeEntry( "Port", port );
427 conf->writeEntry( "SSL", ssl ); 427 conf->writeEntry( "SSL", ssl );
428 conf->writeEntry( "Login", login ); 428 conf->writeEntry( "Login", login );
429 conf->writeEntry( "User", user ); 429 conf->writeEntry( "User", user );
430 conf->writeEntryCrypt( "Password", password ); 430 conf->writeEntryCrypt( "Password", password );
431 conf->writeEntry( "Subscribed" , subscribedGroups, ',' ); 431 conf->writeEntry( "Subscribed" , subscribedGroups, ',' );
432 conf->write(); 432 conf->write();
433 delete conf; 433 delete conf;
434} 434}
435 435
436 436
437QString NNTPaccount::getFileName() 437QString NNTPaccount::getFileName()
438{ 438{
439 return (QString) getenv( "HOME" ) + "/Applications/opiemail/nntp-" + file; 439 return (QString) getenv( "HOME" ) + "/Applications/opiemail/nntp-" + file;
440} 440}
441