Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix paging if sendmail command writes to file #20

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 94 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,123 @@
mutt-ical.py is meant as a simple way to display and reply to ical invitations from mutt.
This single-file Python script `mutt-ical.py` displays and replies to [Icalendar](https://tools.ietf.org/html/rfc5545) invitations (.ics files) from mutt.
It requires Mutt and Python with the [Vobject](https://github.com/py-vobject/vobject) Python package that can be installed with `pip install --user git+https://github.com/py-vobject/vobject`.

Warning
-------

This script was written during a few days in 2013 for Python 2. I currently do
not use it myself. There might be still issues with recent versions of Python 3.
Installing
----------

If this script does not work for you, please consider fixing it yourself. It
is just a few lines of code after all.
Copy the script into a folder in your `$PATH`, (or specify the `$PATH` in your `mailcap` and `muttrc` files).
Mark it executable by `chmod +x`.
We will assume that you copied it into `~/bin` so that its full path is `~/bin/mutt-ical.py`.

Pull requests are accepted, but please do not expect me to test them, they
will be merged after a quick and shallow review.
Initial Setup
-------------

You have been warned.
* To view the calendar entry in mutt by opening the calendar entry in the attachment view (usually opened by hitting `v` after having selected a mail in mutt), add to your `mailcap` file (found at '`~/.mailcap`, `/etc/mailcap` or `$mailcap_path` set in `muttrc`) the following lines:

Installing
----------
```muttrc
text/calendar; ~/bin/mutt-ical.py -D %s; copiousoutput
text/x-vcalendar; ~/bin/mutt-ical.py -D %s; copiousoutput
application/ics; ~/bin/mutt-ical.py -D %s; copiousoutput
```

* Copy it into somewhere in your PATH, (or you can specify the PATH in your .mailcap)
* Edit your mailcap (~/.mailcap or /etc/mailcap) to have the following line:
- To view the calendar entry by opening a selected a mail in mutt, add to your .muttrc the following lines:

```muttrc
auto_view text/calendar text/x-vcalendar application/ics text/plain text/html
alternative_order text/calendar text/x-vcalendar application/ics text/plain text/html
```
# for replying
text/calendar; <path>mutt-ical.py -i -e "user@domain.tld" %s
application/ics; <path>mutt-ical.py -i -e "user@domain.tld" %s
# for auto-view
text/calendar; <path>mutt-ical.py -D %s; copiousoutput
application/ics; <path>mutt-ical.py -D %s; copiousoutput
```
(Don't forget to add your email address)

* if you want to use auto view in the pager, use something like the following in .muttrc
(just an example, configure text/plain and text/html at your own discretion)
Here the second line ensures that the calendar entry is displayed before the message text.

```
auto_view text/calendar text/plain text/html
alternative_order text/calendar text/plain text/html
- To answer a calendar entry by pressing `a` in the attachment view (usually opened by hitting `v` after having selected a mail in mutt), add to your .muttrc a line such as

```muttrc
macro attach a \
"<pipe-entry>iconv -c --to-code=UTF-8 > ~/.cache/mutt.ics<enter><shell-escape>~/bin/mutt-ical.py -i -e your.email@address -s 'msmtp --account=work' ~/.cache/mutt.ics<enter>" \
"answer appointment request"
```

Here you need to customize the email address `your.email@address` and the send command `msmtp --account=work`.
If `-s` is not set, the Mutt setting `$sendmail` will be used.

OSX Users
---------
- To optionally open the Icalendar in your favorite desktop calendar application, such as `Ical`, run `xdg-open ~/.cache/mutt.ics` (on Linux, respectively `open ~/.cache/mutt.ics` on Mac OS) after the `mutt-ical.py` command, for example

* For added fun on OSX, you can extend it to the following, to get iCal to open it nicely too (iCal does not care for mime types it seems):
```
text/calendar; mv %s %s.ics && open %s.ics && <path>mutt-ical.py -i -e "user@domain.tld" %s.ics && rm %s.ics
```muttrc
macro attach a \
"<pipe-entry>iconv -c --to-code=UTF-8 > ~/.cache/mutt.ics<enter><shell-escape>~/bin/mutt-ical.py -i -e your.email@address -s 'msmtp --account=work' ~/.cache/mutt.ics && xdg-open ~/.cache/mutt.ics<enter>" \
"reply to appointment request"
```
* You can force iCal to stop trying to send mail on your behalf by replacing
the file `/Applications/iCal.app/Contents/Resources/Scripts/Mail.scpt` with your
own ActionScript. I went with the following: `error number -128`
Which tells it that the user cancelled the action.

* Open AppleScript Editor, paste the code from above into a new script, then save it.
* Move the old script `/Applications/iCal.app/Contents/Resources/Scripts/Mail.scpt` just in case you want to re-enable the functionality.
* Copy your new script into place.

Usage
-----

If you configure auto_view (see above), the description should be visible in
If you configure auto_view (as above), then the description should be visible in
the pager.
(Otherwise view the attachements (usually by hitting 'v'), select and open the `Icalendar` entry.)
To answer, just open the `Icalendar` file from mutt:

To reply, just open the ical file from mutt:
* View the attachements (usually 'v')
* Select the text/calendar entry
* Invoke the mailcap entry (usually 'm')
* Choose your reply
* Hit 'a'
* Choose your answer


Documentation
-------------

The script supports the following options: `-i`, `-a`, `-d`, `-t`, `-D`, and `-s`. The `-e` option followed by an email address and the path to an `.ics` file are required.
If the `-D` option is used, the script will display the event details and terminate without sending any replies.
The `-i`, `-a`, `-d`, and `-t` options are mutually exclusive;
the last one specified determines the response type sent.
By default, the script will use Mutt's sendmail setting to send the answer, unless the `-s` option is used to override it.

```sh
-e <your.email@address>
Specify the email address to send the answer from. This should be the email address that received the invitation.

-i
Interactive mode. Prompt for user input to accept, decline, or tentatively accept the invitation.

-a
Accept the invitation automatically without prompting.

-d
Decline the invitation automatically without prompting.

-t
Tentatively accept the invitation automatically without prompting.

-D
Display only. Show the event details but do not send any answer.

-s <sendmail command>
Specify the sendmail command to use for sending the email. If not set, the default Mutt setting will be used.

filename.ics
The .ics file to be processed. This should be the invitation file received.

Usage:

mutt-ical.py [OPTIONS] -e your@email.address filename.ics
```

Make sure to replace the placeholder `your.email@address` with your actual email address and `filename.ics` with the path to the .ics file when running the script.

Hints
-----

Mac OS X iCal Users can force iCal to stop trying to send mail on your behalf by replacing
the file `/Applications/iCal.app/Contents/Resources/Scripts/Mail.scpt` with your
own ActionScript. Martin Sander went with the following: `error number -128`
Which tells it that the user cancelled the action.

An old sendmail wrapper is also included, but since mutt's SMTP support has now improved, rather configure your SMTP settings through mutt's config. The wrapper is kept in case someone finds it useful. However, the get_mutt_command function will need the relevant code uncommented to use it.
* Open AppleScript Editor, paste the code from above into a new script, then save it.
* Move the old script `/Applications/iCal.app/Contents/Resources/Scripts/Mail.scpt` just in case you want to re-enable the functionality.
* Copy your new script into place.

Requirements
Inspiration
------------

mutt, python, bash, vobject:
http://vobject.skyhouseconsulting.com/ or 'easy_install vobject'
This forks [Martin Sander's](https://github.com/marvinthepa/mutt-ical/) whose (MIT) license restrictions apply, and which was inspired by
[accept.py](http://weirdzone.ru/~veider/accept.py) and [Rubyforge.org Samples](http://vpim.rubyforge.org/files/samples/README_mutt.html).

Inspired by:
* http://weirdzone.ru/~veider/accept.py
* http://vpim.rubyforge.org/files/samples/README_mutt.html
Loading