0

It occured an error "file error".My code followed When importing into windows,no error occured.But the detail is not like the detail by outlook. When importing into mac,error named "file error" occured.

package main

import (
    "encoding/base64"
    "fmt"
    "github.com/go-ole/go-ole"
    "github.com/go-ole/go-ole/oleutil"
    "io/ioutil"
)

func main() {
    ole.CoInitialize(0)
    session, err := oleutil.CreateObject("Redemption.RDOSession")
    if err != nil {
        fmt.Println(err)
        return
    }

    s, err := session.QueryInterface(ole.IID_IDispatch)
    if err != nil {
        fmt.Println(err)
        return
    }

    // create a pst file
    p := `E:\go_project\src\github.com\outlook-ical-export\redemption\t21.pst`
    store, err := oleutil.CallMethod(s, "LogonPstStore", p, 1, "", "", 2)
    if err != nil {
        fmt.Println(store, err)
        return
    }

    // get a folder object
    inbox, err := s.CallMethod("GetDefaultFolder", 6)
    if err != nil {
        fmt.Println(inbox, err)
        return
    }

    stores := oleutil.MustGetProperty(s, "Stores").ToIDispatch()

    defaultStore := oleutil.MustGetProperty(stores, "DefaultStore").ToIDispatch()
    IPMRootFolder := oleutil.MustGetProperty(defaultStore, "IPMRootFolder").ToIDispatch()
    IPMFolders := oleutil.MustGetProperty(IPMRootFolder, "Folders").ToIDispatch()

    newFolder := oleutil.MustCallMethod(IPMFolders, "Add", "test21").ToIDispatch()
    newFolderItems := oleutil.MustGetProperty(newFolder, "Items").ToIDispatch()
    RDOMail, err := newFolderItems.CallMethod("Add", "IPM.Note")
    if err != nil{
        fmt.Println(RDOMail, err)
        return
    }
    data := "base64"
    ftsDataPath:= `E:\go_project\src\github.com\outlook-ical-export\redemption\test21.txt`

    d, err := base64.StdEncoding.DecodeString(data)
    err = ioutil.WriteFile(ftsDataPath, d, 0644)
    if err != nil {
        panic(err)
    }

    _, err = RDOMail.ToIDispatch().CallMethod("Import", ftsDataPath, 1034)
    if err != nil{
        panic(err)
    }
    _, err = RDOMail.ToIDispatch().CallMethod("Save")
    if err != nil{
        panic(err)
    }

    _, err = defaultStore.CallMethod("Remove")
    if err != nil{
        panic(err)
    }

    v, err := s.GetProperty("FastShutdownSupported")
    if err != nil{
        fmt.Println(err)
    }

    if v.Value() != nil && v.Value().(bool){
        _, err = s.CallMethod("DoFastShutdown")
        if err != nil{
            fmt.Println(err)
        }
    }else {
        _, err = s.CallMethod("Logoff")
        if err != nil{
            fmt.Println(err)
        }
    }

    return
}
schlebe
  • 3,387
  • 5
  • 37
  • 50
catFly
  • 59
  • 7
  • I have solve it. Refering to the [link](https://stackoverflow.com/questions/70872858/how-can-i-transfer-ews-get-item-body-to-pst-file-via-golang-or-other-language-bu/71220027#71220027) – catFly Feb 22 '22 at 11:07

1 Answers1

0

The problem may be in encoding which is not related to Redemption at all.

The SaveAs method of the RDOMail class saves the message to the specified path and in the format of the specified file type. Try using it instead.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45