aboutsummaryrefslogtreecommitdiff
path: root/getmails-alternative
blob: 8fd7ef2c24a35280464954da39b14224fe5023f1 (plain)
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
#!/bin/bash
#
# Simple wrapper around getmail to fetch from all active accounts.
# Alternative to the getmails(1) wrapper.
#
# Supports different config folders, including configurations stored
# in subfolders of $HOME/.config/getmail.
#
# See http://pyropus.ca/software/getmail/configuration.html#running-commandline-options
#

# Parameters
BASE_FOLDER="$HOME/.config/getmail"
CONFIG_FOLDER="${1:-$BASE_FOLDER}"
METADATA_FOLDER="$BASE_FOLDER/.metadata"
GETMAIL="/usr/bin/getmail"

# Check
if [ ! -d "$CONFIG_FOLDER" ]; then
  exit
fi

# Metadata is stored in a separate folder
mkdir -p $METADATA_FOLDER

# Dispatch, block version
#find $CONFIG_FOLDER -type f | grep -v 'oldmail-' | grep '@' | grep -v '.disabled$' | while read config; do
#  # Metadata is stored on each folder
#  folder="`dirname $config`"
#  $GETMAIL -g$folder --rcfile $config
#done

# Dispatch, old oneliner version
#ls -1 $CONFIG_FOLDER | grep -v '^oldmail-' | grep '@' | grep -v '.disabled$' | xargs echo | sed -e 's/ / --rcfile /g' | xargs $GETMAIL -g$CONFIG_FOLDER --rcfile

# Dispatch, new oneliner version, recursive and with data stored in the main folder
#find $CONFIG_FOLDER -type f | grep -v 'oldmail-' | grep '@' | grep -v '.disabled$' | xargs echo | sed -e 's/ / --rcfile /g' | xargs $GETMAIL -g$CONFIG_FOLDER --rcfile

# Dispatch, new oneliner version, recursive and with data stored in the metadata folder
find $CONFIG_FOLDER -type f | grep -v 'oldmail-' | grep '@' | grep -v '.disabled$' | xargs echo | sed -e 's/ / --rcfile /g' | xargs $GETMAIL -g$METADATA_FOLDER --rcfile