feed: Add the digest-post-process setting
[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(self, section='DEFAULT'):
45         _html2text.UNICODE_SNOB = self.getboolean(
46             section, 'unicode-snob', fallback=False)
47         _html2text.LINKS_EACH_PARAGRAPH = self.getboolean(
48             section, 'links-after-each-paragaph', fallback=False)
49         _html2text.BODY_WIDTH = self.getint(section, 'body-width', fallback=0)
50
51
52 CONFIG = Config()
53
54 # setup defaults for feeds that don't customize
55 CONFIG['DEFAULT'] = _collections.OrderedDict((
56         ### Addressing
57         # The email address messages are from by default
58         ('from', 'user@rss2email.invalid'),
59         # Transfer-Encoding. For local mailing it is safe and
60         # convient to use 8bit.
61         ('use-8bit', str(False)),
62         # True: Only use the 'from' address.
63         # False: Use the email address specified by the feed, when possible.
64         ('force-from', str(False)),
65         # True: Use the publisher's email if you can't find the author's.
66         # False: Just use the 'from' email instead.
67         ('use-publisher-email', str(False)),
68         # Only use the feed email address rather than friendly name
69         # plus email address
70         ('friendly-name', str(True)),
71         # Set this to default To email addresses.
72         ('to', ''),
73
74         ### Fetching
75         # Set an HTTP proxy (e.g. 'http://your.proxy.here:8080/')
76         ('proxy', ''),
77         # Set the timeout (in seconds) for feed server response
78         ('feed-timeout', str(60)),
79
80         ### Processing
81         # True: Fetch, process, and email feeds.
82         # False: Don't fetch, process, or email feeds
83         ('active', str(True)),
84         # True: Send a single, multi-entry email per feed per rss2email run.
85         # False: Send a single email per entry.
86         ('digest', str(False)),
87         # True: Generate Date header based on item's date, when possible.
88         # False: Generate Date header based on time sent.
89         ('date-header', str(False)),
90         # A comma-delimited list of some combination of
91         # ('issued', 'created', 'modified', 'expired')
92         # expressing ordered list of preference in dates
93         # to use for the Date header of the email.
94         ('date-header-order', 'modified, issued, created, expired'),
95         # Set this to add bonus headers to all emails
96         # Example: bonus-header = 'Approved: joe@bob.org'
97         ('bonus-header', ''),
98         # True: Receive one email per post.
99         # False: Receive an email every time a post changes.
100         ('trust-guid', str(True)),
101         # To most correctly encode emails with international
102         # characters, we iterate through the list below and use the
103         # first character set that works.
104         ('encodings', 'US-ASCII, ISO-8859-1, UTF-8, BIG5, ISO-2022-JP'),
105         # User processing hooks.  Note the space after the module name.
106         # Example: post-process = 'rss2email.post_process.downcase downcase_message'
107         ('post-process', ''),
108         # User processing hooks for digest messages.  If 'digest' is
109         # enabled, the usual 'post-process' hook gets to massage the
110         # per-entry messages, but this hook is called with the full
111         # digest message before it is mailed.
112         # Example: digest-post-process = 'rss2email.post_process.downcase downcase_message'
113         ('digest-post-process', ''),
114         ## HTML conversion
115         # True: Send text/html messages when possible.
116         # False: Convert HTML to plain text.
117         ('html-mail', str(False)),
118         # Optional CSS styling
119         ('use-css', str(False)),
120         ('css', (
121                 'h1 {\n'
122                 '  font: 18pt Georgia, "Times New Roman";\n'
123                 '}\n'
124                 'body {\n'
125                 '  font: 12pt Arial;\n'
126                 '}\n'
127                 'a:link {\n'
128                 '  font: 12pt Arial;\n'
129                 '  font-weight: bold;\n'
130                 '  color: #0000cc;\n'
131                 '}\n'
132                 'blockquote {\n'
133                 '  font-family: monospace;\n'
134                 '}\n'
135                 '.header {\n'
136                 '  background: #e0ecff;\n'
137                 '  border-bottom: solid 4px #c3d9ff;\n'
138                 '  padding: 5px;\n'
139                 '  margin-top: 0px;\n'
140                 '  color: red;\n'
141                 '}\n'
142                 '.header a {\n'
143                 '  font-size: 20px;\n'
144                 '  text-decoration: none;\n'
145                 '}\n'
146                 '.footer {\n'
147                 '  background: #c3d9ff;\n'
148                 '  border-top: solid 4px #c3d9ff;\n'
149                 '  padding: 5px;\n'
150                 '  margin-bottom: 0px;\n'
151                 '}\n'
152                 '#entry {\n'
153                 '  border: solid 4px #c3d9ff;\n'
154                 '}\n'
155                 '#body {\n'
156                 '  margin-left: 5px;\n'
157                 '  margin-right: 5px;\n'
158                 '}\n')),
159         ## html2text options
160         # Use Unicode characters instead of their ascii psuedo-replacements
161         ('unicode-snob', str(False)),
162         # Put the links after each paragraph instead of at the end.
163         ('links-after-each-paragraph', str(False)),
164         # Wrap long lines at position. 0 for no wrapping.
165         ('body-width', str(0)),
166
167         ### Mailing
168         # True: Use SMTP_SERVER to send mail.
169         # False: Use sendmail (or compatible) to send mail.
170         ('use-smtp', str(False)),
171         ('sendmail', '/usr/sbin/sendmail'),  # Path to sendmail (or compatible)
172         ('smtp-server', 'smtp.yourisp.net:25'),        ('smtp-auth', str(False)),      # set to True to use SMTP AUTH
173         ('smtp-username', 'username'),  # username for SMTP AUTH
174         ('smtp-password', 'password'),  # password for SMTP AUTH
175         ('smtp-ssl', str(False)),       # Connect to the SMTP server using SSL
176
177         ### Miscellaneous
178         # Verbosity (one of 'error', 'warning', 'info', or 'debug').
179         ('verbose', 'warning'),
180         ))