+From fb38f0278d42b1de2a2f76c59aa294276aef64a1 Mon Sep 17 00:00:00 2001
+From: Jan Palus <jpalus@fastmail.com>
+Date: Mon, 15 May 2023 19:16:22 +0200
+Subject: [PATCH 1/2] webdav: fastmail: adapt modtime update
+
+to make new logic work with fastmail bring spec compliant update from:
+https://github.com/rclone/rclone/pull/6108
+---
+ backend/webdav/webdav.go | 17 ++++++++++++++---
+ 1 file changed, 14 insertions(+), 3 deletions(-)
+
+diff --git a/backend/webdav/webdav.go b/backend/webdav/webdav.go
+index 801e8d970..c91e4950c 100644
+--- a/backend/webdav/webdav.go
++++ b/backend/webdav/webdav.go
+@@ -178,6 +178,7 @@ type Fs struct {
+ canStream bool // set if can stream
+ useOCMtime bool // set if can use X-OC-Mtime
+ propsetMtime bool // set if can use propset
++ propNameMtime string // name of property to set for mtime
+ retryWithZeroDepth bool // some vendors (sharepoint) won't list files when Depth is 1 (our default)
+ checkBeforePurge bool // enables extra check that directory to purge really exists
+ hasOCMD5 bool // set if can use owncloud style checksums for MD5
+@@ -581,18 +582,22 @@ func (f *Fs) setQuirks(ctx context.Context, vendor string) error {
+ f.canStream = true
+ f.precision = time.Second
+ f.useOCMtime = true
++ f.propsetMtime = true
++ f.propNameMtime = "getlastmodified"
+ f.hasMESHA1 = true
+ case "owncloud":
+ f.canStream = true
+ f.precision = time.Second
+ f.useOCMtime = true
+ f.propsetMtime = true
++ f.propNameMtime = "lastmodified"
+ f.hasOCMD5 = true
+ f.hasOCSHA1 = true
+ case "nextcloud":
+ f.precision = time.Second
+ f.useOCMtime = true
+ f.propsetMtime = true
++ f.propNameMtime = "lastmodified"
+ f.hasOCSHA1 = true
+ f.canChunk = true
+
+@@ -1322,11 +1327,11 @@ func (o *Object) ModTime(ctx context.Context) time.Time {
+ // Set modified time using propset
+ //
+ // <d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns"><d:response><d:href>/ocm/remote.php/webdav/office/wir.jpg</d:href><d:propstat><d:prop><d:lastmodified/></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:propstat></d:response></d:multistatus>
+-var owncloudPropset = `<?xml version="1.0" encoding="utf-8" ?>
++var mtimePropset = `<?xml version="1.0" encoding="utf-8" ?>
+ <D:propertyupdate xmlns:D="DAV:">
+ <D:set>
+ <D:prop>
+- <lastmodified xmlns="DAV:">%d</lastmodified>
++ <D:%s>%s</D:%s>
+ </D:prop>
+ </D:set>
+ </D:propertyupdate>
+@@ -1335,11 +1340,17 @@ var owncloudPropset = `<?xml version="1.0" encoding="utf-8" ?>
+ // SetModTime sets the modification time of the local fs object
+ func (o *Object) SetModTime(ctx context.Context, modTime time.Time) error {
+ if o.fs.propsetMtime {
++ var modTimeStr string
++ if o.fs.propNameMtime == "getlastmodified" {
++ modTimeStr = modTime.Format(time.RFC1123)
++ } else {
++ modTimeStr = strconv.FormatInt(modTime.Unix(), 10)
++ }
+ opts := rest.Opts{
+ Method: "PROPPATCH",
+ Path: o.filePath(),
+ NoRedirect: true,
+- Body: strings.NewReader(fmt.Sprintf(owncloudPropset, modTime.Unix())),
++ Body: strings.NewReader(fmt.Sprintf(mtimePropset, o.fs.propNameMtime, modTimeStr, o.fs.propNameMtime)),
+ }
+ var result api.Multistatus
+ var resp *http.Response
+--
+2.41.0
+
+From 84d2bbc2e2eb15f4ef3558aec46adf33d3b443c3 Mon Sep 17 00:00:00 2001
+From: Jan Palus <jpalus@fastmail.com>
+Date: Mon, 15 May 2023 19:20:32 +0200
+Subject: [PATCH 2/2] webdav: fastmail: support for update_modtime config opt
+
+for compatibility with:
+https://github.com/rclone/rclone/pull/6108
+---
+ backend/webdav/webdav.go | 15 +++++++++++++--
+ 1 file changed, 13 insertions(+), 2 deletions(-)
+
+diff --git a/backend/webdav/webdav.go b/backend/webdav/webdav.go
+index c91e4950c..a8c7ffce8 100644
+--- a/backend/webdav/webdav.go
++++ b/backend/webdav/webdav.go
+@@ -146,6 +146,14 @@ Set to 0 to disable chunked uploading.
+ Help: "Exclude ownCloud shares",
+ Advanced: true,
+ Default: false,
++ }, {
++ Name: "update_modtime",
++ Help: `Adjust modification time on servers which allow DAV:getlastmodified property update.
++
++Use provider's default if unset.
++`,
++ Default: fs.Tristate{},
++ Advanced: true,
+ }},
+ })
+ }
+@@ -162,6 +170,7 @@ type Options struct {
+ PacerMinSleep fs.Duration `config:"pacer_min_sleep"`
+ ChunkSize fs.SizeSuffix `config:"nextcloud_chunk_size"`
+ ExcludeShares bool `config:"owncloud_exclude_shares"`
++ UpdateModTime fs.Tristate `config:"update_modtime"`
+ }
+
+ // Fs represents a remote webdav
+@@ -582,8 +591,10 @@ func (f *Fs) setQuirks(ctx context.Context, vendor string) error {
+ f.canStream = true
+ f.precision = time.Second
+ f.useOCMtime = true
+- f.propsetMtime = true
+- f.propNameMtime = "getlastmodified"
++ if !f.opt.UpdateModTime.Valid || f.opt.UpdateModTime.Valid && f.opt.UpdateModTime.Value {
++ f.propsetMtime = true
++ f.propNameMtime = "getlastmodified"
++ }
+ f.hasMESHA1 = true
+ case "owncloud":
+ f.canStream = true
+--
+2.41.0
+