diff --git a/internal/useragent/useragent.go b/internal/useragent/useragent.go index 23d21074..73da03a3 100644 --- a/internal/useragent/useragent.go +++ b/internal/useragent/useragent.go @@ -21,6 +21,7 @@ import ( "fmt" "regexp" "runtime" + "strings" "sync" ) @@ -42,9 +43,12 @@ func New() *UserAgent { } func (ua *UserAgent) SetClient(name, version string) { + if strings.EqualFold("Mac OS X Notes", name) { + return + } + ua.lock.Lock() defer ua.lock.Unlock() - ua.client = fmt.Sprintf("%v/%v", name, regexp.MustCompile(`(.*) \((.*)\)`).ReplaceAllString(version, "$1-$2")) } diff --git a/internal/useragent/useragent_test.go b/internal/useragent/useragent_test.go index cb915a33..88b102a7 100644 --- a/internal/useragent/useragent_test.go +++ b/internal/useragent/useragent_test.go @@ -64,6 +64,14 @@ func TestUserAgent(t *testing.T) { platform: "Windows 10 (10.0)", want: "Thunderbird/78.6.1 (Windows 10 (10.0))", }, + + // We ignore Apple Notes. + { + name: "Mac OS X Notes", + version: "4.11", + platform: "Windows 10 (10.0)", + want: DefaultUserAgent + " (Windows 10 (10.0))", + }, } for _, test := range tests { diff --git a/tests/features/imap/id.feature b/tests/features/imap/id.feature index 9e3db21f..69259477 100644 --- a/tests/features/imap/id.feature +++ b/tests/features/imap/id.feature @@ -22,4 +22,29 @@ Feature: The IMAP ID is propagated to bridge When user "[user:user]" connects IMAP client "1" And IMAP client "1" announces its ID with name "name" and version "version" When the user reports a bug - Then the header in the "POST" request to "/core/v4/reports/bug" has "User-Agent" set to "name/version ([GOOS])" \ No newline at end of file + Then the header in the "POST" request to "/core/v4/reports/bug" has "User-Agent" set to "name/version ([GOOS])" + + Scenario: User agent re-announces a new ID to IMAP client + When user "[user:user]" connects IMAP client "1" + And IMAP client "1" announces its ID with name "name" and version "version" + Then the user agent is "name/version ([GOOS])" + And IMAP client "1" announces its ID with name "new_name" and version "new_version" + Then the user agent is "new_name/new_version ([GOOS])" + + Scenario: User agent re-announces a new ID to IMAP client and new ID is used for API calls + When user "[user:user]" connects IMAP client "1" + And IMAP client "1" announces its ID with name "name" and version "version" + When the user reports a bug + Then the header in the "POST" request to "/core/v4/reports/bug" has "User-Agent" set to "name/version ([GOOS])" + When IMAP client "1" announces its ID with name "new_name" and version "new_version" + Then the user agent is "new_name/new_version ([GOOS])" + When the user reports a bug + Then the header in the "POST" request to "/core/v4/reports/bug" has "User-Agent" set to "new_name/new_version ([GOOS])" + + Scenario: Apple Notes user agent is ignored after IMAP client announces its ID + When user "[user:user]" connects IMAP client "1" + And IMAP client "1" announces its ID with name "name" and version "version" + Then the user agent is "name/version ([GOOS])" + When IMAP client "1" announces its ID with name "Mac OS X Notes" and version "4.11" + Then the user agent is "name/version ([GOOS])" +