# Send source patches with (G Suite) and Thunderbird




[にほんご](https://qiita.com/wataash/items/6538c193b5c80a52c285)

Gmail's web mail client is not suitable for sending code patches, since it
doesn't send the email contents **as is**. TABs are converted to white spaces,
trailing spaces are trimmed.

<!-- [f:id:wataash:20200314154617p:plain:alt=patch collapsed via web Gmail] -->
![patch collapsed via web Gmail](2020-08-01-21-38-25.png "patch collapsed via web Gmail")

So the patch cannot be applied with `git am` or `git apply`!

```c
$ git apply < patch.txt
error: patch failed: gdb/ChangeLog:1
error: gdb/ChangeLog: patch does not apply
error: patch failed: gdb/darwin-nat.c:1985
error: gdb/darwin-nat.c: patch does not apply
```

We have to use an external email client (MUA; Mail User Agent).

## Which email client should I use?

TL;DR: Use Mutt if you're familiar with it, otherwise use Thunderbird.

If you're sending git patch, use [git-send-email(1)][] with googling ["git
send-email gmail"](https://www.google.com/search?q=git+send-email+gmail). [It is
the recommended way to send patches to Linux kernel.][linux]

[git-send-email(1)]: https://git-scm.com/docs/git-send-email
[linux]: https://www.kernel.org/doc/html/latest/process/email-clients.html

In this article, `cvs diff`, `svn diff`, or any other *unified diff* (`diff -u`)
formatted patches are supposed to be sent.

So I my checked out all the clients listed in [Linux kernel's document][linux]
and [git-format-patch(1) man page][git-format-patch]. My requirements are:

[git-format-patch]: https://git-scm.com/docs/git-format-patch

- Open source
- Continuously developed; Google changes the Gmail's IMAP interface several
  times, so incompatibility in the client should be fixed soon; for instance, in
  2019, [the password login for IMAP was disabled by default][1], and the
  standard authentication was replaced with OAuth
- Many users send patches with that client; If we encounter a problem, someone
  has likely already solved it on Stack Overflow

[1]: https://gsuiteupdates.googleblog.com/2019/12/less-secure-apps-oauth-google-username-password-incorrect.html

Accordingly with the following google results:

Search keywords                         | GUI or TUI      | # results as of 2020/03/13
---                                     | ---             | ---
"git am" Mutt                           | TUI             | 11,800
"git am" Thunderbird                    | GUI             | 11,600
"git am" Alpine                         | TUI             | 5,300
"git am" KMail                          | GUI             | 1,650
"git am" Claws Mail                     | GUI             | 2,270
"git am" TkRat                          | GUI             | 252
"git am" Sylpheed                       | GUI             | 262
"git am" Evolution (run only on Linux)  | GUI             | 11,900
"git am" outlook (non open source)      | GUI             | 6,690
"git am" apple mail (non open source)   | GUI             | 7,850
"git am" "apple mail" (non open source) | GUI             | 101

At first I tried Mutt, which seemed to meet the needs, then faced an error like
*authentication failed*. I discarded mutt right after searching *gmail mutt
"authentication failed"* which didn't show any useful information to solve it.

Next I tried Thunderbird, and I found out it's very easy, many people are
sending patches with it, and there are many knowledges in the web about sending
patches.

## Enable Gmail's IMAP

*Enable IMAP* in Settings.

<!-- [f:id:wataash:20200314122722p:plain:alt=enable IMAP in Gmail's Setting] -->
![enable IMAP in Gmail's Setting](2020-08-01-21-38-48.png "enable IMAP in Gmail's Setting")

## Add account in Thunderbird

*File* → *New* → *Existing Mail Account...*

<!-- [f:id:wataash:20200314123609p:plain:alt=add Gmail's account on Thunderbird (1)] -->
![add Gmail's account on Thunderbird (1)](2020-08-01-21-40-57.png "add Gmail's account on Thunderbird (1)")

Enter your name and Gmail (foo@gmail.com) or G Suite
(foo@foo-organization.com) email address and press *Continue*. Leave
*Password* blank.

<!-- [f:id:wataash:20200314134732p:plain:alt=add Gmail's account on Thunderbird (2)] -->
![add Gmail's account on Thunderbird (2)](2020-08-01-21-41-04.png "add Gmail's account on Thunderbird (2)")

Press *Manual config*.

<!-- [f:id:wataash:20200314135438p:plain:alt=add Gmail's account on Thunderbird (3)] -->
![add Gmail's account on Thunderbird (3)](2020-08-01-21-41-12.png "add Gmail's account on Thunderbird (3)")

Make sure that *Authentication* is *OAuth2* and press *Done*.

<!-- [f:id:wataash:20200314140106p:plain:alt=add Gmail's account on Thunderbird (4 Google OAuth)] -->
![add Gmail's account on Thunderbird (4 Google OAuth)](2020-08-01-21-41-20.png "add Gmail's account on Thunderbird (4 Google OAuth)")
<!-- [f:id:wataash:20200314140448p:plain:alt=add Gmail's account on Thunderbird (5 Google OAuth)] -->
![add Gmail's account on Thunderbird (5 Google OAuth)](2020-08-01-21-41-26.png "add Gmail's account on Thunderbird (5 Google OAuth)")

Enter your Google (G Suite) password.

<!-- [f:id:wataash:20200314141229p:plain:alt=add Gmail's account on Thunderbird (6)] -->
![add Gmail's account on Thunderbird (6)](2020-08-01-21-41-49.png "add Gmail's account on Thunderbird (6)")

Unfortunately, this time I failed the authentication with the following errors:

- User name or password invalid
- Configuration could not be verified ― is the user name or password wrong?

I believe this will fixed soon.

As a workaround I used the password authentication.

### Password authentication

**Leave the Thunderbird's setting window open!**

First, we have to allow *less secure app access* for password authentication.

If you're adding G Suite account (if email address is you@your-company.com, not
you@gmail.com), the G Suite administrator have to allow [Control access to less
secure apps](https://support.google.com/a/answer/6260879?hl=en).

<!-- [f:id:wataash:20200314143220p:plain:alt=(G Suite) Allow users to manage their access to less secure apps] -->
![(G Suite) Allow users to manage their access to less secure apps](2020-08-01-21-42-11.png "(G Suite) Allow users to manage their access to less secure apps")

For both Gmail and G Suite, goto [Less secure app access
settings](https://myaccount.google.com/lesssecureapps) and turn on *Allow less
secure apps*. Account can be switched by clicking the icon on the upper right.

<!-- [f:id:wataash:20200314144007p:plain:alt=turn on: Allow less secure apps] -->
![turn on: Allow less secure apps](2020-08-01-21-42-25.png "turn on: Allow less secure apps")

Then on Thunderbird, choose *Normal password* as *Authentication* and press
*Done*.

<!-- [f:id:wataash:20200314145818p:plain:alt=add Gmail's account on Thunderbird (7)] -->
![add Gmail's account on Thunderbird (7)](2020-08-01-21-42-33.png "add Gmail's account on Thunderbird (7)")

You will see the received emails on Gmail, hooray 🎉

## Disable format=flowed

But still Thunderbird trims white spaces! Change the settings following to
[git-format-patch(1)][git-format-patch]:

- *Edit* → *Account Settings* → *Composition & Addressing* → uncheck *Compose
  messages in HTML format*
- *Edit* → *Preferences* → *Advanced* → *Config Editor...*
  - `mail.wrap_long_lines`: `false`
  - `mailnews.wraplength`: `0`
  - `mailnews.send_plaintext_flowed`: `false`

Now `format=flowed` will be removed from email headers:

```c
To: bar@gmail.com
From: Wataru Ashihara <foo@gmail.com>
Subject: test
Message-ID: <***@gmail.com>
Date: Mon, 9 Mar 2020 19:48:53 +0900
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101
 Thunderbird/60.9.0
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
                                       ^^^^^^^^^^^^^^^ this removed!
Content-Language: en-US
Content-Transfer-Encoding: 7bit

body
```

and body will be sent *AS IS*.

