I have an email with attachments which seems to be empty so when parsing the body and when the ReadDisposition method runs, the "type" variable contains only a date, not the word "attachment".
The following (see below "Temp fix") solves my problem but what would be the proper way to deal with this issue?
private ContentDisposition ReadDisposition()
{
SkipSpaces();
var sb = new StringBuilder();
char currentChar;
while ((currentChar = (char)_reader.Read()) != '(')
{
sb.Append(currentChar);
if (sb.ToString() == "NIL")
return null;
if (currentChar == Convert.ToChar(65535)) return null;
}
var type = ReadString().ToLower();
var paramaters = ReadParameterList();
ContentDisposition disposition;
try
{
disposition = new ContentDisposition(type);
}
catch (Exception ex)
{
//
// Temp fix
//
// below I added a check to see if "type" contains the word "attachment", and if not then
// I just set disposition to null, ... but if it does, the original "throw New exeption" occurs
//
//
if (type.Contains("attachment"))
{
throw new Exception("Failed on: " + type, ex);
}
else
{
disposition = null;
}
}
foreach (var paramater in paramaters)
{
switch (paramater.Key)
{
case "filename":
case "name":
disposition.FileName = StringDecoder.Decode(paramater.Value, true);
break;
}
}
SkipSpaces();
_reader.Read(); // read ')'
SkipSpaces();
return disposition;
}
The following (see below "Temp fix") solves my problem but what would be the proper way to deal with this issue?
private ContentDisposition ReadDisposition()
{
SkipSpaces();
var sb = new StringBuilder();
char currentChar;
while ((currentChar = (char)_reader.Read()) != '(')
{
sb.Append(currentChar);
if (sb.ToString() == "NIL")
return null;
if (currentChar == Convert.ToChar(65535)) return null;
}
var type = ReadString().ToLower();
var paramaters = ReadParameterList();
ContentDisposition disposition;
try
{
disposition = new ContentDisposition(type);
}
catch (Exception ex)
{
//
// Temp fix
//
// below I added a check to see if "type" contains the word "attachment", and if not then
// I just set disposition to null, ... but if it does, the original "throw New exeption" occurs
//
//
if (type.Contains("attachment"))
{
throw new Exception("Failed on: " + type, ex);
}
else
{
disposition = null;
}
}
foreach (var paramater in paramaters)
{
switch (paramater.Key)
{
case "filename":
case "name":
disposition.FileName = StringDecoder.Decode(paramater.Value, true);
break;
}
}
SkipSpaces();
_reader.Read(); // read ')'
SkipSpaces();
return disposition;
}