aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/mail/save_context.sh
blob: 5cc94005c94bdb50810488b037eb0609ba19304f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#! /bin/bash

# Restore mail in variable
MAIL="$(cat)"

# Only execute the following script when mail receiver is log@topo.tw
grep -qE "^X-Original-To: .*context@topo.tw[>]?$" <<<"$MAIL" || exit 0
# A little hacky way to check if mail is sent from me
sed -nE '/^Received: /p;/^$/q' <<<"$(MAIL)" | wc -l | xargs -i test {} -lt 2 || exit 0

# Write a log
cat <<<"$MAIL"  >>~/Downloads/context.log

# Save content to log file of current week
/home/pham/helper/bin/task/context $(awk -v RS= 'NR>1' <<<"$MAIL")

/home/pham/helper/bin/task/context | cut -f1-3 | /usr/bin/mail -r context@topo.tw -C "chat-version: 1.0" -s no-reply pham

cd ~/log && git add context/* && git commit -m 'Append time by mail'