R
romanko
Нужна помощь в написании агента. Есть код представленный ниже, который берет приатачменный файл, который находится в кодировке OEM 866 перегоняется в кодировку вин 1251 и сохраняется в файл в кодировке utf-8. Как этот код переделать, чтобы подкинуть его в агент который должен срабатывать по событию получение нового письма?
Sub Click(Source As Button)
Dim doc As NotesDocument
Dim rtitem As Variant
Dim sourceName As String
Dim uiDoc As NotesUiDocument
Dim ws As New NotesUIWorkspace
Dim result As NotesMIMEEntity
Dim s As New NotesSession
Dim item As notesitem
Dim mystring As String
Dim res As Integer
Dim Tmp1 As String
Dim neoEmbedAttachment As NotesEmbeddedObject
Dim nrimAttachment As NotesRichTextItem
Dim varFilePath As Variant
Dim strFilePath As String
Dim session As New NotesSession
Dim strFieldname As String
Dim rtdoc As Variant
'_________________________достаем путь прикрепленного файла
If doc.GetItemValue("From")(0) <> "CN=Vasya V Pupkin/O=Roga And Copyta" Then
Set uiDoc = ws.CurrentDocument
Set doc = uiDoc.Document
Set result = doc.CreateMIMEEntity
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)
'____________________________________________________________________
outputFile = Freefile()
fileName$ = "C:\111.xml"
Open fileName$ For Output As outputFile Charset = "UTF-8"
fileNum = Freefile()
Open filepath For Input As fileNum
Do While Not Eof(fileNum)
Line Input #fileNum, MyTmpString
Tmp1 = MyTmpString
res = DosToWin(MyTmpString,Tmp1)
Print #outputFile, Tmp1
Loop
Close outputFile
Close fileNum
Call object.Remove 'удаление прикрепленного файла
'_______________________________________________берем этот файл и приатачеваем его
Set nrimAttachment = doc.GetFirstItem("Files")
Set neoEmbedAttachment = nrimAttachment.EmbedObject( EMBED_ATTACHMENT, "", fileName$)
Set nudWebdoc = ws.CurrentDocument
Set ndocBackWebdoc = nudWebdoc.Document
strFieldname = uidoc.CurrentField
Set nrimAttachment = doc.GetFirstItem("Files")
If session.NotesBuildVersion >= 190 Then
nrimAttachment.Update
Else
Call doc.ComputeWithForm(True, False)
End If
Set Doc = uiDoc.Document
Call doc.Save( True, True )
doc.SaveOptions = "0"
Call uidoc.Close(True)
Set uidocNew = ws.EditDocument(True, ndocBackWebdoc, , , , True)
Delete uidoc
uidocNew.Document.RemoveItem("SaveOptions")
If strFieldname <> "" Then uidocNew.GotoField(strFieldname)
Kill "C:\111.xml" ' удаляет файл с винта
End If
End Forall
End If
End If
End Sub
Sub Click(Source As Button)
Dim doc As NotesDocument
Dim rtitem As Variant
Dim sourceName As String
Dim uiDoc As NotesUiDocument
Dim ws As New NotesUIWorkspace
Dim result As NotesMIMEEntity
Dim s As New NotesSession
Dim item As notesitem
Dim mystring As String
Dim res As Integer
Dim Tmp1 As String
Dim neoEmbedAttachment As NotesEmbeddedObject
Dim nrimAttachment As NotesRichTextItem
Dim varFilePath As Variant
Dim strFilePath As String
Dim session As New NotesSession
Dim strFieldname As String
Dim rtdoc As Variant
'_________________________достаем путь прикрепленного файла
If doc.GetItemValue("From")(0) <> "CN=Vasya V Pupkin/O=Roga And Copyta" Then
Set uiDoc = ws.CurrentDocument
Set doc = uiDoc.Document
Set result = doc.CreateMIMEEntity
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)
'____________________________________________________________________
outputFile = Freefile()
fileName$ = "C:\111.xml"
Open fileName$ For Output As outputFile Charset = "UTF-8"
fileNum = Freefile()
Open filepath For Input As fileNum
Do While Not Eof(fileNum)
Line Input #fileNum, MyTmpString
Tmp1 = MyTmpString
res = DosToWin(MyTmpString,Tmp1)
Print #outputFile, Tmp1
Loop
Close outputFile
Close fileNum
Call object.Remove 'удаление прикрепленного файла
'_______________________________________________берем этот файл и приатачеваем его
Set nrimAttachment = doc.GetFirstItem("Files")
Set neoEmbedAttachment = nrimAttachment.EmbedObject( EMBED_ATTACHMENT, "", fileName$)
Set nudWebdoc = ws.CurrentDocument
Set ndocBackWebdoc = nudWebdoc.Document
strFieldname = uidoc.CurrentField
Set nrimAttachment = doc.GetFirstItem("Files")
If session.NotesBuildVersion >= 190 Then
nrimAttachment.Update
Else
Call doc.ComputeWithForm(True, False)
End If
Set Doc = uiDoc.Document
Call doc.Save( True, True )
doc.SaveOptions = "0"
Call uidoc.Close(True)
Set uidocNew = ws.EditDocument(True, ndocBackWebdoc, , , , True)
Delete uidoc
uidocNew.Document.RemoveItem("SaveOptions")
If strFieldname <> "" Then uidocNew.GotoField(strFieldname)
Kill "C:\111.xml" ' удаляет файл с винта
End If
End Forall
End If
End If
End Sub