khal icon indicating copy to clipboard operation
khal copied to clipboard

Import .ics file from (neo)mutt to khal

Open bepolymathe opened this issue 5 years ago • 13 comments

Hi,

I am a big neomutt user for the management of my emails. When emails arrive with an attached.ics calendar file (for an appointment), I can't pipe it in khal.

image

I do get a request to be included in the agenda but the operation is aborted.

image

I have the impression that there is a time zone problem. My config looks like this:

[locale]

dateformat = %d/%m/%Y
longdateformat = %d/%m/%Y
datetimeformat = %d/%m/%Y %H:%M
longdatetimeformat = %d/%m/%Y %H:%M
firstweekday = 0
weeknumbers = left 
#local_timezone = Europe/Paris
default_timezone = Europe/Paris 

If you have an idea to solve this problem, it would help me! Thank you.

bepolymathe avatar Mar 25 '19 17:03 bepolymathe

The issue about the timezone is "just" a warning and should not prevent khal from importing the event.

To me, it looks more like the interactive part is somehow not working (khal not getting any of your user input). Can you try khal import -a Perso --batch as the import command (or, of course, use any of your other calendars)?

geier avatar Mar 30 '19 16:03 geier

Hi @bepolymathe

I had the same issue, but I fixed it by passing the calendar.ics filepath instead of piping the contents. I have this line in my mailcap file:

# this did not work: 
# text/calendar; khal -a my_calendar import;
text/calendar; khal import -a my_calendar %s;

The -a flag is probably not necessary for you as it looks like you import into the default calendar.

matt-snider avatar Jun 28 '19 11:06 matt-snider

That's great, it works! How could I not have thought of that before? Thank you to you @matt-snider Have a good day.

bepolymathe avatar Jun 29 '19 07:06 bepolymathe

Just one more question. Do you have a solution to send an invitation to an event by combining khal and mutt (and only to receive)?

bepolymathe avatar Jun 29 '19 07:06 bepolymathe

@bepolymathe Glad I could help! :smile:

Currently I don't think there is a way to do this. (neo)mutt contains all the functionality to do it, but if I'm not mistaken, there are few pieces missing for khal to support it.

Attachments not sourced from the filesystem (i.e. output or created by other programs) is supported in (neo)mutt/mailcap via the new-mime command. This is normally bound to n when composing a message. The command used to create the attachment must be specified with the compose flag in the mailcap file.

So, for example, with the following line in your mailcap, run new-mime and set the prompt values to name: calendar.ics, Content-Type: text/calendar:

text/calendar; khal import -a my_calendar %s; compose=nvim %s;

This is just an example to show you the compose functionality. It will open the calendar.ics file in neovim for editing, but of course you aren't going to write it by hand. At the moment there is no way of exporting an event from khal and that is the issue. There is however #839. This would help, but there would still be the issues of finding the event. I think for this there would ideally be an interactive search command:

$ khal search --interactive --output ics

Then events could be filtered interactively, and the selected event could be exported to standard output as ics. (neo)mutt would then be able to save this as an attachment.

matt-snider avatar Jun 29 '19 11:06 matt-snider

Thank you for that clarification. That's interesting. What do you think of that @geier ?

bepolymathe avatar Jun 29 '19 11:06 bepolymathe

Hi @bepolymathe

I had the same issue, but I fixed it by passing the calendar.ics filepath instead of piping the contents. I have this line in my mailcap file:

# this did not work: 
# text/calendar; khal -a my_calendar import;
text/calendar; khal import -a my_calendar %s;

The -a flag is probably not necessary for you as it looks like you import into the default calendar.

Yes! I use the same hack, except I actally (ab)use the print action of mailcap, because I wrote a little parser for "view": https://git.madduck.net/etc/mutt.git/blob/HEAD:/.mutt/icalparser so that I can use it with aauto_view and get an overview first before importing.

madduck avatar Aug 15 '19 00:08 madduck

Thanks @madduck it's a good idea ;-)

bepolymathe avatar Aug 19 '19 06:08 bepolymathe

@madduck Nice solution! So after viewing, do you import with a separate keybinding or the regular (non-print) part of the mailcap entry? Could you post the relevant line of your mailcap file?

matt-snider avatar Aug 19 '19 09:08 matt-snider

Ah sorry it is of course in the same repo:

 text/calendar; ~/.mutt/icalparser; description=iCal details; copiousoutput; print=khal import --batch

matt-snider avatar Aug 19 '19 09:08 matt-snider

I just made a small bash script that prints the event in the ICS file, and then ask on which calendar to save this event. Cheers

if [[ -f $1 ]]; then
    resp=$(echo -e "yes\nno" | rofi -i -only-match -dmenu -p "Would you like to add the event:" -mesg "`khal printics $1 | tail -n +2`")

    if [[ "$resp" == "yes" ]]; then
        calendar=$(echo "`khal printcalendars`" | rofi -i -only-match -dmenu -p "Save to:")
        if [ -z "$calendar" ]; then
            exit;
        fi
        khal import -a "$calendar" --batch $1 && \
            dunstify "Calendar" "Even added";
    fi
fi

tdehaeze avatar Sep 01 '21 20:09 tdehaeze

@tdehaeze I don't know what dunstify is, and I have not installed rofi just now, but I am wondering: doesn't import already ask you where to import to?

Here is what I get with my "print" hack:

2021-09-03 20:00-2021-09-03 22:00 Foo appointment
Which calendar do you want to import to? (unique prefixes are fine)
foo(0), bar(1), madduck(2), baz(3), bam(4), faa(5) [madduck]: 

madduck avatar Sep 01 '21 21:09 madduck

dunstify is an alternative for notify-send: just a way to send a notification to the user. rofi is an alternative to dmenu which is a just a simple menu displayed to the user.

I was not aware to the fact that the import now asked you where to import the ics, this is great!

tdehaeze avatar Sep 01 '21 22:09 tdehaeze