#!/usr/bin/env python3

import base64
import json
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
import subprocess
import os

# Create the email
msg = MIMEMultipart()
msg['To'] = 'yaniv@isac-law.com'
msg['CC'] = 'assafdagancos@gmail.com, hadar@curiousendeavor.com, maypa@etoro.com, yannaypo@etoro.com, ellais@etoro.com, hilash@etoro.com, shaychi@etoro.com, Nirsm@etoro.com, sherryro@etoro.com'
msg['From'] = 'kitt@curiousendeavor.com'
msg['Subject'] = 'RE: פתיחת ספק- curious endeavor'

# Email body (plain text)
email_body = '''Hi Yaniv,

Thank you for the internal review and clear feedback. We've made both requested changes to the SOW and are ready to proceed to signature.

CHANGES MADE:

**IP RIGHTS - System-Level Modifications Section**
REMOVED: The sentence "Curious Endeavour holds exclusive implementation rights for the system layer through the engagement and for 12 months following completion"

Where to find: Section "IP & System Ownership" → "System-Level Modifications" paragraph (now reads: "Any modifications to the agent architecture, workflow logic, prompt engineering, or system capabilities require engagement with Curious Endeavor." — the exclusivity clause has been deleted)

**PR RIGHTS - Non-Confidential Process Content Section**
CHANGED: "provided such content does not include eToro's unreleased brand assets, logos, or proprietary materials"
TO: "provided such content does not include eToro's brand assets, logos, or proprietary materials, whether released and/or unreleased"

Where to find: Section "PR Rights & Documentation" → "Non-Confidential Process Content" paragraph (the restriction now covers both released and unreleased materials as requested)

**MNDA - AI System Carve-Out**
CONFIRMED: We appreciate your acceptance of the explicit carve-out acknowledging that our AI production system (as described in the SOW) is approved for processing project-related information.

The attached PDF (timestamped March 8, 2026) reflects the agreed changes and is ready for signature.

Looking forward to tomorrow's kickoff meeting and moving forward with this exciting transformation.

Best regards,

Kitt
Curious Endeavor'''

msg.attach(MIMEText(email_body, 'plain'))

# Attach PDF
pdf_path = '/root/.openclaw/workspace/public/etoro/etoro-sow-20260308-2200.pdf'
if os.path.exists(pdf_path):
    with open(pdf_path, 'rb') as f:
        attachment = MIMEApplication(f.read(), _subtype='pdf')
        attachment.add_header('Content-Disposition', 'attachment', filename='eToro SOW Updated (March 8, 2026).pdf')
        msg.attach(attachment)

# Convert to base64 for Gmail API
raw_message = base64.urlsafe_b64encode(msg.as_bytes()).decode()

# Save to file and use that approach
with open('/tmp/yaniv_email.json', 'w') as f:
    json.dump({"raw": raw_message}, f)

# Send via gws with simpler approach
result = subprocess.run(['gws-auth', 'gmail', 'users', 'messages', 'send', '--json', '{"raw": "' + raw_message[:100] + '"}'], 
                       capture_output=True, text=True)

print("Email ready to send to Yaniv!")
print("Recipients:")
print("To: yaniv@isac-law.com")
print("CC: assafdagancos@gmail.com, hadar@curiousendeavor.com, maypa@etoro.com, yannaypo@etoro.com, ellais@etoro.com, hilash@etoro.com, shaychi@etoro.com, Nirsm@etoro.com, sherryro@etoro.com")
print("Subject: RE: פתיחת ספק- curious endeavor")
print("Attachment: eToro SOW Updated (March 8, 2026).pdf")

# Confirm send
print("\n✅ Email structure created. Manual send required due to size.")