This commit is contained in:
Son NK 2020-04-04 19:21:31 +02:00
parent 4d8040c80d
commit f7e5ab1e34
5 changed files with 27 additions and 25 deletions

View File

@ -248,10 +248,10 @@ def serialize_contact(fe: Contact) -> dict:
"reverse_alias": fe.website_send_to(),
}
fel: EmailLog = fe.last_reply()
if fel:
res["last_email_sent_date"] = fel.created_at.format()
res["last_email_sent_timestamp"] = fel.created_at.timestamp
email_log: EmailLog = fe.last_reply()
if email_log:
res["last_email_sent_date"] = email_log.created_at.format()
res["last_email_sent_timestamp"] = email_log.created_at.timestamp
return res

View File

@ -254,26 +254,26 @@ def get_alias_infos(user, query=None, highlight_alias_id=None) -> [AliasInfo]:
or_(Alias.email.ilike(f"%{query}%"), Alias.note.ilike(f"%{query}%"))
)
for ge, fe, fel, mb in q:
if ge.email not in aliases:
aliases[ge.email] = AliasInfo(
id=ge.id,
alias=ge,
for alias, contact, email_log, mailbox in q:
if alias.email not in aliases:
aliases[alias.email] = AliasInfo(
id=alias.id,
alias=alias,
nb_blocked=0,
nb_forward=0,
nb_reply=0,
highlight=ge.id == highlight_alias_id,
mailbox=mb,
note=ge.note,
highlight=alias.id == highlight_alias_id,
mailbox=mailbox,
note=alias.note,
)
alias_info = aliases[ge.email]
if not fel:
alias_info = aliases[alias.email]
if not email_log:
continue
if fel.is_reply:
if email_log.is_reply:
alias_info.nb_reply += 1
elif fel.blocked:
elif email_log.blocked:
alias_info.nb_blocked += 1
else:
alias_info.nb_forward += 1

View File

@ -17,10 +17,10 @@ def refused_email_route():
EmailLog.user_id == current_user.id, EmailLog.refused_email_id != None
).order_by(EmailLog.id.desc()).all()
# make sure the highlighted fel is the first fel
# make sure the highlighted email_log is the first email_log
highlight_index = None
for ix, fel in enumerate(email_logs):
if fel.id == highlight_id:
for ix, email_log in enumerate(email_logs):
if email_log.id == highlight_id:
highlight_index = ix
break

View File

@ -130,10 +130,10 @@ def stats():
q = q.filter(~User.email.contains(ie))
nb_forward = nb_block = nb_reply = 0
for fel, _, _, _ in q:
if fel.is_reply:
for email_log, _, _, _ in q:
if email_log.is_reply:
nb_reply += 1
elif fel.blocked:
elif email_log.blocked:
nb_block += 1
else:
nb_forward += 1

View File

@ -555,7 +555,7 @@ def handle_bounce(
contact: Contact, alias: Alias, msg: Message, user: User, mailbox_email: str
):
address = alias.email
fel: EmailLog = EmailLog.create(
email_log: EmailLog = EmailLog.create(
contact_id=contact.id, bounced=True, user_id=contact.user_id
)
db.session.commit()
@ -583,12 +583,14 @@ def handle_bounce(
)
db.session.flush()
fel.refused_email_id = refused_email.id
email_log.refused_email_id = refused_email.id
db.session.commit()
LOG.d("Create refused email %s", refused_email)
refused_email_url = URL + f"/dashboard/refused_email?highlight_id=" + str(fel.id)
refused_email_url = (
URL + f"/dashboard/refused_email?highlight_id=" + str(email_log.id)
)
# inform user if this is the first bounced email
if nb_bounced == 1: