You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
161 lines
4.8 KiB
161 lines
4.8 KiB
15 years ago
|
/*
|
||
|
KAbc2Mutt
|
||
|
|
||
|
Copyright (c) 2003 - 2004 Tobias Koenig <tokoe@kde.org>
|
||
|
|
||
|
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.
|
||
|
*/
|
||
|
|
||
12 years ago
|
#include <tdeabc/distributionlist.h>
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
15 years ago
|
#include <tqregexp.h>
|
||
15 years ago
|
|
||
|
#include <iostream>
|
||
|
|
||
11 years ago
|
#include "tdeabc2mutt.h"
|
||
15 years ago
|
|
||
15 years ago
|
static std::ostream & operator<< ( std::ostream &os, const TQString &s );
|
||
15 years ago
|
|
||
14 years ago
|
KABC2Mutt::KABC2Mutt( TQObject *parent, const char *name )
|
||
|
: TQObject( parent, name ), mFormat( Aliases ),
|
||
15 years ago
|
mIgnoreCase( false ), mAllAddresses( false ),
|
||
|
mAlternateKeyFormat( false ),
|
||
|
mAddressBook( 0 )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void KABC2Mutt::run()
|
||
|
{
|
||
12 years ago
|
mAddressBook = TDEABC::StdAddressBook::self( true );
|
||
|
TDEABC::StdAddressBook::setAutomaticSave( false );
|
||
15 years ago
|
|
||
15 years ago
|
connect( mAddressBook, TQT_SIGNAL( addressBookChanged( AddressBook* ) ),
|
||
|
this, TQT_SLOT( loadingFinished() ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void KABC2Mutt::loadingFinished()
|
||
|
{
|
||
|
// print addressees
|
||
12 years ago
|
TDEABC::AddressBook::ConstIterator iaddr;
|
||
15 years ago
|
for ( iaddr = mAddressBook->begin(); iaddr != mAddressBook->end(); ++iaddr ) {
|
||
15 years ago
|
const TQString name = (*iaddr).givenName() + ' ' + (*iaddr).familyName();
|
||
15 years ago
|
if ( !mQuery.isEmpty() ) {
|
||
14 years ago
|
bool match = (name.find(mQuery, 0, mIgnoreCase) > -1) ||
|
||
|
((*iaddr).preferredEmail().find( mQuery, 0, mIgnoreCase ) > -1 );
|
||
15 years ago
|
if ( !match )
|
||
|
continue;
|
||
|
}
|
||
|
|
||
15 years ago
|
const TQStringList &allAddresses = (*iaddr).emails();
|
||
|
TQStringList::const_iterator from, to;
|
||
15 years ago
|
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 ) {
|
||
15 years ago
|
static const TQChar space = TQChar( ' ' );
|
||
|
static const TQChar underscore = TQChar( '_' );
|
||
15 years ago
|
|
||
15 years ago
|
TQString key;
|
||
15 years ago
|
if ( !mAlternateKeyFormat )
|
||
|
key = (*iaddr).givenName().left( 3 ) + (*iaddr).familyName().left( 3 );
|
||
|
else
|
||
|
if ( !(*iaddr).familyName().isEmpty() )
|
||
|
key = (*iaddr).givenName().left( 1 ).lower() +
|
||
14 years ago
|
(*iaddr).familyName().lower().replace( space, underscore );
|
||
15 years ago
|
else
|
||
14 years ago
|
key = (*iaddr).givenName().lower().replace( space, underscore );
|
||
15 years ago
|
|
||
|
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 "
|
||
14 years ago
|
<< (*iaddr).nickName().lower().replace( space, underscore )
|
||
15 years ago
|
<< '\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
|
||
12 years ago
|
TDEABC::DistributionListManager manager( mAddressBook );
|
||
15 years ago
|
manager.load();
|
||
|
|
||
15 years ago
|
TQStringList dists = manager.listNames();
|
||
|
for ( TQStringList::Iterator iaddr = dists.begin(); iaddr != dists.end(); ++iaddr ) {
|
||
12 years ago
|
TDEABC::DistributionList *list = manager.list( *iaddr );
|
||
15 years ago
|
if ( list ) {
|
||
|
if ( !mQuery.isEmpty() ) {
|
||
14 years ago
|
bool match = ((*iaddr).find(mQuery) > -1);
|
||
15 years ago
|
if ( !match )
|
||
|
continue;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList emails = list->emails();
|
||
15 years ago
|
if ( emails.isEmpty() )
|
||
|
continue;
|
||
|
|
||
|
if ( mFormat == Aliases ) {
|
||
14 years ago
|
std::cout << "alias " << (*iaddr).replace( TQRegExp( " " ), "_" )
|
||
15 years ago
|
<< '\t' << emails.join( "," ) << std::endl;
|
||
|
} else {
|
||
|
std::cout << emails.join( "," ) << '\t' << (*iaddr) << '\t' << std::endl;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
kapp->quit();
|
||
|
}
|
||
|
|
||
15 years ago
|
static std::ostream & operator<< ( std::ostream &os, const TQString &s )
|
||
15 years ago
|
{
|
||
|
os << s.local8Bit().data();
|
||
|
return os;
|
||
|
}
|
||
|
|
||
11 years ago
|
#include "tdeabc2mutt.moc"
|