Beispiel #1
0
VCardLine VCardTool::createAgent(VCard::Version version, const Agent &agent)
{
    VCardLine line("AGENT");

    if(agent.isIntern())
    {
        if(agent.addressee() != 0)
        {
            Addressee::List list;
            list.append(*agent.addressee());

            QString str = createVCards(list, version);
            str.replace("\r\n", "\\n");
            str.replace(";", "\\;");
            str.replace(":", "\\:");
            str.replace(",", "\\,");
            line.setValue(str);
        }
    }
    else if(!agent.url().isEmpty())
    {
        line.setValue(agent.url());
        line.addParameter("value", "URI");
    }

    return line;
}
Beispiel #2
0
bool ResourceEvolution::load()
{
    /* doOpen never get's called :( */
    if(!doOpen())
        return false;
    if(!mWrap)
        return false; // open first!

    DBIterator it = mWrap->begin();
    // skip the "PAS-DB-VERSION"

    for(; it != mWrap->end(); ++it)
    {
        if(it.key().startsWith("PAS-DB-VERSION"))
            continue;

        qWarning("val:%s", it.value().latin1());
        VCardTool tool;
        QString str = it.value().stripWhiteSpace();
        Addressee::List list = tool.parseVCards(str);
        if(!list.first().isEmpty())
        {
            Addressee adr = list.first();
            adr.setResource(this);
            addressBook()->insertAddressee(adr);
        }
    }
    return true;
}
Beispiel #3
0
QString VCardConverter::createVCard( const Addressee &addr, Version version )
{
    Addressee::List list;
    list.append( addr );

    return createVCards( list, version );
}
Beispiel #4
0
int main( int argc, char **argv )
{
  KAboutData aboutData( "testkabcdlg", 0, ki18n( "TestKabc" ), "0.1" );
  KCmdLineArgs::init( argc, argv, &aboutData );

  KCmdLineOptions options;
  options.add( "multiple", ki18n( "Allow selection of multiple addressees" ) );
  KCmdLineArgs::addCmdLineOptions( options );

  KApplication app;

  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
  if ( args->isSet( "multiple" ) ) {
    Addressee::List al = AddresseeDialog::getAddressees( 0 );
    Addressee::List::ConstIterator it;
    kDebug() << "Selected Addressees:";
    for ( it = al.constBegin(); it != al.constEnd(); ++it ) {
      kDebug() << "  " << ( *it ).fullEmail();
    }
  } else {
    Addressee a = AddresseeDialog::getAddressee( 0 );

    if ( !a.isEmpty() ) {
      kDebug() << "Selected Addressee:";
      kDebug() << a.toString();
    } else {
      kDebug() << "No Addressee selected.";
    }
  }
}
Addressee::List AddresseeDialog::addressees()
{
    Addressee::List al;
    AddresseeItem *aItem = 0;

    if(mMultiple)
    {
        QListViewItem *item = mSelectedList->firstChild();
        while(item)
        {
            aItem = dynamic_cast< AddresseeItem * >(item);
            if(aItem)
                al.append(aItem->addressee());
            item = item->nextSibling();
        }
    }
    else
    {
        aItem = dynamic_cast< AddresseeItem * >(mAddresseeList->selectedItem());
        if(aItem)
            al.append(aItem->addressee());
    }

    return al;
}
Beispiel #6
0
bool ResourceEvolution::save(Ticket *ticket)
{
    delete ticket;
    if(!m_isOpen)
        return false;

    // just delete the summary so evolution will regenerate it
    // on next start up
    (void)QFile::remove(QDir::homeDirPath() + "/evolution/local/Contacts/addressbook.db.summary");


    AddressBook::Iterator it;
    Addressee::List list;
    for(it = addressBook()->begin(); it != addressBook()->end(); ++it)
    {
        if((*it).resource() != this || !(*it).changed())
            continue;

        // remove, convert add set unchanged false
        list.clear();
        mWrap->remove((*it).uid());
        VCardTool tool;
        list.append((*it));
        mWrap->add((*it).uid(), tool.createVCards(list, VCard::v2_1));

        (*it).setChanged(false);
    }

    return true;
}
Beispiel #7
0
void ResourceGroupwise::slotReadJobData( KIO::Job *job , const QByteArray &data )
{
  kdDebug() << "ResourceGroupwise::slotReadJobData()" << endl;
  Q_UNUSED( job );

  mJobData.append( data.data() );

  KABC::VCardConverter conv;
  QTime profile;
  profile.start();
  Addressee::List addressees = conv.parseVCards( mJobData );
 // kdDebug() << "  parsed " << addressees.count() << " contacts in "  << profile.elapsed() << "ms, now adding to resource..." << endl;

  Addressee::List::ConstIterator it;
  for( it = addressees.begin(); it != addressees.end(); ++it ) {
    KABC::Addressee addr = *it;
    if ( !addr.isEmpty() ) {
      addr.setResource( this );

      QString remote = addr.custom( "GWRESOURCE", "UID" );
      QString local = idMapper().localId( remote );
      if ( local.isEmpty() ) {
        idMapper().setRemoteId( addr.uid(), remote );
      } else {
        addr.setUid( local );
      }

      insertAddressee( addr );
      clearChange( addr );
    }
  }
  mJobData = QString::null;
}
Beispiel #8
0
Agent VCardTool::parseAgent(const VCardLine &line)
{
    Agent agent;

    const QStringList params = line.parameterList();
    if(params.findIndex("value") != -1)
    {
        if(line.parameter("value").lower() == "uri")
            agent.setUrl(line.value().asString());
    }
    else
    {
        QString str = line.value().asString();
        str.replace("\\n", "\r\n");
        str.replace("\\N", "\r\n");
        str.replace("\\;", ";");
        str.replace("\\:", ":");
        str.replace("\\,", ",");

        const Addressee::List list = parseVCards(str);
        if(list.count() > 0)
        {
            Addressee *addr = new Addressee;
            *addr = list[0];
            agent.setAddressee(addr);
        }
    }

    return agent;
}
Beispiel #9
0
void VCardFormat::save( const Addressee &addressee, QFile *file )
{
  VCardConverter converter;
  Addressee::List vcardlist;

  vcardlist.append( addressee );

  QByteArray data = converter.createVCards( vcardlist );

  file->write( data );
}
Beispiel #10
0
Addressee::List
vCardsAsAddresseeList()
{
    Addressee::List l;

    l.append( vcard1() );
    l.append( vcard2() );
    l.append( vcard3() );

    return l;
}
Beispiel #11
0
Addressee::List AddressBook::allAddressees() const
{
  Addressee::List list;

  ConstIterator it;
  for ( it = begin(); it != end(); ++it ) {
    list.append( *it );
  }

  return list;
}
Beispiel #12
0
Addressee::List Resource::findByName( const TQString &name )
{
  Addressee::List results;

  ConstIterator it;
  for ( it = begin(); it != end(); ++it ) {
    if ( name == (*it).name() )
      results.append( *it );
  }

  return results;
}
Beispiel #13
0
Addressee::List Resource::findByCategory( const TQString &category )
{
  Addressee::List results;

  ConstIterator it;
  for ( it = begin(); it != end(); ++it ) {
    if ( (*it).hasCategory( category) ) {
      results.append( *it );
    }
  }

  return results;
}
Beispiel #14
0
void ResourceGroupwise::slotUpdateJobData( KIO::Job *job, const QByteArray &data )
{
  kdDebug() << "ResourceGroupwise::slotUpdateJobData()" << endl;
  kdDebug() << "  Job address: " << job << endl;
  KABC::VCardConverter conv;
  mJobData.append( data.data() );

  Addressee::List addressees = conv.parseVCards( mJobData );
  Addressee::List::ConstIterator it;

  for( it = addressees.begin(); it != addressees.end(); ++it ) {
    KABC::Addressee addr = *it;
    if ( !addr.isEmpty() ) {
      // if added or changed
      QString syncType = addr.custom( "GWRESOURCE", "SYNC" );
      QString remote = addr.custom( "GWRESOURCE", "UID" );
      QString local = idMapper().localId( remote );

      if ( syncType == "ADD" || syncType == "UPD" )
      {
        addr.setResource( this );
          if ( local.isEmpty() ) {
          idMapper().setRemoteId( addr.uid(), remote );
        } else {
          addr.setUid( local );
        }

        insertAddressee( addr );
        clearChange( addr );
      }
      else if ( syncType == "DEL" )
      {
        // if deleted
        if ( !remote.isEmpty() )
        {
          if ( !local.isEmpty() )
          {
            idMapper().removeRemoteId( remote );
            KABC::Addressee addrToDelete = findByUid( local );
            removeAddressee( addrToDelete );
          }
        }
        else
          kdError() << "Addressee to delete did not have a remote UID, unable to find the corresponding local contact" << endl;
      }
    }
  }
  mJobData = QString::null;
}
Beispiel #15
0
void VCardFormat::saveAll( AddressBook *, Resource *resource, QFile *file )
{
  VCardConverter converter;
  Addressee::List vcardlist;

  Resource::Iterator it;
  Resource::Iterator end( resource->end() );
  for ( it = resource->begin(); it != end; ++it ) {
    ( *it ).setChanged( false );
    vcardlist.append( *it );
  }

  QByteArray data = converter.createVCards( vcardlist );

  file->write( data );
}
Beispiel #16
0
Addressee::List Resource::findByEmail( const TQString &email )
{
  Addressee::List results;
  const TQString lowerEmail = email.lower();

  ConstIterator it;
  for ( it = begin(); it != end(); ++it ) {
    const TQStringList mailList = (*it).emails();
    for ( TQStringList::ConstIterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
      if ( lowerEmail == (*ite).lower() )
        results.append( *it );
    }
  }

  return results;
}
Beispiel #17
0
bool VCardFormat::load( Addressee &addressee, QFile *file )
{
  QByteArray data;

  data = file->readAll();

  VCardConverter converter;
  Addressee::List l = converter.parseVCards( data );

  if ( ! l.first().isEmpty() ) {
    addressee = l.first();
    return true;
  }

  return false;
}
Beispiel #18
0
bool VCardFormat::loadAll( AddressBook *, Resource *resource, QFile *file )
{
  QByteArray data;

  data = file->readAll();

  VCardConverter converter;

  Addressee::List l = converter.parseVCards( data );

  Addressee::List::iterator itr;
  for ( itr = l.begin(); itr != l.end(); ++itr ) {
    Addressee addressee = *itr;
    addressee.setResource( resource );
    addressee.setChanged( false );
    resource->insertAddressee( addressee );
  }

  return true;
}
Beispiel #19
0
void RoundtripTest::testVCardRoundtrip()
{
  QFETCH( QString, inputFile );
  QFETCH( QString, output2_1File );
  QFETCH( QString, output3_0File );

  QVERIFY2( !output2_1File.isEmpty() || !output3_0File.isEmpty(),
            "No reference output file for either format version" );

  QFile input( QFileInfo( mInputDir, inputFile ).absoluteFilePath() );
  QVERIFY( input.open( QIODevice::ReadOnly ) );

  const QByteArray inputData = input.readAll();
  QVERIFY( !inputData.isEmpty() );

  VCardConverter converter;
  const Addressee::List list = converter.parseVCards( inputData );
  QVERIFY( !list.isEmpty() );

  if ( !output2_1File.isEmpty() ) {
    const QByteArray outputData = converter.createVCards( list, VCardConverter::v2_1 );

    QFile outputFile( QFileInfo( mOutput2_1Dir, output2_1File ).absoluteFilePath() );
    QVERIFY( outputFile.open( QIODevice::ReadOnly ) );

    const QByteArray outputRefData = outputFile.readAll();
    QCOMPARE( outputData.size(), outputRefData.size() );

    const QList<QByteArray> outputLines = outputData.split( '\n' );
    const QList<QByteArray> outputRefLines = outputRefData.split( '\n' );
    QCOMPARE( outputLines.count(), outputRefLines.count() );

    for ( int i = 0; i < outputLines.count(); ++i ) {
      const QByteArray actual = outputLines[ i ];
      const QByteArray expect = outputRefLines[ i ];

      if ( actual != expect ) {
        qCritical() << "Mismatch in v2.1 output line" << ( i + 1 );
        QCOMPARE( actual.count(), expect.count() );

        qCritical() << "\nActual:" << actual << "\nExpect:" << expect;
        QCOMPARE( actual, expect );
      }
    }
  }

  if ( !output3_0File.isEmpty() ) {
    const QByteArray outputData = converter.createVCards( list, VCardConverter::v3_0 );

    QFile outputFile( QFileInfo( mOutput3_0Dir, output3_0File ).absoluteFilePath() );
    QVERIFY( outputFile.open( QIODevice::ReadOnly ) );

    const QByteArray outputRefData = outputFile.readAll();
//    QCOMPARE( outputData.size(), outputRefData.size() );

    const QList<QByteArray> outputLines = outputData.split( '\n' );
    const QList<QByteArray> outputRefLines = outputRefData.split( '\n' );
    QCOMPARE( outputLines.count(), outputRefLines.count() );

    for ( int i = 0; i < outputLines.count(); ++i ) {
      const QByteArray actual = outputLines[ i ];
      const QByteArray expect = outputRefLines[ i ];

      if ( actual != expect ) {
        qCritical() << "Mismatch in v3.0 output line" << ( i + 1 );
        QCOMPARE( actual.count(), expect.count() );

        qCritical() << "\nActual:" << actual << "\nExpect:" << expect;
        QCOMPARE( actual, expect );
      }
    }
  }
}
Beispiel #20
0
Addressee::List VCardTool::parseVCards(const QString &vcard)
{
    static const QChar semicolonSep(';');
    static const QChar commaSep(',');
    QString identifier;

    Addressee::List addrList;
    const VCard::List vCardList = VCardParser::parseVCards(vcard);

    VCard::List::ConstIterator cardIt;
    VCard::List::ConstIterator listEnd(vCardList.end());
    for(cardIt = vCardList.begin(); cardIt != listEnd; ++cardIt)
    {
        Addressee addr;

        const QStringList idents = (*cardIt).identifiers();
        QStringList::ConstIterator identIt;
        QStringList::ConstIterator identEnd(idents.end());
        for(identIt = idents.begin(); identIt != identEnd; ++identIt)
        {
            const VCardLine::List lines = (*cardIt).lines((*identIt));
            VCardLine::List::ConstIterator lineIt;

            // iterate over the lines
            for(lineIt = lines.begin(); lineIt != lines.end(); ++lineIt)
            {
                identifier = (*lineIt).identifier().lower();
                // ADR
                if(identifier == "adr")
                {
                    Address address;
                    const QStringList addrParts = splitString(semicolonSep, (*lineIt).value().asString());
                    if(addrParts.count() > 0)
                        address.setPostOfficeBox(addrParts[0]);
                    if(addrParts.count() > 1)
                        address.setExtended(addrParts[1]);
                    if(addrParts.count() > 2)
                        address.setStreet(addrParts[2]);
                    if(addrParts.count() > 3)
                        address.setLocality(addrParts[3]);
                    if(addrParts.count() > 4)
                        address.setRegion(addrParts[4]);
                    if(addrParts.count() > 5)
                        address.setPostalCode(addrParts[5]);
                    if(addrParts.count() > 6)
                        address.setCountry(addrParts[6]);

                    int type = 0;

                    const QStringList types = (*lineIt).parameters("type");
                    for(QStringList::ConstIterator it = types.begin(); it != types.end(); ++it)
                        type += mAddressTypeMap[(*it).lower()];

                    address.setType(type);
                    addr.insertAddress(address);
                }

                // AGENT
                else if(identifier == "agent")
                    addr.setAgent(parseAgent(*lineIt));

                // BDAY
                else if(identifier == "bday")
                    addr.setBirthday(parseDateTime((*lineIt).value().asString()));

                // CATEGORIES
                else if(identifier == "categories")
                {
                    const QStringList categories = splitString(commaSep, (*lineIt).value().asString());
                    addr.setCategories(categories);
                }

                // CLASS
                else if(identifier == "class")
                    addr.setSecrecy(parseSecrecy(*lineIt));

                // EMAIL
                else if(identifier == "email")
                {
                    const QStringList types = (*lineIt).parameters("type");
                    addr.insertEmail((*lineIt).value().asString(), types.findIndex("PREF") != -1);
                }

                // FN
                else if(identifier == "fn")
                    addr.setFormattedName((*lineIt).value().asString());

                // GEO
                else if(identifier == "geo")
                {
                    Geo geo;

                    const QStringList geoParts = QStringList::split(';', (*lineIt).value().asString(), true);
                    geo.setLatitude(geoParts[0].toFloat());
                    geo.setLongitude(geoParts[1].toFloat());

                    addr.setGeo(geo);
                }

                // KEY
                else if(identifier == "key")
                    addr.insertKey(parseKey(*lineIt));

                // LABEL
                else if(identifier == "label")
                {
                    int type = 0;

                    const QStringList types = (*lineIt).parameters("type");
                    for(QStringList::ConstIterator it = types.begin(); it != types.end(); ++it)
                        type += mAddressTypeMap[(*it).lower()];

                    bool available = false;
                    KABC::Address::List addressList = addr.addresses();
                    KABC::Address::List::Iterator it;
                    for(it = addressList.begin(); it != addressList.end(); ++it)
                    {
                        if((*it).type() == type)
                        {
                            (*it).setLabel((*lineIt).value().asString());
                            addr.insertAddress(*it);
                            available = true;
                            break;
                        }
                    }

                    if(!available)
                    { // a standalone LABEL tag
                        KABC::Address address(type);
                        address.setLabel((*lineIt).value().asString());
                        addr.insertAddress(address);
                    }
                }

                // LOGO
                else if(identifier == "logo")
                    addr.setLogo(parsePicture(*lineIt));

                // MAILER
                else if(identifier == "mailer")
                    addr.setMailer((*lineIt).value().asString());

                // N
                else if(identifier == "n")
                {
                    const QStringList nameParts = splitString(semicolonSep, (*lineIt).value().asString());
                    if(nameParts.count() > 0)
                        addr.setFamilyName(nameParts[0]);
                    if(nameParts.count() > 1)
                        addr.setGivenName(nameParts[1]);
                    if(nameParts.count() > 2)
                        addr.setAdditionalName(nameParts[2]);
                    if(nameParts.count() > 3)
                        addr.setPrefix(nameParts[3]);
                    if(nameParts.count() > 4)
                        addr.setSuffix(nameParts[4]);
                }

                // NAME
                else if(identifier == "name")
                    addr.setName((*lineIt).value().asString());

                // NICKNAME
                else if(identifier == "nickname")
                    addr.setNickName((*lineIt).value().asString());

                // NOTE
                else if(identifier == "note")
                    addr.setNote((*lineIt).value().asString());

                // ORGANIZATION
                else if(identifier == "org")
                {
                    const QStringList orgParts = splitString(semicolonSep, (*lineIt).value().asString());
                    if(orgParts.count() > 0)
                        addr.setOrganization(orgParts[0]);
                    if(orgParts.count() > 1)
                        addr.setDepartment(orgParts[1]);
                }

                // PHOTO
                else if(identifier == "photo")
                    addr.setPhoto(parsePicture(*lineIt));

                // PROID
                else if(identifier == "prodid")
                    addr.setProductId((*lineIt).value().asString());

                // REV
                else if(identifier == "rev")
                    addr.setRevision(parseDateTime((*lineIt).value().asString()));

                // ROLE
                else if(identifier == "role")
                    addr.setRole((*lineIt).value().asString());

                // SORT-STRING
                else if(identifier == "sort-string")
                    addr.setSortString((*lineIt).value().asString());

                // SOUND
                else if(identifier == "sound")
                    addr.setSound(parseSound(*lineIt));

                // TEL
                else if(identifier == "tel")
                {
                    PhoneNumber phone;
                    phone.setNumber((*lineIt).value().asString());

                    int type = 0;

                    const QStringList types = (*lineIt).parameters("type");
                    for(QStringList::ConstIterator it = types.begin(); it != types.end(); ++it)
                        type += mPhoneTypeMap[(*it).upper()];

                    phone.setType(type);

                    addr.insertPhoneNumber(phone);
                }

                // TITLE
                else if(identifier == "title")
                    addr.setTitle((*lineIt).value().asString());

                // TZ
                else if(identifier == "tz")
                {
                    TimeZone tz;
                    const QString date = (*lineIt).value().asString();

                    int hours = date.mid(1, 2).toInt();
                    int minutes = date.mid(4, 2).toInt();
                    int offset = (hours * 60) + minutes;
                    offset = offset * (date[0] == '+' ? 1 : -1);

                    tz.setOffset(offset);
                    addr.setTimeZone(tz);
                }

                // UID
                else if(identifier == "uid")
                    addr.setUid((*lineIt).value().asString());

                // URL
                else if(identifier == "url")
                    addr.setUrl(KURL((*lineIt).value().asString()));

                // X-
                else if(identifier.startsWith("x-"))
                {
                    const QString key = (*lineIt).identifier().mid(2);
                    int dash = key.find("-");
                    addr.insertCustom(key.left(dash), key.mid(dash + 1), (*lineIt).value().asString());
                }
            }
        }

        addrList.append(addr);
    }

    return addrList;
}
Beispiel #21
0
// TODO: make list a const&
QString VCardTool::createVCards(Addressee::List list, VCard::Version version)
{
    VCard::List vCardList;

    Addressee::List::ConstIterator addrIt;
    Addressee::List::ConstIterator listEnd(list.constEnd());
    for(addrIt = list.constBegin(); addrIt != listEnd; ++addrIt)
    {
        VCard card;
        QStringList::ConstIterator strIt;

        // ADR + LABEL
        const Address::List addresses = (*addrIt).addresses();
        for(Address::List::ConstIterator it = addresses.begin(); it != addresses.end(); ++it)
        {
            QStringList address;

            bool isEmpty = ((*it).postOfficeBox().isEmpty() && (*it).extended().isEmpty() && (*it).street().isEmpty() && (*it).locality().isEmpty()
                            && (*it).region().isEmpty() && (*it).postalCode().isEmpty() && (*it).country().isEmpty());

            address.append((*it).postOfficeBox().replace(';', "\\;"));
            address.append((*it).extended().replace(';', "\\;"));
            address.append((*it).street().replace(';', "\\;"));
            address.append((*it).locality().replace(';', "\\;"));
            address.append((*it).region().replace(';', "\\;"));
            address.append((*it).postalCode().replace(';', "\\;"));
            address.append((*it).country().replace(';', "\\;"));

            VCardLine adrLine("ADR", address.join(";"));
            if(version == VCard::v2_1 && needsEncoding(address.join(";")))
            {
                adrLine.addParameter("charset", "UTF-8");
                adrLine.addParameter("encoding", "QUOTED-PRINTABLE");
            }

            VCardLine labelLine("LABEL", (*it).label());
            if(version == VCard::v2_1 && needsEncoding((*it).label()))
            {
                labelLine.addParameter("charset", "UTF-8");
                labelLine.addParameter("encoding", "QUOTED-PRINTABLE");
            }

            bool hasLabel = !(*it).label().isEmpty();
            QMap< QString, int >::ConstIterator typeIt;
            for(typeIt = mAddressTypeMap.constBegin(); typeIt != mAddressTypeMap.constEnd(); ++typeIt)
            {
                if(typeIt.data() & (*it).type())
                {
                    adrLine.addParameter("TYPE", typeIt.key());
                    if(hasLabel)
                        labelLine.addParameter("TYPE", typeIt.key());
                }
            }

            if(!isEmpty)
                card.addLine(adrLine);
            if(hasLabel)
                card.addLine(labelLine);
        }

        // AGENT
        card.addLine(createAgent(version, (*addrIt).agent()));

        // BDAY
        card.addLine(VCardLine("BDAY", createDateTime((*addrIt).birthday())));

        // CATEGORIES
        if(version == VCard::v3_0)
        {
            QStringList categories = (*addrIt).categories();
            QStringList::Iterator catIt;
            for(catIt = categories.begin(); catIt != categories.end(); ++catIt)
                (*catIt).replace(',', "\\,");

            VCardLine catLine("CATEGORIES", categories.join(","));
            if(version == VCard::v2_1 && needsEncoding(categories.join(",")))
            {
                catLine.addParameter("charset", "UTF-8");
                catLine.addParameter("encoding", "QUOTED-PRINTABLE");
            }

            card.addLine(catLine);
        }

        // CLASS
        if(version == VCard::v3_0)
        {
            card.addLine(createSecrecy((*addrIt).secrecy()));
        }

        // EMAIL
        const QStringList emails = (*addrIt).emails();
        bool pref = true;
        for(strIt = emails.begin(); strIt != emails.end(); ++strIt)
        {
            VCardLine line("EMAIL", *strIt);
            if(pref == true && emails.count() > 1)
            {
                line.addParameter("TYPE", "PREF");
                pref = false;
            }
            card.addLine(line);
        }

        // FN
        VCardLine fnLine("FN", (*addrIt).formattedName());
        if(version == VCard::v2_1 && needsEncoding((*addrIt).formattedName()))
        {
            fnLine.addParameter("charset", "UTF-8");
            fnLine.addParameter("encoding", "QUOTED-PRINTABLE");
        }
        card.addLine(fnLine);

        // GEO
        Geo geo = (*addrIt).geo();
        if(geo.isValid())
        {
            QString str;
            str.sprintf("%.6f;%.6f", geo.latitude(), geo.longitude());
            card.addLine(VCardLine("GEO", str));
        }

        // KEY
        const Key::List keys = (*addrIt).keys();
        Key::List::ConstIterator keyIt;
        for(keyIt = keys.begin(); keyIt != keys.end(); ++keyIt)
            card.addLine(createKey(*keyIt));

        // LOGO
        card.addLine(createPicture("LOGO", (*addrIt).logo()));

        // MAILER
        VCardLine mailerLine("MAILER", (*addrIt).mailer());
        if(version == VCard::v2_1 && needsEncoding((*addrIt).mailer()))
        {
            mailerLine.addParameter("charset", "UTF-8");
            mailerLine.addParameter("encoding", "QUOTED-PRINTABLE");
        }
        card.addLine(mailerLine);

        // N
        QStringList name;
        name.append((*addrIt).familyName().replace(';', "\\;"));
        name.append((*addrIt).givenName().replace(';', "\\;"));
        name.append((*addrIt).additionalName().replace(';', "\\;"));
        name.append((*addrIt).prefix().replace(';', "\\;"));
        name.append((*addrIt).suffix().replace(';', "\\;"));

        VCardLine nLine("N", name.join(";"));
        if(version == VCard::v2_1 && needsEncoding(name.join(";")))
        {
            nLine.addParameter("charset", "UTF-8");
            nLine.addParameter("encoding", "QUOTED-PRINTABLE");
        }
        card.addLine(nLine);

        // NAME
        VCardLine nameLine("NAME", (*addrIt).name());
        if(version == VCard::v2_1 && needsEncoding((*addrIt).name()))
        {
            nameLine.addParameter("charset", "UTF-8");
            nameLine.addParameter("encoding", "QUOTED-PRINTABLE");
        }
        card.addLine(nameLine);

        // NICKNAME
        if(version == VCard::v3_0)
            card.addLine(VCardLine("NICKNAME", (*addrIt).nickName()));

        // NOTE
        VCardLine noteLine("NOTE", (*addrIt).note());
        if(version == VCard::v2_1 && needsEncoding((*addrIt).note()))
        {
            noteLine.addParameter("charset", "UTF-8");
            noteLine.addParameter("encoding", "QUOTED-PRINTABLE");
        }
        card.addLine(noteLine);

        // ORG
        QStringList organization;
        organization.append((*addrIt).organization().replace(';', "\\;"));
        if(!(*addrIt).department().isEmpty())
            organization.append((*addrIt).department().replace(';', "\\;"));
        VCardLine orgLine("ORG", organization.join(";"));
        if(version == VCard::v2_1 && needsEncoding(organization.join(";")))
        {
            orgLine.addParameter("charset", "UTF-8");
            orgLine.addParameter("encoding", "QUOTED-PRINTABLE");
        }
        card.addLine(orgLine);

        // PHOTO
        card.addLine(createPicture("PHOTO", (*addrIt).photo()));

        // PROID
        if(version == VCard::v3_0)
            card.addLine(VCardLine("PRODID", (*addrIt).productId()));

        // REV
        card.addLine(VCardLine("REV", createDateTime((*addrIt).revision())));

        // ROLE
        VCardLine roleLine("ROLE", (*addrIt).role());
        if(version == VCard::v2_1 && needsEncoding((*addrIt).role()))
        {
            roleLine.addParameter("charset", "UTF-8");
            roleLine.addParameter("encoding", "QUOTED-PRINTABLE");
        }
        card.addLine(roleLine);

        // SORT-STRING
        if(version == VCard::v3_0)
            card.addLine(VCardLine("SORT-STRING", (*addrIt).sortString()));

        // SOUND
        card.addLine(createSound((*addrIt).sound()));

        // TEL
        const PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers();
        PhoneNumber::List::ConstIterator phoneIt;
        for(phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt)
        {
            VCardLine line("TEL", (*phoneIt).number());

            QMap< QString, int >::ConstIterator typeIt;
            for(typeIt = mPhoneTypeMap.constBegin(); typeIt != mPhoneTypeMap.constEnd(); ++typeIt)
            {
                if(typeIt.data() & (*phoneIt).type())
                    line.addParameter("TYPE", typeIt.key());
            }

            card.addLine(line);
        }

        // TITLE
        VCardLine titleLine("TITLE", (*addrIt).title());
        if(version == VCard::v2_1 && needsEncoding((*addrIt).title()))
        {
            titleLine.addParameter("charset", "UTF-8");
            titleLine.addParameter("encoding", "QUOTED-PRINTABLE");
        }
        card.addLine(titleLine);

        // TZ
        TimeZone timeZone = (*addrIt).timeZone();
        if(timeZone.isValid())
        {
            QString str;

            int neg = 1;
            if(timeZone.offset() < 0)
                neg = -1;

            str.sprintf("%c%02d:%02d", (timeZone.offset() >= 0 ? '+' : '-'), (timeZone.offset() / 60) * neg, (timeZone.offset() % 60) * neg);

            card.addLine(VCardLine("TZ", str));
        }

        // UID
        card.addLine(VCardLine("UID", (*addrIt).uid()));

        // URL
        card.addLine(VCardLine("URL", (*addrIt).url().url()));

        // VERSION
        if(version == VCard::v2_1)
            card.addLine(VCardLine("VERSION", "2.1"));
        if(version == VCard::v3_0)
            card.addLine(VCardLine("VERSION", "3.0"));

        // X-
        const QStringList customs = (*addrIt).customs();
        for(strIt = customs.begin(); strIt != customs.end(); ++strIt)
        {
            QString identifier = "X-" + (*strIt).left((*strIt).find(":"));
            QString value = (*strIt).mid((*strIt).find(":") + 1);
            if(value.isEmpty())
                continue;

            VCardLine line(identifier, value);
            if(version == VCard::v2_1 && needsEncoding(value))
            {
                line.addParameter("charset", "UTF-8");
                line.addParameter("encoding", "QUOTED-PRINTABLE");
            }
            card.addLine(line);
        }

        vCardList.append(card);
    }

    return VCardParser::createVCards(vCardList);
}