From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kabc/kabc2mutt/kabc2mutt.cpp | 160 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 kabc/kabc2mutt/kabc2mutt.cpp (limited to 'kabc/kabc2mutt/kabc2mutt.cpp') diff --git a/kabc/kabc2mutt/kabc2mutt.cpp b/kabc/kabc2mutt/kabc2mutt.cpp new file mode 100644 index 00000000..84f4626b --- /dev/null +++ b/kabc/kabc2mutt/kabc2mutt.cpp @@ -0,0 +1,160 @@ +/* + KAbc2Mutt + + Copyright (c) 2003 - 2004 Tobias Koenig + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include + +#include + +#include + +#include "kabc2mutt.h" + +static std::ostream & operator<< ( std::ostream &os, const QString &s ); + +KABC2Mutt::KABC2Mutt( QObject *parent, const char *name ) + : QObject( parent, name ), mFormat( Aliases ), + mIgnoreCase( false ), mAllAddresses( false ), + mAlternateKeyFormat( false ), + mAddressBook( 0 ) +{ +} + +void KABC2Mutt::run() +{ + mAddressBook = KABC::StdAddressBook::self( true ); + KABC::StdAddressBook::setAutomaticSave( false ); + + connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook* ) ), + this, SLOT( loadingFinished() ) ); +} + +void KABC2Mutt::loadingFinished() +{ + // print addressees + KABC::AddressBook::ConstIterator iaddr; + for ( iaddr = mAddressBook->begin(); iaddr != mAddressBook->end(); ++iaddr ) { + const QString name = (*iaddr).givenName() + ' ' + (*iaddr).familyName(); + if ( !mQuery.isEmpty() ) { + bool match = (name.find(mQuery, 0, mIgnoreCase) > -1) || + ((*iaddr).preferredEmail().find( mQuery, 0, mIgnoreCase ) > -1 ); + if ( !match ) + continue; + } + + const QStringList &allAddresses = (*iaddr).emails(); + QStringList::const_iterator from, to; + bool multiple = false; + + if ( mAllAddresses ) { + // use all entries + multiple = allAddresses.size() > 1; + from = allAddresses.begin(); + to = allAddresses.end(); + } else { + // use only the first entry, the one returned by preferredEmail() + from = to = allAddresses.begin(); // start with empty list + if ( to != allAddresses.end() ) + ++to; + } + + size_t index = 0; + if ( mFormat == Aliases ) { + static const QChar space = QChar( ' ' ); + static const QChar underscore = QChar( '_' ); + + QString key; + if ( !mAlternateKeyFormat ) + key = (*iaddr).givenName().left( 3 ) + (*iaddr).familyName().left( 3 ); + else + if ( !(*iaddr).familyName().isEmpty() ) + key = (*iaddr).givenName().left( 1 ).lower() + + (*iaddr).familyName().lower().replace( space, underscore ); + else + key = (*iaddr).givenName().lower().replace( space, underscore ); + + while ( from != to ) { + std::cout << "alias " << key; + if ( index ) + std::cout << index; + std::cout << '\t' << name << " <" << (*from) << '>' << std::endl; + ++index; + ++from; + } + + if ( !(*iaddr).nickName().isEmpty() ) { + std::cout << "alias " + << (*iaddr).nickName().lower().replace( space, underscore ) + << '\t' << name << " <" + << (*iaddr).preferredEmail() << '>' << std::endl; + } + } else { + while ( from != to ) { + std::cout << (*from) << '\t' << name; + if ( multiple ) { + if ( index ) + std::cout << "\t#" << index; + else + std::cout << '\t' << i18n( "preferred" ); + ++index; + } + std::cout << std::endl; + ++from; + } + } + } + + // print all distribution lists + KABC::DistributionListManager manager( mAddressBook ); + manager.load(); + + QStringList dists = manager.listNames(); + for ( QStringList::Iterator iaddr = dists.begin(); iaddr != dists.end(); ++iaddr ) { + KABC::DistributionList *list = manager.list( *iaddr ); + if ( list ) { + if ( !mQuery.isEmpty() ) { + bool match = ((*iaddr).find(mQuery) > -1); + if ( !match ) + continue; + } + + QStringList emails = list->emails(); + if ( emails.isEmpty() ) + continue; + + if ( mFormat == Aliases ) { + std::cout << "alias " << (*iaddr).replace( QRegExp( " " ), "_" ) + << '\t' << emails.join( "," ) << std::endl; + } else { + std::cout << emails.join( "," ) << '\t' << (*iaddr) << '\t' << std::endl; + } + } + } + + kapp->quit(); +} + +static std::ostream & operator<< ( std::ostream &os, const QString &s ) +{ + os << s.local8Bit().data(); + return os; +} + +#include "kabc2mutt.moc" -- cgit v1.2.3