Decoding Attachment from rfc822?
-
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--
-
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--
-
As the content information tells you, it's base64 encoded. Take a look at the
Convert.FromBase64String
method.--- single minded; short sighted; long gone;
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); }
-
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); }