from flask import Flask, request, jsonify
import requests, urllib.parse, json

app = Flask(__name__)

@app.route("/hotinbox")
def hotinbox():
    ep = request.args.get("ep")
    if not ep:
        return jsonify({
            "error": "Missing parameter ep",
            "Developer": "Basic Coders | @SajagOG"
        })

    enc = urllib.parse.quote(ep) + "%7C"
    data = f"ajax=1&do=check&mailpass={enc}&delim=%7C&email=0&bank=0&card=0&info=0"

    headers = {
        "authority": "checkz.co",
        "accept": "application/json, text/javascript, */*; q=0.01",
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
        "cookie": "cf_clearance=YOUR_CF_HERE",
        "origin": "https://checkz.co",
        "referer": "https://checkz.co/hotmail-inbox-checker",
        "user-agent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36",
        "x-requested-with": "XMLHttpRequest"
    }

    r = requests.post("https://checkz.co/ajax/hotmail-inbox-checker.php",
                      headers=headers, data=data)

    try:
        resp = json.loads(r.text)
    except:
        return jsonify({
            "error": "Invalid JSON from source",
            "raw": r.text,
            "Developer": "Basic Coders | @SajagOG"
        })

    if "capture" in resp and isinstance(resp["capture"], dict):
        resp["capture"].pop("ConfigBy", None)

    resp["Developer"] = "Basic Coders | @SajagOG"
    return jsonify(resp)


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=6969)