Skip to content

Commit

Permalink
Support attached_text (formData.txt)
Browse files Browse the repository at this point in the history
Resolves #437
  • Loading branch information
martinhpedersen committed Dec 29, 2023
1 parent a040c76 commit b58e0fa
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/forms/forms.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type MessageForm struct {
Body string `json:"msg_body"`

attachmentXML string
attachmentTXT string
targetForm Form
isReply bool
submitted time.Time
Expand All @@ -118,6 +119,9 @@ func (m MessageForm) Attachments() []*fbb.File {
name := getXMLAttachmentNameForForm(m.targetForm, m.isReply)
files = append(files, fbb.NewFile(name, []byte(xml)))
}
if txt := m.attachmentTXT; txt != "" {
files = append(files, fbb.NewFile("FormData.txt", []byte(txt)))
}
return files
}

Expand Down Expand Up @@ -911,7 +915,7 @@ type formMessageBuilder struct {
FormsMgr *Manager
}

// build returns message subject, body, and XML attachment content for the given template and variable map
// build returns message subject, body, and attachments for the given template and variable map
func (b formMessageBuilder) build() (MessageForm, error) {
tmplPath := b.Template.TxtFileURI
if b.IsReply && b.Template.ReplyTxtFileURI != "" {
Expand All @@ -929,6 +933,12 @@ func (b formMessageBuilder) build() (MessageForm, error) {
msgForm.isReply = b.IsReply
msgForm.submitted = time.Now()

// Add TXT attachment if defined by the form
if v, ok := b.FormValues["attached_text"]; ok {
delete(b.FormValues, "attached_text")
msgForm.attachmentTXT = v
}

formVarsAsXML := ""
for varKey, varVal := range b.FormValues {
formVarsAsXML += fmt.Sprintf(" <%s>%s</%s>\n", xmlEscape(varKey), xmlEscape(varVal), xmlEscape(varKey))
Expand Down

0 comments on commit b58e0fa

Please sign in to comment.