aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMole Shang <[email protected]>2023-01-25 11:37:45 +0800
committerMole Shang <[email protected]>2023-01-25 11:38:42 +0800
commitd741c552a7dbe18515955bfc2c173367a03fdbc7 (patch)
tree365f247b36dfd15955e7be739a5077935d390a92
parentedf030b877a875946215ebf6675a14c96f7f325d (diff)
downloadtelegram-mail-bot-d741c552a7dbe18515955bfc2c173367a03fdbc7.tar.gz
telegram-mail-bot-d741c552a7dbe18515955bfc2c173367a03fdbc7.tar.bz2
telegram-mail-bot-d741c552a7dbe18515955bfc2c173367a03fdbc7.zip
fix(bot.py): rollback to the origin method to refresh inbox_num
-rw-r--r--bot.py10
-rw-r--r--utils/client.py4
2 files changed, 5 insertions, 9 deletions
diff --git a/bot.py b/bot.py
index c533d51..deb8ebe 100644
--- a/bot.py
+++ b/bot.py
@@ -88,14 +88,14 @@ def periodic_task(context: CallbackContext) -> None:
global inbox_num
logger.info("entering periodic task.")
with EmailClient(email_addr, email_passwd) as client:
- new_unseen_num = client.get_mails_unseen_count()
- if new_unseen_num:
- for i in range(inbox_num, inbox_num + new_unseen_num + 1):
- mail = client.get_mail_by_index(i)
+ new_inbox_num = client.get_mails_count()
+ if new_inbox_num > inbox_num:
+ for i in range(inbox_num, inbox_num + new_inbox_num):
+ mail = client.get_mail_by_index(i + 1)
content = mail.__repr__()
for text in handle_large_text(content):
context.bot.send_message(context.job.context, text=text)
- inbox_num += new_unseen_num
+ inbox_num = new_inbox_num
def inbox(update: Update, context: CallbackContext) -> None:
diff --git a/utils/client.py b/utils/client.py
index 884a922..e0bd2f9 100644
--- a/utils/client.py
+++ b/utils/client.py
@@ -32,10 +32,6 @@ class EmailClient(object):
def get_mails_count(self):
return self.number
- def get_mails_unseen_count(self):
- unseen_messages = self.server.search("UNSEEN")
- return len(unseen_messages)
-
def get_mail_by_index(self, index):
list = self.get_mails_list()
msg_data = list[int(index)-1][1]