File: getmail_mbox

package info (click to toggle)
getmail 3.2.5-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 428 kB
  • ctags: 161
  • sloc: python: 1,777; sh: 31; makefile: 12
file content (47 lines) | stat: -rwxr-xr-x 1,698 bytes parent folder | download
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
#!/usr/bin/python
'''getmail_mbox
Reads a message from stdin and delivers it to an mbox file specified as
a commandline argument.  Expects the envelope sender address to be in the
environment variable SENDER.
Copyright (C) 2001-2003 Charles Cazabon <getmail @ discworld.dyndns.org>

This program is free software; you can redistribute it and/or
modify it under the terms of version 2 of the GNU General Public License
as published by the Free Software Foundation.  A copy of this license should
be included in the file COPYING.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

'''
import sys
import os

sys.path.insert(1, '/usr/lib/getmail')
import getmail_mbox

sender = os.environ.get('SENDER', 'unknown')
mbox = None
quiet = 0
for arg in sys.argv[1:]:
    if arg in ('-q', '--quiet'):
        quiet = 1
    elif not mbox:
        mbox = arg
    else:
        sys.stderr.write('Error: mbox specified twice (was %s, now %s)\n' % (mbox, arg))
        raise SystemExit(1)
if not mbox:
    sys.stderr.write('Error: no mbox specified\n')
try:
    getmail_mbox.deliver_mbox(mbox, sys.stdin.read(), sender, quiet)
except getmail_mbox.DeliveryException, error:
    sys.stderr.write('Error delivering to mbox "%s" (%s)\n' % (mbox, error))
    raise SystemExit(1)
sys.stdout.write('Delivered to mbox "%s"\n' % mbox)