Mime+attach

susinmn

Well-known member
16.10.2007
529
3
#1
Set rtdoc=doc.GetFirstItem("Files")
If ( rtdoc.Type = RICHTEXT ) Then
If Not Isempty(rtdoc.EmbeddedObjects) Then
Set mime = result.CreateChildEntity( )
Forall object In rtdoc.EmbeddedObjects
If (object.Type = EMBED_ATTACHMENT ) Then
filepath =Environ("Temp")+"\"+Cstr(Object.name)
Call object.ExtractFile(filepath)

tmp=Evaluate({@ReplaceSubstring(@URLEncode("UTF-8";"}+Strrightback(filepath,"\")+{");"%";"=")})
filename="=?utf-8?Q?"+tmp(0)+"?="

Set mime = result.CreateChildEntity( )
Set hdr = mime.CreateHeader("Content-Disposition")
Call hdr.SetHeaderValAndParams(|attachment; filename="|+filename+|"|)
Set stream = s.CreateStream
stream.Open filepath, "binary"
mime.SetContentFromBytes stream, "application/octet-stream", ENC_BINARY
mime.EncodeContent ENC_BASE64
End If
End Forall
End If
End If

В итоге, если в поле Files 2 файла с одинаковым названием, LN второму *придумывает свое*.
Можно ли это обойти?
Как в mime запихать все, что есть в поле типа RichText (текст, картинки, attach)?

Спасибо

Пришлось делать так:
Dim filenames() As String
i=-1
n=1
Set rtdoc=doc.GetFirstItem("Files")
If ( rtdoc.Type = RICHTEXT ) Then
If Not Isempty(rtdoc.EmbeddedObjects) Then
Set mime = result.CreateChildEntity( )
Forall object In rtdoc.EmbeddedObjects
If (object.Type = EMBED_ATTACHMENT ) Then
filepath =Environ("Temp")+"\"+Cstr(Object.Name)
Call object.ExtractFile(filepath)

tmpSource=Object.Source
i=i+1
NameSource:
If i=0 Then
Redim Preserve filenames(0)
filenames(0)=Object.Source
Else
For j=0 To Ubound(filenames)
If filenames(j)=tmpSource Then
tmpSource=Strleft(Object.Source,".")+Cstr(n)+"."+Strright(Object.Source,".")
n=n+1
Goto NameSource
End If
Next
Redim Preserve filenames(Ubound(filenames)+1)
filenames(Ubound(filenames))=tmpSource
End If

tmp=Evaluate({@ReplaceSubstring(@URLEncode("UTF-8";"}+Cstr(tmpSource)+{");"%";"=")})
filename="=?utf-8?Q?"+tmp(0)+"?="

Set mime = result.CreateChildEntity( )

Set hdr = mime.CreateHeader("Content-Disposition")
Call hdr.SetHeaderValAndParams(|attachment; filename="|+filename+|"|)
Set hdr = mime.createHeader("Content-ID")
Call hdr.setHeaderVal(filename)
Set stream = s.CreateStream
stream.Open filepath, "binary"
mime.SetContentFromBytes stream, |application/octet-stream; name="|+filename+|"|, ENC_BINARY
mime.EncodeContent ENC_BASE64
End If
End Forall
End If
End If