author | eilers <eilers> | 2004-11-19 11:27:04 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-11-19 11:27:04 (UTC) |
commit | 58759f9d1219ecb5eddc9c8c19f89004ee2a942a (patch) (side-by-side diff) | |
tree | 6f34792623e60de8b73d0de52075864675980944 | |
parent | 362e353e4ee43a5aa37fd4c264ad0b40bbd0098b (diff) | |
download | opie-58759f9d1219ecb5eddc9c8c19f89004ee2a942a.zip opie-58759f9d1219ecb5eddc9c8c19f89004ee2a942a.tar.gz opie-58759f9d1219ecb5eddc9c8c19f89004ee2a942a.tar.bz2 |
Make VCARD importer more stable if something parsed which was not expected.
Thus, we are now able to import VCards from Evolution 2 and Apple Addressbook..
This is fixing issue #1479
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | 36 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_vcard.h | 7 |
2 files changed, 36 insertions, 7 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp index 43e530a..5bb21c7 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp @@ -39,25 +39,27 @@ #include <qpe/timeconversion.h> //FIXME: Hack to allow direct access to FILE* fh. Rewrite this! #define protected public #include <qfile.h> #undef protected namespace Opie { OPimContactAccessBackend_VCard::OPimContactAccessBackend_VCard ( const QString& , const QString& filename ): m_dirty( false ), - m_file( filename ) + m_file( filename ), + version_major( 1 ), + version_minor( 0 ) { load(); } bool OPimContactAccessBackend_VCard::load () { m_map.clear(); m_dirty = false; VObject* obj = 0l; @@ -177,66 +179,75 @@ bool OPimContactAccessBackend_VCard::hasQuerySettings (uint ) const return false; // No search possible, therefore all settings invalid ;) } bool OPimContactAccessBackend_VCard::wasChangedExternally() { return false; // Don't expect concurrent access } // *** Private stuff *** OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj ) { OPimContact c; - VObjectIterator it; initPropIterator( &it, obj ); while( moreIteration( &it ) ) { VObject *o = nextVObject( &it ); QCString name = vObjectName( o ); QString value = QString::fromUtf8( vObjectStringZValue( o ) ); - odebug << "(1)Read: %s" << QString( value ).latin1() << oendl; - if ( name == VCNameProp ) { + odebug << "(1)Read: " << name << " " << QString( value ).latin1() << oendl; + if ( name == VCVersionProp ) { + + odebug << "Version: " << value << oendl; + QStringList version = QStringList::split( ".", value ); + version_major = version[0].toUInt(); + version_minor = version[1].toUInt(); + odebug << "Major: "<< version_major << " Minor: " << version_minor << oendl; + + } + else if ( name == VCNameProp ) { VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectTypeInfo( o ); QString value = QString::fromUtf8( vObjectStringZValue( o ) ); - odebug << "(2)Read: %s" << value.latin1() << oendl; + odebug << "Nametype is: "<< name << " Value: " << value.latin1() << oendl; if ( name == VCNamePrefixesProp ) c.setTitle( value ); else if ( name == VCNameSuffixesProp ) c.setSuffix( value ); else if ( name == VCFamilyNameProp ) c.setLastName( value ); else if ( name == VCGivenNameProp ) c.setFirstName( value ); else if ( name == VCAdditionalNamesProp ) c.setMiddleName( value ); } } else if ( name == VCAdrProp ) { bool work = TRUE; // default address is work address QString street; QString city; QString region; QString postal; QString country; VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); - QCString name = vObjectName( o ); + QCString name = vObjectTypeInfo( o ); QString value = QString::fromUtf8( vObjectStringZValue( o ) ); + odebug << "AddressType is: "<< name << " Value: " << value.latin1() << oendl; if ( name == VCHomeProp ) work = FALSE; else if ( name == VCWorkProp ) work = TRUE; else if ( name == VCStreetAddressProp ) street = value; else if ( name == VCCityProp ) city = value; else if ( name == VCRegionProp ) region = value; else if ( name == VCPostalCodeProp ) postal = value; @@ -265,76 +276,85 @@ OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj ) CELL = 0x08, FAX = 0x10, PAGER = 0x20, UNKNOWN = 0x80 }; int type = 0; VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectTypeInfo( o ); + odebug << "Telephonetype is: "<< name << " Value: " << value.latin1() << oendl; if ( name == VCHomeProp ) type |= HOME; else if ( name == VCWorkProp ) type |= WORK; else if ( name == VCVoiceProp ) type |= VOICE; else if ( name == VCCellularProp ) type |= CELL; else if ( name == VCFaxProp ) type |= FAX; else if ( name == VCPagerProp ) type |= PAGER; else if ( name == VCPreferredProp ) ; + else if ( name.left( 2 ) == "X-" || name.left( 2 ) == "x-" ) + ; // Ignore else type |= UNKNOWN; } if ( (type & UNKNOWN) != UNKNOWN ) { if ( ( type & (HOME|WORK) ) == 0 ) // default type |= HOME; if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default type |= VOICE; + odebug << "value %s %d" << value.data() << type << oendl; + if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) ) c.setHomePhone( value ); if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) c.setHomeFax( value ); if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) c.setHomeMobile( value ); if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) ) c.setBusinessPhone( value ); if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) c.setBusinessFax( value ); if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) c.setBusinessMobile( value ); if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) c.setBusinessPager( value ); } } else if ( name == VCEmailAddressProp ) { QString email = QString::fromUtf8( vObjectStringZValue( o ) ); bool valid = TRUE; VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectTypeInfo( o ); + odebug << "Emailtype is: "<< name << " Value: " << value.latin1() << oendl; if ( name != VCInternetProp && name != VCHomeProp && name != VCWorkProp && - name != VCPreferredProp ) + name != VCPreferredProp && + name.left( 2 ) != "X-" && name.left( 2 ) != "x-" ){ // ### preffered should map to default email valid = FALSE; + odebug << "Email was detected as invalid!" << oendl; + } } if ( valid ) { c.insertEmail( email ); } } else if ( name == VCURLProp ) { VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectTypeInfo( o ); if ( name == VCHomeProp ) @@ -573,13 +593,15 @@ VObject* OPimContactAccessBackend_VCard::safeAddPropValue( VObject *o, const cha ret = addPropValue( o, prop, value.utf8() ); return ret; } VObject* OPimContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) { VObject *ret = 0; if ( o ) ret = addProp( o, prop ); return ret; } + + } diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h index 1faf747..b734530 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h @@ -66,17 +66,24 @@ class OPimContactAccessBackend_VCard : public OPimContactAccessBackend { private: OPimContact parseVObject( VObject* obj ); VObject* createVObject( const OPimContact& c ); QString convDateToVCardDate( const QDate& c ) const; QDate convVCardDateToDate( const QString& datestr ); VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); VObject *safeAddProp( VObject* o, const char* prop); bool m_dirty : 1; QString m_file; QMap<int, OPimContact> m_map; + + /** + * Version of parsed VCard + */ + uint version_major; + uint version_minor; + }; } #endif |