goobook 3.5.4
Search your google contacts from the command-line or mutt.
Requires Python: <4.0,>=3.9
Keywords: abook, mutt, e-mail, gmail, google, address-book

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
GooBook -- Access your Google contacts from the command line.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

.. contents:: **Table of Contents**
   :depth: 1

About
=====

The purpose of GooBook is to make it possible to use your Google Contacts from
the command-line and from MUAs such as Mutt.
It can be used from Mutt the same way as abook.

Installation Instructions
=========================

pipx
----

This is the recommended way to install goobook for most users that don't
have it available in their distribution. You may first need to install pipx
itself, which should be available in your distribution. If not, you can
install it with pip; see: https://pypi.org/project/pipx/

Install goobook like this::

    $ pipx install goobook

This will install goobook as `~/.local/bin/goobook` (In a UNIX environment).


Configuration
=============

First you need to authenticate yourself:

- Go to https://developers.google.com/people/quickstart/python
- and click "Enable the People API"
- select a name (ex. GooBook)
- select desktop app and create
- click "Download JSON" and save the file to be used below

run::

    $ goobook authenticate -- client_secrets.json

and follow the instructions, this part is web based.

In case you've already been using goobook and have authenticated with Google
in the past there is no need to re-authenticate again. 


If the procedure above to get client secrets stops working this is an alternative way to do it:

- Go to the Google developer console  https://console.developers.google.com/
- Create a new project (drop down at the top of the screen) (you are free to use an existing one if you so prefer)
- Select the newly created project
- Go to OAuth consent screen from sidebar
- Select the interal user type if you can but most will only be able to select external.
- On next screen give it a name (ex. GooBook)
- select Add scope, click manually paste and write "https://www.googleapis.com/auth/contacts" inte the lower text box.
- and hit hit add and then save
- Go to Credentials from sidebar
- Click Create Credentials from top, then OAuth Client ID in the dropdown
- Choose Desktop app, enter any name you want, and hit create
- click "Download JSON" and save the file to be used below


To authenticate with Google you need a web browser installed. You will be directed to Google and finally
to http://localhost:8080. Make sure, no other service is bound to port tcp/8080 - otherwise the authentication
will fail. Make also sure, no local firewall prevents local access to port 8080.

If you do not have a browser installed locally and do not want to install one, you can perform the
authentication on another system on which goobook and a browser are installed. You will need the client_secrets.json
file and by performing the authentication create an oauth token file, which you must transfer back to your
original system. To easily find the oauth token file, create a configuration file in which you enter
the location and name of the file by::

    oauth_db_filename: ~/.goobook_auth.json
    
See details about the configuration file in the next section.

This configuration file gets included in the authenticate run like this::

    $ goobook ~/.config/goobookrc authenticate -- client_secrets.json


To get access too more settings you can create a configuration file::

    goobook config-template > ~/.config/goobookrc

It will look like this::

    # Use this template to create your ~/.goobookrc

    # "#" or ";" at the start of a line makes it a comment.

    [DEFAULT]
    # The following are optional, defaults are shown when not other specified.

    # This file is written by the oauth library, and should be kept secure,
    # it's like a password to your google contacts.
    # default is to place it in the XDG_DATA_HOME
    ;oauth_db_filename: ~/.goobook_auth.json

    ;cache_filename: ~/.goobook_cache   # default is in the XDG_CACHE_HOME
    ;cache_expiry_hours: 24
    ;filter_groupless_contacts: yes

    # New contacts will be added to this group in addition to "My Contacts"
    # Note that the group has to already exist on google or an error will occur.
    # One use for this is to add new contacts to an "Unsorted" group, which can
    # be sorted easier than all of "My Contacts".
    ;default_group:


Files
-----

GooBook is using three files, the optional config file that can be placed in
the ``XDG_CONFIG_HOME`` (``~/.config/goobookrc``) or in the home directory
(``~/.goobookrc``).

The authentication file that is created by running goobook authenticate in
``XDG_DATA_HOME`` (``~/.local/share/goobook_auth.json``) but can also be placed
in the home directory (``~/.goobook_auth.json``).

The contacts cache file that is created in ``XDG_CACHE_HOME``
(``~/.cache/goobook_cache``) but can also be placed in the home directory
(``~/.goobook_cache``).

Proxy settings
--------------

If you use a proxy you need to set the ``https_proxy`` environment variable.

Mutt
----

If you want to use goobook from mutt, set in your .muttrc file::

    set query_command="goobook query %s"

to query address book. (Normally bound to "Q" key.)

If you want to be able to use <tab> to complete email addresses instead of Ctrl-t add this::

    bind editor <Tab> complete-query

To add email addresses (with "a" key normally bound to create-alias command)::

    macro index,pager a "<pipe-message>goobook add<return>" "add the sender address to Google contacts"

If you want to add an email's sender to Contacts, press a while it's selected in the index or pager.

Usage
=====

To query your contacts::

    $ goobook query QUERY

The add command reads a email from STDIN and adds the From address to your Google contacts::

    $ goobook add

The cache is updated automatically according to the configuration but you can also force an update::

    $ goobook reload

For more commands see::

    $ goobook -h

and::

    $ goobook COMMAND -h

Links, Feedback and getting involved
====================================

- PyPI home: https://pypi.org/project/goobook/
- Code Repository: http://gitlab.com/goobook/goobook
- Issue tracker: https://gitlab.com/goobook/goobook/issues
-