Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Robota #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit messages is not clear, I believe that you want to say:
Changing email script to support multiple emails subjects in inbox or something like.

from classes.mail_wrapper import MailWrapper
from classes.imap import ImapGmailWrapper
from classes.types import MailSenderSubject

from config import mail, app_password, url_telegram, chat_id

Expand All @@ -21,24 +22,23 @@ def check_gmail():
current_mail_id = int(file_reader.read())

if possible_new_email_id > current_mail_id:
latest_email_id = possible_new_email_id
number_of_new_mails = latest_email_id - current_mail_id

file_reader.close()


latest_email_id = possible_new_email_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can possible_new_email_id be not a new email ? There is not checks that validate such name or latest_email_id. You should aim to rename possible_new_email_id to just new_email_id to simplify logic and names.

save_latest_email_id(latest_email_id)

raw_email = imap.fetchs([latest_email_id])
senders_subjects = []
message = 'Shalom Adonai, irmãos. Novo(s) e-mail(s), deem uma olhada:\n'

for mail_id in range(current_mail_id + 1, latest_email_id + 1):
raw_email = imap.fetchs([mail_id])

mail_parser = MailWrapper(raw_email)
sender = mail_parser.get_sender()
mail_parser = MailWrapper(raw_email)

subject = mail_parser.get_subject()
senders_subjects.append(MailSenderSubject(mail_parser.get_sender(), mail_parser.get_subject()))

if number_of_new_mails > 1:
message = 'Shalom Adonai, irmãos. {} novos emails, deem uma olhada.'.format(number_of_new_mails)
else:
message = 'Shalom Adonai, irmãos. Novo email, deem uma olhada.\n\nTítulo: {}\n\nRemetente: {}'.format(subject, sender)
for ss in senders_subjects:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid using abbreviations or simplified names for variables, it's better to be explicit about what we are doing here.
This variable is something related to an old army from europe or it's a abbreviation for sender_object ?

message += '\nRemetente: {}\nTítulo: {}\n'.format(ss.sender, ss.subject)

send_message(message)

Expand Down