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