]> git.rmz.io Git - dotfiles.git/commitdiff
isync: sync youtube parsing implementation with hactar
authorSamir Benmendil <me@rmz.io>
Wed, 28 Feb 2018 23:34:34 +0000 (23:34 +0000)
committerSamir Benmendil <me@rmz.io>
Wed, 28 Feb 2018 23:34:34 +0000 (23:34 +0000)
isync/post-sync.d/10-youtube

index 0b0363c25f0e514fcf2b72635f146d52e4212816..616a0eded3af195a1f9e97c9a2099108bf0cd750 100755 (executable)
@@ -1,5 +1,10 @@
 #!/usr/bin/env bash
 
 #!/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
 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
 
     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
 
 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
 
     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
 done
+
+# resync new yt_dst_mb
+mbsync -c "$config" gmail-$yt_src_mb gmail-$yt_dst_mb