commit 8754afa41dd37bd4c025bc0391fa2f0f2506fc9d
Author: Antoine Amarilli <a3nm@a3nm.net>
Date: Fri, 9 Dec 2016 17:36:29 +0100
uncommitted changes
Diffstat:
replytime.sh | | | 79 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
stat.sh | | | 9 | +++++++++ |
2 files changed, 88 insertions(+), 0 deletions(-)
diff --git a/replytime.sh b/replytime.sh
@@ -0,0 +1,79 @@
+#!/bin/bash
+
+MYEMAILS=$(grep -E '^other_email|^primary_email' ~/.notmuch-config | cut -d '=' -f2 | paste -sd ";")
+MYEMAILSOR=$(echo "$MYEMAILS" | sed 's/^/from:/g' | sed 's/;/ or from:/g')
+MYEMAILSPIPE=$(echo "$MYEMAILS" | sed 's/;/|/g')
+
+echo "notmuch request $MYEMAILSOR"
+NUM=$(notmuch count "$MYEMAILSOR")
+echo "will process $NUM messages"
+# start with older messages as they are more fragile :)
+notmuch search --sort=oldest-first --output=files "$MYEMAILSOR" | pv -l -s$NUM |
+while read l
+do
+ IRT=$(formail -XIn-Reply-To: -c < "$l" | cut -d':' -f2-)
+ ID=$(formail -XMessage-Id: -c < "$l" | cut -d':' -f2- |
+ tr -d '<>' | sed 's/^\s*//;s/\s*$//')
+ DATE=$(formail -XDate: -c < "$l" | cut -d':' -f2-)
+ if [ -z "$DATE" ]
+ then
+ # i have old sent mails from a crappy import with no "Date" field...
+ continue
+ fi
+ TIME=$(date -d"$DATE" +%s)
+ if [ -z "$TIME" ]
+ then
+ if [ -n "$ID" ]
+ then
+ # this is probably a newsgroup message, do not warn
+ continue
+ fi
+ # date was here but could not extract, means I have failed
+ echo -n "Could not extract date" >> "$2"
+ echo -n " from own message <$ID> file <$l>:" >> "$2"
+ echo " extracted $DATE $TIME" >> "$2"
+ continue
+ fi
+ # there might be multiple in-reply-to's
+ echo "$IRT" |cut -d ':' -f2- | sed 's/\s/\n/g' | grep -v '^ *$' | tr -d '<>' |
+ while read m;
+ do
+ SUFF=""
+ FILE=$(notmuch search --output=files --duplicate=1 "id:$m")
+ if [ -z "$FILE" ]
+ then
+ # replying to an email I don't have? weird
+ echo -n "Could not find original message" >> "$2"
+ echo -n " for own message <$ID> file <$l>:" >> "$2"
+ echo " looked for $m" >> "$2"
+ continue
+ fi
+ # exclude replies to own mail
+ if formail -XFrom: -c <"$FILE" | grep -viE "$MYEMAILSPIPE" > /dev/null
+ then
+ DATE2=$(formail -XDelivery-Date: -c <"$FILE" | cut -d':' -f2-)
+ TIME2=$(date -d"$DATE2" +%s 2>/dev/null)
+ # need a lazy OR
+ # time must be defined and not be later than my reply...
+ if [ -z "$TIME2" ] || [ "$TIME2" -gt "$TIME" ]
+ then
+ # keep info that this was not delivery date
+ SUFF="(*)"
+ DATE2=$(formail -XDate: -c <"$FILE" | cut -d':' -f2-)
+ TIME2=$(date -d"$DATE2" +%s 2>/dev/null)
+ fi
+ if [ -z "$TIME2" ] || [ "$TIME2" -gt "$TIME" ]
+ then
+ # still no extracted time
+ echo -n "Could not extract sensible date" >> "$2"
+ echo -n " from foreign message <$m> file <$FILE>:" >> "$2"
+ echo -n " extracted $DATE2 converted $TIME2" >> "$2"
+ echo " but my converted time $TIME" >> "$2"
+ continue
+ fi
+ # save the line
+ echo "$m $TIME2 $ID $TIME $SUFF" >> "$1"
+ fi
+ done
+done
+
diff --git a/stat.sh b/stat.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+sort -k1,1 -k4n |
+ awk '!a[$1]++' |
+ awk '{print $1, $4 - $2}' |
+ sort -k2,2n |
+ cut -d ' ' -f2 |
+ sort -n | awk '{printf ("%d\n", log($1)/log(2))}' | sort -n | uniq -c |
+ awk '{print $1, exp(log(2)*$2)}' | nl -b a