andig / carddav2fb

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

Use REPORT method #129

Closed andig closed 5 years ago

andig commented 5 years ago

Fix #50

/cc @blacksenator @mokkin

andig commented 5 years ago

Double-checked and is working with iCloud for me

mokkin commented 5 years ago

That's strange: with the patch applied it doesn't download any card. Not from my nextcloud and not from the account I sent you the credentials.

andig commented 5 years ago

Setz mal bitte http => debug = true und schick mir per pm die Ausgabe von

./carddav2fb download

Bei mir ging das tatsächlich wunderbar.

mokkin commented 5 years ago

siehe PM

mokkin commented 5 years ago

That's cool! With your last change it's working perfectly and like 100 times faster! :+1: for pushing the pull request

mokkin commented 5 years ago

Just one addition: If there is a really empty addressbook between the ones with contacts, the download fails. That's not a big problem, because you simply can uncomment the one, but maybe this can be skipped.

php carddav2fb.php run
Downloading vCard(s) from account user
  401 [============================]
Downloaded 401 vCard(s)
Downloading vCard(s) from account user
   56 [============================]
Downloaded 858 vCard(s)
Downloading vCard(s) from account user
   81 [============================]
Downloaded 1396 vCard(s)
Downloading vCard(s) from account user
  465 [============================]
Downloaded 2399 vCard(s)
Downloading vCard(s) from account user
   44 [============================]
Downloaded 3446 vCard(s)
Downloading vCard(s) from account user
  107 [============================]
Downloaded 4600 vCard(s)
Downloading vCard(s) from account user
  124 [============================]
Downloaded 5878 vCard(s)
Downloading vCard(s) from account user
  349 [============================]
Downloaded 7505 vCard(s)
Downloading vCard(s) from account user
    3 [============================]
Downloaded 9135 vCard(s)
Downloading vCard(s) from account user
  167 [============================]
Downloaded 10932 vCard(s)
Downloading vCard(s) from account user
   14 [============================]
Downloaded 12743 vCard(s)
Downloading vCard(s) from account user
   35 [============================]
Downloaded 14589 vCard(s)
Downloading vCard(s) from account user
    1 [============================]
Downloaded 16436 vCard(s)
Downloading vCard(s) from account user
    5 [============================]
Downloaded 18288 vCard(s)
Downloading vCard(s) from account user
   14 [============================]
Downloaded 20154 vCard(s)
Downloading vCard(s) from account user
   31 [============================]
Downloaded 22051 vCard(s)
Downloading vCard(s) from account user
    3 [============================]
Downloaded 23951 vCard(s)
Downloading vCard(s) from account user
    0 [>---------------------------]* Hostname carddav.example.com was found in DNS cache
*   Trying 13.95.212.214...
* TCP_NODELAY set
* Connected to carddav.example.com (13.95.212.214) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: CN=carddav.example.com
*  start date: Feb 19 18:33:45 2019 GMT
*  expire date: May 20 18:33:45 2019 GMT
*  subjectAltName: host "carddav.example.com" matched cert's "carddav.example.com"
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify ok.
> REPORT /addressbooks/xxxxxx/yyyyyy/ HTTP/1.1
Host: carddav.example.com
Depth: 1
User-Agent: GuzzleHttp/6.3.3 curl/7.52.1 PHP/7.2.15-1+0~20190209065123.16+stretch~1.gbp3ad8c0
Authorization: Basic bWhheWJhY2g6VGVzdDEyMzQ1OA==
Content-Length: 239

* upload completely sent off: 239 out of 239 bytes
< HTTP/1.1 404 Not Found
< Content-Length: 300
< Content-Type: application/xml; charset=utf-8
< Date: Tue, 26 Mar 2019 21:19:40 GMT
< Server: Apache/2.4.25 (Debian)
< Vary: Accept-Encoding
< X-Powered-By: PHP/7.2.4
< X-Sabre-Version: 3.2.2
< 
* Curl_http_done: called premature == 0
* Connection #0 to host carddav.example.com left intact

In RequestException.php line 113:

  Client error: `REPORT https://carddav.example.com/addressbooks/xxxxxx/yyyyyy/` resulted in a `404 Not Found` response:  
  <?xml version="1.0" encoding="utf-8"?>                                                                                                   
  <d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">                                                                                
    <s:sabredav-version>3 (truncated...)                                                                                                   

run [-i|--image] [-c|--config CONFIG]

(without the empty addressbook the down- and upload is fine)

andig commented 5 years ago

Kinda ugly because we cannot be sure if really the URL is not found or the server sends an empty response. Anyway it's ignored now and logged.

mokkin commented 5 years ago

:+1: works too:

Downloaded 1900 vCard(s)
Downloading vCard(s) from account user
    0 [>---------------------------]Ignoring empty response from carddav REPORT request
    0 [>---------------------------]
Downloaded 1900 vCard(s)
blacksenator commented 5 years ago

Runs like hell! 👍