none
Parsear MIME en binario para obtener adjuntos RRS feed

  • Pregunta

  • Buenas tardes foro, tengo una aplicación de un tercero que guarda los mails que recibe una cuenta en  MIME  pasado a binario en una tabla de sql server, por un tema de integración con otra aplicación necesito parsear ese código y guardar el binario de los adjuntos en otra tabla en un campo imágen, junto con el nombre del archivo y si es factible el tipo de contenido y el tamaño en otras columnas (esto último no sería prioritario).

    Hay alguna función o código para hacer esto? Copio el código de un correo de prueba y como lo necesito obtener.

    Estoy usando SQL Server 2012

    Ejemplo de codigo guardado del email con codificación uuencode:

    Delivered-To: xxx@xxx.com
    Received: by 10.50.65.103 with SMTP id w7csp2164326igs;
            Mon, 4 Sep 2017 05:48:33 -0700 (PDT)
    X-Received: by 10.80.138.129 with SMTP id j1mr418264edj.111.1504529313356;
            Mon, 04 Sep 2017 05:48:33 -0700 (PDT)
    ARC-Seal: i=1; a=rsa-sha256; t=1504529313; cv=none;
            d=google.com; s=arc-20160816;
            b=xy8M+YmuIWiQV1m7CX7ds27IT4vzPEGKgohx12PYS1CP6Zb8EMH7BcTSJapdNC/CDx
             95K7gj46REgu0l/tVeHIa4EWswFH0MpUv3B2gcIblBETKb3rLAlveMXDx6UwRVG5I3p1
             gPleOPO5vkWpXgdGG39yCxSO2B9y3m718rkLDWTHjBFcmzWQaP+CCbWGrUWqn7yFcjPV
             1sV/XQH4NHjV750coFyqBX2xGQNLbi8gY7blVGPkKDdufJ1IP7A/ijt/W5h65mbFdgZQ
             54dp09G6JswAaFpjMHSEvJHGWDIrtjyKm1m0SBMJg/tJNnwZMTOlDOk4ChU9vBo/RjS0
             zmVg==
    ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
            h=to:subject:message-id:date:from:mime-version:dkim-signature
             :arc-authentication-results;
            bh=8xFwvb+oSE7R8jdg0AMi4zaceot99IFg5FcPyK3ZssU=;
            b=J/I40u/EpE9V6Qzk3/oK2dBExdzPPlHkTQ0SWjBHbv0Oehh7rr1/bllgLhroyZHWvt
             w5Ypc3S4Q1j3cCBMIURCLi+XAL7qXrKKMfNsSAXfgJY3lK57R+mYq+kPcBq8x3LWe5W8
             ntfeDGsKrncJ/HxAIdHj2uHYdEmRfjvnxuWnY9k6aCKHMDiJKoJusMq3HJ3mtf+O8XJY
             rva28kqc73rLWgkgigNZiB53OC6B5RTEZ+UHFdSZB65Oer5LHMVJPqo3kaqFes31FMCk
             HO0jq2Fqu26jug0tAIbGyNy0GkPzpyn+je6dOLyWv8Ls8LPercHObrpLJMm3CIomKLZB
             wMvQ==
    ARC-Authentication-Results: i=1; mx.google.com;
           dkim=pass header.i=@xxx-com-ar.20150623.gappssmtp.com header.s=20150623 header.b=U8sqTlzp;
           spf=pass (xxx.com: domain of xxx@xxx.com.ar designates 2a00:1450:400c:c09::22a as permitted sender) smtp.mailfrom=xxx@xxx.com.ar
    Return-Path: <xxx@xxx.com.ar>
    Received: from mail-wm0-x22a.google.com (mail-wm0-x22a.xxx.com. [2a00:1450:400c:c09::22a])
            by mx.xxx.com with ESMTPS id g4si6534568ede.342.2017.09.04.05.48.33
            for <xxx@xxx.com>
            (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
            Mon, 04 Sep 2017 05:48:33 -0700 (PDT)
    Received-SPF: pass (xxx.com: domain of xxx@xxxcom.ar designates 2a00:1450:400c:c09::22a as permitted sender) client-ip=2a00:1450:400c:c09::22a;
    Authentication-Results: mx.xxx.com;
           dkim=pass header.i=@xxxcom-ar.20150623.gappssmtp.com header.s=20150623 header.b=U8sqTlzp;
           spf=pass (xxx.com: domain of xxx@xxxcom.ar designates 2a00:1450:400c:c09::22a as permitted sender) smtp.mailfrom=xxx@xxx.com.ar
    Received: by mail-wm0-x22a.google.com with SMTP id v2so3512271wmf.0
            for <xxx@xxxcom>; Mon, 04 Sep 2017 05:48:33 -0700 (PDT)
    DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
            d=xxx-com-ar.20150623.gappssmtp.com; s=20150623;
            h=mime-version:from:date:message-id:subject:to;
            bh=8xFwvb+oSE7R8jdg0AMi4zaceot99IFg5FcPyK3ZssU=;
            b=U8sqTlzpUV1yrRN7zOyj2nTQncAR8bEKhKc4BOUKoa3YZrjQfHVtiluux4oxK1yOlM
             pOx+F4YQWrPXab6VwIV6e1Q9b4+Uf50EZqo1FzkHXKVUOphuFAeU8pMSzG0pYCn2HPG+
             yfpH/AXeCLwPUh0tGGXLY5Q3kVM/8c5XpRwqWgzUSRC/Lorp/6OonodnlMNglHVWxsAG
             /ddfGdyeg5J15CMtPg35gqD7mJhgfW8lBbbdSXpM6HwMPQ0mYzwNP6mlrT73dxOKMIvr
             M3jbfBF+QX50IEkLqxxpHMtzAjW0sB/wGsL0m190HE2uQfnL6dQ1SFqetvT15LIEhoZK
             rlfg==
    X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
            d=1e100.net; s=20161025;
            h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
            bh=8xFwvb+oSE7R8jdg0AMi4zaceot99IFg5FcPyK3ZssU=;
            b=N5VGh9SBksbpXwQGG3a5VdYDtC4rf+EJNWOri6ink5x4Wr4yln+HWw8qf25I4Bzzy4
             NilJGrz8K+nc4Yw269PauabHifvmO1FYIsCrdS5OfkCKamBvRKlWDxU5C3rKHS77OrrZ
             cjwcgZpc91SgkuJECT7RErJnPKViqC44VCmcxjQ1S5wav+EWjZ0duiJAvMf5SYGzO3/n
             8TAsh+zDcpOLbepSkIujx1NioaitX+rT6oLhg7KoUoDyo2zaTOITvVj4DSYime96drny
             XeBdOI/sKOUi3zNLZ9uo044S6+8hRmQ4W5+ngiISXtpeo8++romYYWxZMLloeAjpApoZ
             bmkg==
    X-Gm-Message-State: AHPjjUhQKn86GqYelPCglV8F3mgM4sJdBZFLCv3lRtbhMO4iqS9SA9rn
    Ri5XOqPQBWdN87uEa7uJ8j+kvS7VJxVI
    X-Google-Smtp-Source: ADKCNb50qSZ90SdKbZqSTBTbx1RXowlXzlgBCrW7LR8CIE5gMe1kEvpiv4pqGJ7o/7J9D8uwCmw4Lo9qtAdeqGkYqWE=
    X-Received: by 10.28.166.141 with SMTP id p135mr209866wme.131.1504529312548;
     Mon, 04 Sep 2017 05:48:32 -0700 (PDT)
    MIME-Version: 1.0
    Received: by 10.223.183.37 with HTTP; Mon, 4 Sep 2017 05:48:11 -0700 (PDT)
    From: "xxx xxx" <xxx@xxx.com.ar>
    Date: Mon, 4 Sep 2017 09:48:11 -0300
    Message-ID: <CAJopg6m_W9VPqKNrj1nh_8RcnTHrWvqVN8=onH=RZM2d=bOqyw@mail.xxx.com>
    Subject: prueba 20170904
    To: xxx@xxx.com
    Content-Type: multipart/mixed; boundary="94eb2c12d29a3af7f205585c8748"

    --94eb2c12d29a3af7f205585c8748
    Content-Type: multipart/alternative; boundary="94eb2c12d29a3af7f005585c8746"

    --94eb2c12d29a3af7f005585c8746
    Content-Type: text/plain; charset="UTF-8"

    con adjunto

    -- 
    -----------------------------
    This message may contain confidential and/or privileged information. If you
    are not the addressee or authorized to receive this for the addressee, you
    must not use, copy, disclose or take any action based on this message or
    any information herein. If you have received this message in error, please
    advise the sender immediately by reply mail and delete this message. Thank
    you for your cooperation.
    -----------------------------

    --94eb2c12d29a3af7f005585c8746
    Content-Type: text/html; charset="UTF-8"
    Content-Transfer-Encoding: quoted-printable

    <div dir=3D"ltr">con adjunto<br clear=3D"all"><div><br></div>-- <br><div cl=
    ass=3D"xxx_signature" data-smartmail=3D"xxx_signature"><div dir=3D"ltr"=
    ><div><div dir=3D"ltr"><div><div dir=3D"ltr"><div><div dir=3D"ltr"><div><di=
    v dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=
    =3D"ltr"><div style=3D"color:rgb(80,0,80);font-size:12.8px">David Pavetti<b=
    r>DESOL S.A.</div><div style=3D"color:rgb(80,0,80);font-size:12.8px">0810-3=
    45-DESOL (33765)<br><span dir=3D"ltr"><span dir=3D"ltr"><span><img height=
    =3D"0" width=3D"0"><span>+54-351-570-3232</span><span></span></span></span>=
    </span><br>+54-9-351-2404749<br><a href=3D"http://www.desol.com.ar/" target=
    =3D"_blank">www.desol.com.ar</a><br><br>-----------------------------<br>Th=
    is
     message may contain confidential and/or privileged information. If you=20
    are not the addressee or authorized to receive this for the addressee,=20
    you must not use, copy, disclose or take any action based on this=20
    message or any information herein. If you have received this message in=20
    error, please advise the sender immediately by reply mail and delete=20
    this message. Thank you for your cooperation.<br>--------------------------=
    ---</div></div></div></div></div></div></div></div></div></div></div></div>=
    </div></div></div>
    </div>

    --94eb2c12d29a3af7f005585c8746--
    --94eb2c12d29a3af7f205585c8748
    Content-Type: text/plain; charset="US-ASCII"; name="test.txt"
    Content-Dis; filename="test.txt"
    Content-Transfer-Encoding: base64
    X-Attachment-Id: f_j765v7uh0

    dGVzdA==
    --94eb2c12d29a3af7f205585c8748--

    Yo necesito obtener para guardar:

    Columna Imagen = dGVzdA

    Columna nombreArchivo = test.txt

    (el boundary del adjunto se ecuentra al final del codigo)

    Desde ya muchas gracias, como siempre


    • Editado DaviT Cba miércoles, 27 de septiembre de 2017 19:05
    martes, 26 de septiembre de 2017 19:32