-rw-r--r-- | kmicromail/libmailwrapper/genericwrapper.cpp | 18 | ||||
-rw-r--r-- | kmicromail/opiemail.cpp | 2 |
2 files changed, 2 insertions, 18 deletions
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp index 09a6447..e691082 100644 --- a/kmicromail/libmailwrapper/genericwrapper.cpp +++ b/kmicromail/libmailwrapper/genericwrapper.cpp @@ -1,548 +1,530 @@ // CHANGED 2004-09-31 Lutz Rogowski #include "genericwrapper.h" #include <libetpan/libetpan.h> #include "mailtypes.h" #include <kconfig.h> #include <kglobal.h> #include <kstandarddirs.h> using namespace Opie::Core; Genericwrapper::Genericwrapper() : AbstractMail() { bodyCache.clear(); m_storage = 0; m_folder = 0; } Genericwrapper::~Genericwrapper() { if (m_folder) { mailfolder_free(m_folder); } if (m_storage) { mailstorage_free(m_storage); } cleanMimeCache(); } const QDateTime Genericwrapper::parseDateTime( mailimf_date_time *date ) { - static bool init = false ; - if ( ! init ) { - KConfig kon ( locateLocal( "config", "korganizerrc" ) ); - kon.setGroup("Locale"); - KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)kon.readNumEntry( "PreferredDate",0) ); - QString dummy = kon.readEntry( "UserDateFormatShort","%aK %d.%m.%y" );// kon.readEntry( ""); - KGlobal::locale()->setHore24Format( !kon.readNumEntry( "PreferredTime",0 ) ); - KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); - dummy = kon.readEntry( "UserDateFormatLong","%A %d %b %y" ); - KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); - kon.setGroup("Time & Date"); - KGlobal::locale()->setDaylightSaving( kon.readBoolEntry( "UseDaylightsaving", true ), - kon.readNumEntry( "DaylightsavingStart", 90), - kon.readNumEntry( "DaylightsavingEnd",304) ); - KGlobal::locale()->setTimezone( kon.readEntry( "TimeZoneName" ," 00:00 Europe/London(UTC)") ); - - init = true; - } QDate da (date->dt_year,date->dt_month, date->dt_day ); QTime ti ( date->dt_hour, date->dt_min, date->dt_sec ); QDateTime dt ( da ,ti ); int addsec = -date->dt_zone*36; //qDebug("adsec1 %d ",addsec ); dt = dt.addSecs( addsec ); int off = KGlobal::locale()->localTimeOffset( dt ); //qDebug("adsec2 %d ",off*60 ); dt = dt.addSecs( off*60 ); return dt; #if 0 QString ret; if ( dt.date() == QDate::currentDate () ) ret = KGlobal::locale()->formatTime( dt.time(),true); else { ret = KGlobal::locale()->formatDateTime( dt,true,true); } #endif #if 0 if ( off < 0 ) ret += " -"; else ret += " +"; ret += QString::number( off / 60 ); ret += "h"; #endif #if 0 char tmp[23]; // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i", date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); return QString( tmp ); #endif //return ret; } void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) { if (!mime) { return; } mailmime_field*field = 0; mailmime_single_fields fields; memset(&fields, 0, sizeof(struct mailmime_single_fields)); if (mime->mm_mime_fields != NULL) { mailmime_single_fields_init(&fields, mime->mm_mime_fields, mime->mm_content_type); } mailmime_content*type = fields.fld_content; clistcell*current; if (!type) { target->setType("text"); target->setSubtype("plain"); } else { target->setSubtype(type->ct_subtype); switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { case MAILMIME_DISCRETE_TYPE_TEXT: target->setType("text"); break; case MAILMIME_DISCRETE_TYPE_IMAGE: target->setType("image"); break; case MAILMIME_DISCRETE_TYPE_AUDIO: target->setType("audio"); break; case MAILMIME_DISCRETE_TYPE_VIDEO: target->setType("video"); break; case MAILMIME_DISCRETE_TYPE_APPLICATION: target->setType("application"); break; case MAILMIME_DISCRETE_TYPE_EXTENSION: default: if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); } break; } if (type->ct_parameters) { fillParameters(target,type->ct_parameters); } } if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { field = (mailmime_field*)current->data; switch(field->fld_type) { case MAILMIME_FIELD_TRANSFER_ENCODING: target->setEncoding(getencoding(field->fld_data.fld_encoding)); break; case MAILMIME_FIELD_ID: target->setIdentifier(field->fld_data.fld_id); break; case MAILMIME_FIELD_DESCRIPTION: target->setDescription(field->fld_data.fld_description); break; default: break; } } } } void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) { if (!parameters) {return;} clistcell*current=0; mailmime_parameter*param; for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { param = (mailmime_parameter*)current->data; if (param) { target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); } } } QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) { QString enc="7bit"; if (!aEnc) return enc; switch(aEnc->enc_type) { case MAILMIME_MECHANISM_7BIT: enc = "7bit"; break; case MAILMIME_MECHANISM_8BIT: enc = "8bit"; break; case MAILMIME_MECHANISM_BINARY: enc = "binary"; break; case MAILMIME_MECHANISM_QUOTED_PRINTABLE: enc = "quoted-printable"; break; case MAILMIME_MECHANISM_BASE64: enc = "base64"; break; case MAILMIME_MECHANISM_TOKEN: default: if (aEnc->enc_token) { enc = QString(aEnc->enc_token); } break; } return enc; } void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) { if (current_rec >= 10) { ; // odebug << "too deep recursion!" << oendl; } if (!message || !mime) { return; } int r; char*data = 0; size_t len; clistiter * cur = 0; QString b; RecPartP part = new RecPart(); switch (mime->mm_type) { case MAILMIME_SINGLE: { QValueList<int>countlist = recList; countlist.append(current_count); r = mailmessage_fetch_section(message,mime,&data,&len); part->setSize(len); part->setPositionlist(countlist); b = gen_attachment_id(); part->setIdentifier(b); fillSingleBody(part,message,mime); if (part->Type()=="text" && target->Bodytext().isNull()) { encodedString*rs = new encodedString(); rs->setContent(data,len); encodedString*res = decode_String(rs,part->Encoding()); if (countlist.count()>2) { bodyCache[b]=rs; target->addPart(part); } else { delete rs; } b = QString(res->Content()); delete res; target->setBodytext(b); target->setDescription(part); } else { bodyCache[b]=new encodedString(data,len); target->addPart(part); } } break; case MAILMIME_MULTIPLE: { unsigned int ccount = 1; mailmime*cbody=0; QValueList<int>countlist = recList; for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { cbody = (mailmime*)clist_content(cur); if (cbody->mm_type==MAILMIME_MULTIPLE) { RecPartP targetPart = new RecPart(); targetPart->setType("multipart"); countlist.append(current_count); targetPart->setPositionlist(countlist); target->addPart(targetPart); } traverseBody(target,message, cbody,countlist,current_rec+1,ccount); if (cbody->mm_type==MAILMIME_MULTIPLE) { countlist = recList; } ++ccount; } } break; case MAILMIME_MESSAGE: { QValueList<int>countlist = recList; countlist.append(current_count); /* the own header is always at recursion 0 - we don't need that */ if (current_rec > 0) { part->setPositionlist(countlist); r = mailmessage_fetch_section(message,mime,&data,&len); part->setSize(len); part->setPositionlist(countlist); b = gen_attachment_id(); part->setIdentifier(b); part->setType("message"); part->setSubtype("rfc822"); bodyCache[b]=new encodedString(data,len); target->addPart(part); } if (mime->mm_data.mm_message.mm_msg_mime != NULL) { traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); } } break; } } RecBodyP Genericwrapper::parseMail( mailmessage * msg ) { int err = MAILIMF_NO_ERROR; mailmime_single_fields fields; /* is bound to msg and will be freed there */ mailmime * mime=0; RecBodyP body = new RecBody(); memset(&fields, 0, sizeof(struct mailmime_single_fields)); err = mailmessage_get_bodystructure(msg,&mime); QValueList<int>recList; traverseBody(body,msg,mime,recList); return body; } QString Genericwrapper::parseAddressList( mailimf_address_list *list ) { QString result( "" ); bool first = true; if (list == 0) return result; for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { mailimf_address *addr = (mailimf_address *) current->data; if ( !first ) { result.append( "," ); } else { first = false; } switch ( addr->ad_type ) { case MAILIMF_ADDRESS_MAILBOX: result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); break; case MAILIMF_ADDRESS_GROUP: result.append( parseGroup( addr->ad_data.ad_group ) ); break; default: ; // odebug << "Generic: unkown mailimf address type" << oendl; break; } } return result; } QString Genericwrapper::parseGroup( mailimf_group *group ) { QString result( "" ); result.append( group->grp_display_name ); result.append( ": " ); if ( group->grp_mb_list != NULL ) { result.append( parseMailboxList( group->grp_mb_list ) ); } result.append( ";" ); return result; } QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) { QString result( "" ); if ( box->mb_display_name == NULL ) { result.append( box->mb_addr_spec ); } else { result.append( convert_String(box->mb_display_name).latin1() ); result.append( " <" ); result.append( box->mb_addr_spec ); result.append( ">" ); } return result; } QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) { QString result( "" ); bool first = true; for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { mailimf_mailbox *box = (mailimf_mailbox *) current->data; if ( !first ) { result.append( "," ); } else { first = false; } result.append( parseMailbox( box ) ); } return result; } encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) { QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); if (it==bodyCache.end()) return new encodedString(); encodedString*t = decode_String(it.data(),part->Encoding()); return t; } encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) { QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); if (it==bodyCache.end()) return new encodedString(); encodedString*t = it.data(); return t; } QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) { encodedString*t = fetchDecodedPart(mail,part); QString text=t->Content(); delete t; return text; } void Genericwrapper::cleanMimeCache() { QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); for (;it!=bodyCache.end();++it) { encodedString*t = it.data(); //it.setValue(0); if (t) delete t; } bodyCache.clear(); ; // odebug << "Genericwrapper: cache cleaned" << oendl; } QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) { QStringList res; if (!in_replies || !in_replies->mid_list) return res; clistiter * current = 0; for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { QString h((char*)current->data); while (h.length()>0 && h[0]=='<') { h.remove(0,1); } while (h.length()>0 && h[h.length()-1]=='>') { h.remove(h.length()-1,1); } if (h.length()>0) { res.append(h); } } return res; } void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) { int r; mailmessage_list * env_list = 0; r = mailsession_get_messages_list(session,&env_list); if (r != MAIL_NO_ERROR) { ; // odebug << "Error message list" << oendl; return; } r = mailsession_get_envelopes_list(session, env_list); if (r != MAIL_NO_ERROR) { ; // odebug << "Error filling message list" << oendl; if (env_list) { mailmessage_list_free(env_list); } return; } mailimf_references * refs = 0; mailimf_in_reply_to * in_replies = 0; uint32_t i = 0; for(; i < carray_count(env_list->msg_tab) ; ++i) { mailmessage * msg; QBitArray mFlags(7); msg = (mailmessage*)carray_get(env_list->msg_tab, i); if (msg->msg_fields == NULL) { //; // odebug << "could not fetch envelope of message " << i << "" << oendl; continue; } RecMailP mail = new RecMail(); mail->setWrapper(this); mail_flags * flag_result = 0; r = mailmessage_get_flags(msg,&flag_result); if (r == MAIL_ERROR_NOT_IMPLEMENTED) { mFlags.setBit(FLAG_SEEN); } mailimf_single_fields single_fields; mailimf_single_fields_init(&single_fields, msg->msg_fields); mail->setMsgsize(msg->msg_size); mail->setFlags(mFlags); mail->setMbox(mailbox); mail->setNumber(msg->msg_index); if (single_fields.fld_subject) mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); if (single_fields.fld_from) mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); if (!mbox_as_to) { if (single_fields.fld_to) mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); } else { mail->setTo(mailbox); } if (single_fields.fld_cc) mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); if (single_fields.fld_bcc) mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); if (single_fields.fld_orig_date) { QDateTime dt = Genericwrapper::parseDateTime( single_fields.fld_orig_date->dt_date_time ); QString ret; if ( dt.date() == QDate::currentDate () ) ret = KGlobal::locale()->formatTime( dt.time(),true); else { ret = KGlobal::locale()->formatDateTime( dt,true,true); } mail->setDate( ret ); char tmp[20]; snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); //qDebug(" iso %s ", tmp); mail->setIsoDate( QString( tmp ) ); } // crashes when accessing pop3 account? if (single_fields.fld_message_id) { mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; } if (single_fields.fld_reply_to) { QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); if (t.count()>0) { mail->setReplyto(t[0]); } } #if 0 refs = single_fields.fld_references; if (refs && refs->mid_list && clist_count(refs->mid_list)) { char * text = (char*)refs->mid_list->first->data; mail->setReplyto(QString(text)); } #endif if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && clist_count(single_fields.fld_in_reply_to->mid_list)) { mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); } if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 ) target.append(mail); } if (env_list) { mailmessage_list_free(env_list); } } diff --git a/kmicromail/opiemail.cpp b/kmicromail/opiemail.cpp index 9a1a750..164988c 100644 --- a/kmicromail/opiemail.cpp +++ b/kmicromail/opiemail.cpp @@ -1,466 +1,468 @@ // CHANGED 2004-09-31 Lutz Rogowski // CHANGED 2004-08-06 Lutz Rogowski #include "settingsdialog.h" #include "opiemail.h" #include "editaccounts.h" #include "composemail.h" #include "mailistviewitem.h" #include "viewmail.h" #include "selectstore.h" #include "selectsmtp.h" #include "accountitem.h" #include "koprefsdialog.h" #include <qmessagebox.h> #include <qtimer.h> #include <libkdepim/externalapphandler.h> +#include <libkdepim/kpimglobalprefs.h> #include <qpe/qpeapplication.h> #include <libmailwrapper/smtpwrapper.h> #include <libmailwrapper/mailtypes.h> #include <libmailwrapper/abstractmail.h> /* OPIE */ //#include <qpe/resource.h> //#include <qpe/qpeapplication.h> /* QT */ //using namespace Opie::Core; OpieMail::OpieMail( QWidget *parent, const char *name ) : MainWindow( parent, name) //, WStyle_ContextHelp ) { settings = new Settings(); + KPimGlobalPrefs::instance()->setGlobalConfig(); folderView->populate( settings->getAccounts() ); } OpieMail::~OpieMail() { if (settings) delete settings; } void OpieMail::appMessage(const QCString &msg, const QByteArray &data) { } #include <stdlib.h> void OpieMail::message(const QCString &msg, const QByteArray &data) { // copied from old mail2 static int ii = 0; //qDebug("QCOP CALL ############################# %d ", ii); //QString mess ( msg ); //qDebug("Message = %s ",mess.latin1()); ++ii; //qDebug("KM:appMessage %d *%s* %x", ii, msg.data(), this); mPendingEmail = QString::null; mPendingName = QString::null; if (msg == "writeMail(QString,QString)") { //qDebug("writeMail(QString,QString) "); QDataStream stream(data,IO_ReadOnly); stream >> mPendingName >> mPendingEmail; // removing the whitespaces at beginning and end is needed! QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); } else if (msg == "newMail()") { //qDebug("slotComposeMail() "); // we cannot call slotComposeMail(); directly, because may be executing a QCOP call // and a QCOP call does not like a processevents in his execution // with the Qtimer we call slotComposeMail() after we reached the main event loop QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); // slotComposeMail(); } else if (msg == "newMail(QString)") { //qDebug(" newMail(QString)"); QDataStream stream(data,IO_ReadOnly); stream >> mPendingName; // the format is // NAME <EMAIL>:SUBJECT QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); } else { mPendingData = data; mPendingMessage = msg; QTimer::singleShot ( 50, this, SLOT(slotExtAppHandler() ) ); } //qDebug("END OpieMail::message "); } void OpieMail::slotExtAppHandler() { ExternalAppHandler::instance()->appMessage ( mPendingMessage, mPendingData ); } void OpieMail::slotwriteMail2(const QString& namemail ) { //qDebug("OpieMail::slotwriteMail2 "); //qApp->processEvents(); ComposeMail compose( settings, this, 0, true ); if ( !namemail.isEmpty() ) { QString to = namemail; if ( namemail.find( " <") > 1 ) { to = "\"" +to.replace( QRegExp( " <"), "\" <") ; } else if ( namemail.find( "<") > 1 ) { to = "\"" +to.replace( QRegExp( "<"), "\" <") ; } int sub = to.find( ">:"); if ( sub > 0 ) { compose.setTo( to.left(sub+1) ); compose.setSubject( to.mid(sub+2) ); } else compose.setTo( to ); } compose.slotAdjustColumns(); compose.showMaximized(); compose.exec(); raise(); //qDebug("retttich "); } void OpieMail::slotwriteMail(const QString&name,const QString&email) { // qDebug("OpieMail::slotwriteMail "); ComposeMail compose( settings, this, 0, true ); if (!email.isEmpty()) { if (!name.isEmpty()) { compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); } else { compose.setTo(email); } } compose.slotAdjustColumns(); compose.showMaximized(); compose.exec(); raise(); } void OpieMail::slotComposeMail() { if ( mPendingEmail == QString::null && mPendingName == QString::null) slotwriteMail2( QString () ); else { if ( mPendingEmail == QString::null ) slotwriteMail2( mPendingName ); else slotwriteMail( mPendingName, mPendingEmail ); } //slotwriteMail(0l,0l); } void OpieMail::slotSendQueued() { SMTPaccount *smtp = 0; QList<Account> list = settings->getAccounts(); QList<SMTPaccount> smtpList; smtpList.setAutoDelete(false); Account *it; for ( it = list.first(); it; it = list.next() ) { if ( it->getType() == MAILLIB::A_SMTP ) { smtp = static_cast<SMTPaccount *>(it); smtpList.append(smtp); } } if (smtpList.count()==0) { QMessageBox::information(0,tr("Info"),tr("Define a smtp account first!\n")); return; } if (smtpList.count()==1) { smtp = smtpList.at(0); } else { smtp = 0; selectsmtp selsmtp; selsmtp.setSelectionlist(&smtpList); selsmtp.showMaximized(); if ( selsmtp.exec() == QDialog::Accepted ) { smtp = selsmtp.selected_smtp(); } } if (smtp) { SMTPwrapper * wrap = new SMTPwrapper(smtp); if ( wrap->flushOutbox() ) { QMessageBox::information(0,tr("Info"),tr("Mail queue flushed")); } delete wrap; } } void OpieMail::slotSearchMails() { qDebug("OpieMail::slotSearchMails():not implemented "); } void OpieMail::slotEditSettings() { #if 0 SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp ); settingsDialog.showMaximized(); settingsDialog.exec(); #endif KOPrefsDialog settingsDialog( this, "koprefs", true ); settingsDialog.showMaximized(); settingsDialog.exec(); } void OpieMail::slotEditAccounts() { EditAccounts eaDialog( settings, this, 0, true ); eaDialog.slotAdjustColumns(); eaDialog.showMaximized(); eaDialog.exec(); if ( settings ) delete settings; settings = new Settings(); folderView->populate( settings->getAccounts() ); } void OpieMail::displayMail() { QListViewItem*item = mailView->currentItem(); if (!item) return; RecMailP mail = ((MailListViewItem*)item)->data(); RecBodyP body = folderView->fetchBody(mail); ViewMail readMail( this,"", Qt::WType_Modal ); readMail.setBody( body ); readMail.setMail( mail ); readMail.showMaximized(); readMail.exec(); if ( readMail.deleted ) { folderView->refreshCurrent(); } else { ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() ); } } void OpieMail::slotGetAllMail() { QListViewItem * item = folderView->firstChild(); while ( item ){ ((AccountViewItem *)item)->contextMenuSelected( 101 ); item = item->nextSibling (); } } void OpieMail::slotGetMail() { QListViewItem * item = folderView->currentItem(); if ( ! item ) return; ((AccountViewItem *)item)->contextMenuSelected( 101 ); } void OpieMail::slotDeleteMail() { if (!mailView->currentItem()) return; RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { mail->Wrapper()->deleteMail( mail ); folderView->refreshCurrent(); } } void OpieMail::slotDeleteAllMail() { QValueList<RecMailP> t; if ( QMessageBox::warning(this, tr("Delete All Mails"), tr("Do you really want to delete\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); while ( item ) { if ( item->isSelected() ) { t.append( item->data() ); } item = (MailListViewItem*)item->nextSibling(); } } else return; if ( t.count() == 0 ) return; RecMailP mail = t.first(); mail->Wrapper()->deleteMailList(t); folderView->refreshCurrent(); } void OpieMail::clearSelection() { mailView->clearSelection(); } void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int ) { if (!mailView->currentItem()) return; MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType(); /* just the RIGHT button - or hold on pda */ if (button!=2) {return;} if (!item) return; QPopupMenu *m = new QPopupMenu(0); if (m) { if (mailtype==MAILLIB::A_NNTP) { m->insertItem(tr("Read this posting"),this,SLOT(displayMail())); m->insertItem(tr("Copy this posting"),this,SLOT(slotMoveCopyMail())); m->insertSeparator(); m->insertItem(tr("Copy all selected postings"),this,SLOT(slotMoveCopyAllMail())); m->insertItem(tr("Clear selection"),this,SLOT(clearSelection())); } else { if (folderView->currentisDraft()) { m->insertItem(tr("Edit this mail"),this,SLOT(reEditMail())); } m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); m->insertItem(tr("Move/Copy this mail"),this,SLOT(slotMoveCopyMail())); m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); m->insertSeparator(); m->insertItem(tr("Move/Copy all selected mail"),this,SLOT(slotMoveCopyAllMail())); m->insertItem(tr("Delete all selected mails"),this,SLOT(slotDeleteAllMail())); m->insertItem(tr("Clear selection"),this,SLOT(clearSelection())); } m->setFocus(); m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); delete m; } } void OpieMail::slotShowFolders( bool show ) { if ( show && folderView->isHidden() ) { folderView->show(); } else if ( !show && !folderView->isHidden() ) { folderView->hide(); } } void OpieMail::refreshMailView(const QValueList<RecMailP>&list) { MailListViewItem*item = 0; mailView->clear(); QValueList<RecMailP>::ConstIterator it; for (it = list.begin(); it != list.end();++it) { item = new MailListViewItem(mailView,item); item->storeData((*it)); item->showEntry(); } } void OpieMail::mailLeftClicked( QListViewItem *item ) { mailView->clearSelection(); /* just LEFT button - or tap with stylus on pda */ //if (button!=1) return; if (!item) return; if (folderView->currentisDraft()) { reEditMail(); } else { displayMail(); } } void OpieMail::slotMoveCopyMail() { if (!mailView->currentItem()) return; RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); AbstractMail*targetMail = 0; QString targetFolder = ""; Selectstore sels; folderView->setupFolderselect(&sels); if (!sels.exec()) return; targetMail = sels.currentMail(); targetFolder = sels.currentFolder(); if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || targetFolder.isEmpty()) { return; } if (sels.newFolder() && !targetMail->createMbox(targetFolder)) { QMessageBox::critical(0,tr("Error creating new Folder"), tr("<center>Error while creating<br>new folder - breaking.</center>")); return; } sels.hide(); qApp->processEvents(); // qDebug("hiding sels "); mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails()); folderView->refreshCurrent(); } void OpieMail::slotMoveCopyAllMail() { if (!mailView->currentItem()) return; QValueList<RecMailP> t; // if ( QMessageBox::warning(this, tr("Move/Copy all selected mails"), tr("Do you really want to copy/move\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); while ( item ) { if ( item->isSelected() ) { t.append( item->data() ); } item = (MailListViewItem*)item->nextSibling(); } } // else // return; if ( t.count() == 0 ) return; RecMailP mail = t.first(); AbstractMail*targetMail = 0; QString targetFolder = ""; Selectstore sels; folderView->setupFolderselect(&sels); if (!sels.exec()) return; targetMail = sels.currentMail(); targetFolder = sels.currentFolder(); if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || targetFolder.isEmpty()) { return; } if (sels.newFolder() && !targetMail->createMbox(targetFolder)) { QMessageBox::critical(0,tr("Error creating new Folder"), tr("<center>Error while creating<br>new folder - breaking.</center>")); return; } sels.hide(); qApp->processEvents(); //qDebug("hiding sels "); mail->Wrapper()->mvcpMailList(t,targetFolder,targetMail,sels.moveMails()); folderView->refreshCurrent(); } void OpieMail::reEditMail() { if (!mailView->currentItem()) return; ComposeMail compose( settings, this, 0, true ); compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data()); compose.slotAdjustColumns(); compose.showMaximized(); compose.exec(); } |