debug(transfer): add detailed logging for email scanning and data extraction

This commit is contained in:
yumoqing 2026-07-17 13:45:11 +08:00
parent 53bdd0681f
commit 93af2f8c62

View File

@ -118,20 +118,30 @@ class TransferGateway(Gateway):
return None return None
def get_transfer_data(self, mail): def get_transfer_data(self, mail):
debug(f'get_transfer_data: from={mail.mailfrom} to={mail.mailto} expect_to={self.email}')
if mail.mailfrom != '95555@message.cmbchina.com': if mail.mailfrom != '95555@message.cmbchina.com':
debug(f'get_transfer_data: wrong sender')
return None return None
if mail.mailto != self.email: if mail.mailto != self.email:
debug(f'get_transfer_data: mailto mismatch: {mail.mailto} != {self.email}')
return None return None
if not mail.body.startswith('动账业务通知'): if not mail.body.startswith('动账业务通知'):
debug(f'get_transfer_data: body not start with 动账业务通知, head={mail.body[:30]}')
return None return None
ns = DictObject() ns = DictObject()
match = re.search(r'交易金额\s*[:]?\s*(\d+(?:\.\d+)?)', mail.body) match = re.search(r'交易金额\s*[:]?\s*(\d+(?:\.\d+)?)', mail.body)
if match: if match:
ns.amount = float(match.group(1)) ns.amount = float(match.group(1))
debug(f'get_transfer_data: amount={ns.amount}')
match = re.search(r'摘要[:]\s*(\d{7})(?!\d)', mail.body) match = re.search(r'摘要[:]\s*(\d{7})(?!\d)', mail.body)
if match: if match:
ns.code = match.group(1) ns.code = match.group(1)
if not hasattr(ns, 'amount') or not hasattr(ns, 'code'): debug(f'get_transfer_data: code={ns.code}')
if not hasattr(ns, 'amount'):
debug(f'get_transfer_data: no amount found, body={mail.body[:200]}')
return None
if not hasattr(ns, 'code'):
debug(f'get_transfer_data: no code found, body={mail.body[:200]}')
return None return None
return ns return ns
@ -231,16 +241,23 @@ class TransferGateway(Gateway):
for i in range(count, 0, -1): for i in range(count, 0, -1):
try: try:
mail = ec.get_mail(i) mail = ec.get_mail(i)
debug(f'check_transfer: mail[{i}] from={mail.mailfrom} body_head={mail.body[:20]}')
if mail.mailfrom != '95555@message.cmbchina.com': if mail.mailfrom != '95555@message.cmbchina.com':
debug(f'check_transfer: mail[{i}] skipped, wrong sender')
continue continue
if not mail.body.startswith('动账业务通知'): if not mail.body.startswith('动账业务通知'):
debug(f'check_transfer: mail[{i}] skipped, not 动账业务通知')
continue continue
data = self.get_transfer_data(mail) data = self.get_transfer_data(mail)
if data is None: if data is None:
debug(f'check_transfer: mail[{i}] get_transfer_data returned None')
continue continue
debug(f'check_transfer: mail[{i}] code={data.code} amount={data.amount}, looking for {tcode}')
if str(data.code) == tcode: if str(data.code) == tcode:
matched = data matched = data
debug(f'check_transfer: mail[{i}] MATCHED!')
break break
debug(f'check_transfer: mail[{i}] code mismatch: {data.code} != {tcode}')
except Exception as e: except Exception as e:
debug(f'check_transfer: skip mail {i}: {e}') debug(f'check_transfer: skip mail {i}: {e}')