]> granicus.if.org Git - neomutt/commitdiff
refactor mutt_account_match
authorRichard Russon <rich@flatcap.org>
Fri, 28 Sep 2018 19:10:53 +0000 (20:10 +0100)
committerRichard Russon <rich@flatcap.org>
Fri, 28 Sep 2018 22:51:56 +0000 (23:51 +0100)
mutt_account.c
mutt_account.h

index 7e63a602c37d98b537247eaaaffb138dcabf1918..ba00ab6836327e6a4be4fc58823a7e125daadb30 100644 (file)
@@ -55,50 +55,47 @@ char *SmtpPass; ///< Config: (smtp) Password for the SMTP server
  * mutt_account_match - Compare account info (host/port/user)
  * @param a1 First ConnAccount
  * @param a2 Second ConnAccount
- * @retval 1 Accounts match
- * @retval 0 Accounts match
+ * @retval true Accounts match
  */
-int mutt_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
+bool mutt_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
 {
-  const char *user = NONULL(Username);
-
   if (a1->type != a2->type)
-    return 0;
+    return false;
   if (mutt_str_strcasecmp(a1->host, a2->host) != 0)
-    return 0;
+    return false;
   if (a1->port != a2->port)
-    return 0;
+    return false;
+  if (a1->flags & a2->flags & MUTT_ACCT_USER)
+    return strcmp(a1->user, a2->user) == 0;
+
+#ifdef USE_NNTP
+  if (a1->type == MUTT_ACCT_TYPE_NNTP)
+    return a1->flags & MUTT_ACCT_USER && a1->user[0] ? 0 : 1;
+#endif
+
+  const char *user = NONULL(Username);
 
 #ifdef USE_IMAP
-  if (a1->type == MUTT_ACCT_TYPE_IMAP)
-  {
-    if (ImapUser)
-      user = ImapUser;
-  }
+  if ((a1->type == MUTT_ACCT_TYPE_IMAP) && ImapUser)
+    user = ImapUser;
 #endif
 
 #ifdef USE_POP
-  if (a1->type == MUTT_ACCT_TYPE_POP && PopUser)
+  if ((a1->type == MUTT_ACCT_TYPE_POP) && PopUser)
     user = PopUser;
 #endif
 
 #ifdef USE_NNTP
-  if (a1->type == MUTT_ACCT_TYPE_NNTP && NntpUser)
+  if ((a1->type == MUTT_ACCT_TYPE_NNTP) && NntpUser)
     user = NntpUser;
 #endif
 
-  if (a1->flags & a2->flags & MUTT_ACCT_USER)
-    return strcmp(a1->user, a2->user) == 0;
-#ifdef USE_NNTP
-  if (a1->type == MUTT_ACCT_TYPE_NNTP)
-    return a1->flags & MUTT_ACCT_USER && a1->user[0] ? 0 : 1;
-#endif
   if (a1->flags & MUTT_ACCT_USER)
     return strcmp(a1->user, user) == 0;
   if (a2->flags & MUTT_ACCT_USER)
     return strcmp(a2->user, user) == 0;
 
-  return 1;
+  return true;
 }
 
 /**
index 2bebabcb3a916c6de8ca1811f78f6fddfa86dfe6..86570b3f8e180f8b2ee2bc41d15bde7977a01ebf 100644 (file)
@@ -59,7 +59,7 @@ enum AccountType
 #define MUTT_ACCT_PASS  (1 << 3)
 #define MUTT_ACCT_SSL   (1 << 4)
 
-int mutt_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2);
+bool mutt_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2);
 int mutt_account_fromurl(struct ConnAccount *account, struct Url *url);
 void mutt_account_tourl(struct ConnAccount *account, struct Url *url);
 int mutt_account_getuser(struct ConnAccount *account);