la5nta / pat

A cross-platform Winlink client written in Go
https://getpat.io
MIT License
495 stars 86 forks source link

Pat is overly sensitive with form file names #384

Closed richcannings closed 1 year ago

richcannings commented 1 year ago

Pat cannot not identify the Norcal Winlink Net check in forms because:

A simple workaround is to:

mkdir -p ~/.local/share/pat/Standard_Forms/norcal_checkin
wget https://www.winlink.org/sites/default/files/RMSE_FORMS/norcal_checkin_v8.1.3.zip
unzip norcal_checkin_v8.1.3.zip -d ~/.local/share/pat/Standard_Forms/norcal_checkin
cd ~/.local/share/pat/Standard_Forms/norcal_checkin
mv v8.1.3-NorCal_Checkin.TXT NorCal_Checkin.txt
mv v8.1.3-NorCal_Checkin.HTML NorCal_Checkin.html

And update the first line of NorCal_Checkin.txt to point to the new file:

Form: NorCal_Checkin.html

I'm working on a fix in Pat, no guarantees when I can land a change.

richcannings commented 1 year ago

Fix

diff --git a/internal/forms/forms.go b/internal/forms/forms.go
index 7c91e99..7795793 100644
--- a/internal/forms/forms.go
+++ b/internal/forms/forms.go
@@ -40,6 +40,7 @@ import (

 const (
        fieldValueFalseInXML = "False"
+       htmlFileExt          = ".html"
        txtFileExt           = ".txt"
        formsVersionInfoURL  = "https://api.getpat.io/v1/forms/standard-templates/latest"
 )
@@ -533,15 +534,15 @@ func (m *Manager) ComposeForm(tmplPath string, subject string) (MessageForm, err

 func (f Form) matchesName(nameToMatch string) bool {
        return f.InitialURI == nameToMatch ||
-               f.InitialURI == nameToMatch+".html" ||
+               strings.EqualFold(f.InitialURI, nameToMatch + htmlFileExt) ||
                f.ViewerURI == nameToMatch ||
-               f.ViewerURI == nameToMatch+".html" ||
+               strings.EqualFold(f.ViewerURI, nameToMatch + htmlFileExt) ||
                f.ReplyInitialURI == nameToMatch ||
                f.ReplyInitialURI == nameToMatch+".0" ||
                f.ReplyViewerURI == nameToMatch ||
                f.ReplyViewerURI == nameToMatch+".0" ||
                f.TxtFileURI == nameToMatch ||
-               f.TxtFileURI == nameToMatch+".txt"
+               strings.EqualFold(f.TxtFileURI, nameToMatch + txtFileExt)
 }

 func (f Form) containsName(partialName string) bool {
@@ -595,7 +596,7 @@ func (m *Manager) innerRecursiveBuildFormFolder(rootPath string) (FormFolder, er
                        retVal.FormCount += subfolder.FormCount
                        continue
                }
-               if filepath.Ext(info.Name()) != txtFileExt {
+               if !strings.EqualFold(filepath.Ext(info.Name()), txtFileExt) {
                        continue
                }
                frm, err := m.buildFormFromTxt(path.Join(rootPath, info.Name()))
@@ -627,7 +628,7 @@ func (m *Manager) buildFormFromTxt(txtPath string) (Form, error) {
        formsPathWithSlash := m.config.FormsPath + "/"

        retVal := Form{
-               Name:       strings.TrimSuffix(path.Base(txtPath), ".txt"),
+               Name:       strings.TrimSuffix(path.Base(txtPath), path.Ext(txtPath)),
                TxtFileURI: strings.TrimPrefix(txtPath, formsPathWithSlash),
        }
        scanner := bufio.NewScanner(f)

Test

mkdir -p ~/.local/share/pat/Standard_Forms/norcal_checkin
wget https://www.winlink.org/sites/default/files/RMSE_FORMS/norcal_checkin_v8.1.3.zip
unzip norcal_checkin_v8.1.3.zip -d ~/.local/share/pat/Standard_Forms/norcal_checkin

And then compose and send an email using the template norcal_checkin > v8.1.3-NorCal_Checkin.

Confirm the receipt of the email, and the attached RMS_Express_Form_v8.1.3-NorCal_Checkin.xml is correctly populated.

richcannings commented 1 year ago

73! Rich KN6UZL