42 files changed, 7485 insertions, 0 deletions
diff --git a/noncore/net/mail/TODO b/noncore/net/mail/TODO new file mode 100644 index 0000000..044dbb1 --- a/dev/null +++ b/noncore/net/mail/TODO | |||
@@ -0,0 +1,11 @@ | |||
1 | - crosscompile libEtPan! | ||
2 | - do at least some error checking and report them to the user | ||
3 | - thread the whole send/recieve thing | ||
4 | - add mail recieve support | ||
5 | - queue mails for sending | ||
6 | - check source for memory leaks (there is a whole bunch out there) | ||
7 | - make bigger (64x64) desktop icon | ||
8 | - rename app to "mail" | ||
9 | - opie taskbar plugin | ||
10 | - integrate in opie pim | ||
11 | - get some sleep | ||
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp new file mode 100644 index 0000000..c6a44ab --- a/dev/null +++ b/noncore/net/mail/accountview.cpp | |||
@@ -0,0 +1,110 @@ | |||
1 | #include "accountview.h" | ||
2 | #include "defines.h" | ||
3 | |||
4 | IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent ) | ||
5 | : AccountViewItem( parent ) | ||
6 | { | ||
7 | account = a; | ||
8 | wrapper = new IMAPwrapper( account ); | ||
9 | setPixmap( 0, PIXMAP_IMAPFOLDER ); | ||
10 | setText( 0, account->getAccountName() ); | ||
11 | setOpen( true ); | ||
12 | } | ||
13 | |||
14 | IMAPviewItem::~IMAPviewItem() | ||
15 | { | ||
16 | delete wrapper; | ||
17 | } | ||
18 | |||
19 | IMAPwrapper *IMAPviewItem::getWrapper() | ||
20 | { | ||
21 | return wrapper; | ||
22 | } | ||
23 | |||
24 | void IMAPviewItem::refresh(Maillist&) | ||
25 | { | ||
26 | QList<IMAPFolder> *folders = wrapper->listFolders(); | ||
27 | |||
28 | QListViewItem *child = firstChild(); | ||
29 | while ( child ) { | ||
30 | QListViewItem *tmp = child; | ||
31 | child = child->nextSibling(); | ||
32 | delete tmp; | ||
33 | } | ||
34 | |||
35 | IMAPFolder *it; | ||
36 | for ( it = folders->first(); it; it = folders->next() ) { | ||
37 | (void) new IMAPfolderItem( it, this ); | ||
38 | } | ||
39 | } | ||
40 | |||
41 | |||
42 | IMAPfolderItem::~IMAPfolderItem() | ||
43 | { | ||
44 | delete folder; | ||
45 | } | ||
46 | |||
47 | IMAPfolderItem::IMAPfolderItem( IMAPFolder *folderInit, IMAPviewItem *parent ) | ||
48 | : AccountViewItem( parent ) | ||
49 | { | ||
50 | folder = folderInit; | ||
51 | imap = parent; | ||
52 | setPixmap( 0, PIXMAP_IMAPFOLDER ); | ||
53 | setText( 0, folder->getDisplayName() ); | ||
54 | } | ||
55 | |||
56 | void IMAPfolderItem::refresh(Maillist&target) | ||
57 | { | ||
58 | imap->getWrapper()->listMessages( folder->getName(),target ); | ||
59 | } | ||
60 | |||
61 | QString IMAPfolderItem::fetchBody(const RecMail&aMail) | ||
62 | { | ||
63 | return imap->getWrapper()->fetchBody(folder->getName(),aMail); | ||
64 | } | ||
65 | |||
66 | AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) | ||
67 | : QListView( parent, name, flags ) | ||
68 | { | ||
69 | connect( this, SIGNAL( clicked( QListViewItem * ) ), | ||
70 | SLOT( refresh( QListViewItem * ) ) ); | ||
71 | } | ||
72 | |||
73 | void AccountView::populate( QList<Account> list ) | ||
74 | { | ||
75 | clear(); | ||
76 | |||
77 | Account *it; | ||
78 | for ( it = list.first(); it; it = list.next() ) { | ||
79 | if ( it->getType().compare( "IMAP" ) == 0 ) { | ||
80 | IMAPaccount *imap = static_cast<IMAPaccount *>(it); | ||
81 | qDebug( "added IMAP " + imap->getAccountName() ); | ||
82 | (void) new IMAPviewItem( imap, this ); | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | |||
87 | void AccountView::refresh(QListViewItem *item) { | ||
88 | qDebug("AccountView refresh..."); | ||
89 | if ( item ) { | ||
90 | Maillist headerlist; | ||
91 | headerlist.setAutoDelete(true); | ||
92 | AccountViewItem *view = static_cast<AccountViewItem *>(item); | ||
93 | view->refresh(headerlist); | ||
94 | emit refreshMailview(&headerlist); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | void AccountView::refreshAll() | ||
99 | { | ||
100 | |||
101 | } | ||
102 | |||
103 | QString AccountView::fetchBody(const RecMail&aMail) | ||
104 | { | ||
105 | QString Body; | ||
106 | QListViewItem*item = selectedItem (); | ||
107 | if (!item) return Body; | ||
108 | AccountViewItem *view = static_cast<AccountViewItem *>(item); | ||
109 | return view->fetchBody(aMail); | ||
110 | } | ||
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h new file mode 100644 index 0000000..14d8efa --- a/dev/null +++ b/noncore/net/mail/accountview.h | |||
@@ -0,0 +1,67 @@ | |||
1 | #ifndef ACCOUNTVIEW_H | ||
2 | #define ACCOUNTVIEW_H | ||
3 | |||
4 | #include <qlistview.h> | ||
5 | |||
6 | #include "settings.h" | ||
7 | #include "mailwrapper.h" | ||
8 | |||
9 | class AccountViewItem : public QListViewItem | ||
10 | { | ||
11 | |||
12 | public: | ||
13 | AccountViewItem( QListView *parent ) : QListViewItem( parent ) {} | ||
14 | AccountViewItem( QListViewItem *parent ) : QListViewItem( parent ) {} | ||
15 | virtual void refresh(Maillist&)=0; | ||
16 | virtual QString fetchBody(const RecMail&)=0; | ||
17 | }; | ||
18 | |||
19 | class IMAPviewItem : public AccountViewItem | ||
20 | { | ||
21 | |||
22 | public: | ||
23 | IMAPviewItem( IMAPaccount *a, QListView *parent ); | ||
24 | ~IMAPviewItem(); | ||
25 | virtual void refresh(Maillist&); | ||
26 | virtual QString fetchBody(const RecMail&){return "";} | ||
27 | IMAPwrapper *getWrapper(); | ||
28 | |||
29 | private: | ||
30 | IMAPaccount *account; | ||
31 | IMAPwrapper *wrapper; | ||
32 | |||
33 | }; | ||
34 | |||
35 | class IMAPfolderItem : public AccountViewItem | ||
36 | { | ||
37 | |||
38 | public: | ||
39 | IMAPfolderItem( IMAPFolder *folder, IMAPviewItem *parent ); | ||
40 | ~IMAPfolderItem(); | ||
41 | virtual void refresh(Maillist&); | ||
42 | virtual QString fetchBody(const RecMail&); | ||
43 | |||
44 | private: | ||
45 | IMAPFolder *folder; | ||
46 | IMAPviewItem *imap; | ||
47 | |||
48 | }; | ||
49 | |||
50 | class AccountView : public QListView | ||
51 | { | ||
52 | Q_OBJECT | ||
53 | |||
54 | public: | ||
55 | AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); | ||
56 | void populate( QList<Account> list ); | ||
57 | QString fetchBody(const RecMail&aMail); | ||
58 | |||
59 | public slots: | ||
60 | void refreshAll(); | ||
61 | void refresh(QListViewItem *item); | ||
62 | |||
63 | signals: | ||
64 | void refreshMailview(Maillist*); | ||
65 | }; | ||
66 | |||
67 | #endif | ||
diff --git a/noncore/net/mail/addresspicker.cpp b/noncore/net/mail/addresspicker.cpp new file mode 100644 index 0000000..2c15bb4 --- a/dev/null +++ b/noncore/net/mail/addresspicker.cpp | |||
@@ -0,0 +1,130 @@ | |||
1 | #include <qpushbutton.h> | ||
2 | #include <qmessagebox.h> | ||
3 | #include <qtextstream.h> | ||
4 | #include <qlistbox.h> | ||
5 | #include <qfile.h> | ||
6 | |||
7 | #include <qpe/resource.h> | ||
8 | |||
9 | #include <stdlib.h> | ||
10 | |||
11 | #include "composemail.h" | ||
12 | |||
13 | AddressPicker::AddressPicker( QWidget *parent, const char *name, bool modal, WFlags flags ) | ||
14 | : AddressPickerUI( parent, name, modal, flags ) | ||
15 | { | ||
16 | okButton->setIconSet( Resource::loadPixmap( "enter" ) ); | ||
17 | cancelButton->setIconSet( Resource::loadPixmap( "editdelete" ) ); | ||
18 | |||
19 | connect(okButton, SIGNAL(clicked()), SLOT(accept())); | ||
20 | connect(cancelButton, SIGNAL(clicked()), SLOT(close())); | ||
21 | |||
22 | QFile f((QString) getenv("HOME") + "/Applications/" | ||
23 | + "addressbook/addressbook.xml"); | ||
24 | |||
25 | if ( f.open( IO_ReadOnly ) ) { | ||
26 | QTextStream stream( &f ); | ||
27 | stream.setEncoding( QTextStream::UnicodeUTF8 ); | ||
28 | QString content; | ||
29 | while ( !f.atEnd() ) { | ||
30 | content += stream.readLine() + "\n"; | ||
31 | } | ||
32 | QStringList lines = QStringList::split( QRegExp( "\\n" ), content ); | ||
33 | QStringList::Iterator it; | ||
34 | for ( it = lines.begin(); it != lines.end(); it++ ) { | ||
35 | if ( (*it).find( QRegExp( "^<Contact.*" ) ) != -1 ) { | ||
36 | int pos = (*it).find( "FirstName=\"" ); | ||
37 | QString fname; | ||
38 | if ( pos != -1 ) { | ||
39 | int i = 1; | ||
40 | QChar c; | ||
41 | while ( c != '"' ) { | ||
42 | c = (*it)[pos + 10 + i]; | ||
43 | if ( c != '"' ) fname += c; | ||
44 | i++; | ||
45 | } | ||
46 | } | ||
47 | pos = (*it).find( "LastName=\"" ); | ||
48 | QString lname; | ||
49 | if ( pos != -1 ) { | ||
50 | int i = 1; | ||
51 | QChar c; | ||
52 | while ( c != '"' ) { | ||
53 | c = (*it)[pos + 9 + i]; | ||
54 | if ( c != '"' ) lname += c; | ||
55 | i++; | ||
56 | } | ||
57 | } | ||
58 | pos = (*it).find( "DefaultEmail=\"" ); | ||
59 | QString email; | ||
60 | if ( pos != -1 ) { | ||
61 | int i = 1; | ||
62 | QChar c; | ||
63 | while ( c != '"' ) { | ||
64 | c = (*it)[pos + 13 + i]; | ||
65 | if ( c != '"' ) email += c; | ||
66 | i++; | ||
67 | } | ||
68 | } | ||
69 | QString tname, temail; | ||
70 | if ( !fname.isEmpty() ) { | ||
71 | tname += fname; | ||
72 | } | ||
73 | if ( !lname.isEmpty() ) { | ||
74 | tname += fname.isEmpty() ? lname : (" " + lname); | ||
75 | } | ||
76 | if ( !email.isEmpty() ) { | ||
77 | temail += tname.isEmpty() ? email : (" <" + email + ">"); | ||
78 | } | ||
79 | if ( !email.isEmpty() ) { | ||
80 | addressList->insertItem( tname + temail ); | ||
81 | } | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | if ( addressList->count() <= 0 ) { | ||
86 | addressList->insertItem( | ||
87 | tr( "There are no entries in the addressbook." ) ); | ||
88 | addressList->setEnabled( false ); | ||
89 | okButton->setEnabled( false ); | ||
90 | } | ||
91 | } | ||
92 | |||
93 | void AddressPicker::accept() | ||
94 | { | ||
95 | QListBoxItem *item = addressList->firstItem(); | ||
96 | QString names; | ||
97 | |||
98 | while ( item ) { | ||
99 | if ( item->selected() ) | ||
100 | names += item->text() + ", "; | ||
101 | item = item->next(); | ||
102 | } | ||
103 | names.replace( names.length() - 2, 2, "" ); | ||
104 | |||
105 | if ( names.isEmpty() ) { | ||
106 | QMessageBox::information(this, tr("Error"), tr("<p>You have to select" | ||
107 | " at least one address entry.</p>"), tr("Ok")); | ||
108 | return; | ||
109 | } | ||
110 | |||
111 | selectedNames = names; | ||
112 | QDialog::accept(); | ||
113 | } | ||
114 | |||
115 | QString AddressPicker::getNames() | ||
116 | { | ||
117 | QString names = 0; | ||
118 | |||
119 | AddressPicker picker(0, 0, true); | ||
120 | picker.showMaximized(); | ||
121 | picker.show(); | ||
122 | |||
123 | int ret = picker.exec(); | ||
124 | if ( QDialog::Accepted == ret ) { | ||
125 | return picker.selectedNames; | ||
126 | } | ||
127 | |||
128 | return 0; | ||
129 | } | ||
130 | |||
diff --git a/noncore/net/mail/addresspickerui.ui b/noncore/net/mail/addresspickerui.ui new file mode 100644 index 0000000..2e37eac --- a/dev/null +++ b/noncore/net/mail/addresspickerui.ui | |||
@@ -0,0 +1,86 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>AddressPickerUI</class> | ||
3 | <widget> | ||
4 | <class>QDialog</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>AddressPickerUI</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>282</width> | ||
15 | <height>320</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Address Picker</string> | ||
21 | </property> | ||
22 | <property> | ||
23 | <name>layoutMargin</name> | ||
24 | </property> | ||
25 | <property> | ||
26 | <name>layoutSpacing</name> | ||
27 | </property> | ||
28 | <grid> | ||
29 | <property stdset="1"> | ||
30 | <name>margin</name> | ||
31 | <number>4</number> | ||
32 | </property> | ||
33 | <property stdset="1"> | ||
34 | <name>spacing</name> | ||
35 | <number>3</number> | ||
36 | </property> | ||
37 | <widget row="0" column="0" rowspan="1" colspan="2" > | ||
38 | <class>QListBox</class> | ||
39 | <property stdset="1"> | ||
40 | <name>name</name> | ||
41 | <cstring>addressList</cstring> | ||
42 | </property> | ||
43 | <property stdset="1"> | ||
44 | <name>selectionMode</name> | ||
45 | <enum>Multi</enum> | ||
46 | </property> | ||
47 | </widget> | ||
48 | <widget row="1" column="0" > | ||
49 | <class>QPushButton</class> | ||
50 | <property stdset="1"> | ||
51 | <name>name</name> | ||
52 | <cstring>okButton</cstring> | ||
53 | </property> | ||
54 | <property stdset="1"> | ||
55 | <name>minimumSize</name> | ||
56 | <size> | ||
57 | <width>10</width> | ||
58 | <height>0</height> | ||
59 | </size> | ||
60 | </property> | ||
61 | <property stdset="1"> | ||
62 | <name>text</name> | ||
63 | <string>Ok</string> | ||
64 | </property> | ||
65 | </widget> | ||
66 | <widget row="1" column="1" > | ||
67 | <class>QPushButton</class> | ||
68 | <property stdset="1"> | ||
69 | <name>name</name> | ||
70 | <cstring>cancelButton</cstring> | ||
71 | </property> | ||
72 | <property stdset="1"> | ||
73 | <name>minimumSize</name> | ||
74 | <size> | ||
75 | <width>10</width> | ||
76 | <height>0</height> | ||
77 | </size> | ||
78 | </property> | ||
79 | <property stdset="1"> | ||
80 | <name>text</name> | ||
81 | <string>Cancel</string> | ||
82 | </property> | ||
83 | </widget> | ||
84 | </grid> | ||
85 | </widget> | ||
86 | </UI> | ||
diff --git a/noncore/net/mail/composemail.cpp b/noncore/net/mail/composemail.cpp new file mode 100644 index 0000000..a17ccb3 --- a/dev/null +++ b/noncore/net/mail/composemail.cpp | |||
@@ -0,0 +1,180 @@ | |||
1 | #include <qt.h> | ||
2 | #include <qcombobox.h> | ||
3 | #include <qmessagebox.h> | ||
4 | #include <qlistview.h> | ||
5 | #include <qtabwidget.h> | ||
6 | #include <qmultilineedit.h> | ||
7 | #include <qregexp.h> | ||
8 | |||
9 | #include <opie/ofiledialog.h> | ||
10 | #include <qpe/resource.h> | ||
11 | |||
12 | #include "composemail.h" | ||
13 | #include "mailwrapper.h" | ||
14 | |||
15 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) | ||
16 | : ComposeMailUI( parent, name, modal, flags ) | ||
17 | { | ||
18 | settings = s; | ||
19 | |||
20 | attList->addColumn( tr( "Name" ) ); | ||
21 | attList->addColumn( tr( "Size" ) ); | ||
22 | |||
23 | QList<Account> accounts = settings->getAccounts(); | ||
24 | Account *it; | ||
25 | for ( it = accounts.first(); it; it = accounts.next() ) { | ||
26 | if ( it->getType().compare( "SMTP" ) == 0 ) { | ||
27 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); | ||
28 | fromBox->insertItem( smtp->getMail() ); | ||
29 | smtpAccounts.append( smtp ); | ||
30 | } | ||
31 | } | ||
32 | |||
33 | if ( smtpAccounts.count() > 0 ) { | ||
34 | fillValues( fromBox->currentItem() ); | ||
35 | } else { | ||
36 | QMessageBox::information( this, tr( "Problem" ), | ||
37 | tr( "<p>Please create an SMTP account first.</p>" ), | ||
38 | tr( "Ok" ) ); | ||
39 | } | ||
40 | |||
41 | connect( fromBox, SIGNAL( activated( int ) ), SLOT( fillValues( int ) ) ); | ||
42 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); | ||
43 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); | ||
44 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); | ||
45 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); | ||
46 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); | ||
47 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); | ||
48 | } | ||
49 | |||
50 | void ComposeMail::pickAddress( QLineEdit *line ) | ||
51 | { | ||
52 | QString names = AddressPicker::getNames(); | ||
53 | if ( line->text().isEmpty() ) { | ||
54 | line->setText( names ); | ||
55 | } else if ( !names.isEmpty() ) { | ||
56 | line->setText( line->text() + ", " + names ); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | void ComposeMail::pickAddressTo() | ||
61 | { | ||
62 | pickAddress( toLine ); | ||
63 | } | ||
64 | |||
65 | void ComposeMail::pickAddressCC() | ||
66 | { | ||
67 | pickAddress( ccLine ); | ||
68 | } | ||
69 | |||
70 | void ComposeMail::pickAddressBCC() | ||
71 | { | ||
72 | pickAddress( bccLine ); | ||
73 | } | ||
74 | |||
75 | void ComposeMail::pickAddressReply() | ||
76 | { | ||
77 | pickAddress( replyLine ); | ||
78 | } | ||
79 | |||
80 | void ComposeMail::fillValues( int current ) | ||
81 | { | ||
82 | SMTPaccount *smtp = smtpAccounts.at( current ); | ||
83 | |||
84 | ccLine->clear(); | ||
85 | if ( smtp->getUseCC() ) { | ||
86 | ccLine->setText( smtp->getCC() ); | ||
87 | } | ||
88 | bccLine->clear(); | ||
89 | if ( smtp->getUseBCC() ) { | ||
90 | bccLine->setText( smtp->getBCC() ); | ||
91 | } | ||
92 | replyLine->clear(); | ||
93 | if ( smtp->getUseReply() ) { | ||
94 | replyLine->setText( smtp->getReply() ); | ||
95 | } | ||
96 | |||
97 | sigMultiLine->setText( smtp->getSignature() ); | ||
98 | } | ||
99 | |||
100 | void ComposeMail::slotAdjustColumns() | ||
101 | { | ||
102 | int currPage = tabWidget->currentPageIndex(); | ||
103 | |||
104 | tabWidget->showPage( attachTab ); | ||
105 | attList->setColumnWidth( 0, attList->visibleWidth() - 80 ); | ||
106 | attList->setColumnWidth( 1, 80 ); | ||
107 | |||
108 | tabWidget->setCurrentPage( currPage ); | ||
109 | } | ||
110 | |||
111 | void ComposeMail::addAttachment() | ||
112 | { | ||
113 | DocLnk lnk = OFileDialog::getOpenFileName( 1, "/" ); | ||
114 | if ( !lnk.name().isEmpty() ) { | ||
115 | Attachment *att = new Attachment( lnk ); | ||
116 | (void) new AttachViewItem( attList, att ); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | void ComposeMail::removeAttachment() | ||
121 | { | ||
122 | if ( !attList->currentItem() ) { | ||
123 | QMessageBox::information( this, tr( "Error" ), | ||
124 | tr( "<p>Please select a File.</p>" ), | ||
125 | tr( "Ok" ) ); | ||
126 | } else { | ||
127 | attList->takeItem( attList->currentItem() ); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | void ComposeMail::accept() | ||
132 | { | ||
133 | qDebug( "Sending Mail with " + | ||
134 | smtpAccounts.at( fromBox->currentItem() )->getAccountName() ); | ||
135 | Mail *mail = new Mail(); | ||
136 | SMTPaccount *smtp = smtpAccounts.at( fromBox->currentItem() ); | ||
137 | mail->setMail( smtp->getMail() ); | ||
138 | mail->setName( smtp->getName() ); | ||
139 | |||
140 | if ( !toLine->text().isEmpty() ) { | ||
141 | mail->setTo( toLine->text() ); | ||
142 | } else { | ||
143 | qDebug( "No Reciever spezified -> returning" ); | ||
144 | return; | ||
145 | } | ||
146 | |||
147 | mail->setCC( ccLine->text() ); | ||
148 | mail->setBCC( bccLine->text() ); | ||
149 | mail->setReply( replyLine->text() ); | ||
150 | mail->setSubject( subjectLine->text() ); | ||
151 | QString txt = message->text(); | ||
152 | if ( !sigMultiLine->text().isEmpty() ) { | ||
153 | txt.append( "\n--\n" ); | ||
154 | txt.append( sigMultiLine->text() ); | ||
155 | } | ||
156 | mail->setMessage( txt ); | ||
157 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); | ||
158 | while ( it != NULL ) { | ||
159 | mail->addAttachment( it->getAttachment() ); | ||
160 | it = (AttachViewItem *) it->itemBelow(); | ||
161 | } | ||
162 | |||
163 | MailWrapper wrapper( settings ); | ||
164 | wrapper.sendMail( *mail ); | ||
165 | |||
166 | QDialog::accept(); | ||
167 | } | ||
168 | |||
169 | AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) | ||
170 | : QListViewItem( parent ) | ||
171 | { | ||
172 | attachment = att; | ||
173 | qDebug( att->getMimeType() ); | ||
174 | setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ? | ||
175 | Resource::loadPixmap( "UnknownDocument-14" ) : | ||
176 | attachment->getDocLnk().pixmap() ); | ||
177 | setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); | ||
178 | setText( 1, QString::number( att->getSize() ) ); | ||
179 | } | ||
180 | |||
diff --git a/noncore/net/mail/composemail.h b/noncore/net/mail/composemail.h new file mode 100644 index 0000000..c7ae22a --- a/dev/null +++ b/noncore/net/mail/composemail.h | |||
@@ -0,0 +1,68 @@ | |||
1 | #ifndef COMPOSEMAIL_H | ||
2 | #define COMPOSEMAIL_H | ||
3 | |||
4 | #include <qlineedit.h> | ||
5 | #include <qlistview.h> | ||
6 | |||
7 | #include "composemailui.h" | ||
8 | #include "addresspickerui.h" | ||
9 | #include "settings.h" | ||
10 | #include "mailwrapper.h" | ||
11 | |||
12 | |||
13 | class AddressPicker : public AddressPickerUI | ||
14 | { | ||
15 | Q_OBJECT | ||
16 | |||
17 | public: | ||
18 | AddressPicker( QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags flags = 0 ); | ||
19 | static QString getNames(); | ||
20 | |||
21 | protected: | ||
22 | QString selectedNames; | ||
23 | void accept(); | ||
24 | |||
25 | }; | ||
26 | |||
27 | |||
28 | class ComposeMail : public ComposeMailUI | ||
29 | { | ||
30 | Q_OBJECT | ||
31 | |||
32 | public: | ||
33 | ComposeMail( Settings *s, QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags flags = 0 ); | ||
34 | |||
35 | public slots: | ||
36 | void slotAdjustColumns(); | ||
37 | |||
38 | protected slots: | ||
39 | void accept(); | ||
40 | |||
41 | private slots: | ||
42 | void fillValues( int current ); | ||
43 | void pickAddress( QLineEdit *line ); | ||
44 | void pickAddressTo(); | ||
45 | void pickAddressCC(); | ||
46 | void pickAddressBCC(); | ||
47 | void pickAddressReply(); | ||
48 | void addAttachment(); | ||
49 | void removeAttachment(); | ||
50 | |||
51 | private: | ||
52 | Settings *settings; | ||
53 | QList<SMTPaccount> smtpAccounts; | ||
54 | |||
55 | }; | ||
56 | |||
57 | class AttachViewItem : public QListViewItem | ||
58 | { | ||
59 | public: | ||
60 | AttachViewItem( QListView *parent, Attachment *att ); | ||
61 | Attachment *getAttachment() { return attachment; } | ||
62 | |||
63 | private: | ||
64 | Attachment *attachment; | ||
65 | |||
66 | }; | ||
67 | |||
68 | #endif | ||
diff --git a/noncore/net/mail/composemailui.ui b/noncore/net/mail/composemailui.ui new file mode 100644 index 0000000..9f5feb9 --- a/dev/null +++ b/noncore/net/mail/composemailui.ui | |||
@@ -0,0 +1,328 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>ComposeMailUI</class> | ||
3 | <widget> | ||
4 | <class>QDialog</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>ComposeMailUI</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>264</width> | ||
15 | <height>360</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Compose Message</string> | ||
21 | </property> | ||
22 | <property> | ||
23 | <name>layoutMargin</name> | ||
24 | </property> | ||
25 | <property> | ||
26 | <name>layoutSpacing</name> | ||
27 | </property> | ||
28 | <vbox> | ||
29 | <property stdset="1"> | ||
30 | <name>margin</name> | ||
31 | <number>0</number> | ||
32 | </property> | ||
33 | <property stdset="1"> | ||
34 | <name>spacing</name> | ||
35 | <number>0</number> | ||
36 | </property> | ||
37 | <widget> | ||
38 | <class>QTabWidget</class> | ||
39 | <property stdset="1"> | ||
40 | <name>name</name> | ||
41 | <cstring>tabWidget</cstring> | ||
42 | </property> | ||
43 | <property> | ||
44 | <name>layoutMargin</name> | ||
45 | </property> | ||
46 | <property> | ||
47 | <name>layoutSpacing</name> | ||
48 | </property> | ||
49 | <widget> | ||
50 | <class>QWidget</class> | ||
51 | <property stdset="1"> | ||
52 | <name>name</name> | ||
53 | <cstring>mailTab</cstring> | ||
54 | </property> | ||
55 | <attribute> | ||
56 | <name>title</name> | ||
57 | <string>Mail</string> | ||
58 | </attribute> | ||
59 | <grid> | ||
60 | <property stdset="1"> | ||
61 | <name>margin</name> | ||
62 | <number>4</number> | ||
63 | </property> | ||
64 | <property stdset="1"> | ||
65 | <name>spacing</name> | ||
66 | <number>3</number> | ||
67 | </property> | ||
68 | <widget row="2" column="1" > | ||
69 | <class>QLineEdit</class> | ||
70 | <property stdset="1"> | ||
71 | <name>name</name> | ||
72 | <cstring>subjectLine</cstring> | ||
73 | </property> | ||
74 | </widget> | ||
75 | <widget row="3" column="0" rowspan="1" colspan="2" > | ||
76 | <class>QMultiLineEdit</class> | ||
77 | <property stdset="1"> | ||
78 | <name>name</name> | ||
79 | <cstring>message</cstring> | ||
80 | </property> | ||
81 | </widget> | ||
82 | <widget row="2" column="0" > | ||
83 | <class>QLabel</class> | ||
84 | <property stdset="1"> | ||
85 | <name>name</name> | ||
86 | <cstring>subjectLabel</cstring> | ||
87 | </property> | ||
88 | <property stdset="1"> | ||
89 | <name>text</name> | ||
90 | <string>Subject</string> | ||
91 | </property> | ||
92 | </widget> | ||
93 | <widget row="0" column="0" > | ||
94 | <class>QLabel</class> | ||
95 | <property stdset="1"> | ||
96 | <name>name</name> | ||
97 | <cstring>fromLabel</cstring> | ||
98 | </property> | ||
99 | <property stdset="1"> | ||
100 | <name>text</name> | ||
101 | <string>From</string> | ||
102 | </property> | ||
103 | </widget> | ||
104 | <widget row="1" column="1" > | ||
105 | <class>QLineEdit</class> | ||
106 | <property stdset="1"> | ||
107 | <name>name</name> | ||
108 | <cstring>toLine</cstring> | ||
109 | </property> | ||
110 | </widget> | ||
111 | <widget row="0" column="1" > | ||
112 | <class>QComboBox</class> | ||
113 | <property stdset="1"> | ||
114 | <name>name</name> | ||
115 | <cstring>fromBox</cstring> | ||
116 | </property> | ||
117 | </widget> | ||
118 | <widget row="1" column="0" > | ||
119 | <class>QPushButton</class> | ||
120 | <property stdset="1"> | ||
121 | <name>name</name> | ||
122 | <cstring>toButton</cstring> | ||
123 | </property> | ||
124 | <property stdset="1"> | ||
125 | <name>text</name> | ||
126 | <string>To</string> | ||
127 | </property> | ||
128 | </widget> | ||
129 | </grid> | ||
130 | </widget> | ||
131 | <widget> | ||
132 | <class>QWidget</class> | ||
133 | <property stdset="1"> | ||
134 | <name>name</name> | ||
135 | <cstring>optionsTab</cstring> | ||
136 | </property> | ||
137 | <attribute> | ||
138 | <name>title</name> | ||
139 | <string>Options</string> | ||
140 | </attribute> | ||
141 | <grid> | ||
142 | <property stdset="1"> | ||
143 | <name>margin</name> | ||
144 | <number>4</number> | ||
145 | </property> | ||
146 | <property stdset="1"> | ||
147 | <name>spacing</name> | ||
148 | <number>3</number> | ||
149 | </property> | ||
150 | <widget row="3" column="0" > | ||
151 | <class>QPushButton</class> | ||
152 | <property stdset="1"> | ||
153 | <name>name</name> | ||
154 | <cstring>replyButton</cstring> | ||
155 | </property> | ||
156 | <property stdset="1"> | ||
157 | <name>text</name> | ||
158 | <string>Reply-To</string> | ||
159 | </property> | ||
160 | </widget> | ||
161 | <widget row="2" column="0" > | ||
162 | <class>QPushButton</class> | ||
163 | <property stdset="1"> | ||
164 | <name>name</name> | ||
165 | <cstring>bccButton</cstring> | ||
166 | </property> | ||
167 | <property stdset="1"> | ||
168 | <name>text</name> | ||
169 | <string>BCC</string> | ||
170 | </property> | ||
171 | </widget> | ||
172 | <widget row="1" column="1" > | ||
173 | <class>QLineEdit</class> | ||
174 | <property stdset="1"> | ||
175 | <name>name</name> | ||
176 | <cstring>ccLine</cstring> | ||
177 | </property> | ||
178 | </widget> | ||
179 | <widget row="2" column="1" > | ||
180 | <class>QLineEdit</class> | ||
181 | <property stdset="1"> | ||
182 | <name>name</name> | ||
183 | <cstring>bccLine</cstring> | ||
184 | </property> | ||
185 | </widget> | ||
186 | <widget row="3" column="1" > | ||
187 | <class>QLineEdit</class> | ||
188 | <property stdset="1"> | ||
189 | <name>name</name> | ||
190 | <cstring>replyLine</cstring> | ||
191 | </property> | ||
192 | </widget> | ||
193 | <widget row="6" column="0" rowspan="1" colspan="2" > | ||
194 | <class>QMultiLineEdit</class> | ||
195 | <property stdset="1"> | ||
196 | <name>name</name> | ||
197 | <cstring>sigMultiLine</cstring> | ||
198 | </property> | ||
199 | </widget> | ||
200 | <widget row="5" column="0" > | ||
201 | <class>QLabel</class> | ||
202 | <property stdset="1"> | ||
203 | <name>name</name> | ||
204 | <cstring>sigLabel</cstring> | ||
205 | </property> | ||
206 | <property stdset="1"> | ||
207 | <name>text</name> | ||
208 | <string>Signature</string> | ||
209 | </property> | ||
210 | </widget> | ||
211 | <spacer row="4" column="0" > | ||
212 | <property> | ||
213 | <name>name</name> | ||
214 | <cstring>Spacer3</cstring> | ||
215 | </property> | ||
216 | <property stdset="1"> | ||
217 | <name>orientation</name> | ||
218 | <enum>Vertical</enum> | ||
219 | </property> | ||
220 | <property stdset="1"> | ||
221 | <name>sizeType</name> | ||
222 | <enum>Expanding</enum> | ||
223 | </property> | ||
224 | <property> | ||
225 | <name>sizeHint</name> | ||
226 | <size> | ||
227 | <width>20</width> | ||
228 | <height>20</height> | ||
229 | </size> | ||
230 | </property> | ||
231 | </spacer> | ||
232 | <widget row="1" column="0" > | ||
233 | <class>QPushButton</class> | ||
234 | <property stdset="1"> | ||
235 | <name>name</name> | ||
236 | <cstring>ccButton</cstring> | ||
237 | </property> | ||
238 | <property stdset="1"> | ||
239 | <name>text</name> | ||
240 | <string>CC</string> | ||
241 | </property> | ||
242 | </widget> | ||
243 | </grid> | ||
244 | </widget> | ||
245 | <widget> | ||
246 | <class>QWidget</class> | ||
247 | <property stdset="1"> | ||
248 | <name>name</name> | ||
249 | <cstring>attachTab</cstring> | ||
250 | </property> | ||
251 | <attribute> | ||
252 | <name>title</name> | ||
253 | <string>Attachment</string> | ||
254 | </attribute> | ||
255 | <grid> | ||
256 | <property stdset="1"> | ||
257 | <name>margin</name> | ||
258 | <number>4</number> | ||
259 | </property> | ||
260 | <property stdset="1"> | ||
261 | <name>spacing</name> | ||
262 | <number>3</number> | ||
263 | </property> | ||
264 | <widget row="0" column="0" rowspan="1" colspan="3" > | ||
265 | <class>QListView</class> | ||
266 | <property stdset="1"> | ||
267 | <name>name</name> | ||
268 | <cstring>attList</cstring> | ||
269 | </property> | ||
270 | <property stdset="1"> | ||
271 | <name>selectionMode</name> | ||
272 | <enum>Single</enum> | ||
273 | </property> | ||
274 | <property stdset="1"> | ||
275 | <name>allColumnsShowFocus</name> | ||
276 | <bool>true</bool> | ||
277 | </property> | ||
278 | <property stdset="1"> | ||
279 | <name>showSortIndicator</name> | ||
280 | <bool>true</bool> | ||
281 | </property> | ||
282 | </widget> | ||
283 | <widget row="1" column="2" > | ||
284 | <class>QPushButton</class> | ||
285 | <property stdset="1"> | ||
286 | <name>name</name> | ||
287 | <cstring>deleteButton</cstring> | ||
288 | </property> | ||
289 | <property stdset="1"> | ||
290 | <name>text</name> | ||
291 | <string>Delete File</string> | ||
292 | </property> | ||
293 | </widget> | ||
294 | <widget row="1" column="0" > | ||
295 | <class>QPushButton</class> | ||
296 | <property stdset="1"> | ||
297 | <name>name</name> | ||
298 | <cstring>addButton</cstring> | ||
299 | </property> | ||
300 | <property stdset="1"> | ||
301 | <name>text</name> | ||
302 | <string>Add File</string> | ||
303 | </property> | ||
304 | </widget> | ||
305 | </grid> | ||
306 | </widget> | ||
307 | </widget> | ||
308 | </vbox> | ||
309 | </widget> | ||
310 | <tabstops> | ||
311 | <tabstop>fromBox</tabstop> | ||
312 | <tabstop>toButton</tabstop> | ||
313 | <tabstop>toLine</tabstop> | ||
314 | <tabstop>subjectLine</tabstop> | ||
315 | <tabstop>message</tabstop> | ||
316 | <tabstop>tabWidget</tabstop> | ||
317 | <tabstop>ccButton</tabstop> | ||
318 | <tabstop>ccLine</tabstop> | ||
319 | <tabstop>bccButton</tabstop> | ||
320 | <tabstop>bccLine</tabstop> | ||
321 | <tabstop>replyButton</tabstop> | ||
322 | <tabstop>replyLine</tabstop> | ||
323 | <tabstop>sigMultiLine</tabstop> | ||
324 | <tabstop>attList</tabstop> | ||
325 | <tabstop>addButton</tabstop> | ||
326 | <tabstop>deleteButton</tabstop> | ||
327 | </tabstops> | ||
328 | </UI> | ||
diff --git a/noncore/net/mail/defines.h b/noncore/net/mail/defines.h new file mode 100644 index 0000000..853454d --- a/dev/null +++ b/noncore/net/mail/defines.h | |||
@@ -0,0 +1,36 @@ | |||
1 | #ifndef DEFINE_CONSTANTS_H | ||
2 | #define DEFINE_CONSTANTS_H | ||
3 | |||
4 | #include <qpe/resource.h> | ||
5 | |||
6 | #define USER_AGENT "OpieMail v0.0.1-alpha" | ||
7 | |||
8 | #define PIC_COMPOSEMAIL "opiemail/composemail" | ||
9 | #define PIC_SENDQUEUED "opiemail/sendqueued" | ||
10 | #define PIC_SHOWFOLDERS "opiemail/showfolders" | ||
11 | #define PIC_SEARCHMAILS "opiemail/searchmails" | ||
12 | #define PIC_EDITSETTINGS "opiemail/editsettings" | ||
13 | #define PIC_EDITACCOUNTS "opiemail/editaccounts" | ||
14 | #define PIC_SYNC "opiemail/sync" | ||
15 | #define PIC_IMAPFOLDER "opiemail/imapfolder" | ||
16 | |||
17 | #define ICON_COMPOSEMAIL QIconSet( Resource::loadPixmap( PIC_COMPOSEMAIL ) ) | ||
18 | #define ICON_SENDQUEUED QIconSet( Resource::loadPixmap( PIC_SENDQUEUED ) ) | ||
19 | #define ICON_SHOWFOLDERS QIconSet( Resource::loadPixmap( PIC_SHOWFOLDERS ) ) | ||
20 | #define ICON_SEARCHMAILS QIconSet( Resource::loadPixmap( PIC_SEARCHMAILS ) ) | ||
21 | #define ICON_EDITSETTINGS QIconSet( Resource::loadPixmap( PIC_EDITSETTINGS ) ) | ||
22 | #define ICON_EDITACCOUNTS QIconSet( Resource::loadPixmap( PIC_EDITACCOUNTS ) ) | ||
23 | #define ICON_SYNC QIconSet( Resource::loadPixmap( PIC_SYNC ) ) | ||
24 | |||
25 | #define PIXMAP_IMAPFOLDER QPixmap( Resource::loadPixmap( PIC_IMAPFOLDER ) ) | ||
26 | |||
27 | #define IMAP_PORT "143" | ||
28 | #define IMAP_SSL_PORT "993" | ||
29 | #define SMTP_PORT "25" | ||
30 | #define SMTP_SSL_PORT "465" | ||
31 | #define POP3_PORT "110" | ||
32 | #define POP3_SSL_PORT "995" | ||
33 | #define NNTP_PORT "119" | ||
34 | #define NNTP_SSL_PORT "563" | ||
35 | |||
36 | #endif | ||
diff --git a/noncore/net/mail/editaccounts.cpp b/noncore/net/mail/editaccounts.cpp new file mode 100644 index 0000000..7e2dd24 --- a/dev/null +++ b/noncore/net/mail/editaccounts.cpp | |||
@@ -0,0 +1,471 @@ | |||
1 | #include <qt.h> | ||
2 | #include <qtabwidget.h> | ||
3 | |||
4 | #include "defines.h" | ||
5 | #include "editaccounts.h" | ||
6 | |||
7 | AccountListItem::AccountListItem( QListView *parent, Account *a) | ||
8 | : QListViewItem( parent ) | ||
9 | { | ||
10 | account = a; | ||
11 | setText( 0, account->getAccountName() ); | ||
12 | setText( 1, account->getType() ); | ||
13 | } | ||
14 | |||
15 | EditAccounts::EditAccounts( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) | ||
16 | : EditAccountsUI( parent, name, modal, flags ) | ||
17 | { | ||
18 | qDebug( "New Account Configuration Widget" ); | ||
19 | settings = s; | ||
20 | |||
21 | mailList->addColumn( tr( "Account" ) ); | ||
22 | mailList->addColumn( tr( "Type" ) ); | ||
23 | |||
24 | newsList->addColumn( tr( "Account" ) ); | ||
25 | |||
26 | connect( newMail, SIGNAL( clicked() ), SLOT( slotNewMail() ) ); | ||
27 | connect( editMail, SIGNAL( clicked() ), SLOT( slotEditMail() ) ); | ||
28 | connect( deleteMail, SIGNAL( clicked() ), SLOT( slotDeleteMail() ) ); | ||
29 | connect( newNews, SIGNAL( clicked() ), SLOT( slotNewNews() ) ); | ||
30 | connect( editNews, SIGNAL( clicked() ), SLOT( slotEditNews() ) ); | ||
31 | connect( deleteNews, SIGNAL( clicked() ), SLOT( slotDeleteNews() ) ); | ||
32 | |||
33 | slotFillLists(); | ||
34 | } | ||
35 | |||
36 | void EditAccounts::slotFillLists() | ||
37 | { | ||
38 | mailList->clear(); | ||
39 | newsList->clear(); | ||
40 | |||
41 | QList<Account> accounts = settings->getAccounts(); | ||
42 | Account *it; | ||
43 | for ( it = accounts.first(); it; it = accounts.next() ) { | ||
44 | if ( it->getType().compare( "NNTP" ) == 0 ) { | ||
45 | (void) new AccountListItem( newsList, it ); | ||
46 | } else { | ||
47 | (void) new AccountListItem( mailList, it ); | ||
48 | } | ||
49 | } | ||
50 | } | ||
51 | |||
52 | void EditAccounts::slotNewMail() | ||
53 | { | ||
54 | qDebug( "New Mail Account" ); | ||
55 | QString *selection = new QString(); | ||
56 | SelectMailType selType( selection, this, 0, true ); | ||
57 | selType.show(); | ||
58 | if ( QDialog::Accepted == selType.exec() ) { | ||
59 | slotNewAccount( *selection ); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | void EditAccounts::slotNewAccount( const QString &type ) | ||
64 | { | ||
65 | if ( type.compare( "IMAP" ) == 0 ) { | ||
66 | qDebug( "-> config IMAP" ); | ||
67 | IMAPaccount *account = new IMAPaccount(); | ||
68 | IMAPconfig imap( account, this, 0, true ); | ||
69 | imap.showMaximized(); | ||
70 | if ( QDialog::Accepted == imap.exec() ) { | ||
71 | settings->addAccount( account ); | ||
72 | account->save(); | ||
73 | slotFillLists(); | ||
74 | } else { | ||
75 | account->remove(); | ||
76 | } | ||
77 | } else if ( type.compare( "POP3" ) == 0 ) { | ||
78 | qDebug( "-> config POP3" ); | ||
79 | POP3account *account = new POP3account(); | ||
80 | POP3config pop3( account, this, 0, true ); | ||
81 | pop3.showMaximized(); | ||
82 | if ( QDialog::Accepted == pop3.exec() ) { | ||
83 | settings->addAccount( account ); | ||
84 | account->save(); | ||
85 | slotFillLists(); | ||
86 | } else { | ||
87 | account->remove(); | ||
88 | } | ||
89 | } else if ( type.compare( "SMTP" ) == 0 ) { | ||
90 | qDebug( "-> config SMTP" ); | ||
91 | SMTPaccount *account = new SMTPaccount(); | ||
92 | SMTPconfig smtp( account, this, 0, true ); | ||
93 | smtp.showMaximized(); | ||
94 | if ( QDialog::Accepted == smtp.exec() ) { | ||
95 | settings->addAccount( account ); | ||
96 | account->save(); | ||
97 | slotFillLists(); | ||
98 | } else { | ||
99 | account->remove(); | ||
100 | } | ||
101 | } else if ( type.compare( "NNTP" ) == 0 ) { | ||
102 | qDebug( "-> config NNTP" ); | ||
103 | NNTPaccount *account = new NNTPaccount(); | ||
104 | NNTPconfig nntp( account, this, 0, true ); | ||
105 | nntp.showMaximized(); | ||
106 | if ( QDialog::Accepted == nntp.exec() ) { | ||
107 | settings->addAccount( account ); | ||
108 | account->save(); | ||
109 | slotFillLists(); | ||
110 | } else { | ||
111 | account->remove(); | ||
112 | } | ||
113 | } | ||
114 | } | ||
115 | |||
116 | void EditAccounts::slotEditAccount( Account *account ) | ||
117 | { | ||
118 | if ( account->getType().compare( "IMAP" ) == 0 ) { | ||
119 | IMAPaccount *imapAcc = static_cast<IMAPaccount *>(account); | ||
120 | IMAPconfig imap( imapAcc, this, 0, true ); | ||
121 | imap.showMaximized(); | ||
122 | if ( QDialog::Accepted == imap.exec() ) { | ||
123 | slotFillLists(); | ||
124 | } | ||
125 | } else if ( account->getType().compare( "POP3" ) == 0 ) { | ||
126 | POP3account *pop3Acc = static_cast<POP3account *>(account); | ||
127 | POP3config pop3( pop3Acc, this, 0, true ); | ||
128 | pop3.showMaximized(); | ||
129 | if ( QDialog::Accepted == pop3.exec() ) { | ||
130 | slotFillLists(); | ||
131 | } | ||
132 | } else if ( account->getType().compare( "SMTP" ) == 0 ) { | ||
133 | SMTPaccount *smtpAcc = static_cast<SMTPaccount *>(account); | ||
134 | SMTPconfig smtp( smtpAcc, this, 0, true ); | ||
135 | smtp.showMaximized(); | ||
136 | if ( QDialog::Accepted == smtp.exec() ) { | ||
137 | slotFillLists(); | ||
138 | } | ||
139 | } else if ( account->getType().compare( "NNTP" ) == 0 ) { | ||
140 | NNTPaccount *nntpAcc = static_cast<NNTPaccount *>(account); | ||
141 | NNTPconfig nntp( nntpAcc, this, 0, true ); | ||
142 | nntp.showMaximized(); | ||
143 | if ( QDialog::Accepted == nntp.exec() ) { | ||
144 | slotFillLists(); | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | |||
149 | void EditAccounts::slotDeleteAccount( Account *account ) | ||
150 | { | ||
151 | if ( QMessageBox::information( this, tr( "Question" ), | ||
152 | tr( "<p>Do you really want to delete the selected Account?</p>" ), | ||
153 | tr( "Yes" ), tr( "No" ) ) == 0 ) { | ||
154 | settings->delAccount( account ); | ||
155 | slotFillLists(); | ||
156 | } | ||
157 | } | ||
158 | |||
159 | void EditAccounts::slotEditMail() | ||
160 | { | ||
161 | qDebug( "Edit Mail Account" ); | ||
162 | if ( !mailList->currentItem() ) { | ||
163 | QMessageBox::information( this, tr( "Error" ), | ||
164 | tr( "<p>Please select an account.</p>" ), | ||
165 | tr( "Ok" ) ); | ||
166 | return; | ||
167 | } | ||
168 | |||
169 | Account *a = ((AccountListItem *) mailList->currentItem())->getAccount(); | ||
170 | slotEditAccount( a ); | ||
171 | } | ||
172 | |||
173 | void EditAccounts::slotDeleteMail() | ||
174 | { | ||
175 | if ( !mailList->currentItem() ) { | ||
176 | QMessageBox::information( this, tr( "Error" ), | ||
177 | tr( "<p>Please select an account.</p>" ), | ||
178 | tr( "Ok" ) ); | ||
179 | return; | ||
180 | } | ||
181 | |||
182 | Account *a = ((AccountListItem *) mailList->currentItem())->getAccount(); | ||
183 | slotDeleteAccount( a ); | ||
184 | } | ||
185 | |||
186 | void EditAccounts::slotNewNews() | ||
187 | { | ||
188 | qDebug( "New News Account" ); | ||
189 | slotNewAccount( "NNTP" ); | ||
190 | } | ||
191 | |||
192 | void EditAccounts::slotEditNews() | ||
193 | { | ||
194 | qDebug( "Edit News Account" ); | ||
195 | if ( !newsList->currentItem() ) { | ||
196 | QMessageBox::information( this, tr( "Error" ), | ||
197 | tr( "<p>Please select an account.</p>" ), | ||
198 | tr( "Ok" ) ); | ||
199 | return; | ||
200 | } | ||
201 | |||
202 | Account *a = ((AccountListItem *) newsList->currentItem())->getAccount(); | ||
203 | slotEditAccount( a ); | ||
204 | } | ||
205 | |||
206 | void EditAccounts::slotDeleteNews() | ||
207 | { | ||
208 | qDebug( "Delete News Account" ); | ||
209 | if ( !newsList->currentItem() ) { | ||
210 | QMessageBox::information( this, tr( "Error" ), | ||
211 | tr( "<p>Please select an account.</p>" ), | ||
212 | tr( "Ok" ) ); | ||
213 | return; | ||
214 | } | ||
215 | |||
216 | Account *a = ((AccountListItem *) newsList->currentItem())->getAccount(); | ||
217 | slotDeleteAccount( a ); | ||
218 | } | ||
219 | |||
220 | void EditAccounts::slotAdjustColumns() | ||
221 | { | ||
222 | int currPage = configTab->currentPageIndex(); | ||
223 | |||
224 | configTab->showPage( mailTab ); | ||
225 | mailList->setColumnWidth( 0, mailList->visibleWidth() - 50 ); | ||
226 | mailList->setColumnWidth( 1, 50 ); | ||
227 | |||
228 | configTab->showPage( newsTab ); | ||
229 | newsList->setColumnWidth( 0, newsList->visibleWidth() ); | ||
230 | |||
231 | configTab->setCurrentPage( currPage ); | ||
232 | } | ||
233 | |||
234 | void EditAccounts::accept() | ||
235 | { | ||
236 | settings->saveAccounts(); | ||
237 | |||
238 | QDialog::accept(); | ||
239 | } | ||
240 | |||
241 | /** | ||
242 | * SelectMailType | ||
243 | */ | ||
244 | |||
245 | SelectMailType::SelectMailType( QString *selection, QWidget *parent, const char *name, bool modal, WFlags flags ) | ||
246 | : SelectMailTypeUI( parent, name, modal, flags ) | ||
247 | { | ||
248 | selected = selection; | ||
249 | selected->replace( 0, selected->length(), typeBox->currentText() ); | ||
250 | connect( typeBox, SIGNAL( activated( const QString & ) ), SLOT( slotSelection( const QString & ) ) ); | ||
251 | } | ||
252 | |||
253 | void SelectMailType::slotSelection( const QString &sel ) | ||
254 | { | ||
255 | selected->replace( 0, selected->length(), sel ); | ||
256 | } | ||
257 | |||
258 | /** | ||
259 | * IMAPconfig | ||
260 | */ | ||
261 | |||
262 | IMAPconfig::IMAPconfig( IMAPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) | ||
263 | : IMAPconfigUI( parent, name, modal, flags ) | ||
264 | { | ||
265 | data = account; | ||
266 | |||
267 | fillValues(); | ||
268 | |||
269 | connect( sslBox, SIGNAL( toggled( bool ) ), SLOT( slotSSL( bool ) ) ); | ||
270 | } | ||
271 | |||
272 | void IMAPconfig::slotSSL( bool enabled ) | ||
273 | { | ||
274 | if ( enabled ) { | ||
275 | portLine->setText( IMAP_SSL_PORT ); | ||
276 | } else { | ||
277 | portLine->setText( IMAP_PORT ); | ||
278 | } | ||
279 | } | ||
280 | |||
281 | void IMAPconfig::fillValues() | ||
282 | { | ||
283 | accountLine->setText( data->getAccountName() ); | ||
284 | serverLine->setText( data->getServer() ); | ||
285 | portLine->setText( data->getPort() ); | ||
286 | sslBox->setChecked( data->getSSL() ); | ||
287 | userLine->setText( data->getUser() ); | ||
288 | passLine->setText( data->getPassword() ); | ||
289 | prefixLine->setText(data->getPrefix()); | ||
290 | } | ||
291 | |||
292 | void IMAPconfig::accept() | ||
293 | { | ||
294 | data->setAccountName( accountLine->text() ); | ||
295 | data->setServer( serverLine->text() ); | ||
296 | data->setPort( portLine->text() ); | ||
297 | data->setSSL( sslBox->isChecked() ); | ||
298 | data->setUser( userLine->text() ); | ||
299 | data->setPassword( passLine->text() ); | ||
300 | data->setPrefix(prefixLine->text()); | ||
301 | |||
302 | QDialog::accept(); | ||
303 | } | ||
304 | |||
305 | /** | ||
306 | * POP3config | ||
307 | */ | ||
308 | |||
309 | POP3config::POP3config( POP3account *account, QWidget *parent, const char *name, bool modal, WFlags flags ) | ||
310 | : POP3configUI( parent, name, modal, flags ) | ||
311 | { | ||
312 | data = account; | ||
313 | fillValues(); | ||
314 | |||
315 | connect( sslBox, SIGNAL( toggled( bool ) ), SLOT( slotSSL( bool ) ) ); | ||
316 | } | ||
317 | |||
318 | void POP3config::slotSSL( bool enabled ) | ||
319 | { | ||
320 | if ( enabled ) { | ||
321 | portLine->setText( POP3_SSL_PORT ); | ||
322 | } else { | ||
323 | portLine->setText( POP3_PORT ); | ||
324 | } | ||
325 | } | ||
326 | |||
327 | void POP3config::fillValues() | ||
328 | { | ||
329 | accountLine->setText( data->getAccountName() ); | ||
330 | serverLine->setText( data->getServer() ); | ||
331 | portLine->setText( data->getPort() ); | ||
332 | sslBox->setChecked( data->getSSL() ); | ||
333 | userLine->setText( data->getUser() ); | ||
334 | passLine->setText( data->getPassword() ); | ||
335 | } | ||
336 | |||
337 | void POP3config::accept() | ||
338 | { | ||
339 | data->setAccountName( accountLine->text() ); | ||
340 | data->setServer( serverLine->text() ); | ||
341 | data->setPort( portLine->text() ); | ||
342 | data->setSSL( sslBox->isChecked() ); | ||
343 | data->setUser( userLine->text() ); | ||
344 | data->setPassword( passLine->text() ); | ||
345 | |||
346 | QDialog::accept(); | ||
347 | } | ||
348 | |||
349 | /** | ||
350 | * SMTPconfig | ||
351 | */ | ||
352 | |||
353 | SMTPconfig::SMTPconfig( SMTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) | ||
354 | : SMTPconfigUI( parent, name, modal, flags ) | ||
355 | { | ||
356 | data = account; | ||
357 | |||
358 | connect( ccBox, SIGNAL( toggled( bool ) ), ccLine, SLOT( setEnabled( bool ) ) ); | ||
359 | connect( bccBox, SIGNAL( toggled( bool ) ), bccLine, SLOT( setEnabled( bool ) ) ); | ||
360 | connect( replyBox, SIGNAL( toggled( bool ) ), replyLine, SLOT( setEnabled( bool ) ) ); | ||
361 | connect( loginBox, SIGNAL( toggled( bool ) ), userLine, SLOT( setEnabled( bool ) ) ); | ||
362 | connect( loginBox, SIGNAL( toggled( bool ) ), passLine, SLOT( setEnabled( bool ) ) ); | ||
363 | |||
364 | fillValues(); | ||
365 | |||
366 | connect( sslBox, SIGNAL( toggled( bool ) ), SLOT( slotSSL( bool ) ) ); | ||
367 | } | ||
368 | |||
369 | void SMTPconfig::slotSSL( bool enabled ) | ||
370 | { | ||
371 | if ( enabled ) { | ||
372 | portLine->setText( SMTP_SSL_PORT ); | ||
373 | } else { | ||
374 | portLine->setText( SMTP_PORT ); | ||
375 | } | ||
376 | } | ||
377 | |||
378 | void SMTPconfig::fillValues() | ||
379 | { | ||
380 | accountLine->setText( data->getAccountName() ); | ||
381 | serverLine->setText( data->getServer() ); | ||
382 | portLine->setText( data->getPort() ); | ||
383 | sslBox->setChecked( data->getSSL() ); | ||
384 | loginBox->setChecked( data->getLogin() ); | ||
385 | userLine->setText( data->getUser() ); | ||
386 | passLine->setText( data->getPassword() ); | ||
387 | nameLine->setText( data->getName() ); | ||
388 | mailLine->setText( data->getMail() ); | ||
389 | orgLine->setText( data->getOrg() ); | ||
390 | ccBox->setChecked( data->getUseCC() ); | ||
391 | ccLine->setText( data->getCC() ); | ||
392 | bccBox->setChecked( data->getUseBCC() ); | ||
393 | bccLine->setText( data->getBCC() ); | ||
394 | replyBox->setChecked( data->getUseReply() ); | ||
395 | replyLine->setText( data->getReply() ); | ||
396 | sigMultiLine->setText( data->getSignature() ); | ||
397 | } | ||
398 | |||
399 | void SMTPconfig::accept() | ||
400 | { | ||
401 | data->setAccountName( accountLine->text() ); | ||
402 | data->setServer( serverLine->text() ); | ||
403 | data->setPort( portLine->text() ); | ||
404 | data->setSSL( sslBox->isChecked() ); | ||
405 | data->setLogin( loginBox->isChecked() ); | ||
406 | data->setUser( userLine->text() ); | ||
407 | data->setPassword( passLine->text() ); | ||
408 | data->setName( nameLine->text() ); | ||
409 | data->setMail( mailLine->text() ); | ||
410 | data->setOrg( orgLine->text() ); | ||
411 | data->setCC( ccLine->text() ); | ||
412 | data->setUseCC( ccBox->isChecked() ); | ||
413 | data->setBCC( bccLine->text() ); | ||
414 | data->setUseBCC( bccBox->isChecked() ); | ||
415 | data->setReply( replyLine->text() ); | ||
416 | data->setUseReply( replyBox->isChecked() ); | ||
417 | data->setSignature( sigMultiLine->text() ); | ||
418 | |||
419 | QDialog::accept(); | ||
420 | } | ||
421 | |||
422 | /** | ||
423 | * NNTPconfig | ||
424 | */ | ||
425 | |||
426 | NNTPconfig::NNTPconfig( NNTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) | ||
427 | : NNTPconfigUI( parent, name, modal, flags ) | ||
428 | { | ||
429 | data = account; | ||
430 | |||
431 | connect( loginBox, SIGNAL( toggled( bool ) ), userLine, SLOT( setEnabled( bool ) ) ); | ||
432 | connect( loginBox, SIGNAL( toggled( bool ) ), passLine, SLOT( setEnabled( bool ) ) ); | ||
433 | |||
434 | fillValues(); | ||
435 | |||
436 | connect( sslBox, SIGNAL( toggled( bool ) ), SLOT( slotSSL( bool ) ) ); | ||
437 | } | ||
438 | |||
439 | void NNTPconfig::slotSSL( bool enabled ) | ||
440 | { | ||
441 | if ( enabled ) { | ||
442 | portLine->setText( NNTP_SSL_PORT ); | ||
443 | } else { | ||
444 | portLine->setText( NNTP_PORT ); | ||
445 | } | ||
446 | } | ||
447 | |||
448 | void NNTPconfig::fillValues() | ||
449 | { | ||
450 | accountLine->setText( data->getAccountName() ); | ||
451 | serverLine->setText( data->getServer() ); | ||
452 | portLine->setText( data->getPort() ); | ||
453 | sslBox->setChecked( data->getSSL() ); | ||
454 | loginBox->setChecked( data->getLogin() ); | ||
455 | userLine->setText( data->getUser() ); | ||
456 | passLine->setText( data->getPassword() ); | ||
457 | } | ||
458 | |||
459 | void NNTPconfig::accept() | ||
460 | { | ||
461 | data->setAccountName( accountLine->text() ); | ||
462 | data->setServer( serverLine->text() ); | ||
463 | data->setPort( portLine->text() ); | ||
464 | data->setSSL( sslBox->isChecked() ); | ||
465 | data->setLogin( loginBox->isChecked() ); | ||
466 | data->setUser( userLine->text() ); | ||
467 | data->setPassword( passLine->text() ); | ||
468 | |||
469 | QDialog::accept(); | ||
470 | } | ||
471 | |||
diff --git a/noncore/net/mail/editaccounts.h b/noncore/net/mail/editaccounts.h new file mode 100644 index 0000000..10ed8b8 --- a/dev/null +++ b/noncore/net/mail/editaccounts.h | |||
@@ -0,0 +1,146 @@ | |||
1 | #ifndef EDITACCOUNTS_H | ||
2 | #define EDITACCOUNTS_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qlistview.h> | ||
6 | |||
7 | #include "editaccountsui.h" | ||
8 | #include "selectmailtypeui.h" | ||
9 | #include "imapconfigui.h" | ||
10 | #include "pop3configui.h" | ||
11 | #include "smtpconfigui.h" | ||
12 | #include "nntpconfigui.h" | ||
13 | #include "settings.h" | ||
14 | |||
15 | class AccountListItem : public QListViewItem | ||
16 | { | ||
17 | |||
18 | public: | ||
19 | AccountListItem( QListView *parent, Account *a); | ||
20 | Account *getAccount() { return account; } | ||
21 | |||
22 | private: | ||
23 | Account *account; | ||
24 | |||
25 | }; | ||
26 | |||
27 | class EditAccounts : public EditAccountsUI | ||
28 | { | ||
29 | Q_OBJECT | ||
30 | |||
31 | public: | ||
32 | EditAccounts( Settings *s, QWidget *parent = 0, const char *name = 0, bool modal = 0, WFlags flags = 0 ); | ||
33 | |||
34 | public slots: | ||
35 | void slotNewAccount( const QString &type ); | ||
36 | void slotEditAccount( Account *account ); | ||
37 | void slotDeleteAccount( Account * account ); | ||
38 | void slotAdjustColumns(); | ||
39 | |||
40 | protected slots: | ||
41 | void slotFillLists(); | ||
42 | void slotNewMail(); | ||
43 | void slotEditMail(); | ||
44 | void slotDeleteMail(); | ||
45 | void slotNewNews(); | ||
46 | void slotEditNews(); | ||
47 | void slotDeleteNews(); | ||
48 | void accept(); | ||
49 | |||
50 | private: | ||
51 | Settings *settings; | ||
52 | |||
53 | }; | ||
54 | |||
55 | class SelectMailType : public SelectMailTypeUI | ||
56 | { | ||
57 | Q_OBJECT | ||
58 | |||
59 | public: | ||
60 | SelectMailType( QString *selection = 0, QWidget *parent = 0, const char *name = 0, bool modal = 0, WFlags flags = 0 ); | ||
61 | |||
62 | private slots: | ||
63 | void slotSelection( const QString &sel ); | ||
64 | |||
65 | private: | ||
66 | QString *selected; | ||
67 | |||
68 | }; | ||
69 | |||
70 | class IMAPconfig : public IMAPconfigUI | ||
71 | { | ||
72 | Q_OBJECT | ||
73 | |||
74 | public: | ||
75 | IMAPconfig( IMAPaccount *account, QWidget *parent = 0, const char *name = 0, bool modal = 0, WFlags flags = 0 ); | ||
76 | |||
77 | public slots: | ||
78 | void fillValues(); | ||
79 | |||
80 | protected slots: | ||
81 | void slotSSL( bool enabled ); | ||
82 | void accept(); | ||
83 | |||
84 | private: | ||
85 | IMAPaccount *data; | ||
86 | |||
87 | }; | ||
88 | |||
89 | class POP3config : public POP3configUI | ||
90 | { | ||
91 | Q_OBJECT | ||
92 | |||
93 | public: | ||
94 | POP3config( POP3account *account, QWidget *parent = 0, const char *name = 0, bool modal = 0, WFlags flags = 0 ); | ||
95 | |||
96 | public slots: | ||
97 | void fillValues(); | ||
98 | |||
99 | protected slots: | ||
100 | void slotSSL( bool enabled ); | ||
101 | void accept(); | ||
102 | |||
103 | private: | ||
104 | POP3account *data; | ||
105 | |||
106 | }; | ||
107 | |||
108 | class SMTPconfig : public SMTPconfigUI | ||
109 | { | ||
110 | Q_OBJECT | ||
111 | |||
112 | public: | ||
113 | SMTPconfig( SMTPaccount *account, QWidget *parent = 0, const char *name = 0, bool modal = 0, WFlags flags = 0 ); | ||
114 | |||
115 | public slots: | ||
116 | void slotSSL( bool enabled ); | ||
117 | void fillValues(); | ||
118 | |||
119 | protected slots: | ||
120 | void accept(); | ||
121 | |||
122 | private: | ||
123 | SMTPaccount *data; | ||
124 | |||
125 | }; | ||
126 | |||
127 | class NNTPconfig : public NNTPconfigUI | ||
128 | { | ||
129 | Q_OBJECT | ||
130 | |||
131 | public: | ||
132 | NNTPconfig( NNTPaccount *account, QWidget *parent = 0, const char *name = 0, bool modal = 0, WFlags flags = 0 ); | ||
133 | |||
134 | public slots: | ||
135 | void fillValues(); | ||
136 | |||
137 | protected slots: | ||
138 | void slotSSL( bool enabled ); | ||
139 | void accept(); | ||
140 | |||
141 | private: | ||
142 | NNTPaccount *data; | ||
143 | |||
144 | }; | ||
145 | |||
146 | #endif | ||
diff --git a/noncore/net/mail/editaccountsui.ui b/noncore/net/mail/editaccountsui.ui new file mode 100644 index 0000000..d86f145 --- a/dev/null +++ b/noncore/net/mail/editaccountsui.ui | |||
@@ -0,0 +1,223 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>EditAccountsUI</class> | ||
3 | <widget> | ||
4 | <class>QDialog</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>EditAccountsUI</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>260</width> | ||
15 | <height>320</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Configure Accounts</string> | ||
21 | </property> | ||
22 | <property> | ||
23 | <name>layoutMargin</name> | ||
24 | </property> | ||
25 | <property> | ||
26 | <name>layoutSpacing</name> | ||
27 | </property> | ||
28 | <vbox> | ||
29 | <property stdset="1"> | ||
30 | <name>margin</name> | ||
31 | <number>0</number> | ||
32 | </property> | ||
33 | <property stdset="1"> | ||
34 | <name>spacing</name> | ||
35 | <number>0</number> | ||
36 | </property> | ||
37 | <widget> | ||
38 | <class>QTabWidget</class> | ||
39 | <property stdset="1"> | ||
40 | <name>name</name> | ||
41 | <cstring>configTab</cstring> | ||
42 | </property> | ||
43 | <property> | ||
44 | <name>layoutMargin</name> | ||
45 | </property> | ||
46 | <property> | ||
47 | <name>layoutSpacing</name> | ||
48 | </property> | ||
49 | <widget> | ||
50 | <class>QWidget</class> | ||
51 | <property stdset="1"> | ||
52 | <name>name</name> | ||
53 | <cstring>mailTab</cstring> | ||
54 | </property> | ||
55 | <attribute> | ||
56 | <name>title</name> | ||
57 | <string>Mail</string> | ||
58 | </attribute> | ||
59 | <grid> | ||
60 | <property stdset="1"> | ||
61 | <name>margin</name> | ||
62 | <number>4</number> | ||
63 | </property> | ||
64 | <property stdset="1"> | ||
65 | <name>spacing</name> | ||
66 | <number>3</number> | ||
67 | </property> | ||
68 | <widget row="1" column="2" > | ||
69 | <class>QPushButton</class> | ||
70 | <property stdset="1"> | ||
71 | <name>name</name> | ||
72 | <cstring>deleteMail</cstring> | ||
73 | </property> | ||
74 | <property stdset="1"> | ||
75 | <name>text</name> | ||
76 | <string>Delete</string> | ||
77 | </property> | ||
78 | </widget> | ||
79 | <widget row="1" column="0" > | ||
80 | <class>QPushButton</class> | ||
81 | <property stdset="1"> | ||
82 | <name>name</name> | ||
83 | <cstring>newMail</cstring> | ||
84 | </property> | ||
85 | <property stdset="1"> | ||
86 | <name>text</name> | ||
87 | <string>New</string> | ||
88 | </property> | ||
89 | </widget> | ||
90 | <widget row="0" column="0" rowspan="1" colspan="3" > | ||
91 | <class>QListView</class> | ||
92 | <property stdset="1"> | ||
93 | <name>name</name> | ||
94 | <cstring>mailList</cstring> | ||
95 | </property> | ||
96 | <property stdset="1"> | ||
97 | <name>sizePolicy</name> | ||
98 | <sizepolicy> | ||
99 | <hsizetype>7</hsizetype> | ||
100 | <vsizetype>7</vsizetype> | ||
101 | </sizepolicy> | ||
102 | </property> | ||
103 | <property stdset="1"> | ||
104 | <name>resizePolicy</name> | ||
105 | <enum>Manual</enum> | ||
106 | </property> | ||
107 | <property stdset="1"> | ||
108 | <name>allColumnsShowFocus</name> | ||
109 | <bool>true</bool> | ||
110 | </property> | ||
111 | <property stdset="1"> | ||
112 | <name>showSortIndicator</name> | ||
113 | <bool>true</bool> | ||
114 | </property> | ||
115 | <property> | ||
116 | <name>toolTip</name> | ||
117 | <string>Name of the Account</string> | ||
118 | </property> | ||
119 | </widget> | ||
120 | <widget row="1" column="1" > | ||
121 | <class>QPushButton</class> | ||
122 | <property stdset="1"> | ||
123 | <name>name</name> | ||
124 | <cstring>editMail</cstring> | ||
125 | </property> | ||
126 | <property stdset="1"> | ||
127 | <name>text</name> | ||
128 | <string>Edit</string> | ||
129 | </property> | ||
130 | </widget> | ||
131 | </grid> | ||
132 | </widget> | ||
133 | <widget> | ||
134 | <class>QWidget</class> | ||
135 | <property stdset="1"> | ||
136 | <name>name</name> | ||
137 | <cstring>newsTab</cstring> | ||
138 | </property> | ||
139 | <attribute> | ||
140 | <name>title</name> | ||
141 | <string>News</string> | ||
142 | </attribute> | ||
143 | <grid> | ||
144 | <property stdset="1"> | ||
145 | <name>margin</name> | ||
146 | <number>4</number> | ||
147 | </property> | ||
148 | <property stdset="1"> | ||
149 | <name>spacing</name> | ||
150 | <number>3</number> | ||
151 | </property> | ||
152 | <widget row="1" column="2" > | ||
153 | <class>QPushButton</class> | ||
154 | <property stdset="1"> | ||
155 | <name>name</name> | ||
156 | <cstring>deleteNews</cstring> | ||
157 | </property> | ||
158 | <property stdset="1"> | ||
159 | <name>sizePolicy</name> | ||
160 | <sizepolicy> | ||
161 | <hsizetype>1</hsizetype> | ||
162 | <vsizetype>0</vsizetype> | ||
163 | </sizepolicy> | ||
164 | </property> | ||
165 | <property stdset="1"> | ||
166 | <name>text</name> | ||
167 | <string>Delete</string> | ||
168 | </property> | ||
169 | </widget> | ||
170 | <widget row="1" column="1" > | ||
171 | <class>QPushButton</class> | ||
172 | <property stdset="1"> | ||
173 | <name>name</name> | ||
174 | <cstring>editNews</cstring> | ||
175 | </property> | ||
176 | <property stdset="1"> | ||
177 | <name>text</name> | ||
178 | <string>Edit</string> | ||
179 | </property> | ||
180 | </widget> | ||
181 | <widget row="0" column="0" rowspan="1" colspan="3" > | ||
182 | <class>QListView</class> | ||
183 | <property stdset="1"> | ||
184 | <name>name</name> | ||
185 | <cstring>newsList</cstring> | ||
186 | </property> | ||
187 | <property stdset="1"> | ||
188 | <name>allColumnsShowFocus</name> | ||
189 | <bool>true</bool> | ||
190 | </property> | ||
191 | <property stdset="1"> | ||
192 | <name>showSortIndicator</name> | ||
193 | <bool>true</bool> | ||
194 | </property> | ||
195 | </widget> | ||
196 | <widget row="1" column="0" > | ||
197 | <class>QPushButton</class> | ||
198 | <property stdset="1"> | ||
199 | <name>name</name> | ||
200 | <cstring>newNews</cstring> | ||
201 | </property> | ||
202 | <property stdset="1"> | ||
203 | <name>text</name> | ||
204 | <string>New</string> | ||
205 | </property> | ||
206 | </widget> | ||
207 | </grid> | ||
208 | </widget> | ||
209 | </widget> | ||
210 | </vbox> | ||
211 | </widget> | ||
212 | <tabstops> | ||
213 | <tabstop>mailList</tabstop> | ||
214 | <tabstop>newMail</tabstop> | ||
215 | <tabstop>editMail</tabstop> | ||
216 | <tabstop>deleteMail</tabstop> | ||
217 | <tabstop>configTab</tabstop> | ||
218 | <tabstop>newsList</tabstop> | ||
219 | <tabstop>newNews</tabstop> | ||
220 | <tabstop>editNews</tabstop> | ||
221 | <tabstop>deleteNews</tabstop> | ||
222 | </tabstops> | ||
223 | </UI> | ||
diff --git a/noncore/net/mail/imapconfigui.ui b/noncore/net/mail/imapconfigui.ui new file mode 100644 index 0000000..ac0297f --- a/dev/null +++ b/noncore/net/mail/imapconfigui.ui | |||
@@ -0,0 +1,242 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>IMAPconfigUI</class> | ||
3 | <widget> | ||
4 | <class>QDialog</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>IMAPconfigUI</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>228</width> | ||
15 | <height>320</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Configure IMAP</string> | ||
21 | </property> | ||
22 | <property> | ||
23 | <name>layoutMargin</name> | ||
24 | </property> | ||
25 | <property> | ||
26 | <name>layoutSpacing</name> | ||
27 | </property> | ||
28 | <grid> | ||
29 | <property stdset="1"> | ||
30 | <name>margin</name> | ||
31 | <number>3</number> | ||
32 | </property> | ||
33 | <property stdset="1"> | ||
34 | <name>spacing</name> | ||
35 | <number>2</number> | ||
36 | </property> | ||
37 | <widget row="6" column="0" > | ||
38 | <class>QLabel</class> | ||
39 | <property stdset="1"> | ||
40 | <name>name</name> | ||
41 | <cstring>userLabel</cstring> | ||
42 | </property> | ||
43 | <property stdset="1"> | ||
44 | <name>text</name> | ||
45 | <string>User</string> | ||
46 | </property> | ||
47 | </widget> | ||
48 | <widget row="4" column="1" > | ||
49 | <class>QCheckBox</class> | ||
50 | <property stdset="1"> | ||
51 | <name>name</name> | ||
52 | <cstring>sslBox</cstring> | ||
53 | </property> | ||
54 | <property stdset="1"> | ||
55 | <name>text</name> | ||
56 | <string>Use SSL</string> | ||
57 | </property> | ||
58 | </widget> | ||
59 | <widget row="2" column="1" > | ||
60 | <class>QLineEdit</class> | ||
61 | <property stdset="1"> | ||
62 | <name>name</name> | ||
63 | <cstring>serverLine</cstring> | ||
64 | </property> | ||
65 | </widget> | ||
66 | <widget row="6" column="1" > | ||
67 | <class>QLineEdit</class> | ||
68 | <property stdset="1"> | ||
69 | <name>name</name> | ||
70 | <cstring>userLine</cstring> | ||
71 | </property> | ||
72 | </widget> | ||
73 | <widget row="7" column="0" > | ||
74 | <class>QLabel</class> | ||
75 | <property stdset="1"> | ||
76 | <name>name</name> | ||
77 | <cstring>passLabel</cstring> | ||
78 | </property> | ||
79 | <property stdset="1"> | ||
80 | <name>text</name> | ||
81 | <string>Password</string> | ||
82 | </property> | ||
83 | </widget> | ||
84 | <widget row="3" column="0" > | ||
85 | <class>QLabel</class> | ||
86 | <property stdset="1"> | ||
87 | <name>name</name> | ||
88 | <cstring>portLabel</cstring> | ||
89 | </property> | ||
90 | <property stdset="1"> | ||
91 | <name>text</name> | ||
92 | <string>Port</string> | ||
93 | </property> | ||
94 | </widget> | ||
95 | <widget row="2" column="0" > | ||
96 | <class>QLabel</class> | ||
97 | <property stdset="1"> | ||
98 | <name>name</name> | ||
99 | <cstring>serverLabel</cstring> | ||
100 | </property> | ||
101 | <property stdset="1"> | ||
102 | <name>text</name> | ||
103 | <string>Server</string> | ||
104 | </property> | ||
105 | </widget> | ||
106 | <widget row="3" column="1" > | ||
107 | <class>QLineEdit</class> | ||
108 | <property stdset="1"> | ||
109 | <name>name</name> | ||
110 | <cstring>portLine</cstring> | ||
111 | </property> | ||
112 | </widget> | ||
113 | <widget row="7" column="1" > | ||
114 | <class>QLineEdit</class> | ||
115 | <property stdset="1"> | ||
116 | <name>name</name> | ||
117 | <cstring>passLine</cstring> | ||
118 | </property> | ||
119 | <property stdset="1"> | ||
120 | <name>echoMode</name> | ||
121 | <enum>Password</enum> | ||
122 | </property> | ||
123 | </widget> | ||
124 | <spacer row="10" column="1" > | ||
125 | <property> | ||
126 | <name>name</name> | ||
127 | <cstring>spacer</cstring> | ||
128 | </property> | ||
129 | <property stdset="1"> | ||
130 | <name>orientation</name> | ||
131 | <enum>Vertical</enum> | ||
132 | </property> | ||
133 | <property stdset="1"> | ||
134 | <name>sizeType</name> | ||
135 | <enum>Expanding</enum> | ||
136 | </property> | ||
137 | <property> | ||
138 | <name>sizeHint</name> | ||
139 | <size> | ||
140 | <width>20</width> | ||
141 | <height>20</height> | ||
142 | </size> | ||
143 | </property> | ||
144 | </spacer> | ||
145 | <widget row="0" column="1" > | ||
146 | <class>QLineEdit</class> | ||
147 | <property stdset="1"> | ||
148 | <name>name</name> | ||
149 | <cstring>accountLine</cstring> | ||
150 | </property> | ||
151 | <property> | ||
152 | <name>toolTip</name> | ||
153 | <string>Name of the Account</string> | ||
154 | </property> | ||
155 | </widget> | ||
156 | <widget row="0" column="0" > | ||
157 | <class>QLabel</class> | ||
158 | <property stdset="1"> | ||
159 | <name>name</name> | ||
160 | <cstring>accountLabel</cstring> | ||
161 | </property> | ||
162 | <property stdset="1"> | ||
163 | <name>text</name> | ||
164 | <string>Account</string> | ||
165 | </property> | ||
166 | </widget> | ||
167 | <widget row="1" column="0" rowspan="1" colspan="2" > | ||
168 | <class>Line</class> | ||
169 | <property stdset="1"> | ||
170 | <name>name</name> | ||
171 | <cstring>line1</cstring> | ||
172 | </property> | ||
173 | <property stdset="1"> | ||
174 | <name>orientation</name> | ||
175 | <enum>Horizontal</enum> | ||
176 | </property> | ||
177 | </widget> | ||
178 | <widget row="9" column="1" > | ||
179 | <class>QLineEdit</class> | ||
180 | <property stdset="1"> | ||
181 | <name>name</name> | ||
182 | <cstring>prefixLine</cstring> | ||
183 | </property> | ||
184 | </widget> | ||
185 | <widget row="9" column="0" > | ||
186 | <class>QLabel</class> | ||
187 | <property stdset="1"> | ||
188 | <name>name</name> | ||
189 | <cstring>prefixLabel</cstring> | ||
190 | </property> | ||
191 | <property stdset="1"> | ||
192 | <name>text</name> | ||
193 | <string>Prefix</string> | ||
194 | </property> | ||
195 | </widget> | ||
196 | <widget row="5" column="0" rowspan="1" colspan="2" > | ||
197 | <class>Line</class> | ||
198 | <property stdset="1"> | ||
199 | <name>name</name> | ||
200 | <cstring>line2</cstring> | ||
201 | </property> | ||
202 | <property stdset="1"> | ||
203 | <name>enabled</name> | ||
204 | <bool>true</bool> | ||
205 | </property> | ||
206 | <property stdset="1"> | ||
207 | <name>caption</name> | ||
208 | <string></string> | ||
209 | </property> | ||
210 | <property stdset="1"> | ||
211 | <name>orientation</name> | ||
212 | <enum>Horizontal</enum> | ||
213 | </property> | ||
214 | <property> | ||
215 | <name>layoutMargin</name> | ||
216 | </property> | ||
217 | <property> | ||
218 | <name>layoutSpacing</name> | ||
219 | </property> | ||
220 | </widget> | ||
221 | <widget row="8" column="0" rowspan="1" colspan="2" > | ||
222 | <class>Line</class> | ||
223 | <property stdset="1"> | ||
224 | <name>name</name> | ||
225 | <cstring>Line3</cstring> | ||
226 | </property> | ||
227 | <property stdset="1"> | ||
228 | <name>orientation</name> | ||
229 | <enum>Horizontal</enum> | ||
230 | </property> | ||
231 | </widget> | ||
232 | </grid> | ||
233 | </widget> | ||
234 | <tabstops> | ||
235 | <tabstop>accountLine</tabstop> | ||
236 | <tabstop>serverLine</tabstop> | ||
237 | <tabstop>portLine</tabstop> | ||
238 | <tabstop>sslBox</tabstop> | ||
239 | <tabstop>userLine</tabstop> | ||
240 | <tabstop>passLine</tabstop> | ||
241 | </tabstops> | ||
242 | </UI> | ||
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp new file mode 100644 index 0000000..16f4565 --- a/dev/null +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -0,0 +1,411 @@ | |||
1 | |||
2 | #include <stdlib.h> | ||
3 | |||
4 | #include "mailwrapper.h" | ||
5 | |||
6 | |||
7 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | ||
8 | { | ||
9 | account = a; | ||
10 | } | ||
11 | |||
12 | void imap_progress( size_t current, size_t maximum ) | ||
13 | { | ||
14 | qDebug( "IMAP: %i of %i", current, maximum ); | ||
15 | } | ||
16 | |||
17 | void IMAPwrapper::listMessages(const QString&mailbox,Maillist&target ) | ||
18 | { | ||
19 | const char *server, *user, *pass, *mb; | ||
20 | uint16_t port; | ||
21 | int err = MAILIMAP_NO_ERROR; | ||
22 | clist *result; | ||
23 | clistcell *current; | ||
24 | mailimap_fetch_att *fetchAtt,*fetchAttFlags; | ||
25 | mailimap_fetch_type *fetchType; | ||
26 | mailimap_set *set; | ||
27 | |||
28 | mb = mailbox.latin1(); | ||
29 | server = account->getServer().latin1(); | ||
30 | port = account->getPort().toUInt(); | ||
31 | user = account->getUser().latin1(); | ||
32 | pass = account->getPassword().latin1(); | ||
33 | |||
34 | mailimap *imap = mailimap_new( 20, &imap_progress ); | ||
35 | if ( imap == NULL ) { | ||
36 | qDebug("IMAP Memory error"); | ||
37 | return; | ||
38 | } | ||
39 | |||
40 | /* connect */ | ||
41 | err = mailimap_socket_connect( imap, (char*)server, port ); | ||
42 | if ( err != MAILIMAP_NO_ERROR && | ||
43 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | ||
44 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | ||
45 | qDebug("error connecting server: %s",imap->response); | ||
46 | mailimap_free( imap ); | ||
47 | return; | ||
48 | } | ||
49 | |||
50 | /* login */ | ||
51 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); | ||
52 | if ( err != MAILIMAP_NO_ERROR ) { | ||
53 | qDebug("error logging in imap: %s",imap->response); | ||
54 | err = mailimap_close( imap ); | ||
55 | mailimap_free( imap ); | ||
56 | return; | ||
57 | } | ||
58 | |||
59 | /* select mailbox READONLY for operations */ | ||
60 | err = mailimap_examine( imap, (char*)mb); | ||
61 | if ( err != MAILIMAP_NO_ERROR ) { | ||
62 | qDebug("error selecting mailbox: %s",imap->response); | ||
63 | err = mailimap_logout( imap ); | ||
64 | err = mailimap_close( imap ); | ||
65 | mailimap_free( imap ); | ||
66 | return; | ||
67 | } | ||
68 | |||
69 | int last = imap->selection_info->exists; | ||
70 | if (last == 0) { | ||
71 | qDebug("mailbox has no mails"); | ||
72 | err = mailimap_logout( imap ); | ||
73 | err = mailimap_close( imap ); | ||
74 | mailimap_free( imap ); | ||
75 | return; | ||
76 | } | ||
77 | |||
78 | |||
79 | result = clist_new(); | ||
80 | /* the range has to start at 1!!! not with 0!!!! */ | ||
81 | set = mailimap_set_new_interval( 1, last ); | ||
82 | fetchAtt = mailimap_fetch_att_new_envelope(); | ||
83 | fetchAttFlags = mailimap_fetch_att_new_flags(); | ||
84 | |||
85 | //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | ||
86 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | ||
87 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); | ||
88 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); | ||
89 | |||
90 | err = mailimap_fetch( imap, set, fetchType, &result ); | ||
91 | mailimap_set_free( set ); | ||
92 | mailimap_fetch_type_free( fetchType ); | ||
93 | |||
94 | QString date,subject,from; | ||
95 | |||
96 | if ( err == MAILIMAP_NO_ERROR ) { | ||
97 | current = clist_begin(result); | ||
98 | mailimap_msg_att * msg_att; | ||
99 | int i = 0; | ||
100 | while ( current != 0 ) { | ||
101 | ++i; | ||
102 | msg_att = (mailimap_msg_att*)current->data; | ||
103 | RecMail*m = parse_list_result(msg_att); | ||
104 | if (m) { | ||
105 | m->setNumber(i); | ||
106 | target.append(m); | ||
107 | } | ||
108 | current = current->next; | ||
109 | } | ||
110 | } else { | ||
111 | qDebug("Error fetching headers: %s",imap->response); | ||
112 | } | ||
113 | |||
114 | err = mailimap_logout( imap ); | ||
115 | err = mailimap_close( imap ); | ||
116 | clist_free(result); | ||
117 | mailimap_free( imap ); | ||
118 | } | ||
119 | |||
120 | QList<IMAPFolder>* IMAPwrapper::listFolders() | ||
121 | { | ||
122 | const char *server, *user, *pass, *path, *mask; | ||
123 | uint16_t port; | ||
124 | int err = MAILIMAP_NO_ERROR; | ||
125 | clist *result; | ||
126 | clistcell *current; | ||
127 | |||
128 | QList<IMAPFolder> * folders = new QList<IMAPFolder>(); | ||
129 | folders->setAutoDelete( true ); | ||
130 | |||
131 | server = account->getServer().latin1(); | ||
132 | port = account->getPort().toUInt(); | ||
133 | user = account->getUser().latin1(); | ||
134 | pass = account->getPassword().latin1(); | ||
135 | path = account->getPrefix().latin1(); | ||
136 | |||
137 | mailimap *imap = mailimap_new( 20, &imap_progress ); | ||
138 | if ( imap == NULL ) { | ||
139 | qDebug("error mailimap_new"); | ||
140 | return folders; | ||
141 | } | ||
142 | |||
143 | err = mailimap_socket_connect( imap, (char*)server, port ); | ||
144 | if ( err != MAILIMAP_NO_ERROR && | ||
145 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | ||
146 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | ||
147 | mailimap_free(imap); | ||
148 | qDebug("error imap_socket_connect: %s",imap->response); | ||
149 | return folders; | ||
150 | } | ||
151 | |||
152 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); | ||
153 | if ( err != MAILIMAP_NO_ERROR ) { | ||
154 | mailimap_free(imap); | ||
155 | qDebug("error logging in: %s",imap->response); | ||
156 | return folders; | ||
157 | } | ||
158 | /* | ||
159 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | ||
160 | * We must not forget to filter them out in next loop! | ||
161 | * it seems like ugly code. and yes - it is ugly code. but the best way. | ||
162 | */ | ||
163 | QString temp; | ||
164 | mask = "INBOX" ; | ||
165 | result = clist_new(); | ||
166 | mailimap_mailbox_list *list; | ||
167 | err = mailimap_list( imap, (char*)"", (char*)mask, &result ); | ||
168 | if ( err == MAILIMAP_NO_ERROR ) { | ||
169 | current = result->first; | ||
170 | for ( int i = result->count; i > 0; i-- ) { | ||
171 | list = (mailimap_mailbox_list *) current->data; | ||
172 | // it is better use the deep copy mechanism of qt itself | ||
173 | // instead of using strdup! | ||
174 | temp = list->mb; | ||
175 | folders->append( new IMAPFolder(temp)); | ||
176 | current = current->next; | ||
177 | } | ||
178 | } else { | ||
179 | qDebug("error fetching folders: %s",imap->response); | ||
180 | } | ||
181 | mailimap_list_result_free( result ); | ||
182 | |||
183 | /* | ||
184 | * second stage - get the other then inbox folders | ||
185 | */ | ||
186 | mask = "*" ; | ||
187 | result = clist_new(); | ||
188 | err = mailimap_list( imap, (char*)path, (char*)mask, &result ); | ||
189 | if ( err == MAILIMAP_NO_ERROR ) { | ||
190 | current = result->first; | ||
191 | for ( int i = result->count; i > 0; i-- ) { | ||
192 | list = (mailimap_mailbox_list *) current->data; | ||
193 | // it is better use the deep copy mechanism of qt itself | ||
194 | // instead of using strdup! | ||
195 | temp = list->mb; | ||
196 | current = current->next; | ||
197 | if (temp.lower()=="inbox") | ||
198 | continue; | ||
199 | folders->append(new IMAPFolder(temp)); | ||
200 | |||
201 | } | ||
202 | } else { | ||
203 | qDebug("error fetching folders"); | ||
204 | } | ||
205 | mailimap_list_result_free( result ); | ||
206 | err = mailimap_logout( imap ); | ||
207 | err = mailimap_close( imap ); | ||
208 | mailimap_free( imap ); | ||
209 | return folders; | ||
210 | } | ||
211 | |||
212 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | ||
213 | { | ||
214 | RecMail * m = 0; | ||
215 | mailimap_msg_att_item *item=0; | ||
216 | bool named_from = false; | ||
217 | QString from,date,subject; | ||
218 | date = from = subject = ""; | ||
219 | clistcell *current,*c,*cf, *current_from = NULL; | ||
220 | mailimap_address * current_address = NULL; | ||
221 | mailimap_msg_att_dynamic*flist; | ||
222 | mailimap_flag_fetch*cflag; | ||
223 | QBitArray mFlags(7); | ||
224 | |||
225 | if (!m_att) { | ||
226 | return m; | ||
227 | } | ||
228 | |||
229 | #if 0 | ||
230 | MAILIMAP_FLAG_KEYWORD, /* keyword flag */ | ||
231 | MAILIMAP_FLAG_EXTENSION, /* \extension flag */ | ||
232 | #endif | ||
233 | c = clist_begin(m_att->list); | ||
234 | while ( c ) { | ||
235 | current = c; | ||
236 | c = c->next; | ||
237 | item = (mailimap_msg_att_item*)current->data; | ||
238 | if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | ||
239 | flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; | ||
240 | if (!flist->list) { | ||
241 | continue; | ||
242 | } | ||
243 | cf = flist->list->first; | ||
244 | while (cf) { | ||
245 | cflag = (mailimap_flag_fetch*)cf->data; | ||
246 | if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { | ||
247 | switch (cflag->flag->type) { | ||
248 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | ||
249 | mFlags.setBit(FLAG_ANSWERED); | ||
250 | break; | ||
251 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | ||
252 | mFlags.setBit(FLAG_FLAGGED); | ||
253 | break; | ||
254 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | ||
255 | mFlags.setBit(FLAG_DELETED); | ||
256 | break; | ||
257 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | ||
258 | mFlags.setBit(FLAG_SEEN); | ||
259 | break; | ||
260 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | ||
261 | mFlags.setBit(FLAG_DRAFT); | ||
262 | break; | ||
263 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | ||
264 | break; | ||
265 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | ||
266 | break; | ||
267 | default: | ||
268 | break; | ||
269 | } | ||
270 | } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { | ||
271 | mFlags.setBit(FLAG_RECENT); | ||
272 | } | ||
273 | |||
274 | cf = cf->next; | ||
275 | } | ||
276 | continue; | ||
277 | } | ||
278 | if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { | ||
279 | qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); | ||
280 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { | ||
281 | mailimap_envelope * head = item->msg_att_static->env; | ||
282 | date = head->date; | ||
283 | subject = head->subject; | ||
284 | if (head->from!=NULL) | ||
285 | current_from = head->from->list->first; | ||
286 | while (current_from != NULL) { | ||
287 | from = ""; | ||
288 | named_from = false; | ||
289 | current_address=(mailimap_address*)current_from->data; | ||
290 | current_from = current_from->next; | ||
291 | if (current_address->personal_name){ | ||
292 | from+=QString(current_address->personal_name); | ||
293 | from+=" "; | ||
294 | named_from = true; | ||
295 | } | ||
296 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | ||
297 | from+="<"; | ||
298 | } | ||
299 | if (current_address->mailbox_name) { | ||
300 | from+=QString(current_address->mailbox_name); | ||
301 | from+="@"; | ||
302 | } | ||
303 | if (current_address->host_name) { | ||
304 | from+=QString(current_address->host_name); | ||
305 | } | ||
306 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | ||
307 | from+=">"; | ||
308 | } | ||
309 | } | ||
310 | qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s", | ||
311 | from.latin1(), | ||
312 | subject.latin1(),date.latin1()); | ||
313 | m = new RecMail(); | ||
314 | m->setSubject(subject); | ||
315 | m->setFrom(from); | ||
316 | m->setDate(date); | ||
317 | } else { | ||
318 | qDebug("Another type"); | ||
319 | } | ||
320 | } | ||
321 | /* msg is already deleted */ | ||
322 | if (mFlags.testBit(FLAG_DELETED) && m) { | ||
323 | delete m; | ||
324 | m = 0; | ||
325 | } | ||
326 | if (m) { | ||
327 | m->setFlags(mFlags); | ||
328 | } | ||
329 | return m; | ||
330 | } | ||
331 | |||
332 | QString IMAPwrapper::fetchBody(const QString & mailbox,const RecMail&mail) | ||
333 | { | ||
334 | QString body = ""; | ||
335 | const char *server, *user, *pass, *mb; | ||
336 | uint16_t port; | ||
337 | int err = MAILIMAP_NO_ERROR; | ||
338 | clist *result; | ||
339 | clistcell *current; | ||
340 | mailimap_fetch_att *fetchAtt; | ||
341 | mailimap_fetch_type *fetchType; | ||
342 | mailimap_set *set; | ||
343 | |||
344 | mb = mailbox.latin1(); | ||
345 | server = account->getServer().latin1(); | ||
346 | port = account->getPort().toUInt(); | ||
347 | user = account->getUser().latin1(); | ||
348 | pass = account->getPassword().latin1(); | ||
349 | |||
350 | mailimap *imap = mailimap_new( 20, &imap_progress ); | ||
351 | if ( imap == NULL ) { | ||
352 | qDebug("IMAP Memory error"); | ||
353 | return body; | ||
354 | } | ||
355 | |||
356 | /* connect */ | ||
357 | err = mailimap_socket_connect( imap, (char*)server, port ); | ||
358 | if ( err != MAILIMAP_NO_ERROR && | ||
359 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | ||
360 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | ||
361 | qDebug("error connecting server: %s",imap->response); | ||
362 | mailimap_free( imap ); | ||
363 | return body; | ||
364 | } | ||
365 | |||
366 | /* login */ | ||
367 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); | ||
368 | if ( err != MAILIMAP_NO_ERROR ) { | ||
369 | qDebug("error logging in imap: %s",imap->response); | ||
370 | err = mailimap_close( imap ); | ||
371 | mailimap_free( imap ); | ||
372 | return body; | ||
373 | } | ||
374 | |||
375 | /* select mailbox READONLY for operations */ | ||
376 | err = mailimap_examine( imap, (char*)mb); | ||
377 | if ( err != MAILIMAP_NO_ERROR ) { | ||
378 | qDebug("error selecting mailbox: %s",imap->response); | ||
379 | err = mailimap_logout( imap ); | ||
380 | err = mailimap_close( imap ); | ||
381 | mailimap_free( imap ); | ||
382 | return body; | ||
383 | } | ||
384 | result = clist_new(); | ||
385 | /* the range has to start at 1!!! not with 0!!!! */ | ||
386 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | ||
387 | fetchAtt = mailimap_fetch_att_new_rfc822_text(); | ||
388 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | ||
389 | err = mailimap_fetch( imap, set, fetchType, &result ); | ||
390 | mailimap_set_free( set ); | ||
391 | mailimap_fetch_type_free( fetchType ); | ||
392 | |||
393 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | ||
394 | mailimap_msg_att * msg_att; | ||
395 | msg_att = (mailimap_msg_att*)current->data; | ||
396 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; | ||
397 | |||
398 | if (item->msg_att_static && item->msg_att_static->rfc822_text) { | ||
399 | body = item->msg_att_static->rfc822_text; | ||
400 | } | ||
401 | } else { | ||
402 | qDebug("error fetching text: %s",imap->response); | ||
403 | } | ||
404 | |||
405 | err = mailimap_logout( imap ); | ||
406 | err = mailimap_close( imap ); | ||
407 | mailimap_free( imap ); | ||
408 | clist_free(result); | ||
409 | |||
410 | return body; | ||
411 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp new file mode 100644 index 0000000..16f4565 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -0,0 +1,411 @@ | |||
1 | |||
2 | #include <stdlib.h> | ||
3 | |||
4 | #include "mailwrapper.h" | ||
5 | |||
6 | |||
7 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | ||
8 | { | ||
9 | account = a; | ||
10 | } | ||
11 | |||
12 | void imap_progress( size_t current, size_t maximum ) | ||
13 | { | ||
14 | qDebug( "IMAP: %i of %i", current, maximum ); | ||
15 | } | ||
16 | |||
17 | void IMAPwrapper::listMessages(const QString&mailbox,Maillist&target ) | ||
18 | { | ||
19 | const char *server, *user, *pass, *mb; | ||
20 | uint16_t port; | ||
21 | int err = MAILIMAP_NO_ERROR; | ||
22 | clist *result; | ||
23 | clistcell *current; | ||
24 | mailimap_fetch_att *fetchAtt,*fetchAttFlags; | ||
25 | mailimap_fetch_type *fetchType; | ||
26 | mailimap_set *set; | ||
27 | |||
28 | mb = mailbox.latin1(); | ||
29 | server = account->getServer().latin1(); | ||
30 | port = account->getPort().toUInt(); | ||
31 | user = account->getUser().latin1(); | ||
32 | pass = account->getPassword().latin1(); | ||
33 | |||
34 | mailimap *imap = mailimap_new( 20, &imap_progress ); | ||
35 | if ( imap == NULL ) { | ||
36 | qDebug("IMAP Memory error"); | ||
37 | return; | ||
38 | } | ||
39 | |||
40 | /* connect */ | ||
41 | err = mailimap_socket_connect( imap, (char*)server, port ); | ||
42 | if ( err != MAILIMAP_NO_ERROR && | ||
43 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | ||
44 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | ||
45 | qDebug("error connecting server: %s",imap->response); | ||
46 | mailimap_free( imap ); | ||
47 | return; | ||
48 | } | ||
49 | |||
50 | /* login */ | ||
51 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); | ||
52 | if ( err != MAILIMAP_NO_ERROR ) { | ||
53 | qDebug("error logging in imap: %s",imap->response); | ||
54 | err = mailimap_close( imap ); | ||
55 | mailimap_free( imap ); | ||
56 | return; | ||
57 | } | ||
58 | |||
59 | /* select mailbox READONLY for operations */ | ||
60 | err = mailimap_examine( imap, (char*)mb); | ||
61 | if ( err != MAILIMAP_NO_ERROR ) { | ||
62 | qDebug("error selecting mailbox: %s",imap->response); | ||
63 | err = mailimap_logout( imap ); | ||
64 | err = mailimap_close( imap ); | ||
65 | mailimap_free( imap ); | ||
66 | return; | ||
67 | } | ||
68 | |||
69 | int last = imap->selection_info->exists; | ||
70 | if (last == 0) { | ||
71 | qDebug("mailbox has no mails"); | ||
72 | err = mailimap_logout( imap ); | ||
73 | err = mailimap_close( imap ); | ||
74 | mailimap_free( imap ); | ||
75 | return; | ||
76 | } | ||
77 | |||
78 | |||
79 | result = clist_new(); | ||
80 | /* the range has to start at 1!!! not with 0!!!! */ | ||
81 | set = mailimap_set_new_interval( 1, last ); | ||
82 | fetchAtt = mailimap_fetch_att_new_envelope(); | ||
83 | fetchAttFlags = mailimap_fetch_att_new_flags(); | ||
84 | |||
85 | //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | ||
86 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | ||
87 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); | ||
88 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); | ||
89 | |||
90 | err = mailimap_fetch( imap, set, fetchType, &result ); | ||
91 | mailimap_set_free( set ); | ||
92 | mailimap_fetch_type_free( fetchType ); | ||
93 | |||
94 | QString date,subject,from; | ||
95 | |||
96 | if ( err == MAILIMAP_NO_ERROR ) { | ||
97 | current = clist_begin(result); | ||
98 | mailimap_msg_att * msg_att; | ||
99 | int i = 0; | ||
100 | while ( current != 0 ) { | ||
101 | ++i; | ||
102 | msg_att = (mailimap_msg_att*)current->data; | ||
103 | RecMail*m = parse_list_result(msg_att); | ||
104 | if (m) { | ||
105 | m->setNumber(i); | ||
106 | target.append(m); | ||
107 | } | ||
108 | current = current->next; | ||
109 | } | ||
110 | } else { | ||
111 | qDebug("Error fetching headers: %s",imap->response); | ||
112 | } | ||
113 | |||
114 | err = mailimap_logout( imap ); | ||
115 | err = mailimap_close( imap ); | ||
116 | clist_free(result); | ||
117 | mailimap_free( imap ); | ||
118 | } | ||
119 | |||
120 | QList<IMAPFolder>* IMAPwrapper::listFolders() | ||
121 | { | ||
122 | const char *server, *user, *pass, *path, *mask; | ||
123 | uint16_t port; | ||
124 | int err = MAILIMAP_NO_ERROR; | ||
125 | clist *result; | ||
126 | clistcell *current; | ||
127 | |||
128 | QList<IMAPFolder> * folders = new QList<IMAPFolder>(); | ||
129 | folders->setAutoDelete( true ); | ||
130 | |||
131 | server = account->getServer().latin1(); | ||
132 | port = account->getPort().toUInt(); | ||
133 | user = account->getUser().latin1(); | ||
134 | pass = account->getPassword().latin1(); | ||
135 | path = account->getPrefix().latin1(); | ||
136 | |||
137 | mailimap *imap = mailimap_new( 20, &imap_progress ); | ||
138 | if ( imap == NULL ) { | ||
139 | qDebug("error mailimap_new"); | ||
140 | return folders; | ||
141 | } | ||
142 | |||
143 | err = mailimap_socket_connect( imap, (char*)server, port ); | ||
144 | if ( err != MAILIMAP_NO_ERROR && | ||
145 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | ||
146 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | ||
147 | mailimap_free(imap); | ||
148 | qDebug("error imap_socket_connect: %s",imap->response); | ||
149 | return folders; | ||
150 | } | ||
151 | |||
152 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); | ||
153 | if ( err != MAILIMAP_NO_ERROR ) { | ||
154 | mailimap_free(imap); | ||
155 | qDebug("error logging in: %s",imap->response); | ||
156 | return folders; | ||
157 | } | ||
158 | /* | ||
159 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | ||
160 | * We must not forget to filter them out in next loop! | ||
161 | * it seems like ugly code. and yes - it is ugly code. but the best way. | ||
162 | */ | ||
163 | QString temp; | ||
164 | mask = "INBOX" ; | ||
165 | result = clist_new(); | ||
166 | mailimap_mailbox_list *list; | ||
167 | err = mailimap_list( imap, (char*)"", (char*)mask, &result ); | ||
168 | if ( err == MAILIMAP_NO_ERROR ) { | ||
169 | current = result->first; | ||
170 | for ( int i = result->count; i > 0; i-- ) { | ||
171 | list = (mailimap_mailbox_list *) current->data; | ||
172 | // it is better use the deep copy mechanism of qt itself | ||
173 | // instead of using strdup! | ||
174 | temp = list->mb; | ||
175 | folders->append( new IMAPFolder(temp)); | ||
176 | current = current->next; | ||
177 | } | ||
178 | } else { | ||
179 | qDebug("error fetching folders: %s",imap->response); | ||
180 | } | ||
181 | mailimap_list_result_free( result ); | ||
182 | |||
183 | /* | ||
184 | * second stage - get the other then inbox folders | ||
185 | */ | ||
186 | mask = "*" ; | ||
187 | result = clist_new(); | ||
188 | err = mailimap_list( imap, (char*)path, (char*)mask, &result ); | ||
189 | if ( err == MAILIMAP_NO_ERROR ) { | ||
190 | current = result->first; | ||
191 | for ( int i = result->count; i > 0; i-- ) { | ||
192 | list = (mailimap_mailbox_list *) current->data; | ||
193 | // it is better use the deep copy mechanism of qt itself | ||
194 | // instead of using strdup! | ||
195 | temp = list->mb; | ||
196 | current = current->next; | ||
197 | if (temp.lower()=="inbox") | ||
198 | continue; | ||
199 | folders->append(new IMAPFolder(temp)); | ||
200 | |||
201 | } | ||
202 | } else { | ||
203 | qDebug("error fetching folders"); | ||
204 | } | ||
205 | mailimap_list_result_free( result ); | ||
206 | err = mailimap_logout( imap ); | ||
207 | err = mailimap_close( imap ); | ||
208 | mailimap_free( imap ); | ||
209 | return folders; | ||
210 | } | ||
211 | |||
212 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | ||
213 | { | ||
214 | RecMail * m = 0; | ||
215 | mailimap_msg_att_item *item=0; | ||
216 | bool named_from = false; | ||
217 | QString from,date,subject; | ||
218 | date = from = subject = ""; | ||
219 | clistcell *current,*c,*cf, *current_from = NULL; | ||
220 | mailimap_address * current_address = NULL; | ||
221 | mailimap_msg_att_dynamic*flist; | ||
222 | mailimap_flag_fetch*cflag; | ||
223 | QBitArray mFlags(7); | ||
224 | |||
225 | if (!m_att) { | ||
226 | return m; | ||
227 | } | ||
228 | |||
229 | #if 0 | ||
230 | MAILIMAP_FLAG_KEYWORD, /* keyword flag */ | ||
231 | MAILIMAP_FLAG_EXTENSION, /* \extension flag */ | ||
232 | #endif | ||
233 | c = clist_begin(m_att->list); | ||
234 | while ( c ) { | ||
235 | current = c; | ||
236 | c = c->next; | ||
237 | item = (mailimap_msg_att_item*)current->data; | ||
238 | if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | ||
239 | flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; | ||
240 | if (!flist->list) { | ||
241 | continue; | ||
242 | } | ||
243 | cf = flist->list->first; | ||
244 | while (cf) { | ||
245 | cflag = (mailimap_flag_fetch*)cf->data; | ||
246 | if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { | ||
247 | switch (cflag->flag->type) { | ||
248 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | ||
249 | mFlags.setBit(FLAG_ANSWERED); | ||
250 | break; | ||
251 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | ||
252 | mFlags.setBit(FLAG_FLAGGED); | ||
253 | break; | ||
254 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | ||
255 | mFlags.setBit(FLAG_DELETED); | ||
256 | break; | ||
257 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | ||
258 | mFlags.setBit(FLAG_SEEN); | ||
259 | break; | ||
260 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | ||
261 | mFlags.setBit(FLAG_DRAFT); | ||
262 | break; | ||
263 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | ||
264 | break; | ||
265 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | ||
266 | break; | ||
267 | default: | ||
268 | break; | ||
269 | } | ||
270 | } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { | ||
271 | mFlags.setBit(FLAG_RECENT); | ||
272 | } | ||
273 | |||
274 | cf = cf->next; | ||
275 | } | ||
276 | continue; | ||
277 | } | ||
278 | if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { | ||
279 | qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); | ||
280 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { | ||
281 | mailimap_envelope * head = item->msg_att_static->env; | ||
282 | date = head->date; | ||
283 | subject = head->subject; | ||
284 | if (head->from!=NULL) | ||
285 | current_from = head->from->list->first; | ||
286 | while (current_from != NULL) { | ||
287 | from = ""; | ||
288 | named_from = false; | ||
289 | current_address=(mailimap_address*)current_from->data; | ||
290 | current_from = current_from->next; | ||
291 | if (current_address->personal_name){ | ||
292 | from+=QString(current_address->personal_name); | ||
293 | from+=" "; | ||
294 | named_from = true; | ||
295 | } | ||
296 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | ||
297 | from+="<"; | ||
298 | } | ||
299 | if (current_address->mailbox_name) { | ||
300 | from+=QString(current_address->mailbox_name); | ||
301 | from+="@"; | ||
302 | } | ||
303 | if (current_address->host_name) { | ||
304 | from+=QString(current_address->host_name); | ||
305 | } | ||
306 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | ||
307 | from+=">"; | ||
308 | } | ||
309 | } | ||
310 | qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s", | ||
311 | from.latin1(), | ||
312 | subject.latin1(),date.latin1()); | ||
313 | m = new RecMail(); | ||
314 | m->setSubject(subject); | ||
315 | m->setFrom(from); | ||
316 | m->setDate(date); | ||
317 | } else { | ||
318 | qDebug("Another type"); | ||
319 | } | ||
320 | } | ||
321 | /* msg is already deleted */ | ||
322 | if (mFlags.testBit(FLAG_DELETED) && m) { | ||
323 | delete m; | ||
324 | m = 0; | ||
325 | } | ||
326 | if (m) { | ||
327 | m->setFlags(mFlags); | ||
328 | } | ||
329 | return m; | ||
330 | } | ||
331 | |||
332 | QString IMAPwrapper::fetchBody(const QString & mailbox,const RecMail&mail) | ||
333 | { | ||
334 | QString body = ""; | ||
335 | const char *server, *user, *pass, *mb; | ||
336 | uint16_t port; | ||
337 | int err = MAILIMAP_NO_ERROR; | ||
338 | clist *result; | ||
339 | clistcell *current; | ||
340 | mailimap_fetch_att *fetchAtt; | ||
341 | mailimap_fetch_type *fetchType; | ||
342 | mailimap_set *set; | ||
343 | |||
344 | mb = mailbox.latin1(); | ||
345 | server = account->getServer().latin1(); | ||
346 | port = account->getPort().toUInt(); | ||
347 | user = account->getUser().latin1(); | ||
348 | pass = account->getPassword().latin1(); | ||
349 | |||
350 | mailimap *imap = mailimap_new( 20, &imap_progress ); | ||
351 | if ( imap == NULL ) { | ||
352 | qDebug("IMAP Memory error"); | ||
353 | return body; | ||
354 | } | ||
355 | |||
356 | /* connect */ | ||
357 | err = mailimap_socket_connect( imap, (char*)server, port ); | ||
358 | if ( err != MAILIMAP_NO_ERROR && | ||
359 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | ||
360 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | ||
361 | qDebug("error connecting server: %s",imap->response); | ||
362 | mailimap_free( imap ); | ||
363 | return body; | ||
364 | } | ||
365 | |||
366 | /* login */ | ||
367 | err = mailimap_login_simple( imap, (char*)user, (char*)pass ); | ||
368 | if ( err != MAILIMAP_NO_ERROR ) { | ||
369 | qDebug("error logging in imap: %s",imap->response); | ||
370 | err = mailimap_close( imap ); | ||
371 | mailimap_free( imap ); | ||
372 | return body; | ||
373 | } | ||
374 | |||
375 | /* select mailbox READONLY for operations */ | ||
376 | err = mailimap_examine( imap, (char*)mb); | ||
377 | if ( err != MAILIMAP_NO_ERROR ) { | ||
378 | qDebug("error selecting mailbox: %s",imap->response); | ||
379 | err = mailimap_logout( imap ); | ||
380 | err = mailimap_close( imap ); | ||
381 | mailimap_free( imap ); | ||
382 | return body; | ||
383 | } | ||
384 | result = clist_new(); | ||
385 | /* the range has to start at 1!!! not with 0!!!! */ | ||
386 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | ||
387 | fetchAtt = mailimap_fetch_att_new_rfc822_text(); | ||
388 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | ||
389 | err = mailimap_fetch( imap, set, fetchType, &result ); | ||
390 | mailimap_set_free( set ); | ||
391 | mailimap_fetch_type_free( fetchType ); | ||
392 | |||
393 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | ||
394 | mailimap_msg_att * msg_att; | ||
395 | msg_att = (mailimap_msg_att*)current->data; | ||
396 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; | ||
397 | |||
398 | if (item->msg_att_static && item->msg_att_static->rfc822_text) { | ||
399 | body = item->msg_att_static->rfc822_text; | ||
400 | } | ||
401 | } else { | ||
402 | qDebug("error fetching text: %s",imap->response); | ||
403 | } | ||
404 | |||
405 | err = mailimap_logout( imap ); | ||
406 | err = mailimap_close( imap ); | ||
407 | mailimap_free( imap ); | ||
408 | clist_free(result); | ||
409 | |||
410 | return body; | ||
411 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/logindialog.cpp b/noncore/net/mail/libmailwrapper/logindialog.cpp new file mode 100644 index 0000000..d2c6a07 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/logindialog.cpp | |||
@@ -0,0 +1,26 @@ | |||
1 | #include <qlineedit.h> | ||
2 | |||
3 | #include "logindialog.h" | ||
4 | |||
5 | LoginDialog::LoginDialog( QString user, QString pass, QWidget *parent, const char *name, bool modal, WFlags flags ) | ||
6 | : LoginDialogUI( parent, name, modal, flags ) | ||
7 | { | ||
8 | userLine->setText( user ); | ||
9 | passLine->setText( pass ); | ||
10 | _user = user; | ||
11 | _pass = pass; | ||
12 | |||
13 | if ( user.isEmpty() ) { | ||
14 | userLine->setFocus(); | ||
15 | } else { | ||
16 | passLine->setFocus(); | ||
17 | } | ||
18 | } | ||
19 | |||
20 | void LoginDialog::accept() | ||
21 | { | ||
22 | _user.replace( 0, _user.length(), userLine->text() ); | ||
23 | _pass.replace( 0, _pass.length(), passLine->text() ); | ||
24 | |||
25 | QDialog::accept(); | ||
26 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/logindialog.h b/noncore/net/mail/libmailwrapper/logindialog.h new file mode 100644 index 0000000..7a0d1b0 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/logindialog.h | |||
@@ -0,0 +1,23 @@ | |||
1 | #ifndef LOGINDIALOG_H | ||
2 | #define LOGINDIALOG_H | ||
3 | |||
4 | #include "logindialogui.h" | ||
5 | |||
6 | class LoginDialog : public LoginDialogUI | ||
7 | { | ||
8 | Q_OBJECT | ||
9 | |||
10 | public: | ||
11 | LoginDialog( QString user, QString pass, QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags flags = 0 ); | ||
12 | QString getUser() { return _user; } | ||
13 | QString getPassword() { return _pass; } | ||
14 | |||
15 | protected slots: | ||
16 | void accept(); | ||
17 | |||
18 | private: | ||
19 | QString _user, _pass; | ||
20 | |||
21 | }; | ||
22 | |||
23 | #endif | ||
diff --git a/noncore/net/mail/libmailwrapper/logindialogui.ui b/noncore/net/mail/libmailwrapper/logindialogui.ui new file mode 100644 index 0000000..565f777 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/logindialogui.ui | |||
@@ -0,0 +1,83 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>LoginDialogUI</class> | ||
3 | <widget> | ||
4 | <class>QDialog</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>LoginDialogUI</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>196</width> | ||
15 | <height>110</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Login</string> | ||
21 | </property> | ||
22 | <property> | ||
23 | <name>layoutMargin</name> | ||
24 | </property> | ||
25 | <property> | ||
26 | <name>layoutSpacing</name> | ||
27 | </property> | ||
28 | <grid> | ||
29 | <property stdset="1"> | ||
30 | <name>margin</name> | ||
31 | <number>4</number> | ||
32 | </property> | ||
33 | <property stdset="1"> | ||
34 | <name>spacing</name> | ||
35 | <number>3</number> | ||
36 | </property> | ||
37 | <widget row="0" column="0" > | ||
38 | <class>QLabel</class> | ||
39 | <property stdset="1"> | ||
40 | <name>name</name> | ||
41 | <cstring>userLabel</cstring> | ||
42 | </property> | ||
43 | <property stdset="1"> | ||
44 | <name>text</name> | ||
45 | <string>User</string> | ||
46 | </property> | ||
47 | </widget> | ||
48 | <widget row="1" column="0" > | ||
49 | <class>QLineEdit</class> | ||
50 | <property stdset="1"> | ||
51 | <name>name</name> | ||
52 | <cstring>userLine</cstring> | ||
53 | </property> | ||
54 | </widget> | ||
55 | <widget row="3" column="0" > | ||
56 | <class>QLineEdit</class> | ||
57 | <property stdset="1"> | ||
58 | <name>name</name> | ||
59 | <cstring>passLine</cstring> | ||
60 | </property> | ||
61 | <property stdset="1"> | ||
62 | <name>echoMode</name> | ||
63 | <enum>Password</enum> | ||
64 | </property> | ||
65 | </widget> | ||
66 | <widget row="2" column="0" > | ||
67 | <class>QLabel</class> | ||
68 | <property stdset="1"> | ||
69 | <name>name</name> | ||
70 | <cstring>passLabel</cstring> | ||
71 | </property> | ||
72 | <property stdset="1"> | ||
73 | <name>text</name> | ||
74 | <string>Password</string> | ||
75 | </property> | ||
76 | </widget> | ||
77 | </grid> | ||
78 | </widget> | ||
79 | <tabstops> | ||
80 | <tabstop>userLine</tabstop> | ||
81 | <tabstop>passLine</tabstop> | ||
82 | </tabstops> | ||
83 | </UI> | ||
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp new file mode 100644 index 0000000..17bed65 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp | |||
@@ -0,0 +1,643 @@ | |||
1 | #include <qfileinfo.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <sys/stat.h> | ||
4 | #include <sys/types.h> | ||
5 | #include <unistd.h> | ||
6 | #include <fcntl.h> | ||
7 | #include <string.h> | ||
8 | #include <qdir.h> | ||
9 | #include <qtextstream.h> | ||
10 | |||
11 | #include "mailwrapper.h" | ||
12 | #include "logindialog.h" | ||
13 | #include "mail.h" | ||
14 | #include "defines.h" | ||
15 | |||
16 | Attachment::Attachment( DocLnk lnk ) | ||
17 | { | ||
18 | doc = lnk; | ||
19 | size = QFileInfo( doc.file() ).size(); | ||
20 | } | ||
21 | |||
22 | Folder::Folder(const QString&tmp_name ) | ||
23 | { | ||
24 | name = tmp_name; | ||
25 | nameDisplay = name; | ||
26 | |||
27 | for ( int pos = nameDisplay.find( '&' ); pos != -1; | ||
28 | pos = nameDisplay.find( '&' ) ) { | ||
29 | int end = nameDisplay.find( '-' ); | ||
30 | if ( end == -1 || end <= pos ) break; | ||
31 | QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 ); | ||
32 | // TODO: do real base64 decoding here ! | ||
33 | if ( str64.compare( "APw" ) == 0 ) { | ||
34 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" ); | ||
35 | } else if ( str64.compare( "APY" ) == 0 ) { | ||
36 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" ); | ||
37 | } | ||
38 | } | ||
39 | |||
40 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); | ||
41 | } | ||
42 | |||
43 | MailWrapper::MailWrapper( Settings *s ) | ||
44 | : QObject() | ||
45 | { | ||
46 | settings = s; | ||
47 | } | ||
48 | |||
49 | QString MailWrapper::mailsmtpError( int errnum ) | ||
50 | { | ||
51 | switch ( errnum ) { | ||
52 | case MAILSMTP_NO_ERROR: | ||
53 | return tr( "No error" ); | ||
54 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | ||
55 | return tr( "Unexpected error code" ); | ||
56 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | ||
57 | return tr( "Service not available" ); | ||
58 | case MAILSMTP_ERROR_STREAM: | ||
59 | return tr( "Stream error" ); | ||
60 | case MAILSMTP_ERROR_HOSTNAME: | ||
61 | return tr( "gethostname() failed" ); | ||
62 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | ||
63 | return tr( "Not implemented" ); | ||
64 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | ||
65 | return tr( "Error, action not taken" ); | ||
66 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | ||
67 | return tr( "Data exceeds storage allocation" ); | ||
68 | case MAILSMTP_ERROR_IN_PROCESSING: | ||
69 | return tr( "Error in processing" ); | ||
70 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | ||
71 | // return tr( "Insufficient system storage" ); | ||
72 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | ||
73 | return tr( "Mailbox unavailable" ); | ||
74 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | ||
75 | return tr( "Mailbox name not allowed" ); | ||
76 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | ||
77 | return tr( "Bad command sequence" ); | ||
78 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | ||
79 | return tr( "User not local" ); | ||
80 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | ||
81 | return tr( "Transaction failed" ); | ||
82 | case MAILSMTP_ERROR_MEMORY: | ||
83 | return tr( "Memory error" ); | ||
84 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | ||
85 | return tr( "Connection refused" ); | ||
86 | default: | ||
87 | return tr( "Unknown error code" ); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) | ||
92 | { | ||
93 | return mailimf_mailbox_new( strdup( name.latin1() ), | ||
94 | strdup( mail.latin1() ) ); | ||
95 | } | ||
96 | |||
97 | mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) | ||
98 | { | ||
99 | mailimf_address_list *addresses; | ||
100 | |||
101 | if ( addr.isEmpty() ) return NULL; | ||
102 | |||
103 | addresses = mailimf_address_list_new_empty(); | ||
104 | |||
105 | QStringList list = QStringList::split( ',', addr ); | ||
106 | QStringList::Iterator it; | ||
107 | for ( it = list.begin(); it != list.end(); it++ ) { | ||
108 | char *str = strdup( (*it).latin1() ); | ||
109 | int err = mailimf_address_list_add_parse( addresses, str ); | ||
110 | if ( err != MAILIMF_NO_ERROR ) { | ||
111 | qDebug( "Error parsing" ); | ||
112 | qDebug( *it ); | ||
113 | free( str ); | ||
114 | } else { | ||
115 | qDebug( "Parse success! :)" ); | ||
116 | } | ||
117 | } | ||
118 | |||
119 | return addresses; | ||
120 | } | ||
121 | |||
122 | mailimf_fields *MailWrapper::createImfFields( Mail *mail ) | ||
123 | { | ||
124 | mailimf_fields *fields; | ||
125 | mailimf_field *xmailer; | ||
126 | mailimf_mailbox *sender, *fromBox; | ||
127 | mailimf_mailbox_list *from; | ||
128 | mailimf_address_list *to, *cc, *bcc, *reply; | ||
129 | char *subject = strdup( mail->getSubject().latin1() ); | ||
130 | int err; | ||
131 | |||
132 | sender = newMailbox( mail->getName(), mail->getMail() ); | ||
133 | if ( sender == NULL ) goto err_free; | ||
134 | |||
135 | fromBox = newMailbox( mail->getName(), mail->getMail() ); | ||
136 | if ( fromBox == NULL ) goto err_free_sender; | ||
137 | |||
138 | from = mailimf_mailbox_list_new_empty(); | ||
139 | if ( from == NULL ) goto err_free_fromBox; | ||
140 | |||
141 | err = mailimf_mailbox_list_add( from, fromBox ); | ||
142 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; | ||
143 | |||
144 | to = parseAddresses( mail->getTo() ); | ||
145 | if ( to == NULL ) goto err_free_from; | ||
146 | |||
147 | cc = parseAddresses( mail->getCC() ); | ||
148 | bcc = parseAddresses( mail->getBCC() ); | ||
149 | reply = parseAddresses( mail->getReply() ); | ||
150 | |||
151 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | ||
152 | NULL, NULL, subject ); | ||
153 | if ( fields == NULL ) goto err_free_reply; | ||
154 | |||
155 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | ||
156 | strdup( USER_AGENT ) ); | ||
157 | if ( xmailer == NULL ) goto err_free_fields; | ||
158 | |||
159 | err = mailimf_fields_add( fields, xmailer ); | ||
160 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; | ||
161 | |||
162 | return fields; // Success :) | ||
163 | |||
164 | err_free_xmailer: | ||
165 | mailimf_field_free( xmailer ); | ||
166 | err_free_fields: | ||
167 | mailimf_fields_free( fields ); | ||
168 | err_free_reply: | ||
169 | mailimf_address_list_free( reply ); | ||
170 | mailimf_address_list_free( bcc ); | ||
171 | mailimf_address_list_free( cc ); | ||
172 | mailimf_address_list_free( to ); | ||
173 | err_free_from: | ||
174 | mailimf_mailbox_list_free( from ); | ||
175 | err_free_fromBox: | ||
176 | mailimf_mailbox_free( fromBox ); | ||
177 | err_free_sender: | ||
178 | mailimf_mailbox_free( sender ); | ||
179 | err_free: | ||
180 | free( subject ); | ||
181 | qDebug( "createImfFields - error" ); | ||
182 | |||
183 | return NULL; // Error :( | ||
184 | } | ||
185 | |||
186 | mailmime *MailWrapper::buildTxtPart( QString str ) | ||
187 | { | ||
188 | mailmime *txtPart; | ||
189 | mailmime_fields *fields; | ||
190 | mailmime_content *content; | ||
191 | mailmime_parameter *param; | ||
192 | char *txt = strdup( str.latin1() ); | ||
193 | int err; | ||
194 | |||
195 | param = mailmime_parameter_new( strdup( "charset" ), | ||
196 | strdup( "iso-8859-1" ) ); | ||
197 | if ( param == NULL ) goto err_free; | ||
198 | |||
199 | content = mailmime_content_new_with_str( "text/plain" ); | ||
200 | if ( content == NULL ) goto err_free_param; | ||
201 | |||
202 | err = clist_append( content->parameters, param ); | ||
203 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | ||
204 | |||
205 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); | ||
206 | if ( fields == NULL ) goto err_free_content; | ||
207 | |||
208 | txtPart = mailmime_new_empty( content, fields ); | ||
209 | if ( txtPart == NULL ) goto err_free_fields; | ||
210 | |||
211 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); | ||
212 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | ||
213 | |||
214 | return txtPart; // Success :) | ||
215 | |||
216 | err_free_txtPart: | ||
217 | mailmime_free( txtPart ); | ||
218 | err_free_fields: | ||
219 | mailmime_fields_free( fields ); | ||
220 | err_free_content: | ||
221 | mailmime_content_free( content ); | ||
222 | err_free_param: | ||
223 | mailmime_parameter_free( param ); | ||
224 | err_free: | ||
225 | free( txt ); | ||
226 | qDebug( "buildTxtPart - error" ); | ||
227 | |||
228 | return NULL; // Error :( | ||
229 | } | ||
230 | |||
231 | mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) | ||
232 | { | ||
233 | mailmime * filePart; | ||
234 | mailmime_fields * fields; | ||
235 | mailmime_content * content; | ||
236 | mailmime_parameter * param = NULL; | ||
237 | int err; | ||
238 | |||
239 | int pos = filename.findRev( '/' ); | ||
240 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | ||
241 | char *name = strdup( tmp.latin1() ); // just filename | ||
242 | char *file = strdup( filename.latin1() ); // full name with path | ||
243 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain | ||
244 | |||
245 | fields = mailmime_fields_new_filename( | ||
246 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, | ||
247 | MAILMIME_MECHANISM_BASE64 ); | ||
248 | if ( fields == NULL ) goto err_free; | ||
249 | |||
250 | content = mailmime_content_new_with_str( mime ); | ||
251 | if ( content == NULL ) goto err_free_fields; | ||
252 | |||
253 | if ( mimetype.compare( "text/plain" ) == 0 ) { | ||
254 | param = mailmime_parameter_new( strdup( "charset" ), | ||
255 | strdup( "iso-8859-1" ) ); | ||
256 | if ( param == NULL ) goto err_free_content; | ||
257 | |||
258 | err = clist_append( content->parameters, param ); | ||
259 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; | ||
260 | } | ||
261 | |||
262 | filePart = mailmime_new_empty( content, fields ); | ||
263 | if ( filePart == NULL ) goto err_free_param; | ||
264 | |||
265 | err = mailmime_set_body_file( filePart, file ); | ||
266 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | ||
267 | |||
268 | return filePart; // Success :) | ||
269 | |||
270 | err_free_filePart: | ||
271 | mailmime_free( filePart ); | ||
272 | err_free_param: | ||
273 | if ( param != NULL ) mailmime_parameter_free( param ); | ||
274 | err_free_content: | ||
275 | mailmime_content_free( content ); | ||
276 | err_free_fields: | ||
277 | mailmime_fields_free( fields ); | ||
278 | err_free: | ||
279 | free( name ); | ||
280 | free( mime ); | ||
281 | free( file ); | ||
282 | qDebug( "buildFilePart - error" ); | ||
283 | |||
284 | return NULL; // Error :( | ||
285 | } | ||
286 | |||
287 | void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) | ||
288 | { | ||
289 | Attachment *it; | ||
290 | for ( it = files.first(); it; it = files.next() ) { | ||
291 | qDebug( "Adding file" ); | ||
292 | mailmime *filePart; | ||
293 | int err; | ||
294 | |||
295 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); | ||
296 | if ( filePart == NULL ) goto err_free; | ||
297 | |||
298 | err = mailmime_smart_add_part( message, filePart ); | ||
299 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | ||
300 | |||
301 | continue; // Success :) | ||
302 | |||
303 | err_free_filePart: | ||
304 | mailmime_free( filePart ); | ||
305 | err_free: | ||
306 | qDebug( "addFileParts: error adding file:" ); | ||
307 | qDebug( it->getFileName() ); | ||
308 | } | ||
309 | } | ||
310 | |||
311 | mailmime *MailWrapper::createMimeMail( Mail *mail ) | ||
312 | { | ||
313 | mailmime *message, *txtPart; | ||
314 | mailimf_fields *fields; | ||
315 | int err; | ||
316 | |||
317 | fields = createImfFields( mail ); | ||
318 | if ( fields == NULL ) goto err_free; | ||
319 | |||
320 | message = mailmime_new_message_data( NULL ); | ||
321 | if ( message == NULL ) goto err_free_fields; | ||
322 | |||
323 | mailmime_set_imf_fields( message, fields ); | ||
324 | |||
325 | txtPart = buildTxtPart( mail->getMessage() ); | ||
326 | if ( txtPart == NULL ) goto err_free_message; | ||
327 | |||
328 | err = mailmime_smart_add_part( message, txtPart ); | ||
329 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | ||
330 | |||
331 | addFileParts( message, mail->getAttachments() ); | ||
332 | |||
333 | return message; // Success :) | ||
334 | |||
335 | err_free_txtPart: | ||
336 | mailmime_free( txtPart ); | ||
337 | err_free_message: | ||
338 | mailmime_free( message ); | ||
339 | err_free_fields: | ||
340 | mailimf_fields_free( fields ); | ||
341 | err_free: | ||
342 | qDebug( "createMimeMail: error" ); | ||
343 | |||
344 | return NULL; // Error :( | ||
345 | } | ||
346 | |||
347 | mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) | ||
348 | { | ||
349 | mailimf_field *field; | ||
350 | clistiter *it; | ||
351 | |||
352 | it = clist_begin( fields->list ); | ||
353 | while ( it ) { | ||
354 | field = (mailimf_field *) it->data; | ||
355 | if ( field->type == type ) { | ||
356 | return field; | ||
357 | } | ||
358 | it = it->next; | ||
359 | } | ||
360 | |||
361 | return NULL; | ||
362 | } | ||
363 | |||
364 | static void addRcpts( clist *list, mailimf_address_list *addr_list ) | ||
365 | { | ||
366 | clistiter *it, *it2; | ||
367 | |||
368 | for ( it = clist_begin( addr_list->list ); it; it = it->next ) { | ||
369 | mailimf_address *addr; | ||
370 | addr = (mailimf_address *) it->data; | ||
371 | |||
372 | if ( addr->type == MAILIMF_ADDRESS_MAILBOX ) { | ||
373 | esmtp_address_list_add( list, addr->mailbox->addr_spec, 0, NULL ); | ||
374 | } else if ( addr->type == MAILIMF_ADDRESS_GROUP ) { | ||
375 | clist *l = addr->group->mb_list->list; | ||
376 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | ||
377 | mailimf_mailbox *mbox; | ||
378 | mbox = (mailimf_mailbox *) it2->data; | ||
379 | esmtp_address_list_add( list, mbox->addr_spec, 0, NULL ); | ||
380 | } | ||
381 | } | ||
382 | } | ||
383 | } | ||
384 | |||
385 | clist *MailWrapper::createRcptList( mailimf_fields *fields ) | ||
386 | { | ||
387 | clist *rcptList; | ||
388 | mailimf_field *field; | ||
389 | |||
390 | rcptList = esmtp_address_list_new(); | ||
391 | |||
392 | field = getField( fields, MAILIMF_FIELD_TO ); | ||
393 | if ( field && (field->type == MAILIMF_FIELD_TO) | ||
394 | && field->field.to->addr_list ) { | ||
395 | addRcpts( rcptList, field->field.to->addr_list ); | ||
396 | } | ||
397 | |||
398 | field = getField( fields, MAILIMF_FIELD_CC ); | ||
399 | if ( field && (field->type == MAILIMF_FIELD_CC) | ||
400 | && field->field.cc->addr_list ) { | ||
401 | addRcpts( rcptList, field->field.cc->addr_list ); | ||
402 | } | ||
403 | |||
404 | field = getField( fields, MAILIMF_FIELD_BCC ); | ||
405 | if ( field && (field->type == MAILIMF_FIELD_BCC) | ||
406 | && field->field.bcc->addr_list ) { | ||
407 | addRcpts( rcptList, field->field.bcc->addr_list ); | ||
408 | } | ||
409 | |||
410 | return rcptList; | ||
411 | } | ||
412 | |||
413 | char *MailWrapper::getFrom( mailmime *mail ) | ||
414 | { | ||
415 | char *from = NULL; | ||
416 | |||
417 | mailimf_field *ffrom; | ||
418 | ffrom = getField( mail->fields, MAILIMF_FIELD_FROM ); | ||
419 | if ( ffrom && (ffrom->type == MAILIMF_FIELD_FROM) | ||
420 | && ffrom->field.from->mb_list && ffrom->field.from->mb_list->list ) { | ||
421 | clist *cl = ffrom->field.from->mb_list->list; | ||
422 | clistiter *it; | ||
423 | for ( it = clist_begin( cl ); it; it = it->next ) { | ||
424 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | ||
425 | from = strdup( mb->addr_spec ); | ||
426 | } | ||
427 | } | ||
428 | |||
429 | return from; | ||
430 | } | ||
431 | |||
432 | SMTPaccount *MailWrapper::getAccount( QString from ) | ||
433 | { | ||
434 | SMTPaccount *smtp; | ||
435 | |||
436 | QList<Account> list = settings->getAccounts(); | ||
437 | Account *it; | ||
438 | for ( it = list.first(); it; it = list.next() ) { | ||
439 | if ( it->getType().compare( "SMTP" ) == 0 ) { | ||
440 | smtp = static_cast<SMTPaccount *>(it); | ||
441 | if ( smtp->getMail().compare( from ) == 0 ) { | ||
442 | qDebug( "SMTPaccount found for" ); | ||
443 | qDebug( from ); | ||
444 | return smtp; | ||
445 | } | ||
446 | } | ||
447 | } | ||
448 | |||
449 | return NULL; | ||
450 | } | ||
451 | |||
452 | QString MailWrapper::getTmpFile() { | ||
453 | int num = 0; | ||
454 | QString unique; | ||
455 | |||
456 | QDir dir( "/tmp" ); | ||
457 | QStringList::Iterator it; | ||
458 | |||
459 | QStringList list = dir.entryList( "opiemail-tmp-*" ); | ||
460 | do { | ||
461 | unique.setNum( num++ ); | ||
462 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); | ||
463 | |||
464 | return "/tmp/opiemail-tmp-" + unique; | ||
465 | } | ||
466 | |||
467 | void MailWrapper::writeToFile( QString file, mailmime *mail ) | ||
468 | { | ||
469 | FILE *f; | ||
470 | int err, col = 0; | ||
471 | |||
472 | f = fopen( file.latin1(), "w" ); | ||
473 | if ( f == NULL ) { | ||
474 | qDebug( "writeToFile: error opening file" ); | ||
475 | return; | ||
476 | } | ||
477 | |||
478 | err = mailmime_write( f, &col, mail ); | ||
479 | if ( err != MAILIMF_NO_ERROR ) { | ||
480 | fclose( f ); | ||
481 | qDebug( "writeToFile: error writing mailmime" ); | ||
482 | return; | ||
483 | } | ||
484 | |||
485 | fclose( f ); | ||
486 | } | ||
487 | |||
488 | void MailWrapper::readFromFile( QString file, char **data, size_t *size ) | ||
489 | { | ||
490 | char *buf; | ||
491 | struct stat st; | ||
492 | int fd, count = 0, total = 0; | ||
493 | |||
494 | fd = open( file.latin1(), O_RDONLY, 0 ); | ||
495 | if ( fd == -1 ) return; | ||
496 | |||
497 | if ( fstat( fd, &st ) != 0 ) goto err_close; | ||
498 | if ( !st.st_size ) goto err_close; | ||
499 | |||
500 | buf = (char *) malloc( st.st_size ); | ||
501 | if ( !buf ) goto err_close; | ||
502 | |||
503 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { | ||
504 | count = read( fd, buf + total, st.st_size - total ); | ||
505 | total += count; | ||
506 | } | ||
507 | if ( count < 0 ) goto err_free; | ||
508 | |||
509 | *data = buf; | ||
510 | *size = st.st_size; | ||
511 | |||
512 | close( fd ); | ||
513 | |||
514 | return; // Success :) | ||
515 | |||
516 | err_free: | ||
517 | free( buf ); | ||
518 | err_close: | ||
519 | close( fd ); | ||
520 | } | ||
521 | |||
522 | void progress( size_t current, size_t maximum ) | ||
523 | { | ||
524 | qDebug( "Current: %i of %i", current, maximum ); | ||
525 | } | ||
526 | |||
527 | void MailWrapper::smtpSend( mailmime *mail ) | ||
528 | { | ||
529 | mailsmtp *session; | ||
530 | clist *rcpts; | ||
531 | char *from, *data, *server, *user = NULL, *pass = NULL; | ||
532 | size_t size; | ||
533 | int err; | ||
534 | bool ssl; | ||
535 | uint16_t port; | ||
536 | |||
537 | |||
538 | from = getFrom( mail ); | ||
539 | SMTPaccount *smtp = getAccount( from ); | ||
540 | if ( smtp == NULL ) { | ||
541 | free(from); | ||
542 | return; | ||
543 | } | ||
544 | server = strdup( smtp->getServer().latin1() ); | ||
545 | ssl = smtp->getSSL(); | ||
546 | port = smtp->getPort().toUInt(); | ||
547 | rcpts = createRcptList( mail->fields ); | ||
548 | |||
549 | QString file = getTmpFile(); | ||
550 | writeToFile( file, mail ); | ||
551 | readFromFile( file, &data, &size ); | ||
552 | QFile f( file ); | ||
553 | f.remove(); | ||
554 | |||
555 | session = mailsmtp_new( 20, &progress ); | ||
556 | if ( session == NULL ) goto free_mem; | ||
557 | |||
558 | qDebug( "Servername %s at port %i", server, port ); | ||
559 | if ( ssl ) { | ||
560 | qDebug( "SSL session" ); | ||
561 | err = mailsmtp_ssl_connect( session, server, port ); | ||
562 | } else { | ||
563 | qDebug( "No SSL session" ); | ||
564 | err = mailsmtp_socket_connect( session, server, port ); | ||
565 | } | ||
566 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; | ||
567 | |||
568 | err = mailsmtp_init( session ); | ||
569 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | ||
570 | |||
571 | qDebug( "INIT OK" ); | ||
572 | |||
573 | if ( smtp->getLogin() ) { | ||
574 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | ||
575 | // get'em | ||
576 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | ||
577 | login.show(); | ||
578 | if ( QDialog::Accepted == login.exec() ) { | ||
579 | // ok | ||
580 | user = strdup( login.getUser().latin1() ); | ||
581 | pass = strdup( login.getPassword().latin1() ); | ||
582 | } else { | ||
583 | goto free_con_session; | ||
584 | } | ||
585 | } else { | ||
586 | user = strdup( smtp->getUser().latin1() ); | ||
587 | pass = strdup( smtp->getPassword().latin1() ); | ||
588 | } | ||
589 | qDebug( "session->auth: %i", session->auth); | ||
590 | err = mailsmtp_auth( session, user, pass ); | ||
591 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); | ||
592 | qDebug( "Done auth!" ); | ||
593 | } | ||
594 | |||
595 | err = mailsmtp_send( session, from, rcpts, data, size ); | ||
596 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | ||
597 | |||
598 | qDebug( "Mail sent." ); | ||
599 | |||
600 | free_con_session: | ||
601 | mailsmtp_quit( session ); | ||
602 | free_mem_session: | ||
603 | mailsmtp_free( session ); | ||
604 | free_mem: | ||
605 | smtp_address_list_free( rcpts ); | ||
606 | free( data ); | ||
607 | free( server ); | ||
608 | if ( smtp->getLogin() ) { | ||
609 | free( user ); | ||
610 | free( pass ); | ||
611 | } | ||
612 | free( from ); | ||
613 | } | ||
614 | |||
615 | void MailWrapper::sendMail( Mail mail ) | ||
616 | { | ||
617 | mailmime *mimeMail; | ||
618 | |||
619 | mimeMail = createMimeMail( &mail ); | ||
620 | if ( mimeMail == NULL ) { | ||
621 | qDebug( "sendMail: error creating mime mail" ); | ||
622 | } else { | ||
623 | smtpSend( mimeMail ); | ||
624 | mailmime_free( mimeMail ); | ||
625 | } | ||
626 | } | ||
627 | |||
628 | Mail::Mail() | ||
629 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") | ||
630 | { | ||
631 | } | ||
632 | |||
633 | RecMail::RecMail() | ||
634 | :subject(""),date(""),msg_number(0),msg_flags(7) | ||
635 | { | ||
636 | } | ||
637 | |||
638 | #if 0 | ||
639 | void RecMail::setDate(const QString&aDate) | ||
640 | { | ||
641 | mDate = QDateTime::fromString(aDate); | ||
642 | } | ||
643 | #endif | ||
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h new file mode 100644 index 0000000..3de28a0 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/mailwrapper.h | |||
@@ -0,0 +1,183 @@ | |||
1 | #ifndef MAILWRAPPER_H | ||
2 | #define MAILWRAPPER_H | ||
3 | |||
4 | #include <qpe/applnk.h> | ||
5 | |||
6 | #include <mailmime.h> | ||
7 | #include <mailimf.h> | ||
8 | #include <mailsmtp.h> | ||
9 | #include <mailimap.h> | ||
10 | #include <mailstorage.h> | ||
11 | #include <maildriver.h> | ||
12 | #include <qbitarray.h> | ||
13 | #include <qdatetime.h> | ||
14 | |||
15 | #include "settings.h" | ||
16 | |||
17 | class Attachment | ||
18 | { | ||
19 | public: | ||
20 | Attachment( DocLnk lnk ); | ||
21 | virtual ~Attachment(){} | ||
22 | const QString getFileName()const{ return doc.file(); } | ||
23 | const QString getName()const{ return doc.name(); } | ||
24 | const QString getMimeType()const{ return doc.type(); } | ||
25 | const QPixmap getPixmap()const{ return doc.pixmap(); } | ||
26 | const int getSize()const { return size; } | ||
27 | DocLnk getDocLnk() { return doc; } | ||
28 | |||
29 | protected: | ||
30 | DocLnk doc; | ||
31 | int size; | ||
32 | |||
33 | }; | ||
34 | |||
35 | #define FLAG_ANSWERED 0 | ||
36 | #define FLAG_FLAGGED 1 | ||
37 | #define FLAG_DELETED 2 | ||
38 | #define FLAG_SEEN 3 | ||
39 | #define FLAG_DRAFT 4 | ||
40 | #define FLAG_RECENT 5 | ||
41 | |||
42 | /* a class to describe mails in a mailbox */ | ||
43 | class RecMail | ||
44 | { | ||
45 | public: | ||
46 | RecMail(); | ||
47 | virtual ~RecMail(){} | ||
48 | |||
49 | const int getNumber()const{return msg_number;} | ||
50 | void setNumber(int number){msg_number=number;} | ||
51 | const QString&getDate()const{ return date; } | ||
52 | void setDate( const QString&a ) { date = a; } | ||
53 | const QString&getFrom()const{ return from; } | ||
54 | void setFrom( const QString&a ) { from = a; } | ||
55 | const QString&getSubject()const { return subject; } | ||
56 | void setSubject( const QString&s ) { subject = s; } | ||
57 | void setFlags(const QBitArray&flags){msg_flags = flags;} | ||
58 | const QBitArray&getFlags()const{return msg_flags;} | ||
59 | |||
60 | #if 0 | ||
61 | void setDate(const QString&dstring); | ||
62 | void setDate(const QDateTime&date){mDate = date;} | ||
63 | QString getDate()const{return mDate.toString();} | ||
64 | #endif | ||
65 | protected: | ||
66 | QString subject,date,from; | ||
67 | int msg_number; | ||
68 | QBitArray msg_flags; | ||
69 | #if 0 | ||
70 | QDateTime mDate; | ||
71 | #endif | ||
72 | }; | ||
73 | |||
74 | typedef QList<RecMail> Maillist; | ||
75 | |||
76 | class Mail | ||
77 | { | ||
78 | public: | ||
79 | Mail(); | ||
80 | /* Possible that this destructor must not be declared virtual | ||
81 | * 'cause it seems that it will never have some child classes. | ||
82 | * in this case this object will not get a virtual table -> memory and | ||
83 | * speed will be a little bit better? | ||
84 | */ | ||
85 | virtual ~Mail(){} | ||
86 | void addAttachment( Attachment *att ) { attList.append( att ); } | ||
87 | const QList<Attachment>& getAttachments()const { return attList; } | ||
88 | void removeAttachment( Attachment *att ) { attList.remove( att ); } | ||
89 | const QString&getName()const { return name; } | ||
90 | void setName( QString s ) { name = s; } | ||
91 | const QString&getMail()const{ return mail; } | ||
92 | void setMail( const QString&s ) { mail = s; } | ||
93 | const QString&getTo()const{ return to; } | ||
94 | void setTo( const QString&s ) { to = s; } | ||
95 | const QString&getCC()const{ return cc; } | ||
96 | void setCC( const QString&s ) { cc = s; } | ||
97 | const QString&getBCC()const { return bcc; } | ||
98 | void setBCC( const QString&s ) { bcc = s; } | ||
99 | const QString&getMessage()const { return message; } | ||
100 | void setMessage( const QString&s ) { message = s; } | ||
101 | const QString&getSubject()const { return subject; } | ||
102 | void setSubject( const QString&s ) { subject = s; } | ||
103 | const QString&getReply()const{ return reply; } | ||
104 | void setReply( const QString&a ) { reply = a; } | ||
105 | |||
106 | private: | ||
107 | QList<Attachment> attList; | ||
108 | QString name, mail, to, cc, bcc, reply, subject, message; | ||
109 | }; | ||
110 | |||
111 | class Folder : public QObject | ||
112 | { | ||
113 | Q_OBJECT | ||
114 | |||
115 | public: | ||
116 | Folder( const QString&init_name ); | ||
117 | const QString&getDisplayName()const { return nameDisplay; } | ||
118 | const QString&getName()const { return name; } | ||
119 | virtual bool may_select()const{return true;}; | ||
120 | |||
121 | private: | ||
122 | QString nameDisplay, name; | ||
123 | |||
124 | }; | ||
125 | |||
126 | class IMAPFolder : public Folder | ||
127 | { | ||
128 | public: | ||
129 | IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} | ||
130 | virtual bool may_select()const{return m_MaySelect;} | ||
131 | private: | ||
132 | bool m_MaySelect; | ||
133 | }; | ||
134 | |||
135 | class MailWrapper : public QObject | ||
136 | { | ||
137 | Q_OBJECT | ||
138 | |||
139 | public: | ||
140 | MailWrapper( Settings *s ); | ||
141 | void sendMail( Mail mail ); | ||
142 | |||
143 | private: | ||
144 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | ||
145 | mailimf_address_list *parseAddresses(const QString&addr ); | ||
146 | mailimf_fields *createImfFields( Mail *mail ); | ||
147 | mailmime *buildTxtPart( QString str ); | ||
148 | mailmime *buildFilePart( QString filename, QString mimetype ); | ||
149 | void addFileParts( mailmime *message, QList<Attachment> files ); | ||
150 | mailmime *createMimeMail( Mail *mail ); | ||
151 | void smtpSend( mailmime *mail ); | ||
152 | mailimf_field *getField( mailimf_fields *fields, int type ); | ||
153 | clist *createRcptList( mailimf_fields *fields ); | ||
154 | char *getFrom( mailmime *mail ); | ||
155 | SMTPaccount *getAccount( QString from ); | ||
156 | void writeToFile( QString file, mailmime *mail ); | ||
157 | void readFromFile( QString file, char **data, size_t *size ); | ||
158 | static QString mailsmtpError( int err ); | ||
159 | static QString getTmpFile(); | ||
160 | |||
161 | Settings *settings; | ||
162 | |||
163 | }; | ||
164 | |||
165 | class IMAPwrapper : public QObject | ||
166 | { | ||
167 | Q_OBJECT | ||
168 | |||
169 | public: | ||
170 | IMAPwrapper( IMAPaccount *a ); | ||
171 | QList<IMAPFolder>* listFolders(); | ||
172 | void listMessages(const QString & mailbox,Maillist&target ); | ||
173 | QString fetchBody(const QString & mailbox,const RecMail&mail); | ||
174 | |||
175 | protected: | ||
176 | RecMail*parse_list_result(mailimap_msg_att*); | ||
177 | |||
178 | private: | ||
179 | IMAPaccount *account; | ||
180 | |||
181 | }; | ||
182 | |||
183 | #endif | ||
diff --git a/noncore/net/mail/libmailwrapper/settings.cpp b/noncore/net/mail/libmailwrapper/settings.cpp new file mode 100644 index 0000000..9632301 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/settings.cpp | |||
@@ -0,0 +1,432 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <qdir.h> | ||
3 | |||
4 | #include <qpe/config.h> | ||
5 | |||
6 | #include "settings.h" | ||
7 | #include "defines.h" | ||
8 | |||
9 | Settings::Settings() | ||
10 | : QObject() | ||
11 | { | ||
12 | updateAccounts(); | ||
13 | } | ||
14 | |||
15 | void Settings::checkDirectory() | ||
16 | { | ||
17 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { | ||
18 | system( "mkdir -p $HOME/Applications/opiemail" ); | ||
19 | qDebug( "$HOME/Applications/opiemail created" ); | ||
20 | } | ||
21 | } | ||
22 | |||
23 | QList<Account> Settings::getAccounts() | ||
24 | { | ||
25 | return accounts; | ||
26 | } | ||
27 | |||
28 | void Settings::addAccount( Account *account ) | ||
29 | { | ||
30 | accounts.append( account ); | ||
31 | } | ||
32 | |||
33 | void Settings::delAccount( Account *account ) | ||
34 | { | ||
35 | accounts.remove( account ); | ||
36 | account->remove(); | ||
37 | } | ||
38 | |||
39 | void Settings::updateAccounts() | ||
40 | { | ||
41 | accounts.clear(); | ||
42 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
43 | QStringList::Iterator it; | ||
44 | |||
45 | QStringList imap = dir.entryList( "imap-*" ); | ||
46 | for ( it = imap.begin(); it != imap.end(); it++ ) { | ||
47 | qDebug( "Added IMAP account" ); | ||
48 | IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); | ||
49 | accounts.append( account ); | ||
50 | } | ||
51 | |||
52 | QStringList pop3 = dir.entryList( "pop3-*" ); | ||
53 | for ( it = pop3.begin(); it != pop3.end(); it++ ) { | ||
54 | qDebug( "Added POP account" ); | ||
55 | POP3account *account = new POP3account( (*it).replace(0, 5, "") ); | ||
56 | accounts.append( account ); | ||
57 | } | ||
58 | |||
59 | QStringList smtp = dir.entryList( "smtp-*" ); | ||
60 | for ( it = smtp.begin(); it != smtp.end(); it++ ) { | ||
61 | qDebug( "Added SMTP account" ); | ||
62 | SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); | ||
63 | accounts.append( account ); | ||
64 | } | ||
65 | |||
66 | QStringList nntp = dir.entryList( "nntp-*" ); | ||
67 | for ( it = nntp.begin(); it != nntp.end(); it++ ) { | ||
68 | qDebug( "Added NNTP account" ); | ||
69 | NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); | ||
70 | accounts.append( account ); | ||
71 | } | ||
72 | |||
73 | readAccounts(); | ||
74 | } | ||
75 | |||
76 | void Settings::saveAccounts() | ||
77 | { | ||
78 | checkDirectory(); | ||
79 | Account *it; | ||
80 | |||
81 | for ( it = accounts.first(); it; it = accounts.next() ) { | ||
82 | it->save(); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | void Settings::readAccounts() | ||
87 | { | ||
88 | checkDirectory(); | ||
89 | Account *it; | ||
90 | |||
91 | for ( it = accounts.first(); it; it = accounts.next() ) { | ||
92 | it->read(); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | Account::Account() | ||
97 | { | ||
98 | accountName = "changeMe"; | ||
99 | type = "changeMe"; | ||
100 | ssl = false; | ||
101 | } | ||
102 | |||
103 | void Account::remove() | ||
104 | { | ||
105 | QFile file( getFileName() ); | ||
106 | file.remove(); | ||
107 | } | ||
108 | |||
109 | IMAPaccount::IMAPaccount() | ||
110 | : Account() | ||
111 | { | ||
112 | file = IMAPaccount::getUniqueFileName(); | ||
113 | accountName = "New IMAP Account"; | ||
114 | ssl = false; | ||
115 | type = "IMAP"; | ||
116 | port = IMAP_PORT; | ||
117 | } | ||
118 | |||
119 | IMAPaccount::IMAPaccount( QString filename ) | ||
120 | : Account() | ||
121 | { | ||
122 | file = filename; | ||
123 | accountName = "New IMAP Account"; | ||
124 | ssl = false; | ||
125 | type = "IMAP"; | ||
126 | port = IMAP_PORT; | ||
127 | } | ||
128 | |||
129 | QString IMAPaccount::getUniqueFileName() | ||
130 | { | ||
131 | int num = 0; | ||
132 | QString unique; | ||
133 | |||
134 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
135 | QStringList::Iterator it; | ||
136 | |||
137 | QStringList imap = dir.entryList( "imap-*" ); | ||
138 | do { | ||
139 | unique.setNum( num++ ); | ||
140 | } while ( imap.contains( "imap-" + unique ) > 0 ); | ||
141 | |||
142 | return unique; | ||
143 | } | ||
144 | |||
145 | void IMAPaccount::read() | ||
146 | { | ||
147 | Config *conf = new Config( getFileName(), Config::File ); | ||
148 | conf->setGroup( "IMAP Account" ); | ||
149 | accountName = conf->readEntry( "Account","" ); | ||
150 | if (accountName.isNull()) accountName = ""; | ||
151 | server = conf->readEntry( "Server","" ); | ||
152 | if (server.isNull()) server=""; | ||
153 | port = conf->readEntry( "Port","" ); | ||
154 | if (port.isNull()) port="143"; | ||
155 | ssl = conf->readBoolEntry( "SSL",false ); | ||
156 | user = conf->readEntry( "User","" ); | ||
157 | if (user.isNull()) user = ""; | ||
158 | password = conf->readEntryCrypt( "Password","" ); | ||
159 | if (password.isNull()) password = ""; | ||
160 | prefix = conf->readEntry("MailPrefix",""); | ||
161 | if (prefix.isNull()) prefix = ""; | ||
162 | } | ||
163 | |||
164 | void IMAPaccount::save() | ||
165 | { | ||
166 | qDebug( "saving " + getFileName() ); | ||
167 | Settings::checkDirectory(); | ||
168 | |||
169 | Config *conf = new Config( getFileName(), Config::File ); | ||
170 | conf->setGroup( "IMAP Account" ); | ||
171 | conf->writeEntry( "Account", accountName ); | ||
172 | conf->writeEntry( "Server", server ); | ||
173 | conf->writeEntry( "Port", port ); | ||
174 | conf->writeEntry( "SSL", ssl ); | ||
175 | conf->writeEntry( "User", user ); | ||
176 | conf->writeEntryCrypt( "Password", password ); | ||
177 | conf->writeEntry( "MailPrefix",prefix); | ||
178 | conf->write(); | ||
179 | } | ||
180 | |||
181 | |||
182 | QString IMAPaccount::getFileName() | ||
183 | { | ||
184 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/imap-" + file; | ||
185 | } | ||
186 | |||
187 | POP3account::POP3account() | ||
188 | : Account() | ||
189 | { | ||
190 | file = POP3account::getUniqueFileName(); | ||
191 | accountName = "New POP3 Account"; | ||
192 | ssl = false; | ||
193 | type = "POP3"; | ||
194 | port = POP3_PORT; | ||
195 | } | ||
196 | |||
197 | POP3account::POP3account( QString filename ) | ||
198 | : Account() | ||
199 | { | ||
200 | file = filename; | ||
201 | accountName = "New POP3 Account"; | ||
202 | ssl = false; | ||
203 | type = "POP3"; | ||
204 | port = POP3_PORT; | ||
205 | } | ||
206 | |||
207 | QString POP3account::getUniqueFileName() | ||
208 | { | ||
209 | int num = 0; | ||
210 | QString unique; | ||
211 | |||
212 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
213 | QStringList::Iterator it; | ||
214 | |||
215 | QStringList imap = dir.entryList( "pop3-*" ); | ||
216 | do { | ||
217 | unique.setNum( num++ ); | ||
218 | } while ( imap.contains( "pop3-" + unique ) > 0 ); | ||
219 | |||
220 | return unique; | ||
221 | } | ||
222 | |||
223 | void POP3account::read() | ||
224 | { | ||
225 | Config *conf = new Config( getFileName(), Config::File ); | ||
226 | conf->setGroup( "POP3 Account" ); | ||
227 | accountName = conf->readEntry( "Account" ); | ||
228 | server = conf->readEntry( "Server" ); | ||
229 | port = conf->readEntry( "Port" ); | ||
230 | ssl = conf->readBoolEntry( "SSL" ); | ||
231 | user = conf->readEntry( "User" ); | ||
232 | password = conf->readEntryCrypt( "Password" ); | ||
233 | } | ||
234 | |||
235 | void POP3account::save() | ||
236 | { | ||
237 | qDebug( "saving " + getFileName() ); | ||
238 | Settings::checkDirectory(); | ||
239 | |||
240 | Config *conf = new Config( getFileName(), Config::File ); | ||
241 | conf->setGroup( "POP3 Account" ); | ||
242 | conf->writeEntry( "Account", accountName ); | ||
243 | conf->writeEntry( "Server", server ); | ||
244 | conf->writeEntry( "Port", port ); | ||
245 | conf->writeEntry( "SSL", ssl ); | ||
246 | conf->writeEntry( "User", user ); | ||
247 | conf->writeEntryCrypt( "Password", password ); | ||
248 | conf->write(); | ||
249 | } | ||
250 | |||
251 | |||
252 | QString POP3account::getFileName() | ||
253 | { | ||
254 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/pop3-" + file; | ||
255 | } | ||
256 | |||
257 | SMTPaccount::SMTPaccount() | ||
258 | : Account() | ||
259 | { | ||
260 | file = SMTPaccount::getUniqueFileName(); | ||
261 | accountName = "New SMTP Account"; | ||
262 | ssl = false; | ||
263 | login = false; | ||
264 | useCC = false; | ||
265 | useBCC = false; | ||
266 | useReply = false; | ||
267 | type = "SMTP"; | ||
268 | port = SMTP_PORT; | ||
269 | } | ||
270 | |||
271 | SMTPaccount::SMTPaccount( QString filename ) | ||
272 | : Account() | ||
273 | { | ||
274 | file = filename; | ||
275 | accountName = "New SMTP Account"; | ||
276 | ssl = false; | ||
277 | login = false; | ||
278 | useCC = false; | ||
279 | useBCC = false; | ||
280 | useReply = false; | ||
281 | type = "SMTP"; | ||
282 | port = SMTP_PORT; | ||
283 | } | ||
284 | |||
285 | QString SMTPaccount::getUniqueFileName() | ||
286 | { | ||
287 | int num = 0; | ||
288 | QString unique; | ||
289 | |||
290 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
291 | QStringList::Iterator it; | ||
292 | |||
293 | QStringList imap = dir.entryList( "smtp-*" ); | ||
294 | do { | ||
295 | unique.setNum( num++ ); | ||
296 | } while ( imap.contains( "smtp-" + unique ) > 0 ); | ||
297 | |||
298 | return unique; | ||
299 | } | ||
300 | |||
301 | void SMTPaccount::read() | ||
302 | { | ||
303 | Config *conf = new Config( getFileName(), Config::File ); | ||
304 | conf->setGroup( "SMTP Account" ); | ||
305 | accountName = conf->readEntry( "Account" ); | ||
306 | server = conf->readEntry( "Server" ); | ||
307 | port = conf->readEntry( "Port" ); | ||
308 | ssl = conf->readBoolEntry( "SSL" ); | ||
309 | login = conf->readBoolEntry( "Login" ); | ||
310 | user = conf->readEntry( "User" ); | ||
311 | password = conf->readEntryCrypt( "Password" ); | ||
312 | useCC = conf->readBoolEntry( "useCC" ); | ||
313 | useBCC = conf->readBoolEntry( "useBCC" ); | ||
314 | useReply = conf->readBoolEntry( "useReply" ); | ||
315 | name = conf->readEntry( "Name" ); | ||
316 | mail = conf->readEntry( "Mail" ); | ||
317 | org = conf->readEntry( "Org" ); | ||
318 | cc = conf->readEntry( "CC" ); | ||
319 | bcc = conf->readEntry( "BCC" ); | ||
320 | reply = conf->readEntry( "Reply" ); | ||
321 | signature = conf->readEntry( "Signature" ); | ||
322 | signature = signature.replace( QRegExp( "<br>" ), "\n" ); | ||
323 | } | ||
324 | |||
325 | void SMTPaccount::save() | ||
326 | { | ||
327 | qDebug( "saving " + getFileName() ); | ||
328 | Settings::checkDirectory(); | ||
329 | |||
330 | Config *conf = new Config( getFileName(), Config::File ); | ||
331 | conf->setGroup( "SMTP Account" ); | ||
332 | conf->writeEntry( "Account", accountName ); | ||
333 | conf->writeEntry( "Server", server ); | ||
334 | conf->writeEntry( "Port", port ); | ||
335 | conf->writeEntry( "SSL", ssl ); | ||
336 | conf->writeEntry( "Login", login ); | ||
337 | conf->writeEntry( "User", user ); | ||
338 | conf->writeEntryCrypt( "Password", password ); | ||
339 | conf->writeEntry( "useCC", useCC ); | ||
340 | conf->writeEntry( "useBCC", useBCC ); | ||
341 | conf->writeEntry( "useReply", useReply ); | ||
342 | conf->writeEntry( "Name", name ); | ||
343 | conf->writeEntry( "Mail", mail ); | ||
344 | conf->writeEntry( "Org", org ); | ||
345 | conf->writeEntry( "CC", cc ); | ||
346 | conf->writeEntry( "BCC", bcc ); | ||
347 | conf->writeEntry( "Reply", reply ); | ||
348 | conf->writeEntry( "Signature", | ||
349 | signature.replace( QRegExp( "\\n" ), "<br>" ) ); | ||
350 | conf->write(); | ||
351 | } | ||
352 | |||
353 | |||
354 | QString SMTPaccount::getFileName() | ||
355 | { | ||
356 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/smtp-" + file; | ||
357 | } | ||
358 | |||
359 | NNTPaccount::NNTPaccount() | ||
360 | : Account() | ||
361 | { | ||
362 | file = NNTPaccount::getUniqueFileName(); | ||
363 | accountName = "New NNTP Account"; | ||
364 | ssl = false; | ||
365 | login = false; | ||
366 | type = "NNTP"; | ||
367 | port = NNTP_PORT; | ||
368 | } | ||
369 | |||
370 | NNTPaccount::NNTPaccount( QString filename ) | ||
371 | : Account() | ||
372 | { | ||
373 | file = filename; | ||
374 | accountName = "New NNTP Account"; | ||
375 | ssl = false; | ||
376 | login = false; | ||
377 | type = "NNTP"; | ||
378 | port = NNTP_PORT; | ||
379 | } | ||
380 | |||
381 | QString NNTPaccount::getUniqueFileName() | ||
382 | { | ||
383 | int num = 0; | ||
384 | QString unique; | ||
385 | |||
386 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
387 | QStringList::Iterator it; | ||
388 | |||
389 | QStringList imap = dir.entryList( "nntp-*" ); | ||
390 | do { | ||
391 | unique.setNum( num++ ); | ||
392 | } while ( imap.contains( "nntp-" + unique ) > 0 ); | ||
393 | |||
394 | return unique; | ||
395 | } | ||
396 | |||
397 | void NNTPaccount::read() | ||
398 | { | ||
399 | Config *conf = new Config( getFileName(), Config::File ); | ||
400 | conf->setGroup( "NNTP Account" ); | ||
401 | accountName = conf->readEntry( "Account" ); | ||
402 | server = conf->readEntry( "Server" ); | ||
403 | port = conf->readEntry( "Port" ); | ||
404 | ssl = conf->readBoolEntry( "SSL" ); | ||
405 | login = conf->readBoolEntry( "Login" ); | ||
406 | user = conf->readEntry( "User" ); | ||
407 | password = conf->readEntryCrypt( "Password" ); | ||
408 | } | ||
409 | |||
410 | void NNTPaccount::save() | ||
411 | { | ||
412 | qDebug( "saving " + getFileName() ); | ||
413 | Settings::checkDirectory(); | ||
414 | |||
415 | Config *conf = new Config( getFileName(), Config::File ); | ||
416 | conf->setGroup( "NNTP Account" ); | ||
417 | conf->writeEntry( "Account", accountName ); | ||
418 | conf->writeEntry( "Server", server ); | ||
419 | conf->writeEntry( "Port", port ); | ||
420 | conf->writeEntry( "SSL", ssl ); | ||
421 | conf->writeEntry( "Login", login ); | ||
422 | conf->writeEntry( "User", user ); | ||
423 | conf->writeEntryCrypt( "Password", password ); | ||
424 | conf->write(); | ||
425 | } | ||
426 | |||
427 | |||
428 | QString NNTPaccount::getFileName() | ||
429 | { | ||
430 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/nntp-" + file; | ||
431 | } | ||
432 | |||
diff --git a/noncore/net/mail/libmailwrapper/settings.h b/noncore/net/mail/libmailwrapper/settings.h new file mode 100644 index 0000000..22184a5 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/settings.h | |||
@@ -0,0 +1,166 @@ | |||
1 | #ifndef SETTINGS_H | ||
2 | #define SETTINGS_H | ||
3 | |||
4 | #include <qobject.h> | ||
5 | #include <qlist.h> | ||
6 | |||
7 | class Account | ||
8 | { | ||
9 | |||
10 | public: | ||
11 | Account(); | ||
12 | virtual ~Account() {} | ||
13 | |||
14 | void remove(); | ||
15 | void setAccountName( QString name ) { accountName = name; } | ||
16 | const QString&getAccountName()const{ return accountName; } | ||
17 | const QString&getType()const{ return type; } | ||
18 | |||
19 | void setServer(const QString&str){ server = str; } | ||
20 | const QString&getServer()const{ return server; } | ||
21 | |||
22 | void setPort(const QString&str) { port = str; } | ||
23 | const QString&getPort()const{ return port; } | ||
24 | |||
25 | void setUser(const QString&str){ user = str; } | ||
26 | const QString&getUser()const{ return user; } | ||
27 | |||
28 | void setPassword(const QString&str) { password = str; } | ||
29 | const QString&getPassword()const { return password; } | ||
30 | |||
31 | void setSSL( bool b ) { ssl = b; } | ||
32 | bool getSSL() { return ssl; } | ||
33 | |||
34 | virtual QString getFileName() { return accountName; } | ||
35 | virtual void read() { qDebug( "base reading..." ); } | ||
36 | virtual void save() { qDebug( "base saving..." ); } | ||
37 | |||
38 | protected: | ||
39 | QString accountName, type, server, port, user, password; | ||
40 | bool ssl; | ||
41 | |||
42 | }; | ||
43 | |||
44 | class IMAPaccount : public Account | ||
45 | { | ||
46 | |||
47 | public: | ||
48 | IMAPaccount(); | ||
49 | IMAPaccount( QString filename ); | ||
50 | |||
51 | static QString getUniqueFileName(); | ||
52 | |||
53 | virtual void read(); | ||
54 | virtual void save(); | ||
55 | virtual QString getFileName(); | ||
56 | |||
57 | void setPrefix(const QString&str) {prefix=str;} | ||
58 | const QString&getPrefix()const{return prefix;} | ||
59 | |||
60 | private: | ||
61 | QString file,prefix; | ||
62 | |||
63 | }; | ||
64 | |||
65 | class POP3account : public Account | ||
66 | { | ||
67 | |||
68 | public: | ||
69 | POP3account(); | ||
70 | POP3account( QString filename ); | ||
71 | |||
72 | static QString getUniqueFileName(); | ||
73 | |||
74 | virtual void read(); | ||
75 | virtual void save(); | ||
76 | virtual QString getFileName(); | ||
77 | |||
78 | private: | ||
79 | QString file; | ||
80 | |||
81 | }; | ||
82 | |||
83 | class SMTPaccount : public Account | ||
84 | { | ||
85 | |||
86 | public: | ||
87 | SMTPaccount(); | ||
88 | SMTPaccount( QString filename ); | ||
89 | |||
90 | static QString getUniqueFileName(); | ||
91 | |||
92 | virtual void read(); | ||
93 | virtual void save(); | ||
94 | virtual QString getFileName(); | ||
95 | |||
96 | void setName( QString str ) { name = str; } | ||
97 | QString getName() { return name; } | ||
98 | void setMail( QString str ) { mail = str; } | ||
99 | QString getMail() { return mail; } | ||
100 | void setOrg( QString str ) { org = str; } | ||
101 | QString getOrg() { return org; } | ||
102 | void setUseCC( bool b ) { useCC = b; } | ||
103 | bool getUseCC() { return useCC; } | ||
104 | void setCC( QString str ) { cc = str; } | ||
105 | QString getCC() { return cc; } | ||
106 | void setUseBCC( bool b ) { useBCC = b; } | ||
107 | bool getUseBCC() { return useBCC; } | ||
108 | void setBCC( QString str ) { bcc = str; } | ||
109 | QString getBCC() { return bcc; } | ||
110 | void setUseReply( bool b ) { useReply = b; } | ||
111 | bool getUseReply() { return useReply; } | ||
112 | void setReply( QString str ) { reply = str; } | ||
113 | QString getReply() { return reply; } | ||
114 | void setSignature( QString str ) { signature = str; } | ||
115 | QString getSignature() { return signature; } | ||
116 | void setLogin( bool b ) { login = b; } | ||
117 | bool getLogin() { return login; } | ||
118 | |||
119 | private: | ||
120 | QString file, name, mail, org, cc, bcc, reply, signature; | ||
121 | bool useCC, useBCC, useReply, login; | ||
122 | |||
123 | }; | ||
124 | |||
125 | class NNTPaccount : public Account | ||
126 | { | ||
127 | |||
128 | public: | ||
129 | NNTPaccount(); | ||
130 | NNTPaccount( QString filename ); | ||
131 | |||
132 | static QString getUniqueFileName(); | ||
133 | |||
134 | virtual void read(); | ||
135 | virtual void save(); | ||
136 | virtual QString getFileName(); | ||
137 | |||
138 | void setLogin( bool b ) { login = b; } | ||
139 | bool getLogin() { return login; } | ||
140 | |||
141 | private: | ||
142 | QString file; | ||
143 | bool login; | ||
144 | |||
145 | }; | ||
146 | |||
147 | class Settings : public QObject | ||
148 | { | ||
149 | Q_OBJECT | ||
150 | |||
151 | public: | ||
152 | Settings(); | ||
153 | QList<Account> getAccounts(); | ||
154 | void addAccount(Account *account); | ||
155 | void delAccount(Account *account); | ||
156 | void saveAccounts(); | ||
157 | void readAccounts(); | ||
158 | static void checkDirectory(); | ||
159 | |||
160 | private: | ||
161 | void updateAccounts(); | ||
162 | QList<Account> accounts; | ||
163 | |||
164 | }; | ||
165 | |||
166 | #endif | ||
diff --git a/noncore/net/mail/logindialog.cpp b/noncore/net/mail/logindialog.cpp new file mode 100644 index 0000000..d2c6a07 --- a/dev/null +++ b/noncore/net/mail/logindialog.cpp | |||
@@ -0,0 +1,26 @@ | |||
1 | #include <qlineedit.h> | ||
2 | |||
3 | #include "logindialog.h" | ||
4 | |||
5 | LoginDialog::LoginDialog( QString user, QString pass, QWidget *parent, const char *name, bool modal, WFlags flags ) | ||
6 | : LoginDialogUI( parent, name, modal, flags ) | ||
7 | { | ||
8 | userLine->setText( user ); | ||
9 | passLine->setText( pass ); | ||
10 | _user = user; | ||
11 | _pass = pass; | ||
12 | |||
13 | if ( user.isEmpty() ) { | ||
14 | userLine->setFocus(); | ||
15 | } else { | ||
16 | passLine->setFocus(); | ||
17 | } | ||
18 | } | ||
19 | |||
20 | void LoginDialog::accept() | ||
21 | { | ||
22 | _user.replace( 0, _user.length(), userLine->text() ); | ||
23 | _pass.replace( 0, _pass.length(), passLine->text() ); | ||
24 | |||
25 | QDialog::accept(); | ||
26 | } | ||
diff --git a/noncore/net/mail/logindialog.h b/noncore/net/mail/logindialog.h new file mode 100644 index 0000000..7a0d1b0 --- a/dev/null +++ b/noncore/net/mail/logindialog.h | |||
@@ -0,0 +1,23 @@ | |||
1 | #ifndef LOGINDIALOG_H | ||
2 | #define LOGINDIALOG_H | ||
3 | |||
4 | #include "logindialogui.h" | ||
5 | |||
6 | class LoginDialog : public LoginDialogUI | ||
7 | { | ||
8 | Q_OBJECT | ||
9 | |||
10 | public: | ||
11 | LoginDialog( QString user, QString pass, QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags flags = 0 ); | ||
12 | QString getUser() { return _user; } | ||
13 | QString getPassword() { return _pass; } | ||
14 | |||
15 | protected slots: | ||
16 | void accept(); | ||
17 | |||
18 | private: | ||
19 | QString _user, _pass; | ||
20 | |||
21 | }; | ||
22 | |||
23 | #endif | ||
diff --git a/noncore/net/mail/logindialogui.ui b/noncore/net/mail/logindialogui.ui new file mode 100644 index 0000000..565f777 --- a/dev/null +++ b/noncore/net/mail/logindialogui.ui | |||
@@ -0,0 +1,83 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>LoginDialogUI</class> | ||
3 | <widget> | ||
4 | <class>QDialog</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>LoginDialogUI</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>196</width> | ||
15 | <height>110</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Login</string> | ||
21 | </property> | ||
22 | <property> | ||
23 | <name>layoutMargin</name> | ||
24 | </property> | ||
25 | <property> | ||
26 | <name>layoutSpacing</name> | ||
27 | </property> | ||
28 | <grid> | ||
29 | <property stdset="1"> | ||
30 | <name>margin</name> | ||
31 | <number>4</number> | ||
32 | </property> | ||
33 | <property stdset="1"> | ||
34 | <name>spacing</name> | ||
35 | <number>3</number> | ||
36 | </property> | ||
37 | <widget row="0" column="0" > | ||
38 | <class>QLabel</class> | ||
39 | <property stdset="1"> | ||
40 | <name>name</name> | ||
41 | <cstring>userLabel</cstring> | ||
42 | </property> | ||
43 | <property stdset="1"> | ||
44 | <name>text</name> | ||
45 | <string>User</string> | ||
46 | </property> | ||
47 | </widget> | ||
48 | <widget row="1" column="0" > | ||
49 | <class>QLineEdit</class> | ||
50 | <property stdset="1"> | ||
51 | <name>name</name> | ||
52 | <cstring>userLine</cstring> | ||
53 | </property> | ||
54 | </widget> | ||
55 | <widget row="3" column="0" > | ||
56 | <class>QLineEdit</class> | ||
57 | <property stdset="1"> | ||
58 | <name>name</name> | ||
59 | <cstring>passLine</cstring> | ||
60 | </property> | ||
61 | <property stdset="1"> | ||
62 | <name>echoMode</name> | ||
63 | <enum>Password</enum> | ||
64 | </property> | ||
65 | </widget> | ||
66 | <widget row="2" column="0" > | ||
67 | <class>QLabel</class> | ||
68 | <property stdset="1"> | ||
69 | <name>name</name> | ||
70 | <cstring>passLabel</cstring> | ||
71 | </property> | ||
72 | <property stdset="1"> | ||
73 | <name>text</name> | ||
74 | <string>Password</string> | ||
75 | </property> | ||
76 | </widget> | ||
77 | </grid> | ||
78 | </widget> | ||
79 | <tabstops> | ||
80 | <tabstop>userLine</tabstop> | ||
81 | <tabstop>passLine</tabstop> | ||
82 | </tabstops> | ||
83 | </UI> | ||
diff --git a/noncore/net/mail/mail.pro b/noncore/net/mail/mail.pro new file mode 100644 index 0000000..098817a --- a/dev/null +++ b/noncore/net/mail/mail.pro | |||
@@ -0,0 +1,42 @@ | |||
1 | CONFIG += qt warn_on debug quick-app | ||
2 | |||
3 | HEADERS = defines.h \ | ||
4 | logindialog.h \ | ||
5 | settings.h \ | ||
6 | editaccounts.h \ | ||
7 | mailwrapper.h \ | ||
8 | composemail.h \ | ||
9 | accountview.h \ | ||
10 | mainwindow.h \ | ||
11 | readmailgui.h \ | ||
12 | opiemail.h | ||
13 | |||
14 | SOURCES = main.cpp \ | ||
15 | opiemail.cpp \ | ||
16 | mainwindow.cpp \ | ||
17 | accountview.cpp \ | ||
18 | composemail.cpp \ | ||
19 | mailwrapper.cpp \ | ||
20 | imapwrapper.cpp \ | ||
21 | addresspicker.cpp \ | ||
22 | editaccounts.cpp \ | ||
23 | logindialog.cpp \ | ||
24 | readmailgui.cpp \ | ||
25 | settings.cpp | ||
26 | |||
27 | INTERFACES = editaccountsui.ui \ | ||
28 | selectmailtypeui.ui \ | ||
29 | imapconfigui.ui \ | ||
30 | pop3configui.ui \ | ||
31 | nntpconfigui.ui \ | ||
32 | smtpconfigui.ui \ | ||
33 | addresspickerui.ui \ | ||
34 | logindialogui.ui \ | ||
35 | composemailui.ui | ||
36 | |||
37 | INCLUDEPATH += $(OPIEDIR)/include | ||
38 | INCLUDEPATH += $(OPIEDIR)/include/libetpan | ||
39 | LIBS += -lqpe -lopie -letpan -lssl -lcrypto -ldb | ||
40 | TARGET = opiemail | ||
41 | |||
42 | include ( $(OPIEDIR)/include.pro ) | ||
diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp new file mode 100644 index 0000000..17bed65 --- a/dev/null +++ b/noncore/net/mail/mailwrapper.cpp | |||
@@ -0,0 +1,643 @@ | |||
1 | #include <qfileinfo.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <sys/stat.h> | ||
4 | #include <sys/types.h> | ||
5 | #include <unistd.h> | ||
6 | #include <fcntl.h> | ||
7 | #include <string.h> | ||
8 | #include <qdir.h> | ||
9 | #include <qtextstream.h> | ||
10 | |||
11 | #include "mailwrapper.h" | ||
12 | #include "logindialog.h" | ||
13 | #include "mail.h" | ||
14 | #include "defines.h" | ||
15 | |||
16 | Attachment::Attachment( DocLnk lnk ) | ||
17 | { | ||
18 | doc = lnk; | ||
19 | size = QFileInfo( doc.file() ).size(); | ||
20 | } | ||
21 | |||
22 | Folder::Folder(const QString&tmp_name ) | ||
23 | { | ||
24 | name = tmp_name; | ||
25 | nameDisplay = name; | ||
26 | |||
27 | for ( int pos = nameDisplay.find( '&' ); pos != -1; | ||
28 | pos = nameDisplay.find( '&' ) ) { | ||
29 | int end = nameDisplay.find( '-' ); | ||
30 | if ( end == -1 || end <= pos ) break; | ||
31 | QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 ); | ||
32 | // TODO: do real base64 decoding here ! | ||
33 | if ( str64.compare( "APw" ) == 0 ) { | ||
34 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" ); | ||
35 | } else if ( str64.compare( "APY" ) == 0 ) { | ||
36 | nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" ); | ||
37 | } | ||
38 | } | ||
39 | |||
40 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); | ||
41 | } | ||
42 | |||
43 | MailWrapper::MailWrapper( Settings *s ) | ||
44 | : QObject() | ||
45 | { | ||
46 | settings = s; | ||
47 | } | ||
48 | |||
49 | QString MailWrapper::mailsmtpError( int errnum ) | ||
50 | { | ||
51 | switch ( errnum ) { | ||
52 | case MAILSMTP_NO_ERROR: | ||
53 | return tr( "No error" ); | ||
54 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | ||
55 | return tr( "Unexpected error code" ); | ||
56 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | ||
57 | return tr( "Service not available" ); | ||
58 | case MAILSMTP_ERROR_STREAM: | ||
59 | return tr( "Stream error" ); | ||
60 | case MAILSMTP_ERROR_HOSTNAME: | ||
61 | return tr( "gethostname() failed" ); | ||
62 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | ||
63 | return tr( "Not implemented" ); | ||
64 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | ||
65 | return tr( "Error, action not taken" ); | ||
66 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | ||
67 | return tr( "Data exceeds storage allocation" ); | ||
68 | case MAILSMTP_ERROR_IN_PROCESSING: | ||
69 | return tr( "Error in processing" ); | ||
70 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | ||
71 | // return tr( "Insufficient system storage" ); | ||
72 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | ||
73 | return tr( "Mailbox unavailable" ); | ||
74 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | ||
75 | return tr( "Mailbox name not allowed" ); | ||
76 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | ||
77 | return tr( "Bad command sequence" ); | ||
78 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | ||
79 | return tr( "User not local" ); | ||
80 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | ||
81 | return tr( "Transaction failed" ); | ||
82 | case MAILSMTP_ERROR_MEMORY: | ||
83 | return tr( "Memory error" ); | ||
84 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | ||
85 | return tr( "Connection refused" ); | ||
86 | default: | ||
87 | return tr( "Unknown error code" ); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) | ||
92 | { | ||
93 | return mailimf_mailbox_new( strdup( name.latin1() ), | ||
94 | strdup( mail.latin1() ) ); | ||
95 | } | ||
96 | |||
97 | mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) | ||
98 | { | ||
99 | mailimf_address_list *addresses; | ||
100 | |||
101 | if ( addr.isEmpty() ) return NULL; | ||
102 | |||
103 | addresses = mailimf_address_list_new_empty(); | ||
104 | |||
105 | QStringList list = QStringList::split( ',', addr ); | ||
106 | QStringList::Iterator it; | ||
107 | for ( it = list.begin(); it != list.end(); it++ ) { | ||
108 | char *str = strdup( (*it).latin1() ); | ||
109 | int err = mailimf_address_list_add_parse( addresses, str ); | ||
110 | if ( err != MAILIMF_NO_ERROR ) { | ||
111 | qDebug( "Error parsing" ); | ||
112 | qDebug( *it ); | ||
113 | free( str ); | ||
114 | } else { | ||
115 | qDebug( "Parse success! :)" ); | ||
116 | } | ||
117 | } | ||
118 | |||
119 | return addresses; | ||
120 | } | ||
121 | |||
122 | mailimf_fields *MailWrapper::createImfFields( Mail *mail ) | ||
123 | { | ||
124 | mailimf_fields *fields; | ||
125 | mailimf_field *xmailer; | ||
126 | mailimf_mailbox *sender, *fromBox; | ||
127 | mailimf_mailbox_list *from; | ||
128 | mailimf_address_list *to, *cc, *bcc, *reply; | ||
129 | char *subject = strdup( mail->getSubject().latin1() ); | ||
130 | int err; | ||
131 | |||
132 | sender = newMailbox( mail->getName(), mail->getMail() ); | ||
133 | if ( sender == NULL ) goto err_free; | ||
134 | |||
135 | fromBox = newMailbox( mail->getName(), mail->getMail() ); | ||
136 | if ( fromBox == NULL ) goto err_free_sender; | ||
137 | |||
138 | from = mailimf_mailbox_list_new_empty(); | ||
139 | if ( from == NULL ) goto err_free_fromBox; | ||
140 | |||
141 | err = mailimf_mailbox_list_add( from, fromBox ); | ||
142 | if ( err != MAILIMF_NO_ERROR ) goto err_free_from; | ||
143 | |||
144 | to = parseAddresses( mail->getTo() ); | ||
145 | if ( to == NULL ) goto err_free_from; | ||
146 | |||
147 | cc = parseAddresses( mail->getCC() ); | ||
148 | bcc = parseAddresses( mail->getBCC() ); | ||
149 | reply = parseAddresses( mail->getReply() ); | ||
150 | |||
151 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | ||
152 | NULL, NULL, subject ); | ||
153 | if ( fields == NULL ) goto err_free_reply; | ||
154 | |||
155 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | ||
156 | strdup( USER_AGENT ) ); | ||
157 | if ( xmailer == NULL ) goto err_free_fields; | ||
158 | |||
159 | err = mailimf_fields_add( fields, xmailer ); | ||
160 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; | ||
161 | |||
162 | return fields; // Success :) | ||
163 | |||
164 | err_free_xmailer: | ||
165 | mailimf_field_free( xmailer ); | ||
166 | err_free_fields: | ||
167 | mailimf_fields_free( fields ); | ||
168 | err_free_reply: | ||
169 | mailimf_address_list_free( reply ); | ||
170 | mailimf_address_list_free( bcc ); | ||
171 | mailimf_address_list_free( cc ); | ||
172 | mailimf_address_list_free( to ); | ||
173 | err_free_from: | ||
174 | mailimf_mailbox_list_free( from ); | ||
175 | err_free_fromBox: | ||
176 | mailimf_mailbox_free( fromBox ); | ||
177 | err_free_sender: | ||
178 | mailimf_mailbox_free( sender ); | ||
179 | err_free: | ||
180 | free( subject ); | ||
181 | qDebug( "createImfFields - error" ); | ||
182 | |||
183 | return NULL; // Error :( | ||
184 | } | ||
185 | |||
186 | mailmime *MailWrapper::buildTxtPart( QString str ) | ||
187 | { | ||
188 | mailmime *txtPart; | ||
189 | mailmime_fields *fields; | ||
190 | mailmime_content *content; | ||
191 | mailmime_parameter *param; | ||
192 | char *txt = strdup( str.latin1() ); | ||
193 | int err; | ||
194 | |||
195 | param = mailmime_parameter_new( strdup( "charset" ), | ||
196 | strdup( "iso-8859-1" ) ); | ||
197 | if ( param == NULL ) goto err_free; | ||
198 | |||
199 | content = mailmime_content_new_with_str( "text/plain" ); | ||
200 | if ( content == NULL ) goto err_free_param; | ||
201 | |||
202 | err = clist_append( content->parameters, param ); | ||
203 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | ||
204 | |||
205 | fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); | ||
206 | if ( fields == NULL ) goto err_free_content; | ||
207 | |||
208 | txtPart = mailmime_new_empty( content, fields ); | ||
209 | if ( txtPart == NULL ) goto err_free_fields; | ||
210 | |||
211 | err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); | ||
212 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | ||
213 | |||
214 | return txtPart; // Success :) | ||
215 | |||
216 | err_free_txtPart: | ||
217 | mailmime_free( txtPart ); | ||
218 | err_free_fields: | ||
219 | mailmime_fields_free( fields ); | ||
220 | err_free_content: | ||
221 | mailmime_content_free( content ); | ||
222 | err_free_param: | ||
223 | mailmime_parameter_free( param ); | ||
224 | err_free: | ||
225 | free( txt ); | ||
226 | qDebug( "buildTxtPart - error" ); | ||
227 | |||
228 | return NULL; // Error :( | ||
229 | } | ||
230 | |||
231 | mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) | ||
232 | { | ||
233 | mailmime * filePart; | ||
234 | mailmime_fields * fields; | ||
235 | mailmime_content * content; | ||
236 | mailmime_parameter * param = NULL; | ||
237 | int err; | ||
238 | |||
239 | int pos = filename.findRev( '/' ); | ||
240 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | ||
241 | char *name = strdup( tmp.latin1() ); // just filename | ||
242 | char *file = strdup( filename.latin1() ); // full name with path | ||
243 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain | ||
244 | |||
245 | fields = mailmime_fields_new_filename( | ||
246 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, | ||
247 | MAILMIME_MECHANISM_BASE64 ); | ||
248 | if ( fields == NULL ) goto err_free; | ||
249 | |||
250 | content = mailmime_content_new_with_str( mime ); | ||
251 | if ( content == NULL ) goto err_free_fields; | ||
252 | |||
253 | if ( mimetype.compare( "text/plain" ) == 0 ) { | ||
254 | param = mailmime_parameter_new( strdup( "charset" ), | ||
255 | strdup( "iso-8859-1" ) ); | ||
256 | if ( param == NULL ) goto err_free_content; | ||
257 | |||
258 | err = clist_append( content->parameters, param ); | ||
259 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; | ||
260 | } | ||
261 | |||
262 | filePart = mailmime_new_empty( content, fields ); | ||
263 | if ( filePart == NULL ) goto err_free_param; | ||
264 | |||
265 | err = mailmime_set_body_file( filePart, file ); | ||
266 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | ||
267 | |||
268 | return filePart; // Success :) | ||
269 | |||
270 | err_free_filePart: | ||
271 | mailmime_free( filePart ); | ||
272 | err_free_param: | ||
273 | if ( param != NULL ) mailmime_parameter_free( param ); | ||
274 | err_free_content: | ||
275 | mailmime_content_free( content ); | ||
276 | err_free_fields: | ||
277 | mailmime_fields_free( fields ); | ||
278 | err_free: | ||
279 | free( name ); | ||
280 | free( mime ); | ||
281 | free( file ); | ||
282 | qDebug( "buildFilePart - error" ); | ||
283 | |||
284 | return NULL; // Error :( | ||
285 | } | ||
286 | |||
287 | void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) | ||
288 | { | ||
289 | Attachment *it; | ||
290 | for ( it = files.first(); it; it = files.next() ) { | ||
291 | qDebug( "Adding file" ); | ||
292 | mailmime *filePart; | ||
293 | int err; | ||
294 | |||
295 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); | ||
296 | if ( filePart == NULL ) goto err_free; | ||
297 | |||
298 | err = mailmime_smart_add_part( message, filePart ); | ||
299 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | ||
300 | |||
301 | continue; // Success :) | ||
302 | |||
303 | err_free_filePart: | ||
304 | mailmime_free( filePart ); | ||
305 | err_free: | ||
306 | qDebug( "addFileParts: error adding file:" ); | ||
307 | qDebug( it->getFileName() ); | ||
308 | } | ||
309 | } | ||
310 | |||
311 | mailmime *MailWrapper::createMimeMail( Mail *mail ) | ||
312 | { | ||
313 | mailmime *message, *txtPart; | ||
314 | mailimf_fields *fields; | ||
315 | int err; | ||
316 | |||
317 | fields = createImfFields( mail ); | ||
318 | if ( fields == NULL ) goto err_free; | ||
319 | |||
320 | message = mailmime_new_message_data( NULL ); | ||
321 | if ( message == NULL ) goto err_free_fields; | ||
322 | |||
323 | mailmime_set_imf_fields( message, fields ); | ||
324 | |||
325 | txtPart = buildTxtPart( mail->getMessage() ); | ||
326 | if ( txtPart == NULL ) goto err_free_message; | ||
327 | |||
328 | err = mailmime_smart_add_part( message, txtPart ); | ||
329 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | ||
330 | |||
331 | addFileParts( message, mail->getAttachments() ); | ||
332 | |||
333 | return message; // Success :) | ||
334 | |||
335 | err_free_txtPart: | ||
336 | mailmime_free( txtPart ); | ||
337 | err_free_message: | ||
338 | mailmime_free( message ); | ||
339 | err_free_fields: | ||
340 | mailimf_fields_free( fields ); | ||
341 | err_free: | ||
342 | qDebug( "createMimeMail: error" ); | ||
343 | |||
344 | return NULL; // Error :( | ||
345 | } | ||
346 | |||
347 | mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) | ||
348 | { | ||
349 | mailimf_field *field; | ||
350 | clistiter *it; | ||
351 | |||
352 | it = clist_begin( fields->list ); | ||
353 | while ( it ) { | ||
354 | field = (mailimf_field *) it->data; | ||
355 | if ( field->type == type ) { | ||
356 | return field; | ||
357 | } | ||
358 | it = it->next; | ||
359 | } | ||
360 | |||
361 | return NULL; | ||
362 | } | ||
363 | |||
364 | static void addRcpts( clist *list, mailimf_address_list *addr_list ) | ||
365 | { | ||
366 | clistiter *it, *it2; | ||
367 | |||
368 | for ( it = clist_begin( addr_list->list ); it; it = it->next ) { | ||
369 | mailimf_address *addr; | ||
370 | addr = (mailimf_address *) it->data; | ||
371 | |||
372 | if ( addr->type == MAILIMF_ADDRESS_MAILBOX ) { | ||
373 | esmtp_address_list_add( list, addr->mailbox->addr_spec, 0, NULL ); | ||
374 | } else if ( addr->type == MAILIMF_ADDRESS_GROUP ) { | ||
375 | clist *l = addr->group->mb_list->list; | ||
376 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | ||
377 | mailimf_mailbox *mbox; | ||
378 | mbox = (mailimf_mailbox *) it2->data; | ||
379 | esmtp_address_list_add( list, mbox->addr_spec, 0, NULL ); | ||
380 | } | ||
381 | } | ||
382 | } | ||
383 | } | ||
384 | |||
385 | clist *MailWrapper::createRcptList( mailimf_fields *fields ) | ||
386 | { | ||
387 | clist *rcptList; | ||
388 | mailimf_field *field; | ||
389 | |||
390 | rcptList = esmtp_address_list_new(); | ||
391 | |||
392 | field = getField( fields, MAILIMF_FIELD_TO ); | ||
393 | if ( field && (field->type == MAILIMF_FIELD_TO) | ||
394 | && field->field.to->addr_list ) { | ||
395 | addRcpts( rcptList, field->field.to->addr_list ); | ||
396 | } | ||
397 | |||
398 | field = getField( fields, MAILIMF_FIELD_CC ); | ||
399 | if ( field && (field->type == MAILIMF_FIELD_CC) | ||
400 | && field->field.cc->addr_list ) { | ||
401 | addRcpts( rcptList, field->field.cc->addr_list ); | ||
402 | } | ||
403 | |||
404 | field = getField( fields, MAILIMF_FIELD_BCC ); | ||
405 | if ( field && (field->type == MAILIMF_FIELD_BCC) | ||
406 | && field->field.bcc->addr_list ) { | ||
407 | addRcpts( rcptList, field->field.bcc->addr_list ); | ||
408 | } | ||
409 | |||
410 | return rcptList; | ||
411 | } | ||
412 | |||
413 | char *MailWrapper::getFrom( mailmime *mail ) | ||
414 | { | ||
415 | char *from = NULL; | ||
416 | |||
417 | mailimf_field *ffrom; | ||
418 | ffrom = getField( mail->fields, MAILIMF_FIELD_FROM ); | ||
419 | if ( ffrom && (ffrom->type == MAILIMF_FIELD_FROM) | ||
420 | && ffrom->field.from->mb_list && ffrom->field.from->mb_list->list ) { | ||
421 | clist *cl = ffrom->field.from->mb_list->list; | ||
422 | clistiter *it; | ||
423 | for ( it = clist_begin( cl ); it; it = it->next ) { | ||
424 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | ||
425 | from = strdup( mb->addr_spec ); | ||
426 | } | ||
427 | } | ||
428 | |||
429 | return from; | ||
430 | } | ||
431 | |||
432 | SMTPaccount *MailWrapper::getAccount( QString from ) | ||
433 | { | ||
434 | SMTPaccount *smtp; | ||
435 | |||
436 | QList<Account> list = settings->getAccounts(); | ||
437 | Account *it; | ||
438 | for ( it = list.first(); it; it = list.next() ) { | ||
439 | if ( it->getType().compare( "SMTP" ) == 0 ) { | ||
440 | smtp = static_cast<SMTPaccount *>(it); | ||
441 | if ( smtp->getMail().compare( from ) == 0 ) { | ||
442 | qDebug( "SMTPaccount found for" ); | ||
443 | qDebug( from ); | ||
444 | return smtp; | ||
445 | } | ||
446 | } | ||
447 | } | ||
448 | |||
449 | return NULL; | ||
450 | } | ||
451 | |||
452 | QString MailWrapper::getTmpFile() { | ||
453 | int num = 0; | ||
454 | QString unique; | ||
455 | |||
456 | QDir dir( "/tmp" ); | ||
457 | QStringList::Iterator it; | ||
458 | |||
459 | QStringList list = dir.entryList( "opiemail-tmp-*" ); | ||
460 | do { | ||
461 | unique.setNum( num++ ); | ||
462 | } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); | ||
463 | |||
464 | return "/tmp/opiemail-tmp-" + unique; | ||
465 | } | ||
466 | |||
467 | void MailWrapper::writeToFile( QString file, mailmime *mail ) | ||
468 | { | ||
469 | FILE *f; | ||
470 | int err, col = 0; | ||
471 | |||
472 | f = fopen( file.latin1(), "w" ); | ||
473 | if ( f == NULL ) { | ||
474 | qDebug( "writeToFile: error opening file" ); | ||
475 | return; | ||
476 | } | ||
477 | |||
478 | err = mailmime_write( f, &col, mail ); | ||
479 | if ( err != MAILIMF_NO_ERROR ) { | ||
480 | fclose( f ); | ||
481 | qDebug( "writeToFile: error writing mailmime" ); | ||
482 | return; | ||
483 | } | ||
484 | |||
485 | fclose( f ); | ||
486 | } | ||
487 | |||
488 | void MailWrapper::readFromFile( QString file, char **data, size_t *size ) | ||
489 | { | ||
490 | char *buf; | ||
491 | struct stat st; | ||
492 | int fd, count = 0, total = 0; | ||
493 | |||
494 | fd = open( file.latin1(), O_RDONLY, 0 ); | ||
495 | if ( fd == -1 ) return; | ||
496 | |||
497 | if ( fstat( fd, &st ) != 0 ) goto err_close; | ||
498 | if ( !st.st_size ) goto err_close; | ||
499 | |||
500 | buf = (char *) malloc( st.st_size ); | ||
501 | if ( !buf ) goto err_close; | ||
502 | |||
503 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { | ||
504 | count = read( fd, buf + total, st.st_size - total ); | ||
505 | total += count; | ||
506 | } | ||
507 | if ( count < 0 ) goto err_free; | ||
508 | |||
509 | *data = buf; | ||
510 | *size = st.st_size; | ||
511 | |||
512 | close( fd ); | ||
513 | |||
514 | return; // Success :) | ||
515 | |||
516 | err_free: | ||
517 | free( buf ); | ||
518 | err_close: | ||
519 | close( fd ); | ||
520 | } | ||
521 | |||
522 | void progress( size_t current, size_t maximum ) | ||
523 | { | ||
524 | qDebug( "Current: %i of %i", current, maximum ); | ||
525 | } | ||
526 | |||
527 | void MailWrapper::smtpSend( mailmime *mail ) | ||
528 | { | ||
529 | mailsmtp *session; | ||
530 | clist *rcpts; | ||
531 | char *from, *data, *server, *user = NULL, *pass = NULL; | ||
532 | size_t size; | ||
533 | int err; | ||
534 | bool ssl; | ||
535 | uint16_t port; | ||
536 | |||
537 | |||
538 | from = getFrom( mail ); | ||
539 | SMTPaccount *smtp = getAccount( from ); | ||
540 | if ( smtp == NULL ) { | ||
541 | free(from); | ||
542 | return; | ||
543 | } | ||
544 | server = strdup( smtp->getServer().latin1() ); | ||
545 | ssl = smtp->getSSL(); | ||
546 | port = smtp->getPort().toUInt(); | ||
547 | rcpts = createRcptList( mail->fields ); | ||
548 | |||
549 | QString file = getTmpFile(); | ||
550 | writeToFile( file, mail ); | ||
551 | readFromFile( file, &data, &size ); | ||
552 | QFile f( file ); | ||
553 | f.remove(); | ||
554 | |||
555 | session = mailsmtp_new( 20, &progress ); | ||
556 | if ( session == NULL ) goto free_mem; | ||
557 | |||
558 | qDebug( "Servername %s at port %i", server, port ); | ||
559 | if ( ssl ) { | ||
560 | qDebug( "SSL session" ); | ||
561 | err = mailsmtp_ssl_connect( session, server, port ); | ||
562 | } else { | ||
563 | qDebug( "No SSL session" ); | ||
564 | err = mailsmtp_socket_connect( session, server, port ); | ||
565 | } | ||
566 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; | ||
567 | |||
568 | err = mailsmtp_init( session ); | ||
569 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | ||
570 | |||
571 | qDebug( "INIT OK" ); | ||
572 | |||
573 | if ( smtp->getLogin() ) { | ||
574 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | ||
575 | // get'em | ||
576 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | ||
577 | login.show(); | ||
578 | if ( QDialog::Accepted == login.exec() ) { | ||
579 | // ok | ||
580 | user = strdup( login.getUser().latin1() ); | ||
581 | pass = strdup( login.getPassword().latin1() ); | ||
582 | } else { | ||
583 | goto free_con_session; | ||
584 | } | ||
585 | } else { | ||
586 | user = strdup( smtp->getUser().latin1() ); | ||
587 | pass = strdup( smtp->getPassword().latin1() ); | ||
588 | } | ||
589 | qDebug( "session->auth: %i", session->auth); | ||
590 | err = mailsmtp_auth( session, user, pass ); | ||
591 | if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); | ||
592 | qDebug( "Done auth!" ); | ||
593 | } | ||
594 | |||
595 | err = mailsmtp_send( session, from, rcpts, data, size ); | ||
596 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | ||
597 | |||
598 | qDebug( "Mail sent." ); | ||
599 | |||
600 | free_con_session: | ||
601 | mailsmtp_quit( session ); | ||
602 | free_mem_session: | ||
603 | mailsmtp_free( session ); | ||
604 | free_mem: | ||
605 | smtp_address_list_free( rcpts ); | ||
606 | free( data ); | ||
607 | free( server ); | ||
608 | if ( smtp->getLogin() ) { | ||
609 | free( user ); | ||
610 | free( pass ); | ||
611 | } | ||
612 | free( from ); | ||
613 | } | ||
614 | |||
615 | void MailWrapper::sendMail( Mail mail ) | ||
616 | { | ||
617 | mailmime *mimeMail; | ||
618 | |||
619 | mimeMail = createMimeMail( &mail ); | ||
620 | if ( mimeMail == NULL ) { | ||
621 | qDebug( "sendMail: error creating mime mail" ); | ||
622 | } else { | ||
623 | smtpSend( mimeMail ); | ||
624 | mailmime_free( mimeMail ); | ||
625 | } | ||
626 | } | ||
627 | |||
628 | Mail::Mail() | ||
629 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") | ||
630 | { | ||
631 | } | ||
632 | |||
633 | RecMail::RecMail() | ||
634 | :subject(""),date(""),msg_number(0),msg_flags(7) | ||
635 | { | ||
636 | } | ||
637 | |||
638 | #if 0 | ||
639 | void RecMail::setDate(const QString&aDate) | ||
640 | { | ||
641 | mDate = QDateTime::fromString(aDate); | ||
642 | } | ||
643 | #endif | ||
diff --git a/noncore/net/mail/mailwrapper.h b/noncore/net/mail/mailwrapper.h new file mode 100644 index 0000000..3de28a0 --- a/dev/null +++ b/noncore/net/mail/mailwrapper.h | |||
@@ -0,0 +1,183 @@ | |||
1 | #ifndef MAILWRAPPER_H | ||
2 | #define MAILWRAPPER_H | ||
3 | |||
4 | #include <qpe/applnk.h> | ||
5 | |||
6 | #include <mailmime.h> | ||
7 | #include <mailimf.h> | ||
8 | #include <mailsmtp.h> | ||
9 | #include <mailimap.h> | ||
10 | #include <mailstorage.h> | ||
11 | #include <maildriver.h> | ||
12 | #include <qbitarray.h> | ||
13 | #include <qdatetime.h> | ||
14 | |||
15 | #include "settings.h" | ||
16 | |||
17 | class Attachment | ||
18 | { | ||
19 | public: | ||
20 | Attachment( DocLnk lnk ); | ||
21 | virtual ~Attachment(){} | ||
22 | const QString getFileName()const{ return doc.file(); } | ||
23 | const QString getName()const{ return doc.name(); } | ||
24 | const QString getMimeType()const{ return doc.type(); } | ||
25 | const QPixmap getPixmap()const{ return doc.pixmap(); } | ||
26 | const int getSize()const { return size; } | ||
27 | DocLnk getDocLnk() { return doc; } | ||
28 | |||
29 | protected: | ||
30 | DocLnk doc; | ||
31 | int size; | ||
32 | |||
33 | }; | ||
34 | |||
35 | #define FLAG_ANSWERED 0 | ||
36 | #define FLAG_FLAGGED 1 | ||
37 | #define FLAG_DELETED 2 | ||
38 | #define FLAG_SEEN 3 | ||
39 | #define FLAG_DRAFT 4 | ||
40 | #define FLAG_RECENT 5 | ||
41 | |||
42 | /* a class to describe mails in a mailbox */ | ||
43 | class RecMail | ||
44 | { | ||
45 | public: | ||
46 | RecMail(); | ||
47 | virtual ~RecMail(){} | ||
48 | |||
49 | const int getNumber()const{return msg_number;} | ||
50 | void setNumber(int number){msg_number=number;} | ||
51 | const QString&getDate()const{ return date; } | ||
52 | void setDate( const QString&a ) { date = a; } | ||
53 | const QString&getFrom()const{ return from; } | ||
54 | void setFrom( const QString&a ) { from = a; } | ||
55 | const QString&getSubject()const { return subject; } | ||
56 | void setSubject( const QString&s ) { subject = s; } | ||
57 | void setFlags(const QBitArray&flags){msg_flags = flags;} | ||
58 | const QBitArray&getFlags()const{return msg_flags;} | ||
59 | |||
60 | #if 0 | ||
61 | void setDate(const QString&dstring); | ||
62 | void setDate(const QDateTime&date){mDate = date;} | ||
63 | QString getDate()const{return mDate.toString();} | ||
64 | #endif | ||
65 | protected: | ||
66 | QString subject,date,from; | ||
67 | int msg_number; | ||
68 | QBitArray msg_flags; | ||
69 | #if 0 | ||
70 | QDateTime mDate; | ||
71 | #endif | ||
72 | }; | ||
73 | |||
74 | typedef QList<RecMail> Maillist; | ||
75 | |||
76 | class Mail | ||
77 | { | ||
78 | public: | ||
79 | Mail(); | ||
80 | /* Possible that this destructor must not be declared virtual | ||
81 | * 'cause it seems that it will never have some child classes. | ||
82 | * in this case this object will not get a virtual table -> memory and | ||
83 | * speed will be a little bit better? | ||
84 | */ | ||
85 | virtual ~Mail(){} | ||
86 | void addAttachment( Attachment *att ) { attList.append( att ); } | ||
87 | const QList<Attachment>& getAttachments()const { return attList; } | ||
88 | void removeAttachment( Attachment *att ) { attList.remove( att ); } | ||
89 | const QString&getName()const { return name; } | ||
90 | void setName( QString s ) { name = s; } | ||
91 | const QString&getMail()const{ return mail; } | ||
92 | void setMail( const QString&s ) { mail = s; } | ||
93 | const QString&getTo()const{ return to; } | ||
94 | void setTo( const QString&s ) { to = s; } | ||
95 | const QString&getCC()const{ return cc; } | ||
96 | void setCC( const QString&s ) { cc = s; } | ||
97 | const QString&getBCC()const { return bcc; } | ||
98 | void setBCC( const QString&s ) { bcc = s; } | ||
99 | const QString&getMessage()const { return message; } | ||
100 | void setMessage( const QString&s ) { message = s; } | ||
101 | const QString&getSubject()const { return subject; } | ||
102 | void setSubject( const QString&s ) { subject = s; } | ||
103 | const QString&getReply()const{ return reply; } | ||
104 | void setReply( const QString&a ) { reply = a; } | ||
105 | |||
106 | private: | ||
107 | QList<Attachment> attList; | ||
108 | QString name, mail, to, cc, bcc, reply, subject, message; | ||
109 | }; | ||
110 | |||
111 | class Folder : public QObject | ||
112 | { | ||
113 | Q_OBJECT | ||
114 | |||
115 | public: | ||
116 | Folder( const QString&init_name ); | ||
117 | const QString&getDisplayName()const { return nameDisplay; } | ||
118 | const QString&getName()const { return name; } | ||
119 | virtual bool may_select()const{return true;}; | ||
120 | |||
121 | private: | ||
122 | QString nameDisplay, name; | ||
123 | |||
124 | }; | ||
125 | |||
126 | class IMAPFolder : public Folder | ||
127 | { | ||
128 | public: | ||
129 | IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} | ||
130 | virtual bool may_select()const{return m_MaySelect;} | ||
131 | private: | ||
132 | bool m_MaySelect; | ||
133 | }; | ||
134 | |||
135 | class MailWrapper : public QObject | ||
136 | { | ||
137 | Q_OBJECT | ||
138 | |||
139 | public: | ||
140 | MailWrapper( Settings *s ); | ||
141 | void sendMail( Mail mail ); | ||
142 | |||
143 | private: | ||
144 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | ||
145 | mailimf_address_list *parseAddresses(const QString&addr ); | ||
146 | mailimf_fields *createImfFields( Mail *mail ); | ||
147 | mailmime *buildTxtPart( QString str ); | ||
148 | mailmime *buildFilePart( QString filename, QString mimetype ); | ||
149 | void addFileParts( mailmime *message, QList<Attachment> files ); | ||
150 | mailmime *createMimeMail( Mail *mail ); | ||
151 | void smtpSend( mailmime *mail ); | ||
152 | mailimf_field *getField( mailimf_fields *fields, int type ); | ||
153 | clist *createRcptList( mailimf_fields *fields ); | ||
154 | char *getFrom( mailmime *mail ); | ||
155 | SMTPaccount *getAccount( QString from ); | ||
156 | void writeToFile( QString file, mailmime *mail ); | ||
157 | void readFromFile( QString file, char **data, size_t *size ); | ||
158 | static QString mailsmtpError( int err ); | ||
159 | static QString getTmpFile(); | ||
160 | |||
161 | Settings *settings; | ||
162 | |||
163 | }; | ||
164 | |||
165 | class IMAPwrapper : public QObject | ||
166 | { | ||
167 | Q_OBJECT | ||
168 | |||
169 | public: | ||
170 | IMAPwrapper( IMAPaccount *a ); | ||
171 | QList<IMAPFolder>* listFolders(); | ||
172 | void listMessages(const QString & mailbox,Maillist&target ); | ||
173 | QString fetchBody(const QString & mailbox,const RecMail&mail); | ||
174 | |||
175 | protected: | ||
176 | RecMail*parse_list_result(mailimap_msg_att*); | ||
177 | |||
178 | private: | ||
179 | IMAPaccount *account; | ||
180 | |||
181 | }; | ||
182 | |||
183 | #endif | ||
diff --git a/noncore/net/mail/main.cpp b/noncore/net/mail/main.cpp new file mode 100644 index 0000000..f97bea1 --- a/dev/null +++ b/noncore/net/mail/main.cpp | |||
@@ -0,0 +1,6 @@ | |||
1 | #include <qpe/qpeapplication.h> | ||
2 | #include <opie/oapplicationfactory.h> | ||
3 | |||
4 | #include "opiemail.h" | ||
5 | |||
6 | OPIE_EXPORT_APP( OApplicationFactory<OpieMail> ) | ||
diff --git a/noncore/net/mail/mainwindow.cpp b/noncore/net/mail/mainwindow.cpp new file mode 100644 index 0000000..0a433a0 --- a/dev/null +++ b/noncore/net/mail/mainwindow.cpp | |||
@@ -0,0 +1,151 @@ | |||
1 | #include <qlabel.h> | ||
2 | #include <qvbox.h> | ||
3 | #include <qheader.h> | ||
4 | #include <qtimer.h> | ||
5 | |||
6 | #include <qpe/resource.h> | ||
7 | |||
8 | #include "defines.h" | ||
9 | #include "readmailgui.h" | ||
10 | #include "mainwindow.h" | ||
11 | |||
12 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags ) | ||
13 | : QMainWindow( parent, name, flags ) | ||
14 | { | ||
15 | setCaption( tr( "Opie-Mail" ) ); | ||
16 | setToolBarsMovable( false ); | ||
17 | |||
18 | toolBar = new QToolBar( this ); | ||
19 | menuBar = new QMenuBar( toolBar ); | ||
20 | mailMenu = new QPopupMenu( menuBar ); | ||
21 | menuBar->insertItem( tr( "Mail" ), mailMenu ); | ||
22 | settingsMenu = new QPopupMenu( menuBar ); | ||
23 | menuBar->insertItem( tr( "Settings" ), settingsMenu ); | ||
24 | |||
25 | addToolBar( toolBar ); | ||
26 | toolBar->setHorizontalStretchable( true ); | ||
27 | |||
28 | QLabel *spacer = new QLabel( toolBar ); | ||
29 | spacer->setBackgroundMode( QWidget::PaletteButton ); | ||
30 | toolBar->setStretchableWidget( spacer ); | ||
31 | |||
32 | composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL, | ||
33 | 0, 0, this ); | ||
34 | composeMail->addTo( toolBar ); | ||
35 | composeMail->addTo( mailMenu ); | ||
36 | |||
37 | sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED, | ||
38 | 0, 0, this ); | ||
39 | sendQueued->addTo( toolBar ); | ||
40 | sendQueued->addTo( mailMenu ); | ||
41 | |||
42 | syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC, | ||
43 | 0, 0, this ); | ||
44 | syncFolders->addTo( toolBar ); | ||
45 | syncFolders->addTo( mailMenu ); | ||
46 | |||
47 | showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS, | ||
48 | 0, 0, this, 0, true ); | ||
49 | showFolders->addTo( toolBar ); | ||
50 | showFolders->addTo( mailMenu ); | ||
51 | connect(showFolders, SIGNAL( toggled( bool ) ), | ||
52 | SLOT( slotShowFolders( bool ) ) ); | ||
53 | |||
54 | searchMails = new QAction( tr( "Search mails" ), ICON_SEARCHMAILS, | ||
55 | 0, 0, this ); | ||
56 | searchMails->addTo( toolBar ); | ||
57 | searchMails->addTo( mailMenu ); | ||
58 | |||
59 | |||
60 | editSettings = new QAction( tr( "Edit settings" ), ICON_EDITSETTINGS, | ||
61 | 0, 0, this ); | ||
62 | editSettings->addTo( settingsMenu ); | ||
63 | |||
64 | editAccounts = new QAction( tr( "Configure accounts" ), ICON_EDITACCOUNTS, | ||
65 | 0, 0, this ); | ||
66 | editAccounts->addTo( settingsMenu ); | ||
67 | |||
68 | QVBox *view = new QVBox( this ); | ||
69 | setCentralWidget( view ); | ||
70 | |||
71 | folderView = new AccountView( view ); | ||
72 | folderView->header()->hide(); | ||
73 | folderView->setMinimumHeight( 90 ); | ||
74 | folderView->setMaximumHeight( 90 ); | ||
75 | folderView->addColumn( tr( "Mailbox" ) ); | ||
76 | folderView->hide(); | ||
77 | |||
78 | mailView = new QListView( view ); | ||
79 | mailView->setMinimumHeight( 50 ); | ||
80 | mailView->addColumn( tr( "Subject" ),QListView::Manual ); | ||
81 | mailView->addColumn( tr( "Sender" ),QListView::Manual ); | ||
82 | mailView->addColumn( tr( "Date" )); | ||
83 | mailView->setAllColumnsShowFocus(true); | ||
84 | mailView->setSorting(-1); | ||
85 | connect( mailView, SIGNAL( clicked( QListViewItem * ) ),this, | ||
86 | SLOT( displayMail( QListViewItem * ) ) ); | ||
87 | |||
88 | connect(folderView,SIGNAL(refreshMailview(Maillist*)),this,SLOT(refreshMailView(Maillist*))); | ||
89 | |||
90 | QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) ); | ||
91 | } | ||
92 | |||
93 | void MainWindow::slotAdjustColumns() | ||
94 | { | ||
95 | bool hidden = folderView->isHidden(); | ||
96 | if ( hidden ) folderView->show(); | ||
97 | folderView->setColumnWidth( 0, folderView->visibleWidth() ); | ||
98 | if ( hidden ) folderView->hide(); | ||
99 | |||
100 | mailView->setColumnWidth( 0, mailView->visibleWidth() - 130 ); | ||
101 | mailView->setColumnWidth( 1, 80 ); | ||
102 | mailView->setColumnWidth( 2, 50 ); | ||
103 | } | ||
104 | |||
105 | void MainWindow::slotShowFolders( bool show ) | ||
106 | { | ||
107 | qDebug( "Show Folders" ); | ||
108 | if ( show && folderView->isHidden() ) { | ||
109 | qDebug( "-> showing" ); | ||
110 | folderView->show(); | ||
111 | } else if ( !show && !folderView->isHidden() ) { | ||
112 | qDebug( "-> hiding" ); | ||
113 | folderView->hide(); | ||
114 | } | ||
115 | } | ||
116 | |||
117 | void MainWindow::refreshMailView(Maillist*list) | ||
118 | { | ||
119 | MailListViewItem*item = 0; | ||
120 | mailView->clear(); | ||
121 | #if 0 | ||
122 | QFont f = mailView->getFont(); | ||
123 | QFont bf = f; | ||
124 | #endif | ||
125 | for (unsigned int i = 0; i < list->count();++i) { | ||
126 | item = new MailListViewItem(mailView,item); | ||
127 | item->storeData(*(list->at(i))); | ||
128 | item->showEntry(); | ||
129 | #if 0 | ||
130 | if (!list->at(i)->getFlags().testBit(FLAG_SEEN)) { | ||
131 | item->setFont(bf); | ||
132 | } | ||
133 | #endif | ||
134 | } | ||
135 | } | ||
136 | void MainWindow::displayMail(QListViewItem*item) | ||
137 | { | ||
138 | if (!item) return; | ||
139 | qDebug("View mail"); | ||
140 | RecMail mail = ((MailListViewItem*)item)->data(); | ||
141 | QString body = folderView->fetchBody(mail); | ||
142 | |||
143 | qDebug(body); | ||
144 | } | ||
145 | |||
146 | void MailListViewItem::showEntry() | ||
147 | { | ||
148 | setText(0,mail_data.getSubject()); | ||
149 | setText(1,mail_data.getFrom()); | ||
150 | setText(2,mail_data.getDate()); | ||
151 | } | ||
diff --git a/noncore/net/mail/mainwindow.h b/noncore/net/mail/mainwindow.h new file mode 100644 index 0000000..a5142ab --- a/dev/null +++ b/noncore/net/mail/mainwindow.h | |||
@@ -0,0 +1,54 @@ | |||
1 | #ifndef MAINWINDOW_H | ||
2 | #define MAINWINDOW_H | ||
3 | |||
4 | #include <qmainwindow.h> | ||
5 | #include <qlistview.h> | ||
6 | #include <qaction.h> | ||
7 | |||
8 | #include <qtoolbar.h> | ||
9 | #include <qmenubar.h> | ||
10 | |||
11 | #include "accountview.h" | ||
12 | |||
13 | class MainWindow : public QMainWindow | ||
14 | { | ||
15 | Q_OBJECT | ||
16 | |||
17 | public: | ||
18 | MainWindow( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); | ||
19 | |||
20 | public slots: | ||
21 | void slotAdjustColumns(); | ||
22 | |||
23 | protected slots: | ||
24 | virtual void slotShowFolders( bool show ); | ||
25 | virtual void refreshMailView(Maillist*); | ||
26 | virtual void displayMail(QListViewItem*); | ||
27 | |||
28 | protected: | ||
29 | QToolBar *toolBar; | ||
30 | QMenuBar *menuBar; | ||
31 | QPopupMenu *mailMenu, *settingsMenu; | ||
32 | QAction *composeMail, *sendQueued, *showFolders, *searchMails, | ||
33 | *editSettings, *editAccounts, *syncFolders; | ||
34 | AccountView *folderView; | ||
35 | QListView *mailView; | ||
36 | |||
37 | }; | ||
38 | |||
39 | class MailListViewItem:public QListViewItem | ||
40 | { | ||
41 | public: | ||
42 | MailListViewItem(QListView * parent, MailListViewItem * after ) | ||
43 | :QListViewItem(parent,after),mail_data(){} | ||
44 | virtual ~MailListViewItem(){} | ||
45 | |||
46 | void storeData(const RecMail&data){mail_data = data;} | ||
47 | const RecMail&data()const{return mail_data;} | ||
48 | void showEntry(); | ||
49 | |||
50 | protected: | ||
51 | RecMail mail_data; | ||
52 | }; | ||
53 | |||
54 | #endif | ||
diff --git a/noncore/net/mail/nntpconfigui.ui b/noncore/net/mail/nntpconfigui.ui new file mode 100644 index 0000000..cc439f4 --- a/dev/null +++ b/noncore/net/mail/nntpconfigui.ui | |||
@@ -0,0 +1,257 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>NNTPconfigUI</class> | ||
3 | <widget> | ||
4 | <class>QDialog</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>NNTPconfigUI</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>228</width> | ||
15 | <height>320</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Configure NNTP</string> | ||
21 | </property> | ||
22 | <property> | ||
23 | <name>layoutMargin</name> | ||
24 | </property> | ||
25 | <property> | ||
26 | <name>layoutSpacing</name> | ||
27 | </property> | ||
28 | <grid> | ||
29 | <property stdset="1"> | ||
30 | <name>margin</name> | ||
31 | <number>4</number> | ||
32 | </property> | ||
33 | <property stdset="1"> | ||
34 | <name>spacing</name> | ||
35 | <number>3</number> | ||
36 | </property> | ||
37 | <widget row="2" column="1" > | ||
38 | <class>QLineEdit</class> | ||
39 | <property stdset="1"> | ||
40 | <name>name</name> | ||
41 | <cstring>serverLine</cstring> | ||
42 | </property> | ||
43 | </widget> | ||
44 | <widget row="3" column="0" > | ||
45 | <class>QLabel</class> | ||
46 | <property stdset="1"> | ||
47 | <name>name</name> | ||
48 | <cstring>portLabel</cstring> | ||
49 | </property> | ||
50 | <property stdset="1"> | ||
51 | <name>text</name> | ||
52 | <string>Port</string> | ||
53 | </property> | ||
54 | </widget> | ||
55 | <widget row="3" column="1" > | ||
56 | <class>QLineEdit</class> | ||
57 | <property stdset="1"> | ||
58 | <name>name</name> | ||
59 | <cstring>portLine</cstring> | ||
60 | </property> | ||
61 | </widget> | ||
62 | <widget row="0" column="1" > | ||
63 | <class>QLineEdit</class> | ||
64 | <property stdset="1"> | ||
65 | <name>name</name> | ||
66 | <cstring>accountLine</cstring> | ||
67 | </property> | ||
68 | <property> | ||
69 | <name>toolTip</name> | ||
70 | <string>Name of the Account</string> | ||
71 | </property> | ||
72 | </widget> | ||
73 | <widget row="0" column="0" > | ||
74 | <class>QLabel</class> | ||
75 | <property stdset="1"> | ||
76 | <name>name</name> | ||
77 | <cstring>accountLabel</cstring> | ||
78 | </property> | ||
79 | <property stdset="1"> | ||
80 | <name>text</name> | ||
81 | <string>Account</string> | ||
82 | </property> | ||
83 | </widget> | ||
84 | <widget row="2" column="0" > | ||
85 | <class>QLabel</class> | ||
86 | <property stdset="1"> | ||
87 | <name>name</name> | ||
88 | <cstring>serverLabel</cstring> | ||
89 | </property> | ||
90 | <property stdset="1"> | ||
91 | <name>enabled</name> | ||
92 | <bool>true</bool> | ||
93 | </property> | ||
94 | <property stdset="1"> | ||
95 | <name>caption</name> | ||
96 | <string></string> | ||
97 | </property> | ||
98 | <property stdset="1"> | ||
99 | <name>text</name> | ||
100 | <string>Server</string> | ||
101 | </property> | ||
102 | <property> | ||
103 | <name>layoutMargin</name> | ||
104 | </property> | ||
105 | <property> | ||
106 | <name>layoutSpacing</name> | ||
107 | </property> | ||
108 | </widget> | ||
109 | <widget row="1" column="0" rowspan="1" colspan="2" > | ||
110 | <class>Line</class> | ||
111 | <property stdset="1"> | ||
112 | <name>name</name> | ||
113 | <cstring>line1</cstring> | ||
114 | </property> | ||
115 | <property stdset="1"> | ||
116 | <name>caption</name> | ||
117 | <string></string> | ||
118 | </property> | ||
119 | <property stdset="1"> | ||
120 | <name>orientation</name> | ||
121 | <enum>Horizontal</enum> | ||
122 | </property> | ||
123 | <property> | ||
124 | <name>layoutMargin</name> | ||
125 | </property> | ||
126 | <property> | ||
127 | <name>layoutSpacing</name> | ||
128 | </property> | ||
129 | </widget> | ||
130 | <widget row="4" column="1" > | ||
131 | <class>QCheckBox</class> | ||
132 | <property stdset="1"> | ||
133 | <name>name</name> | ||
134 | <cstring>sslBox</cstring> | ||
135 | </property> | ||
136 | <property stdset="1"> | ||
137 | <name>text</name> | ||
138 | <string>Use SSL</string> | ||
139 | </property> | ||
140 | </widget> | ||
141 | <widget row="5" column="0" rowspan="1" colspan="2" > | ||
142 | <class>Line</class> | ||
143 | <property stdset="1"> | ||
144 | <name>name</name> | ||
145 | <cstring>line2</cstring> | ||
146 | </property> | ||
147 | <property stdset="1"> | ||
148 | <name>enabled</name> | ||
149 | <bool>true</bool> | ||
150 | </property> | ||
151 | <property stdset="1"> | ||
152 | <name>caption</name> | ||
153 | <string></string> | ||
154 | </property> | ||
155 | <property stdset="1"> | ||
156 | <name>orientation</name> | ||
157 | <enum>Horizontal</enum> | ||
158 | </property> | ||
159 | <property> | ||
160 | <name>layoutMargin</name> | ||
161 | </property> | ||
162 | <property> | ||
163 | <name>layoutSpacing</name> | ||
164 | </property> | ||
165 | </widget> | ||
166 | <widget row="7" column="0" > | ||
167 | <class>QLabel</class> | ||
168 | <property stdset="1"> | ||
169 | <name>name</name> | ||
170 | <cstring>userLabel</cstring> | ||
171 | </property> | ||
172 | <property stdset="1"> | ||
173 | <name>text</name> | ||
174 | <string>User</string> | ||
175 | </property> | ||
176 | </widget> | ||
177 | <widget row="8" column="0" > | ||
178 | <class>QLabel</class> | ||
179 | <property stdset="1"> | ||
180 | <name>name</name> | ||
181 | <cstring>passLabel</cstring> | ||
182 | </property> | ||
183 | <property stdset="1"> | ||
184 | <name>text</name> | ||
185 | <string>Password</string> | ||
186 | </property> | ||
187 | </widget> | ||
188 | <spacer row="9" column="1" > | ||
189 | <property> | ||
190 | <name>name</name> | ||
191 | <cstring>spacer</cstring> | ||
192 | </property> | ||
193 | <property stdset="1"> | ||
194 | <name>orientation</name> | ||
195 | <enum>Vertical</enum> | ||
196 | </property> | ||
197 | <property stdset="1"> | ||
198 | <name>sizeType</name> | ||
199 | <enum>Expanding</enum> | ||
200 | </property> | ||
201 | <property> | ||
202 | <name>sizeHint</name> | ||
203 | <size> | ||
204 | <width>20</width> | ||
205 | <height>20</height> | ||
206 | </size> | ||
207 | </property> | ||
208 | </spacer> | ||
209 | <widget row="6" column="1" > | ||
210 | <class>QCheckBox</class> | ||
211 | <property stdset="1"> | ||
212 | <name>name</name> | ||
213 | <cstring>loginBox</cstring> | ||
214 | </property> | ||
215 | <property stdset="1"> | ||
216 | <name>text</name> | ||
217 | <string>Use Login</string> | ||
218 | </property> | ||
219 | </widget> | ||
220 | <widget row="7" column="1" > | ||
221 | <class>QLineEdit</class> | ||
222 | <property stdset="1"> | ||
223 | <name>name</name> | ||
224 | <cstring>userLine</cstring> | ||
225 | </property> | ||
226 | <property stdset="1"> | ||
227 | <name>enabled</name> | ||
228 | <bool>false</bool> | ||
229 | </property> | ||
230 | </widget> | ||
231 | <widget row="8" column="1" > | ||
232 | <class>QLineEdit</class> | ||
233 | <property stdset="1"> | ||
234 | <name>name</name> | ||
235 | <cstring>passLine</cstring> | ||
236 | </property> | ||
237 | <property stdset="1"> | ||
238 | <name>enabled</name> | ||
239 | <bool>false</bool> | ||
240 | </property> | ||
241 | <property stdset="1"> | ||
242 | <name>echoMode</name> | ||
243 | <enum>Password</enum> | ||
244 | </property> | ||
245 | </widget> | ||
246 | </grid> | ||
247 | </widget> | ||
248 | <tabstops> | ||
249 | <tabstop>accountLine</tabstop> | ||
250 | <tabstop>serverLine</tabstop> | ||
251 | <tabstop>portLine</tabstop> | ||
252 | <tabstop>sslBox</tabstop> | ||
253 | <tabstop>loginBox</tabstop> | ||
254 | <tabstop>userLine</tabstop> | ||
255 | <tabstop>passLine</tabstop> | ||
256 | </tabstops> | ||
257 | </UI> | ||
diff --git a/noncore/net/mail/opie-mail.control b/noncore/net/mail/opie-mail.control new file mode 100644 index 0000000..a93067f --- a/dev/null +++ b/noncore/net/mail/opie-mail.control | |||
@@ -0,0 +1,10 @@ | |||
1 | Package: opie-mail | ||
2 | Files: bin/opiemail apps/1Pim/opiemail.desktop pics/mail/*.png | ||
3 | Priority: optional | ||
4 | Section: opie/applications | ||
5 | Maintainer: Juergen Graf <jgf@openbsd.de> | ||
6 | Architecture: arm | ||
7 | Version: 0.0.1-$SUB_VERSION | ||
8 | Depends: task-opie-minimal, libopie1 | ||
9 | Description: Opie's mail and news client (POP3, IMAP and NNTP) | ||
10 | License: LGPL | ||
diff --git a/noncore/net/mail/opiemail.cpp b/noncore/net/mail/opiemail.cpp new file mode 100644 index 0000000..93f3bb7 --- a/dev/null +++ b/noncore/net/mail/opiemail.cpp | |||
@@ -0,0 +1,50 @@ | |||
1 | #include "opiemail.h" | ||
2 | #include "editaccounts.h" | ||
3 | #include "composemail.h" | ||
4 | |||
5 | OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags ) | ||
6 | : MainWindow( parent, name, flags ) | ||
7 | { | ||
8 | settings = new Settings(); | ||
9 | |||
10 | folderView->populate( settings->getAccounts() ); | ||
11 | |||
12 | connect( composeMail, SIGNAL( activated() ), SLOT( slotComposeMail() ) ); | ||
13 | connect( sendQueued, SIGNAL( activated() ), SLOT( slotSendQueued() ) ); | ||
14 | connect( searchMails, SIGNAL( activated() ), SLOT( slotSearchMails() ) ); | ||
15 | connect( editSettings, SIGNAL( activated() ), SLOT( slotEditSettings() ) ); | ||
16 | connect( editAccounts, SIGNAL( activated() ), SLOT( slotEditAccounts() ) ); | ||
17 | } | ||
18 | |||
19 | void OpieMail::slotComposeMail() | ||
20 | { | ||
21 | qDebug( "Compose Mail" ); | ||
22 | ComposeMail compose( settings, this, 0 , true ); | ||
23 | compose.showMaximized(); | ||
24 | compose.slotAdjustColumns(); | ||
25 | compose.exec(); | ||
26 | } | ||
27 | |||
28 | void OpieMail::slotSendQueued() | ||
29 | { | ||
30 | qDebug( "Send Queued" ); | ||
31 | } | ||
32 | |||
33 | void OpieMail::slotSearchMails() | ||
34 | { | ||
35 | qDebug( "Search Mails" ); | ||
36 | } | ||
37 | |||
38 | void OpieMail::slotEditSettings() | ||
39 | { | ||
40 | qDebug( "Edit Settings" ); | ||
41 | } | ||
42 | |||
43 | void OpieMail::slotEditAccounts() | ||
44 | { | ||
45 | qDebug( "Edit Accounts" ); | ||
46 | EditAccounts eaDialog( settings, this, 0, true ); | ||
47 | eaDialog.showMaximized(); | ||
48 | eaDialog.slotAdjustColumns(); | ||
49 | eaDialog.exec(); | ||
50 | } | ||
diff --git a/noncore/net/mail/opiemail.h b/noncore/net/mail/opiemail.h new file mode 100644 index 0000000..dcab47c --- a/dev/null +++ b/noncore/net/mail/opiemail.h | |||
@@ -0,0 +1,28 @@ | |||
1 | #ifndef OPIEMAIL_H | ||
2 | #define OPIEMAIL_H | ||
3 | |||
4 | #include "mainwindow.h" | ||
5 | #include "settings.h" | ||
6 | |||
7 | class OpieMail : public MainWindow | ||
8 | { | ||
9 | Q_OBJECT | ||
10 | |||
11 | public: | ||
12 | OpieMail( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); | ||
13 | |||
14 | static QString appName() { return QString::fromLatin1("opiemail"); } | ||
15 | |||
16 | protected slots: | ||
17 | void slotComposeMail(); | ||
18 | void slotSendQueued(); | ||
19 | void slotSearchMails(); | ||
20 | void slotEditSettings(); | ||
21 | void slotEditAccounts(); | ||
22 | |||
23 | private: | ||
24 | Settings *settings; | ||
25 | |||
26 | }; | ||
27 | |||
28 | #endif | ||
diff --git a/noncore/net/mail/pop3configui.ui b/noncore/net/mail/pop3configui.ui new file mode 100644 index 0000000..8fdb4ba --- a/dev/null +++ b/noncore/net/mail/pop3configui.ui | |||
@@ -0,0 +1,199 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>POP3configUI</class> | ||
3 | <widget> | ||
4 | <class>QDialog</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>POP3configUI</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>236</width> | ||
15 | <height>320</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Configure POP3</string> | ||
21 | </property> | ||
22 | <property> | ||
23 | <name>layoutMargin</name> | ||
24 | </property> | ||
25 | <property> | ||
26 | <name>layoutSpacing</name> | ||
27 | </property> | ||
28 | <grid> | ||
29 | <property stdset="1"> | ||
30 | <name>margin</name> | ||
31 | <number>4</number> | ||
32 | </property> | ||
33 | <property stdset="1"> | ||
34 | <name>spacing</name> | ||
35 | <number>3</number> | ||
36 | </property> | ||
37 | <widget row="6" column="1" > | ||
38 | <class>QLineEdit</class> | ||
39 | <property stdset="1"> | ||
40 | <name>name</name> | ||
41 | <cstring>userLine</cstring> | ||
42 | </property> | ||
43 | </widget> | ||
44 | <widget row="7" column="0" > | ||
45 | <class>QLabel</class> | ||
46 | <property stdset="1"> | ||
47 | <name>name</name> | ||
48 | <cstring>passLabel</cstring> | ||
49 | </property> | ||
50 | <property stdset="1"> | ||
51 | <name>text</name> | ||
52 | <string>Password</string> | ||
53 | </property> | ||
54 | </widget> | ||
55 | <widget row="7" column="1" > | ||
56 | <class>QLineEdit</class> | ||
57 | <property stdset="1"> | ||
58 | <name>name</name> | ||
59 | <cstring>passLine</cstring> | ||
60 | </property> | ||
61 | <property stdset="1"> | ||
62 | <name>echoMode</name> | ||
63 | <enum>Password</enum> | ||
64 | </property> | ||
65 | </widget> | ||
66 | <widget row="3" column="1" > | ||
67 | <class>QLineEdit</class> | ||
68 | <property stdset="1"> | ||
69 | <name>name</name> | ||
70 | <cstring>portLine</cstring> | ||
71 | </property> | ||
72 | </widget> | ||
73 | <widget row="2" column="1" > | ||
74 | <class>QLineEdit</class> | ||
75 | <property stdset="1"> | ||
76 | <name>name</name> | ||
77 | <cstring>serverLine</cstring> | ||
78 | </property> | ||
79 | </widget> | ||
80 | <widget row="2" column="0" > | ||
81 | <class>QLabel</class> | ||
82 | <property stdset="1"> | ||
83 | <name>name</name> | ||
84 | <cstring>serverLabel</cstring> | ||
85 | </property> | ||
86 | <property stdset="1"> | ||
87 | <name>text</name> | ||
88 | <string>Server</string> | ||
89 | </property> | ||
90 | </widget> | ||
91 | <widget row="4" column="1" > | ||
92 | <class>QCheckBox</class> | ||
93 | <property stdset="1"> | ||
94 | <name>name</name> | ||
95 | <cstring>sslBox</cstring> | ||
96 | </property> | ||
97 | <property stdset="1"> | ||
98 | <name>text</name> | ||
99 | <string>Use SSL</string> | ||
100 | </property> | ||
101 | </widget> | ||
102 | <widget row="3" column="0" > | ||
103 | <class>QLabel</class> | ||
104 | <property stdset="1"> | ||
105 | <name>name</name> | ||
106 | <cstring>portLabel</cstring> | ||
107 | </property> | ||
108 | <property stdset="1"> | ||
109 | <name>text</name> | ||
110 | <string>Port</string> | ||
111 | </property> | ||
112 | </widget> | ||
113 | <widget row="6" column="0" > | ||
114 | <class>QLabel</class> | ||
115 | <property stdset="1"> | ||
116 | <name>name</name> | ||
117 | <cstring>userLabel</cstring> | ||
118 | </property> | ||
119 | <property stdset="1"> | ||
120 | <name>text</name> | ||
121 | <string>User</string> | ||
122 | </property> | ||
123 | </widget> | ||
124 | <spacer row="8" column="1" > | ||
125 | <property> | ||
126 | <name>name</name> | ||
127 | <cstring>spacer</cstring> | ||
128 | </property> | ||
129 | <property stdset="1"> | ||
130 | <name>orientation</name> | ||
131 | <enum>Vertical</enum> | ||
132 | </property> | ||
133 | <property stdset="1"> | ||
134 | <name>sizeType</name> | ||
135 | <enum>Expanding</enum> | ||
136 | </property> | ||
137 | <property> | ||
138 | <name>sizeHint</name> | ||
139 | <size> | ||
140 | <width>20</width> | ||
141 | <height>20</height> | ||
142 | </size> | ||
143 | </property> | ||
144 | </spacer> | ||
145 | <widget row="5" column="0" rowspan="1" colspan="2" > | ||
146 | <class>Line</class> | ||
147 | <property stdset="1"> | ||
148 | <name>name</name> | ||
149 | <cstring>line2</cstring> | ||
150 | </property> | ||
151 | <property stdset="1"> | ||
152 | <name>orientation</name> | ||
153 | <enum>Horizontal</enum> | ||
154 | </property> | ||
155 | </widget> | ||
156 | <widget row="0" column="0" > | ||
157 | <class>QLabel</class> | ||
158 | <property stdset="1"> | ||
159 | <name>name</name> | ||
160 | <cstring>accountLabel</cstring> | ||
161 | </property> | ||
162 | <property stdset="1"> | ||
163 | <name>text</name> | ||
164 | <string>Account</string> | ||
165 | </property> | ||
166 | </widget> | ||
167 | <widget row="0" column="1" > | ||
168 | <class>QLineEdit</class> | ||
169 | <property stdset="1"> | ||
170 | <name>name</name> | ||
171 | <cstring>accountLine</cstring> | ||
172 | </property> | ||
173 | <property> | ||
174 | <name>toolTip</name> | ||
175 | <string>Name of the Account</string> | ||
176 | </property> | ||
177 | </widget> | ||
178 | <widget row="1" column="0" rowspan="1" colspan="2" > | ||
179 | <class>Line</class> | ||
180 | <property stdset="1"> | ||
181 | <name>name</name> | ||
182 | <cstring>line1</cstring> | ||
183 | </property> | ||
184 | <property stdset="1"> | ||
185 | <name>orientation</name> | ||
186 | <enum>Horizontal</enum> | ||
187 | </property> | ||
188 | </widget> | ||
189 | </grid> | ||
190 | </widget> | ||
191 | <tabstops> | ||
192 | <tabstop>accountLine</tabstop> | ||
193 | <tabstop>serverLine</tabstop> | ||
194 | <tabstop>portLine</tabstop> | ||
195 | <tabstop>sslBox</tabstop> | ||
196 | <tabstop>userLine</tabstop> | ||
197 | <tabstop>passLine</tabstop> | ||
198 | </tabstops> | ||
199 | </UI> | ||
diff --git a/noncore/net/mail/readmailgui.cpp b/noncore/net/mail/readmailgui.cpp new file mode 100644 index 0000000..0063070 --- a/dev/null +++ b/noncore/net/mail/readmailgui.cpp | |||
@@ -0,0 +1,29 @@ | |||
1 | #include "readmailgui.h" | ||
2 | #include "defines.h" | ||
3 | #include <qlayout.h> | ||
4 | |||
5 | ReadMailGui::ReadMailGui( QWidget* parent, const char* name, bool modal, WFlags fl ) | ||
6 | : QDialog( parent, name, modal, fl ) { | ||
7 | |||
8 | |||
9 | QVBoxLayout * layout = new QVBoxLayout( this ); | ||
10 | QMainWindow * m_mainWindow = new QMainWindow( this ); | ||
11 | m_toolBar = new QToolBar( m_mainWindow ); | ||
12 | m_mainWindow->addToolBar( m_toolBar ); | ||
13 | |||
14 | m_reply = new QAction( tr( "Compose new mail" ), ICON_SENDQUEUED, 0, 0, m_mainWindow ); | ||
15 | m_reply->addTo( m_toolBar ); | ||
16 | |||
17 | m_textWindow = new QTextBrowser( this ); | ||
18 | m_textWindow->setResizePolicy( QScrollView::AutoOneFit ); | ||
19 | |||
20 | layout->addWidget( m_mainWindow ); | ||
21 | layout->addWidget( m_textWindow ); | ||
22 | } | ||
23 | |||
24 | ReadMailGui::~ReadMailGui() { | ||
25 | } | ||
26 | |||
27 | void ReadMailGui::passMessage( const QString & message ) { | ||
28 | m_textWindow->setText( message ); | ||
29 | } | ||
diff --git a/noncore/net/mail/readmailgui.h b/noncore/net/mail/readmailgui.h new file mode 100644 index 0000000..dac1937 --- a/dev/null +++ b/noncore/net/mail/readmailgui.h | |||
@@ -0,0 +1,33 @@ | |||
1 | #ifndef READMAILGUI_H | ||
2 | #define READMAILGUI_H | ||
3 | |||
4 | #include <qmainwindow.h> | ||
5 | #include <qmenubar.h> | ||
6 | #include <qtoolbar.h> | ||
7 | #include <qtextbrowser.h> | ||
8 | #include <qaction.h> | ||
9 | #include <qstring.h> | ||
10 | #include <qdialog.h> | ||
11 | |||
12 | |||
13 | class ReadMailGui : public QDialog | ||
14 | { | ||
15 | Q_OBJECT | ||
16 | |||
17 | public: | ||
18 | ReadMailGui( QWidget* parent = 0, const char* name = 0, bool modal = TRUE, WFlags fl = 0 ); | ||
19 | ~ReadMailGui(); | ||
20 | |||
21 | void passMessage( const QString & message ); | ||
22 | |||
23 | private: | ||
24 | |||
25 | QMainWindow * m_mainWindow; | ||
26 | QToolBar * m_toolBar; | ||
27 | QMenuBar * m_menuBar; | ||
28 | QTextBrowser * m_textWindow; | ||
29 | QAction * m_reply; | ||
30 | |||
31 | }; | ||
32 | |||
33 | #endif | ||
diff --git a/noncore/net/mail/selectmailtypeui.ui b/noncore/net/mail/selectmailtypeui.ui new file mode 100644 index 0000000..1fe0369 --- a/dev/null +++ b/noncore/net/mail/selectmailtypeui.ui | |||
@@ -0,0 +1,94 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>SelectMailTypeUI</class> | ||
3 | <widget> | ||
4 | <class>QDialog</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>SelectMailTypeUI</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>157</width> | ||
15 | <height>66</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Select Type</string> | ||
21 | </property> | ||
22 | <property> | ||
23 | <name>layoutMargin</name> | ||
24 | </property> | ||
25 | <property> | ||
26 | <name>layoutSpacing</name> | ||
27 | </property> | ||
28 | <grid> | ||
29 | <property stdset="1"> | ||
30 | <name>margin</name> | ||
31 | <number>4</number> | ||
32 | </property> | ||
33 | <property stdset="1"> | ||
34 | <name>spacing</name> | ||
35 | <number>3</number> | ||
36 | </property> | ||
37 | <widget row="0" column="0" > | ||
38 | <class>QGroupBox</class> | ||
39 | <property stdset="1"> | ||
40 | <name>name</name> | ||
41 | <cstring>groupBox</cstring> | ||
42 | </property> | ||
43 | <property stdset="1"> | ||
44 | <name>title</name> | ||
45 | <string>Select Account Type</string> | ||
46 | </property> | ||
47 | <property> | ||
48 | <name>layoutMargin</name> | ||
49 | </property> | ||
50 | <property> | ||
51 | <name>layoutSpacing</name> | ||
52 | </property> | ||
53 | <grid> | ||
54 | <property stdset="1"> | ||
55 | <name>margin</name> | ||
56 | <number>4</number> | ||
57 | </property> | ||
58 | <property stdset="1"> | ||
59 | <name>spacing</name> | ||
60 | <number>3</number> | ||
61 | </property> | ||
62 | <widget row="0" column="0" > | ||
63 | <class>QComboBox</class> | ||
64 | <item> | ||
65 | <property> | ||
66 | <name>text</name> | ||
67 | <string>IMAP</string> | ||
68 | </property> | ||
69 | </item> | ||
70 | <item> | ||
71 | <property> | ||
72 | <name>text</name> | ||
73 | <string>POP3</string> | ||
74 | </property> | ||
75 | </item> | ||
76 | <item> | ||
77 | <property> | ||
78 | <name>text</name> | ||
79 | <string>SMTP</string> | ||
80 | </property> | ||
81 | </item> | ||
82 | <property stdset="1"> | ||
83 | <name>name</name> | ||
84 | <cstring>typeBox</cstring> | ||
85 | </property> | ||
86 | </widget> | ||
87 | </grid> | ||
88 | </widget> | ||
89 | </grid> | ||
90 | </widget> | ||
91 | <tabstops> | ||
92 | <tabstop>typeBox</tabstop> | ||
93 | </tabstops> | ||
94 | </UI> | ||
diff --git a/noncore/net/mail/settings.cpp b/noncore/net/mail/settings.cpp new file mode 100644 index 0000000..9632301 --- a/dev/null +++ b/noncore/net/mail/settings.cpp | |||
@@ -0,0 +1,432 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <qdir.h> | ||
3 | |||
4 | #include <qpe/config.h> | ||
5 | |||
6 | #include "settings.h" | ||
7 | #include "defines.h" | ||
8 | |||
9 | Settings::Settings() | ||
10 | : QObject() | ||
11 | { | ||
12 | updateAccounts(); | ||
13 | } | ||
14 | |||
15 | void Settings::checkDirectory() | ||
16 | { | ||
17 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { | ||
18 | system( "mkdir -p $HOME/Applications/opiemail" ); | ||
19 | qDebug( "$HOME/Applications/opiemail created" ); | ||
20 | } | ||
21 | } | ||
22 | |||
23 | QList<Account> Settings::getAccounts() | ||
24 | { | ||
25 | return accounts; | ||
26 | } | ||
27 | |||
28 | void Settings::addAccount( Account *account ) | ||
29 | { | ||
30 | accounts.append( account ); | ||
31 | } | ||
32 | |||
33 | void Settings::delAccount( Account *account ) | ||
34 | { | ||
35 | accounts.remove( account ); | ||
36 | account->remove(); | ||
37 | } | ||
38 | |||
39 | void Settings::updateAccounts() | ||
40 | { | ||
41 | accounts.clear(); | ||
42 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
43 | QStringList::Iterator it; | ||
44 | |||
45 | QStringList imap = dir.entryList( "imap-*" ); | ||
46 | for ( it = imap.begin(); it != imap.end(); it++ ) { | ||
47 | qDebug( "Added IMAP account" ); | ||
48 | IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); | ||
49 | accounts.append( account ); | ||
50 | } | ||
51 | |||
52 | QStringList pop3 = dir.entryList( "pop3-*" ); | ||
53 | for ( it = pop3.begin(); it != pop3.end(); it++ ) { | ||
54 | qDebug( "Added POP account" ); | ||
55 | POP3account *account = new POP3account( (*it).replace(0, 5, "") ); | ||
56 | accounts.append( account ); | ||
57 | } | ||
58 | |||
59 | QStringList smtp = dir.entryList( "smtp-*" ); | ||
60 | for ( it = smtp.begin(); it != smtp.end(); it++ ) { | ||
61 | qDebug( "Added SMTP account" ); | ||
62 | SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); | ||
63 | accounts.append( account ); | ||
64 | } | ||
65 | |||
66 | QStringList nntp = dir.entryList( "nntp-*" ); | ||
67 | for ( it = nntp.begin(); it != nntp.end(); it++ ) { | ||
68 | qDebug( "Added NNTP account" ); | ||
69 | NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); | ||
70 | accounts.append( account ); | ||
71 | } | ||
72 | |||
73 | readAccounts(); | ||
74 | } | ||
75 | |||
76 | void Settings::saveAccounts() | ||
77 | { | ||
78 | checkDirectory(); | ||
79 | Account *it; | ||
80 | |||
81 | for ( it = accounts.first(); it; it = accounts.next() ) { | ||
82 | it->save(); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | void Settings::readAccounts() | ||
87 | { | ||
88 | checkDirectory(); | ||
89 | Account *it; | ||
90 | |||
91 | for ( it = accounts.first(); it; it = accounts.next() ) { | ||
92 | it->read(); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | Account::Account() | ||
97 | { | ||
98 | accountName = "changeMe"; | ||
99 | type = "changeMe"; | ||
100 | ssl = false; | ||
101 | } | ||
102 | |||
103 | void Account::remove() | ||
104 | { | ||
105 | QFile file( getFileName() ); | ||
106 | file.remove(); | ||
107 | } | ||
108 | |||
109 | IMAPaccount::IMAPaccount() | ||
110 | : Account() | ||
111 | { | ||
112 | file = IMAPaccount::getUniqueFileName(); | ||
113 | accountName = "New IMAP Account"; | ||
114 | ssl = false; | ||
115 | type = "IMAP"; | ||
116 | port = IMAP_PORT; | ||
117 | } | ||
118 | |||
119 | IMAPaccount::IMAPaccount( QString filename ) | ||
120 | : Account() | ||
121 | { | ||
122 | file = filename; | ||
123 | accountName = "New IMAP Account"; | ||
124 | ssl = false; | ||
125 | type = "IMAP"; | ||
126 | port = IMAP_PORT; | ||
127 | } | ||
128 | |||
129 | QString IMAPaccount::getUniqueFileName() | ||
130 | { | ||
131 | int num = 0; | ||
132 | QString unique; | ||
133 | |||
134 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
135 | QStringList::Iterator it; | ||
136 | |||
137 | QStringList imap = dir.entryList( "imap-*" ); | ||
138 | do { | ||
139 | unique.setNum( num++ ); | ||
140 | } while ( imap.contains( "imap-" + unique ) > 0 ); | ||
141 | |||
142 | return unique; | ||
143 | } | ||
144 | |||
145 | void IMAPaccount::read() | ||
146 | { | ||
147 | Config *conf = new Config( getFileName(), Config::File ); | ||
148 | conf->setGroup( "IMAP Account" ); | ||
149 | accountName = conf->readEntry( "Account","" ); | ||
150 | if (accountName.isNull()) accountName = ""; | ||
151 | server = conf->readEntry( "Server","" ); | ||
152 | if (server.isNull()) server=""; | ||
153 | port = conf->readEntry( "Port","" ); | ||
154 | if (port.isNull()) port="143"; | ||
155 | ssl = conf->readBoolEntry( "SSL",false ); | ||
156 | user = conf->readEntry( "User","" ); | ||
157 | if (user.isNull()) user = ""; | ||
158 | password = conf->readEntryCrypt( "Password","" ); | ||
159 | if (password.isNull()) password = ""; | ||
160 | prefix = conf->readEntry("MailPrefix",""); | ||
161 | if (prefix.isNull()) prefix = ""; | ||
162 | } | ||
163 | |||
164 | void IMAPaccount::save() | ||
165 | { | ||
166 | qDebug( "saving " + getFileName() ); | ||
167 | Settings::checkDirectory(); | ||
168 | |||
169 | Config *conf = new Config( getFileName(), Config::File ); | ||
170 | conf->setGroup( "IMAP Account" ); | ||
171 | conf->writeEntry( "Account", accountName ); | ||
172 | conf->writeEntry( "Server", server ); | ||
173 | conf->writeEntry( "Port", port ); | ||
174 | conf->writeEntry( "SSL", ssl ); | ||
175 | conf->writeEntry( "User", user ); | ||
176 | conf->writeEntryCrypt( "Password", password ); | ||
177 | conf->writeEntry( "MailPrefix",prefix); | ||
178 | conf->write(); | ||
179 | } | ||
180 | |||
181 | |||
182 | QString IMAPaccount::getFileName() | ||
183 | { | ||
184 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/imap-" + file; | ||
185 | } | ||
186 | |||
187 | POP3account::POP3account() | ||
188 | : Account() | ||
189 | { | ||
190 | file = POP3account::getUniqueFileName(); | ||
191 | accountName = "New POP3 Account"; | ||
192 | ssl = false; | ||
193 | type = "POP3"; | ||
194 | port = POP3_PORT; | ||
195 | } | ||
196 | |||
197 | POP3account::POP3account( QString filename ) | ||
198 | : Account() | ||
199 | { | ||
200 | file = filename; | ||
201 | accountName = "New POP3 Account"; | ||
202 | ssl = false; | ||
203 | type = "POP3"; | ||
204 | port = POP3_PORT; | ||
205 | } | ||
206 | |||
207 | QString POP3account::getUniqueFileName() | ||
208 | { | ||
209 | int num = 0; | ||
210 | QString unique; | ||
211 | |||
212 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
213 | QStringList::Iterator it; | ||
214 | |||
215 | QStringList imap = dir.entryList( "pop3-*" ); | ||
216 | do { | ||
217 | unique.setNum( num++ ); | ||
218 | } while ( imap.contains( "pop3-" + unique ) > 0 ); | ||
219 | |||
220 | return unique; | ||
221 | } | ||
222 | |||
223 | void POP3account::read() | ||
224 | { | ||
225 | Config *conf = new Config( getFileName(), Config::File ); | ||
226 | conf->setGroup( "POP3 Account" ); | ||
227 | accountName = conf->readEntry( "Account" ); | ||
228 | server = conf->readEntry( "Server" ); | ||
229 | port = conf->readEntry( "Port" ); | ||
230 | ssl = conf->readBoolEntry( "SSL" ); | ||
231 | user = conf->readEntry( "User" ); | ||
232 | password = conf->readEntryCrypt( "Password" ); | ||
233 | } | ||
234 | |||
235 | void POP3account::save() | ||
236 | { | ||
237 | qDebug( "saving " + getFileName() ); | ||
238 | Settings::checkDirectory(); | ||
239 | |||
240 | Config *conf = new Config( getFileName(), Config::File ); | ||
241 | conf->setGroup( "POP3 Account" ); | ||
242 | conf->writeEntry( "Account", accountName ); | ||
243 | conf->writeEntry( "Server", server ); | ||
244 | conf->writeEntry( "Port", port ); | ||
245 | conf->writeEntry( "SSL", ssl ); | ||
246 | conf->writeEntry( "User", user ); | ||
247 | conf->writeEntryCrypt( "Password", password ); | ||
248 | conf->write(); | ||
249 | } | ||
250 | |||
251 | |||
252 | QString POP3account::getFileName() | ||
253 | { | ||
254 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/pop3-" + file; | ||
255 | } | ||
256 | |||
257 | SMTPaccount::SMTPaccount() | ||
258 | : Account() | ||
259 | { | ||
260 | file = SMTPaccount::getUniqueFileName(); | ||
261 | accountName = "New SMTP Account"; | ||
262 | ssl = false; | ||
263 | login = false; | ||
264 | useCC = false; | ||
265 | useBCC = false; | ||
266 | useReply = false; | ||
267 | type = "SMTP"; | ||
268 | port = SMTP_PORT; | ||
269 | } | ||
270 | |||
271 | SMTPaccount::SMTPaccount( QString filename ) | ||
272 | : Account() | ||
273 | { | ||
274 | file = filename; | ||
275 | accountName = "New SMTP Account"; | ||
276 | ssl = false; | ||
277 | login = false; | ||
278 | useCC = false; | ||
279 | useBCC = false; | ||
280 | useReply = false; | ||
281 | type = "SMTP"; | ||
282 | port = SMTP_PORT; | ||
283 | } | ||
284 | |||
285 | QString SMTPaccount::getUniqueFileName() | ||
286 | { | ||
287 | int num = 0; | ||
288 | QString unique; | ||
289 | |||
290 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
291 | QStringList::Iterator it; | ||
292 | |||
293 | QStringList imap = dir.entryList( "smtp-*" ); | ||
294 | do { | ||
295 | unique.setNum( num++ ); | ||
296 | } while ( imap.contains( "smtp-" + unique ) > 0 ); | ||
297 | |||
298 | return unique; | ||
299 | } | ||
300 | |||
301 | void SMTPaccount::read() | ||
302 | { | ||
303 | Config *conf = new Config( getFileName(), Config::File ); | ||
304 | conf->setGroup( "SMTP Account" ); | ||
305 | accountName = conf->readEntry( "Account" ); | ||
306 | server = conf->readEntry( "Server" ); | ||
307 | port = conf->readEntry( "Port" ); | ||
308 | ssl = conf->readBoolEntry( "SSL" ); | ||
309 | login = conf->readBoolEntry( "Login" ); | ||
310 | user = conf->readEntry( "User" ); | ||
311 | password = conf->readEntryCrypt( "Password" ); | ||
312 | useCC = conf->readBoolEntry( "useCC" ); | ||
313 | useBCC = conf->readBoolEntry( "useBCC" ); | ||
314 | useReply = conf->readBoolEntry( "useReply" ); | ||
315 | name = conf->readEntry( "Name" ); | ||
316 | mail = conf->readEntry( "Mail" ); | ||
317 | org = conf->readEntry( "Org" ); | ||
318 | cc = conf->readEntry( "CC" ); | ||
319 | bcc = conf->readEntry( "BCC" ); | ||
320 | reply = conf->readEntry( "Reply" ); | ||
321 | signature = conf->readEntry( "Signature" ); | ||
322 | signature = signature.replace( QRegExp( "<br>" ), "\n" ); | ||
323 | } | ||
324 | |||
325 | void SMTPaccount::save() | ||
326 | { | ||
327 | qDebug( "saving " + getFileName() ); | ||
328 | Settings::checkDirectory(); | ||
329 | |||
330 | Config *conf = new Config( getFileName(), Config::File ); | ||
331 | conf->setGroup( "SMTP Account" ); | ||
332 | conf->writeEntry( "Account", accountName ); | ||
333 | conf->writeEntry( "Server", server ); | ||
334 | conf->writeEntry( "Port", port ); | ||
335 | conf->writeEntry( "SSL", ssl ); | ||
336 | conf->writeEntry( "Login", login ); | ||
337 | conf->writeEntry( "User", user ); | ||
338 | conf->writeEntryCrypt( "Password", password ); | ||
339 | conf->writeEntry( "useCC", useCC ); | ||
340 | conf->writeEntry( "useBCC", useBCC ); | ||
341 | conf->writeEntry( "useReply", useReply ); | ||
342 | conf->writeEntry( "Name", name ); | ||
343 | conf->writeEntry( "Mail", mail ); | ||
344 | conf->writeEntry( "Org", org ); | ||
345 | conf->writeEntry( "CC", cc ); | ||
346 | conf->writeEntry( "BCC", bcc ); | ||
347 | conf->writeEntry( "Reply", reply ); | ||
348 | conf->writeEntry( "Signature", | ||
349 | signature.replace( QRegExp( "\\n" ), "<br>" ) ); | ||
350 | conf->write(); | ||
351 | } | ||
352 | |||
353 | |||
354 | QString SMTPaccount::getFileName() | ||
355 | { | ||
356 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/smtp-" + file; | ||
357 | } | ||
358 | |||
359 | NNTPaccount::NNTPaccount() | ||
360 | : Account() | ||
361 | { | ||
362 | file = NNTPaccount::getUniqueFileName(); | ||
363 | accountName = "New NNTP Account"; | ||
364 | ssl = false; | ||
365 | login = false; | ||
366 | type = "NNTP"; | ||
367 | port = NNTP_PORT; | ||
368 | } | ||
369 | |||
370 | NNTPaccount::NNTPaccount( QString filename ) | ||
371 | : Account() | ||
372 | { | ||
373 | file = filename; | ||
374 | accountName = "New NNTP Account"; | ||
375 | ssl = false; | ||
376 | login = false; | ||
377 | type = "NNTP"; | ||
378 | port = NNTP_PORT; | ||
379 | } | ||
380 | |||
381 | QString NNTPaccount::getUniqueFileName() | ||
382 | { | ||
383 | int num = 0; | ||
384 | QString unique; | ||
385 | |||
386 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
387 | QStringList::Iterator it; | ||
388 | |||
389 | QStringList imap = dir.entryList( "nntp-*" ); | ||
390 | do { | ||
391 | unique.setNum( num++ ); | ||
392 | } while ( imap.contains( "nntp-" + unique ) > 0 ); | ||
393 | |||
394 | return unique; | ||
395 | } | ||
396 | |||
397 | void NNTPaccount::read() | ||
398 | { | ||
399 | Config *conf = new Config( getFileName(), Config::File ); | ||
400 | conf->setGroup( "NNTP Account" ); | ||
401 | accountName = conf->readEntry( "Account" ); | ||
402 | server = conf->readEntry( "Server" ); | ||
403 | port = conf->readEntry( "Port" ); | ||
404 | ssl = conf->readBoolEntry( "SSL" ); | ||
405 | login = conf->readBoolEntry( "Login" ); | ||
406 | user = conf->readEntry( "User" ); | ||
407 | password = conf->readEntryCrypt( "Password" ); | ||
408 | } | ||
409 | |||
410 | void NNTPaccount::save() | ||
411 | { | ||
412 | qDebug( "saving " + getFileName() ); | ||
413 | Settings::checkDirectory(); | ||
414 | |||
415 | Config *conf = new Config( getFileName(), Config::File ); | ||
416 | conf->setGroup( "NNTP Account" ); | ||
417 | conf->writeEntry( "Account", accountName ); | ||
418 | conf->writeEntry( "Server", server ); | ||
419 | conf->writeEntry( "Port", port ); | ||
420 | conf->writeEntry( "SSL", ssl ); | ||
421 | conf->writeEntry( "Login", login ); | ||
422 | conf->writeEntry( "User", user ); | ||
423 | conf->writeEntryCrypt( "Password", password ); | ||
424 | conf->write(); | ||
425 | } | ||
426 | |||
427 | |||
428 | QString NNTPaccount::getFileName() | ||
429 | { | ||
430 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/nntp-" + file; | ||
431 | } | ||
432 | |||
diff --git a/noncore/net/mail/settings.h b/noncore/net/mail/settings.h new file mode 100644 index 0000000..22184a5 --- a/dev/null +++ b/noncore/net/mail/settings.h | |||
@@ -0,0 +1,166 @@ | |||
1 | #ifndef SETTINGS_H | ||
2 | #define SETTINGS_H | ||
3 | |||
4 | #include <qobject.h> | ||
5 | #include <qlist.h> | ||
6 | |||
7 | class Account | ||
8 | { | ||
9 | |||
10 | public: | ||
11 | Account(); | ||
12 | virtual ~Account() {} | ||
13 | |||
14 | void remove(); | ||
15 | void setAccountName( QString name ) { accountName = name; } | ||
16 | const QString&getAccountName()const{ return accountName; } | ||
17 | const QString&getType()const{ return type; } | ||
18 | |||
19 | void setServer(const QString&str){ server = str; } | ||
20 | const QString&getServer()const{ return server; } | ||
21 | |||
22 | void setPort(const QString&str) { port = str; } | ||
23 | const QString&getPort()const{ return port; } | ||
24 | |||
25 | void setUser(const QString&str){ user = str; } | ||
26 | const QString&getUser()const{ return user; } | ||
27 | |||
28 | void setPassword(const QString&str) { password = str; } | ||
29 | const QString&getPassword()const { return password; } | ||
30 | |||
31 | void setSSL( bool b ) { ssl = b; } | ||
32 | bool getSSL() { return ssl; } | ||
33 | |||
34 | virtual QString getFileName() { return accountName; } | ||
35 | virtual void read() { qDebug( "base reading..." ); } | ||
36 | virtual void save() { qDebug( "base saving..." ); } | ||
37 | |||
38 | protected: | ||
39 | QString accountName, type, server, port, user, password; | ||
40 | bool ssl; | ||
41 | |||
42 | }; | ||
43 | |||
44 | class IMAPaccount : public Account | ||
45 | { | ||
46 | |||
47 | public: | ||
48 | IMAPaccount(); | ||
49 | IMAPaccount( QString filename ); | ||
50 | |||
51 | static QString getUniqueFileName(); | ||
52 | |||
53 | virtual void read(); | ||
54 | virtual void save(); | ||
55 | virtual QString getFileName(); | ||
56 | |||
57 | void setPrefix(const QString&str) {prefix=str;} | ||
58 | const QString&getPrefix()const{return prefix;} | ||
59 | |||
60 | private: | ||
61 | QString file,prefix; | ||
62 | |||
63 | }; | ||
64 | |||
65 | class POP3account : public Account | ||
66 | { | ||
67 | |||
68 | public: | ||
69 | POP3account(); | ||
70 | POP3account( QString filename ); | ||
71 | |||
72 | static QString getUniqueFileName(); | ||
73 | |||
74 | virtual void read(); | ||
75 | virtual void save(); | ||
76 | virtual QString getFileName(); | ||
77 | |||
78 | private: | ||
79 | QString file; | ||
80 | |||
81 | }; | ||
82 | |||
83 | class SMTPaccount : public Account | ||
84 | { | ||
85 | |||
86 | public: | ||
87 | SMTPaccount(); | ||
88 | SMTPaccount( QString filename ); | ||
89 | |||
90 | static QString getUniqueFileName(); | ||
91 | |||
92 | virtual void read(); | ||
93 | virtual void save(); | ||
94 | virtual QString getFileName(); | ||
95 | |||
96 | void setName( QString str ) { name = str; } | ||
97 | QString getName() { return name; } | ||
98 | void setMail( QString str ) { mail = str; } | ||
99 | QString getMail() { return mail; } | ||
100 | void setOrg( QString str ) { org = str; } | ||
101 | QString getOrg() { return org; } | ||
102 | void setUseCC( bool b ) { useCC = b; } | ||
103 | bool getUseCC() { return useCC; } | ||
104 | void setCC( QString str ) { cc = str; } | ||
105 | QString getCC() { return cc; } | ||
106 | void setUseBCC( bool b ) { useBCC = b; } | ||
107 | bool getUseBCC() { return useBCC; } | ||
108 | void setBCC( QString str ) { bcc = str; } | ||
109 | QString getBCC() { return bcc; } | ||
110 | void setUseReply( bool b ) { useReply = b; } | ||
111 | bool getUseReply() { return useReply; } | ||
112 | void setReply( QString str ) { reply = str; } | ||
113 | QString getReply() { return reply; } | ||
114 | void setSignature( QString str ) { signature = str; } | ||
115 | QString getSignature() { return signature; } | ||
116 | void setLogin( bool b ) { login = b; } | ||
117 | bool getLogin() { return login; } | ||
118 | |||
119 | private: | ||
120 | QString file, name, mail, org, cc, bcc, reply, signature; | ||
121 | bool useCC, useBCC, useReply, login; | ||
122 | |||
123 | }; | ||
124 | |||
125 | class NNTPaccount : public Account | ||
126 | { | ||
127 | |||
128 | public: | ||
129 | NNTPaccount(); | ||
130 | NNTPaccount( QString filename ); | ||
131 | |||
132 | static QString getUniqueFileName(); | ||
133 | |||
134 | virtual void read(); | ||
135 | virtual void save(); | ||
136 | virtual QString getFileName(); | ||
137 | |||
138 | void setLogin( bool b ) { login = b; } | ||
139 | bool getLogin() { return login; } | ||
140 | |||
141 | private: | ||
142 | QString file; | ||
143 | bool login; | ||
144 | |||
145 | }; | ||
146 | |||
147 | class Settings : public QObject | ||
148 | { | ||
149 | Q_OBJECT | ||
150 | |||
151 | public: | ||
152 | Settings(); | ||
153 | QList<Account> getAccounts(); | ||
154 | void addAccount(Account *account); | ||
155 | void delAccount(Account *account); | ||
156 | void saveAccounts(); | ||
157 | void readAccounts(); | ||
158 | static void checkDirectory(); | ||
159 | |||
160 | private: | ||
161 | void updateAccounts(); | ||
162 | QList<Account> accounts; | ||
163 | |||
164 | }; | ||
165 | |||
166 | #endif | ||
diff --git a/noncore/net/mail/smtpconfigui.ui b/noncore/net/mail/smtpconfigui.ui new file mode 100644 index 0000000..2cae8d6 --- a/dev/null +++ b/noncore/net/mail/smtpconfigui.ui | |||
@@ -0,0 +1,500 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>SMTPconfigUI</class> | ||
3 | <widget> | ||
4 | <class>QDialog</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>SMTPconfigUI</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>253</width> | ||
15 | <height>342</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Configure SMTP</string> | ||
21 | </property> | ||
22 | <property> | ||
23 | <name>layoutMargin</name> | ||
24 | </property> | ||
25 | <property> | ||
26 | <name>layoutSpacing</name> | ||
27 | </property> | ||
28 | <vbox> | ||
29 | <property stdset="1"> | ||
30 | <name>margin</name> | ||
31 | <number>0</number> | ||
32 | </property> | ||
33 | <property stdset="1"> | ||
34 | <name>spacing</name> | ||
35 | <number>0</number> | ||
36 | </property> | ||
37 | <widget> | ||
38 | <class>QTabWidget</class> | ||
39 | <property stdset="1"> | ||
40 | <name>name</name> | ||
41 | <cstring>smtpTab</cstring> | ||
42 | </property> | ||
43 | <property stdset="1"> | ||
44 | <name>caption</name> | ||
45 | <string></string> | ||
46 | </property> | ||
47 | <property> | ||
48 | <name>layoutMargin</name> | ||
49 | </property> | ||
50 | <property> | ||
51 | <name>layoutSpacing</name> | ||
52 | </property> | ||
53 | <widget> | ||
54 | <class>QWidget</class> | ||
55 | <property stdset="1"> | ||
56 | <name>name</name> | ||
57 | <cstring>serverTab</cstring> | ||
58 | </property> | ||
59 | <attribute> | ||
60 | <name>title</name> | ||
61 | <string>Server</string> | ||
62 | </attribute> | ||
63 | <grid> | ||
64 | <property stdset="1"> | ||
65 | <name>margin</name> | ||
66 | <number>4</number> | ||
67 | </property> | ||
68 | <property stdset="1"> | ||
69 | <name>spacing</name> | ||
70 | <number>3</number> | ||
71 | </property> | ||
72 | <widget row="3" column="0" > | ||
73 | <class>QLabel</class> | ||
74 | <property stdset="1"> | ||
75 | <name>name</name> | ||
76 | <cstring>portLabel</cstring> | ||
77 | </property> | ||
78 | <property stdset="1"> | ||
79 | <name>text</name> | ||
80 | <string>Port</string> | ||
81 | </property> | ||
82 | </widget> | ||
83 | <widget row="2" column="1" rowspan="1" colspan="2" > | ||
84 | <class>QLineEdit</class> | ||
85 | <property stdset="1"> | ||
86 | <name>name</name> | ||
87 | <cstring>serverLine</cstring> | ||
88 | </property> | ||
89 | <property> | ||
90 | <name>toolTip</name> | ||
91 | <string>Name of the SMTP Server</string> | ||
92 | </property> | ||
93 | </widget> | ||
94 | <widget row="2" column="0" > | ||
95 | <class>QLabel</class> | ||
96 | <property stdset="1"> | ||
97 | <name>name</name> | ||
98 | <cstring>serverLabel</cstring> | ||
99 | </property> | ||
100 | <property stdset="1"> | ||
101 | <name>text</name> | ||
102 | <string>Server</string> | ||
103 | </property> | ||
104 | </widget> | ||
105 | <widget row="3" column="1" rowspan="1" colspan="2" > | ||
106 | <class>QLineEdit</class> | ||
107 | <property stdset="1"> | ||
108 | <name>name</name> | ||
109 | <cstring>portLine</cstring> | ||
110 | </property> | ||
111 | <property> | ||
112 | <name>toolTip</name> | ||
113 | <string>Port of the SMTP Server</string> | ||
114 | </property> | ||
115 | </widget> | ||
116 | <widget row="0" column="0" > | ||
117 | <class>QLabel</class> | ||
118 | <property stdset="1"> | ||
119 | <name>name</name> | ||
120 | <cstring>accountLabel</cstring> | ||
121 | </property> | ||
122 | <property stdset="1"> | ||
123 | <name>text</name> | ||
124 | <string>Account</string> | ||
125 | </property> | ||
126 | </widget> | ||
127 | <widget row="0" column="1" rowspan="1" colspan="2" > | ||
128 | <class>QLineEdit</class> | ||
129 | <property stdset="1"> | ||
130 | <name>name</name> | ||
131 | <cstring>accountLine</cstring> | ||
132 | </property> | ||
133 | <property> | ||
134 | <name>toolTip</name> | ||
135 | <string>Name of the Account</string> | ||
136 | </property> | ||
137 | </widget> | ||
138 | <widget row="1" column="0" rowspan="1" colspan="3" > | ||
139 | <class>Line</class> | ||
140 | <property stdset="1"> | ||
141 | <name>name</name> | ||
142 | <cstring>line1</cstring> | ||
143 | </property> | ||
144 | <property stdset="1"> | ||
145 | <name>orientation</name> | ||
146 | <enum>Horizontal</enum> | ||
147 | </property> | ||
148 | </widget> | ||
149 | <widget row="4" column="1" > | ||
150 | <class>QCheckBox</class> | ||
151 | <property stdset="1"> | ||
152 | <name>name</name> | ||
153 | <cstring>sslBox</cstring> | ||
154 | </property> | ||
155 | <property stdset="1"> | ||
156 | <name>text</name> | ||
157 | <string>Use SSL</string> | ||
158 | </property> | ||
159 | </widget> | ||
160 | <widget row="5" column="0" rowspan="1" colspan="3" > | ||
161 | <class>Line</class> | ||
162 | <property stdset="1"> | ||
163 | <name>name</name> | ||
164 | <cstring>line2</cstring> | ||
165 | </property> | ||
166 | <property stdset="1"> | ||
167 | <name>orientation</name> | ||
168 | <enum>Horizontal</enum> | ||
169 | </property> | ||
170 | </widget> | ||
171 | <widget row="8" column="1" rowspan="1" colspan="2" > | ||
172 | <class>QLineEdit</class> | ||
173 | <property stdset="1"> | ||
174 | <name>name</name> | ||
175 | <cstring>passLine</cstring> | ||
176 | </property> | ||
177 | <property stdset="1"> | ||
178 | <name>enabled</name> | ||
179 | <bool>false</bool> | ||
180 | </property> | ||
181 | <property stdset="1"> | ||
182 | <name>echoMode</name> | ||
183 | <enum>Password</enum> | ||
184 | </property> | ||
185 | </widget> | ||
186 | <widget row="6" column="1" rowspan="1" colspan="2" > | ||
187 | <class>QCheckBox</class> | ||
188 | <property stdset="1"> | ||
189 | <name>name</name> | ||
190 | <cstring>loginBox</cstring> | ||
191 | </property> | ||
192 | <property stdset="1"> | ||
193 | <name>text</name> | ||
194 | <string>Use Login</string> | ||
195 | </property> | ||
196 | </widget> | ||
197 | <widget row="8" column="0" > | ||
198 | <class>QLabel</class> | ||
199 | <property stdset="1"> | ||
200 | <name>name</name> | ||
201 | <cstring>passLabel</cstring> | ||
202 | </property> | ||
203 | <property stdset="1"> | ||
204 | <name>text</name> | ||
205 | <string>Password</string> | ||
206 | </property> | ||
207 | </widget> | ||
208 | <widget row="7" column="0" > | ||
209 | <class>QLabel</class> | ||
210 | <property stdset="1"> | ||
211 | <name>name</name> | ||
212 | <cstring>userLabel</cstring> | ||
213 | </property> | ||
214 | <property stdset="1"> | ||
215 | <name>text</name> | ||
216 | <string>User</string> | ||
217 | </property> | ||
218 | </widget> | ||
219 | <widget row="7" column="1" rowspan="1" colspan="2" > | ||
220 | <class>QLineEdit</class> | ||
221 | <property stdset="1"> | ||
222 | <name>name</name> | ||
223 | <cstring>userLine</cstring> | ||
224 | </property> | ||
225 | <property stdset="1"> | ||
226 | <name>enabled</name> | ||
227 | <bool>false</bool> | ||
228 | </property> | ||
229 | </widget> | ||
230 | <spacer row="9" column="2" > | ||
231 | <property> | ||
232 | <name>name</name> | ||
233 | <cstring>spacer</cstring> | ||
234 | </property> | ||
235 | <property stdset="1"> | ||
236 | <name>orientation</name> | ||
237 | <enum>Vertical</enum> | ||
238 | </property> | ||
239 | <property stdset="1"> | ||
240 | <name>sizeType</name> | ||
241 | <enum>Expanding</enum> | ||
242 | </property> | ||
243 | <property> | ||
244 | <name>sizeHint</name> | ||
245 | <size> | ||
246 | <width>20</width> | ||
247 | <height>20</height> | ||
248 | </size> | ||
249 | </property> | ||
250 | </spacer> | ||
251 | </grid> | ||
252 | </widget> | ||
253 | <widget> | ||
254 | <class>QWidget</class> | ||
255 | <property stdset="1"> | ||
256 | <name>name</name> | ||
257 | <cstring>identityTab</cstring> | ||
258 | </property> | ||
259 | <attribute> | ||
260 | <name>title</name> | ||
261 | <string>Identity</string> | ||
262 | </attribute> | ||
263 | <grid> | ||
264 | <property stdset="1"> | ||
265 | <name>margin</name> | ||
266 | <number>4</number> | ||
267 | </property> | ||
268 | <property stdset="1"> | ||
269 | <name>spacing</name> | ||
270 | <number>3</number> | ||
271 | </property> | ||
272 | <widget row="9" column="0" rowspan="1" colspan="4" > | ||
273 | <class>QMultiLineEdit</class> | ||
274 | <property stdset="1"> | ||
275 | <name>name</name> | ||
276 | <cstring>sigMultiLine</cstring> | ||
277 | </property> | ||
278 | </widget> | ||
279 | <spacer row="10" column="3" > | ||
280 | <property> | ||
281 | <name>name</name> | ||
282 | <cstring>Spacer3</cstring> | ||
283 | </property> | ||
284 | <property stdset="1"> | ||
285 | <name>orientation</name> | ||
286 | <enum>Vertical</enum> | ||
287 | </property> | ||
288 | <property stdset="1"> | ||
289 | <name>sizeType</name> | ||
290 | <enum>Expanding</enum> | ||
291 | </property> | ||
292 | <property> | ||
293 | <name>sizeHint</name> | ||
294 | <size> | ||
295 | <width>20</width> | ||
296 | <height>20</height> | ||
297 | </size> | ||
298 | </property> | ||
299 | <property> | ||
300 | <name>toolTip</name> | ||
301 | <string>Name of the Account</string> | ||
302 | </property> | ||
303 | </spacer> | ||
304 | <widget row="8" column="0" rowspan="1" colspan="3" > | ||
305 | <class>QLabel</class> | ||
306 | <property stdset="1"> | ||
307 | <name>name</name> | ||
308 | <cstring>sigLabel</cstring> | ||
309 | </property> | ||
310 | <property stdset="1"> | ||
311 | <name>text</name> | ||
312 | <string>Signature</string> | ||
313 | </property> | ||
314 | </widget> | ||
315 | <widget row="6" column="2" rowspan="1" colspan="2" > | ||
316 | <class>QLineEdit</class> | ||
317 | <property stdset="1"> | ||
318 | <name>name</name> | ||
319 | <cstring>replyLine</cstring> | ||
320 | </property> | ||
321 | <property stdset="1"> | ||
322 | <name>enabled</name> | ||
323 | <bool>false</bool> | ||
324 | </property> | ||
325 | </widget> | ||
326 | <widget row="5" column="2" rowspan="1" colspan="2" > | ||
327 | <class>QLineEdit</class> | ||
328 | <property stdset="1"> | ||
329 | <name>name</name> | ||
330 | <cstring>bccLine</cstring> | ||
331 | </property> | ||
332 | <property stdset="1"> | ||
333 | <name>enabled</name> | ||
334 | <bool>false</bool> | ||
335 | </property> | ||
336 | </widget> | ||
337 | <widget row="4" column="2" rowspan="1" colspan="2" > | ||
338 | <class>QLineEdit</class> | ||
339 | <property stdset="1"> | ||
340 | <name>name</name> | ||
341 | <cstring>ccLine</cstring> | ||
342 | </property> | ||
343 | <property stdset="1"> | ||
344 | <name>enabled</name> | ||
345 | <bool>false</bool> | ||
346 | </property> | ||
347 | </widget> | ||
348 | <widget row="5" column="0" rowspan="1" colspan="2" > | ||
349 | <class>QCheckBox</class> | ||
350 | <property stdset="1"> | ||
351 | <name>name</name> | ||
352 | <cstring>bccBox</cstring> | ||
353 | </property> | ||
354 | <property stdset="1"> | ||
355 | <name>text</name> | ||
356 | <string>BCC</string> | ||
357 | </property> | ||
358 | </widget> | ||
359 | <widget row="6" column="0" rowspan="1" colspan="2" > | ||
360 | <class>QCheckBox</class> | ||
361 | <property stdset="1"> | ||
362 | <name>name</name> | ||
363 | <cstring>replyBox</cstring> | ||
364 | </property> | ||
365 | <property stdset="1"> | ||
366 | <name>text</name> | ||
367 | <string>Reply-To</string> | ||
368 | </property> | ||
369 | </widget> | ||
370 | <widget row="4" column="0" rowspan="1" colspan="2" > | ||
371 | <class>QCheckBox</class> | ||
372 | <property stdset="1"> | ||
373 | <name>name</name> | ||
374 | <cstring>ccBox</cstring> | ||
375 | </property> | ||
376 | <property stdset="1"> | ||
377 | <name>text</name> | ||
378 | <string>CC</string> | ||
379 | </property> | ||
380 | </widget> | ||
381 | <widget row="1" column="0" > | ||
382 | <class>QLabel</class> | ||
383 | <property stdset="1"> | ||
384 | <name>name</name> | ||
385 | <cstring>mailLabel</cstring> | ||
386 | </property> | ||
387 | <property stdset="1"> | ||
388 | <name>text</name> | ||
389 | <string>E-Mail</string> | ||
390 | </property> | ||
391 | </widget> | ||
392 | <widget row="0" column="1" rowspan="1" colspan="3" > | ||
393 | <class>QLineEdit</class> | ||
394 | <property stdset="1"> | ||
395 | <name>name</name> | ||
396 | <cstring>nameLine</cstring> | ||
397 | </property> | ||
398 | <property> | ||
399 | <name>toolTip</name> | ||
400 | <string>Your Full Name</string> | ||
401 | </property> | ||
402 | </widget> | ||
403 | <widget row="0" column="0" > | ||
404 | <class>QLabel</class> | ||
405 | <property stdset="1"> | ||
406 | <name>name</name> | ||
407 | <cstring>nameLabel</cstring> | ||
408 | </property> | ||
409 | <property stdset="1"> | ||
410 | <name>text</name> | ||
411 | <string>Name</string> | ||
412 | </property> | ||
413 | </widget> | ||
414 | <widget row="2" column="0" > | ||
415 | <class>QLabel</class> | ||
416 | <property stdset="1"> | ||
417 | <name>name</name> | ||
418 | <cstring>orgLabel</cstring> | ||
419 | </property> | ||
420 | <property stdset="1"> | ||
421 | <name>text</name> | ||
422 | <string>Org.</string> | ||
423 | </property> | ||
424 | <property> | ||
425 | <name>layoutMargin</name> | ||
426 | </property> | ||
427 | <property> | ||
428 | <name>layoutSpacing</name> | ||
429 | </property> | ||
430 | </widget> | ||
431 | <widget row="2" column="1" rowspan="1" colspan="3" > | ||
432 | <class>QLineEdit</class> | ||
433 | <property stdset="1"> | ||
434 | <name>name</name> | ||
435 | <cstring>orgLine</cstring> | ||
436 | </property> | ||
437 | <property> | ||
438 | <name>toolTip</name> | ||
439 | <string>Your Organisation</string> | ||
440 | </property> | ||
441 | </widget> | ||
442 | <widget row="1" column="1" rowspan="1" colspan="3" > | ||
443 | <class>QLineEdit</class> | ||
444 | <property stdset="1"> | ||
445 | <name>name</name> | ||
446 | <cstring>mailLine</cstring> | ||
447 | </property> | ||
448 | <property> | ||
449 | <name>toolTip</name> | ||
450 | <string>Your E-Mail Adress</string> | ||
451 | </property> | ||
452 | </widget> | ||
453 | <widget row="3" column="0" rowspan="1" colspan="4" > | ||
454 | <class>Line</class> | ||
455 | <property stdset="1"> | ||
456 | <name>name</name> | ||
457 | <cstring>line3</cstring> | ||
458 | </property> | ||
459 | <property stdset="1"> | ||
460 | <name>orientation</name> | ||
461 | <enum>Horizontal</enum> | ||
462 | </property> | ||
463 | </widget> | ||
464 | <widget row="7" column="0" rowspan="1" colspan="4" > | ||
465 | <class>Line</class> | ||
466 | <property stdset="1"> | ||
467 | <name>name</name> | ||
468 | <cstring>line4</cstring> | ||
469 | </property> | ||
470 | <property stdset="1"> | ||
471 | <name>orientation</name> | ||
472 | <enum>Horizontal</enum> | ||
473 | </property> | ||
474 | </widget> | ||
475 | </grid> | ||
476 | </widget> | ||
477 | </widget> | ||
478 | </vbox> | ||
479 | </widget> | ||
480 | <tabstops> | ||
481 | <tabstop>accountLine</tabstop> | ||
482 | <tabstop>serverLine</tabstop> | ||
483 | <tabstop>portLine</tabstop> | ||
484 | <tabstop>sslBox</tabstop> | ||
485 | <tabstop>loginBox</tabstop> | ||
486 | <tabstop>userLine</tabstop> | ||
487 | <tabstop>passLine</tabstop> | ||
488 | <tabstop>smtpTab</tabstop> | ||
489 | <tabstop>nameLine</tabstop> | ||
490 | <tabstop>mailLine</tabstop> | ||
491 | <tabstop>orgLine</tabstop> | ||
492 | <tabstop>ccBox</tabstop> | ||
493 | <tabstop>ccLine</tabstop> | ||
494 | <tabstop>bccBox</tabstop> | ||
495 | <tabstop>bccLine</tabstop> | ||
496 | <tabstop>replyBox</tabstop> | ||
497 | <tabstop>replyLine</tabstop> | ||
498 | <tabstop>sigMultiLine</tabstop> | ||
499 | </tabstops> | ||
500 | </UI> | ||