-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail_service.py
More file actions
541 lines (468 loc) · 26.1 KB
/
Copy pathemail_service.py
File metadata and controls
541 lines (468 loc) · 26.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
"""
email_service.py — Centralized email sending module
Uses Python's built-in smtplib with STARTTLS.
Reads all config from environment variables.
Compatible with Gmail (App Password) and any standard SMTP provider.
Gmail setup:
1. Enable 2-Step Verification on your Google account
2. Go to https://myaccount.google.com/apppasswords
3. Generate an App Password for "Mail"
4. Set SMTP_USER=your@gmail.com and SMTP_PASS=<16-char app password>
5. Set SMTP_HOST=smtp.gmail.com and SMTP_PORT=587
"""
import os
import smtplib
import ssl
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from typing import Optional
# ── Config from environment ─────────────────────────────────────────────────
SMTP_HOST = os.environ.get("SMTP_HOST", "smtp.gmail.com")
SMTP_PORT = int(os.environ.get("SMTP_PORT", "587"))
SMTP_USER = os.environ.get("SMTP_USER", "")
SMTP_PASS = os.environ.get("SMTP_PASS", "")
BASE_URL = os.environ.get("BASE_URL", "http://localhost:8000").rstrip("/")
ADMIN_EMAIL = os.environ.get("ADMIN_EMAIL", "")
def _is_configured() -> bool:
"""Returns True if SMTP credentials are set in the environment."""
return bool(SMTP_HOST and SMTP_USER and SMTP_PASS)
def send_email(to: str, subject: str, html_body: str, text_body: Optional[str] = None, attachment_path: Optional[str] = None) -> bool:
"""
Send an email via SMTP with STARTTLS.
Falls back to console print if SMTP is not configured.
Returns True on success, False on failure.
"""
if not _is_configured():
# Graceful fallback — log to console for local dev without SMTP
print(f"\n{'─'*60}")
print("📧 EMAIL (not sent — SMTP not configured)")
print(f" To : {to}")
print(f" Subject : {subject}")
if attachment_path: print(f" Attach : {attachment_path}")
print(f" Body : {text_body or html_body[:300]}")
print(f"{'─'*60}\n")
return False
if attachment_path and os.path.exists(attachment_path):
root_msg = MIMEMultipart("mixed")
root_msg["Subject"] = subject
root_msg["From"] = SMTP_USER
root_msg["To"] = to
alt_msg = MIMEMultipart("alternative")
if text_body:
alt_msg.attach(MIMEText(text_body, "plain"))
alt_msg.attach(MIMEText(html_body, "html"))
root_msg.attach(alt_msg)
try:
with open(attachment_path, "rb") as f:
part = MIMEApplication(f.read(), Name=os.path.basename(attachment_path))
part['Content-Disposition'] = f'attachment; filename="{os.path.basename(attachment_path)}"'
root_msg.attach(part)
except Exception as e:
print(f"Failed to attach file: {e}")
msg = root_msg
else:
msg = MIMEMultipart("alternative")
msg["Subject"] = subject
msg["From"] = SMTP_USER
msg["To"] = to
if text_body:
msg.attach(MIMEText(text_body, "plain"))
msg.attach(MIMEText(html_body, "html"))
try:
context = ssl.create_default_context()
with smtplib.SMTP(SMTP_HOST, SMTP_PORT) as server:
server.ehlo()
server.starttls(context=context)
server.login(SMTP_USER, SMTP_PASS)
server.sendmail(SMTP_USER, to, msg.as_string())
print(f"✅ Email sent → {to} | {subject}")
return True
except Exception as e:
print(f"❌ Email FAILED → {to} | {subject} | Error: {e}")
return False
# ── Email Templates ──────────────────────────────────────────────────────────
def _wrap_html(title: str, body: str) -> str:
"""Wraps email body in a clean, branded HTML shell."""
return f"""<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{title}</title>
</head>
<body style="margin:0;padding:0;background:#0f172a;font-family:'Segoe UI',Arial,sans-serif;">
<table width="100%" cellpadding="0" cellspacing="0" style="background:#0f172a;padding:40px 0;">
<tr><td align="center">
<table width="600" cellpadding="0" cellspacing="0"
style="background:#1e293b;border-radius:16px;overflow:hidden;border:1px solid rgba(255,255,255,0.08);">
<!-- Header -->
<tr>
<td style="background:linear-gradient(135deg,#4f46e5,#7c3aed);padding:32px 40px;">
<h1 style="color:#fff;margin:0;font-size:22px;letter-spacing:-0.5px;">⚖️ AI Arbitration Platform</h1>
<p style="color:rgba(255,255,255,0.7);margin:6px 0 0;font-size:13px;">Automated Contract Arbitration</p>
</td>
</tr>
<!-- Body -->
<tr>
<td style="padding:36px 40px;color:#e2e8f0;font-size:15px;line-height:1.7;">
{body}
</td>
</tr>
<!-- Footer -->
<tr>
<td style="padding:20px 40px;border-top:1px solid rgba(255,255,255,0.06);
color:#475569;font-size:12px;text-align:center;">
This is an automated message from the AI Arbitration Platform.
Do not reply to this email.
</td>
</tr>
</table>
</td></tr>
</table>
</body>
</html>"""
def _btn(url: str, label: str, color: str = "#4f46e5") -> str:
return (f'<a href="{url}" style="display:inline-block;background:{color};color:#fff;'
f'text-decoration:none;padding:13px 28px;border-radius:8px;font-weight:600;'
f'font-size:14px;margin:8px 4px 8px 0;">{label}</a>')
def _case_badge(case_id: str) -> str:
return (f'<div style="background:rgba(99,102,241,0.12);border:1px solid rgba(99,102,241,0.3);'
f'border-radius:8px;padding:12px 18px;margin:20px 0;font-family:monospace;'
f'font-size:16px;color:#a5b4fc;letter-spacing:1px;">'
f'Case ID: <strong>{case_id}</strong></div>')
# ── Initialization emails ────────────────────────────────────────────────────
def send_case_registered(case_id: str, party: str, name: str, email: str,
token: str, counterpart_name: str,
escrow_eth: float, contract_text_preview: str,
attachment_path: Optional[str] = None) -> bool:
"""Sent to each party after a new case is created."""
accept_url = f"{BASE_URL}/response?caseId={case_id}&party={party}&action=accept&token={token}"
decline_url = f"{BASE_URL}/response?caseId={case_id}&party={party}&action=decline&token={token}"
wallet_url = f"{BASE_URL}/wallet?caseId={case_id}&party={party}&token={token}"
preview = contract_text_preview[:300] + ("…" if len(contract_text_preview) > 300 else "")
body = f"""
<p>Hello <strong>{name}</strong>,</p>
<p>A new arbitration contract has been registered between you and <strong>{counterpart_name}</strong>.
Please review the details below and accept or decline.</p>
{_case_badge(case_id)}
<p><strong>Escrow Required:</strong> {escrow_eth} ETH</p>
<div style="background:rgba(255,255,255,0.04);border-radius:8px;padding:16px;
margin:16px 0;font-size:13px;color:#94a3b8;border-left:3px solid #4f46e5;
white-space: pre-wrap; font-family: monospace;">
<strong style="color:#cbd5e1; font-family: 'Segoe UI',Arial,sans-serif;">Contract Preview:</strong><br><br>{preview}
</div>
<p style="font-size:13px;color:#64748b;">
<a href="{BASE_URL}/terms?caseId={case_id}&token={token}" style="color:#a5b4fc;text-decoration:underline;">View Full Legal Agreement</a>
</p>
<p><strong>Action required — please respond within 7 days:</strong></p>
{_btn(accept_url, "✅ Accept Contract", "#16a34a")}
{_btn(decline_url, "❌ Decline Contract", "#dc2626")}
<hr style="border:none;border-top:1px solid rgba(255,255,255,0.08);margin:28px 0;">
<p style="font-size:13px;color:#64748b;">
You can also register or update your Ethereum wallet address at any time:<br>
{_btn(wallet_url, "🔑 Submit Wallet Address", "#0891b2")}
</p>
"""
return send_email(
to=email,
subject=f"Action Required: Contract Registered ({case_id})",
html_body=_wrap_html(f"Contract Registered — {case_id}", body),
text_body=(f"Hello {name},\n\nA contract has been registered. Case: {case_id}\n\n"
f"Accept: {accept_url}\nDecline: {decline_url}\nWallet: {wallet_url}"),
attachment_path=attachment_path
)
def send_wallet_confirmed(case_id: str, party: str, name: str, email: str, wallet: str) -> bool:
"""Sent after a party successfully submits a wallet address."""
body = f"""
<p>Hello <strong>{name}</strong>,</p>
<p>Your Ethereum wallet address has been successfully registered for case <strong>{case_id}</strong>.</p>
{_case_badge(case_id)}
<p><strong>Registered Wallet:</strong><br>
<code style="background:rgba(255,255,255,0.06);padding:8px 12px;border-radius:6px;
font-size:14px;color:#a5b4fc;">{wallet}</code></p>
<p style="color:#94a3b8;font-size:13px;">
If this was not you, contact the platform administrator immediately.
</p>
"""
return send_email(
to=email,
subject=f"Wallet Address Confirmed ({case_id})",
html_body=_wrap_html("Wallet Confirmed", body),
text_body=f"Hello {name},\n\nYour wallet {wallet} has been registered for case {case_id}."
)
def send_contract_signed(case_id: str, seller_name: str, seller_email: str, seller_token: str,
buyer_name: str, buyer_email: str, buyer_token: str,
escrow_address: str, escrow_eth: float, total_eth: float) -> None:
"""Sent to both parties when the contract is fully signed — instructs Buyer to fund escrow."""
def deposit_body(name, token):
return f"""
<p>Hello <strong>{name}</strong>,</p>
<p>Both parties have accepted the contract. The case is now <strong>SIGNED</strong>.</p>
{_case_badge(case_id)}
<p>The Buyer (<strong>{buyer_name}</strong>) must now deposit escrow to activate the agreement.</p>
<p>
<strong>Escrow Wallet Address:</strong><br>
<code style="background:rgba(255,255,255,0.06);padding:8px 12px;border-radius:6px;
font-size:14px;color:#a5b4fc;">{escrow_address}</code>
</p>
<p><strong>Amount to deposit:</strong> {total_eth:.6f} ETH
<span style="color:#64748b;font-size:13px;">(includes 0.001 ETH platform fee)</span></p>
<p style="color:#94a3b8;font-size:13px;">
Include your Case ID hex <strong>0x{case_id.split('-')[-1]}</strong> in the transaction memo/data field.
</p>
<div style="margin-top:20px;">
{_btn(f"{BASE_URL}/transactions/verify?caseId={case_id}&token={token}", "🔍 Verify Escrow Deposit", "#0284c7")}
</div>
"""
for name, email, token in [(seller_name, seller_email, seller_token), (buyer_name, buyer_email, buyer_token)]:
send_email(
to=email,
subject=f"Contract Signed — Awaiting Escrow Deposit ({case_id})",
html_body=_wrap_html("Contract Signed", deposit_body(name, token)),
text_body=(f"Case {case_id} is SIGNED. Buyer must deposit {total_eth} ETH to {escrow_address}.")
)
def send_contract_declined(case_id: str, declining_party: str,
seller_name: str, seller_email: str,
buyer_name: str, buyer_email: str) -> None:
"""Sent to both parties when a contract is declined."""
def body(name):
return f"""
<p>Hello <strong>{name}</strong>,</p>
<p><strong>{declining_party}</strong> has declined the contract. Case <strong>{case_id}</strong>
is now closed.</p>
{_case_badge(case_id)}
<p style="color:#94a3b8;">No further action is required.</p>
"""
for name, email in [(seller_name, seller_email), (buyer_name, buyer_email)]:
send_email(
to=email,
subject=f"Contract Declined ({case_id})",
html_body=_wrap_html("Contract Declined", body(name)),
text_body=f"Case {case_id}: {declining_party} declined the contract."
)
# ── Transactions emails ──────────────────────────────────────────────────────
def send_escrow_confirmed(case_id: str,
seller_name: str, seller_email: str, seller_token: str,
buyer_name: str, buyer_email: str, buyer_token: str,
excess_eth: float = 0.0) -> None:
"""Sent to both parties when escrow deposit is confirmed."""
seller_body = f"""
<p>Hello <strong>{seller_name}</strong>,</p>
<p>The escrow deposit for case <strong>{case_id}</strong> has been confirmed.
The agreement is now <strong>active</strong>.</p>
{_case_badge(case_id)}
<p>The Buyer may now release payment to you once services are delivered, or request a refund.
You can also proactively request a payment or send a refund to the buyer.</p>
{_btn(f"{BASE_URL}/transactions/action?caseId={case_id}&token={seller_token}&actionType=request_payment", "📝 Request Payment (or Tip)", "#16a34a")}
{_btn(f"{BASE_URL}/transactions/action?caseId={case_id}&token={seller_token}&actionType=send_refund", "↩️ Send Refund to Buyer", "#d97706")}
"""
buyer_body = f"""
<p>Hello <strong>{buyer_name}</strong>,</p>
<p>Your escrow deposit for case <strong>{case_id}</strong> has been confirmed.
The agreement is now <strong>active</strong>.</p>
{_case_badge(case_id)}
<p>Once you are satisfied with the delivered services, release payment to the Seller.
If you have a concern, you can request a refund.</p>
{_btn(f"{BASE_URL}/transactions/action?caseId={case_id}&token={buyer_token}&actionType=send_payment", "💰 Send Payment", "#16a34a")}
{_btn(f"{BASE_URL}/transactions/action?caseId={case_id}&token={buyer_token}&actionType=request_refund", "↩️ Request Refund", "#d97706")}
"""
if excess_eth > 0:
buyer_body += f"""
<div style="margin-top:28px;padding-top:20px;border-top:1px solid rgba(255,255,255,0.08);">
<h4 style="color:#a5b4fc;margin:0 0 10px 0;">Excess Funds Detected</h4>
<p style="font-size:14px;">You deposited an excess of <strong>{excess_eth:.6f} ETH</strong> beyond the required escrow and fee. You can withdraw this excess back to your wallet or send it as a tip to the Seller at any time.</p>
{_btn(f"{BASE_URL}/transactions/action?caseId={case_id}&token={buyer_token}&actionType=withdraw_excess", "💸 Withdraw Excess", "#6366f1")}
{_btn(f"{BASE_URL}/transactions/action?caseId={case_id}&token={buyer_token}&actionType=tip_excess", "🎁 Tip Seller", "#ec4899")}
</div>
"""
send_email(seller_email, f"Escrow Confirmed — Agreement Active ({case_id})",
_wrap_html("Escrow Confirmed", seller_body),
text_body=f"Escrow confirmed for {case_id}. The agreement is now active.")
send_email(buyer_email, f"Escrow Confirmed — Agreement Active ({case_id})",
_wrap_html("Escrow Confirmed", buyer_body),
text_body=f"Escrow confirmed for {case_id}. The agreement is now active.")
def send_payment_released(case_id: str, seller_name: str, seller_email: str,
buyer_name: str, buyer_email: str,
amount_eth: float, closed: bool) -> None:
"""Sent to both parties after a payment is released to the Seller."""
status_note = "The case is now <strong>CLOSED</strong>." if closed else "Partial payment released — case remains active."
for name, email in [(seller_name, seller_email), (buyer_name, buyer_email)]:
body = f"""
<p>Hello <strong>{name}</strong>,</p>
<p>A payment of <strong>{amount_eth:.6f} ETH</strong> has been released to the Seller
for case <strong>{case_id}</strong>.</p>
{_case_badge(case_id)}
<p>{status_note}</p>
"""
send_email(email, f"Payment Released ({case_id})",
_wrap_html("Payment Released", body))
def send_refund_released(case_id: str, seller_name: str, seller_email: str,
buyer_name: str, buyer_email: str,
amount_eth: float, closed: bool) -> None:
"""Sent to both parties after a refund is released to the Buyer."""
status_note = "The case is now <strong>CLOSED</strong>." if closed else "Partial refund released — case remains active."
for name, email in [(seller_name, seller_email), (buyer_name, buyer_email)]:
body = f"""
<p>Hello <strong>{name}</strong>,</p>
<p>A refund of <strong>{amount_eth:.6f} ETH</strong> has been released to the Buyer
for case <strong>{case_id}</strong>.</p>
{_case_badge(case_id)}
<p>{status_note}</p>
"""
send_email(email, f"Refund Released ({case_id})",
_wrap_html("Refund Released", body))
def send_refund_requested(case_id: str,
seller_name: str, seller_email: str,
buyer_name: str, buyer_email: str) -> None:
"""Sent to both parties when the Buyer requests a refund (initiates DISPUTED)."""
for name, email in [(seller_name, seller_email), (buyer_name, buyer_email)]:
body = f"""
<p>Hello <strong>{name}</strong>,</p>
<p>The Buyer has requested a refund for case <strong>{case_id}</strong>.
The case is now in <strong>DISPUTED</strong> status.</p>
{_case_badge(case_id)}
<p>Both parties now have <strong>7 days</strong> to submit evidence and arguments
through the Evidence Portal.</p>
"""
send_email(email, f"Refund Requested — Case Disputed ({case_id})",
_wrap_html("Case Disputed", body))
def send_payment_requested(case_id: str,
seller_name: str, seller_email: str,
buyer_name: str, buyer_email: str, buyer_token: str) -> None:
"""Sent to both parties when the Seller requests a payment."""
for name, email in [(seller_name, seller_email), (buyer_name, buyer_email)]:
body = f"""
<p>Hello <strong>{name}</strong>,</p>
<p>The Seller has requested a payment for case <strong>{case_id}</strong>.</p>
{_case_badge(case_id)}
<p>The Buyer has <strong>7 days</strong> to approve or dispute this request.</p>
"""
send_email(email, f"Payment Requested ({case_id})",
_wrap_html("Payment Requested", body))
# ── Prosecution emails ───────────────────────────────────────────────────────
def send_evidence_received(case_id: str, submitter_name: str,
recipient_name: str, recipient_email: str) -> bool:
"""Notifies the opposing party that new evidence has been submitted."""
body = f"""
<p>Hello <strong>{recipient_name}</strong>,</p>
<p><strong>{submitter_name}</strong> has submitted new evidence for case
<strong>{case_id}</strong>.</p>
{_case_badge(case_id)}
<p>The evidence has been recorded and will be reviewed during adjudication.
You may also submit your own evidence and arguments.</p>
<p style="color:#94a3b8;font-size:13px;">
Use the secure link in your original case email to access the Evidence Portal.
</p>
"""
return send_email(
to=recipient_email,
subject=f"New Evidence Submitted ({case_id})",
html_body=_wrap_html("New Evidence", body)
)
# ── Adjudication emails ──────────────────────────────────────────────────────
def send_determination(case_id: str,
seller_name: str, seller_email: str, seller_token: str,
buyer_name: str, buyer_email: str, buyer_token: str,
decision: str, seller_award_eth: float, buyer_award_eth: float) -> None:
"""Sent to both parties after AI Final Judge issues a ruling."""
for name, email, token in [
(seller_name, seller_email, seller_token),
(buyer_name, buyer_email, buyer_token)
]:
appeal_url = f"{BASE_URL}/objection/appeal?caseId={case_id}&token={token}"
body = f"""
<p>Hello <strong>{name}</strong>,</p>
<p>The AI Adjudication Panel has issued a final determination for case
<strong>{case_id}</strong>.</p>
{_case_badge(case_id)}
<div style="background:rgba(99,102,241,0.08);border:1px solid rgba(99,102,241,0.2);
border-radius:10px;padding:20px;margin:20px 0;">
<p style="margin:0 0 12px;font-weight:600;color:#c7d2fe;">📋 Decision Summary</p>
<p style="color:#e2e8f0;margin:0;">{decision}</p>
</div>
<table style="width:100%;border-collapse:collapse;margin:16px 0;">
<tr>
<td style="padding:12px;background:rgba(22,163,74,0.1);border-radius:8px 0 0 8px;
color:#86efac;text-align:center;">
<div style="font-size:12px;color:#4ade80;margin-bottom:4px;">Seller Award</div>
<strong style="font-size:20px;">{seller_award_eth:.6f} ETH</strong>
</td>
<td style="width:8px;"></td>
<td style="padding:12px;background:rgba(59,130,246,0.1);border-radius:0 8px 8px 0;
color:#93c5fd;text-align:center;">
<div style="font-size:12px;color:#60a5fa;margin-bottom:4px;">Buyer Award</div>
<strong style="font-size:20px;">{buyer_award_eth:.6f} ETH</strong>
</td>
</tr>
</table>
<p>You have <strong>7 days</strong> from this notice to file a procedural objection.
Awards will be distributed automatically after the objection window closes.</p>
{_btn(appeal_url, "📝 File Procedural Objection", "#7c3aed")}
<p style="color:#64748b;font-size:12px;margin-top:24px;">
Objections are limited to procedural or logical errors.
No new evidence or arguments are permitted at this stage.
</p>
"""
send_email(
to=email,
subject=f"Final Determination Issued ({case_id})",
html_body=_wrap_html("Final Determination", body),
text_body=(f"Determination for {case_id}:\n{decision}\n\n"
f"Seller Award: {seller_award_eth} ETH | Buyer Award: {buyer_award_eth} ETH\n"
f"File objection (7 days): {appeal_url}")
)
# ── Objection emails ─────────────────────────────────────────────────────────
def send_objection_received(case_id: str, objecting_party: str,
admin_email: str, review_url: str) -> bool:
"""Notifies the admin that an objection has been filed and requires HITL review."""
body = f"""
<p>A procedural objection has been filed for case <strong>{case_id}</strong>
by <strong>{objecting_party}</strong>.</p>
{_case_badge(case_id)}
<p>Please review the objection and the AI ruling, then uphold or reverse the determination.</p>
{_btn(review_url, "🔍 Open Review Portal", "#4f46e5")}
"""
return send_email(
to=admin_email,
subject=f"Objection Filed — Review Required ({case_id})",
html_body=_wrap_html("Objection Filed", body),
text_body=f"Objection filed for {case_id} by {objecting_party}.\nReview: {review_url}"
)
def send_award_distributed(case_id: str,
seller_name: str, seller_email: str, seller_award_eth: float,
buyer_name: str, buyer_email: str, buyer_award_eth: float) -> None:
"""Sent to both parties after final award distribution."""
for name, email, award in [
(seller_name, seller_email, seller_award_eth),
(buyer_name, buyer_email, buyer_award_eth)
]:
body = f"""
<p>Hello <strong>{name}</strong>,</p>
<p>The award distribution for case <strong>{case_id}</strong> has been completed.</p>
{_case_badge(case_id)}
<p>Your award of <strong>{award:.6f} ETH</strong> has been transferred to your
registered wallet.</p>
<p>The case is now <strong>CLOSED</strong>.</p>
"""
send_email(
to=email,
subject=f"Award Distributed — Case Closed ({case_id})",
html_body=_wrap_html("Award Distributed", body),
text_body=f"Case {case_id} closed. Your award: {award} ETH."
)
def send_late_submission_reply(case_id: str, to_email: str):
"""
Auto-reply when evidence is submitted past the 7-day deadline or outside the DISPUTED status.
"""
subject = f"[{case_id}] Evidence Submission Rejected (Deadline Passed)"
text = f"Your email/evidence regarding case {case_id} could not be accepted.\n\nThe 7-day evidence collection window has either closed, or the case is no longer in the DISPUTED phase. The AI Magistrate will not consider this submission.\n\nAI Arbitration System."
html = f"""
<div style="font-family: sans-serif; padding: 20px;">
<h2 style="color: #E74C3C;">Late Submission Rejected</h2>
<p>Your email and any attached evidence regarding case <strong>{case_id}</strong> could not be accepted.</p>
<p>The 7-day evidence collection window has either closed, or the case is no longer in the active <em>DISPUTED</em> phase.</p>
<p>The AI Magistrate will <strong>not</strong> consider this submission.</p>
</div>
"""
return send_email(to_email, subject, html, text)