-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.sh
43 lines (34 loc) · 1.32 KB
/
mail.sh
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
#!/bin/bash
####### VARIABLES BEGIN #######
# Define the variables in this section
## Define the directory where attachments will be saved
SAVE_DIR="/root/sync/sync"
## Define the command to upload PDFs to reMarkable
RMAPI_CMD="RMAPI_CONFIG=/root/.config/rmapi/rmapi.conf RMAPI_HOST=https://remarkable.mydomain.com /root/go/bin/rmapi -ni put"
####### VARIABLES END #######
####### SCRIPT BEGIN #######
# Write date and time to log
echo $(date +'%Y-%m-%d %H:%M:%S'): Script starting.
# Sync emails using offlineimap
offlineimap -o
# Extract all attachments
if [ ! -d "/tmp/munpack-extracted-files" ]
then
echo "Directory doesn't exist, creating it."
mkdir "/tmp/munpack-extracted-files"
else
echo "Directory already exists."
fi
# The directory "/root/Maildir/" is what you have selected in the .offlineimaprc configuration file. Make sure it matches
munpack -f -t -C /tmp/munpack-extracted-files /root/Maildir/INBOX/new/*
# Loop through all files in the directory
for fname in /tmp/munpack-extracted-files/*.pdf
do
mv "$fname" "$fname"-$RANDOM.pdf
done
# Clean-up files
mv /tmp/munpack-extracted-files/*.pdf /root/sync/sync/
# The directory "/root/Maildir/" is what you have selected in the .offlineimaprc configuration file. Make sure it matches
rm Maildir/INBOX/new/*
rm /tmp/munpack-extracted-files/part*
####### SCRIPT END #######