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