andig / carddav2fb

Download CardDAV VCards and upload as phonebook to AVM FRITZ!Box
63 stars 19 forks source link

International area code ignored #193

Open obnys opened 4 years ago

obnys commented 4 years ago

Greetings, since import without FTP is working, I noticed today, that the international area code is beeing ignored with the imported data. e.g. +49 1234 987654 has been imported as 1234 987654, so the leading "0" has not been added while the international area code has been ignored. Are there intensions to add this? Otherwise I would just use 0049 1234 987654 or leave the area code aside as long as the number is in the same country.

andig commented 4 years ago

See https://github.com/andig/carddav2fb/blob/master/config.example.php#L100. Seems our default settings arent very good and we should replace with 0 instead of empty?

obnys commented 4 years ago

Oh dear, I'm sorry, I didn't notice I could just adjust the config.php. Now it works perfectly! Again thanks a lot! =) But you're right. "+49" it should either be replaced with '0049' or '0', instead of '' by default.

blacksenator commented 4 years ago

@obnys here a suggestion:

'phoneReplaceCharacters' => [          // are processed consecutively. Order decides!
    '('     => '',                          // delete separators
    ')'     => '',
    '/'     => '',
    '-'     => '',
    ' '     => '',
    '+491'  => '01',                   // domestic numbers without country code
    '+492'  => '02',
    '+493'  => '03',
    '+494'  => '04',
    '+495'  => '05',
    '+496'  => '06',
    '+497'  => '07',
    '+498'  => '08',
    '+499'  => '09',
    '+49'   => '',
    '+'     => '00'                    // normalize foreign numbers
]
obnys commented 4 years ago

Thank you @blacksenator =) But wouldn't this already be sufficient?

...
'+49'  => '0',
'0049'  => '0',
'+'     => '00',    // keep international area codes for foreign countries intact.
...

Do you think I would really need to add an entry for each area code digit from 1-9?

andig commented 4 years ago

But wouldn't this already be sufficient?

Think so. Would you kindly open a PR?

blacksenator commented 4 years ago

@obnys

But wouldn't this already be sufficient?

That depends on your source data and what you want to receive. I only want to have digits as numbers: 03667337171 for domestic numbers or 001476458488 for foreign numbers

I just made a few tests with my data and only this works for me:

'phoneReplaceCharacters' => [          // are processed consecutively. Order decides!
    '('     => '',                     // delete separators
    ')'     => '',
    '/'     => '',
    '-'     => '',
    ' '     => '',
    '+49 1'  => '01',                   // domestic numbers without area code
    '+49 2'  => '02',
    '+49 3'  => '03',
    '+49 4'  => '04',
    '+49 5'  => '05',
    '+49 6'  => '06',
    '+49 7'  => '07',
    '+49 8'  => '08',
    '+49 9'  => '09',
    '+491'  => '01',
    '+492'  => '02',
    '+493'  => '03',
    '+494'  => '04',
    '+495'  => '05',
    '+496'  => '06',
    '+497'  => '07',
    '+498'  => '08',
    '+499'  => '09',
    '+49'   => '',
    '+'     => '00'                    // normalize foreign numbers
]

@andig - I never thought about this line - so I tried to find information about how strstr works with assoziativ array (like in this way) - but couldn´t find any proper information.

andig commented 4 years ago

I never thought about this line - so I tried to find information about how strstr works with assoziativ array (like in this way) - but couldn´t find any proper information.

The thing is that strtr will replace verbatim, the array case is documented, too. Longest matches are processed first.

We're not using a regex here. Therefore:

$replace = [
    '+49' => '0',
    '+49 ' => '0',
];

echo(strtr('+49 151 4711', $replace)."\n");

gives

0151 4711

if you omit the second replacement you'll get

0 151 4711

which is ugly. So remember the variant with the space.

Would like a see a PR for improving the default config ;)

obnys commented 4 years ago

Oki, I made a pull request and somehow it landed at jens-maus. I hope I did it correct. Sorry, never did that before and I have zero experience with GitHub :-P

andig commented 4 years ago

Please use this repo as target- github allows to select that.

Am 20.01.2020 um 22:15 schrieb obnys notifications@github.com:

Oki, I made a pull request and somehow it landed at jens-maus. I hope I did it correct. Sorry, never did that before and I have zero experience with GitHub :-P

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

blacksenator commented 4 years ago

I have lost track of who is waiting for whom with a PR!

@andig When I wrote the line "I never thought about this line ..." I had overlooked the fact that it was strtr and not strstr. My confusion cleared up after reading the documentation for strtr.

andig commented 4 years ago

Ping @obnys would you mind to open another PR against this repo?

blacksenator commented 3 years ago

I can't see a reason keeping this issue open