From 6939e0c251e8e4f42a382aa7e60437b208208383 Mon Sep 17 00:00:00 2001 From: Martin Di Paola Date: Sat, 27 Jun 2020 03:25:38 +0000 Subject: [PATCH 1/2] Use feed names provided by the user as the sender of emails Instead of using the feed title, use the feed names that the user provided in the configuration file as the name of the sender of the emails for that feed. This allows the user to control it (some feeds have too long titles and it is annoying to have them as the senders' names). This only affects the sender but not how the data is stored in the database so this does not introduce any regression (no migration is required) --- feed2maildir/converter.py | 5 +++-- feed2maildir/reader.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/feed2maildir/converter.py b/feed2maildir/converter.py index 5268d17..967ed6f 100644 --- a/feed2maildir/converter.py +++ b/feed2maildir/converter.py @@ -109,6 +109,7 @@ def find_new(self, feeds, db, writedb=True, dbfile=None): newtimes = {} for feed in feeds: feedname = feed.feed.title + feedaliasname = feed.feed_alias_name try: # to get the update time from the feed itself feedup = self.mktime(feed.feed.updated) except: # there is no info, then find it in the posts @@ -134,9 +135,9 @@ def find_new(self, feeds, db, writedb=True, dbfile=None): feedtime = feedtime.replace(tzinfo=dateutil.tz.tzutc()) if not oldtime or oldtime < feedtime: try: # to append the post the the feed-list - new[feedname].append(post) + new[feedaliasname].append(post) except: # it is the first one, make a new list - new[feedname] = [post, ] + new[feedaliasname] = [post, ] if writedb: newtimes[feedname] = feedup.strftime('%Y-%m-%d %H:%M:%S %Z') diff --git a/feed2maildir/reader.py b/feed2maildir/reader.py index a60a3d6..5f83241 100644 --- a/feed2maildir/reader.py +++ b/feed2maildir/reader.py @@ -11,6 +11,7 @@ def __init__(self, feeds, silent=False): if f.bozo: self.output('WARNING: could not parse feed {}'.format(feed)) else: + f.feed_alias_name = feed # user provided text self.feeds.append(f) def output(self, arg): From a0f74ae9396b5ef635eeb201f0d853fcdf6b7352 Mon Sep 17 00:00:00 2001 From: Martin Di Paola Date: Sat, 27 Jun 2020 03:32:24 +0000 Subject: [PATCH 2/2] Fix the tests with alias name introduction --- feed2maildir/tests/convertertests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/feed2maildir/tests/convertertests.py b/feed2maildir/tests/convertertests.py index 7c8dbdf..a362fae 100644 --- a/feed2maildir/tests/convertertests.py +++ b/feed2maildir/tests/convertertests.py @@ -45,6 +45,7 @@ def setUp(self): ), ], ) + self.testfeed.feed_alias_name = self.testfeed.feed.title self.test = [self.testfeed, ] def test_read_nonexistent_db(self): @@ -69,7 +70,7 @@ def test_convert_valid_input(self): converter = Converter(db='/tmp/db') converter.load(self.test) self.assertEqual(len(converter.feeds), 1) - self.assertEqual(len(converter.feeds[0]), 2) + self.assertEqual(len(converter.feeds[0]), 3) def test_fail_to_make_maildir(self): converter = Converter(maildir='/maildir', db='/tmp/db', silent=True)