57 Commits

Author SHA1 Message Date
Lukas Fleischer
4eda8f6937 calcurse-caldav: drop misplaced filter argument
We cannot use the filter options when importing events.

This was noticed because the new calcurse argument parser catches
invalid input flag combinations and bails out.

Partly addresses GitHub issue #177.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2019-02-02 18:13:49 +01:00
Bram
6f22e99ad5 calcurse-caldav: fix authentication in debug mode
Objects are reference in python, ".pop" was modifying the original
dictionary and thus breaking authentication by removing auth headers.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-12-05 17:36:00 +01:00
Lukas Fleischer
c4960aaf93 calcurse-caldav: fix auth method check
Fixes a regression introduced in 6a6c711 (calcurse-caldav: fix basic
authentication, 2018-07-20).

Addresses GitHub issue #149.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-09-27 07:33:47 +02:00
Lukas Fleischer
8466717f06 calcurse-caldav: print executed commands in debug mode
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-25 08:54:03 +02:00
Lukas Fleischer
dd4d444c0c calcurse-caldav: print HTTP status codes in debug mode
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-21 05:51:35 +02:00
Dino Macri
6a6c7117de calcurse-caldav: fix basic authentication
Read whether basic authentication is used and add the credentials to
httplib2 when making a request.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-07-22 11:00:12 +02:00
Dino Macri
61dc7ab538 calcurse-caldav: add HTTP support
Introduce support for HTTP connections. Use "HTTPS" in the config file
to enable/disable (default is enabled). The option modifies the prefix
of the host name to "http://" when disabled, rather than always using
"https://" with no option to change.

httplib2 automatically handles URLs beginning with either http or https.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-07-22 10:58:33 +02:00
Lukas Fleischer
fda8c1a7e2 calcurse-caldav: remove authorization data from logs
The Authorization header contains the Base64-encoded user name and
password. Remove this information from debug logs, unless the user
explicitly requests to keep them by using the --debug-raw flag.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-23 17:59:50 +02:00
Lukas Fleischer
edc44d613b calcurse-caldav: Avoid corrupting the sync DB
When importing an iCal event via calcurse fails (i.e. does not return a
single object hash), do not write anything to the synchronization
database instead of blindly appending the entry, thereby potentially
corrupting the database.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-11-23 08:57:45 +01:00
Randy Ramos
9be2c106e6 calcurse-caldav: Read password from env variable
Add the option to read the basic authentication password from the
CALCURSE_CALDAV_PASSWORD environment variable.

Signed-off-by: Randy Ramos <rramos1295@gmail.com>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-11-10 16:00:49 +01:00
Lukas Fleischer
5b94be2246 Revert "calcurse-caldav: Add --password command line argument"
This reverts commit efd76a0d995292e48f5466fccada4901618f7d97.

Passing passwords as command line arguments is not a good idea, since
they may appear in process listings which are potentially visible to
other users logged into the system.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-11-08 21:54:53 +01:00
Satvik Sharma
b96e175192 calcurse-caldav: Add SyncFilter config option
The SyncFilter option filters the types of items synced from/to a CalDAV
server by making use of the --filter-type command line argument.

Signed-off-by: Satvik Sharma <satvik.sharma2@gmail.com>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-11-05 20:14:30 +01:00
Stefan Hagen
2fa1511898 calcurse-caldav: Use /usr/bin/env in the shebang
It is best practice to use `/usr/bin/env python3` instead of a hard
coded path. This will search for "python3" in the PATH environment
variable.

Most Linux distributions install python to "/usr/bin". Most BSDs to
"/usr/local/bin".

Signed-off-by: Stefan Hagen <github@textmail.me>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-11-05 19:16:07 +01:00
Randy Ramos
efd76a0d99 calcurse-caldav: Add --password command line argument
The "--password" argument overrides the corresponding option in the
config file.

Signed-off-by: Randy Ramos <rramos1295@gmail.com>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-19 06:26:31 +02:00
Randy Ramos
479e39fbb7 Add OAuth2 support for calcurse-caldav
OAuth2 authentication is completely optional. It is controlled by the
AuthMethod option in the config file. Other required options were
appended to config.sample.

Signed-off-by: Randy Ramos <rramos1295@gmail.com>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 22:35:36 +02:00
Randy Ramos
1e1d61585d Refactor calcurse-caldav to use httplib2
This will allow much more flexibility and less code duplication when
adding OAuth2 support. OAuth2 support will require this library as it is
a dependency of oauth2client. The documentation was updated to reflect
the new dependency.

Signed-off-by: Randy Ramos <rramos1295@gmail.com>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 22:35:36 +02:00
Randy Ramos
2d1e6e394d Change remote_wipe to delete objects individually
Certain CalDAV servers prohibit a single DELETE request to be sent to
the calendar collection root. Instead items need to be deleted one by
one.

Signed-off-by: Randy Ramos <rramos1295@gmail.com>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 22:35:36 +02:00
Randy Ramos
e943b0605f URL encode href before saving to sync.db
When pushing objects, the unencoded uri path would be saved into the
sync.db. The unencoded path and the encoded path from the server would
be seen as two different objects, causing both to be resynced
unnecessarily.

Signed-off-by: Randy Ramos <rramos1295@gmail.com>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 22:35:36 +02:00
Lukas Fleischer
e76b96c9ff calcurse-caldav: Specify depth in the initial request
For the initial calendar-query request, set the Depth header to 1. This
is required because according to RFC 4791, the depth value defaults to 0
if no header is specified.

Fixes GitHub issue #38.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-28 06:42:53 +02:00
Lukas Fleischer
e2086c426c calcurse-caldav: Use right diffs when synchronizing
Some parameters where swapped accidentally when reworking the diff
computation in c8d3d87 (calcurse-caldav: Compute diffs before
synchronizing, 2016-12-13) such that the synchronization functions were
working with incorrect diffs since that commit. Exchange the parameters
again to fix this.

Reported-by: Guillaume Laurès <guillaume@lauresfamily.fr>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-12-15 18:41:24 +01:00
Lukas Fleischer
6a80e156dd calcurse-caldav: Fix scrambled comment
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-12-13 18:47:38 +01:00
Lukas Fleischer
c8d3d87c84 calcurse-caldav: Compute diffs before synchronizing
Instead of computing the objects to push/pull on-demand, use a snapshot
of the synchronization database taken before the synchronization process
starts.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-12-13 18:32:12 +01:00
Lukas Fleischer
338e556f8d calcurse-caldav: Fix appointment imports
When importing an appointment from the server, make sure we store a hash
of the item in the sync DB, and not the serialized item itself.

Reported-by: Guillaume Laurès <guillaume@lauresfamily.fr>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-12-08 21:43:35 +01:00
Lukas Fleischer
e70b41bda9 calcurse-caldav: Add debug output for sync DB operations
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-12-08 16:22:00 +01:00
Lukas Fleischer
9fdb714aea calcurse-caldav: Avoid empty multiget
When there are no new objects to pull from the server, skip the import
routine instead of sending a query that requests zero items.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-12-08 16:22:00 +01:00
Lukas Fleischer
7b5602ae17 calcurse-caldav: Split object addition and removal
Instead of performing two synchronization steps (push/pull), split the
synchronization protocol into four steps:

1. Retrieve new objects from the server.
2. Delete local objects that no longer exist on the server.
3. Push new objects to the server.
4. Delete remote objects that no longer exist locally.

Each of the steps is performed by a separate function.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-12-08 16:22:00 +01:00
Lukas Fleischer
b6f95b380f calcurse-caldav: Encode the request body in UTF-8
When a string is passed to HTTPConnection.request(), it is automatically
ISO 8859-1 encoded. Therefore, since we already specify UTF-8 as
character set in the headers, we need to UTF-8 encode the request body
manually.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-06-18 10:30:30 +02:00
Lukas Fleischer
07954626c6 Support format strings when dumping imported items
In commit 3eae7ce (Add --list-imported command line option, 2016-01-12),
we added an option to print the hashes of imported items to stdout.
Extend this command line option such that it dumps the items using the
specified formatting strings. With the new behavior it is, for example,
easier to check items for import errors.

Also, rename the option from --list-imported to --dump-imported (it is
not part of any official release yet so we do not need to care about
backwards compatibility).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-11 18:33:57 +01:00
Lukas Fleischer
e5ba06ff5d calcurse-caldav: Add hook support
Introduce pre-sync and post-sync hooks which need to be located under
~/.calcurse/caldav/hooks/ and are executed before/after synchronization
with a CalDAV server.

Also, add an example post-sync hook and change the example post-save
hook such that it does not create tiny commits during synchronization.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-07 13:29:44 +01:00
Lukas Fleischer
812c6b1dd6 calcurse-caldav: Use -G and %(hash) to list hashes
Instead of reimplementing the code to generate object hashes in the
synchronization script, use format strings to print the hashes in grep
mode.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-05 19:12:12 +01:00
Lukas Fleischer
8bdf0c0b3b calcurse-caldav: Reword dry-run warning
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-02 08:16:08 +01:00
Lukas Fleischer
4671a02846 calcurse-caldav: Modernize format strings
Replace %-style string formatting with format().

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-01 19:11:27 +01:00
Lukas Fleischer
2cf7023b37 calcurse-caldav: Make synchronization more robust
In addition to storing ETag-hash tuples in the synchronization database,
also store the URI of each object. This makes the synchronization
process a bit more robust as we do not need to depend on ETags being
globally unique. It also allows us to detect conflicts which occur when
an object is modified locally and on the server at the same time.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-01 19:11:27 +01:00
Lukas Fleischer
cb85175524 calcurse-caldav: Fix issues reported by pylint
Add missing parameter to remote_query() and fix various style issues.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-01 19:05:27 +01:00
Lukas Fleischer
fb54b56cac calcurse-caldav: Fix version check
Since commit 41389ab (args.c: Revise help/usage/version output,
2016-01-28), the version string starts with "calcurse" (lowercase).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-28 19:30:29 +01:00
Lukas Fleischer
3dbfc7c1f5 calcurse-caldav: Use calendar-multiget to obtain ETag
Some CalDAV servers do not support calendar-query with a UID filter. Use
a calendar-multiget request to obtain the ETag of submitted objects
instead.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-26 17:33:49 +01:00
Lukas Fleischer
304ff81836 calcurse-caldav: Fix property filter
Fix a TypeError that occurred during string formatting by putting
parentheses around the multi-line string.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-26 15:31:50 +01:00
Lukas Fleischer
bfafec3ebf calcurse-caldav: Handle missing ETag gracefully
This was partly fixed by 475c341 (calcurse-caldav: Fix late retrieval of
ETag, 2016-01-25). However, the case where the server does not return
ETag after creating a new item still wasn't handled properly. This patch
hopefully addresses this and also makes sure that the ETag header is
matched case-insensitively.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 21:55:10 +01:00
Lukas Fleischer
4fff8ae4fe calcurse-caldav: Improve version check
Make sure that at least a current Git build of calcurse is used.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 21:02:30 +01:00
Lukas Fleischer
1a45713d1d calcurse-caldav: Print XML dump in debug mode only
In die_atnode(), we currently print a full dump of the XML node if
verbose mode is enabled. Change this behavior such that a dump is only
created in debug mode.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 20:17:53 +01:00
Lukas Fleischer
5e6a61eee9 calcurse-caldav: Fix comment on certificate checks
Clarify that ssl._create_unverified_context() was added in Python 3.4.3.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 19:59:38 +01:00
Lukas Fleischer
849459c63f calcurse-caldav: Support custom HTTP headers
Add support for specifying additional HTTP headers, such as the
User-Agent, in the configuration file.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 19:58:41 +01:00
Lukas Fleischer
475c341686 calcurse-caldav: Fix late retrieval of ETag
Fixes another regression introduced in badbd71 (calcurse-caldav: Add a
debug mode, 2016-01-23).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 13:08:17 +01:00
Lukas Fleischer
5abef70ee5 calcurse-caldav: Fix --init=keep-local
Fixes a regression introduced in badbd71 (calcurse-caldav: Add a debug
mode, 2016-01-23).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 10:55:32 +01:00
Lukas Fleischer
4a14103d38 calcurse-caldav: Fix duplicate Content-Type prefix
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 10:24:02 +01:00
Lukas Fleischer
2f82457bbc calcurse-caldav: Fix MIME type in requests
Specify application/xml in the Content-Type of requests except for PUT,
where we actually submit calendar data.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-25 09:49:24 +01:00
Lukas Fleischer
7e7d21722a calcurse-caldav: Show debug output before checking status
Make sure we print the headers and the body of a HTTP response in debug
mode, even if the HTTP status code indicates failure.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-24 13:44:27 +01:00
Lukas Fleischer
b9d80c3cf4 calcurse-caldav: Add XML declaration to requests
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-24 02:26:02 +01:00
Lukas Fleischer
84c0f8b5f8 calcurse-caldav: Prefix error messages with "error:"
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-23 16:58:01 +01:00
Lukas Fleischer
03e149d4e1 calcurse-caldav: Check response status
Bail out if the HTTP status code of any of the replies starts with a
digit other than 2.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-23 16:58:01 +01:00