File size: 3,877 Bytes
86f92bb
 
8b25376
86f92bb
8b25376
 
86f92bb
 
 
 
 
 
b4a3a7a
86f92bb
 
8b25376
86f92bb
 
 
 
 
 
 
 
8b25376
 
 
 
 
 
 
 
 
 
 
 
 
 
7cc0595
8b25376
 
 
 
 
 
 
 
 
 
 
 
86f92bb
8b25376
 
86f92bb
8b25376
 
 
 
 
 
 
 
 
 
 
 
 
7cc0595
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8b25376
 
86f92bb
7cc0595
8b25376
7cc0595
 
 
 
 
 
86f92bb
8b25376
8ac88a9
7cc0595
8b25376
86f92bb
8b25376
86f92bb
8b25376
86f92bb
8b25376
7cc0595
8b25376
 
 
86f92bb
 
7cc0595
 
8b25376
 
7cc0595
86f92bb
8b25376
 
 
86f92bb
8b25376
86f92bb
 
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
import gradio as gr
import asyncio
import nest_asyncio
import re
import io
import sys
import os

from protonmail import ProtonMail

nest_asyncio.apply()

username = "laygyi3344@proton.me"
password = "htz175039"

# Session setup
proton = ProtonMail()
if not os.path.exists("session.pickle"):
    proton.login(username, password)
    proton.save_session("session.pickle")

proton.load_session("session.pickle", auto_save=True)


async def get_verification_code_async():
    old_stdout = sys.stdout
    sys.stdout = mystdout = io.StringIO()

    try:
        messages = proton.get_messages()
        if not messages:
            return "No messages found.", "", "No verification code found.", "", mystdout.getvalue()

        message = proton.read_message(messages[0])
        sender = message.sender.address
        subject = message.subject
        body = message.body

        # Match 6-digit or 8-char hex (Runway style)
        code_match_6 = re.search(r'\b\d{6}\b', body)
        code_match_runway = re.search(r'\b[A-F0-9]{8}\b', body)

        if code_match_6:
            verification_code = code_match_6.group()
        elif code_match_runway:
            verification_code = code_match_runway.group()
        else:
            verification_code = "No verification code found."

        with open("message.html", "w", encoding="utf-8") as f:
            f.write(body)

        logs = mystdout.getvalue()
        return sender, subject, verification_code, body, logs

    finally:
        sys.stdout = old_stdout


def get_verification_code_sync():
    return asyncio.get_event_loop().run_until_complete(get_verification_code_async())


def display_verification():
    sender, subject, code, body, logs = get_verification_code_sync()

    if code != "No verification code found.":
        html_code = f"""
        <div style="font-size: 20px; margin-top: 15px;">
            <b>Verification Code:</b>
            <span id="vcode" style="color: green; font-weight: bold; font-size: 22px;">{code}</span>
            <button onclick="navigator.clipboard.writeText(document.getElementById('vcode').innerText)"
                    style="
                        margin-left: 15px;
                        padding: 6px 12px;
                        background-color: #4CAF50;
                        color: white;
                        border: none;
                        border-radius: 6px;
                        cursor: pointer;
                        font-size: 14px;
                        transition: 0.2s ease-in-out;
                    "
                    onmouseover="this.style.backgroundColor='#45a049'"
                    onmouseout="this.style.backgroundColor='#4CAF50'">
                Copy
            </button>
        </div>
        """
    else:
        html_code = f"<div style='color: red; font-size: 18px; margin-top: 10px;'>{code}</div>"

    info_text = f"""
    <div style="margin-top: 10px;">
        <b>Sender:</b> {sender}<br>
        <b>Subject:</b> {subject}
    </div>
    """

    log_html = f"""
    <div style='background: black; color: black; padding: 10px; font-family: monospace; border: 1px solid #ddd; border-radius: 8px;
                max-height: 400px; overflow-y: auto; margin-top: 10px; white-space: pre-wrap;'>
[LOG OUTPUT]

{logs}

[EMAIL BODY]

{body}
    </div>
    """

    return html_code, info_text, log_html


with gr.Blocks(css=".gr-button {font-weight:bold; padding:10px 20px; border-radius:8px; background:#1976d2; color:white; transition:0.2s;} .gr-button:hover {background:#1565c0;}") as demo:
    gr.Markdown("## 📨 ProtonMail Verification Code Fetcher")

    with gr.Row():
        btn = gr.Button("🔍 Get Verification Code")

    code_area = gr.HTML()
    info_area = gr.HTML()
    log_area = gr.HTML()

    btn.click(fn=display_verification, outputs=[code_area, info_area, log_area])

demo.launch()