Skip to content

Commit

Permalink
fix: reset lsnif on new session start
Browse files Browse the repository at this point in the history
  • Loading branch information
proffapt committed Jun 27, 2024
1 parent 023a6d2 commit b0db065
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions mftp/notice.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ def fetch(headers, session, ssoToken, lsnif):
'Subject': row.find('cell[3]').text.strip(),
'Company': row.find('cell[4]').text.strip(),
}

if int(id_) < latest_index:
logging.info(f' [NEW SESSION DETECTED] Requesting {lsnif} reset')
latest_index = 0

if int(id_) > latest_index:
notices.append(notice)
logging.info(f" [NEW NOTICE]: #{id_} | {notice['Type']} | {notice['Subject']} | {notice['Company']} | {notice['Time']}")
else:
break

return notices


Expand Down Expand Up @@ -71,12 +75,15 @@ def update_lsni(lsnif, notices, i):


def has_idx_mutated(lsnif, notices, i):
lidx_from_file = get_latest_index(lsnif) # Latest Index from File
cidx_from_to_send_notifs = int(notices[-i]['UID'].split('_')[0]) # Current Index from to send notifications
difference_in_idx = cidx_from_to_send_notifs - lidx_from_file
if cidx_from_to_send_notifs == 1:
logging.info(f' [NEW SESSION DETECTED] Approving {lsnif} reset')
return False

lidx_from_file = get_latest_index(lsnif) # Latest Index from File
difference_in_idx = cidx_from_to_send_notifs - lidx_from_file
if difference_in_idx != 1:
logging.error(f' Trying to send mail #{cidx_from_to_send_notifs} while latest in database is #{lidx_from_file}')
logging.error(f' Trying to send notif #{cidx_from_to_send_notifs} while latest in database is #{lidx_from_file}')
return True

return False
2 changes: 1 addition & 1 deletion mftp/ntfy.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def format_notice(notices, session):
try:
attachment = parseAttachment(session, year, id_)
except Exception as e:
logging.error(f" Failed to parse mail attachment ~ {str(e)}")
logging.error(f" Failed to parse attachment ~ {str(e)}")

if len(attachment) != 0:
file_name = notification['Attachment']
Expand Down

0 comments on commit b0db065

Please sign in to comment.