"Fossies" - the Fresh Open Source Software Archive 
Member "getmail-5.16/getmail_maildir" (31 Oct 2021, 2687 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_maildir":
5.15_vs_5.16.
1 #!/usr/bin/env python2
2 '''getmail_maildir
3 Reads a message from stdin and delivers it to a maildir 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
29 from getmailcore.message import Message
30 from getmailcore.utilities import *
31 from getmailcore.exceptions import *
32
33 hostname = localhostname()
34
35 verbose = False
36 path = None
37 for arg in sys.argv[1:]:
38 if arg in ('-h', '--help'):
39 sys.stdout.write('Usage: %s maildirpath\n' % sys.argv[0])
40 raise SystemExit
41 elif arg in ('-v', '--verbose'):
42 verbose = True
43 elif not path:
44 path = arg
45 else:
46 raise SystemExit('Error: maildir path specified twice (was %s, now %s)'
47 % (path, arg))
48
49 if os.name == 'posix' and (os.geteuid() == 0 or os.getegid() == 0):
50 raise SystemExit('Error: do not run this program as user root')
51
52 if not (path and (path.startswith('.') or path.startswith('/'))
53 and path.endswith('/')):
54 raise SystemExit('Error: maildir must start with . or / and end with /')
55
56 if not is_maildir(path):
57 raise SystemExit('Error: %s is not a maildir' % path)
58
59 msg = Message(fromfile=sys.stdin)
60 if os.environ.has_key('SENDER'):
61 msg.sender = os.environ['SENDER']
62 if os.environ.has_key('RECIPIENT'):
63 msg.recipient = os.environ['RECIPIENT']
64
65 try:
66 d = deliver_maildir(path, msg.flatten(True, False), hostname)
67 except getmailDeliveryError, o:
68 raise SystemExit('Error: delivery error delivering to maildir %s (%s)'
69 % (path, o))
70 except StandardError, o:
71 raise SystemExit('Error: other error delivering to maildir %s (%s)'
72 % (path, o))
73
74 if verbose:
75 sys.stdout.write('Delivered to maildir %s\n' % path)