forked from kura/python-procmail-forwarding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforward.py
More file actions
40 lines (31 loc) · 884 Bytes
/
forward.py
File metadata and controls
40 lines (31 loc) · 884 Bytes
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
#!/usr/bin/env python
"""Script for getting emails from procmail and forwarding their
from and subject to another address
Used for bouncing mails to a PUSH server without sending the whole
email.
"""
import sys
import re
import smtplib
__author__ = "Kura"
__copyright__ = "None"
__credits__ = ["Kura"]
__license__ = "Free"
__version__ = "0.1 Beta"
__maintainer__ = "Kura"
__email__ = "kura@deviling.net"
__status__ = "Beta/Test"
content = sys.stdin.read()
from_regex = re.compile(r"[^.]From:(\s)?(?P<from>.*)")
subject_regex = re.compile(r"[^.]Subject:(\s)?(?P<subject>.*)")
to_addr = "XXX@YYY.ZZZ"
from_addr = from_regex.search(content).group('from')
subject = subject_regex.search(content).group('subject')
message = """From: %s
To: %s
Subject: %s
""" % (from_addr, to_addr, subject)
smtp = smtplib.SMTP("localhost")
smtp.sendmail(from_addr, to_addr, message)
smtp.quit()
#