/android/import-contacts

To get this branch, use:
bzr branch http://bzr.ed.am/android/import-contacts

« back to all changes in this revision

Viewing changes to src/am/ed/importcontacts/VcardImporter.java

  • Committer: Tim Marston
  • Date: 2016-03-28 18:18:11 UTC
  • Revision ID: tim@ed.am-20160328181811-as61lllmvnv8e5os
handle vcards with missing vesion lines (treat as v2.1)

Show diffs side-by-side

added added

removed removed

90
90
                                // get files
91
91
                                class VCardFilter implements FilenameFilter {
92
92
                                        public boolean accept( File dir, String name ) {
93
 
                                                return name.toLowerCase( Locale.US ).endsWith( ".vcf" );
 
93
                                                return name.toLowerCase( Locale.ENGLISH )
 
94
                                                        .endsWith( ".vcf" );
94
95
                                        }
95
96
                                }
96
97
                                files = file.listFiles( new VCardFilter() );
235
236
                                                importContact( vcard );
236
237
                                        }
237
238
                                        catch( Vcard.ParseException e ) {
238
 
                                                if( !showContinue(
 
239
                                                showContinueOrAbort(
239
240
                                                        getText( R.string.error_vcf_parse ).toString()
240
241
                                                        + fileName +
241
242
                                                        getText( R.string.error_vcf_parse_line ).toString()
242
 
                                                        + cli.getLineNumber() + ":\n" + e.getMessage() ) )
243
 
                                                {
244
 
                                                        finish( ACTION_ABORT );
245
 
                                                }
246
 
                                                else
247
 
                                                        skipContact();
 
243
                                                        + cli.getLineNumber() + ":\n" + e.getMessage() );
 
244
                                                skipContact();
248
245
                                        }
249
246
                                        catch( ContactData.ContactNotIdentifiableException e ) {
250
 
                                                if( !showContinue(
 
247
                                                showContinueOrAbort(
251
248
                                                        getText( R.string.error_vcf_parse ).toString()
252
249
                                                        + fileName +
253
250
                                                        getText( R.string.error_vcf_parse_line ).toString()
254
251
                                                        + vcard_start_line + ":\n" + getText(
255
 
                                                                R.string.error_vcf_notenoughinfo ).toString()
256
 
                                                ) )
257
 
                                                {
258
 
                                                        finish( ACTION_ABORT );
259
 
                                                }
260
 
                                                else
261
 
                                                        skipContact();
 
252
                                                                R.string.error_vcf_notenoughinfo ).toString() );
 
253
                                                skipContact();
 
254
                                        }
 
255
                                        catch( Vcard.SkipImportException e ) {
 
256
                                                skipContact();
262
257
                                        }
263
258
 
264
259
                                        // discard this vcard
272
267
                                        }
273
268
                                        catch( Vcard.ParseException e ) {
274
269
                                                skipContact();
275
 
                                                if( !showContinue(
 
270
                                                showContinueOrAbort(
276
271
                                                        getText( R.string.error_vcf_parse ).toString()
277
272
                                                        + fileName +
278
273
                                                        getText( R.string.error_vcf_parse_line ).toString()
279
 
                                                        + cli.getLineNumber() + "\n" + e.getMessage() ) )
280
 
                                                {
281
 
                                                        finish( ACTION_ABORT );
282
 
                                                }
 
274
                                                        + cli.getLineNumber() + "\n" + e.getMessage() );
283
275
 
284
276
                                                // Although we're continuing, we still need to abort
285
277
                                                // this vCard.  Further lines will be ignored until we
616
608
                                ) );
617
609
                                boolean is_interesting_field =
618
610
                                        interesting_fields.contains(
619
 
                                                name_param_parts[ 0 ].toUpperCase( Locale.US ) );
 
611
                                                name_param_parts[ 0 ].toUpperCase( Locale.ENGLISH ) );
620
612
 
621
613
                                // parse encoding parameter
622
614
                                String encoding = checkParam( name_param_parts, "ENCODING" );
623
615
                                if( encoding != null )
624
 
                                        encoding = encoding.toUpperCase( Locale.US );
 
616
                                        encoding = encoding.toUpperCase( Locale.ENGLISH );
625
617
                                if( is_interesting_field && encoding != null &&
626
618
                                        !encoding.equalsIgnoreCase( "8BIT" ) &&
627
619
                                        !encoding.equalsIgnoreCase( "QUOTED-PRINTABLE" ) )
633
625
                                // parse charset parameter
634
626
                                String charset = checkParam( name_param_parts, "CHARSET" );
635
627
                                if( charset != null )
636
 
                                        charset = charset.toUpperCase( Locale.US );
 
628
                                        charset = charset.toUpperCase( Locale.ENGLISH );
637
629
                                if( charset != null &&
638
630
                                        !charset.equalsIgnoreCase( "US-ASCII" ) &&
639
631
                                        !charset.equalsIgnoreCase( "ASCII" ) &&
1046
1038
                }
1047
1039
 
1048
1040
                public void finaliseVcard()
1049
 
                        throws ParseException, ContactNotIdentifiableException
 
1041
                        throws ParseException, ContactNotIdentifiableException,
 
1042
                                SkipImportException, AbortImportException
1050
1043
                {
1051
 
                        // missing version (and data is present)
1052
 
                        if( _version == null && _content_lines != null )
1053
 
                                throw new ParseException( R.string.error_vcf_malformed );
 
1044
                        // if there was content present, but no version line, then it must
 
1045
                        // be a version 2.1 vCard; process that content now
 
1046
                        if( _version == null && _content_lines != null ) {
 
1047
                                _version = "2.1";
 
1048
                                for( int i = 0; i < _content_lines.size(); i++ )
 
1049
                                        parseLine( _content_lines.get( i ) );
 
1050
                                _content_lines = null;
 
1051
                        }
1054
1052
 
1055
1053
                        // finalise the parent class
1056
1054
                        finalise();
1115
1113
                                // this is in the specs!)
1116
1114
                                String[] parts = type_params[ a ].split( "," );
1117
1115
                                for( int i = 0; i < parts.length; i++ ) {
1118
 
                                        String ucpart = parts[ i ].toUpperCase( Locale.US );
 
1116
                                        String ucpart = parts[ i ].toUpperCase( Locale.ENGLISH );
1119
1117
                                        if( valid_types.contains( ucpart ) )
1120
1118
                                                types.add( ucpart );
1121
1119
                                }
1124
1122
                        // get 2.1-style type param
1125
1123
                        if( _version.equals( "2.1" ) ) {
1126
1124
                                for( int i = 1; i < params.length; i++ ) {
1127
 
                                        String ucparam = params[ i ].toUpperCase( Locale.US );
 
1125
                                        String ucparam = params[ i ].toUpperCase( Locale.ENGLISH );
1128
1126
                                        if( valid_types.contains( ucparam ) )
1129
1127
                                                types.add( ucparam );
1130
1128
                                }