Skip to content

Instantly share code, notes, and snippets.

@jb55
Last active August 6, 2017 08:01
Show Gist options
  • Select an option

  • Save jb55/1cdb1a78b12226968cb86a70fd7f51ef to your computer and use it in GitHub Desktop.

Select an option

Save jb55/1cdb1a78b12226968cb86a70fd7f51ef to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
get_mimetype(){
file --mime-type "$1" | sed 's/.*: //'
}
usage () {
printf "kindle-email <file.pdf>\n" 1>&2
exit 1
}
[ -z "$1" ] && usage
file="$1"
filename="$2"
from="jackbox55@gmail.com"
to="jb55@free.kindle.com"
subject="kindle-email test"
body="hi"
boundary="=-=-=-=-=-="
name="${filename:-$(basename "$file")}"
# Build headers
{
cat <<EOF
From: $from
To: $to
Subject: $subject
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="$boundary"
--${boundary}
Content-Type: text/plain; charset="UTF-8"
$body
EOF
mimetype=$(get_mimetype "$file")
cat <<EOF
--${boundary}
Content-Type: ${mimetype}; charset="UTF-8"; name="$name"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="$name"
EOF
base64 "$file"
printf '%s\n' "--${boundary}--"
} | sendmail --read-envelope-from -oi -t
#!/usr/bin/env bash
set -e
usage () {
printf "usage: $(basename $0) <title.txt>\n"
exit 1
}
[ -z "$1" ] && usage
tmp="$(mktemp)"
cat > "$tmp"
kindle-email "$tmp" "$1"
rm -f "$tmp"
#!/usr/bin/env bash
if [ -z "$1" ]; then
printf "usage: transcript <url>\n"
exit 1
fi
curl -sL "$1" \
| pandoc -f html -t plain \
| grep -v -e 'speaker headshot' -e '__ ' \
| cat -s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment