rss2email: split massive package into modules
[rss2email.git] / rss2email / config.py
1 # Copyright
2
3 """Per-user rss2email configuration
4 """
5
6 import collections as _collections
7 import configparser as _configparser
8
9 import html2text as _html2text
10
11
12 class Config (_configparser.ConfigParser):
13     def __init__(self, **kwargs):
14         super(Config, self).__init__(dict_type=_collections.OrderedDict)
15
16     def _setup(self, section='DEFAULT'):
17         _html2text.UNICODE_SNOB = self.getboolean(
18             section, 'unicode-snob', fallback=False)
19         _html2text.LINKS_EACH_PARAGRAPH = self.getboolean(
20             section, 'links-after-each-paragaph', fallback=False)
21         _html2text.BODY_WIDTH = self.getint(section, 'body-width', fallback=0)
22
23
24 CONFIG = Config()
25
26 # setup defaults for feeds that don't customize
27 CONFIG['DEFAULT'] = _collections.OrderedDict((
28         ### Addressing
29         # The email address messages are from by default
30         ('from', 'bozo@dev.null.invalid'),
31         # True: Only use the 'from' address.
32         # False: Use the email address specified by the feed, when possible.
33         ('force-from', str(False)),
34         # True: Use the publisher's email if you can't find the author's.
35         # False: Just use the 'from' email instead.
36         ('use-publisher-email', str(False)),
37         # Only use the feed email address rather than friendly name
38         # plus email address
39         ('friendly-name', str(True)),
40         # Set this to default To email addresses.
41         ('to', ''),
42
43         ### Fetching
44         # Set an HTTP proxy (e.g. 'http://your.proxy.here:8080/')
45         ('proxy', ''),
46         # Set the timeout (in seconds) for feed server response
47         ('feed-timeout', str(60)),
48
49         ### Processing
50         # True: Fetch, process, and email feeds.
51         # False: Don't fetch, process, or email feeds
52         ('active', str(True)),
53         # True: Generate Date header based on item's date, when possible.
54         # False: Generate Date header based on time sent.
55         ('date-header', str(False)),
56         # A comma-delimited list of some combination of
57         # ('issued', 'created', 'modified', 'expired')
58         # expressing ordered list of preference in dates
59         # to use for the Date header of the email.
60         ('date-header-order', 'modified, issued, created, expired'),
61         # Set this to add bonus headers to all emails
62         # Example: bonus-header = 'Approved: joe@bob.org'
63         ('bonus-header', ''),
64         # True: Receive one email per post.
65         # False: Receive an email every time a post changes.
66         ('trust-guid', str(True)),
67         # To most correctly encode emails with international
68         # characters, we iterate through the list below and use the
69         # first character set that works Eventually (and
70         # theoretically) UTF-8 is our catch-all failsafe.
71         ('encodings', 'US-ASCII, BIG5, ISO-2022-JP, ISO-8859-1, UTF-8'),
72         ## HTML conversion
73         # True: Send text/html messages when possible.
74         # False: Convert HTML to plain text.
75         ('html-mail', str(False)),
76         # Optional CSS styling
77         ('use-css', str(False)),
78         ('css', (
79                 'h1 {\n'
80                 '  font: 18pt Georgia, "Times New Roman";\n'
81                 '}\n'
82                 'body {\n'
83                 '  font: 12pt Arial;\n'
84                 '}\n'
85                 'a:link {\n'
86                 '  font: 12pt Arial;\n'
87                 '  font-weight: bold;\n'
88                 '  color: #0000cc;\n'
89                 '}\n'
90                 'blockquote {\n'
91                 '  font-family: monospace;\n'
92                 '}\n'
93                 '.header {\n'
94                 '  background: #e0ecff;\n'
95                 '  border-bottom: solid 4px #c3d9ff;\n'
96                 '  padding: 5px;\n'
97                 '  margin-top: 0px;\n'
98                 '  color: red;\n'
99                 '}\n'
100                 '.header a {\n'
101                 '  font-size: 20px;\n'
102                 '  text-decoration: none;\n'
103                 '}\n'
104                 '.footer {\n'
105                 '  background: #c3d9ff;\n'
106                 '  border-top: solid 4px #c3d9ff;\n'
107                 '  padding: 5px;\n'
108                 '  margin-bottom: 0px;\n'
109                 '}\n'
110                 '#entry {\n'
111                 '  border: solid 4px #c3d9ff;\n'
112                 '}\n'
113                 '#body {\n'
114                 '  margin-left: 5px;\n'
115                 '  margin-right: 5px;\n'
116                 '}\n')),
117         ## html2text options
118         # Use Unicode characters instead of their ascii psuedo-replacements
119         ('unicode-snob', str(False)),
120         # Put the links after each paragraph instead of at the end.
121         ('links-after-each-paragraph', str(False)),
122         # Wrap long lines at position. 0 for no wrapping.
123         ('body-width', str(0)),
124
125         ### Mailing
126         # True: Use SMTP_SERVER to send mail.
127         # False: Call /usr/sbin/sendmail to send mail.
128         ('use-smtp', str(False)),
129         ('smtp-server', 'smtp.yourisp.net:25'),        ('smtp-auth', str(False)),      # set to True to use SMTP AUTH
130         ('smtp-username', 'username'),  # username for SMTP AUTH
131         ('smtp-password', 'password'),  # password for SMTP AUTH
132         ('smtp-ssl', str(False)),       # Connect to the SMTP server using SSL
133
134         ### Miscellaneous
135         # Verbosity (one of 'error', 'warning', 'info', or 'debug').
136         ('verbose', 'warning'),
137         ))