Skip to content

Commit

Permalink
Fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
mooijtech committed Jun 13, 2023
1 parent 6fc36ff commit a8061d9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
9 changes: 0 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,3 @@ require (
github.com/philhofer/fwd v1.1.2 // indirect
golang.org/x/sys v0.8.0 // indirect
)

retract (
[v0.0.1, v0.0.11]
v1.0.0
[v2.0.1, v2.0.2]
[v3.0.0, v3.2.1]
v4.0.0
[v5.0.0, v5.0.4]
)
46 changes: 45 additions & 1 deletion pkg/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
package pst

import (
"github.com/mooijtech/go-pst/pkg/properties"
"github.com/mooijtech/go-pst/v6/pkg/properties"
"io"

"github.com/rotisserie/eris"
)

// Attachment represents a message attachment.
type Attachment struct {
Identifier Identifier
PropertyContext *PropertyContext
LocalDescriptors []LocalDescriptor
properties.Attachment
Expand Down Expand Up @@ -163,6 +164,7 @@ func (message *Message) GetAttachment(attachmentIndex int) (*Attachment, error)
}

attachment := &Attachment{
Identifier: attachmentLocalDescriptor.Identifier,
PropertyContext: attachmentPropertyContext,
LocalDescriptors: attachmentLocalDescriptors,
}
Expand All @@ -174,6 +176,48 @@ func (message *Message) GetAttachment(attachmentIndex int) (*Attachment, error)
return attachment, nil
}

// GetAttachment returns the attachment.
// Note that the properties aren't populated (call PropertyContext.Populate).
func (file *File) GetAttachment(messageIdentifier Identifier) (*Attachment, error) {
attachmentsNode, err := file.GetNodeBTreeNode(messageIdentifier)

if err != nil {
return nil, eris.Wrap(err, "failed to find node b-tree node")
}

attachmentsDataNode, err := file.GetBlockBTreeNode(attachmentsNode.DataIdentifier)

if err != nil {
return nil, eris.Wrap(err, "failed to find block b-tree node")
}

attachmentsHeapOnNode, err := file.GetHeapOnNode(attachmentsDataNode)

if err != nil {
return nil, eris.Wrap(err, "failed to get Heap-on-Node")
}

localDescriptors, err := file.GetLocalDescriptors(attachmentsNode)

if err != nil {
return nil, eris.Wrap(err, "failed to find local descriptors")
}

propertyContext, err := file.GetPropertyContext(attachmentsHeapOnNode)

attachment := &Attachment{
Identifier: messageIdentifier,
PropertyContext: propertyContext,
LocalDescriptors: localDescriptors,
}

if err := propertyContext.Populate(attachment, localDescriptors); err != nil {
return nil, eris.Wrap(err, "failed to populate attachment property context")
}

return attachment, nil
}

// GetAllAttachments returns the attachments of this message.
// See AttachmentIterator.
func (message *Message) GetAllAttachments() ([]*Attachment, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package pst
import (
_ "embed"
"fmt"
"github.com/mooijtech/go-pst/pkg/properties"
"github.com/mooijtech/go-pst/v6/pkg/properties"
"github.com/pkg/errors"
"github.com/rotisserie/eris"
"github.com/tinylib/msgp/msgp"
Expand Down

0 comments on commit a8061d9

Please sign in to comment.