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
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':
debug(f'get_transfer_data: wrong sender')
return None
if mail.mailto != self.email:
debug(f'get_transfer_data: mailto mismatch: {mail.mailto} != {self.email}')
return None
if not mail.body.startswith('动账业务通知'):
debug(f'get_transfer_data: body not start with 动账业务通知, head={mail.body[:30]}')
return None
ns = DictObject()
match = re.search(r'交易金额\s*[:]?\s*(\d+(?:\.\d+)?)', mail.body)
if match:
ns.amount = float(match.group(1))
debug(f'get_transfer_data: amount={ns.amount}')
match = re.search(r'摘要[:]\s*(\d{7})(?!\d)', mail.body)
if match:
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 ns
@ -231,16 +241,23 @@ class TransferGateway(Gateway):
for i in range(count, 0, -1):
try:
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':
debug(f'check_transfer: mail[{i}] skipped, wrong sender')
continue
if not mail.body.startswith('动账业务通知'):
debug(f'check_transfer: mail[{i}] skipped, not 动账业务通知')
continue
data = self.get_transfer_data(mail)
if data is None:
debug(f'check_transfer: mail[{i}] get_transfer_data returned None')
continue
debug(f'check_transfer: mail[{i}] code={data.code} amount={data.amount}, looking for {tcode}')
if str(data.code) == tcode:
matched = data
debug(f'check_transfer: mail[{i}] MATCHED!')
break
debug(f'check_transfer: mail[{i}] code mismatch: {data.code} != {tcode}')
except Exception as e:
debug(f'check_transfer: skip mail {i}: {e}')