Merge branch 'post-process'
[rss2email.git] / rss2email / config.py
1 # Copyright (C) 2004-2013 Aaron Swartz
2 #                         Brian Lalor
3 #                         Dean Jackson
4 #                         Erik Hetzner
5 #                         Etienne Millon <me@emillon.org>
6 #                         Joey Hess
7 #                         Lindsey Smith <lindsey.smith@gmail.com>
8 #                         Marcel Ackermann
9 #                         Martin 'Joey' Schulze
10 #                         Matej Cepl
11 #                         W. Trevor King <wking@tremily.us>
12 #
13 # This file is part of rss2email.
14 #
15 # rss2email is free software: you can redistribute it and/or modify it under
16 # the terms of the GNU General Public License as published by the Free Software
17 # Foundation, either version 2 of the License, or (at your option) version 3 of
18 # the License.
19 #
20 # rss2email is distributed in the hope that it will be useful, but WITHOUT ANY
21 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
22 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License along with
25 # rss2email.  If not, see <http://www.gnu.org/licenses/>.
26
27 """Per-user rss2email configuration
28 """
29
30 import collections as _collections
31 import configparser as _configparser
32
33 import html2text as _html2text
34
35
36 class Config (_configparser.ConfigParser):
37     def __init__(self, dict_type=_collections.OrderedDict,
38                  interpolation=_configparser.ExtendedInterpolation(),
39                  **kwargs):
40         super(Config, self).__init__(
41             dict_type=dict_type, interpolation=interpolation, **kwargs)
42
43     def _setup(self, section='DEFAULT'):
44         _html2text.UNICODE_SNOB = self.getboolean(
45             section, 'unicode-snob', fallback=False)
46         _html2text.LINKS_EACH_PARAGRAPH = self.getboolean(
47             section, 'links-after-each-paragaph', fallback=False)
48         _html2text.BODY_WIDTH = self.getint(section, 'body-width', fallback=0)
49
50
51 CONFIG = Config()
52
53 # setup defaults for feeds that don't customize
54 CONFIG['DEFAULT'] = _collections.OrderedDict((
55         ### Addressing
56         # The email address messages are from by default
57         ('from', 'user@rss2email.invalid'),
58         # Transfer-Encoding. For local mailing it is safe and
59         # convient to use 8bit.
60         ('use-8bit', str(False)),
61         # True: Only use the 'from' address.
62         # False: Use the email address specified by the feed, when possible.
63         ('force-from', str(False)),
64         # True: Use the publisher's email if you can't find the author's.
65         # False: Just use the 'from' email instead.
66         ('use-publisher-email', str(False)),
67         # Only use the feed email address rather than friendly name
68         # plus email address
69         ('friendly-name', str(True)),
70         # Set this to default To email addresses.
71         ('to', ''),
72
73         ### Fetching
74         # Set an HTTP proxy (e.g. 'http://your.proxy.here:8080/')
75         ('proxy', ''),
76         # Set the timeout (in seconds) for feed server response
77         ('feed-timeout', str(60)),
78
79         ### Processing
80         # True: Fetch, process, and email feeds.
81         # False: Don't fetch, process, or email feeds
82         ('active', str(True)),
83         # True: Generate Date header based on item's date, when possible.
84         # False: Generate Date header based on time sent.
85         ('date-header', str(False)),
86         # A comma-delimited list of some combination of
87         # ('issued', 'created', 'modified', 'expired')
88         # expressing ordered list of preference in dates
89         # to use for the Date header of the email.
90         ('date-header-order', 'modified, issued, created, expired'),
91         # Set this to add bonus headers to all emails
92         # Example: bonus-header = 'Approved: joe@bob.org'
93         ('bonus-header', ''),
94         # True: Receive one email per post.
95         # False: Receive an email every time a post changes.
96         ('trust-guid', str(True)),
97         # To most correctly encode emails with international
98         # characters, we iterate through the list below and use the
99         # first character set that works.
100         ('encodings', 'US-ASCII, ISO-8859-1, UTF-8, BIG5, ISO-2022-JP'),
101         # User processing hooks.  Note the space after the module name.
102         # Example: post-process = 'rss2email.post_process.downcase downcase_message'
103         ('post-process', ''),
104         ## HTML conversion
105         # True: Send text/html messages when possible.
106         # False: Convert HTML to plain text.
107         ('html-mail', str(False)),
108         # Optional CSS styling
109         ('use-css', str(False)),
110         ('css', (
111                 'h1 {\n'
112                 '  font: 18pt Georgia, "Times New Roman";\n'
113                 '}\n'
114                 'body {\n'
115                 '  font: 12pt Arial;\n'
116                 '}\n'
117                 'a:link {\n'
118                 '  font: 12pt Arial;\n'
119                 '  font-weight: bold;\n'
120                 '  color: #0000cc;\n'
121                 '}\n'
122                 'blockquote {\n'
123                 '  font-family: monospace;\n'
124                 '}\n'
125                 '.header {\n'
126                 '  background: #e0ecff;\n'
127                 '  border-bottom: solid 4px #c3d9ff;\n'
128                 '  padding: 5px;\n'
129                 '  margin-top: 0px;\n'
130                 '  color: red;\n'
131                 '}\n'
132                 '.header a {\n'
133                 '  font-size: 20px;\n'
134                 '  text-decoration: none;\n'
135                 '}\n'
136                 '.footer {\n'
137                 '  background: #c3d9ff;\n'
138                 '  border-top: solid 4px #c3d9ff;\n'
139                 '  padding: 5px;\n'
140                 '  margin-bottom: 0px;\n'
141                 '}\n'
142                 '#entry {\n'
143                 '  border: solid 4px #c3d9ff;\n'
144                 '}\n'
145                 '#body {\n'
146                 '  margin-left: 5px;\n'
147                 '  margin-right: 5px;\n'
148                 '}\n')),
149         ## html2text options
150         # Use Unicode characters instead of their ascii psuedo-replacements
151         ('unicode-snob', str(False)),
152         # Put the links after each paragraph instead of at the end.
153         ('links-after-each-paragraph', str(False)),
154         # Wrap long lines at position. 0 for no wrapping.
155         ('body-width', str(0)),
156
157         ### Mailing
158         # True: Use SMTP_SERVER to send mail.
159         # False: Use sendmail (or compatible) to send mail.
160         ('use-smtp', str(False)),
161         ('sendmail', '/usr/sbin/sendmail'),  # Path to sendmail (or compatible)
162         ('smtp-server', 'smtp.yourisp.net:25'),        ('smtp-auth', str(False)),      # set to True to use SMTP AUTH
163         ('smtp-username', 'username'),  # username for SMTP AUTH
164         ('smtp-password', 'password'),  # password for SMTP AUTH
165         ('smtp-ssl', str(False)),       # Connect to the SMTP server using SSL
166
167         ### Miscellaneous
168         # Verbosity (one of 'error', 'warning', 'info', or 'debug').
169         ('verbose', 'warning'),
170         ))