namespace ReadyPOP3
{
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
public class MIMEAttachment
{
private string m_ContentTransferEncoding;
private string m_ContentType;
private string m_Data;
private byte[] m_DecodedData;
private string m_Name;
public static string ConvertFromQuotedPrintable(string dat)
{
string str2 = "";
if ((StringType.StrCmp(dat, "", false) != 0) & !Information.IsNothing(dat))
{
object obj3 = Strings.Split(dat, "\r\n", -1, CompareMethod.Binary);
string vLeft = "";
IEnumerator enumerator = ((IEnumerable)obj3).GetEnumerator();
while (enumerator.MoveNext())
{
bool flag;
string sLeft = StringType.FromObject(enumerator.Current);
if ((StringType.StrCmp(sLeft, "", false) != 0) & !Information.IsNothing(sLeft))
{
sLeft = Strings.Trim(sLeft);
if (StringType.StrCmp(Strings.Right(sLeft, 1), "=", false) == 0)
{
sLeft = Strings.Left(sLeft, Strings.Len(sLeft) - 1);
vLeft = vLeft + sLeft;
flag = false;
}
else
{
object obj2 = null;
object obj4 = null;
flag = true;
Array array = Strings.Split(sLeft, "=", -1, CompareMethod.Binary);
string str6 = "";
string str5 = "";
if (FlowControl.ForLoopInitObj(obj2, 0, Information.UBound(array, 1), 1, ref obj4, ref obj2))
{
do
{
if (ObjectType.ObjTst(obj2, 0, false) == 0)
{
vLeft = StringType.FromObject(ObjectType.StrCatObj(vLeft, LateBinding.LateIndexGet(array, new object[] { RuntimeHelpers.GetObjectValue(obj2) }, null)));
}
else
{
str6 = Strings.Left(StringType.FromObject(LateBinding.LateIndexGet(array, new object[] { RuntimeHelpers.GetObjectValue(obj2) }, null)), 2);
if (Strings.Len(RuntimeHelpers.GetObjectValue(LateBinding.LateIndexGet(array, new object[] { RuntimeHelpers.GetObjectValue(obj2) }, null))) >= 2)
{
str5 = Strings.Right(StringType.FromObject(LateBinding.LateIndexGet(array, new object[] { RuntimeHelpers.GetObjectValue(obj2) }, null)), Strings.Len(RuntimeHelpers.GetObjectValue(LateBinding.LateIndexGet(array, new object[] { RuntimeHelpers.GetObjectValue(obj2) }, null))) - 2);
}
else
{
str5 = "";
}
str6 = StringType.FromChar(Strings.Chr((int) Math.Round(Conversion.Val("&h" + str6))));
vLeft = vLeft + str6 + str5;
}
}
while (FlowControl.ForNextCheckObj(obj2, obj4, ref obj2));
}
}
}
else
{
flag = true;
}
str2 = str2 + vLeft;
if (flag)
{
str2 = str2 + "\r\n";
}
vLeft = "";
}
}
return str2.ToString();
}
private void DecodeData()
{
string contentTransferEncoding = this.ContentTransferEncoding;
if (StringType.StrCmp(contentTransferEncoding, "7bit", false) == 0)
{
this.m_DecodedData = new ASCIIEncoding().GetBytes(this.m_Data);
}
else if (StringType.StrCmp(contentTransferEncoding, "base64", false) == 0)
{
this.m_DecodedData = Convert.FromBase64String(this.m_Data);
}
else if (StringType.StrCmp(contentTransferEncoding, "quoted-printable", false) == 0)
{
this.m_DecodedData = this.StrToByteArray(ConvertFromQuotedPrintable(this.m_Data));
}
else if (StringType.StrCmp(contentTransferEncoding, "8bit", false) == 0)
{
this.m_DecodedData = Encoding.UTF8.GetBytes(this.m_Data);
}
else if (StringType.StrCmp(contentTransferEncoding, "binary", false) == 0)
{
this.m_DecodedData = Encoding.UTF8.GetBytes(this.m_Data);
}
}
public void SaveAs(string filename)
{
try
{
FileStream stream = File.OpenWrite(filename);
stream.Write(this.DecodedData, 0, this.DecodedData.Length);
stream.Close();
}
catch (Exception exception1)
{
ProjectData.SetProjectError(exception1);
Information.Err().Raise(1, null, this.DecodedData.Length, null, null);
ProjectData.ClearProjectError();
}
}
private byte[] StrToByteArray(string str)
{
ASCIIEncoding encoding = new ASCIIEncoding();
return encoding.GetBytes(str);
}
public string ToaString()
{
this.DecodeData();
StringBuilder builder = new StringBuilder();
foreach (byte num in this.DecodedData)
{
builder.Append(Convert.ToChar(num));
}
return builder.ToString();
}
public string ContentTransferEncoding
{
get
{
return this.m_ContentTransferEncoding.ToLower();
}
set
{
this.m_ContentTransferEncoding = value;
}
}
public string ContentType
{
get
{
return this.m_ContentType.ToLower();
}
set
{
this.m_ContentType = value;
}
}
public string Data
{
get
{
return this.m_Data;
}
set
{
this.m_Data = value;
}
}
public byte[] DecodedData
{
get
{
if (this.m_DecodedData == null)
{
this.DecodeData();
}
return this.m_DecodedData;
}
}
public string Name
{
get
{
return this.m_Name;
}
set
{
this.m_Name = value;
}
}
}
}