-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheml2md.sh
More file actions
executable file
·50 lines (39 loc) · 1000 Bytes
/
Copy patheml2md.sh
File metadata and controls
executable file
·50 lines (39 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
#
# Time-stamp: <Monday 2025-08-04 11:05:05 Jess Moore>
#
# Uses pandoc to convert eml file to markdown
#
# Usage: eml2md.sh [args...]
function usage() {
echo "Usage: eml2md.sh file"
echo ""
echo "Description: Uses pandoc to convert eml file to markdown."
echo ""
echo "Arguments:"
echo " file: Filename of .eml file."
echo ""
exit 1 # Exit with a non-zero status to indicate an error
}
if [[ $# -eq 0 || $* == *"help "* || $* == *"-h"* ]]; then
usage
fi
FILE=$1
BASENAME=${FILE%.*}
# Convert file
pandoc -f html -o "${BASENAME}".md "${BASENAME}".eml
CONTENT=$(cat "${BASENAME}".md)
# Remove content before " To: "
START_CONTENT=' To: '
RES="To: "${CONTENT#*"$START_CONTENT"}
# Remove backslashes
RES="${RES//\\/}"
# Remove div tags
RES="${RES//<div>/}"
RES="${RES//<\/div>/}"
# Remove ending https line
END_CONTENT='![](https:'
RES="${RES%"$END_CONTENT"*}"
# Write cleaned content to file
echo "$RES" > "${BASENAME}".md
ls -l "$BASENAME"*