Debian Codegraph @

server/backend/attachment.go

raw
1 package backend
2
3 import (
4 "encoding/base64"
5
6 "github.com/ProtonMail/gluon/rfc822"
7 "github.com/google/uuid"
8 "github.com/henrybear327/go-proton-api"
9 )
10
11 func (b *Backend) createAttData(dataPacket []byte) string {
12 attDataID := uuid.NewString()
13
14 b.attDataLock.Lock()
15 defer b.attDataLock.Unlock()
16
17 b.attData[attDataID] = dataPacket
18
19 return attDataID
20 }
21
22 type attachment struct {
23 attachID string
24 attDataID string
25
26 filename string
27 mimeType rfc822.MIMEType
28 disposition proton.Disposition
29
30 keyPackets []byte
31 armSig string
32 }
33
34 func newAttachment(
35 filename string,
36 mimeType rfc822.MIMEType,
37 disposition proton.Disposition,
38 keyPackets []byte,
39 dataPacketID string,
40 armSig string,
41 ) *attachment {
42 return &attachment{
43 attachID: uuid.NewString(),
44 attDataID: dataPacketID,
45
46 filename: filename,
47 mimeType: mimeType,
48 disposition: disposition,
49
50 keyPackets: keyPackets,
51 armSig: armSig,
52 }
53 }
54
55 func (att *attachment) toAttachment() proton.Attachment {
56 return proton.Attachment{
57 ID: att.attachID,
58
59 Name: att.filename,
60 MIMEType: att.mimeType,
61 Disposition: att.disposition,
62
63 KeyPackets: base64.StdEncoding.EncodeToString(att.keyPackets),
64 Signature: att.armSig,
65 }
66 }