go-msgauth icon indicating copy to clipboard operation
go-msgauth copied to clipboard

Improve line folding algorithm

Open emersion opened this issue 5 years ago • 4 comments

With https://github.com/emersion/go-msgauth/pull/29 we no longer generate broken signatures with FWS where they shouldn't be. However we could still improve our folding algorithm. Given these constraints:

  • We want to be RFC-conformant (lines < 1000 chars)
  • We don't want something too complicated (see https://github.com/emersion/go-msgauth/pull/27)
  • Ensuring that lines are <75 chars is not necessary

We may want to fix these:

  • We still don't properly fold h= params if they are very long
  • We fold b= params at 75 chars, but we don't need to

emersion avatar May 28 '20 13:05 emersion

I can work on it on the next days! :D My idea is to write two simple functions, one to fold h and one for b (that we already have).

ludusrusso avatar May 28 '20 17:05 ludusrusso

Nice!

I think to fold h, it'll probably be simpler to do it before turning the list into a string, ie. in formatTagList:

https://github.com/emersion/go-msgauth/blob/fb07ec9e7323788ae953eea6797a1dddb8a13106/dkim/sign.go#L340

emersion avatar May 28 '20 17:05 emersion

Nice!

I think to fold h, it'll probably be simpler to do it before turning the list into a string, ie. in formatTagList:

https://github.com/emersion/go-msgauth/blob/fb07ec9e7323788ae953eea6797a1dddb8a13106/dkim/sign.go#L340

Thats right, but I then need to change some piece of code in the middle, I thinks that it would be simpler by just use Strings.split in

https://github.com/emersion/go-msgauth/blob/fb07ec9e7323788ae953eea6797a1dddb8a13106/dkim/header.go#L95

ludusrusso avatar May 28 '20 17:05 ludusrusso

By the way, #30 fixed the h= wrapping as well.

wjywbs avatar May 29 '20 14:05 wjywbs