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