Honor the sendmail.smtpUser from gerrit.config on upgrade

If a review site was already existing when the "init" was run but
sendmail.smtpUser was not defined then "init" would set
sendmail.smtpUser to the username of the user running the init. This
would make gerrit use smtp authentication where, before upgrade, smtp
authentication wasn't used.

Instead of doing that, we now honor the value of sendmail.smtpUser from
gerrit.config even when it is null (not present in gerrit.config) in
order to ensure the same behavior of smtp authentication as before
upgrade.

Change-Id: I1b241484ae1d9b5ded7eaf97dbe5dd5cbe10eaf0
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitSendEmail.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitSendEmail.java
index 7a3556e..c5732e9 100644
--- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitSendEmail.java
+++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitSendEmail.java
@@ -28,12 +28,14 @@
 class InitSendEmail implements InitStep {
   private final ConsoleUI ui;
   private final Section sendemail;
+  private final SitePaths site;
 
   @Inject
   InitSendEmail(final ConsoleUI ui, final SitePaths site,
       final Section.Factory sections) {
     this.ui = ui;
     this.sendemail = sections.get("sendemail");
+    this.site = site;
   }
 
   public void run() {
@@ -49,7 +51,9 @@
             true);
 
     String username = null;
-    if ((enc != null && enc != Encryption.NONE) || !isLocal(hostname)) {
+    if (site.gerrit_config.exists()) {
+      username = sendemail.get("smtpUser");
+    } else if ((enc != null && enc != Encryption.NONE) || !isLocal(hostname)) {
       username = username();
     }
     sendemail.string("SMTP username", "smtpUser", username);