Skip to content

Commit

Permalink
Only attach Forms XML if a viewer file is defined
Browse files Browse the repository at this point in the history
Resolves #420
  • Loading branch information
martinhpedersen committed Sep 22, 2023
1 parent a1555a9 commit 6b75f18
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
6 changes: 4 additions & 2 deletions cli_composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,10 @@ func composeFormReport(ctx context.Context, args []string) {

msg.SetBody(formMsg.Body)

attachmentFile := fbb.NewFile(formMsg.AttachmentName, []byte(formMsg.AttachmentXML))
msg.AddFile(attachmentFile)
if xml := formMsg.AttachmentXML; xml != "" {
attachmentFile := fbb.NewFile(formMsg.AttachmentName, []byte(xml))
msg.AddFile(attachmentFile)
}

postMessage(msg)
}
6 changes: 4 additions & 2 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,10 @@ func postOutboundMessageHandler(w http.ResponseWriter, r *http.Request) {
cookie, err := r.Cookie("forminstance")
if err == nil {
formData := formsMgr.GetPostedFormData(cookie.Value)
name := formsMgr.GetXMLAttachmentNameForForm(formData.TargetForm, formData.IsReply)
msg.AddFile(fbb.NewFile(name, []byte(formData.MsgXML)))
if xml := formData.MsgXML; xml != "" {
name := formsMgr.GetXMLAttachmentNameForForm(formData.TargetForm, formData.IsReply)
msg.AddFile(fbb.NewFile(name, []byte(formData.MsgXML)))
}
}

// Other fields
Expand Down
50 changes: 28 additions & 22 deletions internal/forms/forms.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,17 +631,18 @@ func (m *Manager) buildFormFromTxt(txtPath string) (Form, error) {
l := scanner.Text()
switch {
case strings.HasPrefix(l, "Form:"):
trimmed := strings.TrimSpace(strings.TrimPrefix(l, "Form:"))
fileNames := strings.Split(trimmed, ",")
if len(fileNames) >= 2 {
initial := strings.TrimSpace(fileNames[0])
viewer := strings.TrimSpace(fileNames[1])
form.InitialURI = path.Join(baseURI, initial)
form.ViewerURI = path.Join(baseURI, viewer)
} else {
view := strings.TrimSpace(fileNames[0])
form.InitialURI = path.Join(baseURI, view)
form.ViewerURI = path.Join(baseURI, view)
// Form: <composer>,<viewer>
files := strings.Split(strings.TrimPrefix(l, "Form:"), ",")
// Extend to absolute paths and add missing html extension
for i := range files {
files[i] = path.Join(baseURI, strings.TrimSpace(files[i]))
if ext := path.Ext(files[i]); ext == "" {
files[i] += ".html"
}
}
form.InitialURI = files[0]
if len(files) > 1 {
form.ViewerURI = files[1]
}
case strings.HasPrefix(l, "ReplyTemplate:"):
form.ReplyTxtFileURI = path.Join(baseURI, strings.TrimSpace(strings.TrimPrefix(l, "ReplyTemplate:")))
Expand Down Expand Up @@ -949,7 +950,10 @@ func (b formMessageBuilder) build() (MessageForm, error) {
if err != nil {
return MessageForm{}, err
}
msgForm.AttachmentXML = fmt.Sprintf(`%s<RMS_Express_Form>

// Add XML if a viewer is defined for this form
if b.Template.ViewerURI != "" {
msgForm.AttachmentXML = fmt.Sprintf(`%s<RMS_Express_Form>
<form_parameters>
<xml_file_version>%s</xml_file_version>
<rms_express_version>%s</rms_express_version>
Expand All @@ -964,16 +968,18 @@ func (b formMessageBuilder) build() (MessageForm, error) {
</variables>
</RMS_Express_Form>
`,
xml.Header,
"1.0",
b.FormsMgr.config.AppVersion,
time.Now().UTC().Format("20060102150405"),
b.FormsMgr.config.MyCall,
b.FormsMgr.config.Locator,
viewer,
replier,
formVarsAsXML)
msgForm.AttachmentName = b.FormsMgr.GetXMLAttachmentNameForForm(b.Template, false)
xml.Header,
"1.0",
b.FormsMgr.config.AppVersion,
time.Now().UTC().Format("20060102150405"),
b.FormsMgr.config.MyCall,
b.FormsMgr.config.Locator,
viewer,
replier,
formVarsAsXML)
msgForm.AttachmentName = b.FormsMgr.GetXMLAttachmentNameForForm(b.Template, false)
}

msgForm.To = strings.TrimSpace(msgForm.To)
msgForm.Cc = strings.TrimSpace(msgForm.Cc)
msgForm.Subject = strings.TrimSpace(msgForm.Subject)
Expand Down

0 comments on commit 6b75f18

Please sign in to comment.