~soywod/pimalaya#212: 
Split messages printed by `himalaya message read` in some way

Please disregard #22 "mbox", it was written by mistake.

To make it easier to consume git patch emails via git am, I have written a script using himalaya.

Here is my current script:

email_ids=$(himalaya --output plain "${@}" | \
    tail -n +2 | \
    fzf --nth 3..5 \
        --preview="himalaya message read -p ${@} {1}" \
        --header-lines=1 \
        --multi | \
        awk -F' *| *' '/|/{print $1}')

(
    for email_id in $email_ids; do
        printf '\nFrom nobody Mon Sep 17 00:00:00 2001\n'
        himalaya --output plain message read -p --raw "${@}" $email_id
    done
) | git am -

This script fires up himalaya. It allows the user to select multiple git patch emails. It feeds the IDs of the emails to a for loop which prints <newline>From nobody Mon Sep 17 00:00:00 2001<newline> before each piece of mail is printed. Finally, it pipes all that output into git am -, so that the emails can be used to patch my git repo.

This script is slow since an IMAP connection is initiated for each retrieved email. I want a command that would enable me to retrieve all mails on the same connection, and which would print out the necessary From ... heading that makes it an "mbox file" suitable for git.

More generally, there is no way to tell the difference between one email and the next when printing out multiple emails in this way. Even if I specify --output json, the output is given as one single JSON string all run together.

I want the script I would like to write is this:

#!/bin/sh

himalaya --output plain "${@}" | \
    tail -n +2 | \
    fzf --nth 3..5 \
        --preview="himalaya message read -p ${@} {1}" \
        --header-lines=1 \
        --multi | \
        awk -F' *| *' '/|/{print $1}' | \
        xargs himalaya --output plain message read -p --raw "${@}" --mbox | \
        git am -

This script is much nicer since all the email patches are downloaded with a single imap connection, and thus runs faster.

I'd even be okay if we didn't support mbox format, but instead when I specified --output json that each email were in its own record, as in

#!/bin/sh

himalaya --output plain "${@}" | \
    tail -n +2 | \
    fzf --nth 3..5 \
        --preview="himalaya message read -p ${@} {1}" \
        --header-lines=1 \
        --multi | \
        awk -F' *| *' '/|/{print $1}' | \
        xargs himalaya --output json message read -p --raw "${@}" | \
        jq -r '.messages[] | '\nFrom nobody Mon Sep 17 00:00:00 2001\n\(.raw)'

In summary, I am asking for two distinct features:

  • When --output json is specified with himalaya message read, offer more than just a single string blob, but allow the messages to be consumed one by one.
  • Optionally (but preferably), implement an --mbox option allowing messages to be printed in git mbox format.
Status
REPORTED
Submitter
~skin
Assigned to
No-one
Submitted
a month ago
Updated
a month ago
Labels
No labels applied.

~soywod a month ago

In summary, I am asking for two distinct features:

  • When --output json is specified with himalaya message read, offer more than just a single string blob, but allow the messages to be consumed one by one.

An issue already exists for this purpose, see:

https://todo.sr.ht/~soywod/pimalaya/151

  • Optionally (but preferably), implement an --mbox option allowing messages to be printed in git mbox format.

Let's keep the issue for that purpose. What the date refers to? Now? The received date? The sent date (the same as the Date header)?

-- Regards Clément DOUIN https://soywod.me

Register here or Log in to comment, or comment via email.