O
Ole K
In my last thread
http://social.technet.microsoft.com...e87-c17a-4e73-8465-4c096555d004?prof=required
I asked about the possibility to add Content-ID Header. That was solved. But
in my last reply to my own question I still have no response.
So i 'd like to ask the question again:
How can I add th "Content-Disposition:" header into Attachment headers?
For example i tried this:
writer.StartProperty(new
TnefPropertyTag(TnefPropertyId.AttachDisposition, TnefPropertyType.String8));
writer.WritePropertyValue(RANDOMKEY);
But it was not working. But content Id works in this place.... Here again th
full source of the function:
private
void
AttachmentFromTNEF(ref
EmailMessage emailMessage){
TnefReader reader = new
TnefReader(emailMessage.TnefPart.GetContentReadStream(), 0,
TnefComplianceMode.Loose);
short
key = reader.AttachmentKey;<br/>
TnefWriter writer = new
TnefWriter(emailMessage.TnefPart.GetContentWriteStream("Binary"
), key);
int
attachmentCount = 0;
int
foundFile = 0;
try
{
#region
Attachment handling in TNEF format, insert properties for LOGO
while
(reader.ReadNextAttribute())
{
if
(reader.AttributeLevel == TnefAttributeLevel.Attachment)
{
Debug.WriteLine(attachmentCount + " - AttributeTag: "
+ reader.AttributeTag.ToString());
if
(reader.AttributeTag == TnefAttributeTag.AttachRenderData)
attachmentCount++;
switch
(reader.AttributeTag)
{
case
TnefAttributeTag.AttachTitle:
writer.StartAttribute(reader.AttributeTag,
reader.AttributeLevel);
if
(attachmentCount > 0)
{
while
(reader.PropertyReader.ReadNextProperty())
{
Debug.WriteLine("AttachTitle -
PropertyId: "
+ reader.PropertyReader.PropertyTag.Id.ToString());
if
(reader.PropertyReader.PropertyTag.Id == TnefPropertyId.AttachFilename)
{
string
pr = reader.PropertyReader.ReadValueAsString();
if
(pr == RANDOMKEY)
foundFile = attachmentCount;
writer.WriteProperty(reader.PropertyReader.PropertyTag, pr);
}
else
{
writer.WriteProperty(reader.PropertyReader);
}
}
}
else
{
writer.WriteAllProperties(reader.PropertyReader);
}
break
;
case
TnefAttributeTag.Attachment:
if
(foundFile == attachmentCount && attachmentCount > 0)
{
writer.WriteAllProperties(reader.PropertyReader);
writer.StartProperty(new
TnefPropertyTag(TnefPropertyId.AttachDisposition, TnefPropertyType.String8));
writer.WritePropertyValue("Inline"
);
}
else
{
writer.WriteAttribute(reader);
}
break
;
default
:
writer.WriteAttribute(reader);
break
;
}
}
else
{
writer.WriteAttribute(reader);
}
}
#endregion
Debug.WriteLine("Found "
+ attachmentCount + " attachment(s)"
);
}
catch
(Exception x)
{
myLog.WriteEntry("OnAttachmentParse: "
+ x.Message + x.StackTrace, EventLogEntryType.Error);
}
finally
{
writer.Close();
reader.Close();
}
}
http://social.technet.microsoft.com...e87-c17a-4e73-8465-4c096555d004?prof=required
I asked about the possibility to add Content-ID Header. That was solved. But
in my last reply to my own question I still have no response.
So i 'd like to ask the question again:
How can I add th "Content-Disposition:" header into Attachment headers?
For example i tried this:
writer.StartProperty(new
TnefPropertyTag(TnefPropertyId.AttachDisposition, TnefPropertyType.String8));
writer.WritePropertyValue(RANDOMKEY);
But it was not working. But content Id works in this place.... Here again th
full source of the function:
private
void
AttachmentFromTNEF(ref
EmailMessage emailMessage){
TnefReader reader = new
TnefReader(emailMessage.TnefPart.GetContentReadStream(), 0,
TnefComplianceMode.Loose);
short
key = reader.AttachmentKey;<br/>
TnefWriter writer = new
TnefWriter(emailMessage.TnefPart.GetContentWriteStream("Binary"
), key);
int
attachmentCount = 0;
int
foundFile = 0;
try
{
#region
Attachment handling in TNEF format, insert properties for LOGO
while
(reader.ReadNextAttribute())
{
if
(reader.AttributeLevel == TnefAttributeLevel.Attachment)
{
Debug.WriteLine(attachmentCount + " - AttributeTag: "
+ reader.AttributeTag.ToString());
if
(reader.AttributeTag == TnefAttributeTag.AttachRenderData)
attachmentCount++;
switch
(reader.AttributeTag)
{
case
TnefAttributeTag.AttachTitle:
writer.StartAttribute(reader.AttributeTag,
reader.AttributeLevel);
if
(attachmentCount > 0)
{
while
(reader.PropertyReader.ReadNextProperty())
{
Debug.WriteLine("AttachTitle -
PropertyId: "
+ reader.PropertyReader.PropertyTag.Id.ToString());
if
(reader.PropertyReader.PropertyTag.Id == TnefPropertyId.AttachFilename)
{
string
pr = reader.PropertyReader.ReadValueAsString();
if
(pr == RANDOMKEY)
foundFile = attachmentCount;
writer.WriteProperty(reader.PropertyReader.PropertyTag, pr);
}
else
{
writer.WriteProperty(reader.PropertyReader);
}
}
}
else
{
writer.WriteAllProperties(reader.PropertyReader);
}
break
;
case
TnefAttributeTag.Attachment:
if
(foundFile == attachmentCount && attachmentCount > 0)
{
writer.WriteAllProperties(reader.PropertyReader);
writer.StartProperty(new
TnefPropertyTag(TnefPropertyId.AttachDisposition, TnefPropertyType.String8));
writer.WritePropertyValue("Inline"
);
}
else
{
writer.WriteAttribute(reader);
}
break
;
default
:
writer.WriteAttribute(reader);
break
;
}
}
else
{
writer.WriteAttribute(reader);
}
}
#endregion
Debug.WriteLine("Found "
+ attachmentCount + " attachment(s)"
);
}
catch
(Exception x)
{
myLog.WriteEntry("OnAttachmentParse: "
+ x.Message + x.StackTrace, EventLogEntryType.Error);
}
finally
{
writer.Close();
reader.Close();
}
}