"Fossies" - the Fresh Open Source Software Archive 
Member "getmail-5.16/getmail_mbox" (31 Oct 2021, 2892 Bytes) of package /linux/misc/getmail-5.16.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the latest
Fossies "Diffs" side-by-side code changes report for "getmail_mbox":
5.15_vs_5.16.
1 #!/usr/bin/env python2
2 '''getmail_mbox
3 Reads a message from stdin and delivers it to an mbox file specified as
4 a commandline argument. Expects the envelope sender address to be in the
5 environment variable SENDER.
6 Copyright (C) 2001-2021 Charles Cazabon <charlesc-getmail @ pyropus.ca>
7
8 This program is free software; you can redistribute it and/or modify it under
9 the terms of version 2 (only) of the GNU General Public License as published by
10 the Free Software Foundation. A copy of this license should be included in the
11 file COPYING.
12
13 This program is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 PARTICULAR PURPOSE. See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along with
18 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
19 Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 '''
21 import sys
22
23 if sys.hexversion < 0x2030300:
24 raise ImportError('getmail version 5 requires Python version 2.3.3 '
25 'or later')
26
27 import os
28 import email
29 from getmailcore.exceptions import *
30 from getmailcore.message import Message
31 from getmailcore import logging, constants, destinations
32
33 verbose = False
34 path = None
35 for arg in sys.argv[1:]:
36 if arg in ('-h', '--help'):
37 sys.stdout.write('Usage: %s mboxpath\n' % sys.argv[0])
38 raise SystemExit
39 elif arg in ('-v', '--verbose'):
40 verbose = True
41 elif not path:
42 path = arg
43 else:
44 raise SystemExit('Error: mbox path specified twice (was %s, now %s)'
45 % (path, arg))
46
47 if os.name == 'posix' and (os.geteuid() == 0 or os.getegid() == 0):
48 raise SystemExit('Error: do not run this program as user root')
49
50 logger = logging.Logger()
51 logger.addhandler(sys.stderr, constants.WARNING)
52 if verbose:
53 logger.addhandler(sys.stdout, constants.INFO, constants.INFO)
54
55 if not (path and (path.startswith('.') or path.startswith('/'))
56 and not path.endswith('/')):
57 raise SystemExit('Error: mbox must start with . or / and not end with /')
58
59 if os.path.exists(path) and not os.path.isfile(path):
60 raise SystemExit('Error: %s is not an mbox' % path)
61
62 msg = Message(fromfile=sys.stdin)
63 if os.environ.has_key('SENDER'):
64 msg.sender = os.environ['SENDER']
65 if os.environ.has_key('RECIPIENT'):
66 msg.recipient = os.environ['RECIPIENT']
67
68 try:
69 dest = destinations.Mboxrd(path=path)
70 d = dest.deliver_message(msg, True, False)
71 except getmailDeliveryError, o:
72 raise SystemExit('Error: delivery error delivering to mboxrd %s (%s)'
73 % (path, o))
74 except StandardError, o:
75 raise SystemExit('Error: other error delivering to mboxrd %s (%s)'
76 % (path, o))
77
78 if verbose:
79 sys.stdout.write('Delivered to mboxrd %s\n' % path)