Summary: | automatically add people I reply to to address book | ||
---|---|---|---|
Product: | [Unmaintained] kmail | Reporter: | David Findlay <david> |
Component: | addressbook | Assignee: | Bruno Bigras <bigras.bruno> |
Status: | RESOLVED FIXED | ||
Severity: | wishlist | CC: | adorosh, bigras.bruno, cerebro84, harrywilly, jkt, kames, m.wege, me, mjhweb-kdebugs, null, r_a, siro_belza, tuju |
Priority: | NOR | ||
Version: | 1.4.3 | ||
Target Milestone: | --- | ||
Platform: | Debian testing | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: | |||
Attachments: |
addressbook auto-add filter
address book auto-add filter kmfilteraction.diff |
Description
David Findlay
2002-09-02 09:51:20 UTC
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Monday 02 September 2002 16:18 Gene Heskett wrote: > I'll heartily second that motion. Thor on my old amaiga did that > handier than bottled beer and sliced bread combined. One thing it > should do that Thor didn't though would be to only keep the last > entry for that person. Some people moved around and I wound up > with many different addresses for them. Which one was the right > one? Who knows... :-) Do you really want to have kmail@mail.kde.org david@davsoft.com.au=20 (Sorry!) and submit@bugs.kde.org (these are the addresses you sent your=20 message to) in your address book? If you want to add an address to the address book you can simply click=20 on it with the right mouse button and select "Add to Addressbook". In=20 KDE 3.1 this will add the address _without_ opening the KDE Address=20 Book. Furthermore KMail keeps the 30 (?) most recently used email addresses. I don't see why this feature could be useful. It would only clutter your=20 address book with a lot of unimportant email addresses. Regards Ingo -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9c+87GnR+RTDgudgRAsIcAJ9RdTDd7uQzx7FPMLASH4IxJTqU5QCfYi+y 9TZ5eIsKEy16O/rqoxzvy6c=3D =3D2AtW -----END PGP SIGNATURE----- On Monday 02 September 2002 19:07 Ingo Klöcker wrote: >-----BEGIN PGP SIGNED MESSAGE----- >Hash: SHA1 > >On Monday 02 September 2002 16:18 Gene Heskett wrote: >> I'll heartily second that motion. Thor on my old amaiga did >> that handier than bottled beer and sliced bread combined. One >> thing it should do that Thor didn't though would be to only >> keep the last entry for that person. Some people moved around >> and I wound up with many different addresses for them. Which >> one was the right one? Who knows... :-) > >Do you really want to have kmail@mail.kde.org > david@davsoft.com.au (Sorry!) and submit@bugs.kde.org (these are > the addresses you sent your message to) in your address book? > >If you want to add an address to the address book you can simply > click on it with the right mouse button and select "Add to > Addressbook". In KDE 3.1 this will add the address _without_ > opening the KDE Address Book. > >Furthermore KMail keeps the 30 (?) most recently used email > addresses. Humm expand that to say 300 to cover all the mailing lists I'm on and I'll shut up. But its still not auto-add and thats what we really need. >I don't see why this feature could be useful. It would only > clutter your address book with a lot of unimportant email > addresses. I disagree there Ingo I'd druther my address book was a alpha sorted mess running toward 10000 entries than to need an address 2 weeks after it expired. Just because I haven't used it in 2 years doesn't mean I won't need it tomorrow. Disk space to keep it is a non-argument today. -- Cheers Gene AMD K6-III@500mhz 320M Athlon1600XP@1400mhz 512M 99.13% setiathome rank not too shabby for a WV hillbilly -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 03 September 2002 02:51 Gene Heskett wrote: > On Monday 02 September 2002 19:07 Ingo Kl=F6cker wrote: > >I don't see why this feature could be useful. It would only > > clutter your address book with a lot of unimportant email > > addresses. > > I disagree there Ingo I'd druther my address book was a alpha > sorted mess running toward 10000 entries than to need an address 2 > weeks after it expired. Just because I haven't used it in 2 years > doesn't mean I won't need it tomorrow. Disk space to keep it is a > non-argument today. If disk space isn't a problem then why don't you simply archive all your=20 mail? Then you can simply search you mail archive for the desired=20 address. This won't take much more time than searching through 10000=20 entries in your addressbook. BTW you can easily write a filter which adds the To header of all=20 outgoing messages to a file (by executing a simple perl script).=20 Alternatively you can probably even add the addresses automatically to=20 KAddressbook via the dcop interface. Using a filter for this would even allow you to not add email addresses=20 like 47333@bugs.kde.org. Regards Ingo -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9dpWAGnR+RTDgudgRAgNBAJ4iEy7UJx0uqKuGRWsZ3Z8DsAV3bwCgliEA czHZ7GUx92UiUj6oqA+ZieA=3D =3D2XgE -----END PGP SIGNATURE----- This is a feature I'd like too. With a small refinement, a category could be defined for automatically collected addresses so that they can be easily filtered and separated from those which have been manually added. I'm sure it's annoying to get comments like this, but mozilla does this and I've found it a very useful feature. It's a nice way of avoiding the need to go through every email I know and add them. Perhaps as an alternative it would be nice to be able to right-click a message box and choose "harvest addresses" or some such to collect a whole set of addresses at once. This again would speed transistion from a different email system. Ingo, please don't brush it off that fast, it's a sincere enhancement request. I've been wishing this for a while also. When I use email, I usually just do my communications, and address book comes in as an afterthought. I found that Outlook Express has this feature and found it really useful - I rarely have to search for the addresses I need, it's all in the book already. One might restrict the addition to be 'Sender only' (makes for a relevant option) instead of the 'Everyone' approach taken by OE - OTOH I've used that facility to harvest addresses of remote friends I might want to get in touch with. It's a usability enhancement thing - nothing sexy - just makes life easier for Joe A. User. Created attachment 2560 [details]
addressbook auto-add filter
Here's a first pass at a solution to this. It's a filter, so you can either set
it to automatically add, or add manually. The filter lets you specify which
headers to extract from (From, To, CC, BCC).
It currently uses KMAddrBookExternal::addEmail which is "noisy" (you get a
dialog notification of each email added (or not if it's already in the list).
This would rapidly get annoying. Is there a correct "quiet" way to add it.
Preferably including adding a "automatic" category to the entry in the
addressbook.
patch is against CVS HEAD.
Created attachment 2777 [details]
address book auto-add filter
A much improved patch for this filter. It calls KAddressBook directly rather
than going through the kmail wrapper, so it doesn't produce dialogs on every
action. It also now takes a parameter to specify a category for the address
book entry. (Defaulting to "kmail-autoadd" which perhaps needs a better name).
(I know kmail is in feature freeze at the moment, but the patch is there in
case anyone wants to test and/or critique it).
This appears to be the same basic problem as bugs #18020 and #35421. (I don't have the permissions to assign them as duplicates however). *** Bug 74081 has been marked as a duplicate of this bug. *** *** This bug has been marked as a duplicate of 18020 *** Sorry the other way around... bug #18020 is a duplicate of this bug. *** Bug 18020 has been marked as a duplicate of this bug. *** *** Bug 29892 has been marked as a duplicate of this bug. *** *** Bug 35421 has been marked as a duplicate of this bug. *** Is there any problems with the patch attached to this bug? If not, any reason why it shouldn't be commited? The automatic option may exist and it could be set on or off. Personally I prefer to add them manually so I can control who I have on my adress book. I think this may be usefull for commercial companies, for the great spam emails would also be great! This is related to #70417 (one could be considered a duplicate of the other as the solution is the same). Created attachment 19248 [details] kmfilteraction.diff this is the patch from comment #7 adapted to SVN, +i18n, +resource combobox, +bug fix in resent-to SVN commit 625680 by schaarsc: - new filter action: add to address book - avoid endless loop in resent-to outbound messages GUI CCBUG: 47333 M +279 -0 branches/work/kdepim-3.5.5+/kmail/kmfilteraction.cpp --- branches/work/kdepim-3.5.5+/kmail/kmfilteraction.cpp #625679:625680 @@ -40,7 +40,11 @@ #include <kprocess.h> #include <kaudioplayer.h> #include <kurlrequester.h> +#include <kabc/addressbook.h> +#include <kabc/stdaddressbook.h> +#include <kabc/resource.h> +#include <qtooltip.h> #include <qlabel.h> #include <qlayout.h> #include <qtextcodec.h> @@ -592,8 +596,277 @@ return GoOn; } +//============================================================================= +// KMFilterActionAddToAddressBook +// - add email address from header to address book +//============================================================================= +class KMFilterActionAddToAddressBook: public KMFilterActionWithStringList +{ +public: + KMFilterActionAddToAddressBook(); + virtual ReturnCode process( KMMessage* msg ) const; + static KMFilterAction* newAction(); + virtual bool isEmpty() const { return false; } + virtual QWidget* createParamWidget( QWidget* parent ) const; + virtual void setParamWidgetValue( QWidget* paramWidget ) const; + virtual void applyParamWidgetValue( QWidget* paramWidget ); + virtual void clearParamWidget( QWidget* paramWidget ) const; + + virtual const QString argsAsString() const; + virtual void argsFromString( const QString argsStr ); + +private: + void updateLookups(); + QString mCategory, mResourceName; + QMap<QString, KABC::Resource*> mResourceByName, mResourceByID; + const QString mStdResourceString, mFromStr, mToStr, mCCStr, mBCCStr; +}; + +KMFilterAction* KMFilterActionAddToAddressBook::newAction() +{ + return (new KMFilterActionAddToAddressBook); +} + +KMFilterActionAddToAddressBook::KMFilterActionAddToAddressBook() + : KMFilterActionWithStringList( "add to address book", i18n("Add To Address Book") ), + mStdResourceString( i18n( "<default>" ) ), mFromStr( i18n( "From" ) ), + mToStr( i18n( "To" ) ), mCCStr( i18n( "CC" ) ), mBCCStr( i18n( "BCC" ) ) +{ + mParameterList.append( mFromStr ); + mParameterList.append( mToStr ); + mParameterList.append( mCCStr ); + mParameterList.append( mBCCStr ); + + mParameter = *mParameterList.at(0); + + updateLookups(); + mResourceName = mStdResourceString; + mCategory = i18n( "kmail-autoadd" ); +} + +void KMFilterActionAddToAddressBook::updateLookups() +{ + //find resources in standard addressbook + //and prepare lookups + QPtrList<KABC::Resource> list = KABC::StdAddressBook::self()->resources(); + for ( KABC::Resource* res = list.first() ; res; res = list.next() ) { + if ( !res->readOnly() && res->isOpen() ) { + mResourceByID.insert( res->identifier(), res ); + mResourceByName.insert( res->resourceName(), res ); + } + } +} + +KMFilterAction::ReturnCode KMFilterActionAddToAddressBook::process( KMMessage* msg ) const +{ + QString headerLine; + if ( mParameter == mFromStr ) + headerLine = msg->from(); + else if ( mParameter == mToStr ) + headerLine = msg->to(); + else if ( mParameter == mCCStr ) + headerLine = msg->cc(); + else if ( mParameter == mBCCStr ) + headerLine = msg->bcc(); + + QStringList emails = KPIM::splitEmailAddrList( headerLine ); + + KABC::AddressBook *ab = KABC::StdAddressBook::self(); + // force a reload of the address book file so that changes that were made + // by other programs are loaded + ab->load(); + + QString email; + QString name; + + QMap<QString, KABC::Resource*>::const_iterator it = mResourceByName.find( mResourceName ); + KABC::Resource* res = 0; + //if it==end(), then the resouce has been removed from addressbook + //or default has been selected, in either case store in default resource + if ( it != mResourceByName.end() ) + res = it.data(); + + KABC::Ticket *ticket = ab->requestSaveTicket( res ); + + if ( ticket ) { + for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { + KABC::Addressee::parseEmailAddress( *it, name, email ); + KABC::Addressee::List addressees = ab->findByEmail( email ); + + if ( addressees.isEmpty() ) { + KABC::Addressee a; + a.setNameFromString( name ); + a.insertEmail( email, true ); + if ( !mCategory.isEmpty() ) + a.insertCategory( mCategory ); + if( res ) + a.setResource( res ); + + ab->insertAddressee(a); + } + } + + if ( !ab->save( ticket ) ) + ab->error( i18n( "Can't save new addresses to address book." ) ); + } else + ab->error( i18n( "Can't save to address book. Address book is locked." ) ); + + return GoOn; +} + +QWidget* KMFilterActionAddToAddressBook::createParamWidget( QWidget* parent ) const +{ + QWidget *w = new QWidget( parent ); + QHBoxLayout *hbl = new QHBoxLayout( w ); + hbl->setSpacing( 4 ); + + QComboBox *cb = new QComboBox( FALSE, w, "combo" ); + cb->setInsertionPolicy( QComboBox::AtBottom ); + hbl->addWidget( cb, 0 /* stretch */ ); + + QLabel *l = new QLabel( i18n( "with category" ), w ); + l->setFixedWidth( l->sizeHint().width() ); + hbl->addWidget( l, 0 ); + + QLineEdit *le = new KLineEdit( w, "ledit" ); + hbl->addWidget( le, 1 ); + + l = new QLabel( i18n( "in resource" ), w ); + l->setFixedWidth( l->sizeHint().width() ); + hbl->addWidget( l, 0 ); + + cb = new QComboBox( FALSE, w, "resCombo" ); + QToolTip::add( cb, i18n( "This defines the preferred resource.<br>" + "If it is not accesible, the filter will fallback to < default> .<br>" + "<b>Notice:</b> changes to the addressbook will not be visible here until kmail has been restarted.") ); + cb->setInsertionPolicy( QComboBox::AtBottom ); + hbl->addWidget( cb, 0 /* stretch */ ); + + setParamWidgetValue( w ); + return w; +} + +void KMFilterActionAddToAddressBook::setParamWidgetValue( QWidget* paramWidget ) const +{ + QComboBox *cb = (QComboBox*)paramWidget->child( "combo" ); + Q_ASSERT( cb ); + cb->clear(); + cb->insertStringList( mParameterList ); + int idx = mParameterList.findIndex( mParameter ); + if ( idx < 0 ) { + kdDebug(5006)<<"unknown mParameter in KMFilterActionAddToAddressBook::setParamWidgetValue. strange???"<<endl; + cb->insertItem( mParameter ); + cb->setCurrentItem( cb->count() - 1 ); + } else { + cb->setCurrentItem( idx ); + } + + QLineEdit *le = (QLineEdit*)paramWidget->child( "ledit" ); + Q_ASSERT( le ); + le->setText( mCategory ); + + QStringList list = mResourceByName.keys(); + idx = list.findIndex( mResourceName ); + cb = (QComboBox*)paramWidget->child( "resCombo" ); + Q_ASSERT( cb ); + cb->clear(); + cb->insertItem( mStdResourceString ); + cb->insertStringList( mResourceByName.keys() ); + if ( idx < 0 ) { + cb->setCurrentItem( 0 ); + } else { + cb->setCurrentItem( idx + 1 /*mStdResourceString is not in keys() */ ); + } + +} + +void KMFilterActionAddToAddressBook::applyParamWidgetValue( QWidget* paramWidget ) +{ + QComboBox *cb = (QComboBox*)paramWidget->child( "combo" ); + Q_ASSERT( cb ); + mParameter = cb->currentText(); + + QLineEdit *le = (QLineEdit*)paramWidget->child( "ledit" ); + Q_ASSERT( le ); + mCategory = le->text(); + + cb = (QComboBox*)paramWidget->child( "resCombo" ); + Q_ASSERT( cb ); + mResourceName = cb->currentText(); +} + +void KMFilterActionAddToAddressBook::clearParamWidget( QWidget* paramWidget ) const +{ + QComboBox *cb = (QComboBox*)paramWidget->child( "combo" ); + Q_ASSERT( cb ); + cb->setCurrentItem( 0 ); + QLineEdit *le = (QLineEdit*)paramWidget->child( "ledit" ); + Q_ASSERT( le ); + le->setText( i18n( "kmail-autoadd" ) ); + cb = (QComboBox*)paramWidget->child( "resCombo" ); + Q_ASSERT( cb ); + cb->setCurrentItem( 0 ); +} + +const QString KMFilterActionAddToAddressBook::argsAsString() const +{ + QString result; + + if ( mParameter == mFromStr ) + result = "From"; + else if ( mParameter == mToStr ) + result = "To"; + else if ( mParameter == mCCStr ) + result = "CC"; + else if ( mParameter == mBCCStr ) + result = "BCC"; + + result += '\t'; + + QMap<QString, KABC::Resource*>::const_iterator it = mResourceByName.find( mResourceName ); + if ( it != mResourceByName.end() ) + result += it.data()->identifier(); + else + result += mStdResourceString; + + result += '\t'; + + result += mCategory; + + return result; +} + +void KMFilterActionAddToAddressBook::argsFromString( const QString argsStr ) +{ + updateLookups(); + + QStringList l = QStringList::split( '\t', argsStr, TRUE /*allow empty entries*/ ); + + mParameter = l[0]; + if ( mParameter == "From" ) + mParameter = mFromStr; + else if ( mParameter == "To" ) + mParameter = mToStr; + else if ( mParameter == "CC" ) + mParameter = mCCStr; + else if ( mParameter == "BCC" ) + mParameter = mBCCStr; + + QMap<QString, KABC::Resource*>::iterator it = mResourceByID.find( l[1] ); + if ( it != mResourceByID.end() ) + mResourceName = it.data()->resourceName(); + else + mResourceName = mStdResourceString; + + if ( l.count() < 3 ) + mCategory = ""; + else + mCategory = l[2]; +} + + //============================================================================= // KMFilterActionSetTransport - set transport to... // Specify mail transport (smtp server) to be used when replying to a message @@ -1548,6 +1821,11 @@ KMFilterAction::ReturnCode KMFilterActionRedirect::process(KMMessage* aMsg) const { + //avoid endless loop in outbound filters + const QString resentTo = aMsg->headerField( "Resent-To" ); + if ( KMMessage::addressIsInAddressList( mParameter, resentTo ) ) + return ErrorButGoOn; + KMMessage* msg; if ( mParameter.isEmpty() ) return ErrorButGoOn; @@ -1885,6 +2163,7 @@ insert( KMFilterActionAddHeader::newAction ); insert( KMFilterActionRewriteHeader::newAction ); insert( KMFilterActionExecSound::newAction ); + insert( KMFilterActionAddToAddressBook::newAction ); // Register custom filter actions below this line. } // The int in the QDict constructor (41) must be a prime *** Bug 139390 has been marked as a duplicate of this bug. *** Cool, that you did this. Are you in any way into filters? A few days ago I have reported a bug which is concerning the filters. Would be nice, if you could have a look at http://bugs.kde.org/show_bug.cgi?id=139747 *** Bug 144461 has been marked as a duplicate of this bug. *** how do I use this patch. do I have to recompile kde or is it a configuration file to copy somewhere? *** Bug 150915 has been marked as a duplicate of this bug. *** Does this filter exist in Kmail or not? It appears that something has been committed a long time ago. but I do not find a way to use it. If it exists this bug could be closed and may then it should be made a more visible feature. Comment #19 claims it was commited to 3.5.5+, but it does not seem to exist in 3.5.9. patch for kde4: http://reviewboard.kde.org/r/1038/diff/3/ related thread: http://osdir.com/ml/kde-pim/2009-07/threads.html#00181 (In reply to comment #25) > Does this filter exist in Kmail or not? afaik it has not been commited yet. (In reply to comment #23) > how do I use this patch. do I have to recompile kde or is it a configuration > file to copy somewhere? you have to get the kmail/kdepim source, apply the patch and recompile it. (In reply to comment #27) > afaik it has not been commited yet. You're right. The patch work but the changes made the UI look bad for others filter actions. I'm working on it. SVN commit 1003568 by bbigras: New "add to address book" filter type. Based on a commit from Christian Schaarschmidt on the 3.5.5+ branch. BUG: 47333 M +273 -0 kmfilteraction.cpp M +34 -18 kmfilterdlg.cpp M +13 -14 kmfilterdlg.h WebSVN link: http://websvn.kde.org/?view=rev&revision=1003568 When will the patch be included in a release (it isnt in 4.3.0)? The fix went in too late for 4.3 and because it's a new feature it can't be backported to 4.3. It will only be in 4.4 :( |