From 3c44ccc1e65be9d3c16d6bda5f677aa16606b3cd Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Wed, 28 Feb 2018 23:34:34 +0000 Subject: [PATCH] isync: sync youtube parsing implementation with hactar --- isync/post-sync.d/10-youtube | 64 ++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/isync/post-sync.d/10-youtube b/isync/post-sync.d/10-youtube index 0b0363c..616a0ed 100755 --- a/isync/post-sync.d/10-youtube +++ b/isync/post-sync.d/10-youtube @@ -1,5 +1,10 @@ #!/usr/bin/env bash +maildir="$MAILDIR/gmail" +yt_src_mb=youtube-orig +yt_dst_mb=youtube +yt_parser=$dir/parse-mail.py + if [[ $mbsync_errno -ne 0 ]]; then echo "mbsync failed, ignoring post-sync commands." >&2 exit @@ -12,46 +17,33 @@ if [[ "$mbsync_args" != "gmail" ]]; then exit fi -yt_src_mb=youtube-orig -yt_dst_mb=youtube -yt_parser=$dir/parse-mail.py -maildirs=( $(sed -nr 's/^Path\s*(.*)$/\1/p' $config) ) +shopt -s extglob +shopt -s nullglob -if [[ -z $maildirs ]]; then - echo "Could not extract 'Path' from 'MaildirStore' in '$config'" >&2 - exit 1 +if [[ ! -d "$maildir/$yt_src_mb" ]]; then + echo "No mailbox at '$maildir/$yt_src_mb'" + exit fi -shopt -s extglob -shopt -s nullglob -for maildir in "${maildirs[@]}"; do - # expand tilde - maildir=${maildir/#~/$HOME} +for mail in "$maildir"/$yt_src_mb/new/* ; do + mangled_mail=${mail/$yt_src_mb/$yt_dst_mb} + # remove UID for mbsync to regenerate it + mangled_mail="${mangled_mail/,U=+([0-9])}" + + echo -n "Parsing new message '$(basename "$mail")'..." + $yt_parser <"$mail" >"$mangled_mail" - if [[ ! -d "$maildir/$yt_src_mb" ]]; then - echo "No mailbox at '$maildir/$yt_src_mb'" - continue + if [[ $? -eq 0 ]]; then + echo " Success." + else + echo " Failure! Copying message as is." + cp "$mail" "$mangled_mail" fi - for mail in "$maildir"/$yt_src_mb/new/* ; do - mangled_mail=${mail/$yt_src_mb/$yt_dst_mb} - # remove UID for mbsync to regenerate it - mangled_mail="${mangled_mail/,U=+([0-9])}" - - echo -n "Parsing new message '$(basename "$mail")'..." - $yt_parser <"$mail" >"$mangled_mail" - - if [[ $? -eq 0 ]]; then - echo " Success." - else - echo " Failure! Copying message as is." - cp "$mail" "$mangled_mail" - fi - - # sync {a,m}time - touch --reference "$mail" "$mangled_mail" - mv "$mail" "${mail/new/cur}S" - done - # resync new yt_dst_mb - mbsync -c "$config" gmail-$yt_src_mb gmail-$yt_dst_mb + # sync {a,m}time + touch --reference "$mail" "$mangled_mail" + mv "$mail" "${mail/new/cur}S" done + +# resync new yt_dst_mb +mbsync -c "$config" gmail-$yt_src_mb gmail-$yt_dst_mb -- 2.48.1