Debian Codegraph @

attachments.go

raw symbols SCIP
1 package mailyakscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/
2
3 import (
4 "encoding/base64scip-go gomod github.com/golang/go/src go1.12 `encoding/base64`/"
5 "fmtscip-go gomod github.com/golang/go/src go1.12 fmt/"
6 "ioscip-go gomod github.com/golang/go/src go1.12 io/"
7 "net/httpscip-go gomod github.com/golang/go/src go1.12 `net/http`/"
8 "net/textprotoscip-go gomod github.com/golang/go/src go1.12 `net/textproto`/"
9 )
10
11 // DetectContentType needs at most 512 bytes
12 const sniffLenscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/sniffLen. = 512
13
14 type partCreatorscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/partCreator# interface {
15 CreatePartscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/partCreator#CreatePart.(header textprotoscip-go gomod github.com/golang/go/src go1.12 `net/textproto`/.MIMEHeaderscip-go gomod github.com/golang/go/src go1.12 `net/textproto`/MIMEHeader#) (ioscip-go gomod github.com/golang/go/src go1.12 io/.Writerscip-go gomod github.com/golang/go/src go1.12 io/Writer#, error)
16 }
17
18 type writeWrapperscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/writeWrapper# interface {
19 newscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/writeWrapper#new.(w ioscip-go gomod github.com/golang/go/src go1.12 io/.Writerscip-go gomod github.com/golang/go/src go1.12 io/Writer#) ioscip-go gomod github.com/golang/go/src go1.12 io/.Writerscip-go gomod github.com/golang/go/src go1.12 io/Writer#
20 }
21
22 type attachmentscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment# struct {
23 filenamescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#filename. string
24 contentscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#content. ioscip-go gomod github.com/golang/go/src go1.12 io/.Readerscip-go gomod github.com/golang/go/src go1.12 io/Reader#
25 inlinescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#inline. bool
26 mimeTypescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#mimeType. string
27 }
28
29 // Attach adds the contents of r to the email as an attachment with name as the
30 // filename.
31 //
32 // r is not read until Send is called and the MIME type will be detected
33 // using https://golang.org/pkg/net/http/#DetectContentType
34 func (m *MailYakscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#) Attachscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#Attach().(name string, r ioscip-go gomod github.com/golang/go/src go1.12 io/.Readerscip-go gomod github.com/golang/go/src go1.12 io/Reader#) {
35 m.attachmentsscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#attachments. = append(m.attachmentsscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#attachments., attachmentscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#{
36 filenamescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#filename.: name,
37 contentscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#content.: r,
38 inlinescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#inline.: false,
39 })
40 }
41
42 // AttachWithMimeType adds the contents of r to the email as an attachment with
43 // name as the filename and mimeType as the specified MIME type of the content.
44 // It is up to the user to ensure the mimeType is correct.
45 //
46 // r is not read until Send is called.
47 func (m *MailYakscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#) AttachWithMimeTypescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#AttachWithMimeType().(name string, r ioscip-go gomod github.com/golang/go/src go1.12 io/.Readerscip-go gomod github.com/golang/go/src go1.12 io/Reader#, mimeType string) {
48 m.attachmentsscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#attachments. = append(m.attachmentsscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#attachments., attachmentscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#{
49 filenamescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#filename.: name,
50 contentscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#content.: r,
51 inlinescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#inline.: false,
52 mimeTypescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#mimeType.: mimeType,
53 })
54 }
55
56 // AttachInline adds the contents of r to the email as an inline attachment.
57 // Inline attachments are typically used within the email body, such as a logo
58 // or header image. It is up to the user to ensure name is unique.
59 //
60 // Files can be referenced by their name within the email using the cid URL
61 // protocol:
62 //
63 // <img src="cid:myFileName"/>
64 //
65 // r is not read until Send is called and the MIME type will be detected
66 // using https://golang.org/pkg/net/http/#DetectContentType
67 func (m *MailYakscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#) AttachInlinescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#AttachInline().(name string, r ioscip-go gomod github.com/golang/go/src go1.12 io/.Readerscip-go gomod github.com/golang/go/src go1.12 io/Reader#) {
68 m.attachmentsscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#attachments. = append(m.attachmentsscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#attachments., attachmentscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#{
69 filenamescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#filename.: name,
70 contentscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#content.: r,
71 inlinescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#inline.: true,
72 })
73 }
74
75 // AttachInlineWithMimeType adds the contents of r to the email as an inline attachment
76 // with mimeType as the specified MIME type of the content. Inline attachments are
77 // typically used within the email body, such as a logo or header image. It is up to the
78 // user to ensure name is unique and the specified mimeType is correct.
79 //
80 // Files can be referenced by their name within the email using the cid URL
81 // protocol:
82 //
83 // <img src="cid:myFileName"/>
84 //
85 // r is not read until Send is called.
86 func (m *MailYakscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#) AttachInlineWithMimeTypescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#AttachInlineWithMimeType().(name string, r ioscip-go gomod github.com/golang/go/src go1.12 io/.Readerscip-go gomod github.com/golang/go/src go1.12 io/Reader#, mimeType string) {
87 m.attachmentsscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#attachments. = append(m.attachmentsscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#attachments., attachmentscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#{
88 filenamescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#filename.: name,
89 contentscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#content.: r,
90 inlinescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#inline.: true,
91 mimeTypescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#mimeType.: mimeType,
92 })
93 }
94
95 // ClearAttachments removes all current attachments.
96 func (m *MailYakscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#) ClearAttachmentsscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#ClearAttachments().() {
97 m.attachmentsscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#attachments. = []attachmentscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#{}
98 }
99
100 // writeAttachments loops over the attachments, guesses their content-type and
101 // writes the data as a line-broken base64 string (using the splitter mutator).
102 func (m *MailYakscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#) writeAttachmentsscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#writeAttachments().(mixed partCreatorscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/partCreator#, splitter writeWrapperscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/writeWrapper#) error {
103 h := make([]byte, sniffLenscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/sniffLen.)
104
105 for _, item := range m.attachmentsscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/MailYak#attachments. {
106 hLen, err := ioscip-go gomod github.com/golang/go/src go1.12 io/.ReadFullscip-go gomod github.com/golang/go/src go1.12 io/ReadFull().(item.contentscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#content., h)
107 if err != nil && err != ioscip-go gomod github.com/golang/go/src go1.12 io/.EOFscip-go gomod github.com/golang/go/src go1.12 io/EOF. && err != ioscip-go gomod github.com/golang/go/src go1.12 io/.ErrUnexpectedEOFscip-go gomod github.com/golang/go/src go1.12 io/ErrUnexpectedEOF. {
108 return err
109 }
110
111 if item.mimeTypescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#mimeType. == "" {
112 item.mimeTypescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#mimeType. = httpscip-go gomod github.com/golang/go/src go1.12 `net/http`/.DetectContentTypescip-go gomod github.com/golang/go/src go1.12 `net/http`/DetectContentType().(h[:hLen])
113 }
114
115 ctype := fmtscip-go gomod github.com/golang/go/src go1.12 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.12 fmt/Sprintf().("%s;\n\tfilename=%q; name=%q", item.mimeTypescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#mimeType., item.filenamescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#filename., item.filenamescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#filename.)
116
117 part, err := mixed.CreatePartscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/partCreator#CreatePart.(getMIMEHeaderscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/getMIMEHeader().(item, ctype))
118 if err != nil {
119 return err
120 }
121
122 encoder := base64scip-go gomod github.com/golang/go/src go1.12 `encoding/base64`/.NewEncoderscip-go gomod github.com/golang/go/src go1.12 `encoding/base64`/NewEncoder().(base64scip-go gomod github.com/golang/go/src go1.12 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.12 `encoding/base64`/StdEncoding., splitter.newscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/writeWrapper#new.(part))
123 if _, err := encoder.Writescip-go gomod github.com/golang/go/src go1.12 io/Writer#Write().(h[:hLen]); err != nil {
124 return err
125 }
126
127 // More to write?
128 if hLen == sniffLenscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/sniffLen. {
129 if _, err := ioscip-go gomod github.com/golang/go/src go1.12 io/.Copyscip-go gomod github.com/golang/go/src go1.12 io/Copy().(encoder, item.contentscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#content.); err != nil {
130 return err
131 }
132 }
133
134 if err := encoder.Closescip-go gomod github.com/golang/go/src go1.12 io/Closer#Close().(); err != nil {
135 return err
136 }
137 }
138
139 return nil
140 }
141
142 func getMIMEHeaderscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/getMIMEHeader().(a attachmentscip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#, ctype string) textprotoscip-go gomod github.com/golang/go/src go1.12 `net/textproto`/.MIMEHeaderscip-go gomod github.com/golang/go/src go1.12 `net/textproto`/MIMEHeader# {
143 var disp string
144 var header textprotoscip-go gomod github.com/golang/go/src go1.12 `net/textproto`/.MIMEHeaderscip-go gomod github.com/golang/go/src go1.12 `net/textproto`/MIMEHeader#
145
146 cid := fmtscip-go gomod github.com/golang/go/src go1.12 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.12 fmt/Sprintf().("<%s>", a.filenamescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#filename.)
147 if a.inlinescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#inline. {
148 disp = fmtscip-go gomod github.com/golang/go/src go1.12 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.12 fmt/Sprintf().("inline;\n\tfilename=%q; name=%q", a.filenamescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#filename., a.filenamescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#filename.)
149 header = textprotoscip-go gomod github.com/golang/go/src go1.12 `net/textproto`/.MIMEHeaderscip-go gomod github.com/golang/go/src go1.12 `net/textproto`/MIMEHeader#{
150 "Content-Type": {ctype},
151 "Content-Disposition": {disp},
152 "Content-Transfer-Encoding": {"base64"},
153 "Content-ID": {cid},
154 }
155 } else {
156 disp = fmtscip-go gomod github.com/golang/go/src go1.12 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.12 fmt/Sprintf().("attachment;\n\tfilename=%q; name=%q", a.filenamescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#filename., a.filenamescip-go gomod github.com/domodwyer/mailyak/v3 . `github.com/domodwyer/mailyak/v3`/attachment#filename.)
157 header = textprotoscip-go gomod github.com/golang/go/src go1.12 `net/textproto`/.MIMEHeaderscip-go gomod github.com/golang/go/src go1.12 `net/textproto`/MIMEHeader#{
158 "Content-Type": {ctype},
159 "Content-Disposition": {disp},
160 "Content-Transfer-Encoding": {"base64"},
161 "Content-ID": {cid},
162 }
163 }
164
165 return header
166 }