1

The situation

I have the following ~/.fetchmailrc

poll pop.gmail.com       protocol pop3 user "[email protected]"      password "***"            ssl
mda "/usr/bin/procmail -d default -a foo@example-com"

poll pop.gmail.com       protocol pop3 user "[email protected]"      password "***"            ssl
mda "/usr/bin/procmail -d default -a bar@example-com"

So, I retrieve all the mails with fetchmail -v -m '/usr/bin/procmail -d %T'.

The problem

But the problem is all the accounts are retrieved.

The question

Is it possible from fetchmail command to ask for retrieving just one specific addresses’ mails?

1 Answer 1

2

You can give each account a different name and use the via option

eg

poll foo via pop.gmail.com ...

poll bar via pop.gmail.com ...

Now you can specify each one on the command line; fetchmail foo will only fetch mail for that one account.

I use this type of structure for Outlook:

poll outlook via imap-mail.outlook.com port 993
  proto IMAP
  user [email protected] is foo here
  fetchall
  password *****
  ssl

poll outlook2 via imap-mail.outlook.com port 993
  proto IMAP
  user [email protected] is bar here
  fetchall
  password *****
  ssl

This can be implemented as follows in zsh.

Alias and function to retrieve mail

alias retrieveallmails="fetchmail -v -m '/usr/bin/procmail -d %T'" # For all the accounts

function retrievemail()
{
    # For a specific account
    fetchmail $1 -v -m '/usr/bin/procmail -d %T'
}

Related completion

_retrievemail_complete() {
    local accounts
    accounts=($(fetchmail --configdump | sed -n 's/.*"pollname":"\(.*\)",/\1/p'))


    _arguments \
        '1: :->account' \
        '*:: :->arguments'

    case $state in
        (account)
            _describe 'accounts' accounts
            ;;
        (arguments)
            _files
            ;;
    esac
}

compdef _retrievemail_complete retrievemail
4
  • Just one more question. Is it possible to ask fetchmail to give a list of all accounts names? As example in your case, it could be someting like « outlook,outlook2… ».
    – fauve
    Commented Mar 31 at 14:15
  • It works with grep -E "poll\s+\w+\s+via" ~/.fetchmailrc | awk '{print $2}' | tr '\n' ', ' | sed 's/, $//' but it still hacky.
    – fauve
    Commented Mar 31 at 14:20
  • 1
    I don't know of an official way of doing it, but you could use --configdump and a simple sed; eg fetchmail --configdump | sed -n 's/.*"pollname":"\(.*\)",/\1/p'. The output is meant to be python parsable, so you could write a python script to report what you need. Commented Mar 31 at 18:28
  • Tangentially, perhaps see also useless use of grep | awk
    – tripleee
    Commented Apr 1 at 7:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .