summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/composemail.cpp7
-rw-r--r--noncore/net/mail/editaccounts.cpp1
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.cpp2
-rw-r--r--noncore/net/mail/mailwrapper.cpp2
-rw-r--r--noncore/net/mail/main.cpp1
-rw-r--r--noncore/net/mail/mainwindow.cpp1
6 files changed, 0 insertions, 14 deletions
diff --git a/noncore/net/mail/composemail.cpp b/noncore/net/mail/composemail.cpp
index a17ccb3..88dd780 100644
--- a/noncore/net/mail/composemail.cpp
+++ b/noncore/net/mail/composemail.cpp
@@ -1,180 +1,173 @@
#include <qt.h>
-#include <qcombobox.h>
-#include <qmessagebox.h>
-#include <qlistview.h>
-#include <qtabwidget.h>
-#include <qmultilineedit.h>
-#include <qregexp.h>
#include <opie/ofiledialog.h>
#include <qpe/resource.h>
#include "composemail.h"
-#include "mailwrapper.h"
ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags )
: ComposeMailUI( parent, name, modal, flags )
{
settings = s;
attList->addColumn( tr( "Name" ) );
attList->addColumn( tr( "Size" ) );
QList<Account> accounts = settings->getAccounts();
Account *it;
for ( it = accounts.first(); it; it = accounts.next() ) {
if ( it->getType().compare( "SMTP" ) == 0 ) {
SMTPaccount *smtp = static_cast<SMTPaccount *>(it);
fromBox->insertItem( smtp->getMail() );
smtpAccounts.append( smtp );
}
}
if ( smtpAccounts.count() > 0 ) {
fillValues( fromBox->currentItem() );
} else {
QMessageBox::information( this, tr( "Problem" ),
tr( "<p>Please create an SMTP account first.</p>" ),
tr( "Ok" ) );
}
connect( fromBox, SIGNAL( activated( int ) ), SLOT( fillValues( int ) ) );
connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) );
connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) );
connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) );
connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) );
connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) );
connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) );
}
void ComposeMail::pickAddress( QLineEdit *line )
{
QString names = AddressPicker::getNames();
if ( line->text().isEmpty() ) {
line->setText( names );
} else if ( !names.isEmpty() ) {
line->setText( line->text() + ", " + names );
}
}
void ComposeMail::pickAddressTo()
{
pickAddress( toLine );
}
void ComposeMail::pickAddressCC()
{
pickAddress( ccLine );
}
void ComposeMail::pickAddressBCC()
{
pickAddress( bccLine );
}
void ComposeMail::pickAddressReply()
{
pickAddress( replyLine );
}
void ComposeMail::fillValues( int current )
{
SMTPaccount *smtp = smtpAccounts.at( current );
ccLine->clear();
if ( smtp->getUseCC() ) {
ccLine->setText( smtp->getCC() );
}
bccLine->clear();
if ( smtp->getUseBCC() ) {
bccLine->setText( smtp->getBCC() );
}
replyLine->clear();
if ( smtp->getUseReply() ) {
replyLine->setText( smtp->getReply() );
}
sigMultiLine->setText( smtp->getSignature() );
}
void ComposeMail::slotAdjustColumns()
{
int currPage = tabWidget->currentPageIndex();
tabWidget->showPage( attachTab );
attList->setColumnWidth( 0, attList->visibleWidth() - 80 );
attList->setColumnWidth( 1, 80 );
tabWidget->setCurrentPage( currPage );
}
void ComposeMail::addAttachment()
{
DocLnk lnk = OFileDialog::getOpenFileName( 1, "/" );
if ( !lnk.name().isEmpty() ) {
Attachment *att = new Attachment( lnk );
(void) new AttachViewItem( attList, att );
}
}
void ComposeMail::removeAttachment()
{
if ( !attList->currentItem() ) {
QMessageBox::information( this, tr( "Error" ),
tr( "<p>Please select a File.</p>" ),
tr( "Ok" ) );
} else {
attList->takeItem( attList->currentItem() );
}
}
void ComposeMail::accept()
{
qDebug( "Sending Mail with " +
smtpAccounts.at( fromBox->currentItem() )->getAccountName() );
Mail *mail = new Mail();
SMTPaccount *smtp = smtpAccounts.at( fromBox->currentItem() );
mail->setMail( smtp->getMail() );
mail->setName( smtp->getName() );
if ( !toLine->text().isEmpty() ) {
mail->setTo( toLine->text() );
} else {
qDebug( "No Reciever spezified -> returning" );
return;
}
mail->setCC( ccLine->text() );
mail->setBCC( bccLine->text() );
mail->setReply( replyLine->text() );
mail->setSubject( subjectLine->text() );
QString txt = message->text();
if ( !sigMultiLine->text().isEmpty() ) {
txt.append( "\n--\n" );
txt.append( sigMultiLine->text() );
}
mail->setMessage( txt );
AttachViewItem *it = (AttachViewItem *) attList->firstChild();
while ( it != NULL ) {
mail->addAttachment( it->getAttachment() );
it = (AttachViewItem *) it->itemBelow();
}
MailWrapper wrapper( settings );
wrapper.sendMail( *mail );
QDialog::accept();
}
AttachViewItem::AttachViewItem( QListView *parent, Attachment *att )
: QListViewItem( parent )
{
attachment = att;
qDebug( att->getMimeType() );
setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ?
Resource::loadPixmap( "UnknownDocument-14" ) :
attachment->getDocLnk().pixmap() );
setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() );
setText( 1, QString::number( att->getSize() ) );
}
diff --git a/noncore/net/mail/editaccounts.cpp b/noncore/net/mail/editaccounts.cpp
index 7e2dd24..1c80adb 100644
--- a/noncore/net/mail/editaccounts.cpp
+++ b/noncore/net/mail/editaccounts.cpp
@@ -1,471 +1,470 @@
#include <qt.h>
-#include <qtabwidget.h>
#include "defines.h"
#include "editaccounts.h"
AccountListItem::AccountListItem( QListView *parent, Account *a)
: QListViewItem( parent )
{
account = a;
setText( 0, account->getAccountName() );
setText( 1, account->getType() );
}
EditAccounts::EditAccounts( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags )
: EditAccountsUI( parent, name, modal, flags )
{
qDebug( "New Account Configuration Widget" );
settings = s;
mailList->addColumn( tr( "Account" ) );
mailList->addColumn( tr( "Type" ) );
newsList->addColumn( tr( "Account" ) );
connect( newMail, SIGNAL( clicked() ), SLOT( slotNewMail() ) );
connect( editMail, SIGNAL( clicked() ), SLOT( slotEditMail() ) );
connect( deleteMail, SIGNAL( clicked() ), SLOT( slotDeleteMail() ) );
connect( newNews, SIGNAL( clicked() ), SLOT( slotNewNews() ) );
connect( editNews, SIGNAL( clicked() ), SLOT( slotEditNews() ) );
connect( deleteNews, SIGNAL( clicked() ), SLOT( slotDeleteNews() ) );
slotFillLists();
}
void EditAccounts::slotFillLists()
{
mailList->clear();
newsList->clear();
QList<Account> accounts = settings->getAccounts();
Account *it;
for ( it = accounts.first(); it; it = accounts.next() ) {
if ( it->getType().compare( "NNTP" ) == 0 ) {
(void) new AccountListItem( newsList, it );
} else {
(void) new AccountListItem( mailList, it );
}
}
}
void EditAccounts::slotNewMail()
{
qDebug( "New Mail Account" );
QString *selection = new QString();
SelectMailType selType( selection, this, 0, true );
selType.show();
if ( QDialog::Accepted == selType.exec() ) {
slotNewAccount( *selection );
}
}
void EditAccounts::slotNewAccount( const QString &type )
{
if ( type.compare( "IMAP" ) == 0 ) {
qDebug( "-> config IMAP" );
IMAPaccount *account = new IMAPaccount();
IMAPconfig imap( account, this, 0, true );
imap.showMaximized();
if ( QDialog::Accepted == imap.exec() ) {
settings->addAccount( account );
account->save();
slotFillLists();
} else {
account->remove();
}
} else if ( type.compare( "POP3" ) == 0 ) {
qDebug( "-> config POP3" );
POP3account *account = new POP3account();
POP3config pop3( account, this, 0, true );
pop3.showMaximized();
if ( QDialog::Accepted == pop3.exec() ) {
settings->addAccount( account );
account->save();
slotFillLists();
} else {
account->remove();
}
} else if ( type.compare( "SMTP" ) == 0 ) {
qDebug( "-> config SMTP" );
SMTPaccount *account = new SMTPaccount();
SMTPconfig smtp( account, this, 0, true );
smtp.showMaximized();
if ( QDialog::Accepted == smtp.exec() ) {
settings->addAccount( account );
account->save();
slotFillLists();
} else {
account->remove();
}
} else if ( type.compare( "NNTP" ) == 0 ) {
qDebug( "-> config NNTP" );
NNTPaccount *account = new NNTPaccount();
NNTPconfig nntp( account, this, 0, true );
nntp.showMaximized();
if ( QDialog::Accepted == nntp.exec() ) {
settings->addAccount( account );
account->save();
slotFillLists();
} else {
account->remove();
}
}
}
void EditAccounts::slotEditAccount( Account *account )
{
if ( account->getType().compare( "IMAP" ) == 0 ) {
IMAPaccount *imapAcc = static_cast<IMAPaccount *>(account);
IMAPconfig imap( imapAcc, this, 0, true );
imap.showMaximized();
if ( QDialog::Accepted == imap.exec() ) {
slotFillLists();
}
} else if ( account->getType().compare( "POP3" ) == 0 ) {
POP3account *pop3Acc = static_cast<POP3account *>(account);
POP3config pop3( pop3Acc, this, 0, true );
pop3.showMaximized();
if ( QDialog::Accepted == pop3.exec() ) {
slotFillLists();
}
} else if ( account->getType().compare( "SMTP" ) == 0 ) {
SMTPaccount *smtpAcc = static_cast<SMTPaccount *>(account);
SMTPconfig smtp( smtpAcc, this, 0, true );
smtp.showMaximized();
if ( QDialog::Accepted == smtp.exec() ) {
slotFillLists();
}
} else if ( account->getType().compare( "NNTP" ) == 0 ) {
NNTPaccount *nntpAcc = static_cast<NNTPaccount *>(account);
NNTPconfig nntp( nntpAcc, this, 0, true );
nntp.showMaximized();
if ( QDialog::Accepted == nntp.exec() ) {
slotFillLists();
}
}
}
void EditAccounts::slotDeleteAccount( Account *account )
{
if ( QMessageBox::information( this, tr( "Question" ),
tr( "<p>Do you really want to delete the selected Account?</p>" ),
tr( "Yes" ), tr( "No" ) ) == 0 ) {
settings->delAccount( account );
slotFillLists();
}
}
void EditAccounts::slotEditMail()
{
qDebug( "Edit Mail Account" );
if ( !mailList->currentItem() ) {
QMessageBox::information( this, tr( "Error" ),
tr( "<p>Please select an account.</p>" ),
tr( "Ok" ) );
return;
}
Account *a = ((AccountListItem *) mailList->currentItem())->getAccount();
slotEditAccount( a );
}
void EditAccounts::slotDeleteMail()
{
if ( !mailList->currentItem() ) {
QMessageBox::information( this, tr( "Error" ),
tr( "<p>Please select an account.</p>" ),
tr( "Ok" ) );
return;
}
Account *a = ((AccountListItem *) mailList->currentItem())->getAccount();
slotDeleteAccount( a );
}
void EditAccounts::slotNewNews()
{
qDebug( "New News Account" );
slotNewAccount( "NNTP" );
}
void EditAccounts::slotEditNews()
{
qDebug( "Edit News Account" );
if ( !newsList->currentItem() ) {
QMessageBox::information( this, tr( "Error" ),
tr( "<p>Please select an account.</p>" ),
tr( "Ok" ) );
return;
}
Account *a = ((AccountListItem *) newsList->currentItem())->getAccount();
slotEditAccount( a );
}
void EditAccounts::slotDeleteNews()
{
qDebug( "Delete News Account" );
if ( !newsList->currentItem() ) {
QMessageBox::information( this, tr( "Error" ),
tr( "<p>Please select an account.</p>" ),
tr( "Ok" ) );
return;
}
Account *a = ((AccountListItem *) newsList->currentItem())->getAccount();
slotDeleteAccount( a );
}
void EditAccounts::slotAdjustColumns()
{
int currPage = configTab->currentPageIndex();
configTab->showPage( mailTab );
mailList->setColumnWidth( 0, mailList->visibleWidth() - 50 );
mailList->setColumnWidth( 1, 50 );
configTab->showPage( newsTab );
newsList->setColumnWidth( 0, newsList->visibleWidth() );
configTab->setCurrentPage( currPage );
}
void EditAccounts::accept()
{
settings->saveAccounts();
QDialog::accept();
}
/**
* SelectMailType
*/
SelectMailType::SelectMailType( QString *selection, QWidget *parent, const char *name, bool modal, WFlags flags )
: SelectMailTypeUI( parent, name, modal, flags )
{
selected = selection;
selected->replace( 0, selected->length(), typeBox->currentText() );
connect( typeBox, SIGNAL( activated( const QString & ) ), SLOT( slotSelection( const QString & ) ) );
}
void SelectMailType::slotSelection( const QString &sel )
{
selected->replace( 0, selected->length(), sel );
}
/**
* IMAPconfig
*/
IMAPconfig::IMAPconfig( IMAPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags )
: IMAPconfigUI( parent, name, modal, flags )
{
data = account;
fillValues();
connect( sslBox, SIGNAL( toggled( bool ) ), SLOT( slotSSL( bool ) ) );
}
void IMAPconfig::slotSSL( bool enabled )
{
if ( enabled ) {
portLine->setText( IMAP_SSL_PORT );
} else {
portLine->setText( IMAP_PORT );
}
}
void IMAPconfig::fillValues()
{
accountLine->setText( data->getAccountName() );
serverLine->setText( data->getServer() );
portLine->setText( data->getPort() );
sslBox->setChecked( data->getSSL() );
userLine->setText( data->getUser() );
passLine->setText( data->getPassword() );
prefixLine->setText(data->getPrefix());
}
void IMAPconfig::accept()
{
data->setAccountName( accountLine->text() );
data->setServer( serverLine->text() );
data->setPort( portLine->text() );
data->setSSL( sslBox->isChecked() );
data->setUser( userLine->text() );
data->setPassword( passLine->text() );
data->setPrefix(prefixLine->text());
QDialog::accept();
}
/**
* POP3config
*/
POP3config::POP3config( POP3account *account, QWidget *parent, const char *name, bool modal, WFlags flags )
: POP3configUI( parent, name, modal, flags )
{
data = account;
fillValues();
connect( sslBox, SIGNAL( toggled( bool ) ), SLOT( slotSSL( bool ) ) );
}
void POP3config::slotSSL( bool enabled )
{
if ( enabled ) {
portLine->setText( POP3_SSL_PORT );
} else {
portLine->setText( POP3_PORT );
}
}
void POP3config::fillValues()
{
accountLine->setText( data->getAccountName() );
serverLine->setText( data->getServer() );
portLine->setText( data->getPort() );
sslBox->setChecked( data->getSSL() );
userLine->setText( data->getUser() );
passLine->setText( data->getPassword() );
}
void POP3config::accept()
{
data->setAccountName( accountLine->text() );
data->setServer( serverLine->text() );
data->setPort( portLine->text() );
data->setSSL( sslBox->isChecked() );
data->setUser( userLine->text() );
data->setPassword( passLine->text() );
QDialog::accept();
}
/**
* SMTPconfig
*/
SMTPconfig::SMTPconfig( SMTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags )
: SMTPconfigUI( parent, name, modal, flags )
{
data = account;
connect( ccBox, SIGNAL( toggled( bool ) ), ccLine, SLOT( setEnabled( bool ) ) );
connect( bccBox, SIGNAL( toggled( bool ) ), bccLine, SLOT( setEnabled( bool ) ) );
connect( replyBox, SIGNAL( toggled( bool ) ), replyLine, SLOT( setEnabled( bool ) ) );
connect( loginBox, SIGNAL( toggled( bool ) ), userLine, SLOT( setEnabled( bool ) ) );
connect( loginBox, SIGNAL( toggled( bool ) ), passLine, SLOT( setEnabled( bool ) ) );
fillValues();
connect( sslBox, SIGNAL( toggled( bool ) ), SLOT( slotSSL( bool ) ) );
}
void SMTPconfig::slotSSL( bool enabled )
{
if ( enabled ) {
portLine->setText( SMTP_SSL_PORT );
} else {
portLine->setText( SMTP_PORT );
}
}
void SMTPconfig::fillValues()
{
accountLine->setText( data->getAccountName() );
serverLine->setText( data->getServer() );
portLine->setText( data->getPort() );
sslBox->setChecked( data->getSSL() );
loginBox->setChecked( data->getLogin() );
userLine->setText( data->getUser() );
passLine->setText( data->getPassword() );
nameLine->setText( data->getName() );
mailLine->setText( data->getMail() );
orgLine->setText( data->getOrg() );
ccBox->setChecked( data->getUseCC() );
ccLine->setText( data->getCC() );
bccBox->setChecked( data->getUseBCC() );
bccLine->setText( data->getBCC() );
replyBox->setChecked( data->getUseReply() );
replyLine->setText( data->getReply() );
sigMultiLine->setText( data->getSignature() );
}
void SMTPconfig::accept()
{
data->setAccountName( accountLine->text() );
data->setServer( serverLine->text() );
data->setPort( portLine->text() );
data->setSSL( sslBox->isChecked() );
data->setLogin( loginBox->isChecked() );
data->setUser( userLine->text() );
data->setPassword( passLine->text() );
data->setName( nameLine->text() );
data->setMail( mailLine->text() );
data->setOrg( orgLine->text() );
data->setCC( ccLine->text() );
data->setUseCC( ccBox->isChecked() );
data->setBCC( bccLine->text() );
data->setUseBCC( bccBox->isChecked() );
data->setReply( replyLine->text() );
data->setUseReply( replyBox->isChecked() );
data->setSignature( sigMultiLine->text() );
QDialog::accept();
}
/**
* NNTPconfig
*/
NNTPconfig::NNTPconfig( NNTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags )
: NNTPconfigUI( parent, name, modal, flags )
{
data = account;
connect( loginBox, SIGNAL( toggled( bool ) ), userLine, SLOT( setEnabled( bool ) ) );
connect( loginBox, SIGNAL( toggled( bool ) ), passLine, SLOT( setEnabled( bool ) ) );
fillValues();
connect( sslBox, SIGNAL( toggled( bool ) ), SLOT( slotSSL( bool ) ) );
}
void NNTPconfig::slotSSL( bool enabled )
{
if ( enabled ) {
portLine->setText( NNTP_SSL_PORT );
} else {
portLine->setText( NNTP_PORT );
}
}
void NNTPconfig::fillValues()
{
accountLine->setText( data->getAccountName() );
serverLine->setText( data->getServer() );
portLine->setText( data->getPort() );
sslBox->setChecked( data->getSSL() );
loginBox->setChecked( data->getLogin() );
userLine->setText( data->getUser() );
passLine->setText( data->getPassword() );
}
void NNTPconfig::accept()
{
data->setAccountName( accountLine->text() );
data->setServer( serverLine->text() );
data->setPort( portLine->text() );
data->setSSL( sslBox->isChecked() );
data->setLogin( loginBox->isChecked() );
data->setUser( userLine->text() );
data->setPassword( passLine->text() );
QDialog::accept();
}
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
index 13a3fd9..ea9e7b2 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
@@ -1,521 +1,519 @@
-#include <qfileinfo.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <qdir.h>
-#include <qtextstream.h>
#include "mailwrapper.h"
#include "logindialog.h"
//#include "mail.h"
#include "defines.h"
Attachment::Attachment( DocLnk lnk )
{
doc = lnk;
size = QFileInfo( doc.file() ).size();
}
Folder::Folder(const QString&tmp_name )
{
name = tmp_name;
nameDisplay = name;
for ( int pos = nameDisplay.find( '&' ); pos != -1;
pos = nameDisplay.find( '&' ) ) {
int end = nameDisplay.find( '-' );
if ( end == -1 || end <= pos ) break;
QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 );
// TODO: do real base64 decoding here !
if ( str64.compare( "APw" ) == 0 ) {
nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" );
} else if ( str64.compare( "APY" ) == 0 ) {
nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" );
}
}
qDebug( "folder " + name + " - displayed as " + nameDisplay );
}
MailWrapper::MailWrapper( Settings *s )
: QObject()
{
settings = s;
}
QString MailWrapper::mailsmtpError( int errnum )
{
switch ( errnum ) {
case MAILSMTP_NO_ERROR:
return tr( "No error" );
case MAILSMTP_ERROR_UNEXPECTED_CODE:
return tr( "Unexpected error code" );
case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
return tr( "Service not available" );
case MAILSMTP_ERROR_STREAM:
return tr( "Stream error" );
case MAILSMTP_ERROR_HOSTNAME:
return tr( "gethostname() failed" );
case MAILSMTP_ERROR_NOT_IMPLEMENTED:
return tr( "Not implemented" );
case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
return tr( "Error, action not taken" );
case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
return tr( "Data exceeds storage allocation" );
case MAILSMTP_ERROR_IN_PROCESSING:
return tr( "Error in processing" );
// case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
// return tr( "Insufficient system storage" );
case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
return tr( "Mailbox unavailable" );
case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
return tr( "Mailbox name not allowed" );
case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
return tr( "Bad command sequence" );
case MAILSMTP_ERROR_USER_NOT_LOCAL:
return tr( "User not local" );
case MAILSMTP_ERROR_TRANSACTION_FAILED:
return tr( "Transaction failed" );
case MAILSMTP_ERROR_MEMORY:
return tr( "Memory error" );
case MAILSMTP_ERROR_CONNECTION_REFUSED:
return tr( "Connection refused" );
default:
return tr( "Unknown error code" );
}
}
mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail )
{
return mailimf_mailbox_new( strdup( name.latin1() ),
strdup( mail.latin1() ) );
}
mailimf_address_list *MailWrapper::parseAddresses(const QString&addr )
{
mailimf_address_list *addresses;
if ( addr.isEmpty() ) return NULL;
addresses = mailimf_address_list_new_empty();
QStringList list = QStringList::split( ',', addr );
QStringList::Iterator it;
for ( it = list.begin(); it != list.end(); it++ ) {
char *str = strdup( (*it).latin1() );
int err = mailimf_address_list_add_parse( addresses, str );
if ( err != MAILIMF_NO_ERROR ) {
qDebug( "Error parsing" );
qDebug( *it );
free( str );
} else {
qDebug( "Parse success! :)" );
}
}
return addresses;
}
mailimf_fields *MailWrapper::createImfFields( Mail *mail )
{
mailimf_fields *fields;
mailimf_field *xmailer;
mailimf_mailbox *sender, *fromBox;
mailimf_mailbox_list *from;
mailimf_address_list *to, *cc, *bcc, *reply;
char *subject = strdup( mail->getSubject().latin1() );
int err;
sender = newMailbox( mail->getName(), mail->getMail() );
if ( sender == NULL ) goto err_free;
fromBox = newMailbox( mail->getName(), mail->getMail() );
if ( fromBox == NULL ) goto err_free_sender;
from = mailimf_mailbox_list_new_empty();
if ( from == NULL ) goto err_free_fromBox;
err = mailimf_mailbox_list_add( from, fromBox );
if ( err != MAILIMF_NO_ERROR ) goto err_free_from;
to = parseAddresses( mail->getTo() );
if ( to == NULL ) goto err_free_from;
cc = parseAddresses( mail->getCC() );
bcc = parseAddresses( mail->getBCC() );
reply = parseAddresses( mail->getReply() );
fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
NULL, NULL, subject );
if ( fields == NULL ) goto err_free_reply;
xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
strdup( USER_AGENT ) );
if ( xmailer == NULL ) goto err_free_fields;
err = mailimf_fields_add( fields, xmailer );
if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer;
return fields; // Success :)
err_free_xmailer:
mailimf_field_free( xmailer );
err_free_fields:
mailimf_fields_free( fields );
err_free_reply:
mailimf_address_list_free( reply );
mailimf_address_list_free( bcc );
mailimf_address_list_free( cc );
mailimf_address_list_free( to );
err_free_from:
mailimf_mailbox_list_free( from );
err_free_fromBox:
mailimf_mailbox_free( fromBox );
err_free_sender:
mailimf_mailbox_free( sender );
err_free:
free( subject );
qDebug( "createImfFields - error" );
return NULL; // Error :(
}
mailmime *MailWrapper::buildTxtPart( QString str )
{
mailmime *txtPart;
mailmime_fields *fields;
mailmime_content *content;
mailmime_parameter *param;
char *txt = strdup( str.latin1() );
int err;
param = mailmime_parameter_new( strdup( "charset" ),
strdup( "iso-8859-1" ) );
if ( param == NULL ) goto err_free;
content = mailmime_content_new_with_str( "text/plain" );
if ( content == NULL ) goto err_free_param;
err = clist_append( content->parameters, param );
if ( err != MAILIMF_NO_ERROR ) goto err_free_content;
fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT );
if ( fields == NULL ) goto err_free_content;
txtPart = mailmime_new_empty( content, fields );
if ( txtPart == NULL ) goto err_free_fields;
err = mailmime_set_body_text( txtPart, txt, strlen( txt ) );
if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
return txtPart; // Success :)
err_free_txtPart:
mailmime_free( txtPart );
err_free_fields:
mailmime_fields_free( fields );
err_free_content:
mailmime_content_free( content );
err_free_param:
mailmime_parameter_free( param );
err_free:
free( txt );
qDebug( "buildTxtPart - error" );
return NULL; // Error :(
}
mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype )
{
mailmime * filePart;
mailmime_fields * fields;
mailmime_content * content;
mailmime_parameter * param = NULL;
int err;
int pos = filename.findRev( '/' );
QString tmp = filename.right( filename.length() - ( pos + 1 ) );
char *name = strdup( tmp.latin1() ); // just filename
char *file = strdup( filename.latin1() ); // full name with path
char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain
fields = mailmime_fields_new_filename(
MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name,
MAILMIME_MECHANISM_BASE64 );
if ( fields == NULL ) goto err_free;
content = mailmime_content_new_with_str( mime );
if ( content == NULL ) goto err_free_fields;
if ( mimetype.compare( "text/plain" ) == 0 ) {
param = mailmime_parameter_new( strdup( "charset" ),
strdup( "iso-8859-1" ) );
if ( param == NULL ) goto err_free_content;
err = clist_append( content->parameters, param );
if ( err != MAILIMF_NO_ERROR ) goto err_free_param;
}
filePart = mailmime_new_empty( content, fields );
if ( filePart == NULL ) goto err_free_param;
err = mailmime_set_body_file( filePart, file );
if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
return filePart; // Success :)
err_free_filePart:
mailmime_free( filePart );
err_free_param:
if ( param != NULL ) mailmime_parameter_free( param );
err_free_content:
mailmime_content_free( content );
err_free_fields:
mailmime_fields_free( fields );
err_free:
free( name );
free( mime );
free( file );
qDebug( "buildFilePart - error" );
return NULL; // Error :(
}
void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files )
{
Attachment *it;
for ( it = files.first(); it; it = files.next() ) {
qDebug( "Adding file" );
mailmime *filePart;
int err;
filePart = buildFilePart( it->getFileName(), it->getMimeType() );
if ( filePart == NULL ) goto err_free;
err = mailmime_smart_add_part( message, filePart );
if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
continue; // Success :)
err_free_filePart:
mailmime_free( filePart );
err_free:
qDebug( "addFileParts: error adding file:" );
qDebug( it->getFileName() );
}
}
mailmime *MailWrapper::createMimeMail( Mail *mail )
{
mailmime *message, *txtPart;
mailimf_fields *fields;
int err;
fields = createImfFields( mail );
if ( fields == NULL ) goto err_free;
message = mailmime_new_message_data( NULL );
if ( message == NULL ) goto err_free_fields;
mailmime_set_imf_fields( message, fields );
txtPart = buildTxtPart( mail->getMessage() );
if ( txtPart == NULL ) goto err_free_message;
err = mailmime_smart_add_part( message, txtPart );
if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
addFileParts( message, mail->getAttachments() );
return message; // Success :)
err_free_txtPart:
mailmime_free( txtPart );
err_free_message:
mailmime_free( message );
err_free_fields:
mailimf_fields_free( fields );
err_free:
qDebug( "createMimeMail: error" );
return NULL; // Error :(
}
mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type )
{
mailimf_field *field;
clistiter *it;
it = clist_begin( fields->list );
while ( it ) {
field = (mailimf_field *) it->data;
if ( field->type == type ) {
return field;
}
it = it->next;
}
return NULL;
}
static void addRcpts( clist *list, mailimf_address_list *addr_list )
{
clistiter *it, *it2;
for ( it = clist_begin( addr_list->list ); it; it = it->next ) {
mailimf_address *addr;
addr = (mailimf_address *) it->data;
if ( addr->type == MAILIMF_ADDRESS_MAILBOX ) {
esmtp_address_list_add( list, addr->mailbox->addr_spec, 0, NULL );
} else if ( addr->type == MAILIMF_ADDRESS_GROUP ) {
clist *l = addr->group->mb_list->list;
for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
mailimf_mailbox *mbox;
mbox = (mailimf_mailbox *) it2->data;
esmtp_address_list_add( list, mbox->addr_spec, 0, NULL );
}
}
}
}
clist *MailWrapper::createRcptList( mailimf_fields *fields )
{
clist *rcptList;
mailimf_field *field;
rcptList = esmtp_address_list_new();
field = getField( fields, MAILIMF_FIELD_TO );
if ( field && (field->type == MAILIMF_FIELD_TO)
&& field->field.to->addr_list ) {
addRcpts( rcptList, field->field.to->addr_list );
}
field = getField( fields, MAILIMF_FIELD_CC );
if ( field && (field->type == MAILIMF_FIELD_CC)
&& field->field.cc->addr_list ) {
addRcpts( rcptList, field->field.cc->addr_list );
}
field = getField( fields, MAILIMF_FIELD_BCC );
if ( field && (field->type == MAILIMF_FIELD_BCC)
&& field->field.bcc->addr_list ) {
addRcpts( rcptList, field->field.bcc->addr_list );
}
return rcptList;
}
char *MailWrapper::getFrom( mailmime *mail )
{
char *from = NULL;
mailimf_field *ffrom;
ffrom = getField( mail->fields, MAILIMF_FIELD_FROM );
if ( ffrom && (ffrom->type == MAILIMF_FIELD_FROM)
&& ffrom->field.from->mb_list && ffrom->field.from->mb_list->list ) {
clist *cl = ffrom->field.from->mb_list->list;
clistiter *it;
for ( it = clist_begin( cl ); it; it = it->next ) {
mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
from = strdup( mb->addr_spec );
}
}
return from;
}
SMTPaccount *MailWrapper::getAccount( QString from )
{
SMTPaccount *smtp;
QList<Account> list = settings->getAccounts();
Account *it;
for ( it = list.first(); it; it = list.next() ) {
if ( it->getType().compare( "SMTP" ) == 0 ) {
smtp = static_cast<SMTPaccount *>(it);
if ( smtp->getMail().compare( from ) == 0 ) {
qDebug( "SMTPaccount found for" );
qDebug( from );
return smtp;
}
}
}
return NULL;
}
QString MailWrapper::getTmpFile() {
int num = 0;
QString unique;
QDir dir( "/tmp" );
QStringList::Iterator it;
QStringList list = dir.entryList( "opiemail-tmp-*" );
do {
unique.setNum( num++ );
} while ( list.contains( "opiemail-tmp-" + unique ) > 0 );
return "/tmp/opiemail-tmp-" + unique;
}
void MailWrapper::writeToFile( QString file, mailmime *mail )
{
FILE *f;
int err, col = 0;
f = fopen( file.latin1(), "w" );
if ( f == NULL ) {
qDebug( "writeToFile: error opening file" );
return;
}
err = mailmime_write( f, &col, mail );
if ( err != MAILIMF_NO_ERROR ) {
fclose( f );
qDebug( "writeToFile: error writing mailmime" );
return;
}
fclose( f );
}
void MailWrapper::readFromFile( QString file, char **data, size_t *size )
{
char *buf;
struct stat st;
int fd, count = 0, total = 0;
fd = open( file.latin1(), O_RDONLY, 0 );
if ( fd == -1 ) return;
if ( fstat( fd, &st ) != 0 ) goto err_close;
if ( !st.st_size ) goto err_close;
buf = (char *) malloc( st.st_size );
if ( !buf ) goto err_close;
while ( ( total < st.st_size ) && ( count >= 0 ) ) {
count = read( fd, buf + total, st.st_size - total );
total += count;
}
if ( count < 0 ) goto err_free;
*data = buf;
*size = st.st_size;
close( fd );
return; // Success :)
err_free:
free( buf );
err_close:
close( fd );
}
diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp
index 13a3fd9..ea9e7b2 100644
--- a/noncore/net/mail/mailwrapper.cpp
+++ b/noncore/net/mail/mailwrapper.cpp
@@ -1,521 +1,519 @@
-#include <qfileinfo.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <qdir.h>
-#include <qtextstream.h>
#include "mailwrapper.h"
#include "logindialog.h"
//#include "mail.h"
#include "defines.h"
Attachment::Attachment( DocLnk lnk )
{
doc = lnk;
size = QFileInfo( doc.file() ).size();
}
Folder::Folder(const QString&tmp_name )
{
name = tmp_name;
nameDisplay = name;
for ( int pos = nameDisplay.find( '&' ); pos != -1;
pos = nameDisplay.find( '&' ) ) {
int end = nameDisplay.find( '-' );
if ( end == -1 || end <= pos ) break;
QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 );
// TODO: do real base64 decoding here !
if ( str64.compare( "APw" ) == 0 ) {
nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" );
} else if ( str64.compare( "APY" ) == 0 ) {
nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" );
}
}
qDebug( "folder " + name + " - displayed as " + nameDisplay );
}
MailWrapper::MailWrapper( Settings *s )
: QObject()
{
settings = s;
}
QString MailWrapper::mailsmtpError( int errnum )
{
switch ( errnum ) {
case MAILSMTP_NO_ERROR:
return tr( "No error" );
case MAILSMTP_ERROR_UNEXPECTED_CODE:
return tr( "Unexpected error code" );
case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
return tr( "Service not available" );
case MAILSMTP_ERROR_STREAM:
return tr( "Stream error" );
case MAILSMTP_ERROR_HOSTNAME:
return tr( "gethostname() failed" );
case MAILSMTP_ERROR_NOT_IMPLEMENTED:
return tr( "Not implemented" );
case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
return tr( "Error, action not taken" );
case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
return tr( "Data exceeds storage allocation" );
case MAILSMTP_ERROR_IN_PROCESSING:
return tr( "Error in processing" );
// case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
// return tr( "Insufficient system storage" );
case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
return tr( "Mailbox unavailable" );
case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
return tr( "Mailbox name not allowed" );
case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
return tr( "Bad command sequence" );
case MAILSMTP_ERROR_USER_NOT_LOCAL:
return tr( "User not local" );
case MAILSMTP_ERROR_TRANSACTION_FAILED:
return tr( "Transaction failed" );
case MAILSMTP_ERROR_MEMORY:
return tr( "Memory error" );
case MAILSMTP_ERROR_CONNECTION_REFUSED:
return tr( "Connection refused" );
default:
return tr( "Unknown error code" );
}
}
mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail )
{
return mailimf_mailbox_new( strdup( name.latin1() ),
strdup( mail.latin1() ) );
}
mailimf_address_list *MailWrapper::parseAddresses(const QString&addr )
{
mailimf_address_list *addresses;
if ( addr.isEmpty() ) return NULL;
addresses = mailimf_address_list_new_empty();
QStringList list = QStringList::split( ',', addr );
QStringList::Iterator it;
for ( it = list.begin(); it != list.end(); it++ ) {
char *str = strdup( (*it).latin1() );
int err = mailimf_address_list_add_parse( addresses, str );
if ( err != MAILIMF_NO_ERROR ) {
qDebug( "Error parsing" );
qDebug( *it );
free( str );
} else {
qDebug( "Parse success! :)" );
}
}
return addresses;
}
mailimf_fields *MailWrapper::createImfFields( Mail *mail )
{
mailimf_fields *fields;
mailimf_field *xmailer;
mailimf_mailbox *sender, *fromBox;
mailimf_mailbox_list *from;
mailimf_address_list *to, *cc, *bcc, *reply;
char *subject = strdup( mail->getSubject().latin1() );
int err;
sender = newMailbox( mail->getName(), mail->getMail() );
if ( sender == NULL ) goto err_free;
fromBox = newMailbox( mail->getName(), mail->getMail() );
if ( fromBox == NULL ) goto err_free_sender;
from = mailimf_mailbox_list_new_empty();
if ( from == NULL ) goto err_free_fromBox;
err = mailimf_mailbox_list_add( from, fromBox );
if ( err != MAILIMF_NO_ERROR ) goto err_free_from;
to = parseAddresses( mail->getTo() );
if ( to == NULL ) goto err_free_from;
cc = parseAddresses( mail->getCC() );
bcc = parseAddresses( mail->getBCC() );
reply = parseAddresses( mail->getReply() );
fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
NULL, NULL, subject );
if ( fields == NULL ) goto err_free_reply;
xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
strdup( USER_AGENT ) );
if ( xmailer == NULL ) goto err_free_fields;
err = mailimf_fields_add( fields, xmailer );
if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer;
return fields; // Success :)
err_free_xmailer:
mailimf_field_free( xmailer );
err_free_fields:
mailimf_fields_free( fields );
err_free_reply:
mailimf_address_list_free( reply );
mailimf_address_list_free( bcc );
mailimf_address_list_free( cc );
mailimf_address_list_free( to );
err_free_from:
mailimf_mailbox_list_free( from );
err_free_fromBox:
mailimf_mailbox_free( fromBox );
err_free_sender:
mailimf_mailbox_free( sender );
err_free:
free( subject );
qDebug( "createImfFields - error" );
return NULL; // Error :(
}
mailmime *MailWrapper::buildTxtPart( QString str )
{
mailmime *txtPart;
mailmime_fields *fields;
mailmime_content *content;
mailmime_parameter *param;
char *txt = strdup( str.latin1() );
int err;
param = mailmime_parameter_new( strdup( "charset" ),
strdup( "iso-8859-1" ) );
if ( param == NULL ) goto err_free;
content = mailmime_content_new_with_str( "text/plain" );
if ( content == NULL ) goto err_free_param;
err = clist_append( content->parameters, param );
if ( err != MAILIMF_NO_ERROR ) goto err_free_content;
fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT );
if ( fields == NULL ) goto err_free_content;
txtPart = mailmime_new_empty( content, fields );
if ( txtPart == NULL ) goto err_free_fields;
err = mailmime_set_body_text( txtPart, txt, strlen( txt ) );
if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
return txtPart; // Success :)
err_free_txtPart:
mailmime_free( txtPart );
err_free_fields:
mailmime_fields_free( fields );
err_free_content:
mailmime_content_free( content );
err_free_param:
mailmime_parameter_free( param );
err_free:
free( txt );
qDebug( "buildTxtPart - error" );
return NULL; // Error :(
}
mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype )
{
mailmime * filePart;
mailmime_fields * fields;
mailmime_content * content;
mailmime_parameter * param = NULL;
int err;
int pos = filename.findRev( '/' );
QString tmp = filename.right( filename.length() - ( pos + 1 ) );
char *name = strdup( tmp.latin1() ); // just filename
char *file = strdup( filename.latin1() ); // full name with path
char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain
fields = mailmime_fields_new_filename(
MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name,
MAILMIME_MECHANISM_BASE64 );
if ( fields == NULL ) goto err_free;
content = mailmime_content_new_with_str( mime );
if ( content == NULL ) goto err_free_fields;
if ( mimetype.compare( "text/plain" ) == 0 ) {
param = mailmime_parameter_new( strdup( "charset" ),
strdup( "iso-8859-1" ) );
if ( param == NULL ) goto err_free_content;
err = clist_append( content->parameters, param );
if ( err != MAILIMF_NO_ERROR ) goto err_free_param;
}
filePart = mailmime_new_empty( content, fields );
if ( filePart == NULL ) goto err_free_param;
err = mailmime_set_body_file( filePart, file );
if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
return filePart; // Success :)
err_free_filePart:
mailmime_free( filePart );
err_free_param:
if ( param != NULL ) mailmime_parameter_free( param );
err_free_content:
mailmime_content_free( content );
err_free_fields:
mailmime_fields_free( fields );
err_free:
free( name );
free( mime );
free( file );
qDebug( "buildFilePart - error" );
return NULL; // Error :(
}
void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files )
{
Attachment *it;
for ( it = files.first(); it; it = files.next() ) {
qDebug( "Adding file" );
mailmime *filePart;
int err;
filePart = buildFilePart( it->getFileName(), it->getMimeType() );
if ( filePart == NULL ) goto err_free;
err = mailmime_smart_add_part( message, filePart );
if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
continue; // Success :)
err_free_filePart:
mailmime_free( filePart );
err_free:
qDebug( "addFileParts: error adding file:" );
qDebug( it->getFileName() );
}
}
mailmime *MailWrapper::createMimeMail( Mail *mail )
{
mailmime *message, *txtPart;
mailimf_fields *fields;
int err;
fields = createImfFields( mail );
if ( fields == NULL ) goto err_free;
message = mailmime_new_message_data( NULL );
if ( message == NULL ) goto err_free_fields;
mailmime_set_imf_fields( message, fields );
txtPart = buildTxtPart( mail->getMessage() );
if ( txtPart == NULL ) goto err_free_message;
err = mailmime_smart_add_part( message, txtPart );
if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
addFileParts( message, mail->getAttachments() );
return message; // Success :)
err_free_txtPart:
mailmime_free( txtPart );
err_free_message:
mailmime_free( message );
err_free_fields:
mailimf_fields_free( fields );
err_free:
qDebug( "createMimeMail: error" );
return NULL; // Error :(
}
mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type )
{
mailimf_field *field;
clistiter *it;
it = clist_begin( fields->list );
while ( it ) {
field = (mailimf_field *) it->data;
if ( field->type == type ) {
return field;
}
it = it->next;
}
return NULL;
}
static void addRcpts( clist *list, mailimf_address_list *addr_list )
{
clistiter *it, *it2;
for ( it = clist_begin( addr_list->list ); it; it = it->next ) {
mailimf_address *addr;
addr = (mailimf_address *) it->data;
if ( addr->type == MAILIMF_ADDRESS_MAILBOX ) {
esmtp_address_list_add( list, addr->mailbox->addr_spec, 0, NULL );
} else if ( addr->type == MAILIMF_ADDRESS_GROUP ) {
clist *l = addr->group->mb_list->list;
for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
mailimf_mailbox *mbox;
mbox = (mailimf_mailbox *) it2->data;
esmtp_address_list_add( list, mbox->addr_spec, 0, NULL );
}
}
}
}
clist *MailWrapper::createRcptList( mailimf_fields *fields )
{
clist *rcptList;
mailimf_field *field;
rcptList = esmtp_address_list_new();
field = getField( fields, MAILIMF_FIELD_TO );
if ( field && (field->type == MAILIMF_FIELD_TO)
&& field->field.to->addr_list ) {
addRcpts( rcptList, field->field.to->addr_list );
}
field = getField( fields, MAILIMF_FIELD_CC );
if ( field && (field->type == MAILIMF_FIELD_CC)
&& field->field.cc->addr_list ) {
addRcpts( rcptList, field->field.cc->addr_list );
}
field = getField( fields, MAILIMF_FIELD_BCC );
if ( field && (field->type == MAILIMF_FIELD_BCC)
&& field->field.bcc->addr_list ) {
addRcpts( rcptList, field->field.bcc->addr_list );
}
return rcptList;
}
char *MailWrapper::getFrom( mailmime *mail )
{
char *from = NULL;
mailimf_field *ffrom;
ffrom = getField( mail->fields, MAILIMF_FIELD_FROM );
if ( ffrom && (ffrom->type == MAILIMF_FIELD_FROM)
&& ffrom->field.from->mb_list && ffrom->field.from->mb_list->list ) {
clist *cl = ffrom->field.from->mb_list->list;
clistiter *it;
for ( it = clist_begin( cl ); it; it = it->next ) {
mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
from = strdup( mb->addr_spec );
}
}
return from;
}
SMTPaccount *MailWrapper::getAccount( QString from )
{
SMTPaccount *smtp;
QList<Account> list = settings->getAccounts();
Account *it;
for ( it = list.first(); it; it = list.next() ) {
if ( it->getType().compare( "SMTP" ) == 0 ) {
smtp = static_cast<SMTPaccount *>(it);
if ( smtp->getMail().compare( from ) == 0 ) {
qDebug( "SMTPaccount found for" );
qDebug( from );
return smtp;
}
}
}
return NULL;
}
QString MailWrapper::getTmpFile() {
int num = 0;
QString unique;
QDir dir( "/tmp" );
QStringList::Iterator it;
QStringList list = dir.entryList( "opiemail-tmp-*" );
do {
unique.setNum( num++ );
} while ( list.contains( "opiemail-tmp-" + unique ) > 0 );
return "/tmp/opiemail-tmp-" + unique;
}
void MailWrapper::writeToFile( QString file, mailmime *mail )
{
FILE *f;
int err, col = 0;
f = fopen( file.latin1(), "w" );
if ( f == NULL ) {
qDebug( "writeToFile: error opening file" );
return;
}
err = mailmime_write( f, &col, mail );
if ( err != MAILIMF_NO_ERROR ) {
fclose( f );
qDebug( "writeToFile: error writing mailmime" );
return;
}
fclose( f );
}
void MailWrapper::readFromFile( QString file, char **data, size_t *size )
{
char *buf;
struct stat st;
int fd, count = 0, total = 0;
fd = open( file.latin1(), O_RDONLY, 0 );
if ( fd == -1 ) return;
if ( fstat( fd, &st ) != 0 ) goto err_close;
if ( !st.st_size ) goto err_close;
buf = (char *) malloc( st.st_size );
if ( !buf ) goto err_close;
while ( ( total < st.st_size ) && ( count >= 0 ) ) {
count = read( fd, buf + total, st.st_size - total );
total += count;
}
if ( count < 0 ) goto err_free;
*data = buf;
*size = st.st_size;
close( fd );
return; // Success :)
err_free:
free( buf );
err_close:
close( fd );
}
diff --git a/noncore/net/mail/main.cpp b/noncore/net/mail/main.cpp
index f97bea1..3bfcb4a 100644
--- a/noncore/net/mail/main.cpp
+++ b/noncore/net/mail/main.cpp
@@ -1,6 +1,5 @@
-#include <qpe/qpeapplication.h>
#include <opie/oapplicationfactory.h>
#include "opiemail.h"
OPIE_EXPORT_APP( OApplicationFactory<OpieMail> )
diff --git a/noncore/net/mail/mainwindow.cpp b/noncore/net/mail/mainwindow.cpp
index 28111d0..6f054cc 100644
--- a/noncore/net/mail/mainwindow.cpp
+++ b/noncore/net/mail/mainwindow.cpp
@@ -1,150 +1,149 @@
#include <qlabel.h>
#include <qvbox.h>
#include <qheader.h>
#include <qtimer.h>
-#include <qpe/resource.h>
#include "defines.h"
#include "mainwindow.h"
MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags )
: QMainWindow( parent, name, flags )
{
setCaption( tr( "Opie-Mail" ) );
setToolBarsMovable( false );
toolBar = new QToolBar( this );
menuBar = new QMenuBar( toolBar );
mailMenu = new QPopupMenu( menuBar );
menuBar->insertItem( tr( "Mail" ), mailMenu );
settingsMenu = new QPopupMenu( menuBar );
menuBar->insertItem( tr( "Settings" ), settingsMenu );
addToolBar( toolBar );
toolBar->setHorizontalStretchable( true );
QLabel *spacer = new QLabel( toolBar );
spacer->setBackgroundMode( QWidget::PaletteButton );
toolBar->setStretchableWidget( spacer );
composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL,
0, 0, this );
composeMail->addTo( toolBar );
composeMail->addTo( mailMenu );
sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED,
0, 0, this );
sendQueued->addTo( toolBar );
sendQueued->addTo( mailMenu );
syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC,
0, 0, this );
syncFolders->addTo( toolBar );
syncFolders->addTo( mailMenu );
showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS,
0, 0, this, 0, true );
showFolders->addTo( toolBar );
showFolders->addTo( mailMenu );
connect(showFolders, SIGNAL( toggled( bool ) ),
SLOT( slotShowFolders( bool ) ) );
searchMails = new QAction( tr( "Search mails" ), ICON_SEARCHMAILS,
0, 0, this );
searchMails->addTo( toolBar );
searchMails->addTo( mailMenu );
editSettings = new QAction( tr( "Edit settings" ), ICON_EDITSETTINGS,
0, 0, this );
editSettings->addTo( settingsMenu );
editAccounts = new QAction( tr( "Configure accounts" ), ICON_EDITACCOUNTS,
0, 0, this );
editAccounts->addTo( settingsMenu );
QVBox *view = new QVBox( this );
setCentralWidget( view );
folderView = new AccountView( view );
folderView->header()->hide();
folderView->setMinimumHeight( 90 );
folderView->setMaximumHeight( 90 );
folderView->addColumn( tr( "Mailbox" ) );
folderView->hide();
mailView = new QListView( view );
mailView->setMinimumHeight( 50 );
mailView->addColumn( tr( "Subject" ),QListView::Manual );
mailView->addColumn( tr( "Sender" ),QListView::Manual );
mailView->addColumn( tr( "Date" ));
mailView->setAllColumnsShowFocus(true);
mailView->setSorting(-1);
connect( mailView, SIGNAL( clicked( QListViewItem * ) ),this,
SLOT( displayMail( QListViewItem * ) ) );
connect(folderView,SIGNAL(refreshMailview(Maillist*)),this,SLOT(refreshMailView(Maillist*)));
QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) );
}
void MainWindow::slotAdjustColumns()
{
bool hidden = folderView->isHidden();
if ( hidden ) folderView->show();
folderView->setColumnWidth( 0, folderView->visibleWidth() );
if ( hidden ) folderView->hide();
mailView->setColumnWidth( 0, mailView->visibleWidth() - 130 );
mailView->setColumnWidth( 1, 80 );
mailView->setColumnWidth( 2, 50 );
}
void MainWindow::slotShowFolders( bool show )
{
qDebug( "Show Folders" );
if ( show && folderView->isHidden() ) {
qDebug( "-> showing" );
folderView->show();
} else if ( !show && !folderView->isHidden() ) {
qDebug( "-> hiding" );
folderView->hide();
}
}
void MainWindow::refreshMailView(Maillist*list)
{
MailListViewItem*item = 0;
mailView->clear();
#if 0
QFont f = mailView->getFont();
QFont bf = f;
#endif
for (unsigned int i = 0; i < list->count();++i) {
item = new MailListViewItem(mailView,item);
item->storeData(*(list->at(i)));
item->showEntry();
#if 0
if (!list->at(i)->getFlags().testBit(FLAG_SEEN)) {
item->setFont(bf);
}
#endif
}
}
void MainWindow::displayMail(QListViewItem*item)
{
if (!item) return;
qDebug("View mail");
RecMail mail = ((MailListViewItem*)item)->data();
QString body = folderView->fetchBody(mail);
qDebug(body);
}
void MailListViewItem::showEntry()
{
setText(0,mail_data.getSubject());
setText(1,mail_data.getFrom());
setText(2,mail_data.getDate());
}