2
// Copyright (C) 2005 - 2006 Kevin Krammer <kevin.krammer@gmx.at>
2
// Copyright (C) 2005 - 2011 Kevin Krammer <kevin.krammer@gmx.at>
3
// Copyright (C) 2011 Fernando Schapachnik <fernando@schapachnik.com.ar>
4
5
// This program is free software; you can redistribute it and/or modify
5
6
// it under the terms of the GNU General Public License as published by
390
391
///////////////////////////////////////////////////////////////////////////////
391
392
///////////////////////////////////////////////////////////////////////////////
393
MuttOutput::MuttOutput() : m_allEmails(false), m_queryFormat(false), m_altKeyFormat(false)
394
MuttOutput::MuttOutput()
395
: m_allEmails(false), m_queryFormat(false), m_altKeyFormat(false),
396
m_preferNickNameKey(false), m_alsoNickNameKey(false)
419
422
m_queryFormat = false;
420
423
else if ((*it) == "altkeys")
421
424
m_altKeyFormat = true;
425
else if ((*it) == "prefernick")
426
m_preferNickNameKey = true;
427
else if ((*it) == "alsonick")
428
m_alsoNickNameKey = true;
433
if (m_alsoNickNameKey && m_preferNickNameKey)
435
kDebug() << "Both 'prefernick' and 'alsonick' specified, using only 'alsonick'";
436
m_preferNickNameKey = false;
431
444
QString MuttOutput::optionUsage() const
434
i18n("Comma separated list of: allemails, query, alias, altkeys. Default is alias");
447
i18n("Comma separated list of: allemails, query, alias, altkeys, prefernick, alsonick. "
458
472
usage += i18n("Use alternative keys with alias format, e.g.\n\t\t"
459
473
"alias jdoe[tab]John Doe <jdoe@foo.com>");
477
usage += "prefernick\t";
478
usage += i18n("If a nick name exists use it instead of the key, e.g.\n\t\t"
479
"alias johnny[tab]John Doe <jdoe@foo.com>");
483
usage += "alsonick\t";
484
usage += i18n("Generate additional aliases with the nick name as the key, e.g.\n\t\t"
485
"alias johnny[tab]John Doe <jdoe@foo.com>\n\t\t"
486
"Deactivates 'prefernick' to avoid duplicates");
479
506
if (stream.bad()) return false;
508
const QString nickKeyString = nickNameKey(addressee);
510
// if we have a key based on nick name and we prefer it over normal key use it
511
// other wise use normal key
512
const QString keyString =
513
(m_preferNickNameKey && !nickKeyString.isEmpty()) ? nickKeyString : key(addressee);
483
517
QStringList emails = addressee.emails();
503
535
stream << fromUnicode(m_codec, addressee.givenName()).constData() << " "
504
536
<< fromUnicode(m_codec, addressee.familyName()).constData()<< " <"
505
537
<< fromUnicode(m_codec, *it).constData() << ">";
539
if (m_alsoNickNameKey && !nickKeyString.isEmpty())
543
<< fromUnicode(m_codec, nickKeyString).constData() << "\t";
544
stream << fromUnicode(m_codec, addressee.givenName()).constData() << " "
545
<< fromUnicode(m_codec, addressee.familyName()).constData()<< " <"
546
<< fromUnicode(m_codec, *it).constData() << ">";
508
550
if (stream.bad()) return false;
533
575
stream << fromUnicode(m_codec, addressee.givenName()).constData() << " "
534
576
<< fromUnicode(m_codec, addressee.familyName()).constData() << " <"
535
577
<< fromUnicode(m_codec, *it).constData() << ">";
579
if (m_alsoNickNameKey && !nickKeyString.isEmpty())
583
<< fromUnicode(m_codec, nickKeyString).constData() << "\t";
584
stream << fromUnicode(m_codec, addressee.givenName()).constData() << " "
585
<< fromUnicode(m_codec, addressee.familyName()).constData()<< " <"
586
<< fromUnicode(m_codec, *it).constData() << ">";
538
590
if (stream.bad()) return false;
544
if (!addressee.preferredEmail().isEmpty())
596
const QString preferredEmail = addressee.preferredEmail();
597
if (!preferredEmail.isEmpty())
546
599
if (m_queryFormat)
548
stream << fromUnicode(m_codec, addressee.preferredEmail()).constData() << "\t"
549
<< fromUnicode(m_codec, addressee.givenName()).constData() << " "
601
stream << fromUnicode(m_codec, preferredEmail).constData() << "\t"
602
<< fromUnicode(m_codec, addressee.givenName()).constData() << " "
550
603
<< fromUnicode(m_codec, addressee.familyName()).constData();
554
stream << "alias " << fromUnicode(m_codec, key(addressee)).constData() << "\t";
555
stream << fromUnicode(m_codec, addressee.givenName()).constData() << " "
556
<< fromUnicode(m_codec, addressee.familyName()).constData() << " <"
557
<< fromUnicode(m_codec, addressee.preferredEmail()).constData() << ">";
607
stream << "alias " << fromUnicode(m_codec, keyString).constData() << "\t";
608
stream << fromUnicode(m_codec, addressee.givenName()).constData() << " "
609
<< fromUnicode(m_codec, addressee.familyName()).constData() << " <"
610
<< fromUnicode(m_codec, preferredEmail).constData() << ">";
612
if (m_alsoNickNameKey && !nickKeyString.isEmpty())
616
<< fromUnicode(m_codec, nickKeyString).constData() << "\t";
617
stream << fromUnicode(m_codec, addressee.givenName()).constData() << " "
618
<< fromUnicode(m_codec, addressee.familyName()).constData()<< " <"
619
<< fromUnicode(m_codec, preferredEmail).constData() << ">";
602
665
return addressee.givenName().left(3) + addressee.familyName().left(3);
668
QString MuttOutput::nickNameKey(const KABC::Addressee& addressee) const
670
if (!addressee.nickName().isEmpty())
672
const QChar space = ' ';
673
const QChar underscore = '_';
674
return addressee.nickName().toLower().replace(space, underscore);
605
680
///////////////////////////////////////////////////////////////////////////////
606
681
///////////////////////////////////////////////////////////////////////////////