From 32f9963a39236d08718a36d5adad2a0c5c4e2602 Mon Sep 17 00:00:00 2001 From: zautrix Date: Sat, 11 Sep 2004 15:41:30 +0000 Subject: Mail enhancements --- diff --git a/kmicromail/accountitem.cpp b/kmicromail/accountitem.cpp index 1698b40..7b9b881 100644 --- a/kmicromail/accountitem.cpp +++ b/kmicromail/accountitem.cpp @@ -92,11 +92,12 @@ QPopupMenu * POP3viewItem::getContextMenu() { m->insertItem(QObject::tr("Disconnect",contextName),0); m->insertItem(QObject::tr("Set offline",contextName),1); - m->insertItem(QObject::tr("Download messages",contextName),2); + m->insertItem(QObject::tr("Download new INBOX messages",contextName),2); } else { m->insertItem(QObject::tr("Set online",contextName),1); + m->insertItem(QObject::tr("Download new INBOX messages",contextName),2); } } return m; @@ -137,6 +138,8 @@ void POP3viewItem::contextMenuSelected(int which) setOnOffline(); break; case 2: // daunlood + if (account->getOffline()) + setOnOffline(); AccountView*bl = accountView(); if (!bl) return; AccountViewItem* in = findSubItem( "inbox" , 0); @@ -513,10 +516,14 @@ QPopupMenu * IMAPviewItem::getContextMenu() m->insertSeparator(); m->insertItem(QObject::tr("Disconnect",contextName),2); m->insertItem(QObject::tr("Set offline",contextName),3); + m->insertSeparator(); + m->insertItem(QObject::tr("Download new INBOX messages",contextName),4); } else { m->insertItem(QObject::tr("Set online",contextName),3); + m->insertSeparator(); + m->insertItem(QObject::tr("Download new INBOX messages",contextName),4); } } return m; @@ -570,6 +577,19 @@ void IMAPviewItem::contextMenuSelected(int id) SETPIX(PIXMAP_IMAPFOLDER); refreshFolders(false); break; + case 4: // daunlood + { + if (account->getOffline()) { + contextMenuSelected( 3 ); + } + AccountView*bl = accountView(); + if (!bl) return; + AccountViewItem* in = findSubItem( "inbox" , 0); + if ( ! in ) + return; + bl->downloadMailsInbox(in->getFolder(),getWrapper()); + } + break; default: break; } diff --git a/kmicromail/accountview.cpp b/kmicromail/accountview.cpp index 85523b1..de8c5bb 100644 --- a/kmicromail/accountview.cpp +++ b/kmicromail/accountview.cpp @@ -141,6 +141,7 @@ void AccountView::setupFolderselect(Selectstore*sels) } void AccountView::downloadMailsInbox(const FolderP&fromFolder,AbstractMail*fromWrapper) { +#if 0 AbstractMail*targetMail = 0; QString targetFolder = ""; Selectstore sels; @@ -162,9 +163,11 @@ void AccountView::downloadMailsInbox(const FolderP&fromFolder,AbstractMail*fromW int maxsize = 0; if ( sels.useSize->isChecked()) maxsize = sels.sizeSpinBox->value(); - fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails(), maxsize); +#endif + fromWrapper->downloadNewMails( fromFolder, mhAccounts[0]->getWrapper()); refreshCurrent(); + } void AccountView::downloadMails(const FolderP&fromFolder,AbstractMail*fromWrapper) diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp index f876235..374d606 100644 --- a/kmicromail/libmailwrapper/abstractmail.cpp +++ b/kmicromail/libmailwrapper/abstractmail.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -158,6 +159,72 @@ void AbstractMail::deleteMailList(const QValueList&target) ++iii; } } + +void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail ) +{ + qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1()); + // get local folder + Account * acc = getAccount(); + if ( !acc ) return; + QString lfName = acc->getLocalFolder(); + if ( lfName.isEmpty() ) + lfName = acc->getAccountName(); + // create local folder + if ( !targetMail->createMbox(lfName)) + { + QMessageBox::critical(0,tr("Error creating new Folder"), + tr("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName)); + return; + } + QValueList t; + listMessages(fromFolder->getName(),t,acc->getMaxMailSize() ); + if ( t.count() == 0 ) { + Global::statusMessage(tr("There are no new messages")); + return; + } + QValueList e; + targetMail->listMessages(lfName,e,acc->getMaxMailSize() ); + qDebug("target has mails %d ", e.count()); + QValueList n; + int iii = 0; + int count = t.count(); + while (iii < count ) { + RecMailP r = (*t.at( iii )); + bool found = false; + int jjj = 0; + int countE = e.count(); + while (jjj < countE ) { + RecMailP re = (*e.at( jjj )); + if ( re->isEqual(r) ) { + found = true; + break; + } + ++jjj; + } + if ( found ) + qDebug("found "); + else + qDebug("NOT found "); + + if ( !found ) { + n.append( r ); + } + ++iii; + } + if ( n.count() == 0 ) { + Global::statusMessage(tr("There are no new messages")); + return; + } + mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer()); + + +#if 0 + QValueList t; + listMessages(fromFolder->getName(),t, maxSizeInKb); + mvcpMailList( t,targetFolder,targetWrapper,moveit); +#endif + +} void AbstractMail::mvcpAllMails(const FolderP&fromFolder, const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) { diff --git a/kmicromail/libmailwrapper/abstractmail.h b/kmicromail/libmailwrapper/abstractmail.h index cae83f4..2069ca1 100644 --- a/kmicromail/libmailwrapper/abstractmail.h +++ b/kmicromail/libmailwrapper/abstractmail.h @@ -10,6 +10,9 @@ #include #include "mailtypes.h" + +#include "mailwrapper.h" + class IMAPwrapper; class POP3wrapper; class Folder; @@ -38,7 +41,7 @@ public: virtual void deleteMails(const QString & FolderName,const QValueList >&target); virtual int deleteMbox(const Opie::Core::OSmartPointer&)=0; virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0; - + void downloadNewMails(const FolderP&fromFolder,AbstractMail*targetWrapper ); virtual void mvcpAllMails(const Opie::Core::OSmartPointer&fromFolder, const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int sizeInKb = 0); virtual void mvcpMailList(const QValueList& t, @@ -55,6 +58,8 @@ public: const QString& delemiter="/",bool getsubfolder=false); virtual void logout()=0; + virtual Account* getAccount() = 0; + static AbstractMail* getWrapper(IMAPaccount *a); static AbstractMail* getWrapper(POP3account *a); static AbstractMail* getWrapper(NNTPaccount *a); diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp index 9614d53..2b04847 100644 --- a/kmicromail/libmailwrapper/genericwrapper.cpp +++ b/kmicromail/libmailwrapper/genericwrapper.cpp @@ -3,6 +3,9 @@ #include #include "mailtypes.h" +#include +#include +#include using namespace Opie::Core; @@ -24,6 +27,48 @@ Genericwrapper::~Genericwrapper() } cleanMimeCache(); } +QString 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.readBoolEntry( "PreferredTime",0 ) ); + KGlobal::locale()->setDateFormatShort(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; + + } + QDateTime dt (QDate(date->dt_year,date->dt_month, date->dt_day ),QTime(date->dt_hour, date->dt_min, date->dt_sec ) ); + int off = KGlobal::locale()->localTimeOffset( dt ); + dt = dt.addSecs( off*60 ); + QString ret = KGlobal::locale()->formatDateTime( dt,true,true); + if ( off < 0 ) + ret += " -"; + else + ret += " +"; + ret += QString::number( off / 60 ); + ret += "h"; +#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) { @@ -242,17 +287,6 @@ RecBodyP Genericwrapper::parseMail( mailmessage * msg ) return body; } -QString Genericwrapper::parseDateTime( mailimf_date_time *date ) -{ - 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 ); -} QString Genericwrapper::parseAddressList( mailimf_address_list *list ) { @@ -448,8 +482,14 @@ void Genericwrapper::parseList(QValueList > & 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) + if (single_fields.fld_orig_date) { mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); + char tmp[23]; + struct mailimf_date_time* date = single_fields.fld_orig_date->dt_date_time; + 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 ); + 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)); diff --git a/kmicromail/libmailwrapper/genericwrapper.h b/kmicromail/libmailwrapper/genericwrapper.h index 235e116..244212f 100644 --- a/kmicromail/libmailwrapper/genericwrapper.h +++ b/kmicromail/libmailwrapper/genericwrapper.h @@ -42,6 +42,7 @@ public: virtual int deleteMbox(const Opie::Core::OSmartPointer&){return 1;} virtual void logout(){}; virtual void storeMessage(const char*msg,size_t length, const QString&folder){}; + static QString parseDateTime( mailimf_date_time *date ); protected: RecBodyP parseMail( mailmessage * msg ); @@ -49,7 +50,6 @@ protected: QString parseMailbox( mailimf_mailbox *box ); QString parseGroup( mailimf_group *group ); QString parseAddressList( mailimf_address_list *list ); - QString parseDateTime( mailimf_date_time *date ); void traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueListrecList,unsigned int current_rek=0,int current_count=1); static void fillSingleBody(RecPartP&target,mailmessage*message,mailmime*mime); diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index 6faa524..5441a9b 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp @@ -7,6 +7,7 @@ #include "mailtypes.h" #include "logindialog.h" #include +#include "genericwrapper.h" using namespace Opie::Core; int IMAPwrapper::mMax = 0; @@ -456,8 +457,23 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) mailimap_envelope * head = item->att_data.att_static->att_data.att_env; if ( head == NULL ) continue; - if ( head->env_date != NULL ) + if ( head->env_date != NULL ) { m->setDate(head->env_date); + struct mailimf_date_time result; + struct mailimf_date_time* date = &result; + struct mailimf_date_time **re = &date; + size_t length = m->getDate().length(); + size_t index = 0; + if ( mailimf_date_time_parse(head->env_date, length,&index, re ) == MAILIMF_NO_ERROR ) { + m->setDate( Genericwrapper::parseDateTime( date ) ); + char tmp[23]; + 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 ); + m->setIsoDate( QString( tmp ) ); + } else { + m->setIsoDate(head->env_date); + } + } if ( head->env_subject != NULL ) m->setSubject(convert_String((const char*)head->env_subject)); //m->setSubject(head->env_subject); diff --git a/kmicromail/libmailwrapper/imapwrapper.h b/kmicromail/libmailwrapper/imapwrapper.h index db8ab5b..5535d8d 100644 --- a/kmicromail/libmailwrapper/imapwrapper.h +++ b/kmicromail/libmailwrapper/imapwrapper.h @@ -52,6 +52,7 @@ public: virtual void logout(); virtual MAILLIB::ATYPE getType()const; virtual const QString&getName()const; + virtual Account* getAccount() { return account; }; protected: RecMail*parse_list_result(mailimap_msg_att*); diff --git a/kmicromail/libmailwrapper/mailtypes.cpp b/kmicromail/libmailwrapper/mailtypes.cpp index d43bdc6..1a4ffd1 100644 --- a/kmicromail/libmailwrapper/mailtypes.cpp +++ b/kmicromail/libmailwrapper/mailtypes.cpp @@ -23,7 +23,30 @@ RecMail::~RecMail() { wrapper = 0; } +static bool stringCompareRec( const QString& s1, const QString& s2 ) +{ + if ( s1.isEmpty() && s2.isEmpty() ) + return true; + return s1 == s2; +} +bool RecMail::isEqual( RecMail* r1 ) +{ + if ( !stringCompareRec( isodate, r1->isodate ) ) { + // qDebug("date *%s* *%s* ", isodate.latin1(), r1->isodate.latin1()); + return false; + } + if ( !stringCompareRec( from, r1->from ) ) { + //qDebug("from *%s* *%s* ", from.latin1(), r1->from.latin1()); + return false; + } + if ( !stringCompareRec( subject, r1->subject ) ) { + //qDebug("sub "); + return false; + } + + return true; +} void RecMail::copy_old(const RecMail&old) { subject = old.subject; diff --git a/kmicromail/libmailwrapper/mailtypes.h b/kmicromail/libmailwrapper/mailtypes.h index c317880..020278d 100644 --- a/kmicromail/libmailwrapper/mailtypes.h +++ b/kmicromail/libmailwrapper/mailtypes.h @@ -35,11 +35,14 @@ public: RecMail(); RecMail(const RecMail&old); virtual ~RecMail(); + bool isEqual( RecMail* r1 ); const unsigned int getNumber()const{return msg_number;} void setNumber(unsigned int number){msg_number=number;} const QString&getDate()const{ return date; } void setDate( const QString&a ) { date = a; } + const QString&getIsoDate()const{ return isodate; } + void setIsoDate( const QString&a ) { isodate = a; } const QString&getFrom()const{ return from; } void setFrom( const QString&a ) { from = a; } const QString&getSubject()const { return subject; } @@ -72,7 +75,7 @@ public: AbstractMail* Wrapper(); protected: - QString subject,date,from,mbox,msg_id,replyto; + QString subject,date,isodate,from,mbox,msg_id,replyto; unsigned int msg_number,msg_size; QBitArray msg_flags; QStringList to,cc,bcc,in_reply_to,references; diff --git a/kmicromail/libmailwrapper/mboxwrapper.h b/kmicromail/libmailwrapper/mboxwrapper.h index 9731b85..d03940f 100644 --- a/kmicromail/libmailwrapper/mboxwrapper.h +++ b/kmicromail/libmailwrapper/mboxwrapper.h @@ -36,6 +36,7 @@ public: virtual int deleteAllMail(const Opie::Core::OSmartPointer&); virtual MAILLIB::ATYPE getType()const; virtual const QString&getName()const; + virtual Account* getAccount() { return 0; }; protected: static void deleteMails(mailmbox_folder*f,const QValueList &target); diff --git a/kmicromail/libmailwrapper/mhwrapper.cpp b/kmicromail/libmailwrapper/mhwrapper.cpp index cbc52d9..962dac0 100644 --- a/kmicromail/libmailwrapper/mhwrapper.cpp +++ b/kmicromail/libmailwrapper/mhwrapper.cpp @@ -65,6 +65,7 @@ MHwrapper::~MHwrapper() void MHwrapper::listMessages(const QString & mailbox, QValueList > &target, int maxSizeInKb ) { + qDebug("MHwrapper::listMessages "); init_storage(); if (!m_storage) { return; diff --git a/kmicromail/libmailwrapper/mhwrapper.h b/kmicromail/libmailwrapper/mhwrapper.h index 550824d..d1b7d1f 100644 --- a/kmicromail/libmailwrapper/mhwrapper.h +++ b/kmicromail/libmailwrapper/mhwrapper.h @@ -42,6 +42,7 @@ public: virtual int deleteAllMail(const Opie::Core::OSmartPointer&); virtual MAILLIB::ATYPE getType()const; virtual const QString&getName()const; + virtual Account* getAccount() { return 0; }; public slots: /* for deleting maildirs we are using a system call */ diff --git a/kmicromail/libmailwrapper/nntpwrapper.h b/kmicromail/libmailwrapper/nntpwrapper.h index 5d4e5ce..8c54f12 100644 --- a/kmicromail/libmailwrapper/nntpwrapper.h +++ b/kmicromail/libmailwrapper/nntpwrapper.h @@ -37,6 +37,7 @@ public: virtual MAILLIB::ATYPE getType()const; virtual const QString&getName()const; static void nntp_progress( size_t current, size_t maximum ); + virtual Account* getAccount() { return account; }; protected: void login(); diff --git a/kmicromail/libmailwrapper/pop3wrapper.h b/kmicromail/libmailwrapper/pop3wrapper.h index 7c70942..ebc2fc7 100644 --- a/kmicromail/libmailwrapper/pop3wrapper.h +++ b/kmicromail/libmailwrapper/pop3wrapper.h @@ -34,7 +34,7 @@ public: virtual MAILLIB::ATYPE getType()const; virtual const QString&getName()const; static void pop3_progress( size_t current, size_t maximum ); - + virtual Account* getAccount() { return account; }; protected: void login(); POP3account *account; diff --git a/kmicromail/libmailwrapper/smtpwrapper.h b/kmicromail/libmailwrapper/smtpwrapper.h index 105cbf5..ec42b56 100644 --- a/kmicromail/libmailwrapper/smtpwrapper.h +++ b/kmicromail/libmailwrapper/smtpwrapper.h @@ -27,6 +27,7 @@ public: bool flushOutbox(); static progressMailSend*sendProgress; + virtual Account* getAccount() { return m_SmtpAccount; }; signals: void queuedMails( int ); diff --git a/kmicromail/mailistviewitem.cpp b/kmicromail/mailistviewitem.cpp index b92b0cf..484a635 100644 --- a/kmicromail/mailistviewitem.cpp +++ b/kmicromail/mailistviewitem.cpp @@ -53,11 +53,11 @@ void MailListViewItem::showEntry() //setText(3, "kB" + fsort ); // test only } else { //setText(3, fsize + "MB"); - mKeyMap.insert(4, "M" +fsort ); + mKeyMap.insert(3, "M" +fsort ); } setText(1,mail_data->getSubject()); setText(2,mail_data->getFrom()); - +#if 0 QString date = mail_data->getDate(); int kom = date.find( ",")+2; @@ -98,9 +98,12 @@ void MailListViewItem::showEntry() so = "12"; date = date.mid(7,4)+so+date.left(2)+date.mid(12,14); } + //qDebug("insert Date %s ", date.latin1()); // if ( date.left(1) != "1" || date.left(1) != "2" ) // date = date.mid(5); mKeyMap.insert(4,date); +#endif + mKeyMap.insert(4,mail_data->getIsoDate()); setText(4,mail_data->getDate()); } @@ -115,7 +118,7 @@ void MailListViewItem::setSortKey(int column,const QString &key) QString MailListViewItem::key(int column, bool) const { // to make is fast, we use here special cases - if ( column == 3 || column == 4 ) { + if ( column == 3 || column == 4 ) { return *mKeyMap.find(column); } if ( column == 1 ) { -- cgit v0.9.0.2