Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Decoding Attachment from rfc822?

Decoding Attachment from rfc822?

Scheduled Pinned Locked Moved C#
questionhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eddymvp
    wrote on last edited by
    #1

    I can't seems to find enough sources to decode an attachment. I get the following line. it tells me the name of the image and what type of content is it. ------=_NextPart_000_0010_01C74AC1.03E2B080 Content-Type: image/gif; name="mapping.gif" Content-ID: 001301c74ac1$03e2b080$0124cc3c@VALERIA Content-Transfer-Encoding: base64 Where i'm having problem is on the attachment that will look like this, how can i convert that? R0lGODlhygHoAIcAAAAAAP///5n///8A/wD//1Vm//+Z//+q/1X///8R/wBm//8i//8z/xH/ /5lm/wAAmTOIIv8AAGb//yL//0T//4j//8z//93///9E/wCZZplE//8zADNmmcwAACLdAP/M ////AGbud///Zv+Imf93////d//d////mf/u///d3f//u///iP//7v//qv//3f//zP+I//+7 4xgYGE1NTYKCgre3t+zs7CEhIVZWVouLi8DAwPX19SoqKl9fX5SUlMnJyf7+/jMzM2hoaJ2d ------=_NextPart_000_0010_01C74AC1.03E2B080--

    G 1 Reply Last reply
    0
    • E Eddymvp

      I can't seems to find enough sources to decode an attachment. I get the following line. it tells me the name of the image and what type of content is it. ------=_NextPart_000_0010_01C74AC1.03E2B080 Content-Type: image/gif; name="mapping.gif" Content-ID: 001301c74ac1$03e2b080$0124cc3c@VALERIA Content-Transfer-Encoding: base64 Where i'm having problem is on the attachment that will look like this, how can i convert that? R0lGODlhygHoAIcAAAAAAP///5n///8A/wD//1Vm//+Z//+q/1X///8R/wBm//8i//8z/xH/ /5lm/wAAmTOIIv8AAGb//yL//0T//4j//8z//93///9E/wCZZplE//8zADNmmcwAACLdAP/M ////AGbud///Zv+Imf93////d//d////mf/u///d3f//u///iP//7v//qv//3f//zP+I//+7 4xgYGE1NTYKCgre3t+zs7CEhIVZWVouLi8DAwPX19SoqKl9fX5SUlMnJyf7+/jMzM2hoaJ2d ------=_NextPart_000_0010_01C74AC1.03E2B080--

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      As the content information tells you, it's base64 encoded. Take a look at the Convert.FromBase64String method.

      --- single minded; short sighted; long gone;

      E 1 Reply Last reply
      0
      • G Guffa

        As the content information tells you, it's base64 encoded. Take a look at the Convert.FromBase64String method.

        --- single minded; short sighted; long gone;

        E Offline
        E Offline
        Eddymvp
        wrote on last edited by
        #3

        thanks for the reply Guffa, i did a search on the Convert.FromBase64String and found a good source of code in http://msdn2.microsoft.com/en-us/library/system.convert.frombase64string(VS.71).aspx[^] however when I run the following code I get the error Base 64 string length is not 4 or is not an even multiple of 4. Did I miss something or Am I doing something wrong? byte[] binaryData; try { binaryData = System.Convert.FromBase64String(attach); } catch (System.ArgumentNullException) { MessageBox.Show("Base 64 string is null."); return; } catch (System.FormatException) { MessageBox.Show("Base 64 string length is not " + "4 or is not an even multiple of 4." ); return; } // Write out the decoded data. System.IO.FileStream outFile; try { outFile = new System.IO.FileStream(Application.StartupPath+"\\josetest.gif", System.IO.FileMode.Create, System.IO.FileAccess.Write); outFile.Write(binaryData, 0, binaryData.Length); outFile.Close(); } catch (System.Exception exp) { // Error creating stream or writing to it. System.Console.WriteLine("{0}", exp.Message); }

        G 1 Reply Last reply
        0
        • E Eddymvp

          thanks for the reply Guffa, i did a search on the Convert.FromBase64String and found a good source of code in http://msdn2.microsoft.com/en-us/library/system.convert.frombase64string(VS.71).aspx[^] however when I run the following code I get the error Base 64 string length is not 4 or is not an even multiple of 4. Did I miss something or Am I doing something wrong? byte[] binaryData; try { binaryData = System.Convert.FromBase64String(attach); } catch (System.ArgumentNullException) { MessageBox.Show("Base 64 string is null."); return; } catch (System.FormatException) { MessageBox.Show("Base 64 string length is not " + "4 or is not an even multiple of 4." ); return; } // Write out the decoded data. System.IO.FileStream outFile; try { outFile = new System.IO.FileStream(Application.StartupPath+"\\josetest.gif", System.IO.FileMode.Create, System.IO.FileAccess.Write); outFile.Write(binaryData, 0, binaryData.Length); outFile.Close(); } catch (System.Exception exp) { // Error creating stream or writing to it. System.Console.WriteLine("{0}", exp.Message); }

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          What does the attach string contain? If you just ripped it from the mail, you have to remove the line breaks from it, so that it only contains the base64 data.

          --- single minded; short sighted; long gone;

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups